• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Joe H. Allen's exorsim with 6809 (and 6801)


Commit MetaInfo

Revision73ec18525884730e1e2112933923c65840a021fd (tree)
Zeit2020-11-22 02:03:25
AutorJoel Matthew Rees <joel.rees@gmai...>
CommiterJoel Matthew Rees

Log Message

buggy in 6800 mode, not sure why

Ändern Zusammenfassung

Diff

--- a/Makefile
+++ b/Makefile
@@ -1,8 +1,8 @@
11
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
33
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 \
66 doc/doc.man doc/mdos-hello.txt doc/mdos-tech.txt doc/mdos.txt doc/mpl_upd.txt doc/mplnotes \
77 doc/notes doc/fort.man
88
@@ -66,11 +66,11 @@ CC = gcc
6666
6767 all : mdos exor unasm
6868
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
7171
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
7474
7575 mdos : mdos.o
7676 $(CC) -o mdos mdos.o
--- a/exor.c
+++ b/exor.c
@@ -26,6 +26,7 @@
2626 #include <signal.h>
2727 #include <unistd.h> /* JMR20201103 */
2828
29+#include "exorsim.h" /* JMR20201121 */
2930 #include "sim6800.h"
3031 #include "unasm6800.h" /* JMR202021103 */
3132 #include "exor.h"
@@ -935,6 +936,8 @@ int main(int argc, char *argv[])
935936 trace = 1;
936937 } else if (!strcmp(argv[x], "--swtpc")) {
937938 swtpc = 1;
939+ } else if (!strcmp(argv[x], "--6801")) {
940+ cputype = 0x6801;
938941 } else if (!strcmp(argv[x], "--dtrace")) {
939942 trace_disk = 1;
940943 } else if (!strcmp(argv[x], "--mon")) {
@@ -957,6 +960,7 @@ int main(int argc, char *argv[])
957960 printf(" --dtrace Produce disk access trace on stderr\n");
958961 printf(" --skip nnn Skip first nnn insns in trace\n");
959962 printf(" --swtpc Simulate SWTPC instead of EXORciser\n");
963+ printf(" --6801 Simulate additional 6801 instructions\n");
960964 printf(" --exbug name Give name for ROM if not 'exbug.bin'\n");
961965 printf(" -x Go into EXBUG/SWTBUG instead of MDOS/FLEX\n");
962966 printf(" --facts file Process facts files for commented disassembly\n");
--- a/exorsim.h
+++ b/exorsim.h
@@ -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
23 * This file copyright 2020 Joel Matthew Rees
34 *
45 * This is free software; you can redistribute it and/or modify it under the
@@ -16,7 +17,17 @@
1617 */
1718
1819
19-/* #define SIM6800 0x6800 */
20-#define SIM6801 0x6801
20+#ifndef EXORSIM_H
21+#define EXORSIM_H
2122
2223
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+
--- a/sim6800.c
+++ b/sim6800.c
@@ -157,11 +157,11 @@ unsigned short pull2()
157157 #define V_SUB(a,b,f) ((((a) ^ (b)) & ((f) ^ (a))) >> 7)
158158 #define C_SUB(a,b,f) (((~(a) & (b)) | ((~(a) | (b)) & (f))) >> 7)
159159 #define H(a,b,f) ((((f) ^ (a) ^ (b)) >> 4) & 1)
160-#ifdef SIM6801
160+/* #ifdef SIM6801 */
161161 #define C_16(a,b,f) ((((a) & (b)) | (((a) | (b)) & ~(f))) >> 15)
162162 #define V_16_SUB(a,b,f) ((((a) ^ (b)) & ((f) ^ (a))) >> 15)
163163 #define C_16_SUB(a,b,f) (((~(a) & (b)) | ((~(a) | (b)) & (f))) >> 15)
164-#endif /* def SIM6801 */
164+/* #endif / * def SIM6801 */
165165
166166 /* Print one trace line */
167167
@@ -217,11 +217,8 @@ void show_trace(int insn_no, struct trace_entry *t)
217217 sprintf(buf + strlen(buf), "%2.2X ", t->insn[0]);
218218
219219 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) ) ) {
225222 if (t->insn[0] & 0x40) {
226223 sprintf(operand, "B");
227224 } else {
@@ -260,19 +257,13 @@ void show_trace(int insn_no, struct trace_entry *t)
260257 } case 0x02: /* SBC N,Z,V,C (no H?) */ {
261258 insn = "SBC";
262259 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***";
267265 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 */ {
276267 insn = "AND";
277268 break;
278269 } case 0x05: /* BIT N,Z,V=0*/ {
@@ -327,15 +318,14 @@ void show_trace(int insn_no, struct trace_entry *t)
327318 }
328319 }
329320 switch (t->insn[0]) {
330-#ifdef SIM6801
331321 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. */
332324 if (t->cc & 0x80)
333325 sprintf(buf3, "EA=%4.4X%s D=%4.4X", t->ea, buf_ea, t->data);
334- insn = "SUBD";
326+ insn = (cputype == 0x6800) ? "???SUBD" : "SUBD";
335327 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 */ {
339329 if (t->cc & 0x80)
340330 sprintf(buf3, "EA=%4.4X%s D=%4.4X", t->ea, buf_ea, t->data);
341331 insn = "CPX";
@@ -357,36 +347,36 @@ void show_trace(int insn_no, struct trace_entry *t)
357347 sprintf(buf3, "EA=%4.4X%s D=%4.4X", t->ea, buf_ea, t->data);
358348 insn = "STS";
359349 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)
366354 sprintf(buf3, "EA=%4.4X%s", t->ea, buf_ea);
367355 insn = "JSR";
368356 subr = 1;
369357 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)
374362 sprintf(buf3, "EA=%4.4X%s D=%4.4X", t->ea, buf_ea, t->data);
375363 insn = "ADDD";
376364 break;
377365 } 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)
379369 sprintf(buf3, "EA=%4.4X%s D=%4.4X", t->ea, buf_ea, t->data);
380370 insn = "LDD";
381371 break;
382372 } 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)
384376 sprintf(buf3, "EA=%4.4X%s D=%4.4X", t->ea, buf_ea, t->data);
385377 insn = "STD";
386378 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 */ {
390380 if (t->cc & 0x80)
391381 sprintf(buf3, "EA=%4.4X%s D=%4.4X", t->ea, buf_ea, t->data);
392382 insn = "LDX";
@@ -397,6 +387,8 @@ void show_trace(int insn_no, struct trace_entry *t)
397387 insn = "STX";
398388 break;
399389 } default: /* ??? */ {
390+invalid16:
391+fprintf( stderr, "invalid16 from mnemonic: %x\n", t->insn[0] );
400392 goto invalid;
401393 break;
402394 }
@@ -481,17 +473,19 @@ void show_trace(int insn_no, struct trace_entry *t)
481473 case 0x01: /* NOP */ { /* Do nothing */
482474 insn = "NOP";
483475 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";
488481 break;
489482 } case 0x05: /* LSLD N,Z,V,C (6801) */ {
490- insn = "LSLD";
483+ if (cputype == 0x6800)
484+ goto invalidinh;
485+ else
486+ insn = "LSLD";
491487 break;
492- }
493-#endif /* def SIM6801 */
494- case 0x06: /* TAP (all flags) */ {
488+ } case 0x06: /* TAP (all flags) */ {
495489 insn = "TAP";
496490 break;
497491 } case 0x07: /* TPA */ {
@@ -546,18 +540,18 @@ void show_trace(int insn_no, struct trace_entry *t)
546540 sprintf(buf3, "EA=%4.4X%s", t->ea, buf_ea);
547541 insn = "BRA";
548542 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+ }
557553 break;
558- }
559-#endif /* def SIM6801 */
560- case 0x22: /* BHI */ {
554+ } case 0x22: /* BHI */ {
561555 sprintf(buf + strlen(buf), "%2.2X ", t->insn[1]);
562556 sprintf(operand, " %4.4X", t->pc + 2 + (char)t->insn[1]);
563557 if (t->cc & 0x80)
@@ -679,45 +673,46 @@ void show_trace(int insn_no, struct trace_entry *t)
679673 } case 0x37: /* PSHB */ {
680674 insn = "PSHB";
681675 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";
686681 break;
687- }
688-#endif /* def SIM6801 */
689- case 0x39: /* RTS */ {
682+ } case 0x39: /* RTS */ {
690683 insn = "RTS";
691684 subr = 1;
692685 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";
697691 break;
698- }
699-#endif /* def SIM6801 */
700- case 0x3B: /* RTI */ {
692+ } case 0x3B: /* RTI */ {
701693 insn = "RTI";
702694 subr = 1;
703695 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";
708701 break;
709702 } case 0x3D: /* MUL C=accb bit 7 (6801) */ {
710- insn = "MUL";
703+ if (cputype == 0x6800)
704+ goto invalidinh;
705+ else
706+ insn = "MUL";
711707 break;
712- }
713-#endif /* def SIM6801 */
714- case 0x3E: /* WAI */ {
708+ } case 0x3E: /* WAI */ {
715709 insn = "WAI";
716710 break;
717711 } case 0x3F: /* SWI */ {
718712 insn = "SWI";
719713 break;
720714 } default: /* ??? */ {
715+invalidinh:
721716 goto invalid;
722717 break;
723718 }
@@ -775,11 +770,9 @@ void sim(void)
775770 unsigned char b;
776771 unsigned char f;
777772 unsigned char data;
778-#ifdef SIM6801
779773 unsigned short accd;
780774 #define setACCD( val ) ( val = ( ( (unsigned int) acca ) << 8 ) | ( (unsigned char) accb ) )
781775 #define restoreACCM( res ) ( acca = (unsigned char) ( (res) >> 8 ), accb = ( (unsigned char) (res) ) )
782-#endif /* def SIM6801 */
783776 unsigned short w;
784777 unsigned short fw;
785778 int wb;
@@ -859,11 +852,8 @@ void sim(void)
859852 opcode = fetch();
860853
861854 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)) ) {
867857 /* Get operand A */
868858 if (opcode & 0x40) {
869859 a = accb;
@@ -919,14 +909,12 @@ void sim(void)
919909 n_flag = N(f);
920910 z_flag = Z(f);
921911 break;
922- }
923-#ifndef SIM6801
924- case 0x03: /* ??? */ {
912+ } case 0x03: /* ??? */ {
913+ if (cputype == 0x6801)
914+ fprintf( stderr, "Internal error on SUBD (6801)\n" );
925915 goto invalid;
926916 break;
927- }
928-#endif /* ndef SIM6801 */
929- case 0x04: /* AND N,Z,V=0 */ {
917+ } case 0x04: /* AND N,Z,V=0 */ {
930918 f = (a & b);
931919 n_flag = N(f);
932920 z_flag = Z(f);
@@ -1006,35 +994,36 @@ void sim(void)
1006994 }
1007995 }
1008996 switch (opcode) {
1009-#ifdef SIM6801
1010997 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+ }
10201013 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 */ {
10241015 w = mread2(ea);
10251016 t->ea = ea; t->data = w;
10261017 fw = ix - w;
10271018 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+ }
10381027 break;
10391028 } case 0x8D: /* BSR REL */ {
10401029 push2(pc - 1);
@@ -1055,46 +1044,56 @@ void sim(void)
10551044 v_flag = 0;
10561045 break;
10571046 }
1058-#ifdef SIM6801
10591047 case 0x9D: /* (6801) */
1060-#endif /* def SIM6801 */
10611048 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+ }
10651056 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+ }
10781071 break;
10791072 } 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+ }
10861083 break;
10871084 } 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+ }
10941095 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 */ {
10981097 ix = mread2(ea);
10991098 t->ea = ea; t->data = ix;
11001099 z_flag = Z_16(ix);
@@ -1109,6 +1108,9 @@ void sim(void)
11091108 v_flag = 0;
11101109 break;
11111110 } default: /* ??? */ {
1111+invalid16:
1112+fprintf( stderr, "invalid16 from opcode: %x => %x\n", t->insn[0], opcode );
1113+
11121114 goto invalid;
11131115 break;
11141116 }
@@ -1250,31 +1252,35 @@ void sim(void)
12501252 switch(opcode) {
12511253 case 0x01: /* NOP */ { /* Do nothing */
12521254 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+ }
12641268 break;
12651269 } 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+ }
12741282 break;
1275- }
1276-#endif /* def SIM6801 */
1277- case 0x06: /* TAP (all flags) */ {
1283+ } case 0x06: /* TAP (all flags) */ {
12781284 write_flags(acca);
12791285 break;
12801286 } case 0x07: /* TPA */ {
@@ -1360,15 +1366,15 @@ void sim(void)
13601366 offset = fetch();
13611367 jump(t->ea = (pc + offset));
13621368 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+ }
13681376 break;
1369- }
1370-#endif /* def SIM6801 */
1371- case 0x22: /* BHI */ {
1377+ } case 0x22: /* BHI */ {
13721378 offset = fetch();
13731379 t->ea = pc + offset;
13741380 if (!(c_flag | z_flag))
@@ -1476,48 +1482,52 @@ void sim(void)
14761482 } case 0x37: /* PSHB */ {
14771483 push(accb);
14781484 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+ }
14831491 break;
1484- }
1485-#endif /* def SIM6801 */
1486- case 0x39: /* RTS */ {
1492+ } case 0x39: /* RTS */ {
14871493 if (sp == sp_stop) {
14881494 stop = 1;
14891495 sp_stop = -1;
14901496 } else
14911497 jump(pull2());
14921498 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+ }
14971505 break;
1498- }
1499-#endif /* def SIM6801 */
1500- case 0x3B: /* RTI */ {
1506+ } case 0x3B: /* RTI */ {
15011507 write_flags(pull());
15021508 accb = pull();
15031509 acca = pull();
15041510 ix = pull2();
15051511 jump(pull2());
15061512 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+ }
15111519 break;
15121520 } 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+ }
15171529 break;
1518- }
1519-#endif /* def SIM6801 */
1520- case 0x3E: /* WAI */ {
1530+ } case 0x3E: /* WAI */ {
15211531 printf("WAI encountered...\n");
15221532 return;
15231533 break;
@@ -1530,6 +1540,7 @@ void sim(void)
15301540 jump(mread2(0xFFFA));
15311541 break;
15321542 } default: /* ??? */ {
1543+invalidinh:
15331544 goto invalid;
15341545 break;
15351546 }