summaryrefslogtreecommitdiff
path: root/sux.c
diff options
context:
space:
mode:
Diffstat (limited to 'sux.c')
-rw-r--r--sux.c38
1 files changed, 16 insertions, 22 deletions
diff --git a/sux.c b/sux.c
index ae62304..ae99a8b 100644
--- a/sux.c
+++ b/sux.c
@@ -172,6 +172,7 @@ void *run(void *args) {
pthread_mutex_unlock(&mutex);
#endif
#endif
+ uint8_t size = (1 << ((prefix >> 4) & 3))-1;
switch(opcode) {
case CPS_IMP: /* Clear Processor Status. */
cpu->ps.u64 = 0;
@@ -183,11 +184,11 @@ void *run(void *args) {
case ADC_Z: /* ADC Zero Matrix. */
adc(cpu, value.u64, thread);
break;
- case PHP_IMP: push(cpu, cpu->ps.u64, 0, thread); break; /* PusH Processor status to stack. */
- case PHA_IMP: push(cpu, cpu->a , prefix, thread); break; /* PusH Accumulator to stack. */
- case PHB_IMP: push(cpu, cpu->b , prefix, thread); break; /* PusH B register to stack. */
- case PHY_IMP: push(cpu, cpu->y , prefix, thread); break; /* PusH Y register to stack. */
- case PHX_IMP: push(cpu, cpu->x , prefix, thread); break; /* PusH X register to stack. */
+ case PHP_IMP: push(cpu, cpu->ps.u8[thread], 0, thread); break; /* PusH Processor status to stack. */
+ case PHA_IMP: push(cpu, cpu->a , size, thread); break; /* PusH Accumulator to stack. */
+ case PHB_IMP: push(cpu, cpu->b , size, thread); break; /* PusH B register to stack. */
+ case PHY_IMP: push(cpu, cpu->y , size, thread); break; /* PusH Y register to stack. */
+ case PHX_IMP: push(cpu, cpu->x , size, thread); break; /* PusH X register to stack. */
case TAY_IMP: /* Transfer Accumulator to Y. */
case TAX_IMP: /* Transfer Accumulator to Y. */
case TYX_IMP: /* Transfer Y to X. */
@@ -213,11 +214,11 @@ void *run(void *args) {
case SBC_Z: /* SBC Zero Matrix. */
sbc(cpu, value.u64, thread);
break;
- case PLP_IMP: cpu->ps.u64 = pull(cpu, 0, thread); break; /* PuLl Processor status from stack. */
- case PLA_IMP: cpu->a = pull(cpu, prefix, thread); break; /* PuLl Accumulator from stack. */
- case PLB_IMP: cpu->b = pull(cpu, prefix, thread); break; /* PuLl B register from stack. */
- case PLY_IMP: cpu->y = pull(cpu, prefix, thread); break; /* PuLl Y register from stack. */
- case PLX_IMP: cpu->x = pull(cpu, prefix, thread); break; /* PuLl X register from stack. */
+ case PLP_IMP: cpu->ps.u8[thread] = pull(cpu, 0, thread); break; /* PuLl Processor status from stack. */
+ case PLA_IMP: cpu->a = pull(cpu, size, thread); break; /* PuLl Accumulator from stack. */
+ case PLB_IMP: cpu->b = pull(cpu, size, thread); break; /* PuLl B register from stack. */
+ case PLY_IMP: cpu->y = pull(cpu, size, thread); break; /* PuLl Y register from stack. */
+ case PLX_IMP: cpu->x = pull(cpu, size, thread); break; /* PuLl X register from stack. */
break;
case ABA_IMP: /* bitwise And with Accumulator, and B register. */
value.u64 = cpu->b; /* Falls Through. */
@@ -442,9 +443,7 @@ void *run(void *args) {
case JSR_IN: /* JSR Indirect. */
case JSR_AB: /* Jump to SubRoutine. */
case JSR_Z: /* JSR Zero Matrix. */
- value.u64 = cpu->pc;
- setreg(addr, -, (cpu->stk_st << 16)+cpu->sp, value.u8, +, 0, 7);
- cpu->sp -= 8;
+ push(cpu, cpu->pc, 7, thread);
cpu->pc = address.u64;
break;
case INC_AB: /* INC Absolute. */
@@ -454,12 +453,9 @@ void *run(void *args) {
case NOP_IMP: /* No OPeration. */
break;
case RTI_IMP: /* ReTurn from Interrupt routine. */
- cpu->sp += 1;
- cpu->ps.u8[thread] = addr[(cpu->stk_st << 16)+(cpu->sp)]; /* Falls through. */
+ cpu->ps.u64 = pull(cpu, 0, thread);
case RTS_IMP: /* ReTurn from Subroutine. */
- cpu->sp += 8;
- setreg(value.u8, +, 0, addr, -, (cpu->stk_st << 16)+cpu->sp, 7);
- cpu->pc = value.u64;
+ cpu->pc = pull(cpu, 7, thread);
break;
case DEC_AB: /* DEC Absolute. */
case DEC_Z: /* DEC Zero Matrix. */
@@ -475,10 +471,8 @@ void *run(void *args) {
pthread_cond_wait(&cond, &mutex);
pthread_mutex_unlock(&mutex);
}
- value.u64 = cpu->pc;
- setreg(addr, -, (cpu->stk_st << 16)+cpu->sp, value.u8, +, 0, 7);
- addr[(cpu->stk_st << 16)+cpu->sp-8] = cpu->ps.u8[thread];
- cpu->sp -= 9;
+ push(cpu, cpu->pc, 7, thread);
+ push(cpu, cpu->ps.u8[thread], 0, thread);
setflag(1, I);
setreg(value.u8, +, 0, addr, +, (opcode == BRK) ? 0xFFE0 : 0xFFA0, 7);
if (opcode == WAI_IMP) {