From 1dfc78b8bf5b708cb1118a9d6646397772a1b894 Mon Sep 17 00:00:00 2001 From: mrb0nk500 Date: Tue, 24 Dec 2019 22:18:32 -0500 Subject: Added support for Indirect addressing modes, and allow for use of the B register as an operand, for ALU based instructions. This allows for both low code size, and high performance. This means we can save upto 9 bytes, by just using the B register for ALU operations, rather than using a memory address. The indirect addressing modes, give Sux the abillity to now use pointers. Hope you guys have a Merry Christmas! From mr b0nk 500 --- sux.c | 1264 ++++++++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 734 insertions(+), 530 deletions(-) (limited to 'sux.c') diff --git a/sux.c b/sux.c index 0b8da2e..85280c1 100644 --- a/sux.c +++ b/sux.c @@ -5,8 +5,8 @@ #include #include #define bench 0 -#define debug 0 -#define IO 1 +#define debug 1 +#define IO 0 #define keypoll 0 #if bench #include @@ -90,7 +90,7 @@ void *run(void *args) { kbd_rdy &= (uint8_t)~(1 << thread); } prefix = addr[cpu->pc[thread]]; - if ((prefix & 0x07) == 0x07) + if ((prefix & 0x0F) == 0x07) cpu->pc[thread]++; else prefix = 0; @@ -132,45 +132,50 @@ void *run(void *args) { cpu->ps &= 0; break; case ADC: /* ADC Immediate. */ + case AAB: /* Add Accumulator with carry by B register. */ case 0x03: /* ADC Absolute. */ case 0x05: /* ADC Zero Matrix. */ - if (opcode == ADC) { - address = cpu->pc[thread]; - cpu->pc[thread]+=regsize; - } - if (opcode == 0x03) { - address = (uint64_t)addr[cpu->pc[thread]] - | (uint64_t)addr[cpu->pc[thread]+1] << 8 - | (uint64_t)addr[cpu->pc[thread]+2] << 16 - | (uint64_t)addr[cpu->pc[thread]+3] << 24 - | (uint64_t)addr[cpu->pc[thread]+4] << 32 - | (uint64_t)addr[cpu->pc[thread]+5] << 40 - | (uint64_t)addr[cpu->pc[thread]+6] << 48 - | (uint64_t)addr[cpu->pc[thread]+7] << 56; - cpu->pc[thread]+=8; - iclk++; - } - if (opcode == 0x05) { - address = addr[cpu->pc[thread]] - | addr[cpu->pc[thread]+1] << 8 - | addr[cpu->pc[thread]+2] << 16 - | addr[cpu->pc[thread]+3] << 24; - cpu->pc[thread]+=4; - iclk++; - } - value = addr[address]; - if (regsize >= 2) { - value += (uint64_t)addr[address+1] << 8; - } - if (regsize >= 4) { - value += (uint64_t)addr[address+2] << 16; - value += (uint64_t)addr[address+3] << 24; - } - if (regsize >= 8) { - value += (uint64_t)addr[address+4] << 32; - value += (uint64_t)addr[address+5] << 40; - value += (uint64_t)addr[address+6] << 48; - value += (uint64_t)addr[address+7] << 56; + if (opcode != AAB) { + if (opcode == ADC) { + address = cpu->pc[thread]; + cpu->pc[thread]+=regsize; + } + if (opcode == 0x03) { + address = (uint64_t)addr[cpu->pc[thread]] + | (uint64_t)addr[cpu->pc[thread]+1] << 8 + | (uint64_t)addr[cpu->pc[thread]+2] << 16 + | (uint64_t)addr[cpu->pc[thread]+3] << 24 + | (uint64_t)addr[cpu->pc[thread]+4] << 32 + | (uint64_t)addr[cpu->pc[thread]+5] << 40 + | (uint64_t)addr[cpu->pc[thread]+6] << 48 + | (uint64_t)addr[cpu->pc[thread]+7] << 56; + cpu->pc[thread]+=8; + iclk++; + } + if (opcode == 0x05) { + address = addr[cpu->pc[thread]] + | addr[cpu->pc[thread]+1] << 8 + | addr[cpu->pc[thread]+2] << 16 + | addr[cpu->pc[thread]+3] << 24; + cpu->pc[thread]+=4; + iclk++; + } + value = addr[address]; + if (regsize >= 2) { + value += (uint64_t)addr[address+1] << 8; + } + if (regsize >= 4) { + value += (uint64_t)addr[address+2] << 16; + value += (uint64_t)addr[address+3] << 24; + } + if (regsize >= 8) { + value += (uint64_t)addr[address+4] << 32; + value += (uint64_t)addr[address+5] << 40; + value += (uint64_t)addr[address+6] << 48; + value += (uint64_t)addr[address+7] << 56; + } + } else { + value = cpu->b[thread]; } sum = cpu->a[thread]+value+cpu->c[thread]; cpu->a[thread] = sum; @@ -183,6 +188,18 @@ void *run(void *args) { (cpu->v[thread]) ? (cpu->ps |= (V << 8*thread)) : (cpu->ps &= ~(V << 8*thread)); (cpu->c[thread]) ? (cpu->ps |= (C << 8*thread)) : (cpu->ps &= ~(C << 8*thread)); break; + case PHB: /* PusH B register to stack. */ + tmp = addr[cpu->pc[thread]++]; + if (tmp > 7) + tmp = 7; + for (int8_t i = tmp*8; i >= 0; i-=8) { + if (i) + addr[(cpu->stk_st[thread] << 16)+cpu->sp[thread]] = (uint64_t)cpu->b[thread] >> i; + else + addr[(cpu->stk_st[thread] << 16)+cpu->sp[thread]] = (uint64_t)cpu->b[thread] & 0xFF; + cpu->sp[thread]--; + } + break; case PHP: /* PusH Processor status to stack. */ tmp = addr[cpu->pc[thread]++]; if (tmp > 7) @@ -301,45 +318,50 @@ void *run(void *args) { cpu->pc[thread] = address; break; case SBC: /* SBC Immediate. */ + case SAB: /* Subtract Accumulator with carry by B register. */ case 0x13: /* SBC Absolute. */ case 0x15: /* SBC Zero Matrix. */ - if (opcode == SBC) { - address = cpu->pc[thread]; - cpu->pc[thread]+=regsize; - } - if (opcode == 0x13) { - address = (uint64_t)addr[cpu->pc[thread]] - | (uint64_t)addr[cpu->pc[thread]+1] << 8 - | (uint64_t)addr[cpu->pc[thread]+2] << 16 - | (uint64_t)addr[cpu->pc[thread]+3] << 24 - | (uint64_t)addr[cpu->pc[thread]+4] << 32 - | (uint64_t)addr[cpu->pc[thread]+5] << 40 - | (uint64_t)addr[cpu->pc[thread]+6] << 48 - | (uint64_t)addr[cpu->pc[thread]+7] << 56; - cpu->pc[thread]+=8; - iclk++; - } - if (opcode == 0x15) { - address = addr[cpu->pc[thread]] - | addr[cpu->pc[thread]+1] << 8 - | addr[cpu->pc[thread]+2] << 16 - | addr[cpu->pc[thread]+3] << 24; - cpu->pc[thread]+=4; - iclk++; - } - value = addr[address]; - if (regsize >= 2) { - value += (uint64_t)addr[address+1] << 8; - } - if (regsize >= 4) { - value += (uint64_t)addr[address+2] << 16; - value += (uint64_t)addr[address+3] << 24; - } - if (regsize >= 8) { - value += (uint64_t)addr[address+4] << 32; - value += (uint64_t)addr[address+5] << 40; - value += (uint64_t)addr[address+6] << 48; - value += (uint64_t)addr[address+7] << 56; + if (opcode != SAB) { + if (opcode == SBC) { + address = cpu->pc[thread]; + cpu->pc[thread]+=regsize; + } + if (opcode == 0x13) { + address = (uint64_t)addr[cpu->pc[thread]] + | (uint64_t)addr[cpu->pc[thread]+1] << 8 + | (uint64_t)addr[cpu->pc[thread]+2] << 16 + | (uint64_t)addr[cpu->pc[thread]+3] << 24 + | (uint64_t)addr[cpu->pc[thread]+4] << 32 + | (uint64_t)addr[cpu->pc[thread]+5] << 40 + | (uint64_t)addr[cpu->pc[thread]+6] << 48 + | (uint64_t)addr[cpu->pc[thread]+7] << 56; + cpu->pc[thread]+=8; + iclk++; + } + if (opcode == 0x15) { + address = addr[cpu->pc[thread]] + | addr[cpu->pc[thread]+1] << 8 + | addr[cpu->pc[thread]+2] << 16 + | addr[cpu->pc[thread]+3] << 24; + cpu->pc[thread]+=4; + iclk++; + } + value = addr[address]; + if (regsize >= 2) { + value += (uint64_t)addr[address+1] << 8; + } + if (regsize >= 4) { + value += (uint64_t)addr[address+2] << 16; + value += (uint64_t)addr[address+3] << 24; + } + if (regsize >= 8) { + value += (uint64_t)addr[address+4] << 32; + value += (uint64_t)addr[address+5] << 40; + value += (uint64_t)addr[address+6] << 48; + value += (uint64_t)addr[address+7] << 56; + } + } else { + value = cpu->b[thread]; } sum = cpu->a[thread]-value-!cpu->c[thread]; cpu->z[thread] = (sum == 0); @@ -352,6 +374,18 @@ void *run(void *args) { (cpu->c[thread]) ? (cpu->ps |= (C << 8*thread)) : (cpu->ps &= ~(C << 8*thread)); cpu->a[thread] = sum; break; + case PLB: /* PuLl B register from stack. */ + tmp = addr[cpu->pc[thread]++]; + if (tmp > 7) + tmp = 7; + for (uint8_t i = 0; i < (tmp+1)*8; i+=8) { + cpu->sp[thread]++; + if (i) + cpu->b[thread] += (uint64_t)addr[(cpu->stk_st[thread] << 16)+cpu->sp[thread]] << i; + else + cpu->b[thread] = (uint64_t)addr[(cpu->stk_st[thread] << 16)+cpu->sp[thread]] & 0xFF; + } + break; case PLP: /* PuLl Processor status from stack. */ tmp = addr[cpu->pc[thread]++]; if (tmp > 7) @@ -400,11 +434,28 @@ void *run(void *args) { cpu->x[thread] = (uint64_t)addr[(cpu->stk_st[thread] << 16)+cpu->sp[thread]] & 0xFF; } break; + case 0x34: /* JSR Indirect. */ + case 0x44: /* JSR Indexed Indirect. */ + case 0x54: /* JSR Indirect Indexed. */ case JSR: /* Jump to SubRoutine. */ address = (uint64_t)addr[cpu->pc[thread]] | (uint64_t)addr[cpu->pc[thread]+1] << 8 | (uint64_t)addr[cpu->pc[thread]+2] << 16 | (uint64_t)addr[cpu->pc[thread]+3] << 24; + if (opcode == 0x34 || opcode == 0x44 || opcode == 0x54) { + address = (uint64_t)addr[address] + | (uint64_t)addr[address+1] << 8 + | (uint64_t)addr[address+2] << 16 + | (uint64_t)addr[address+3] << 24 + | (uint64_t)addr[address+4] << 32 + | (uint64_t)addr[address+5] << 40 + | (uint64_t)addr[address+6] << 48 + | (uint64_t)addr[address+7] << 56; + if (opcode == 0x44) + address += cpu->x[thread]; + if (opcode == 0x54) + address += cpu->y[thread]; + } cpu->pc[thread]+=4; for (int8_t i = 24; i >= 0; i-=8) { if (i) @@ -416,73 +467,54 @@ void *run(void *args) { cpu->pc[thread] = address; break; case AND: /* AND Immediate. */ - case 0x29: /* AND Absolute. */ - case 0x2B: /* AND Zero Matrix. */ - case ANY: /* ANY Immediate. */ - case 0x52: /* ANY Absolute. */ - case 0x82: /* ANY Zero Matrix. */ - case ANX: /* ANX Immediate. */ - case 0x54: /* ANX Absolute. */ - case 0x84: /* ANX Zero Matrix. */ - if (opcode == AND || opcode == ANY || opcode == ANX) { - address = cpu->pc[thread]; - cpu->pc[thread]+=regsize; - } - if (opcode == 0x29 || opcode == 0x52 || opcode == 0x54) { - address = (uint64_t)addr[cpu->pc[thread]] - | (uint64_t)addr[cpu->pc[thread]+1] << 8 - | (uint64_t)addr[cpu->pc[thread]+2] << 16 - | (uint64_t)addr[cpu->pc[thread]+3] << 24 - | (uint64_t)addr[cpu->pc[thread]+4] << 32 - | (uint64_t)addr[cpu->pc[thread]+5] << 40 - | (uint64_t)addr[cpu->pc[thread]+6] << 48 - | (uint64_t)addr[cpu->pc[thread]+7] << 56; - cpu->pc[thread]+=8; - iclk++; - } - if (opcode == 0x2B || opcode == 0x82 || opcode == 0x84) { - address = addr[cpu->pc[thread]] - | addr[cpu->pc[thread]+1] << 8 - | addr[cpu->pc[thread]+2] << 16 - | addr[cpu->pc[thread]+3] << 24; - cpu->pc[thread]+=4; - iclk++; - } - value = (uint64_t)addr[address]; - if (regsize >= 2) - value += (uint64_t)addr[address+1] << 8; - if (regsize >= 4) { - value += (uint64_t)addr[address+2] << 16; - value += (uint64_t)addr[address+3] << 24; - } - if (regsize >= 8) { - value += (uint64_t)addr[address+4] << 32; - value += (uint64_t)addr[address+5] << 40; - value += (uint64_t)addr[address+6] << 48; - value += (uint64_t)addr[address+7] << 56; + case ABA: /* bitwise And with Accumulator, and B register. */ + case 0x23: /* AND Absolute. */ + case 0x25: /* AND Zero Matrix. */ + if (opcode != ABA) { + if (opcode == AND) { + address = cpu->pc[thread]; + cpu->pc[thread]+=regsize; + } + if (opcode == 0x23) { + address = (uint64_t)addr[cpu->pc[thread]] + | (uint64_t)addr[cpu->pc[thread]+1] << 8 + | (uint64_t)addr[cpu->pc[thread]+2] << 16 + | (uint64_t)addr[cpu->pc[thread]+3] << 24 + | (uint64_t)addr[cpu->pc[thread]+4] << 32 + | (uint64_t)addr[cpu->pc[thread]+5] << 40 + | (uint64_t)addr[cpu->pc[thread]+6] << 48 + | (uint64_t)addr[cpu->pc[thread]+7] << 56; + cpu->pc[thread]+=8; + iclk++; + } + if (opcode == 0x25) { + address = addr[cpu->pc[thread]] + | addr[cpu->pc[thread]+1] << 8 + | addr[cpu->pc[thread]+2] << 16 + | addr[cpu->pc[thread]+3] << 24; + cpu->pc[thread]+=4; + iclk++; + } + value = (uint64_t)addr[address]; + if (regsize >= 2) + value += (uint64_t)addr[address+1] << 8; + if (regsize >= 4) { + value += (uint64_t)addr[address+2] << 16; + value += (uint64_t)addr[address+3] << 24; + } + if (regsize >= 8) { + value += (uint64_t)addr[address+4] << 32; + value += (uint64_t)addr[address+5] << 40; + value += (uint64_t)addr[address+6] << 48; + value += (uint64_t)addr[address+7] << 56; + } } - if (opcode == AND || opcode == 0x29 || opcode == 0x2B) - cpu->a[thread] &= value; - if (opcode == ANY || opcode == 0x52 || opcode == 0x82) - cpu->y[thread] &= value; - if (opcode == ANX || opcode == 0x54 || opcode == 0x84) - cpu->x[thread] &= value; + cpu->a[thread] &= value; cpu->z[thread] = (value == 0); cpu->n[thread] = (value >> 63); (cpu->z[thread]) ? (cpu->ps |= (Z << 8*thread)) : (cpu->ps &= ~(Z << 8*thread)); (cpu->n[thread]) ? (cpu->ps |= (N << 8*thread)) : (cpu->ps &= ~(N << 8*thread)); break; - case AAY: - case AAX: - if (opcode == AAY) - cpu->a[thread] &= cpu->y[thread]; - if (opcode == AAX) - cpu->a[thread] &= cpu->x[thread]; - cpu->z[thread] = (sum == 0); - cpu->n[thread] = (sum >> 63); - (cpu->z[thread]) ? (cpu->ps |= (Z << 8*thread)) : (cpu->ps &= ~(Z << 8*thread)); - (cpu->n[thread]) ? (cpu->ps |= (N << 8*thread)) : (cpu->ps &= ~(N << 8*thread)); - break; case STT: /* STart Thread. */ address = cpu->pc[thread]; cpu->pc[thread]++; @@ -502,34 +534,9 @@ void *run(void *args) { } } break; - case BPO: /* Branch if POsitive. */ - address = (uint64_t)addr[cpu->pc[thread]] - | (uint64_t)addr[cpu->pc[thread]+1] << 8 - | (uint64_t)addr[cpu->pc[thread]+2] << 16 - | (uint64_t)addr[cpu->pc[thread]+3] << 24 - | (uint64_t)addr[cpu->pc[thread]+4] << 32 - | (uint64_t)addr[cpu->pc[thread]+5] << 40 - | (uint64_t)addr[cpu->pc[thread]+6] << 48 - | (uint64_t)addr[cpu->pc[thread]+7] << 56; - cpu->pc[thread]+=8; - iclk++; - if (cpu->n[thread]) - cpu->pc[thread] = address; - break; - case ORA: /* ORA Immediate. */ - case 0x39: /* ORA Absolute. */ - case 0x3B: /* ORA Zero Matrix. */ - case ORY: /* ORY Immediate. */ - case 0x62: /* ORY Absolute. */ - case 0x92: /* ORY Zero Matrix. */ - case ORX: /* ORX Immediate. */ - case 0x64: /* ORX Absolute. */ - case 0x94: /* ORX Zero Matrix. */ - if (opcode == ORA || opcode == ORY || opcode == ORX) { - address = cpu->pc[thread]; - cpu->pc[thread]+=regsize; - } - if (opcode == 0x39 || opcode == 0x62 || opcode == 0x64) { + case BPO: /* BPO Absolute. */ + case 0x64: /* BPO Zero Matrix. */ + if (opcode == BPO) { address = (uint64_t)addr[cpu->pc[thread]] | (uint64_t)addr[cpu->pc[thread]+1] << 8 | (uint64_t)addr[cpu->pc[thread]+2] << 16 @@ -540,8 +547,7 @@ void *run(void *args) { | (uint64_t)addr[cpu->pc[thread]+7] << 56; cpu->pc[thread]+=8; iclk++; - } - if (opcode == 0x3B || opcode == 0x92 || opcode == 0x94) { + } else { address = addr[cpu->pc[thread]] | addr[cpu->pc[thread]+1] << 8 | addr[cpu->pc[thread]+2] << 16 @@ -549,73 +555,67 @@ void *run(void *args) { cpu->pc[thread]+=4; iclk++; } - value = (uint64_t)addr[address]; - if (regsize >= 2) - value += (uint64_t)addr[address+1] << 8; - if (regsize >= 4) { - value += (uint64_t)addr[address+2] << 16; - value += (uint64_t)addr[address+3] << 24; - } - if (regsize >= 8) { - value += (uint64_t)addr[address+4] << 32; - value += (uint64_t)addr[address+5] << 40; - value += (uint64_t)addr[address+6] << 48; - value += (uint64_t)addr[address+7] << 56; + if (cpu->n[thread]) + cpu->pc[thread] = address; + break; + case ORA: /* ORA Immediate. */ + case OAB: /* bitwise Or with Accumulator, and B register. */ + case 0x33: /* ORA Absolute. */ + case 0x35: /* ORA Zero Matrix. */ + if (opcode != OAB) { + if (opcode == ORA) { + address = cpu->pc[thread]; + cpu->pc[thread]+=regsize; + } + if (opcode == 0x39) { + address = (uint64_t)addr[cpu->pc[thread]] + | (uint64_t)addr[cpu->pc[thread]+1] << 8 + | (uint64_t)addr[cpu->pc[thread]+2] << 16 + | (uint64_t)addr[cpu->pc[thread]+3] << 24 + | (uint64_t)addr[cpu->pc[thread]+4] << 32 + | (uint64_t)addr[cpu->pc[thread]+5] << 40 + | (uint64_t)addr[cpu->pc[thread]+6] << 48 + | (uint64_t)addr[cpu->pc[thread]+7] << 56; + cpu->pc[thread]+=8; + iclk++; + } + if (opcode == 0x3B) { + address = addr[cpu->pc[thread]] + | addr[cpu->pc[thread]+1] << 8 + | addr[cpu->pc[thread]+2] << 16 + | addr[cpu->pc[thread]+3] << 24; + cpu->pc[thread]+=4; + iclk++; + } + value = (uint64_t)addr[address]; + if (regsize >= 2) + value += (uint64_t)addr[address+1] << 8; + if (regsize >= 4) { + value += (uint64_t)addr[address+2] << 16; + value += (uint64_t)addr[address+3] << 24; + } + if (regsize >= 8) { + value += (uint64_t)addr[address+4] << 32; + value += (uint64_t)addr[address+5] << 40; + value += (uint64_t)addr[address+6] << 48; + value += (uint64_t)addr[address+7] << 56; + } + } else { + value = cpu->b[thread]; } - if (opcode == ORA || opcode == 0x39 || opcode == 0x3B) - cpu->a[thread] |= value; - if (opcode == ORY || opcode == 0x62 || opcode == 0x92) - cpu->y[thread] |= value; - if (opcode == ORX || opcode == 0x64 || opcode == 0x94) - cpu->x[thread] |= value; + cpu->a[thread] |= value; cpu->z[thread] = (value == 0); cpu->n[thread] = (value >> 63); (cpu->z[thread]) ? (cpu->ps |= (Z << 8*thread)) : (cpu->ps &= ~(Z << 8*thread)); (cpu->n[thread]) ? (cpu->ps |= (N << 8*thread)) : (cpu->ps &= ~(N << 8*thread)); break; - case OAY: - case OAX: - if (opcode == OAY) - cpu->a[thread] |= cpu->y[thread]; - if (opcode == OAX) - cpu->a[thread] |= cpu->x[thread]; - cpu->z[thread] = (sum == 0); - cpu->n[thread] = (sum >> 63); - (cpu->z[thread]) ? (cpu->ps |= (Z << 8*thread)) : (cpu->ps &= ~(Z << 8*thread)); - (cpu->n[thread]) ? (cpu->ps |= (N << 8*thread)) : (cpu->ps &= ~(N << 8*thread)); - break; case SEI: /* SEt Interrupt. */ cpu->i[thread] = 1; (cpu->ps |= (I << 8*thread)); break; - case BNG: /* Branch if NeGative. */ - address = (uint64_t)addr[cpu->pc[thread]] - | (uint64_t)addr[cpu->pc[thread]+1] << 8 - | (uint64_t)addr[cpu->pc[thread]+2] << 16 - | (uint64_t)addr[cpu->pc[thread]+3] << 24 - | (uint64_t)addr[cpu->pc[thread]+4] << 32 - | (uint64_t)addr[cpu->pc[thread]+5] << 40 - | (uint64_t)addr[cpu->pc[thread]+6] << 48 - | (uint64_t)addr[cpu->pc[thread]+7] << 56; - cpu->pc[thread]+=8; - iclk++; - if (!cpu->n[thread]) - cpu->pc[thread] = address; - break; - case XOR: /* XOR Immediate. */ - case 0x49: /* XOR Absolute. */ - case 0x4B: /* XOR Zero Matrix. */ - case XRY: /* XRY Immediate. */ - case 0x72: /* XRY Absolute. */ - case 0xA2: /* XRY Zero Matrix. */ - case XRX: /* XRX Immediate. */ - case 0x74: /* XRX Absolute. */ - case 0xA4: /* XRX Zero Matrix. */ - if (opcode == XOR || opcode == XRY || opcode == XRX) { - address = cpu->pc[thread]; - cpu->pc[thread]+=regsize; - } - if (opcode == 0x49 || opcode == 0x72 || opcode == 0x74) { + case BNG: /* BNG Absolute. */ + case 0x74: /* BNG Zero Matrix. */ + if (opcode == BNG) { address = (uint64_t)addr[cpu->pc[thread]] | (uint64_t)addr[cpu->pc[thread]+1] << 8 | (uint64_t)addr[cpu->pc[thread]+2] << 16 @@ -626,8 +626,7 @@ void *run(void *args) { | (uint64_t)addr[cpu->pc[thread]+7] << 56; cpu->pc[thread]+=8; iclk++; - } - if (opcode == 0x4B || opcode == 0xA2 || opcode == 0xA4) { + } else { address = addr[cpu->pc[thread]] | addr[cpu->pc[thread]+1] << 8 | addr[cpu->pc[thread]+2] << 16 @@ -635,67 +634,67 @@ void *run(void *args) { cpu->pc[thread]+=4; iclk++; } - value = (uint64_t)addr[address]; - if (regsize >= 2) - value += (uint64_t)addr[address+1] << 8; - if (regsize >= 4) { - value += (uint64_t)addr[address+2] << 16; - value += (uint64_t)addr[address+3] << 24; - } - if (regsize >= 8) { - value += (uint64_t)addr[address+4] << 32; - value += (uint64_t)addr[address+5] << 40; - value += (uint64_t)addr[address+6] << 48; - value += (uint64_t)addr[address+7] << 56; + if (!cpu->n[thread]) + cpu->pc[thread] = address; + break; + case XOR: /* XOR Immediate. */ + case XAB: /* bitwise Xor with Accumulator, and B register. */ + case 0x43: /* XOR Absolute. */ + case 0x45: /* XOR Zero Matrix. */ + if (opcode != XAB) { + if (opcode == XOR) { + address = cpu->pc[thread]; + cpu->pc[thread]+=regsize; + } + if (opcode == 0x49) { + address = (uint64_t)addr[cpu->pc[thread]] + | (uint64_t)addr[cpu->pc[thread]+1] << 8 + | (uint64_t)addr[cpu->pc[thread]+2] << 16 + | (uint64_t)addr[cpu->pc[thread]+3] << 24 + | (uint64_t)addr[cpu->pc[thread]+4] << 32 + | (uint64_t)addr[cpu->pc[thread]+5] << 40 + | (uint64_t)addr[cpu->pc[thread]+6] << 48 + | (uint64_t)addr[cpu->pc[thread]+7] << 56; + cpu->pc[thread]+=8; + iclk++; + } + if (opcode == 0x4B) { + address = addr[cpu->pc[thread]] + | addr[cpu->pc[thread]+1] << 8 + | addr[cpu->pc[thread]+2] << 16 + | addr[cpu->pc[thread]+3] << 24; + cpu->pc[thread]+=4; + iclk++; + } + value = (uint64_t)addr[address]; + if (regsize >= 2) + value += (uint64_t)addr[address+1] << 8; + if (regsize >= 4) { + value += (uint64_t)addr[address+2] << 16; + value += (uint64_t)addr[address+3] << 24; + } + if (regsize >= 8) { + value += (uint64_t)addr[address+4] << 32; + value += (uint64_t)addr[address+5] << 40; + value += (uint64_t)addr[address+6] << 48; + value += (uint64_t)addr[address+7] << 56; + } + } else { + value = cpu->b[thread]; } - if (opcode == XOR || opcode == 0x49 || opcode == 0x4B) - cpu->a[thread] ^= value; - if (opcode == ORY || opcode == 0x72 || opcode == 0xA2) - cpu->y[thread] ^= value; - if (opcode == ORX || opcode == 0x74 || opcode == 0xA4) - cpu->x[thread] ^= value; + cpu->a[thread] ^= value; cpu->z[thread] = (value == 0); cpu->n[thread] = (value >> 63); (cpu->z[thread]) ? (cpu->ps |= (Z << 8*thread)) : (cpu->ps &= ~(Z << 8*thread)); (cpu->n[thread]) ? (cpu->ps |= (N << 8*thread)) : (cpu->ps &= ~(N << 8*thread)); break; - case XAY: - case XAX: - if (opcode == XAY) - cpu->a[thread] ^= cpu->y[thread]; - if (opcode == XAX) - cpu->a[thread] ^= cpu->x[thread]; - cpu->z[thread] = (sum == 0); - cpu->n[thread] = (sum >> 63); - (cpu->z[thread]) ? (cpu->ps |= (Z << 8*thread)) : (cpu->ps &= ~(Z << 8*thread)); - (cpu->n[thread]) ? (cpu->ps |= (N << 8*thread)) : (cpu->ps &= ~(N << 8*thread)); - break; case CLI: /* CLear Interrupt. */ cpu->i[thread] = 0; (cpu->ps &= ~(I << 8*thread)); break; - case BCS: /* Branch if Carry Set. */ - address = (uint64_t)addr[cpu->pc[thread]] - | (uint64_t)addr[cpu->pc[thread]+1] << 8 - | (uint64_t)addr[cpu->pc[thread]+2] << 16 - | (uint64_t)addr[cpu->pc[thread]+3] << 24 - | (uint64_t)addr[cpu->pc[thread]+4] << 32 - | (uint64_t)addr[cpu->pc[thread]+5] << 40 - | (uint64_t)addr[cpu->pc[thread]+6] << 48 - | (uint64_t)addr[cpu->pc[thread]+7] << 56; - cpu->pc[thread]+=8; - iclk++; - if (cpu->c[thread]) - cpu->pc[thread] = address; - break; - case LSL: /* LSL Immediate. */ - case 0x53: /* LSL Absolute. */ - case 0x55: /* LSL Zero Matrix. */ - if (opcode == LSL) { - address = cpu->pc[thread]; - cpu->pc[thread]++; - } - if (opcode == 0x53) { + case BCS: /* BCS Absolute. */ + case 0x84: /* BCS Zero Matrix. */ + if (opcode == BCS) { address = (uint64_t)addr[cpu->pc[thread]] | (uint64_t)addr[cpu->pc[thread]+1] << 8 | (uint64_t)addr[cpu->pc[thread]+2] << 16 @@ -704,11 +703,9 @@ void *run(void *args) { | (uint64_t)addr[cpu->pc[thread]+5] << 40 | (uint64_t)addr[cpu->pc[thread]+6] << 48 | (uint64_t)addr[cpu->pc[thread]+7] << 56; - cpu->pc[thread]+=8; iclk++; - } - if (opcode == 0x55) { + } else { address = addr[cpu->pc[thread]] | addr[cpu->pc[thread]+1] << 8 | addr[cpu->pc[thread]+2] << 16 @@ -716,7 +713,43 @@ void *run(void *args) { cpu->pc[thread]+=4; iclk++; } - value = addr[address]; + if (cpu->c[thread]) + cpu->pc[thread] = address; + break; + case LSL: /* LSL Immediate. */ + case LLB: /* Logical shift Left accumulator by B. */ + case 0x53: /* LSL Absolute. */ + case 0x55: /* LSL Zero Matrix. */ + if (opcode != LLB) { + if (opcode == LSL) { + address = cpu->pc[thread]; + cpu->pc[thread]++; + } + if (opcode == 0x53) { + address = (uint64_t)addr[cpu->pc[thread]] + | (uint64_t)addr[cpu->pc[thread]+1] << 8 + | (uint64_t)addr[cpu->pc[thread]+2] << 16 + | (uint64_t)addr[cpu->pc[thread]+3] << 24 + | (uint64_t)addr[cpu->pc[thread]+4] << 32 + | (uint64_t)addr[cpu->pc[thread]+5] << 40 + | (uint64_t)addr[cpu->pc[thread]+6] << 48 + | (uint64_t)addr[cpu->pc[thread]+7] << 56; + + cpu->pc[thread]+=8; + iclk++; + } + if (opcode == 0x55) { + address = addr[cpu->pc[thread]] + | addr[cpu->pc[thread]+1] << 8 + | addr[cpu->pc[thread]+2] << 16 + | addr[cpu->pc[thread]+3] << 24; + cpu->pc[thread]+=4; + iclk++; + } + value = addr[address]; + } else { + value = cpu->b[thread]; + } sum = (value < 64) ? cpu->a[thread] << value : 0; cpu->z[thread] = (sum == 0); cpu->n[thread] = (sum >> 63); @@ -733,14 +766,28 @@ void *run(void *args) { case STA: /* STA Absolute. */ case STY: /* STY Absolute. */ case STX: /* STX Absolute. */ + case STB: /* STB Absolute. */ case 0x7B: /* STA Zero Matrix. */ case 0x7D: /* STY Zero Matrix. */ case 0x7E: /* STX Zero Matrix. */ + case 0x7F: /* STB Zero Matrix. */ case 0x8B: /* STA Zero Matrix, Indexed with X. */ case 0x8D: /* STY Zero Matrix, Indexed with X. */ + case 0x8F: /* STA Zero Matrix, Indexed with X. */ case 0x9B: /* STA Zero Matrix, Indexed with Y. */ case 0x9E: /* STX Zero Matrix, Indexed with Y. */ - if (opcode == STA || opcode == STY || opcode == STX) { + case 0x9F: /* STA Zero Matrix, Indexed with Y. */ + case 0xAB: /* STA Indirect. */ + case 0xAD: /* STY Indirect. */ + case 0xAE: /* STX Indirect. */ + case 0xAF: /* STB Indirect. */ + case 0xBB: /* STA Indexed Indirect. */ + case 0xBD: /* STY Indexed Indirect. */ + case 0xBF: /* STB Indexed Indirect. */ + case 0xCB: /* STA Indirect Indexed. */ + case 0xCE: /* STX Indirect Indexed. */ + case 0xCF: /* STB Indirect Indexed. */ + if (opcode == STA || opcode == STY || opcode == STX || opcode == STB) { address = (uint64_t)addr[cpu->pc[thread]] | (uint64_t)addr[cpu->pc[thread]+1] << 8 | (uint64_t)addr[cpu->pc[thread]+2] << 16 @@ -751,15 +798,27 @@ void *run(void *args) { | (uint64_t)addr[cpu->pc[thread]+7] << 56; cpu->pc[thread]+=8; iclk++; - } - if (opcode == 0x7B || opcode == 0x7D || opcode == 0x7E || opcode == 0x8B || opcode == 0x8D || opcode == 0x9B || opcode == 0x9E) { + } else { address = addr[cpu->pc[thread]] | addr[cpu->pc[thread]+1] << 8 | addr[cpu->pc[thread]+2] << 16 | addr[cpu->pc[thread]+3] << 24; - if (opcode == 0x8B || opcode == 0x8D) + if (opcode == 0xAB || opcode == 0xAD || opcode == 0xAE || opcode == 0xAF || opcode == 0xBB || + opcode == 0xBD || opcode == 0xBF || opcode == 0xCB || opcode == 0xCE || opcode == 0xCF) { + address = (uint64_t)addr[address] + | (uint64_t)addr[address+1] << 8 + | (uint64_t)addr[address+2] << 16 + | (uint64_t)addr[address+3] << 24 + | (uint64_t)addr[address+4] << 32 + | (uint64_t)addr[address+5] << 40 + | (uint64_t)addr[address+6] << 48 + | (uint64_t)addr[address+7] << 56; + } + if (opcode == 0x8B || opcode == 0x8D || opcode == 0x8F || + opcode == 0xBB || opcode == 0xBD || opcode == 0xBF) address += cpu->x[thread]; - if (opcode == 0x9B || opcode == 0x9E) + if (opcode == 0x9B || opcode == 0x9E || opcode == 0x9F || + opcode == 0xCB || opcode == 0xCE || opcode == 0xCF) address += cpu->y[thread]; cpu->pc[thread]+=4; iclk++; @@ -770,6 +829,8 @@ void *run(void *args) { value = cpu->y[thread]; if (opcode == STX || opcode == 0x7E || opcode == 0x9E) value = cpu->x[thread]; + if (opcode == STB || opcode == 0x7F || opcode == 0x8F || opcode == 0x9F) + value = cpu->b[thread]; addr[address] = value & 0xFF; #if IO if (address == TX_ADDR) { @@ -894,6 +955,7 @@ void *run(void *args) { x = 0; else x = ((bcd[1]*10) + bcd[0]); + mvwprintw(scr, getmaxy(scr)-25, 0, "x: %i, y: %i ", x, y); idx = 3; bcd[0] = 0; bcd[1] = 0; @@ -916,6 +978,7 @@ void *run(void *args) { default: iscol = (addr[address] == ';'); break; + } } else { if (addr[address] == CURSES_BACKSPACE || addr[address] == '\b') { if (x > 0) { @@ -947,31 +1010,9 @@ void *run(void *args) { addr[address+7] = value >> 56; } break; - case BCC: /* Branch if Carry Clear. */ - address = (uint64_t)addr[cpu->pc[thread]] - | (uint64_t)addr[cpu->pc[thread]+1] << 8 - | (uint64_t)addr[cpu->pc[thread]+2] << 16 - | (uint64_t)addr[cpu->pc[thread]+3] << 24 - | (uint64_t)addr[cpu->pc[thread]+4] << 32 - | (uint64_t)addr[cpu->pc[thread]+5] << 40 - | (uint64_t)addr[cpu->pc[thread]+6] << 48 - | (uint64_t)addr[cpu->pc[thread]+7] << 56; - cpu->pc[thread]+=8; - iclk++; - if (!cpu->c[thread]) - cpu->pc[thread] = address; - break; - case LSR: /* LSR Immediate. */ - case 0x63: /* LSR Absolute. */ - case 0x65: /* LSR Zero Matrix. */ - case ASR: /* ASR Immediate. */ - case 0xAB: /* ASR Absolute. */ - case 0xAD: /* ASR Zero Matrix. */ - if (opcode == LSR || opcode == ASR) { - address = cpu->pc[thread]; - cpu->pc[thread]++; - } - if (opcode == 0x63 || opcode == 0xAB) { + case BCC: /* BCC Absolute. */ + case 0x94: /* BCC Zero Matrix. */ + if (opcode == BCC) { address = (uint64_t)addr[cpu->pc[thread]] | (uint64_t)addr[cpu->pc[thread]+1] << 8 | (uint64_t)addr[cpu->pc[thread]+2] << 16 @@ -982,8 +1023,7 @@ void *run(void *args) { | (uint64_t)addr[cpu->pc[thread]+7] << 56; cpu->pc[thread]+=8; iclk++; - } - if (opcode == 0x65 || opcode == 0xAD) { + } else { address = addr[cpu->pc[thread]] | addr[cpu->pc[thread]+1] << 8 | addr[cpu->pc[thread]+2] << 16 @@ -991,12 +1031,51 @@ void *run(void *args) { cpu->pc[thread]+=4; iclk++; } - value = addr[address]; - if (opcode == ASR || opcode == 0xAB || opcode == 0xAD) { + if (!cpu->c[thread]) + cpu->pc[thread] = address; + break; + case LSR: /* LSR Immediate. */ + case LRB: /* Logical shift Right accumulator by B. */ + case 0x63: /* LSR Absolute. */ + case 0x65: /* LSR Zero Matrix. */ + case ASR: /* ASR Immediate. */ + case ARB: /* Arithmetic shift Right accumulator by B. */ + case 0xE3: /* ASR Absolute. */ + case 0xE5: /* ASR Zero Matrix. */ + if (opcode != LRB || opcode != ARB) { + if (opcode == LSR || opcode == ASR) { + address = cpu->pc[thread]; + cpu->pc[thread]++; + } + if (opcode == 0x63 || opcode == 0xE3) { + address = (uint64_t)addr[cpu->pc[thread]] + | (uint64_t)addr[cpu->pc[thread]+1] << 8 + | (uint64_t)addr[cpu->pc[thread]+2] << 16 + | (uint64_t)addr[cpu->pc[thread]+3] << 24 + | (uint64_t)addr[cpu->pc[thread]+4] << 32 + | (uint64_t)addr[cpu->pc[thread]+5] << 40 + | (uint64_t)addr[cpu->pc[thread]+6] << 48 + | (uint64_t)addr[cpu->pc[thread]+7] << 56; + cpu->pc[thread]+=8; + iclk++; + } + if (opcode == 0x65 || opcode == 0xE5) { + address = addr[cpu->pc[thread]] + | addr[cpu->pc[thread]+1] << 8 + | addr[cpu->pc[thread]+2] << 16 + | addr[cpu->pc[thread]+3] << 24; + cpu->pc[thread]+=4; + iclk++; + } + value = addr[address]; + } else { + value = cpu->b[thread]; + } + if (opcode == ASR || opcode == ARB || opcode == 0xE3 || opcode == 0xE5) { sign = cpu->a[thread] & 0x8000000000000000; sum = (value < 64) ? (cpu->a[thread] >> value) | sign : 0; } - if (opcode == LSR || opcode == 0x63 || opcode == 0x65) { + if (opcode == LSR || opcode == LRB || opcode == 0x63 || opcode == 0x65) { sum = (value < 64) ? cpu->a[thread] >> value : 0; } cpu->z[thread] = (sum == 0); @@ -1011,24 +1090,38 @@ void *run(void *args) { cpu->c[thread] = 0; (cpu->ps &= ~(C << 8*thread)); break; + case 0x56: /* LDB Absolute. */ case 0x59: /* LDA Absolute. */ case 0x5A: /* LDY Absolute. */ case 0x5C: /* LDX Absolute. */ + case LDB: /* LDB Immediate. */ case LDA: /* LDA Immediate. */ case LDY: /* LDY Immediate. */ case LDX: /* LDX Immediate. */ + case 0x76: /* LDB Zero Matrix. */ case 0x79: /* LDA Zero Matrix. */ case 0x7A: /* LDY Zero Matrix. */ case 0x7C: /* LDX Zero Matrix. */ + case 0x86: /* LDB Zero Matrix, Indexed with X. */ case 0x89: /* LDA Zero Matrix, Indexed with X. */ case 0x8A: /* LDY Zero Matrix, Indexed with X. */ + case 0x96: /* LDB Zero Matrix, Indexed with Y. */ case 0x99: /* LDA Zero Matrix, Indexed with Y. */ case 0x9C: /* LDX Zero Matrix, Indexed with Y. */ - if (opcode == LDA || opcode == LDY || opcode == LDX) { + case 0xA6: /* LDB Indirect. */ + case 0xA9: /* LDA Indirect. */ + case 0xAA: /* LDY Indirect. */ + case 0xAC: /* LDX Indirect. */ + case 0xB6: /* LDB Indexed Indirect. */ + case 0xB9: /* LDA Indexed Indirect. */ + case 0xBA: /* LDY Indexed Indirect. */ + case 0xC6: /* LDB Indirect Indexed. */ + case 0xC9: /* LDA Indirect Indexed. */ + case 0xCC: /* LDX Indirect Indexed. */ + if (opcode == LDB || opcode == LDA || opcode == LDY || opcode == LDX) { address = cpu->pc[thread]; cpu->pc[thread]+=regsize; - } - if (opcode == 0x59 || opcode == 0x5A || opcode == 0x5C) { + } else if (opcode == 0x56 || opcode == 0x59 || opcode == 0x5A || opcode == 0x5C) { address = (uint64_t)addr[cpu->pc[thread]] | (uint64_t)addr[cpu->pc[thread]+1] << 8 | (uint64_t)addr[cpu->pc[thread]+2] << 16 @@ -1039,15 +1132,27 @@ void *run(void *args) { | (uint64_t)addr[cpu->pc[thread]+7] << 56; cpu->pc[thread]+=8; iclk++; - } - if (opcode == 0x79 || opcode == 0x7A || opcode == 0x7C || opcode == 0x89 || opcode == 0x8A || opcode == 0x99 || opcode == 0x9C) { + } else { address = addr[cpu->pc[thread]] | addr[cpu->pc[thread]+1] << 8 | addr[cpu->pc[thread]+2] << 16 | addr[cpu->pc[thread]+3] << 24; - if (opcode == 0x89 || opcode == 0x8A) + if (opcode == 0xA6 || opcode == 0xA9 || opcode == 0xAA || opcode == 0xAC || opcode == 0xB6 || + opcode == 0xB9 || opcode == 0xBA || opcode == 0xC6 || opcode == 0xC9 || opcode == 0xCC) { + address = (uint64_t)addr[address] + | (uint64_t)addr[address+1] << 8 + | (uint64_t)addr[address+2] << 16 + | (uint64_t)addr[address+3] << 24 + | (uint64_t)addr[address+4] << 32 + | (uint64_t)addr[address+5] << 40 + | (uint64_t)addr[address+6] << 48 + | (uint64_t)addr[address+7] << 56; + } + if (opcode == 0x86 || opcode == 0x89 || opcode == 0x8A || + opcode == 0xB6 || opcode == 0xB9 || opcode == 0xBA) address += cpu->x[thread]; - if (opcode == 0x99 || opcode == 0x9C) + if (opcode == 0x96 || opcode == 0x99 || opcode == 0x9C || + opcode == 0xC6 || opcode == 0xC9 || opcode == 0xCC) address += cpu->y[thread]; cpu->pc[thread]+=4; iclk++; @@ -1075,6 +1180,8 @@ void *run(void *args) { value += (uint64_t)addr[address+6] << 48; value += (uint64_t)addr[address+7] << 56; } + if (opcode == LDB || opcode == 0x56 || opcode == 0x76 || opcode == 0x86 || opcode == 0x96) + cpu->b[thread] = value; if (opcode == LDA || opcode == 0x59 || opcode == 0x79 || opcode == 0x89 || opcode == 0x99) cpu->a[thread] = value; if (opcode == LDY || opcode == 0x5A || opcode == 0x7A || opcode == 0x8A) @@ -1086,28 +1193,9 @@ void *run(void *args) { (cpu->z[thread]) ? (cpu->ps |= (Z << 8*thread)) : (cpu->ps &= ~(Z << 8*thread)); (cpu->n[thread]) ? (cpu->ps |= (N << 8*thread)) : (cpu->ps &= ~(N << 8*thread)); break; - case BEQ: /* Branch if EQual. */ - address = (uint64_t)addr[cpu->pc[thread]] - | (uint64_t)addr[cpu->pc[thread]+1] << 8 - | (uint64_t)addr[cpu->pc[thread]+2] << 16 - | (uint64_t)addr[cpu->pc[thread]+3] << 24 - | (uint64_t)addr[cpu->pc[thread]+4] << 32 - | (uint64_t)addr[cpu->pc[thread]+5] << 40 - | (uint64_t)addr[cpu->pc[thread]+6] << 48 - | (uint64_t)addr[cpu->pc[thread]+7] << 56; - cpu->pc[thread]+=8; - iclk++; - if (cpu->z[thread]) - cpu->pc[thread] = address; - break; - case ROL: /* ROL Immediate. */ - case 0x73: /* ROL Absolute. */ - case 0x75: /* ROL Zero Matrix. */ - if (opcode == ROL) { - address = cpu->pc[thread]; - cpu->pc[thread]++; - } - if (opcode == 0x73) { + case BEQ: /* BEQ Absolute. */ + case 0xA4: /* BEQ Zero Matrix. */ + if (opcode == BEQ) { address = (uint64_t)addr[cpu->pc[thread]] | (uint64_t)addr[cpu->pc[thread]+1] << 8 | (uint64_t)addr[cpu->pc[thread]+2] << 16 @@ -1118,8 +1206,7 @@ void *run(void *args) { | (uint64_t)addr[cpu->pc[thread]+7] << 56; cpu->pc[thread]+=8; iclk++; - } - if (opcode == 0x75) { + } else { address = addr[cpu->pc[thread]] | addr[cpu->pc[thread]+1] << 8 | addr[cpu->pc[thread]+2] << 16 @@ -1127,7 +1214,42 @@ void *run(void *args) { cpu->pc[thread]+=4; iclk++; } - value = addr[address]; + if (cpu->z[thread]) + cpu->pc[thread] = address; + break; + case ROL: /* ROL Immediate. */ + case RLB: /* Rotate Left accumulator by B. */ + case 0x73: /* ROL Absolute. */ + case 0x75: /* ROL Zero Matrix. */ + if (opcode != RLB) { + if (opcode == ROL) { + address = cpu->pc[thread]; + cpu->pc[thread]++; + } + if (opcode == 0x73) { + address = (uint64_t)addr[cpu->pc[thread]] + | (uint64_t)addr[cpu->pc[thread]+1] << 8 + | (uint64_t)addr[cpu->pc[thread]+2] << 16 + | (uint64_t)addr[cpu->pc[thread]+3] << 24 + | (uint64_t)addr[cpu->pc[thread]+4] << 32 + | (uint64_t)addr[cpu->pc[thread]+5] << 40 + | (uint64_t)addr[cpu->pc[thread]+6] << 48 + | (uint64_t)addr[cpu->pc[thread]+7] << 56; + cpu->pc[thread]+=8; + iclk++; + } + if (opcode == 0x75) { + address = addr[cpu->pc[thread]] + | addr[cpu->pc[thread]+1] << 8 + | addr[cpu->pc[thread]+2] << 16 + | addr[cpu->pc[thread]+3] << 24; + cpu->pc[thread]+=4; + iclk++; + } + value = addr[address]; + } else { + value = cpu->b[thread]; + } sum = cpu->a[thread] << value; sum |= cpu->c[thread]; cpu->z[thread] = (sum == 0); @@ -1142,28 +1264,9 @@ void *run(void *args) { cpu->s[thread] = 1; (cpu->ps |= (S << 8*thread)); break; - case BNE: /* Branch if Not Equal. */ - address = (uint64_t)addr[cpu->pc[thread]] - | (uint64_t)addr[cpu->pc[thread]+1] << 8 - | (uint64_t)addr[cpu->pc[thread]+2] << 16 - | (uint64_t)addr[cpu->pc[thread]+3] << 24 - | (uint64_t)addr[cpu->pc[thread]+4] << 32 - | (uint64_t)addr[cpu->pc[thread]+5] << 40 - | (uint64_t)addr[cpu->pc[thread]+6] << 48 - | (uint64_t)addr[cpu->pc[thread]+7] << 56; - cpu->pc[thread]+=8; - iclk++; - if (!cpu->z[thread]) - cpu->pc[thread] = address; - break; - case ROR: /* ROR Immediate. */ - case 0x83: /* ROR Absolute. */ - case 0x85: /* ROR Zero Matrix. */ - if (opcode == ROR) { - address = cpu->pc[thread]; - cpu->pc[thread]++; - } - if (opcode == 0x83) { + case BNE: /* BNE Absolute. */ + case 0xB4: /* BNE Zero Matrix. */ + if (opcode == BNE) { address = (uint64_t)addr[cpu->pc[thread]] | (uint64_t)addr[cpu->pc[thread]+1] << 8 | (uint64_t)addr[cpu->pc[thread]+2] << 16 @@ -1174,8 +1277,7 @@ void *run(void *args) { | (uint64_t)addr[cpu->pc[thread]+7] << 56; cpu->pc[thread]+=8; iclk++; - } - if (opcode == 0x85) { + } else { address = addr[cpu->pc[thread]] | addr[cpu->pc[thread]+1] << 8 | addr[cpu->pc[thread]+2] << 16 @@ -1183,7 +1285,42 @@ void *run(void *args) { cpu->pc[thread]+=4; iclk++; } - value = addr[address]; + if (!cpu->z[thread]) + cpu->pc[thread] = address; + break; + case ROR: /* ROR Immediate. */ + case RRB: /* Rotate Right accumulator by B. */ + case 0x83: /* ROR Absolute. */ + case 0x85: /* ROR Zero Matrix. */ + if (opcode != RRB) { + if (opcode == ROR) { + address = cpu->pc[thread]; + cpu->pc[thread]++; + } + if (opcode == 0x83) { + address = (uint64_t)addr[cpu->pc[thread]] + | (uint64_t)addr[cpu->pc[thread]+1] << 8 + | (uint64_t)addr[cpu->pc[thread]+2] << 16 + | (uint64_t)addr[cpu->pc[thread]+3] << 24 + | (uint64_t)addr[cpu->pc[thread]+4] << 32 + | (uint64_t)addr[cpu->pc[thread]+5] << 40 + | (uint64_t)addr[cpu->pc[thread]+6] << 48 + | (uint64_t)addr[cpu->pc[thread]+7] << 56; + cpu->pc[thread]+=8; + iclk++; + } + if (opcode == 0x85) { + address = addr[cpu->pc[thread]] + | addr[cpu->pc[thread]+1] << 8 + | addr[cpu->pc[thread]+2] << 16 + | addr[cpu->pc[thread]+3] << 24; + cpu->pc[thread]+=4; + iclk++; + } + value = addr[address]; + } else { + value = cpu->b[thread]; + } sum = cpu->a[thread] >> value; sum |= (uint64_t)cpu->c[thread] << (uint64_t)64-value; cpu->z[thread] = (sum == 0); @@ -1198,28 +1335,9 @@ void *run(void *args) { cpu->s[thread] = 0; (cpu->ps &= ~(S << 8*thread)); break; - case BVS: /* Branch if oVerflow Set. */ - address = (uint64_t)addr[cpu->pc[thread]] - | (uint64_t)addr[cpu->pc[thread]+1] << 8 - | (uint64_t)addr[cpu->pc[thread]+2] << 16 - | (uint64_t)addr[cpu->pc[thread]+3] << 24 - | (uint64_t)addr[cpu->pc[thread]+4] << 32 - | (uint64_t)addr[cpu->pc[thread]+5] << 40 - | (uint64_t)addr[cpu->pc[thread]+6] << 48 - | (uint64_t)addr[cpu->pc[thread]+7] << 56; - cpu->pc[thread]+=8; - iclk++; - if (cpu->v[thread]) - cpu->pc[thread] = address; - break; - case MUL: /* MUL Immediate. */ - case 0x93: /* MUL Absolute. */ - case 0x95: /* MUL Zero Matrix. */ - if (opcode == MUL) { - address = cpu->pc[thread]; - cpu->pc[thread]+=regsize; - } - if (opcode == 0x93) { + case BVS: /* BVS Absolute. */ + case 0xC4: /* BVS Zero Matrix. */ + if (opcode == BVS) { address = (uint64_t)addr[cpu->pc[thread]] | (uint64_t)addr[cpu->pc[thread]+1] << 8 | (uint64_t)addr[cpu->pc[thread]+2] << 16 @@ -1230,8 +1348,7 @@ void *run(void *args) { | (uint64_t)addr[cpu->pc[thread]+7] << 56; cpu->pc[thread]+=8; iclk++; - } - if (opcode == 0x95) { + } else { address = addr[cpu->pc[thread]] | addr[cpu->pc[thread]+1] << 8 | addr[cpu->pc[thread]+2] << 16 @@ -1239,19 +1356,54 @@ void *run(void *args) { cpu->pc[thread]+=4; iclk++; } - value = addr[address]; - if (regsize >= 2) { - value += (uint64_t)addr[address+1] << 8; - } - if (regsize >= 4) { - value += (uint64_t)addr[address+2] << 16; - value += (uint64_t)addr[address+3] << 24; - } - if (regsize >= 8) { - value += (uint64_t)addr[address+4] << 32; - value += (uint64_t)addr[address+5] << 40; - value += (uint64_t)addr[address+6] << 48; - value += (uint64_t)addr[address+7] << 56; + if (cpu->v[thread]) + cpu->pc[thread] = address; + break; + case MUL: /* MUL Immediate. */ + case MAB: /* Multiply Accumulator by B. */ + case 0x93: /* MUL Absolute. */ + case 0x95: /* MUL Zero Matrix. */ + if (opcode != MAB) { + if (opcode == MUL) { + address = cpu->pc[thread]; + cpu->pc[thread]+=regsize; + } + if (opcode == 0x93) { + address = (uint64_t)addr[cpu->pc[thread]] + | (uint64_t)addr[cpu->pc[thread]+1] << 8 + | (uint64_t)addr[cpu->pc[thread]+2] << 16 + | (uint64_t)addr[cpu->pc[thread]+3] << 24 + | (uint64_t)addr[cpu->pc[thread]+4] << 32 + | (uint64_t)addr[cpu->pc[thread]+5] << 40 + | (uint64_t)addr[cpu->pc[thread]+6] << 48 + | (uint64_t)addr[cpu->pc[thread]+7] << 56; + cpu->pc[thread]+=8; + iclk++; + } + if (opcode == 0x95) { + address = addr[cpu->pc[thread]] + | addr[cpu->pc[thread]+1] << 8 + | addr[cpu->pc[thread]+2] << 16 + | addr[cpu->pc[thread]+3] << 24; + cpu->pc[thread]+=4; + iclk++; + } + value = addr[address]; + if (regsize >= 2) { + value += (uint64_t)addr[address+1] << 8; + } + if (regsize >= 4) { + value += (uint64_t)addr[address+2] << 16; + value += (uint64_t)addr[address+3] << 24; + } + if (regsize >= 8) { + value += (uint64_t)addr[address+4] << 32; + value += (uint64_t)addr[address+5] << 40; + value += (uint64_t)addr[address+6] << 48; + value += (uint64_t)addr[address+7] << 56; + } + } else { + value = cpu->b[thread]; } sum = cpu->a[thread]*value+cpu->c[thread]; cpu->a[thread] = sum; @@ -1268,28 +1420,9 @@ void *run(void *args) { cpu->v[thread] = 1; (cpu->ps |= (V << 8*thread)); break; - case BVC: /* Branch if oVerflow Clear. */ - address = (uint64_t)addr[cpu->pc[thread]] - | (uint64_t)addr[cpu->pc[thread]+1] << 8 - | (uint64_t)addr[cpu->pc[thread]+2] << 16 - | (uint64_t)addr[cpu->pc[thread]+3] << 24 - | (uint64_t)addr[cpu->pc[thread]+4] << 32 - | (uint64_t)addr[cpu->pc[thread]+5] << 40 - | (uint64_t)addr[cpu->pc[thread]+6] << 48 - | (uint64_t)addr[cpu->pc[thread]+7] << 56; - cpu->pc[thread]+=8; - iclk++; - if (!cpu->v[thread]) - cpu->pc[thread] = address; - break; - case DIV: /* DIV Immediate. */ - case 0xA3: /* DIV Absolute. */ - case 0xA5: /* DIV Zero Matrix. */ - if (opcode == DIV) { - address = cpu->pc[thread]; - cpu->pc[thread]+=regsize; - } - if (opcode == 0xA3) { + case BVC: /* BVC Absolute. */ + case 0xD4: /* BVC Zero Matrix. */ + if (opcode == BVC) { address = (uint64_t)addr[cpu->pc[thread]] | (uint64_t)addr[cpu->pc[thread]+1] << 8 | (uint64_t)addr[cpu->pc[thread]+2] << 16 @@ -1300,8 +1433,7 @@ void *run(void *args) { | (uint64_t)addr[cpu->pc[thread]+7] << 56; cpu->pc[thread]+=8; iclk++; - } - if (opcode == 0xA5) { + } else { address = addr[cpu->pc[thread]] | addr[cpu->pc[thread]+1] << 8 | addr[cpu->pc[thread]+2] << 16 @@ -1309,21 +1441,57 @@ void *run(void *args) { cpu->pc[thread]+=4; iclk++; } - value = addr[address]; - if (regsize >= 2) { - value += (uint64_t)addr[address+1] << 8; - } - if (regsize >= 4) { - value += (uint64_t)addr[address+2] << 16; - value += (uint64_t)addr[address+3] << 24; - } - if (regsize >= 8) { - value += (uint64_t)addr[address+4] << 32; - value += (uint64_t)addr[address+5] << 40; - value += (uint64_t)addr[address+6] << 48; - value += (uint64_t)addr[address+7] << 56; + if (!cpu->v[thread]) + cpu->pc[thread] = address; + break; + case DIV: /* DIV Immediate. */ + case DAB: /* Divide Accumulator by B. */ + case 0xA3: /* DIV Absolute. */ + case 0xA5: /* DIV Zero Matrix. */ + if (opcode != DAB) { + if (opcode == DIV) { + address = cpu->pc[thread]; + cpu->pc[thread]+=regsize; + } + if (opcode == 0xA3) { + address = (uint64_t)addr[cpu->pc[thread]] + | (uint64_t)addr[cpu->pc[thread]+1] << 8 + | (uint64_t)addr[cpu->pc[thread]+2] << 16 + | (uint64_t)addr[cpu->pc[thread]+3] << 24 + | (uint64_t)addr[cpu->pc[thread]+4] << 32 + | (uint64_t)addr[cpu->pc[thread]+5] << 40 + | (uint64_t)addr[cpu->pc[thread]+6] << 48 + | (uint64_t)addr[cpu->pc[thread]+7] << 56; + cpu->pc[thread]+=8; + iclk++; + } + if (opcode == 0xA5) { + address = addr[cpu->pc[thread]] + | addr[cpu->pc[thread]+1] << 8 + | addr[cpu->pc[thread]+2] << 16 + | addr[cpu->pc[thread]+3] << 24; + cpu->pc[thread]+=4; + iclk++; + } + value = addr[address]; + if (regsize >= 2) { + value += (uint64_t)addr[address+1] << 8; + } + if (regsize >= 4) { + value += (uint64_t)addr[address+2] << 16; + value += (uint64_t)addr[address+3] << 24; + } + if (regsize >= 8) { + value += (uint64_t)addr[address+4] << 32; + value += (uint64_t)addr[address+5] << 40; + value += (uint64_t)addr[address+6] << 48; + value += (uint64_t)addr[address+7] << 56; + } + cpu->b[thread] = cpu->a[thread] % value; + } else { + value = cpu->b[thread]; + cpu->x[thread] = cpu->a[thread] % value; } - cpu->b[thread] = cpu->a[thread] % value; sum = cpu->a[thread]/value; cpu->a[thread] = sum; cpu->z[thread] = (sum == 0); @@ -1344,53 +1512,84 @@ void *run(void *args) { cpu->pc[thread] = addr[(cpu->stk_st[thread] << 16)+cpu->sp[thread]]; } break; + case CPB: /* CPB Immediate. */ case CMP: /* CMP Immediate. */ + case CAB: /* Compare Accumulator, and B. */ case CPY: /* CPY Immediate. */ case CPX: /* CPX Immediate. */ - case 0xE2: /* CPY Absolute. */ - case 0xE4: /* CPX Absolute. */ - case 0xE5: /* CMP Absolute. */ - case 0xF2: /* CPY Zero Matrix. */ - case 0xF4: /* CPX Zero Matrix. */ - case 0xF5: /* CMP Zero Matrix. */ - if (opcode == CMP || opcode == CPY || opcode == CPX) { - address = cpu->pc[thread]; - cpu->pc[thread]+=regsize; - } - if (opcode == 0xE5 || opcode == 0xE2 || opcode == 0xE4) { - address = (uint64_t)addr[cpu->pc[thread]] - | (uint64_t)addr[cpu->pc[thread]+1] << 8 - | (uint64_t)addr[cpu->pc[thread]+2] << 16 - | (uint64_t)addr[cpu->pc[thread]+3] << 24 - | (uint64_t)addr[cpu->pc[thread]+4] << 32 - | (uint64_t)addr[cpu->pc[thread]+5] << 40 - | (uint64_t)addr[cpu->pc[thread]+6] << 48 - | (uint64_t)addr[cpu->pc[thread]+7] << 56; - cpu->pc[thread]+=8; - iclk++; - } - if (opcode == 0xF5 || opcode == 0xF2 || opcode == 0xF4) { - address = addr[cpu->pc[thread]] - | addr[cpu->pc[thread]+1] << 8 - | addr[cpu->pc[thread]+2] << 16 - | addr[cpu->pc[thread]+3] << 24; - cpu->pc[thread]+=4; - iclk++; - } - value = (uint64_t)addr[address]; - if (regsize >= 2) - value += (uint64_t)addr[address+1] << 8; - if (regsize >= 4) { - value += (uint64_t)addr[address+2] << 16; - value += (uint64_t)addr[address+3] << 24; - } - if (regsize >= 8) { - value += (uint64_t)addr[address+4] << 32; - value += (uint64_t)addr[address+5] << 40; - value += (uint64_t)addr[address+6] << 48; - value += (uint64_t)addr[address+7] << 56; + case 0x2B: /* CPY Absolute. */ + case 0x2D: /* CPX Absolute. */ + case 0xB3: /* CMP Absolute. */ + case 0xE6: /* CPB Absolute. */ + case 0x3B: /* CPY Zero Matrix. */ + case 0x3D: /* CPX Zero Matrix. */ + case 0xB5: /* CMP Zero Matrix. */ + case 0xF6: /* CPB Zero Matrix. */ + case 0xE9: /* CMP Indirect. */ + case 0xEA: /* CPY Indirect. */ + case 0xEC: /* CPX Indirect. */ + case 0xDF: /* CPB Indirect. */ + case 0xEB: /* CMP Indexed Indirect. */ + case 0xFA: /* CPY Indexed Indirect. */ + case 0xEF: /* CPB Indexed Indirect. */ + case 0xED: /* CMP Indirect Indexed. */ + case 0xFC: /* CPX Indirect Indexed. */ + case 0xFF: /* CPB Indirect Indexed. */ + if (opcode != CAB) { + if (opcode == CMP || opcode == CPY || opcode == CPX || opcode == CPB) { + address = cpu->pc[thread]; + cpu->pc[thread]+=regsize; + } else if (opcode == 0xB3 || opcode == 0x2B || opcode == 0x2D) { + address = (uint64_t)addr[cpu->pc[thread]] + | (uint64_t)addr[cpu->pc[thread]+1] << 8 + | (uint64_t)addr[cpu->pc[thread]+2] << 16 + | (uint64_t)addr[cpu->pc[thread]+3] << 24 + | (uint64_t)addr[cpu->pc[thread]+4] << 32 + | (uint64_t)addr[cpu->pc[thread]+5] << 40 + | (uint64_t)addr[cpu->pc[thread]+6] << 48 + | (uint64_t)addr[cpu->pc[thread]+7] << 56; + cpu->pc[thread]+=8; + iclk++; + } else { + address = addr[cpu->pc[thread]] + | addr[cpu->pc[thread]+1] << 8 + | addr[cpu->pc[thread]+2] << 16 + | addr[cpu->pc[thread]+3] << 24; + if (opcode == 0xDF || opcode == 0xE9 || opcode == 0xEA || opcode == 0xEB || opcode == 0xEC || + opcode == 0xED || opcode == 0xEF || opcode == 0xFA || opcode == 0xFC || opcode == 0xFF) { + address = (uint64_t)addr[address] + | (uint64_t)addr[address+1] << 8 + | (uint64_t)addr[address+2] << 16 + | (uint64_t)addr[address+3] << 24 + | (uint64_t)addr[address+4] << 32 + | (uint64_t)addr[address+5] << 40 + | (uint64_t)addr[address+6] << 48 + | (uint64_t)addr[address+7] << 56; + if (opcode == 0xEB || opcode == 0xEF || opcode == 0xFA) + address += cpu->x[thread]; + if (opcode == 0xED || opcode == 0xFC || opcode == 0xFF) + address += cpu->y[thread]; + } + cpu->pc[thread]+=4; + iclk++; + } + value = (uint64_t)addr[address]; + if (regsize >= 2) + value += (uint64_t)addr[address+1] << 8; + if (regsize >= 4) { + value += (uint64_t)addr[address+2] << 16; + value += (uint64_t)addr[address+3] << 24; + } + if (regsize >= 8) { + value += (uint64_t)addr[address+4] << 32; + value += (uint64_t)addr[address+5] << 40; + value += (uint64_t)addr[address+6] << 48; + value += (uint64_t)addr[address+7] << 56; + } + } else { + value = cpu->b[thread]; } - if (opcode == CMP || opcode == 0xE5 || opcode == 0xF5) + if (opcode == CMP || opcode == CAB || opcode == 0xE5 || opcode == 0xF5) sum = cpu->a[thread]-value; if (opcode == CPY || opcode == 0xE2 || opcode == 0xF2) sum = cpu->y[thread]-value; @@ -1403,22 +1602,6 @@ void *run(void *args) { (cpu->n[thread]) ? (cpu->ps |= (N << 8*thread)) : (cpu->ps &= ~(N << 8*thread)); (cpu->c[thread]) ? (cpu->ps |= (C << 8*thread)) : (cpu->ps &= ~(C << 8*thread)); break; - case CAY: - case CAX: - if (opcode == CAY) - sum = cpu->a[thread]-cpu->y[thread]; - if (opcode == CAX) - sum = cpu->a[thread]-cpu->x[thread]; - cpu->n[thread] = (sum & 0x8000000000000000) ? 1 : 0; - cpu->z[thread] = (sum == 0) ? 1 : 0; - if (opcode == CAY) - cpu->c[thread] = (sum > cpu->y[thread]) ? 1 : 0; - if (opcode == CAX) - cpu->c[thread] = (sum > cpu->x[thread]) ? 1 : 0; - (cpu->z[thread]) ? (cpu->ps |= (Z << 8*thread)) : (cpu->ps &= ~(Z << 8*thread)); - (cpu->n[thread]) ? (cpu->ps |= (N << 8*thread)) : (cpu->ps &= ~(N << 8*thread)); - (cpu->c[thread]) ? (cpu->ps |= (C << 8*thread)) : (cpu->ps &= ~(C << 8*thread)); - break; case ENT: /* ENd Thread. */ value = addr[address]; cpu->crt &= ~value; @@ -1438,60 +1621,80 @@ void *run(void *args) { } break; case INC: /* INC Accumulator. */ + case IAB: case INY: - case IAY: case INX: - case IAX: - if (opcode == INC || opcode == IAY || opcode == IAX) { + if (opcode == INC || opcode == IAB) { cpu->a[thread]+=1; + if (opcode == IAB) + cpu->b[thread]+=1; cpu->z[thread] = (cpu->a[thread] == 0); cpu->n[thread] = (cpu->a[thread] >> 63); - (cpu->z[thread]) ? (cpu->ps |= (Z << 8*thread)) : (cpu->ps &= ~(Z << 8*thread)); - (cpu->n[thread]) ? (cpu->ps |= (N << 8*thread)) : (cpu->ps &= ~(N << 8*thread)); } - if (opcode == INY || opcode == IAY) { + if (opcode == INY) { cpu->y[thread]+=1; cpu->z[thread] = (cpu->y[thread] == 0); cpu->n[thread] = (cpu->y[thread] >> 63); } - if (opcode == INX || opcode == IAX) { + if (opcode == INX) { cpu->x[thread]+=1; cpu->z[thread] = (cpu->x[thread] == 0); cpu->n[thread] = (cpu->x[thread] >> 63); } + (cpu->z[thread]) ? (cpu->ps |= (Z << 8*thread)) : (cpu->ps &= ~(Z << 8*thread)); + (cpu->n[thread]) ? (cpu->ps |= (N << 8*thread)) : (cpu->ps &= ~(N << 8*thread)); break; + case 0x04: /* JMP Indirect. */ + case 0x14: /* JMP Indexed Indirect. */ + case 0x24: /* JMP Indirect Indexed. */ case 0xD0: /* JMP Zero Matrix. */ address = (uint32_t)addr[cpu->pc[thread]] |(uint32_t)addr[cpu->pc[thread]+1] << 8 |(uint32_t)addr[cpu->pc[thread]+2] << 16 |(uint32_t)addr[cpu->pc[thread]+3] << 24; + + if (opcode == 0x04 || opcode == 0x14 || opcode == 0x24) { + address = (uint64_t)addr[address] + | (uint64_t)addr[address+1] << 8 + | (uint64_t)addr[address+2] << 16 + | (uint64_t)addr[address+3] << 24 + | (uint64_t)addr[address+4] << 32 + | (uint64_t)addr[address+5] << 40 + | (uint64_t)addr[address+6] << 48 + | (uint64_t)addr[address+7] << 56; + if (opcode == 0x14) + address += cpu->x[thread]; + if (opcode == 0x24) + address += cpu->y[thread]; + } cpu->pc[thread]+=4; iclk++; cpu->pc[thread] = address; break; case DEC: /* DEC Accumulator. */ + case DBA: case DEY: - case DAY: case DEX: - case DAX: - if (opcode == DEC || opcode == DAY || opcode == DAX) { + if (opcode == DEC || opcode == DBA) { cpu->a[thread]-=1; + if (opcode == DBA) + cpu->b[thread]-=1; cpu->z[thread] = (cpu->a[thread] == 0); cpu->n[thread] = (cpu->a[thread] >> 63); - (cpu->z[thread]) ? (cpu->ps |= (Z << 8*thread)) : (cpu->ps &= ~(Z << 8*thread)); - (cpu->n[thread]) ? (cpu->ps |= (N << 8*thread)) : (cpu->ps &= ~(N << 8*thread)); } - if (opcode == DEY || opcode == DAY) { + if (opcode == DEY) { cpu->y[thread]-=1; cpu->z[thread] = (cpu->y[thread] == 0); cpu->n[thread] = (cpu->y[thread] >> 63); } - if (opcode == DEX || opcode == DAX) { + if (opcode == DEX) { cpu->x[thread]-=1; cpu->z[thread] = (cpu->x[thread] == 0); cpu->n[thread] = (cpu->x[thread] >> 63); } + (cpu->z[thread]) ? (cpu->ps |= (Z << 8*thread)) : (cpu->ps &= ~(Z << 8*thread)); + (cpu->n[thread]) ? (cpu->ps |= (N << 8*thread)) : (cpu->ps &= ~(N << 8*thread)); break; case JSL: /* Jump to Subroutine Long. */ address = (uint64_t)addr[cpu->pc[thread]] @@ -1512,9 +1715,9 @@ void *run(void *args) { } cpu->pc[thread] = address; break; - case 0xE1: /* INC Absolute. */ - case 0xE3: /* INC Zero Matrix. */ - if (opcode == 0xE1) { + case 0xC3: /* INC Absolute. */ + case 0xC5: /* INC Zero Matrix. */ + if (opcode == 0xC3) { address = (uint64_t)addr[cpu->pc[thread]] | (uint64_t)addr[cpu->pc[thread]+1] << 8 | (uint64_t)addr[cpu->pc[thread]+2] << 16 @@ -1526,7 +1729,7 @@ void *run(void *args) { cpu->pc[thread]+=8; iclk++; } - if (opcode == 0xE3) { + if (opcode == 0xC5) { address = addr[cpu->pc[thread]] | addr[cpu->pc[thread]+1] << 8 | addr[cpu->pc[thread]+2] << 16 @@ -1549,9 +1752,9 @@ void *run(void *args) { cpu->pc[thread] = addr[(cpu->stk_st[thread] << 16)+cpu->sp[thread]]; } break; - case 0xF1: /* DEC Absolute. */ - case 0xF3: /* DEC Zero Matrix. */ - if (opcode == 0xF1) { + case 0xD3: /* DEC Absolute. */ + case 0xD5: /* DEC Zero Matrix. */ + if (opcode == 0xD3) { address = (uint64_t)addr[cpu->pc[thread]] | (uint64_t)addr[cpu->pc[thread]+1] << 8 | (uint64_t)addr[cpu->pc[thread]+2] << 16 @@ -1563,7 +1766,7 @@ void *run(void *args) { cpu->pc[thread]+=8; iclk++; } - if (opcode == 0xF3) { + if (opcode == 0xD5) { address = addr[cpu->pc[thread]] | addr[cpu->pc[thread]+1] << 8 | addr[cpu->pc[thread]+2] << 16 @@ -1607,6 +1810,7 @@ void *run(void *args) { break; } ins++; + usleep(100000); #if debug && !bench #if keypoll pthread_mutex_lock(&mutex); -- cgit v1.2.3-13-gbd6f