2 Skelton for retropc emulator
5 Author : Takeda.Toshiya
9 Notes from K.Ohta <whatisthis.sowhat _at_ gmail.com> at Jan 16, 2015:
10 All of undocumented instructions (i.e. ngc, flag16) of MC6809(not HD6309) are written by me.
11 These behaviors of undocumented insns are refered from "vm/cpu_x86.asm" (ia32 assembly codefor nasm) within XM7
12 written by Ryu Takegami , and older article wrote in magazine, "I/O" at 1985.
13 But, these C implements are written from scratch by me , and I tested many years at XM7/SDL.
14 Perhaps, these insns. are not implement MAME/MESS yet.
17 // Fixed IRQ/FIRQ by Mr.Sasaji at 2011.06.17
22 #include "mc6809_consts.h"
28 void MC6809::initialize()
30 MC6809_BASE::initialize();
36 d_debugger->set_context_mem(d_mem);
40 void MC6809::run_one_opecode()
43 bool now_debugging = d_debugger->now_debugging;
45 d_debugger->check_break_points(PC);
46 if(d_debugger->now_suspended) {
48 d_debugger->now_waiting = true;
49 while(d_debugger->now_debugging && d_debugger->now_suspended) {
52 d_debugger->now_waiting = false;
54 if(d_debugger->now_debugging) {
57 now_debugging = false;
60 d_debugger->add_cpu_trace(PC);
61 int first_icount = icount;
63 uint8_t ireg = ROP(PCD);
65 icount -= cycles1[ireg];
66 icount -= extra_icount;
69 total_icount += first_icount - icount;
72 if(!d_debugger->now_going) {
73 d_debugger->now_suspended = true;
78 d_debugger->add_cpu_trace(PC);
79 int first_icount = icount;
81 uint8_t ireg = ROP(PCD);
83 icount -= cycles1[ireg];
84 icount -= extra_icount;
87 total_icount += first_icount - icount;
91 uint8_t ireg = ROP(PCD);
93 icount -= cycles1[ireg];
94 icount -= extra_icount;
106 /*****************************************************************************
108 6809dasm.c - a 6809 opcode disassembler
110 Copyright Sean Riddle
112 Thanks to Franklin Bowen for bug fixes, ideas
114 Freely distributable on any medium given all copyrights are retained
115 by the author and no charge greater than $7.00 is made for obtaining
118 Please send all bug reports, update ideas and data files to:
121 *****************************************************************************/
125 uint8_t opcode; // 8-bit opcode value
126 uint8_t length; // Opcode length in bytes
127 _TCHAR name[6]; // Opcode name
128 uint8_t mode; // Addressing mode
129 // unsigned flags; // Disassembly flags
132 enum m6809_addressing_modes
137 REL, // Relative (8 bit)
138 LREL, // Long relative (16 bit)
141 IMM_RR, // Register-to-register
142 PG1, // Switch to page 1 opcodes
143 PG2 // Switch to page 2 opcodes
146 // Page 0 opcodes (single byte)
147 static const opcodeinfo m6809_pg0opcodes[] =
149 { 0x00, 2, _T("NEG"), DIR },
150 { 0x01, 2, _T("NEG"), DIR },
151 { 0x02, 2, _T("NGC"), DIR },
152 { 0x03, 2, _T("COM"), DIR },
153 { 0x04, 2, _T("LSR"), DIR },
154 { 0x05, 2, _T("LSR"), DIR },
155 { 0x06, 2, _T("ROR"), DIR },
156 { 0x07, 2, _T("ASR"), DIR },
157 { 0x08, 2, _T("ASL"), DIR },
158 { 0x09, 2, _T("ROL"), DIR },
159 { 0x0A, 2, _T("DEC"), DIR },
160 { 0x0B, 2, _T("DCC"), DIR },
161 { 0x0C, 2, _T("INC"), DIR },
162 { 0x0D, 2, _T("TST"), DIR },
163 { 0x0E, 2, _T("JMP"), DIR },
164 { 0x0F, 2, _T("CLR"), DIR },
166 { 0x10, 1, _T("page1"), PG1 },
167 { 0x11, 1, _T("page2"), PG2 },
168 { 0x12, 1, _T("NOP"), INH },
169 { 0x13, 1, _T("SYNC"), INH },
170 { 0x14, 1, _T("HALT"), INH },
171 { 0x15, 1, _T("HALT"), INH },
172 { 0x16, 3, _T("LBRA"), LREL },
173 { 0x17, 3, _T("LBSR"), LREL },
174 { 0x18, 1, _T("ASLCC"), INH },
175 { 0x19, 1, _T("DAA"), INH },
176 { 0x1A, 2, _T("ORCC"), IMM },
177 { 0x1B, 1, _T("NOP"), INH },
178 { 0x1C, 2, _T("ANDCC"), IMM },
179 { 0x1D, 1, _T("SEX"), INH },
180 { 0x1E, 2, _T("EXG"), IMM_RR },
181 { 0x1F, 2, _T("TFR"), IMM_RR },
183 { 0x20, 2, _T("BRA"), REL },
184 { 0x21, 2, _T("BRN"), REL },
185 { 0x22, 2, _T("BHI"), REL },
186 { 0x23, 2, _T("BLS"), REL },
187 { 0x24, 2, _T("BCC"), REL },
188 { 0x25, 2, _T("BCS"), REL },
189 { 0x26, 2, _T("BNE"), REL },
190 { 0x27, 2, _T("BEQ"), REL },
191 { 0x28, 2, _T("BVC"), REL },
192 { 0x29, 2, _T("BVS"), REL },
193 { 0x2A, 2, _T("BPL"), REL },
194 { 0x2B, 2, _T("BMI"), REL },
195 { 0x2C, 2, _T("BGE"), REL },
196 { 0x2D, 2, _T("BLT"), REL },
197 { 0x2E, 2, _T("BGT"), REL },
198 { 0x2F, 2, _T("BLE"), REL },
200 { 0x30, 2, _T("LEAX"), IND },
201 { 0x31, 2, _T("LEAY"), IND },
202 { 0x32, 2, _T("LEAS"), IND },
203 { 0x33, 2, _T("LEAU"), IND },
204 { 0x34, 2, _T("PSHS"), INH },
205 { 0x35, 2, _T("PULS"), INH },
206 { 0x36, 2, _T("PSHU"), INH },
207 { 0x37, 2, _T("PULU"), INH },
208 { 0x38, 2, _T("ANDCC"), IMM },
209 { 0x39, 1, _T("RTS"), INH },
210 { 0x3A, 1, _T("ABX"), INH },
211 { 0x3B, 1, _T("RTI"), INH },
212 { 0x3C, 2, _T("CWAI"), IMM },
213 { 0x3D, 1, _T("MUL"), INH },
214 { 0x3F, 1, _T("SWI"), INH },
216 { 0x40, 1, _T("NEGA"), INH },
217 { 0x41, 1, _T("NEGA"), INH },
218 { 0x42, 1, _T("NGGA"), INH },
219 { 0x43, 1, _T("COMA"), INH },
220 { 0x44, 1, _T("LSRA"), INH },
221 { 0x45, 1, _T("LSRA"), INH },
222 { 0x46, 1, _T("RORA"), INH },
223 { 0x47, 1, _T("ASRA"), INH },
224 { 0x48, 1, _T("ASLA"), INH },
225 { 0x49, 1, _T("ROLA"), INH },
226 { 0x4A, 1, _T("DECA"), INH },
227 { 0x4B, 1, _T("DCCA"), INH },
228 { 0x4C, 1, _T("INCA"), INH },
229 { 0x4D, 1, _T("TSTA"), INH },
230 { 0x4E, 1, _T("CLCA"), INH },
231 { 0x4F, 1, _T("CLRA"), INH },
233 { 0x50, 1, _T("NEGB"), INH },
234 { 0x51, 1, _T("NEGB"), INH },
235 { 0x52, 1, _T("NGGB"), INH },
236 { 0x53, 1, _T("COMB"), INH },
237 { 0x54, 1, _T("LSRB"), INH },
238 { 0x55, 1, _T("LSRB"), INH },
239 { 0x56, 1, _T("RORB"), INH },
240 { 0x57, 1, _T("ASRB"), INH },
241 { 0x58, 1, _T("ASLB"), INH },
242 { 0x59, 1, _T("ROLB"), INH },
243 { 0x5A, 1, _T("DECB"), INH },
244 { 0x5B, 1, _T("DCCB"), INH },
245 { 0x5C, 1, _T("INCB"), INH },
246 { 0x5D, 1, _T("TSTB"), INH },
247 { 0x5E, 1, _T("CLCB"), INH },
248 { 0x5F, 1, _T("CLRB"), INH },
250 { 0x60, 2, _T("NEG"), IND },
251 { 0x61, 2, _T("NEG"), IND },
252 { 0x62, 2, _T("NGC"), IND },
253 { 0x63, 2, _T("COM"), IND },
254 { 0x64, 2, _T("LSR"), IND },
255 { 0x65, 2, _T("LSR"), IND },
256 { 0x66, 2, _T("ROR"), IND },
257 { 0x67, 2, _T("ASR"), IND },
258 { 0x68, 2, _T("ASL"), IND },
259 { 0x69, 2, _T("ROL"), IND },
260 { 0x6A, 2, _T("DEC"), IND },
261 { 0x6B, 2, _T("DCC"), IND },
262 { 0x6C, 2, _T("INC"), IND },
263 { 0x6D, 2, _T("TST"), IND },
264 { 0x6E, 2, _T("JMP"), IND },
265 { 0x6F, 2, _T("CLR"), IND },
267 { 0x70, 3, _T("NEG"), EXT },
268 { 0x71, 3, _T("NEG"), EXT },
269 { 0x72, 3, _T("NGC"), EXT },
270 { 0x73, 3, _T("COM"), EXT },
271 { 0x74, 3, _T("LSR"), EXT },
272 { 0x75, 3, _T("LSR"), EXT },
273 { 0x76, 3, _T("ROR"), EXT },
274 { 0x77, 3, _T("ASR"), EXT },
275 { 0x78, 3, _T("ASL"), EXT },
276 { 0x79, 3, _T("ROL"), EXT },
277 { 0x7A, 3, _T("DEC"), EXT },
278 { 0x7B, 3, _T("DCC"), EXT },
279 { 0x7C, 3, _T("INC"), EXT },
280 { 0x7D, 3, _T("TST"), EXT },
281 { 0x7E, 3, _T("JMP"), EXT },
282 { 0x7F, 3, _T("CLR"), EXT },
284 { 0x80, 2, _T("SUBA"), IMM },
285 { 0x81, 2, _T("CMPA"), IMM },
286 { 0x82, 2, _T("SBCA"), IMM },
287 { 0x83, 3, _T("SUBD"), IMM },
288 { 0x84, 2, _T("ANDA"), IMM },
289 { 0x85, 2, _T("BITA"), IMM },
290 { 0x86, 2, _T("LDA"), IMM },
291 { 0x87, 2, _T("FLAG"), IMM },
292 { 0x88, 2, _T("EORA"), IMM },
293 { 0x89, 2, _T("ADCA"), IMM },
294 { 0x8A, 2, _T("ORA"), IMM },
295 { 0x8B, 2, _T("ADDA"), IMM },
296 { 0x8C, 3, _T("CMPX"), IMM },
297 { 0x8D, 2, _T("BSR"), REL },
298 { 0x8E, 3, _T("LDX"), IMM },
299 { 0x8F, 3, _T("FLAG"), IMM },
301 { 0x90, 2, _T("SUBA"), DIR },
302 { 0x91, 2, _T("CMPA"), DIR },
303 { 0x92, 2, _T("SBCA"), DIR },
304 { 0x93, 2, _T("SUBD"), DIR },
305 { 0x94, 2, _T("ANDA"), DIR },
306 { 0x95, 2, _T("BITA"), DIR },
307 { 0x96, 2, _T("LDA"), DIR },
308 { 0x97, 2, _T("STA"), DIR },
309 { 0x98, 2, _T("EORA"), DIR },
310 { 0x99, 2, _T("ADCA"), DIR },
311 { 0x9A, 2, _T("ORA"), DIR },
312 { 0x9B, 2, _T("ADDA"), DIR },
313 { 0x9C, 2, _T("CMPX"), DIR },
314 { 0x9D, 2, _T("JSR"), DIR },
315 { 0x9E, 2, _T("LDX"), DIR },
316 { 0x9F, 2, _T("STX"), DIR },
318 { 0xA0, 2, _T("SUBA"), IND },
319 { 0xA1, 2, _T("CMPA"), IND },
320 { 0xA2, 2, _T("SBCA"), IND },
321 { 0xA3, 2, _T("SUBD"), IND },
322 { 0xA4, 2, _T("ANDA"), IND },
323 { 0xA5, 2, _T("BITA"), IND },
324 { 0xA6, 2, _T("LDA"), IND },
325 { 0xA7, 2, _T("STA"), IND },
326 { 0xA8, 2, _T("EORA"), IND },
327 { 0xA9, 2, _T("ADCA"), IND },
328 { 0xAA, 2, _T("ORA"), IND },
329 { 0xAB, 2, _T("ADDA"), IND },
330 { 0xAC, 2, _T("CMPX"), IND },
331 { 0xAD, 2, _T("JSR"), IND },
332 { 0xAE, 2, _T("LDX"), IND },
333 { 0xAF, 2, _T("STX"), IND },
335 { 0xB0, 3, _T("SUBA"), EXT },
336 { 0xB1, 3, _T("CMPA"), EXT },
337 { 0xB2, 3, _T("SBCA"), EXT },
338 { 0xB3, 3, _T("SUBD"), EXT },
339 { 0xB4, 3, _T("ANDA"), EXT },
340 { 0xB5, 3, _T("BITA"), EXT },
341 { 0xB6, 3, _T("LDA"), EXT },
342 { 0xB7, 3, _T("STA"), EXT },
343 { 0xB8, 3, _T("EORA"), EXT },
344 { 0xB9, 3, _T("ADCA"), EXT },
345 { 0xBA, 3, _T("ORA"), EXT },
346 { 0xBB, 3, _T("ADDA"), EXT },
347 { 0xBC, 3, _T("CMPX"), EXT },
348 { 0xBD, 3, _T("JSR"), EXT },
349 { 0xBE, 3, _T("LDX"), EXT },
350 { 0xBF, 3, _T("STX"), EXT },
352 { 0xC0, 2, _T("SUBB"), IMM },
353 { 0xC1, 2, _T("CMPB"), IMM },
354 { 0xC2, 2, _T("SBCB"), IMM },
355 { 0xC3, 3, _T("ADDD"), IMM },
356 { 0xC4, 2, _T("ANDB"), IMM },
357 { 0xC5, 2, _T("BITB"), IMM },
358 { 0xC6, 2, _T("LDB"), IMM },
359 { 0xC7, 2, _T("FLAG"), IMM },
360 { 0xC8, 2, _T("EORB"), IMM },
361 { 0xC9, 2, _T("ADCB"), IMM },
362 { 0xCA, 2, _T("ORB"), IMM },
363 { 0xCB, 2, _T("ADDB"), IMM },
364 { 0xCC, 3, _T("LDD"), IMM },
365 { 0xCD, 1, _T("HALT"), INH },
366 { 0xCE, 3, _T("LDU"), IMM },
367 { 0xCF, 3, _T("FLAG"), IMM },
369 { 0xD0, 2, _T("SUBB"), DIR },
370 { 0xD1, 2, _T("CMPB"), DIR },
371 { 0xD2, 2, _T("SBCB"), DIR },
372 { 0xD3, 2, _T("ADDD"), DIR },
373 { 0xD4, 2, _T("ANDB"), DIR },
374 { 0xD5, 2, _T("BITB"), DIR },
375 { 0xD6, 2, _T("LDB"), DIR },
376 { 0xD7, 2, _T("STB"), DIR },
377 { 0xD8, 2, _T("EORB"), DIR },
378 { 0xD9, 2, _T("ADCB"), DIR },
379 { 0xDA, 2, _T("ORB"), DIR },
380 { 0xDB, 2, _T("ADDB"), DIR },
381 { 0xDC, 2, _T("LDD"), DIR },
382 { 0xDD, 2, _T("STD"), DIR },
383 { 0xDE, 2, _T("LDU"), DIR },
384 { 0xDF, 2, _T("STU"), DIR },
386 { 0xE0, 2, _T("SUBB"), IND },
387 { 0xE1, 2, _T("CMPB"), IND },
388 { 0xE2, 2, _T("SBCB"), IND },
389 { 0xE3, 2, _T("ADDD"), IND },
390 { 0xE4, 2, _T("ANDB"), IND },
391 { 0xE5, 2, _T("BITB"), IND },
392 { 0xE6, 2, _T("LDB"), IND },
393 { 0xE7, 2, _T("STB"), IND },
394 { 0xE8, 2, _T("EORB"), IND },
395 { 0xE9, 2, _T("ADCB"), IND },
396 { 0xEA, 2, _T("ORB"), IND },
397 { 0xEB, 2, _T("ADDB"), IND },
398 { 0xEC, 2, _T("LDD"), IND },
399 { 0xED, 2, _T("STD"), IND },
400 { 0xEE, 2, _T("LDU"), IND },
401 { 0xEF, 2, _T("STU"), IND },
403 { 0xF0, 3, _T("SUBB"), EXT },
404 { 0xF1, 3, _T("CMPB"), EXT },
405 { 0xF2, 3, _T("SBCB"), EXT },
406 { 0xF3, 3, _T("ADDD"), EXT },
407 { 0xF4, 3, _T("ANDB"), EXT },
408 { 0xF5, 3, _T("BITB"), EXT },
409 { 0xF6, 3, _T("LDB"), EXT },
410 { 0xF7, 3, _T("STB"), EXT },
411 { 0xF8, 3, _T("EORB"), EXT },
412 { 0xF9, 3, _T("ADCB"), EXT },
413 { 0xFA, 3, _T("ORB"), EXT },
414 { 0xFB, 3, _T("ADDB"), EXT },
415 { 0xFC, 3, _T("LDD"), EXT },
416 { 0xFD, 3, _T("STD"), EXT },
417 { 0xFE, 3, _T("LDU"), EXT },
418 { 0xFF, 3, _T("STU"), EXT }
421 // Page 1 opcodes (0x10 0x..)
422 static const opcodeinfo m6809_pg1opcodes[] =
424 { 0x20, 4, _T("LBRA"), LREL },
425 { 0x21, 4, _T("LBRN"), LREL },
426 { 0x22, 4, _T("LBHI"), LREL },
427 { 0x23, 4, _T("LBLS"), LREL },
428 { 0x24, 4, _T("LBCC"), LREL },
429 { 0x25, 4, _T("LBCS"), LREL },
430 { 0x26, 4, _T("LBNE"), LREL },
431 { 0x27, 4, _T("LBEQ"), LREL },
432 { 0x28, 4, _T("LBVC"), LREL },
433 { 0x29, 4, _T("LBVS"), LREL },
434 { 0x2A, 4, _T("LBPL"), LREL },
435 { 0x2B, 4, _T("LBMI"), LREL },
436 { 0x2C, 4, _T("LBGE"), LREL },
437 { 0x2D, 4, _T("LBLT"), LREL },
438 { 0x2E, 4, _T("LBGT"), LREL },
439 { 0x2F, 4, _T("LBLE"), LREL },
440 { 0x3F, 2, _T("SWI2"), INH },
441 { 0x83, 4, _T("CMPD"), IMM },
442 { 0x8C, 4, _T("CMPY"), IMM },
443 { 0x8D, 4, _T("LBSR"), LREL },
444 { 0x8E, 4, _T("LDY"), IMM },
445 { 0x93, 3, _T("CMPD"), DIR },
446 { 0x9C, 3, _T("CMPY"), DIR },
447 { 0x9E, 3, _T("LDY"), DIR },
448 { 0x9F, 3, _T("STY"), DIR },
449 { 0xA3, 3, _T("CMPD"), IND },
450 { 0xAC, 3, _T("CMPY"), IND },
451 { 0xAE, 3, _T("LDY"), IND },
452 { 0xAF, 3, _T("STY"), IND },
453 { 0xB3, 4, _T("CMPD"), EXT },
454 { 0xBC, 4, _T("CMPY"), EXT },
455 { 0xBE, 4, _T("LDY"), EXT },
456 { 0xBF, 4, _T("STY"), EXT },
457 { 0xCE, 4, _T("LDS"), IMM },
458 { 0xDE, 3, _T("LDS"), DIR },
459 { 0xDF, 3, _T("STS"), DIR },
460 { 0xEE, 3, _T("LDS"), IND },
461 { 0xEF, 3, _T("STS"), IND },
462 { 0xFE, 4, _T("LDS"), EXT },
463 { 0xFF, 4, _T("STS"), EXT }
466 // Page 2 opcodes (0x11 0x..)
467 static const opcodeinfo m6809_pg2opcodes[] =
469 { 0x3F, 2, _T("SWI3"), INH },
470 { 0x83, 4, _T("CMPU"), IMM },
471 { 0x8C, 4, _T("CMPS"), IMM },
472 { 0x93, 3, _T("CMPU"), DIR },
473 { 0x9C, 3, _T("CMPS"), DIR },
474 { 0xA3, 3, _T("CMPU"), IND },
475 { 0xAC, 3, _T("CMPS"), IND },
476 { 0xB3, 4, _T("CMPU"), EXT },
477 { 0xBC, 4, _T("CMPS"), EXT }
480 static const opcodeinfo *const m6809_pgpointers[3] =
482 m6809_pg0opcodes, m6809_pg1opcodes, m6809_pg2opcodes
485 static const int m6809_numops[3] =
487 array_length(m6809_pg0opcodes),
488 array_length(m6809_pg1opcodes),
489 array_length(m6809_pg2opcodes)
491 #endif /* USE_DEBUGGER */
493 uint32_t MC6809::cpu_disassemble_m6809(_TCHAR *buffer, uint32_t pc, const uint8_t *oprom, const uint8_t *opram)
496 uint8_t opcode, mode, pb, pbm, reg;
497 const uint8_t *operandarray;
498 unsigned int ea;//, flags;
499 int numoperands, offset;
500 int i, p = 0, page = 0;
501 bool opcode_found = false;
503 const _TCHAR *name = NULL;
508 for (i = 0; i < m6809_numops[page]; i++)
509 if (m6809_pgpointers[page][i].opcode == opcode)
512 if (i < m6809_numops[page])
516 _stprintf(buffer, _T("Illegal Opcode %02X"), opcode);
520 if (m6809_pgpointers[page][i].mode >= PG1)
522 page = m6809_pgpointers[page][i].mode - PG1 + 1;
523 opcode_found = false;
525 } while (!opcode_found);
528 numoperands = m6809_pgpointers[page][i].length - 1;
530 numoperands = m6809_pgpointers[page][i].length - 2;
532 operandarray = &opram[p];
535 mode = m6809_pgpointers[page][i].mode;
536 // flags = m6809_pgpointers[page][i].flags;
538 buffer += _stprintf(buffer, _T("%-6s"), m6809_pgpointers[page][i].name);
547 pb = operandarray[0];
549 buffer += _stprintf(buffer, _T("PC"));
551 buffer += _stprintf(buffer, _T("%s%s"), (pb&0x80)?_T(","):_T(""), (opcode==0x34)?"U":"S");
553 buffer += _stprintf(buffer, _T("%sY"), (pb&0xc0)?_T(","):_T(""));
555 buffer += _stprintf(buffer, _T("%sX"), (pb&0xe0)?_T(","):_T(""));
557 buffer += _stprintf(buffer, _T("%sDP"), (pb&0xf0)?_T(","):_T(""));
559 buffer += _stprintf(buffer, _T("%sB"), (pb&0xf8)?_T(","):_T(""));
561 buffer += _stprintf(buffer, _T("%sA"), (pb&0xfc)?_T(","):_T(""));
563 buffer += _stprintf(buffer, _T("%sCC"), (pb&0xfe)?_T(","):_T(""));
567 pb = operandarray[0];
569 buffer += _stprintf(buffer, _T("CC"));
571 buffer += _stprintf(buffer, _T("%sA"), (pb&0x01)?_T(","):_T(""));
573 buffer += _stprintf(buffer, _T("%sB"), (pb&0x03)?_T(","):_T(""));
575 buffer += _stprintf(buffer, _T("%sDP"), (pb&0x07)?_T(","):_T(""));
577 buffer += _stprintf(buffer, _T("%sX"), (pb&0x0f)?_T(","):_T(""));
579 buffer += _stprintf(buffer, _T("%sY"), (pb&0x1f)?_T(","):_T(""));
581 buffer += _stprintf(buffer, _T("%s%s"), (pb&0x3f)?_T(","):_T(""), (opcode==0x35)?_T("U"):_T("S"));
583 buffer += _stprintf(buffer, _T("%sPC ; (PUL? PC=RTS)"), (pb&0x7f)?_T(","):_T(""));
592 ea = operandarray[0];
593 buffer += _stprintf(buffer, _T("$%02X"), ea);
597 offset = (int8_t)operandarray[0];
598 buffer += _stprintf(buffer, _T("%s"), get_value_or_symbol(d_debugger->first_symbol, _T("$%04X"), (pc + offset) & 0xffff));
602 offset = (int16_t)((operandarray[0] << 8) + operandarray[1]);
603 buffer += _stprintf(buffer, _T("%s"), get_value_or_symbol(d_debugger->first_symbol, _T("$%04X"), (pc + offset) & 0xffff));
607 ea = (operandarray[0] << 8) + operandarray[1];
608 buffer += _stprintf(buffer, _T("%s"), get_value_or_symbol(d_debugger->first_symbol, _T("$%04X"), ea));
612 pb = operandarray[0];
615 indirect = ((pb & 0x90) == 0x90 )? true : false;
617 // open brackets if indirect
618 if (indirect && pbm != 0x80 && pbm != 0x82)
619 buffer += _stprintf(buffer, _T("["));
625 _tcscpy(buffer, _T("Illegal Postbyte"));
627 buffer += _stprintf(buffer, _T(",%s+"), m6809_regs[reg]);
631 buffer += _stprintf(buffer, _T(",%s++"), m6809_regs[reg]);
636 // _tcscpy(buffer, _T("Illegal Postbyte"));
638 buffer += _stprintf(buffer, _T(",-%s"), m6809_regs[reg]);
642 buffer += _stprintf(buffer, _T(",--%s"), m6809_regs[reg]);
646 buffer += _stprintf(buffer, _T(",%s"), m6809_regs[reg]);
649 case 0x85: // (+/- B),R
650 buffer += _stprintf(buffer, _T("B,%s"), m6809_regs[reg]);
653 case 0x86: // (+/- A),R
654 buffer += _stprintf(buffer, _T("A,%s"), m6809_regs[reg]);
657 case 0x87: // (+/- A),R // Also 0x*6.
658 buffer += _stprintf(buffer, _T("A,%s"), m6809_regs[reg]);
661 //_tcscpy(buffer, _T("Illegal Postbyte"));
664 case 0x88: // (+/- 7 bit offset),R
665 offset = (int8_t)opram[p++];
666 buffer += _stprintf(buffer, _T("%s"), (offset < 0) ? "-" : "");
667 buffer += _stprintf(buffer, _T("$%02X,"), (offset < 0) ? -offset : offset);
668 buffer += _stprintf(buffer, _T("%s"), m6809_regs[reg]);
671 case 0x89: // (+/- 15 bit offset),R
672 offset = (int16_t)((opram[p+0] << 8) + opram[p+1]);
674 buffer += _stprintf(buffer, _T("%s"), (offset < 0) ? "-" : "");
675 buffer += _stprintf(buffer, _T("$%04X,"), (offset < 0) ? -offset : offset);
676 buffer += _stprintf(buffer, _T("%s"), m6809_regs[reg]);
680 _tcscpy(buffer, _T("Illegal Postbyte"));
683 case 0x8b: // (+/- D),R
684 buffer += _stprintf(buffer, _T("D,%s"), m6809_regs[reg]);
687 case 0x8c: // (+/- 7 bit offset),PC
688 offset = (int8_t)opram[p++];
689 if((name = get_symbol(d_debugger->first_symbol, (p - 1 + offset) & 0xffff)) != NULL) {
690 buffer += _stprintf(buffer, _T("%s,PCR"), name);
692 buffer += _stprintf(buffer, _T("%s"), (offset < 0) ? "-" : "");
693 buffer += _stprintf(buffer, _T("$%02X,PC"), (offset < 0) ? -offset : offset);
697 case 0x8d: // (+/- 15 bit offset),PC
698 offset = (int16_t)((opram[p+0] << 8) + opram[p+1]);
700 if((name = get_symbol(d_debugger->first_symbol, (p - 2 + offset) & 0xffff)) != NULL) {
701 buffer += _stprintf(buffer, _T("%s,PCR"), name);
703 buffer += _stprintf(buffer, _T("%s"), (offset < 0) ? "-" : "");
704 buffer += _stprintf(buffer, _T("$%04X,PC"), (offset < 0) ? -offset : offset);
709 //_tcscpy(buffer, _T("Illegal Postbyte"));
710 offset = (int16_t)0xffff;
712 buffer += _stprintf(buffer, _T("$%04X"), offset);
715 case 0x8f: // address
716 ea = (uint16_t)((opram[p+0] << 8) + opram[p+1]);
718 buffer += _stprintf(buffer, _T("%s"), get_value_or_symbol(d_debugger->first_symbol, _T("$%04X"), ea));
721 default: // (+/- 4 bit offset),R
724 offset = offset - 32;
725 buffer += _stprintf(buffer, _T("%s"), (offset < 0) ? "-" : "");
726 buffer += _stprintf(buffer, _T("$%X,"), (offset < 0) ? -offset : offset);
727 buffer += _stprintf(buffer, _T("%s"), m6809_regs[reg]);
731 // close brackets if indirect
732 if (indirect && pbm != 0x80 && pbm != 0x82)
733 buffer += _stprintf(buffer, _T("]"));
737 if (numoperands == 2)
739 ea = (operandarray[0] << 8) + operandarray[1];
740 buffer += _stprintf(buffer, _T("#%s"), get_value_or_symbol(d_debugger->first_symbol, _T("$%04X"), ea));
743 if (numoperands == 1)
745 ea = operandarray[0];
746 buffer += _stprintf(buffer, _T("#$%02X"), ea);
751 pb = operandarray[0];
752 buffer += _stprintf(buffer, _T("%s,%s"), m6809_regs_te[(pb >> 4) & 0xf], m6809_regs_te[pb & 0xf]);
762 int MC6809::debug_dasm(uint32_t pc, _TCHAR *buffer, size_t buffer_len)
765 _TCHAR buffer_tmp[1024]; // enough ???
767 for(int i = 0; i < 4; i++) {
768 ops[i] = d_mem_stored->read_data8(pc + i);
770 int length = cpu_disassemble_m6809(buffer_tmp, pc, ops, ops);
771 my_tcscpy_s(buffer, buffer_len, buffer_tmp);