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
|
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define OPNAME(opcode) [opcode] = #opcode
#define CPS 0x00
#define ADC 0x01
#define AAB 0x02
#define PHB 0x06
#define PHP 0x08
#define PHA 0x09
#define PHY 0x0A
#define TAY 0x0B
#define PHX 0x0C
#define TAX 0x0D
#define TYX 0x0E
#define JMP 0x10
#define SBC 0x11
#define SAB 0x12
#define PLB 0x16
#define PLP 0x18
#define PLA 0x19
#define PLY 0x1A
#define TYA 0x1B
#define PLX 0x1C
#define TXA 0x1D
#define TXY 0x1E
#define JSR 0x20
#define AND 0x21
#define ABA 0x22
#define TAB 0x26
#define STT 0x28
#define CPY 0x2A
#define CPX 0x2C
#define TSX 0x2E
#define BPO 0x30
#define ORA 0x31
#define OAB 0x32
#define TBA 0x36
#define SEI 0x38
#define INY 0x3A
#define INX 0x3C
#define TXS 0x3E
#define BNG 0x40
#define XOR 0x41
#define XAB 0x42
#define CLI 0x48
#define DEY 0x4A
#define DEX 0x4C
#define BCS 0x50
#define LSL 0x51
#define LLB 0x52
#define SEC 0x58
#define STA 0x5B
#define STY 0x5D
#define STX 0x5E
#define STB 0x5F
#define BCC 0x60
#define LSR 0x61
#define LRB 0x62
#define LDB 0x66
#define CLC 0x68
#define LDA 0x69
#define LDY 0x6A
#define LDX 0x6C
#define BEQ 0x70
#define ROL 0x71
#define RLB 0x72
#define SSP 0x78
#define BNE 0x80
#define ROR 0x81
#define RRB 0x82
#define CSP 0x88
#define BVS 0x90
#define MUL 0x91
#define MAB 0x92
#define SEV 0x98
#define BVC 0xA0
#define DIV 0xA1
#define DAB 0xA2
#define CLV 0xA8
#define RTS 0xB0
#define CMP 0xB1
#define CAB 0xB2
#define ENT 0xB8
#define RTI 0xC0
#define INC 0xC1
#define IAB 0xC2
#define DEC 0xD1
#define DBA 0xD2
#define CPB 0xD6
#define WAI 0xD8
#define JSL 0xE0
#define ASR 0xE1
#define ARB 0xE2
#define NOP 0xE8
#define RTL 0xF0
#define BRK 0xF8
#define C ((uint64_t)1 << 0)
#define Z ((uint64_t)1 << 1)
#define I ((uint64_t)1 << 2)
#define S ((uint64_t)1 << 3)
#define V ((uint64_t)1 << 6)
#define N ((uint64_t)1 << 7)
struct sux;
uint8_t *addr;
uint8_t ibcount;
struct sux {
uint64_t ps;
uint64_t a[8], b[8], y[8], x[8];
uint64_t pc[8];
uint16_t sp[8];
uint16_t stk_st[8];
uint8_t crt;
uint8_t c[8], z[8], i[8], s[8], v[8], n[8];
};
typedef struct {
char mnemonic[4];
uint8_t imm;
uint8_t abs;
uint8_t zm;
uint8_t zmy;
uint8_t zmx;
uint8_t ind;
uint8_t inx;
uint8_t iny;
uint8_t impl;
} opent;
static const char *opname[0x100] = {
[0x00] = "CPS",
[0x01] = "ADC #",
[0x02] = "AAB",
[0x03] = "ADC a",
[0x04] = "JMP (ind)",
[0x05] = "ADC zm",
[0x06] = "PHB",
[0x08] = "PHP",
[0x09] = "PHA",
[0x0A] = "PHY",
[0x0B] = "TAY",
[0x0C] = "PHX",
[0x0D] = "TAX",
[0x0E] = "TYX",
[0x10] = "JMP a",
[0x11] = "SBC #",
[0x12] = "SAB",
[0x13] = "SBC a",
[0x14] = "JMP (ind, x)",
[0x15] = "SBC zm",
[0x16] = "PLB",
[0x18] = "PLP",
[0x19] = "PLA",
[0x1A] = "PLY",
[0x1B] = "TYA",
[0x1C] = "PLX",
[0x1D] = "TXA",
[0x1E] = "TXY",
[0x20] = "JSR",
[0x21] = "AND #",
[0x22] = "ABA",
[0x23] = "AND a",
[0x24] = "JMP (ind), y",
[0x25] = "AND zm",
[0x26] = "TAB",
[0x28] = "STT",
[0x2A] = "CPY #",
[0x2B] = "CPY a",
[0x2C] = "CPX #",
[0x2D] = "CPX a",
[0x2E] = "TSX",
[0x30] = "BPO a",
[0x31] = "ORA #",
[0x32] = "OAB",
[0x33] = "ORA a",
[0x34] = "JSR (ind)",
[0x35] = "ORA zm",
[0x36] = "TBA",
[0x38] = "SEI",
[0x3A] = "INY",
[0x3B] = "CPY zm",
[0x3C] = "INX",
[0x3D] = "CPX zm",
[0x3E] = "TXS",
[0x40] = "BNG a",
[0x41] = "XOR #",
[0x42] = "XAB",
[0x43] = "XOR a",
[0x44] = "JSR (ind, x)",
[0x45] = "XOR zm",
[0x48] = "CLI",
[0x4A] = "DEY",
[0x4C] = "DEX",
[0x50] = "BCS a",
[0x51] = "LSL #",
[0x52] = "LLB",
[0x53] = "LSL a",
[0x54] = "JSR (ind), y",
[0x55] = "LSL zm",
[0x56] = "LDB a",
[0x58] = "SEC",
[0x59] = "LDA a",
[0x5A] = "LDY a",
[0x5B] = "STA a",
[0x5C] = "LDX a",
[0x5D] = "STY a",
[0x5E] = "STX a",
[0x5F] = "STB a",
[0x60] = "BCC a",
[0x61] = "LSR #",
[0x62] = "LRB",
[0x63] = "LSR a",
[0x64] = "BPO zm",
[0x65] = "LSR zm",
[0x66] = "LDB #",
[0x68] = "CLC",
[0x69] = "LDA #",
[0x6A] = "LDY #",
[0x6C] = "LDX #",
[0x70] = "BEQ a",
[0x71] = "ROL #",
[0x72] = "RLB",
[0x73] = "ROL a",
[0x74] = "BNG zm",
[0x75] = "ROL zm",
[0x76] = "LDB zm",
[0x78] = "SSP",
[0x79] = "LDA zm",
[0x7A] = "LDY zm",
[0x7B] = "STA zm",
[0x7C] = "LDX zm",
[0x7D] = "STY zm",
[0x7E] = "STX zm",
[0x7F] = "STB zm",
[0x80] = "BNE a",
[0x81] = "ROR #",
[0x82] = "RRB",
[0x83] = "ROR a",
[0x84] = "BCS zm",
[0x85] = "ROR zm",
[0x86] = "LDB zm, x",
[0x88] = "CSP",
[0x89] = "LDA zm, x",
[0x8A] = "LDY zm, x",
[0x8B] = "STA zm, x",
[0x8D] = "STY zm, x",
[0x8F] = "STB zm, x",
[0x90] = "BVS a",
[0x91] = "MUL #",
[0x92] = "MAB",
[0x93] = "MUL a",
[0x94] = "BCC zm",
[0x95] = "MUL zm",
[0x96] = "LDB zm, y",
[0x98] = "SEV",
[0x99] = "LDA zm, y",
[0x9B] = "STA zm, y",
[0x9C] = "LDX zm, y",
[0x9E] = "STX zm, y",
[0x9F] = "STB zm, y",
[0xA0] = "BVC a",
[0xA1] = "DIV #",
[0xA2] = "DAB",
[0xA3] = "DIV a",
[0xA4] = "BEQ zm",
[0xA5] = "DIV zm",
[0xA6] = "LDB (ind)",
[0xA8] = "CLV",
[0xA9] = "LDA (ind)",
[0xAA] = "LDY (ind)",
[0xAB] = "STA (ind)",
[0xAC] = "LDX (ind)",
[0xAD] = "STY (ind)",
[0xAE] = "STX (ind)",
[0xAF] = "STB (ind)",
[0xB0] = "RTS",
[0xB1] = "CMP #",
[0xB2] = "CAB",
[0xB3] = "CMP a",
[0xB4] = "BNE zm",
[0xB5] = "CMP zm",
[0xB6] = "LDB (ind, x)",
[0xB8] = "ENT",
[0xB9] = "LDA (ind, x)",
[0xBA] = "LDY (ind, x)",
[0xBB] = "STA (ind, x)",
[0xBD] = "STY (ind, x)",
[0xBF] = "STB (ind, x)",
[0xC0] = "RTI",
[0xC1] = "INC A",
[0xC2] = "IAB",
[0xC3] = "INC a",
[0xC4] = "BVS zm",
[0xC5] = "INC zm",
[0xC6] = "LDB (ind), y",
[0xC9] = "LDA (ind), y",
[0xCB] = "STA (ind), y",
[0xCC] = "LDX (ind), y",
[0xCE] = "STX (ind), y",
[0xCF] = "STB (ind), y",
[0xD0] = "JMP zm",
[0xD1] = "DEC A",
[0xD2] = "DBA",
[0xD3] = "DEC a",
[0xD4] = "BVC zm",
[0xD5] = "DEC zm",
[0xD6] = "CPB #",
[0xD8] = "WAI",
[0xDF] = "CPB (ind)",
[0xE0] = "JSL",
[0xE1] = "ASR #",
[0xE2] = "ARB",
[0xE3] = "ASR a",
[0xE5] = "ASR zm",
[0xE6] = "CPB a",
[0xE8] = "NOP",
[0xE9] = "CMP (ind)",
[0xEA] = "CPY (ind)",
[0xEB] = "CMP (ind, x)",
[0xEC] = "CPX (ind)",
[0xED] = "CMP (ind), y",
[0xEF] = "CPB (ind, x)",
[0xF0] = "RTL",
[0xF6] = "CPB zm",
[0xF8] = "BRK",
[0xFA] = "CPY (ind, x)",
[0xFC] = "CPX (ind), y",
[0xFF] = "CPB (ind), y"
};
extern int asmmon();
extern void adc(struct sux *cpu, uint64_t adr, uint8_t thread, uint8_t regsize);
extern void sbc(struct sux *cpu, uint64_t adr, uint8_t thread, uint8_t regsize);
extern void mul(struct sux *cpu, uint64_t adr, uint8_t thread, uint8_t regsize);
extern void divd(struct sux *cpu, uint64_t adr, uint8_t thread, uint8_t regsize);
extern uint64_t and(struct sux *cpu, uint64_t value, uint8_t thread);
extern void and_addr(struct sux *cpu, uint64_t* const reg, uint64_t adr, uint8_t thread, uint8_t regsize);
extern uint64_t or(struct sux *cpu, uint64_t value, uint8_t thread);
extern void or_addr(struct sux *cpu, uint64_t* const reg, uint64_t adr, uint8_t thread, uint8_t regsize);
extern uint64_t xor(struct sux *cpu, uint64_t value, uint8_t thread);
extern void xor_addr(struct sux *cpu, uint64_t* const reg, uint64_t adr, uint8_t thread, uint8_t regsize);
extern void rol(struct sux *cpu, uint64_t adr, uint8_t thread);
extern void ror(struct sux *cpu, uint64_t adr, uint8_t thread);
extern void lsl(struct sux *cpu, uint64_t adr, uint8_t thread);
extern void lsr(struct sux *cpu, uint64_t adr, uint8_t thread);
extern void inc(struct sux *cpu, uint64_t *reg, uint8_t thread);
extern void inc_addr(struct sux *cpu, uint64_t adr, uint8_t thread);
extern void dec(struct sux *cpu, uint64_t *reg, uint8_t thread);
extern void dec_addr(struct sux *cpu, uint64_t adr, uint8_t thread);
extern void stt(struct sux *cpu, uint8_t value);
extern void ent(struct sux *cpu, uint8_t value);
extern void ld(struct sux *cpu, uint64_t *reg, uint64_t adr, uint8_t thread, uint8_t regsize);
extern void st(struct sux *cpu, uint64_t *reg, uint64_t adr, uint8_t thread, uint8_t regsize);
extern void push(struct sux *cpu, uint8_t value);
extern uint8_t pull(struct sux *cpu);
extern void cmp_addr(struct sux *cpu, uint64_t reg, uint64_t adr, uint8_t thread, uint8_t regsize);
extern void cmp(struct sux *cpu, uint64_t reg1, uint64_t reg2, uint8_t thread);
extern void bfs(struct sux *cpu, uint8_t flag, uint64_t adr, uint8_t thread);
extern void bfc(struct sux *cpu, uint8_t flag, uint64_t adr, uint8_t thread);
extern void setps(struct sux *cpu, uint8_t thread);
extern uint64_t immaddr(struct sux *cpu, uint8_t thread, uint8_t size);
extern uint64_t absaddr(struct sux *cpu, uint8_t thread);
extern uint32_t zeromtx(struct sux *cpu, uint8_t thread);
extern uint32_t zeromx(struct sux *cpu, uint8_t thread);
extern uint32_t zeromy(struct sux *cpu, uint8_t thread);
|