forked from Arakula/dasmfw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDasm6500.h
391 lines (339 loc) · 12.8 KB
/
Dasm6500.h
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
/***************************************************************************
* 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. *
***************************************************************************/
/*****************************************************************************/
/* Dasm650X.h : definition of the Dasm650X class */
/*****************************************************************************/
#ifndef __Dasm6500_h_defined__
#define __Dasm6500_h_defined__
#include "Disassembler.h"
/*****************************************************************************/
/* CMatrixEntry : little structure for the code matrix entries */
/*****************************************************************************/
struct CMatrixEntry
{
uint16_t mne; /* index of mnemonic */
uint8_t adrmode; /* addressing mode */
};
/*****************************************************************************/
/* Dasm650X : base class for a MOS Technology 650x processor */
/*****************************************************************************/
class Dasm650X :
public Disassembler
{
public:
Dasm650X(Application *pApp);
virtual ~Dasm650X(void);
// Overrides
public:
// return processor long name
virtual string GetName() { return "MOS 650x"; }
// return whether big- or little-endian
virtual Endian GetEndianness() { return LittleEndian; }
// return bus width
virtual int GetBusWidth(int bus = BusCode) { (void)bus; return 16; }
// return code bits
virtual int GetCodeBits() { return 16; }
// return code pointer size in bytes
virtual int GetCodePtrSize() { return 2; }
// return highest possible code address
virtual cadr_t GetHighestCodeAddr() { return 0xffff; }
// return data bits
virtual int GetDataBits() { return 8; }
// return data pointer size in bytes
virtual int GetDataPtrSize() { return 2; }
// return highest possible data address
virtual dadr_t GetHighestDataAddr() { return 0xffff; }
// Options handler
protected:
int Set6500Option(string name, string value);
string Get6500Option(string name);
protected:
// parse data area for labels
virtual adr_t ParseData(adr_t addr, int bus = BusCode);
// parse instruction at given memory address for labels
virtual adr_t ParseCode(adr_t addr, int bus = BusCode);
// pass back correct mnemonic and parameters for a label
virtual bool DisassembleLabel(Label *label, string &slabel, string &smnemo, string &sparm, int bus = BusCode);
// pass back correct mnemonic and parameters for a DefLabel
virtual bool DisassembleDefLabel(DefLabel *label, string &slabel, string &smnemo, string &sparm, int bus = BusCode);
// disassemble data area at given memory address
virtual adr_t DisassembleData(adr_t addr, adr_t end, uint32_t flags, string &smnemo, string &sparm, int maxparmlen, int bus = BusCode);
// disassemble instruction at given memory address
virtual adr_t DisassembleCode(adr_t addr, string &smnemo, string &sparm, int bus = BusCode);
// Get Flags for disassembly of data areas
virtual uint32_t GetDisassemblyFlags(adr_t addr, int bus = BusCode);
// Get/Set additional cell information
virtual adr_t GetDirectPage(adr_t addr, int bus = BusCode)
{ (void)addr; (void)bus; return 0; }
virtual void SetDirectPage(adr_t addr, adr_t dp, int bus = BusCode)
{ (void)addr; (void)dp; (void)bus; }
public:
// Initialize parsing
virtual bool InitParse(int bus = BusCode);
// pass back disassembler-specific state changes before/after a disassembly line
virtual bool DisassembleChanges(adr_t addr, adr_t prevaddr, adr_t prevsz, bool bAfterLine, vector<LineChange> &changes, int bus = BusCode);
protected:
virtual bool String2Number(string s, adr_t &value);
virtual string Number2String(adr_t value, int nDigits, adr_t addr, int bus = BusCode);
virtual string Address2String(adr_t addr, int bus = BusCode)
{ (void)bus; return sformat("$%04X", addr); }
virtual adr_t FetchInstructionDetails(adr_t PC, uint8_t &instpg, uint8_t &instb, uint8_t &mode, int &mnemoIndex);
void AddForced(string &smnemo, string &sparm, bool bAbsolute = true);
protected:
// 6500 addressing modes
enum AddrMode6500
{
_nom, /* no mode */
_imp, /* inherent/implied (no arguments) */
_acc, /* accumulator */
_imm, /* # immediate */
_abs, /* absolute */
_abx, /* absolute,X */
_aby, /* absolute,Y */
_zpg, /* zero page */
_zpx, /* zero page,X */
_zpy, /* zero page,Y */
_ind, /* indirect */
_idx, /* (ind,X) */
_idy, /* (ind),Y */
_rel, /* relative */
addrmodes6500_count,
_nof = 0x40 /* no forced addressing (JSR) */
};
// 6500 mnemonics
enum Mnemonics6500
{
_equ, /* start with pseudo-ops */
_rmb,
_fcb,
_fdb,
_fcc,
_org,
_phase,
_dephase,
_end,
_ill, /* illegal */
_adc,
_and,
_asl,
_bcc,
_bcs,
_beq,
_bit,
_bmi,
_bne,
_bpl,
_brk,
_bvc,
_bvs,
_clc,
_cld,
_cli,
_clv,
_cmp,
_cpx,
_cpy,
_dec,
_dex,
_dey,
_eor,
_inc,
_inx,
_iny,
_jmp,
_jsr,
_lda,
_ldx,
_ldy,
_lsr,
_nop,
_ora,
_pha,
_php,
_pla,
_plp,
_rol,
_ror,
_rti,
_rts,
_sbc,
_sec,
_sed,
_sei,
_sta,
_stx,
_sty,
_tax,
_tay,
_tsx,
_txa,
_txs,
_tya,
mnemo6500_count
};
enum Reg6500
{
_a,
_x,
_y,
_p,
_pc,
reg6500_count
};
static CMatrixEntry m6500_codes[256];
CMatrixEntry *codes;
static OpCode opcodes[mnemo6500_count];
static const char *regnames[reg6500_count];
adr_t dirpage;
bool useConvenience;
bool useFCC;
bool closeCC;
bool forceExtendedAddr;
bool forceDirectAddr;
bool useDPLabels;
bool accparm;
string textAbsAddr, textZpgAddr;
};
/*****************************************************************************/
/* Dasm6501 : class for a MOS Technology 6501/2 processor */
/*****************************************************************************/
class Dasm6501 :
public Dasm650X
{
public:
Dasm6501(Application *pApp);
// Options handler
protected:
int Set6501Option(string name, string value);
string Get6501Option(string name);
protected:
virtual adr_t FetchInstructionDetails(adr_t PC, uint8_t &instpg, uint8_t &instb, uint8_t &mode, int &mnemoIndex);
protected:
// 6501 addressing modes
enum AddrMode6501
{
_und = 0x80 /* additional flag for "undefined" */
};
// 6501 additional mnemonics
enum Mnemonics6501
{
_lax = mnemo6500_count, // A,X:={adr}
_dcp, // {adr}:={adr}-1 A-{adr}
_isc, // {adr}:={adr}+1 A:=A-{adr}
_rla, // {adr}:={adr}rol A:=A and {adr}
_rra, // {adr}:={adr}ror A:=A adc {adr}
_sax, // {adr}:=A&X
_slo, // {adr}:={adr}*2 A:=A or {adr}
_sre, // {adr}:={adr}/2 A:=A exor {adr}
_anc, // A:=A&#{imm}
_arr, // A:=(A&#{imm})/2
_alr, // A:=(A&#{imm})/2
_axs, // X:=A&X-#{imm}
_xaa, // A:=X&#{imm}
_tas, // S:=A&X {adr}:=S&H
_ahx, // {adr}:=A&X&H
_las, // A,X,S:={adr}&S
_shx, // {adr}:=X&H
_shy, // {adr}:=Y&H
mnemo6501_count
};
static CMatrixEntry m6501_codes[256];
static OpCode m6501_opcodes[mnemo6501_count - mnemo6500_count];
bool useUndefined;
};
/*****************************************************************************/
/* Dasm6503 : class for a MOS Technology 6503, 6505, 6506 processors */
/*****************************************************************************/
class Dasm6503 :
public Dasm6501
{
public:
Dasm6503(Application *pApp);
// Overrides
public:
// return bus width
virtual int GetBusWidth(int bus = BusCode) { (void)bus; return 12; }
// return highest possible code address
virtual cadr_t GetHighestCodeAddr() { return 0x0fff; }
// return highest possible data address
virtual dadr_t GetHighestDataAddr() { return 0x0fff; }
};
/*****************************************************************************/
/* Dasm6504 : class for a MOS Technology 6504, 6507 processors */
/*****************************************************************************/
class Dasm6504 :
public Dasm6501
{
public:
Dasm6504(Application *pApp);
// Overrides
public:
// return bus width
virtual int GetBusWidth(int bus = BusCode) { (void)bus; return 13; }
// return highest possible code address
virtual cadr_t GetHighestCodeAddr() { return 0x1fff; }
// return highest possible data address
virtual dadr_t GetHighestDataAddr() { return 0x1fff; }
};
/*****************************************************************************/
/* Dasm65C02 : class for a 65C02 processor */
/*****************************************************************************/
class Dasm65C02 :
public Dasm650X
{
public:
Dasm65C02(Application *pApp);
// return processor long name
virtual string GetName() { return "MOS 65C02"; }
protected:
// parse instruction at given memory address for labels
virtual adr_t ParseCode(adr_t addr, int bus = BusCode);
// disassemble instruction at given memory address
virtual adr_t DisassembleCode(adr_t addr, string &smnemo, string &sparm, int bus = BusCode);
protected:
// 65C02 addressing modes
enum AddrMode65C02
{
_zpi = addrmodes6500_count, /* zero-page indexed */
_bbt, /* branch on bit (Rockwell/WDC) */
_zpb, /* zero-page bit (Rockwell/WDC) */
};
// 65C02 additional mnemonics
enum Mnemonics65C02
{
_bra = mnemo6500_count,
_phx,
_phy,
_plx,
_ply,
_stz,
_trb,
_tsb,
_bbr, /* Rockwell / WDC */
_bbs,
_rmb,
_smb,
_stp,
_wai,
mnemo65C02_count
};
static CMatrixEntry m65c02_codes[256];
static OpCode m65c02_opcodes[mnemo65C02_count - mnemo6500_count];
bool useUndefined;
};
#endif // __Dasm6500_h_defined__