Motorola M6800 (6800) Exorciser / SWTPC emulator plus 6801 instruction set emulation
修訂 | 73ec18525884730e1e2112933923c65840a021fd (tree) |
---|---|
時間 | 2020-11-22 02:03:25 |
作者 | Joel Matthew Rees <joel.rees@gmai...> |
Commiter | Joel Matthew Rees |
buggy in 6800 mode, not sure why
@@ -1,8 +1,8 @@ | ||
1 | 1 | |
2 | -OBJS = unasm.o utils.o exor.o sim6800.o asm6800.o mdos.o unasm6800.o exorterm.o | |
2 | +OBJS = unasm.o utils.o exor.o sim6800.o asm6800.o mdos.o unasm6800.o mon.o exorterm.o exorsim.o | |
3 | 3 | |
4 | -DIST = unasm.c utils.c exor.c sim6800.c asm6800.c mdos.c unasm6800.c mon.c exorterm.c Makefile \ | |
5 | - exbug.bin swtbug.bin utils.h sim6800.h asm6800.h unasm6800.h exor.h facts README COPYING \ | |
4 | +DIST = unasm.c utils.c exor.c sim6800.c asm6800.c mdos.c unasm6800.c mon.c exorterm.c exorsim.c Makefile \ | |
5 | + exbug.bin swtbug.bin utils.h sim6800.h asm6800.h unasm6800.h exor.h exorsim.h facts README COPYING \ | |
6 | 6 | doc/doc.man doc/mdos-hello.txt doc/mdos-tech.txt doc/mdos.txt doc/mpl_upd.txt doc/mplnotes \ |
7 | 7 | doc/notes doc/fort.man |
8 | 8 |
@@ -66,11 +66,11 @@ CC = gcc | ||
66 | 66 | |
67 | 67 | all : mdos exor unasm |
68 | 68 | |
69 | -unasm : unasm.o utils.o unasm6800.o | |
70 | - $(CC) -o unasm unasm.o utils.o unasm6800.o | |
69 | +unasm : unasm.o utils.o unasm6800.o exorsim.o | |
70 | + $(CC) -o unasm unasm.o utils.o unasm6800.o exorsim.o | |
71 | 71 | |
72 | -exor : exor.o utils.o sim6800.o asm6800.o unasm6800.o mon.o exorterm.o | |
73 | - $(CC) -o exor exor.o utils.o sim6800.o asm6800.o unasm6800.o mon.o exorterm.o | |
72 | +exor : exor.o utils.o sim6800.o asm6800.o unasm6800.o mon.o exorterm.o exorsim.o | |
73 | + $(CC) -o exor exor.o utils.o sim6800.o asm6800.o unasm6800.o mon.o exorterm.o exorsim.o | |
74 | 74 | |
75 | 75 | mdos : mdos.o |
76 | 76 | $(CC) -o mdos mdos.o |
@@ -26,6 +26,7 @@ | ||
26 | 26 | #include <signal.h> |
27 | 27 | #include <unistd.h> /* JMR20201103 */ |
28 | 28 | |
29 | +#include "exorsim.h" /* JMR20201121 */ | |
29 | 30 | #include "sim6800.h" |
30 | 31 | #include "unasm6800.h" /* JMR202021103 */ |
31 | 32 | #include "exor.h" |
@@ -935,6 +936,8 @@ int main(int argc, char *argv[]) | ||
935 | 936 | trace = 1; |
936 | 937 | } else if (!strcmp(argv[x], "--swtpc")) { |
937 | 938 | swtpc = 1; |
939 | + } else if (!strcmp(argv[x], "--6801")) { | |
940 | + cputype = 0x6801; | |
938 | 941 | } else if (!strcmp(argv[x], "--dtrace")) { |
939 | 942 | trace_disk = 1; |
940 | 943 | } else if (!strcmp(argv[x], "--mon")) { |
@@ -957,6 +960,7 @@ int main(int argc, char *argv[]) | ||
957 | 960 | printf(" --dtrace Produce disk access trace on stderr\n"); |
958 | 961 | printf(" --skip nnn Skip first nnn insns in trace\n"); |
959 | 962 | printf(" --swtpc Simulate SWTPC instead of EXORciser\n"); |
963 | + printf(" --6801 Simulate additional 6801 instructions\n"); | |
960 | 964 | printf(" --exbug name Give name for ROM if not 'exbug.bin'\n"); |
961 | 965 | printf(" -x Go into EXBUG/SWTBUG instead of MDOS/FLEX\n"); |
962 | 966 | printf(" --facts file Process facts files for commented disassembly\n"); |
@@ -1,4 +1,5 @@ | ||
1 | -/* Configurations for Joseph H. Allen's Exorsim | |
1 | +/* Configurations include file | |
2 | + * for modifications to Joseph H. Allen's Exorsim | |
2 | 3 | * This file copyright 2020 Joel Matthew Rees |
3 | 4 | * |
4 | 5 | * This is free software; you can redistribute it and/or modify it under the |
@@ -16,7 +17,17 @@ | ||
16 | 17 | */ |
17 | 18 | |
18 | 19 | |
19 | -/* #define SIM6800 0x6800 */ | |
20 | -#define SIM6801 0x6801 | |
20 | +#ifndef EXORSIM_H | |
21 | +#define EXORSIM_H | |
21 | 22 | |
22 | 23 | |
24 | +#define SIM6801 0x6800 /* Set 0x6801 by command-line flags. */ | |
25 | + | |
26 | + | |
27 | +#ifndef EXORSIM_C | |
28 | + extern unsigned cputype; | |
29 | +#endif | |
30 | + | |
31 | + | |
32 | +#endif | |
33 | + |
@@ -157,11 +157,11 @@ unsigned short pull2() | ||
157 | 157 | #define V_SUB(a,b,f) ((((a) ^ (b)) & ((f) ^ (a))) >> 7) |
158 | 158 | #define C_SUB(a,b,f) (((~(a) & (b)) | ((~(a) | (b)) & (f))) >> 7) |
159 | 159 | #define H(a,b,f) ((((f) ^ (a) ^ (b)) >> 4) & 1) |
160 | -#ifdef SIM6801 | |
160 | +/* #ifdef SIM6801 */ | |
161 | 161 | #define C_16(a,b,f) ((((a) & (b)) | (((a) | (b)) & ~(f))) >> 15) |
162 | 162 | #define V_16_SUB(a,b,f) ((((a) ^ (b)) & ((f) ^ (a))) >> 15) |
163 | 163 | #define C_16_SUB(a,b,f) (((~(a) & (b)) | ((~(a) | (b)) & (f))) >> 15) |
164 | -#endif /* def SIM6801 */ | |
164 | +/* #endif / * def SIM6801 */ | |
165 | 165 | |
166 | 166 | /* Print one trace line */ |
167 | 167 |
@@ -217,11 +217,8 @@ void show_trace(int insn_no, struct trace_entry *t) | ||
217 | 217 | sprintf(buf + strlen(buf), "%2.2X ", t->insn[0]); |
218 | 218 | |
219 | 219 | if (t->insn[0] & 0x80) { |
220 | -#ifdef SIM6801 | |
221 | - if ( ((t->insn[0] & 0x0F) < 0x0C) && ((t->insn[0] & 0x0F) != 0x03 ) ) { | |
222 | -#else | |
223 | - if ((t->insn[0] & 0x0F) < 0x0C) { | |
224 | -#endif /* def SIM6801 */ | |
220 | + if ( ((t->insn[0] & 0x0F) < 0x0C) | |
221 | + && ( (cputype == 0x6801 && (t->insn[0] & 0x0F) != 0x03) ) ) { | |
225 | 222 | if (t->insn[0] & 0x40) { |
226 | 223 | sprintf(operand, "B"); |
227 | 224 | } else { |
@@ -260,19 +257,13 @@ void show_trace(int insn_no, struct trace_entry *t) | ||
260 | 257 | } case 0x02: /* SBC N,Z,V,C (no H?) */ { |
261 | 258 | insn = "SBC"; |
262 | 259 | break; |
263 | - } | |
264 | -#ifdef SIM6801 | |
265 | - case 0x03: /* ACCMD should never get here at run time. */ { | |
266 | - insn = ""; | |
260 | + } case 0x03: /* ACCMD should never get here at run time? */ { | |
261 | + if (cputype == 0x6800) | |
262 | + goto invalid; /* ??? */ | |
263 | + else | |
264 | + insn = "SUBD***"; | |
267 | 265 | break; |
268 | - } | |
269 | -#else | |
270 | - case 0x03: /* ??? */ { | |
271 | - goto invalid; | |
272 | - break; | |
273 | - } | |
274 | -#endif /* ndef SIM6801 */ | |
275 | - case 0x04: /* AND N,Z,V=0 */ { | |
266 | + } case 0x04: /* AND N,Z,V=0 */ { | |
276 | 267 | insn = "AND"; |
277 | 268 | break; |
278 | 269 | } case 0x05: /* BIT N,Z,V=0*/ { |
@@ -327,15 +318,14 @@ void show_trace(int insn_no, struct trace_entry *t) | ||
327 | 318 | } |
328 | 319 | } |
329 | 320 | switch (t->insn[0]) { |
330 | -#ifdef SIM6801 | |
331 | 321 | case 0x83: case 0x93: case 0xA3: case 0xB3: /* SUBD N,Z,V,C (6801) */ { |
322 | + /* Should never come here when cputype == 0x6800. */ | |
323 | + /* But if it does, we want to do something defined. */ | |
332 | 324 | if (t->cc & 0x80) |
333 | 325 | sprintf(buf3, "EA=%4.4X%s D=%4.4X", t->ea, buf_ea, t->data); |
334 | - insn = "SUBD"; | |
326 | + insn = (cputype == 0x6800) ? "???SUBD" : "SUBD"; | |
335 | 327 | break; |
336 | - } | |
337 | -#endif /* def SIM6801 */ | |
338 | - case 0x8C: case 0x9C: case 0xAC: case 0xBC: /* CPX N,Z,V */ { | |
328 | + } case 0x8C: case 0x9C: case 0xAC: case 0xBC: /* CPX N,Z,V */ { | |
339 | 329 | if (t->cc & 0x80) |
340 | 330 | sprintf(buf3, "EA=%4.4X%s D=%4.4X", t->ea, buf_ea, t->data); |
341 | 331 | insn = "CPX"; |
@@ -357,36 +347,36 @@ void show_trace(int insn_no, struct trace_entry *t) | ||
357 | 347 | sprintf(buf3, "EA=%4.4X%s D=%4.4X", t->ea, buf_ea, t->data); |
358 | 348 | insn = "STS"; |
359 | 349 | break; |
360 | - } | |
361 | -#ifdef SIM6801 | |
362 | - case 0x9D: /* (6801) */ | |
363 | -#endif /* def SIM6801 */ | |
364 | - case 0xAD: case 0xBD: /* JSR */ { | |
365 | - if (t->cc & 0x80) | |
350 | + } case 0x9D: case 0xAD: case 0xBD: /* JSR */ { | |
351 | + if (cputype == 0x6800 && t->insn[0] == 0x9D) | |
352 | +{ fputs( "JSR\n", stderr ); goto invalid16; | |
353 | +} else if (t->cc & 0x80) | |
366 | 354 | sprintf(buf3, "EA=%4.4X%s", t->ea, buf_ea); |
367 | 355 | insn = "JSR"; |
368 | 356 | subr = 1; |
369 | 357 | break; |
370 | - } | |
371 | -#ifdef SIM6801 | |
372 | - case 0xC3: case 0xD3: case 0xE3: case 0xF3: /* ADDD N,Z,V,C (6801) */ { | |
373 | - if (t->cc & 0x80) | |
358 | + } case 0xC3: case 0xD3: case 0xE3: case 0xF3: /* ADDD N,Z,V,C (6801) */ { | |
359 | + if (cputype == 0x6800) | |
360 | +{ fputs( "ADDD\n", stderr ); goto invalid16; | |
361 | +} else if (t->cc & 0x80) | |
374 | 362 | sprintf(buf3, "EA=%4.4X%s D=%4.4X", t->ea, buf_ea, t->data); |
375 | 363 | insn = "ADDD"; |
376 | 364 | break; |
377 | 365 | } case 0xCC: case 0xDC: case 0xEC: case 0xFC: /* LDD N,Z,V=0 (6801) */ { |
378 | - if (t->cc & 0x80) | |
366 | + if (cputype == 0x6800) | |
367 | +{ fputs( "LDD\n", stderr ); goto invalid16; | |
368 | +} else if (t->cc & 0x80) | |
379 | 369 | sprintf(buf3, "EA=%4.4X%s D=%4.4X", t->ea, buf_ea, t->data); |
380 | 370 | insn = "LDD"; |
381 | 371 | break; |
382 | 372 | } case 0xCD: case 0xDD: case 0xED: case 0xFD: /* STD N,Z,V=0 (6801) */ { |
383 | - if (t->cc & 0x80) | |
373 | + if (cputype == 0x6800) | |
374 | +{ fputs( "STD\n", stderr ); goto invalid16; | |
375 | +} else if (t->cc & 0x80) | |
384 | 376 | sprintf(buf3, "EA=%4.4X%s D=%4.4X", t->ea, buf_ea, t->data); |
385 | 377 | insn = "STD"; |
386 | 378 | break; |
387 | - } | |
388 | -#endif /* def SIM6801 */ | |
389 | - case 0xCE: case 0xDE: case 0xEE: case 0xFE: /* LDX N,Z,V */ { | |
379 | + } case 0xCE: case 0xDE: case 0xEE: case 0xFE: /* LDX N,Z,V */ { | |
390 | 380 | if (t->cc & 0x80) |
391 | 381 | sprintf(buf3, "EA=%4.4X%s D=%4.4X", t->ea, buf_ea, t->data); |
392 | 382 | insn = "LDX"; |
@@ -397,6 +387,8 @@ void show_trace(int insn_no, struct trace_entry *t) | ||
397 | 387 | insn = "STX"; |
398 | 388 | break; |
399 | 389 | } default: /* ??? */ { |
390 | +invalid16: | |
391 | +fprintf( stderr, "invalid16 from mnemonic: %x\n", t->insn[0] ); | |
400 | 392 | goto invalid; |
401 | 393 | break; |
402 | 394 | } |
@@ -481,17 +473,19 @@ void show_trace(int insn_no, struct trace_entry *t) | ||
481 | 473 | case 0x01: /* NOP */ { /* Do nothing */ |
482 | 474 | insn = "NOP"; |
483 | 475 | break; |
484 | - } | |
485 | -#ifdef SIM6801 | |
486 | - case 0x04: /* LSRD N=0,Z,V,C (6801) */ { | |
487 | - insn = "LSRD"; | |
476 | + } case 0x04: /* LSRD N=0,Z,V,C (6801) */ { | |
477 | + if (cputype == 0x6800) | |
478 | + goto invalidinh; | |
479 | + else | |
480 | + insn = "LSRD"; | |
488 | 481 | break; |
489 | 482 | } case 0x05: /* LSLD N,Z,V,C (6801) */ { |
490 | - insn = "LSLD"; | |
483 | + if (cputype == 0x6800) | |
484 | + goto invalidinh; | |
485 | + else | |
486 | + insn = "LSLD"; | |
491 | 487 | break; |
492 | - } | |
493 | -#endif /* def SIM6801 */ | |
494 | - case 0x06: /* TAP (all flags) */ { | |
488 | + } case 0x06: /* TAP (all flags) */ { | |
495 | 489 | insn = "TAP"; |
496 | 490 | break; |
497 | 491 | } case 0x07: /* TPA */ { |
@@ -546,18 +540,18 @@ void show_trace(int insn_no, struct trace_entry *t) | ||
546 | 540 | sprintf(buf3, "EA=%4.4X%s", t->ea, buf_ea); |
547 | 541 | insn = "BRA"; |
548 | 542 | break; |
549 | - } | |
550 | -#ifdef SIM6801 | |
551 | - case 0x21: /* BRN (6801) */ { | |
552 | - sprintf(buf + strlen(buf), "%2.2X ", t->insn[1]); | |
553 | - sprintf(operand, " %4.4X", t->pc + 2 + (char)t->insn[1]); | |
554 | - if (t->cc & 0x80) | |
555 | - sprintf(buf3, "EA=%4.4X%s", t->ea, buf_ea); | |
556 | - insn = "BRN"; | |
543 | + } case 0x21: /* BRN (6801) */ { | |
544 | + if (cputype == 0x6800) | |
545 | + goto invalidinh; | |
546 | + else { | |
547 | + sprintf(buf + strlen(buf), "%2.2X ", t->insn[1]); | |
548 | + sprintf(operand, " %4.4X", t->pc + 2 + (char)t->insn[1]); | |
549 | + if (t->cc & 0x80) | |
550 | + sprintf(buf3, "EA=%4.4X%s", t->ea, buf_ea); | |
551 | + insn = "BRN"; | |
552 | + } | |
557 | 553 | break; |
558 | - } | |
559 | -#endif /* def SIM6801 */ | |
560 | - case 0x22: /* BHI */ { | |
554 | + } case 0x22: /* BHI */ { | |
561 | 555 | sprintf(buf + strlen(buf), "%2.2X ", t->insn[1]); |
562 | 556 | sprintf(operand, " %4.4X", t->pc + 2 + (char)t->insn[1]); |
563 | 557 | if (t->cc & 0x80) |
@@ -679,45 +673,46 @@ void show_trace(int insn_no, struct trace_entry *t) | ||
679 | 673 | } case 0x37: /* PSHB */ { |
680 | 674 | insn = "PSHB"; |
681 | 675 | break; |
682 | - } | |
683 | -#ifdef SIM6801 | |
684 | - case 0x38: /* PULX (6801) */ { | |
685 | - insn = "PULX"; | |
676 | + } case 0x38: /* PULX (6801) */ { | |
677 | + if (cputype == 0x6800) | |
678 | + goto invalidinh; | |
679 | + else | |
680 | + insn = "PULX"; | |
686 | 681 | break; |
687 | - } | |
688 | -#endif /* def SIM6801 */ | |
689 | - case 0x39: /* RTS */ { | |
682 | + } case 0x39: /* RTS */ { | |
690 | 683 | insn = "RTS"; |
691 | 684 | subr = 1; |
692 | 685 | break; |
693 | - } | |
694 | -#ifdef SIM6801 | |
695 | - case 0x3A: /* ABX (6801) */ { | |
696 | - insn = "ABX"; | |
686 | + } case 0x3A: /* ABX (6801) */ { | |
687 | + if (cputype == 0x6800) | |
688 | + goto invalidinh; | |
689 | + else | |
690 | + insn = "ABX"; | |
697 | 691 | break; |
698 | - } | |
699 | -#endif /* def SIM6801 */ | |
700 | - case 0x3B: /* RTI */ { | |
692 | + } case 0x3B: /* RTI */ { | |
701 | 693 | insn = "RTI"; |
702 | 694 | subr = 1; |
703 | 695 | break; |
704 | - } | |
705 | -#ifdef SIM6801 | |
706 | - case 0x3C: /* PSHX (6801) */ { | |
707 | - insn = "PSHX"; | |
696 | + } case 0x3C: /* PSHX (6801) */ { | |
697 | + if (cputype == 0x6800) | |
698 | + goto invalidinh; | |
699 | + else | |
700 | + insn = "PSHX"; | |
708 | 701 | break; |
709 | 702 | } case 0x3D: /* MUL C=accb bit 7 (6801) */ { |
710 | - insn = "MUL"; | |
703 | + if (cputype == 0x6800) | |
704 | + goto invalidinh; | |
705 | + else | |
706 | + insn = "MUL"; | |
711 | 707 | break; |
712 | - } | |
713 | -#endif /* def SIM6801 */ | |
714 | - case 0x3E: /* WAI */ { | |
708 | + } case 0x3E: /* WAI */ { | |
715 | 709 | insn = "WAI"; |
716 | 710 | break; |
717 | 711 | } case 0x3F: /* SWI */ { |
718 | 712 | insn = "SWI"; |
719 | 713 | break; |
720 | 714 | } default: /* ??? */ { |
715 | +invalidinh: | |
721 | 716 | goto invalid; |
722 | 717 | break; |
723 | 718 | } |
@@ -775,11 +770,9 @@ void sim(void) | ||
775 | 770 | unsigned char b; |
776 | 771 | unsigned char f; |
777 | 772 | unsigned char data; |
778 | -#ifdef SIM6801 | |
779 | 773 | unsigned short accd; |
780 | 774 | #define setACCD( val ) ( val = ( ( (unsigned int) acca ) << 8 ) | ( (unsigned char) accb ) ) |
781 | 775 | #define restoreACCM( res ) ( acca = (unsigned char) ( (res) >> 8 ), accb = ( (unsigned char) (res) ) ) |
782 | -#endif /* def SIM6801 */ | |
783 | 776 | unsigned short w; |
784 | 777 | unsigned short fw; |
785 | 778 | int wb; |
@@ -859,11 +852,8 @@ void sim(void) | ||
859 | 852 | opcode = fetch(); |
860 | 853 | |
861 | 854 | if (opcode & 0x80) { |
862 | -#ifdef SIM6801 | |
863 | - if ( ((opcode & 0x0F) < 0x0C) && ((opcode & 0x0F) != 0x03) ) { | |
864 | -#else | |
865 | - if ((opcode & 0x0F) < 0x0C) { | |
866 | -#endif /* def SIM6801 */ | |
855 | + if ( ((opcode & 0x0F) < 0x0C) | |
856 | + && (cputype == 0x6801 && ((opcode & 0x0F) != 0x03)) ) { | |
867 | 857 | /* Get operand A */ |
868 | 858 | if (opcode & 0x40) { |
869 | 859 | a = accb; |
@@ -919,14 +909,12 @@ void sim(void) | ||
919 | 909 | n_flag = N(f); |
920 | 910 | z_flag = Z(f); |
921 | 911 | break; |
922 | - } | |
923 | -#ifndef SIM6801 | |
924 | - case 0x03: /* ??? */ { | |
912 | + } case 0x03: /* ??? */ { | |
913 | + if (cputype == 0x6801) | |
914 | + fprintf( stderr, "Internal error on SUBD (6801)\n" ); | |
925 | 915 | goto invalid; |
926 | 916 | break; |
927 | - } | |
928 | -#endif /* ndef SIM6801 */ | |
929 | - case 0x04: /* AND N,Z,V=0 */ { | |
917 | + } case 0x04: /* AND N,Z,V=0 */ { | |
930 | 918 | f = (a & b); |
931 | 919 | n_flag = N(f); |
932 | 920 | z_flag = Z(f); |
@@ -1006,35 +994,36 @@ void sim(void) | ||
1006 | 994 | } |
1007 | 995 | } |
1008 | 996 | switch (opcode) { |
1009 | -#ifdef SIM6801 | |
1010 | 997 | case 0x83: case 0x93: case 0xA3: case 0xB3: /* SUBD N,Z,V,C (6801) */ { |
1011 | - setACCD( accd ); | |
1012 | - w = mread2(ea); | |
1013 | - t->ea = ea; t->data = w; | |
1014 | - fw = accd - w; | |
1015 | - z_flag = Z_16(fw); | |
1016 | - n_flag = N_16(fw); | |
1017 | - v_flag = V_16_SUB(accd, w, fw); | |
1018 | - c_flag = C_16_SUB(accd, w, fw); | |
1019 | - restoreACCM( fw ); | |
998 | + if (cputype == 0x6800) { | |
999 | + fprintf( stderr, "Internal error on SUBD (6800)\n" ); | |
1000 | + goto invalid16; | |
1001 | + } | |
1002 | + else { | |
1003 | + setACCD( accd ); | |
1004 | + w = mread2(ea); | |
1005 | + t->ea = ea; t->data = w; | |
1006 | + fw = accd - w; | |
1007 | + z_flag = Z_16(fw); | |
1008 | + n_flag = N_16(fw); | |
1009 | + v_flag = V_16_SUB(accd, w, fw); | |
1010 | + c_flag = C_16_SUB(accd, w, fw); | |
1011 | + restoreACCM( fw ); | |
1012 | + } | |
1020 | 1013 | break; |
1021 | - } | |
1022 | -#endif /* def SIM6801 */ | |
1023 | - case 0x8C: case 0x9C: case 0xAC: case 0xBC: /* CPX (N_hi8),Z,(V_hi8) JMR20201103 */ { | |
1014 | + } case 0x8C: case 0x9C: case 0xAC: case 0xBC: /* CPX (N_hi8),Z,(V_hi8) JMR20201103 */ { | |
1024 | 1015 | w = mread2(ea); |
1025 | 1016 | t->ea = ea; t->data = w; |
1026 | 1017 | fw = ix - w; |
1027 | 1018 | z_flag = Z_16(fw); |
1028 | -#if defined SIM6801 | |
1029 | - n_flag = N_16(fw); | |
1030 | - v_flag = V_16(ix, w, fw); | |
1031 | -#elif defined SIM6800 | |
1032 | - f = ( ix >> 8 ) - ( w >> 8 ); | |
1033 | - n_flag = N(f); | |
1034 | - v_flag = V(ix >> 8, w >> 8, f); | |
1035 | -#else | |
1036 | -# error "68HC11, etc. not defined here!" | |
1037 | -#endif /* defined SIM6800 */ | |
1019 | + if (cputype == 0x6800) { | |
1020 | + f = ( ix >> 8 ) - ( w >> 8 ); | |
1021 | + n_flag = N(f); | |
1022 | + v_flag = V(ix >> 8, w >> 8, f); | |
1023 | + } else { /* assume 0x6801 compatible for now. */ | |
1024 | + n_flag = N_16(fw); | |
1025 | + v_flag = V_16(ix, w, fw); | |
1026 | + } | |
1038 | 1027 | break; |
1039 | 1028 | } case 0x8D: /* BSR REL */ { |
1040 | 1029 | push2(pc - 1); |
@@ -1055,46 +1044,56 @@ void sim(void) | ||
1055 | 1044 | v_flag = 0; |
1056 | 1045 | break; |
1057 | 1046 | } |
1058 | -#ifdef SIM6801 | |
1059 | 1047 | case 0x9D: /* (6801) */ |
1060 | -#endif /* def SIM6801 */ | |
1061 | 1048 | case 0xAD: case 0xBD: /* JSR */ { |
1062 | - push2(pc); | |
1063 | - jump(ea); | |
1064 | - t->ea = ea; | |
1049 | + if (cputype == 0x6800 && opcode == 0x9D) | |
1050 | + goto invalid16; | |
1051 | + else { | |
1052 | + push2(pc); | |
1053 | + jump(ea); | |
1054 | + t->ea = ea; | |
1055 | + } | |
1065 | 1056 | break; |
1066 | - } | |
1067 | -#ifdef SIM6801 | |
1068 | - case 0xC3: case 0xD3: case 0xE3: case 0xF3: /* ADDD N,Z,V,C (6801) */ { | |
1069 | - setACCD( accd ); | |
1070 | - w = mread2(ea); | |
1071 | - t->ea = ea; t->data = w; | |
1072 | - fw = accd + w; | |
1073 | - z_flag = Z_16(fw); | |
1074 | - n_flag = N_16(fw); | |
1075 | - v_flag = V_16(accd, w, fw); | |
1076 | - c_flag = C_16(accd, w, fw); | |
1077 | - restoreACCM( fw ); | |
1057 | + } case 0xC3: case 0xD3: case 0xE3: case 0xF3: /* ADDD N,Z,V,C (6801) */ { | |
1058 | + if (cputype == 0x6800) | |
1059 | + goto invalid16; | |
1060 | + else { | |
1061 | + setACCD( accd ); | |
1062 | + w = mread2(ea); | |
1063 | + t->ea = ea; t->data = w; | |
1064 | + fw = accd + w; | |
1065 | + z_flag = Z_16(fw); | |
1066 | + n_flag = N_16(fw); | |
1067 | + v_flag = V_16(accd, w, fw); | |
1068 | + c_flag = C_16(accd, w, fw); | |
1069 | + restoreACCM( fw ); | |
1070 | + } | |
1078 | 1071 | break; |
1079 | 1072 | } case 0xCC: case 0xDC: case 0xEC: case 0xFC: /* LDD N,Z,V=0 (6801) */ { |
1080 | - accd = mread2(ea); | |
1081 | - t->ea = ea; t->data = accd; | |
1082 | - z_flag = Z_16( accd ); | |
1083 | - n_flag = N_16( accd ); | |
1084 | - v_flag = 0; | |
1085 | - restoreACCM( accd ); | |
1073 | + if (cputype == 0x6800) | |
1074 | + goto invalid16; | |
1075 | + else { | |
1076 | + accd = mread2(ea); | |
1077 | + t->ea = ea; t->data = accd; | |
1078 | + z_flag = Z_16( accd ); | |
1079 | + n_flag = N_16( accd ); | |
1080 | + v_flag = 0; | |
1081 | + restoreACCM( accd ); | |
1082 | + } | |
1086 | 1083 | break; |
1087 | 1084 | } case 0xDD: case 0xED: case 0xFD: /* STD N,Z,V=0 (6801) */ { |
1088 | - setACCD( accd ); | |
1089 | - n_flag = N_16( accd ); | |
1090 | - z_flag = Z_16( accd ); | |
1091 | - v_flag = 0; | |
1092 | - mwrite2( ea, accd ); | |
1093 | - t->ea = ea; t->data = accd; | |
1085 | + if (cputype == 0x6800) | |
1086 | + goto invalid16; | |
1087 | + else { | |
1088 | + setACCD( accd ); | |
1089 | + n_flag = N_16( accd ); | |
1090 | + z_flag = Z_16( accd ); | |
1091 | + v_flag = 0; | |
1092 | + mwrite2( ea, accd ); | |
1093 | + t->ea = ea; t->data = accd; | |
1094 | + } | |
1094 | 1095 | break; |
1095 | - } | |
1096 | -#endif /* def SIM6801 */ | |
1097 | - case 0xCE: case 0xDE: case 0xEE: case 0xFE: /* LDX N,Z,V */ { | |
1096 | + } case 0xCE: case 0xDE: case 0xEE: case 0xFE: /* LDX N,Z,V */ { | |
1098 | 1097 | ix = mread2(ea); |
1099 | 1098 | t->ea = ea; t->data = ix; |
1100 | 1099 | z_flag = Z_16(ix); |
@@ -1109,6 +1108,9 @@ void sim(void) | ||
1109 | 1108 | v_flag = 0; |
1110 | 1109 | break; |
1111 | 1110 | } default: /* ??? */ { |
1111 | +invalid16: | |
1112 | +fprintf( stderr, "invalid16 from opcode: %x => %x\n", t->insn[0], opcode ); | |
1113 | + | |
1112 | 1114 | goto invalid; |
1113 | 1115 | break; |
1114 | 1116 | } |
@@ -1250,31 +1252,35 @@ void sim(void) | ||
1250 | 1252 | switch(opcode) { |
1251 | 1253 | case 0x01: /* NOP */ { /* Do nothing */ |
1252 | 1254 | break; |
1253 | - } | |
1254 | -#ifdef SIM6801 | |
1255 | - case 0x04: /* LSRD (6801) */ { | |
1256 | - setACCD( accd ); | |
1257 | - t->data = accd; | |
1258 | - fw = (accd >> 1); | |
1259 | - c_flag = (accd & 1); | |
1260 | - n_flag = 0; | |
1261 | - z_flag = Z_16(fw); | |
1262 | - v_flag = n_flag ^ c_flag; | |
1263 | - restoreACCM( fw ); | |
1255 | + } case 0x04: /* LSRD (6801) */ { | |
1256 | + if (cputype == 0x6800) | |
1257 | + goto invalidinh; | |
1258 | + else { | |
1259 | + setACCD( accd ); | |
1260 | + t->data = accd; | |
1261 | + fw = (accd >> 1); | |
1262 | + c_flag = (accd & 1); | |
1263 | + n_flag = 0; | |
1264 | + z_flag = Z_16(fw); | |
1265 | + v_flag = n_flag ^ c_flag; | |
1266 | + restoreACCM( fw ); | |
1267 | + } | |
1264 | 1268 | break; |
1265 | 1269 | } case 0x05: /* LSLD (6801) */ { |
1266 | - setACCD( accd ); | |
1267 | - t->data = accd; | |
1268 | - fw = (accd << 1); | |
1269 | - c_flag = (accd >> 15); | |
1270 | - n_flag = N_16(fw); | |
1271 | - z_flag = Z_16(fw); | |
1272 | - v_flag = n_flag ^ c_flag; | |
1273 | - restoreACCM( fw ); | |
1270 | + if (cputype == 0x6800) | |
1271 | + goto invalidinh; | |
1272 | + else { | |
1273 | + setACCD( accd ); | |
1274 | + t->data = accd; | |
1275 | + fw = (accd << 1); | |
1276 | + c_flag = (accd >> 15); | |
1277 | + n_flag = N_16(fw); | |
1278 | + z_flag = Z_16(fw); | |
1279 | + v_flag = n_flag ^ c_flag; | |
1280 | + restoreACCM( fw ); | |
1281 | + } | |
1274 | 1282 | break; |
1275 | - } | |
1276 | -#endif /* def SIM6801 */ | |
1277 | - case 0x06: /* TAP (all flags) */ { | |
1283 | + } case 0x06: /* TAP (all flags) */ { | |
1278 | 1284 | write_flags(acca); |
1279 | 1285 | break; |
1280 | 1286 | } case 0x07: /* TPA */ { |
@@ -1360,15 +1366,15 @@ void sim(void) | ||
1360 | 1366 | offset = fetch(); |
1361 | 1367 | jump(t->ea = (pc + offset)); |
1362 | 1368 | break; |
1363 | - } | |
1364 | -#ifdef SIM6801 | |
1365 | - case 0x21: /* BRN (6801) */ { | |
1366 | - offset = fetch(); | |
1367 | - t->ea = pc + offset; | |
1369 | + } case 0x21: /* BRN (6801) */ { | |
1370 | + if (cputype == 0x6800) | |
1371 | + goto invalidinh; | |
1372 | + else { | |
1373 | + offset = fetch(); | |
1374 | + t->ea = pc + offset; | |
1375 | + } | |
1368 | 1376 | break; |
1369 | - } | |
1370 | -#endif /* def SIM6801 */ | |
1371 | - case 0x22: /* BHI */ { | |
1377 | + } case 0x22: /* BHI */ { | |
1372 | 1378 | offset = fetch(); |
1373 | 1379 | t->ea = pc + offset; |
1374 | 1380 | if (!(c_flag | z_flag)) |
@@ -1476,48 +1482,52 @@ void sim(void) | ||
1476 | 1482 | } case 0x37: /* PSHB */ { |
1477 | 1483 | push(accb); |
1478 | 1484 | break; |
1479 | - } | |
1480 | -#ifdef SIM6801 | |
1481 | - case 0x38: /* PULX (6801) */ { | |
1482 | - ix = pull2(); | |
1485 | + } case 0x38: /* PULX (6801) */ { | |
1486 | + if (cputype == 0x6800) | |
1487 | + goto invalidinh; | |
1488 | + else { | |
1489 | + ix = pull2(); | |
1490 | + } | |
1483 | 1491 | break; |
1484 | - } | |
1485 | -#endif /* def SIM6801 */ | |
1486 | - case 0x39: /* RTS */ { | |
1492 | + } case 0x39: /* RTS */ { | |
1487 | 1493 | if (sp == sp_stop) { |
1488 | 1494 | stop = 1; |
1489 | 1495 | sp_stop = -1; |
1490 | 1496 | } else |
1491 | 1497 | jump(pull2()); |
1492 | 1498 | break; |
1493 | - } | |
1494 | -#ifdef SIM6801 | |
1495 | - case 0x3A: /* ABX (6801) */ { | |
1496 | - ix = ix + accb; | |
1499 | + } case 0x3A: /* ABX (6801) */ { | |
1500 | + if (cputype == 0x6800) | |
1501 | + goto invalidinh; | |
1502 | + else { | |
1503 | + ix = ix + accb; | |
1504 | + } | |
1497 | 1505 | break; |
1498 | - } | |
1499 | -#endif /* def SIM6801 */ | |
1500 | - case 0x3B: /* RTI */ { | |
1506 | + } case 0x3B: /* RTI */ { | |
1501 | 1507 | write_flags(pull()); |
1502 | 1508 | accb = pull(); |
1503 | 1509 | acca = pull(); |
1504 | 1510 | ix = pull2(); |
1505 | 1511 | jump(pull2()); |
1506 | 1512 | break; |
1507 | - } | |
1508 | -#ifdef SIM6801 | |
1509 | - case 0x3C: /* PSHX (6801) */ { | |
1510 | - push2(ix); | |
1513 | + } case 0x3C: /* PSHX (6801) */ { | |
1514 | + if (cputype == 0x6800) | |
1515 | + goto invalidinh; | |
1516 | + else { | |
1517 | + push2(ix); | |
1518 | + } | |
1511 | 1519 | break; |
1512 | 1520 | } case 0x3D: /* MUL C=accb bit 7 (6801) */ { |
1513 | - unsigned product = acca * accb; | |
1514 | - accb = (unsigned char) product; | |
1515 | - acca = (unsigned char) ( product >> 8 ); | |
1516 | - c_flag = N(acca); | |
1521 | + if (cputype == 0x6800) | |
1522 | + goto invalidinh; | |
1523 | + else { | |
1524 | + unsigned product = acca * accb; | |
1525 | + accb = (unsigned char) product; | |
1526 | + acca = (unsigned char) ( product >> 8 ); | |
1527 | + c_flag = N(acca); | |
1528 | + } | |
1517 | 1529 | break; |
1518 | - } | |
1519 | -#endif /* def SIM6801 */ | |
1520 | - case 0x3E: /* WAI */ { | |
1530 | + } case 0x3E: /* WAI */ { | |
1521 | 1531 | printf("WAI encountered...\n"); |
1522 | 1532 | return; |
1523 | 1533 | break; |
@@ -1530,6 +1540,7 @@ void sim(void) | ||
1530 | 1540 | jump(mread2(0xFFFA)); |
1531 | 1541 | break; |
1532 | 1542 | } default: /* ??? */ { |
1543 | +invalidinh: | |
1533 | 1544 | goto invalid; |
1534 | 1545 | break; |
1535 | 1546 | } |