-
Notifications
You must be signed in to change notification settings - Fork 4
/
Dasm6801.cpp
248 lines (224 loc) · 13.1 KB
/
Dasm6801.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
/***************************************************************************
* dasmfw -- Disassembler Framework *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the Free Software *
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
***************************************************************************/
/* The 6801 disassembler engine is based on contributions to f9dasm *
* by Rainer Buchty, so *
* Parts Copyright (C) 2014 Rainer Buchty *
***************************************************************************/
/*****************************************************************************/
/* Dasm6801.cpp : 6801 disassembler classes implementation */
/*****************************************************************************/
#include "Dasm6801.h"
/*****************************************************************************/
/* Create6801 : create an 6801 disassembler */
/*****************************************************************************/
static Disassembler *Create6801(Application *pApp)
{
Disassembler *pDasm = new Dasm6801(pApp);
if (pDasm) pDasm->Setup();
return pDasm;
}
/*****************************************************************************/
/* Auto-registration */
/*****************************************************************************/
static bool bRegistered[] =
{
RegisterDisassembler("6801", Create6801),
RegisterDisassembler("6803", Create6801),
};
/*===========================================================================*/
/* Dasm6801 class members */
/*===========================================================================*/
/*****************************************************************************/
/* m6801_codes : table of all 6801 instruction bytes and types */
/*****************************************************************************/
CMatrixEntry Dasm6801::m6801_codes[256] =
{
{_ill ,_nom}, {_nop ,_imp}, {_ill ,_nom}, {_ill ,_nom}, /* 00..03 */
{_lsrd ,_imp}, {_asld ,_imp}, {_tap ,_imp}, {_tpa ,_imp}, /* 04..07 */
{_inx ,_imp}, {_dex ,_imp}, {_clv ,_imp}, {_sev ,_imp}, /* 08..0B */
{_clc ,_imp}, {_sec ,_imp}, {_cli ,_imp}, {_sei ,_imp}, /* 0C..0F */
{_sba ,_imp}, {_cba ,_imp}, {_ill ,_nom}, {_ill ,_nom}, /* 10..13 */
{_ill ,_nom}, {_ill ,_nom}, {_tab ,_imp}, {_tba ,_imp}, /* 14..17 */
{_ill ,_nom}, {_daa ,_imp}, {_ill ,_nom}, {_aba ,_imp}, /* 18..1B */
{_ill ,_nom}, {_ill ,_nom}, {_ill ,_nom}, {_ill ,_nom}, /* 1C..1F */
{_bra ,_reb}, {_brn ,_reb}, {_bhi ,_reb}, {_bls ,_reb}, /* 20..23 */
{_bcc ,_reb}, {_bcs ,_reb}, {_bne ,_reb}, {_beq ,_reb}, /* 24..27 */
{_bvc ,_reb}, {_bvs ,_reb}, {_bpl ,_reb}, {_bmi ,_reb}, /* 28..2B */
{_bge ,_reb}, {_blt ,_reb}, {_bgt ,_reb}, {_ble ,_reb}, /* 2C..2F */
{_tsx ,_imp}, {_ins ,_imp}, {_pula ,_imp}, {_pulb ,_imp}, /* 30..33 */
{_des ,_imp}, {_txs ,_imp}, {_psha ,_imp}, {_pshb ,_imp}, /* 34..37 */
{_pulx ,_imp}, {_rts ,_imp}, {_abx ,_imp}, {_rti ,_imp}, /* 38..3B */
{_pshx ,_imp}, {_mul ,_imp}, {_wai ,_imp}, {_swi ,_imp}, /* 3C..3F */
{_nega ,_imp}, {_ill ,_nom}, {_ill ,_nom}, {_coma ,_imp}, /* 40..43 */
{_lsra ,_imp}, {_ill ,_nom}, {_rora ,_imp}, {_asra ,_imp}, /* 44..47 */
{_asla ,_imp}, {_rola ,_imp}, {_deca ,_imp}, {_ill ,_nom}, /* 48..4B */
{_inca ,_imp}, {_tsta ,_imp}, {_ill ,_nom}, {_clra ,_imp}, /* 4C..4F */
{_negb ,_imp}, {_ill ,_nom}, {_ill ,_nom}, {_comb ,_imp}, /* 50..53 */
{_lsrb ,_imp}, {_ill ,_nom}, {_rorb ,_imp}, {_asrb ,_imp}, /* 54..57 */
{_aslb ,_imp}, {_rolb ,_imp}, {_decb ,_imp}, {_ill ,_nom}, /* 58..5B */
{_incb ,_imp}, {_tstb ,_imp}, {_ill ,_nom}, {_clrb ,_imp}, /* 5C..5F */
{_neg ,_ix8}, {_ill ,_nom}, {_ill ,_nom}, {_com ,_ix8}, /* 60..63 */
{_lsr ,_ix8}, {_ill ,_nom}, {_ror ,_ix8}, {_asr ,_ix8}, /* 64..67 */
{_asl ,_ix8}, {_rol ,_ix8}, {_dec ,_ix8}, {_ill ,_nom}, /* 68..6B */
{_inc ,_ix8}, {_tst ,_ix8}, {_jmp ,_ix8}, {_clr ,_ix8}, /* 6C..6F */
{_neg ,_ext}, {_ill ,_nom}, {_ill ,_nom}, {_com ,_ext}, /* 70..73 */
{_lsr ,_ext}, {_ill ,_nom}, {_ror ,_ext}, {_asr ,_ext}, /* 74..77 */
{_asl ,_ext}, {_rol ,_ext}, {_dec ,_ext}, {_ill ,_nom}, /* 78..7B */
{_inc ,_ext}, {_tst ,_ext}, {_jmp ,_ext}, {_clr ,_ext}, /* 7C..7F */
{_suba ,_imb}, {_cmpa ,_imb}, {_sbca ,_imb}, {_subd ,_imw}, /* 80..83 */
{_anda ,_imb}, {_bita ,_imb}, {_lda ,_imb}, {_ill ,_nom}, /* 84..87 */
{_eora ,_imb}, {_adca ,_imb}, {_ora ,_imb}, {_adda ,_imb}, /* 88..8B */
{_cpx ,_imw}, {_bsr ,_reb}, {_lds ,_imw}, {_ill ,_nom}, /* 8C..8F */
{_suba ,_dir}, {_cmpa ,_dir}, {_sbca ,_dir}, {_subd ,_dir}, /* 90..93 */
{_anda ,_dir}, {_bita ,_dir}, {_lda ,_dir}, {_sta ,_dir}, /* 94..97 */
{_eora ,_dir}, {_adca ,_dir}, {_ora ,_dir}, {_adda ,_dir}, /* 98..9B */
{_cpx ,_dir}, {_jsr ,_dir}, {_lds ,_dir}, {_sts ,_dir}, /* 9C..9F */
{_suba ,_ix8}, {_cmpa ,_ix8}, {_sbca ,_ix8}, {_subd ,_ix8}, /* A0..A3 */
{_anda ,_ix8}, {_bita ,_ix8}, {_lda ,_ix8}, {_sta ,_ix8}, /* A4..A7 */
{_eora ,_ix8}, {_adca ,_ix8}, {_ora ,_ix8}, {_adda ,_ix8}, /* A8..AB */
{_cpx ,_ix8}, {_jsr ,_ix8}, {_lds ,_ix8}, {_sts ,_ix8}, /* AC..AF */
{_suba ,_ext}, {_cmpa ,_ext}, {_sbca ,_ext}, {_subd ,_ext}, /* B0..B3 */
{_anda ,_ext}, {_bita ,_ext}, {_lda ,_ext}, {_sta ,_ext}, /* B4..B7 */
{_eora ,_ext}, {_adca ,_ext}, {_ora ,_ext}, {_adda ,_ext}, /* B8..BB */
{_cpx ,_ext}, {_jsr ,_ext}, {_lds ,_ext}, {_sts ,_ext}, /* BC..BF */
{_subb ,_imb}, {_cmpb ,_imb}, {_sbcb ,_imb}, {_addd ,_imw}, /* C0..C3 */
{_andb ,_imb}, {_bitb ,_imb}, {_ldb ,_imb}, {_ill ,_nom}, /* C4..C7 */
{_eorb ,_imb}, {_adcb ,_imb}, {_orb ,_imb}, {_addb ,_imb}, /* C8..CB */
{_ldd ,_imw}, {_ill ,_nom}, {_ldx ,_imw}, {_ill ,_nom}, /* CC..CF */
{_subb ,_dir}, {_cmpb ,_dir}, {_sbcb ,_dir}, {_addd ,_dir}, /* D0..D3 */
{_andb ,_dir}, {_bitb ,_dir}, {_ldb ,_dir}, {_stb ,_dir}, /* D4..D7 */
{_eorb ,_dir}, {_adcb ,_dir}, {_orb ,_dir}, {_addb ,_dir}, /* D8..DB */
{_ldd ,_dir}, {_std ,_dir}, {_ldx ,_dir}, {_stx ,_dir}, /* DC..DF */
{_subb ,_ix8}, {_cmpb ,_ix8}, {_sbcb ,_ix8}, {_addd ,_ix8}, /* E0..E3 */
{_andb ,_ix8}, {_bitb ,_ix8}, {_ldb ,_ix8}, {_stb ,_ix8}, /* E4..E7 */
{_eorb ,_ix8}, {_adcb ,_ix8}, {_orb ,_ix8}, {_addb ,_ix8}, /* E8..EB */
{_ldd ,_ix8}, {_std ,_ix8}, {_ldx ,_ix8}, {_stx ,_ix8}, /* EC..EF */
{_subb ,_ext}, {_cmpb ,_ext}, {_sbcb ,_ext}, {_addd ,_ext}, /* F0..F3 */
{_andb ,_ext}, {_bitb ,_ext}, {_ldb ,_ext}, {_stb ,_ext}, /* F4..F7 */
{_eorb ,_ext}, {_adcb ,_ext}, {_orb ,_ext}, {_addb ,_ext}, /* F8..FB */
{_ldd ,_ext}, {_std ,_ext}, {_ldx ,_ext}, {_stx ,_ext}, /* FC..FF */
};
/*****************************************************************************/
/* opcodes : additional opcodes over 6800 */
/*****************************************************************************/
OpCode Dasm6801::opcodes[mnemo6801_count - mnemo6800_count] =
{
{ "ABX", Data }, /* _abx */
{ "ADDD", Data }, /* _addd */
{ "BRN", Code }, /* _brn */
{ "LDD", Data }, /* _ldd */
{ "MUL", Data }, /* _mul */
{ "PULX", Data }, /* _pulx */
{ "PSHX", Data }, /* _pshx */
{ "STD", Data }, /* _std */
{ "SUBD", Data }, /* _subd */
};
/*****************************************************************************/
/* regnames : additional register names over 6800 */
/*****************************************************************************/
const char *Dasm6801::regnames[reg6801_count - reg6800_count] =
{
"D", /* _d */
};
/*****************************************************************************/
/* Dasm6801 : constructor */
/*****************************************************************************/
Dasm6801::Dasm6801(Application *pApp)
: Dasm6800(pApp)
{
codes = m6801_codes;
mnemo.resize(mnemo6801_count); /* set up additional mnemonics */
int i;
for (i = 0; i < mnemo6801_count - mnemo6800_count; i++)
mnemo[mnemo6800_count + i] = opcodes[i];
regname.resize(reg6801_count); /* set up additional register names */
for (i = 0; i < reg6801_count - reg6800_count; i++)
regname[reg6800_count + i] = regnames[i];
}
/*****************************************************************************/
/* ~Dasm6801 : destructor */
/*****************************************************************************/
Dasm6801::~Dasm6801(void)
{
}
/*****************************************************************************/
/* InitParse : initialize parsing */
/*****************************************************************************/
bool Dasm6801::InitParse(int bus)
{
Dasm6800::InitParse(bus); /* let 6800 init go first */
// needs to be done before, since we need to override a vector
if (bus == BusCode)
{
if (bSetSysVec)
{
static const char *vectbl[] =
{
"IRQ_SCI", /* fff0 */
"IRQ_T0F", /* fff2 */
"IRQ_OCF", /* fff4 */
"IRQ_ICF", /* fff6 */
"IRQ_EXT", /* fff8 */
};
for (adr_t addr = 0xfff0; addr <= 0xfff8; addr += 2)
{
if (addr == 0xfff8 && /* override IRQ with IRQ_EXT */
GetLabel(addr) == "IRQ")
{
adr_t tgtaddr = GetUWord(addr);
Label *pLbl = FindLabel(tgtaddr);
if (pLbl && pLbl->GetText() == "vec_IRQ")
RemoveLabel(addr);
}
MemoryType memType = GetMemType(addr);
if (memType != Untyped && /* if system vector loaded */
memType != Const && /* and not defined as constant */
!FindLabel(addr)) /* and no label set in info file */
{
SetMemType(addr, Data); /* that's a data word */
SetCellSize(addr, 2);
/* look whether it points to loaded */
adr_t tgtaddr = GetUWord(addr);
if (GetMemType(tgtaddr) != Untyped)
{ /* if so, */
SetMemType(tgtaddr, Code); /* that's code there */
AddLabel(tgtaddr, Code, /* and it got a predefined label */
sformat("vec_%s", vectbl[(addr - 0xfff0) / 2]),
true);
}
}
}
}
}
return true;
}
/*****************************************************************************/
/* SetConvenience : set convenience mnemonics as appropriate */
/*****************************************************************************/
bool Dasm6801::SetConvenience(uint8_t instpg, uint16_t u2, string &smnemo, adr_t &PC)
{
// PC is on the second byte of u2
// The 6801 has special mnemonics that collide with 6800 convenience!
switch (u2)
{
case 0x4456 : /* LSRA + RORB -> LSRD (0x04!) */
case 0x5849 : /* ASLB + ROLA -> ASLD(/LSLD) (0x05!)*/
return false;
}
return Dasm6800::SetConvenience(instpg, u2, smnemo, PC);
}