1 /*
2 
3 Copyright 2021, dettus@dettus.net
4 
5 Redistribution and use in source and binary forms, with or without modification,
6 are permitted provided that the following conditions are met:
7 
8 1. Redistributions of source code must retain the above copyright notice, this
9    list of conditions and the following disclaimer.
10 
11 2. Redistributions in binary form must reproduce the above copyright notice,
12    this list of conditions and the following disclaimer in the documentation
13    and/or other materials provided with the distribution.
14 
15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 
26 
27 */
28 
29 #ifndef	VM68K_DECODE_H
30 #define	VM68K_DECODE_H
31 //#define	DEBUG_PRINT
32 #include "vm68k_datatypes.h"
33 
34 
35 // this data structure makes the decoding process easier to read.
36 typedef	enum _tVM68k_instruction
37 {
38 VM68K_INST_UNKNOWN=0,
39 VM68K_INST_ABCD,	//1100xxx10000myyy
40  VM68K_INST_ADD,	//1101 rrro oomm myyy
41  VM68K_INST_ADDA,	//1101 rrro oomm myyy
42  VM68K_INST_ADDI,	//0000 0110 ssmm myyy
43  VM68K_INST_ADDQ,	//0101 ddd0 ssmm myyy
44  VM68K_INST_ADDX,	//1101 xxx1 ss00 myyy
45  VM68K_INST_AND,	//1100 xxxo oomm myyy
46  VM68K_INST_ANDI,	//0000 0010 ssmm myyy
47  VM68K_INST_ANDItoCCR,	//0000 0010 0011 1100 00000000dddddddd
48  VM68K_INST_ANDItoSR,	//0000 0010 0111 1100 dddddddddddddddd
49  VM68K_INST_ASL_ASR,	//1110 cccd ssl0 0yyy
50  VM68K_INST_BCC,	//0110 CCCC dddd dddd
51  VM68K_INST_BCHG,	//0000 xxx1 01mm myyy
52  VM68K_INST_BCHGB,	//0000 1000 10mm myyy
53  VM68K_INST_BCLR,	//0000 xxx1 10mm myyy
54  VM68K_INST_BCLRI,	//0000xxx110mmmyyy
55  VM68K_INST_BRA,	//0110 0000 dddd dddd
56  VM68K_INST_BSET,	//0000 xxx1 11mm myyy
57  VM68K_INST_BSETB,	//0000 1000 11mm myyy
58 // VM68K_INST_BSR,		//01100001dddddddd
59  VM68K_INST_BTST,	//0000 xxx1 00mm myyy
60  VM68K_INST_BTSTB,	//0000 1000 00mm myyy
61 VM68K_INST_CHK,		//0100xxxss0mmmyyy
62  VM68K_INST_CLR,	//0100 0010 ssmm myyy
63  VM68K_INST_CMP,	//1011 xxxo oomm myyy
64  VM68K_INST_CMPA,	//1011 xxxo oomm myyy
65  VM68K_INST_CMPI,	//0000 1100 ssmm myyy
66  VM68K_INST_CMPM,	//1011 xxx1 ss00 1yyy
67  VM68K_INST_DBcc,	//0101 CCCC 1100 1yyy
68 VM68K_INST_DIVS,	//1000xxx111mmmyyy
69 VM68K_INST_DIVU,	//1000xxx011mmmyyy
70  VM68K_INST_EOR,	//1011 xxxo oomm myyy
71  VM68K_INST_EORI,	//0000 1010 ssmm myyy
72  VM68K_INST_EORItoCCR,	//0000 1010 0011 1100 00000000dddddddd
73  VM68K_INST_EORItoSR,	//0000 1010 0111 1100 dddddddddddddddd
74  VM68K_INST_EXG,	//1100 xxx1 oooo oyyy
75  VM68K_INST_EXT,	//0100 100o oo00 0yyy
76 VM68K_INST_ILLEGAL,	//0100101011111100
77  VM68K_INST_JMP,	//0100 1110 11mm myyy
78  VM68K_INST_JSR,	//0100 1110 10mm myyy
79  VM68K_INST_LEA,	//0100 xxx1 11mm myyy
80 VM68K_INST_LINK,	//0100111001010yyydddddddddddddddd
81  VM68K_INST_LSL_LSR,	//1110 cccd ssl0 1yyy
82  VM68K_INST_MOVE,	//00ss xxxm mmMM Myyy
83  VM68K_INST_MOVEA,	//00ss xxx0 01mm myyy
84  VM68K_INST_MOVEtoCCR,	//0100010011mmmyyy
85  VM68K_INST_MOVEfromSR,	//0100000011mmmyyy
86  VM68K_INST_MOVEtoSR,	//0100011011mmmyyy
87 VM68K_INST_MOVEUSP,	//010011100110dyyy
88  VM68K_INST_MOVEMregtomem,	//0100 1d00 1smm myyy
89  VM68K_INST_MOVEMmemtoreg,	//0100 1d00 1smm myyy
90 VM68K_INST_MOVEP,	//0000xxxooo001yyydddddddddddddddd
91  VM68K_INST_MOVEQ,	//0111xxx0dddddddd
92 VM68K_INST_MULS,	//1100xxx111mmmyyy
93 VM68K_INST_MULU,	//1100xxx011mmmyyy!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
94 VM68K_INST_NBCD,	//1100xxx011mmmyyy!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
95  VM68K_INST_NEG,	//0100 0100 ssmm myyy
96  VM68K_INST_NEGX,	//0100 0000 ssmm myyy
97  VM68K_INST_NOP,	//0100 1110 0111 0001
98  VM68K_INST_NOT,	//0100 0110 ssmm myyy
99  VM68K_INST_OR,		//1000 xxxo oomm myyy
100  VM68K_INST_ORI,	//0000 0000 ssmm myyy
101  VM68K_INST_ORItoCCR,	//0000 0000 0011 1100 00000000dddddddd
102  VM68K_INST_ORItoSR,	//0000 0000 0111 1100 dddddddddddddddd
103  VM68K_INST_PEA,	//0100 1000 01mm myyy
104 VM68K_INST_RESET,	//0100111001110000
105  VM68K_INST_ROL_ROR,	//1110 cccd ssl1 1yyy
106  VM68K_INST_ROXL_ROXR,	//1110 cccd ssl1 0yyy
107 VM68K_INST_RTE,		//0100 1110 0111 0011
108 VM68K_INST_RTR,		//0100 1110 0111 0111
109  VM68K_INST_RTS,	//0100 1110 0111 0101
110 VM68K_INST_SBCD,	//1000xxx10000ryyy
111  VM68K_INST_SCC,	//0101 CCCC 11mm myyy
112 VM68K_INST_STOP,	//0100111001110010iiiiiiiiiiiiiiii
113  VM68K_INST_SUB,	//1001 xxxo oomm myyy
114  VM68K_INST_SUBA,	//1001 xxxo oomm myyy
115  VM68K_INST_SUBI,	//0000 0100 ssmm myyy
116  VM68K_INST_SUBQ,	//0101 ddd1 ssmm myyy
117  VM68K_INST_SUBX,	//1001 yyy1 ss00 ryyy
118 VM68K_INST_SWAP,	//0100100001000yyy
119 VM68K_INST_TAS,		//0100101011mmmyyy
120 VM68K_INST_TRAP,	//010011100100vvvv
121 VM68K_INST_TRAPV,	//0100111001110110
122  VM68K_INST_TST,	//0100 1010 ssmm myyy
123 VM68K_INST_UNLK,	//0100111001011yyy
124 } tVM68k_instruction;
125 
126 
127 
128 // opcodes are 16 bit values, this function translates them into an easier-to-handle enumeration.
129 tVM68k_instruction vm68k_decode(tVM68k_uword opcode);
130 
131 #ifdef	DEBUG_PRINT
132 // this function is for translating the enumeration into something human-readable.
133 void vm68k_get_instructionname(tVM68k_instruction instruction,char* name);
134 #endif
135 
136 #endif
137