Fix more issues
authorNick Downing <nick@ndcode.org>
Mon, 25 Jul 2022 07:29:24 +0000 (17:29 +1000)
committerNick Downing <nick@ndcode.org>
Mon, 25 Jul 2022 07:29:24 +0000 (17:29 +1000)
cpu_6800.c
cpu_6800.h
decode_6800.sed
instr_6800.txt
sim68xx

index 1a9c43e..ad77599 100644 (file)
@@ -119,7 +119,7 @@ void cpu_6800_execute(struct cpu_6800 *self) {
     cpu_6800_ill(self);
     break;
   case 0x16:
-    cpu_6800_lda(self, CPU_6800_EA_A, self->regs.byte.a);
+    cpu_6800_lda(self, CPU_6800_EA_B, self->regs.byte.a);
     break;
   case 0x17:
     cpu_6800_lda(self, CPU_6800_EA_A, self->regs.byte.b);
@@ -284,7 +284,7 @@ void cpu_6800_execute(struct cpu_6800 *self) {
     cpu_6800_inc(self, CPU_6800_EA_A);
     break;
   case 0x4d:
-    cpu_6800_tst(self, self->regs.byte.a);
+    cpu_6800_cmp(self, self->regs.byte.a, 0);
     break;
   case 0x4e:
     cpu_6800_ill(self);
@@ -332,7 +332,7 @@ void cpu_6800_execute(struct cpu_6800 *self) {
     cpu_6800_inc(self, CPU_6800_EA_B);
     break;
   case 0x5d:
-    cpu_6800_tst(self, self->regs.byte.b);
+    cpu_6800_cmp(self, self->regs.byte.b, 0);
     break;
   case 0x5e:
     cpu_6800_ill(self);
@@ -380,7 +380,7 @@ void cpu_6800_execute(struct cpu_6800 *self) {
     cpu_6800_inc(self, cpu_6800_ea_direct_indexed(self, self->regs.word.x));
     break;
   case 0x6d:
-    cpu_6800_tst(self, cpu_6800_read_byte(self, cpu_6800_ea_direct_indexed(self, self->regs.word.x)));
+    cpu_6800_cmp(self, cpu_6800_read_byte(self, cpu_6800_ea_direct_indexed(self, self->regs.word.x)), 0);
     break;
   case 0x6e:
     cpu_6800_jmp(self, cpu_6800_ea_direct_indexed(self, self->regs.word.x));
@@ -428,7 +428,7 @@ void cpu_6800_execute(struct cpu_6800 *self) {
     cpu_6800_inc(self, cpu_6800_ea_extended(self));
     break;
   case 0x7d:
-    cpu_6800_tst(self, cpu_6800_read_byte(self, cpu_6800_ea_extended(self)));
+    cpu_6800_cmp(self, cpu_6800_read_byte(self, cpu_6800_ea_extended(self)), 0);
     break;
   case 0x7e:
     cpu_6800_jmp(self, cpu_6800_ea_extended(self));
@@ -689,10 +689,10 @@ void cpu_6800_execute(struct cpu_6800 *self) {
     cpu_6800_ill(self);
     break;
   case 0xd4:
-    cpu_6800_and(self, CPU_6800_EA_A, cpu_6800_read_byte(self, cpu_6800_ea_direct(self)));
+    cpu_6800_and(self, CPU_6800_EA_B, cpu_6800_read_byte(self, cpu_6800_ea_direct(self)));
     break;
   case 0xd5:
-    cpu_6800_bit(self, CPU_6800_EA_A, cpu_6800_read_byte(self, cpu_6800_ea_direct(self)));
+    cpu_6800_bit(self, CPU_6800_EA_B, cpu_6800_read_byte(self, cpu_6800_ea_direct(self)));
     break;
   case 0xd6:
     cpu_6800_lda(self, CPU_6800_EA_B, cpu_6800_read_byte(self, cpu_6800_ea_direct(self)));
@@ -737,10 +737,10 @@ void cpu_6800_execute(struct cpu_6800 *self) {
     cpu_6800_ill(self);
     break;
   case 0xe4:
-    cpu_6800_and(self, CPU_6800_EA_A, cpu_6800_read_byte(self, cpu_6800_ea_direct_indexed(self, self->regs.word.x)));
+    cpu_6800_and(self, CPU_6800_EA_B, cpu_6800_read_byte(self, cpu_6800_ea_direct_indexed(self, self->regs.word.x)));
     break;
   case 0xe5:
-    cpu_6800_bit(self, CPU_6800_EA_A, cpu_6800_read_byte(self, cpu_6800_ea_direct_indexed(self, self->regs.word.x)));
+    cpu_6800_bit(self, CPU_6800_EA_B, cpu_6800_read_byte(self, cpu_6800_ea_direct_indexed(self, self->regs.word.x)));
     break;
   case 0xe6:
     cpu_6800_lda(self, CPU_6800_EA_B, cpu_6800_read_byte(self, cpu_6800_ea_direct_indexed(self, self->regs.word.x)));
@@ -785,10 +785,10 @@ void cpu_6800_execute(struct cpu_6800 *self) {
     cpu_6800_ill(self);
     break;
   case 0xf4:
-    cpu_6800_and(self, CPU_6800_EA_A, cpu_6800_read_byte(self, cpu_6800_ea_extended(self)));
+    cpu_6800_and(self, CPU_6800_EA_B, cpu_6800_read_byte(self, cpu_6800_ea_extended(self)));
     break;
   case 0xf5:
-    cpu_6800_bit(self, CPU_6800_EA_A, cpu_6800_read_byte(self, cpu_6800_ea_extended(self)));
+    cpu_6800_bit(self, CPU_6800_EA_B, cpu_6800_read_byte(self, cpu_6800_ea_extended(self)));
     break;
   case 0xf6:
     cpu_6800_lda(self, CPU_6800_EA_B, cpu_6800_read_byte(self, cpu_6800_ea_extended(self)));
index 14c7478..a7a9400 100644 (file)
@@ -207,7 +207,9 @@ static ALWAYS_INLINE int cpu_6800_ea_direct(struct cpu_6800 *self) {
 }
 
 static ALWAYS_INLINE int cpu_6800_ea_direct_indexed(struct cpu_6800 *self, int rvalue) {
-  return (cpu_6800_ea_direct(self) + rvalue) & 0xff;
+  int addr = cpu_6800_ea_direct(self);
+  self->cycles += ((addr & 0xff) + (rvalue & 0xff)) >> 8;
+  return addr + rvalue;
 }
 
 // instruction execute
@@ -241,8 +243,9 @@ static ALWAYS_INLINE void cpu_6800_and(struct cpu_6800 *self, int lvalue, int rv
   int result = cpu_6800_read_byte(self, lvalue) & rvalue;
 
   cpu_6800_write_byte(self, lvalue, result);
-  self->regs.bit.zf = result == 0;
   self->regs.bit.nf = result >> 7;
+  self->regs.bit.zf = result == 0;
+  self->regs.bit.vf = false;
 }
 
 static ALWAYS_INLINE void cpu_6800_asr(struct cpu_6800 *self, int lvalue) {
@@ -289,6 +292,11 @@ static ALWAYS_INLINE void cpu_6800_cl(struct cpu_6800 *self, int n) {
 
 static ALWAYS_INLINE void cpu_6800_clr(struct cpu_6800 *self, int lvalue) {
   cpu_6800_write_byte(self, lvalue, 0);
+
+  self->regs.bit.nf = false;
+  self->regs.bit.zf = true;
+  self->regs.bit.vf = false;
+  self->regs.bit.cf = false;
 }
 
 static ALWAYS_INLINE void cpu_6800_cmp(struct cpu_6800 *self, int rvalue0, int rvalue1) {
@@ -342,8 +350,9 @@ static ALWAYS_INLINE void cpu_6800_eor(struct cpu_6800 *self, int lvalue, int rv
   int result = cpu_6800_read_byte(self, lvalue) ^ rvalue;
 
   cpu_6800_write_byte(self, lvalue, result);
-  self->regs.bit.zf = result == 0;
   self->regs.bit.nf = result >> 7;
+  self->regs.bit.zf = result == 0;
+  self->regs.bit.vf = false;
 }
 
 static ALWAYS_INLINE void cpu_6800_ill(struct cpu_6800 *self) {
@@ -441,8 +450,9 @@ static ALWAYS_INLINE void cpu_6800_ora(struct cpu_6800 *self, int lvalue, int rv
   int result = cpu_6800_read_byte(self, lvalue) | rvalue;
 
   cpu_6800_write_byte(self, lvalue, result);
-  self->regs.bit.zf = result == 0;
   self->regs.bit.nf = result >> 7;
+  self->regs.bit.zf = result == 0;
+  self->regs.bit.vf = false;
 }
 
 //static ALWAYS_INLINE void cpu_6800_plp(struct cpu_6800 *self) {
index 86ea6d3..8903cf2 100644 (file)
@@ -28,8 +28,9 @@ s/cpu_6800_de\([xs]\)(self/cpu_6800_de(self, CPU_6800_EA_\1/
 s/cpu_6800_cp\([xs]\)(self\(.*\)byte/cpu_6800_cp(self, self->regs.word.\1\2word/
 s/cpu_6800_cp\([xs]\)(self/cpu_6800_cp(self, self->regs.word.\1/
 s/cpu_6800_swi(self/cpu_6800_swi(self, CPU_6800_SWI_VECTOR/
+s/cpu_6800_tst(self\(.*\));/cpu_6800_cmp(self\1, 0);/
 s/CPU_6800_EA_a/CPU_6800_EA_A/g
-s/CPU_6800_EA_b/CPU_6800_EA_A/g
+s/CPU_6800_EA_b/CPU_6800_EA_B/g
 s/CPU_6800_EA_x/CPU_6800_EA_X/g
 s/CPU_6800_EA_s/CPU_6800_EA_S/g
 s/CPU_6800_REG_P_BIT_c/CPU_6800_REG_P_BIT_C/g
index 0f2af54..d440a9d 100644 (file)
 0100   d1 12           cmpb 12
 0100   d2 12           sbcb 12
 0100   d3 12           ---
-0100   d4 12           anda 12
-0100   d5 12           bita 12
+0100   d4 12           andb 12
+0100   d5 12           bitb 12
 0100   d6 12           ldab 12
 0100   d7 12           stab 12
 0100   d8 12           eorb 12
 0100   e1 12           cmpb 12,x
 0100   e2 12           sbcb 12,x
 0100   e3 12           ---
-0100   e4 12           anda 12,x
-0100   e5 12           bita 12,x
+0100   e4 12           andb 12,x
+0100   e5 12           bitb 12,x
 0100   e6 12           ldab 12,x
 0100   e7 12           stab 12,x
 0100   e8 12           eorb 12,x
 0100   f1 12 34        cmpb 1234
 0100   f2 12 34        sbcb 1234
 0100   f3 12 34        ---
-0100   f4 12 34        anda 1234
-0100   f5 12 34        bita 1234
+0100   f4 12 34        andb 1234
+0100   f5 12 34        bitb 1234
 0100   f6 12 34        ldab 1234
 0100   f7 12 34        stab 1234
 0100   f8 12 34        eorb 1234
diff --git a/sim68xx b/sim68xx
index d05bafb..706f5f8 160000 (submodule)
--- a/sim68xx
+++ b/sim68xx
@@ -1 +1 @@
-Subproject commit d05bafbe581ab92e42e2b0d68e5500c45f4159fc
+Subproject commit 706f5f8076336bc722a0ea3e51ed489587f18d68