Start converting some opcodes to cycle-based.

This commit is contained in:
Brandon Wright 2011-09-14 12:54:51 -05:00
parent 4668ae5850
commit a19395ee3c
4 changed files with 147 additions and 378 deletions

View File

@ -13,12 +13,25 @@ void SMP::tick() {
#endif #endif
} }
void SMP::tick(unsigned clocks) {
timer0.tick(clocks);
timer1.tick(clocks);
timer2.tick(clocks);
clock += clocks;
dsp.clock += clocks;
}
void SMP::op_io() { void SMP::op_io() {
#if defined(CYCLE_ACCURATE) #if defined(CYCLE_ACCURATE)
tick(); tick();
#endif #endif
} }
void SMP::op_io(unsigned clocks) {
tick(clocks);
}
uint8 SMP::op_read(uint16 addr) { uint8 SMP::op_read(uint16 addr) {
#if defined(CYCLE_ACCURATE) #if defined(CYCLE_ACCURATE)
tick(); tick();

View File

@ -1,70 +1,34 @@
case 0x00: { case 0x00: {
switch(opcode_cycle++) {
case 1:
op_io(); op_io();
opcode_cycle = 0; opcode_cycle = 0;
break; break;
} }
break;
}
case 0xef: { case 0xef: {
switch(opcode_cycle++) { op_io(2);
case 1:
op_io();
break;
case 2:
op_io();
regs.pc--; regs.pc--;
opcode_cycle = 0; opcode_cycle = 0;
break; break;
} }
break;
}
case 0xff: { case 0xff: {
switch(opcode_cycle++) { op_io(2);
case 1:
op_io();
break;
case 2:
op_io();
regs.pc--; regs.pc--;
opcode_cycle = 0; opcode_cycle = 0;
break; break;
} }
break;
}
case 0x9f: { case 0x9f: {
switch(opcode_cycle++) { op_io(4);
case 1:
op_io();
break;
case 2:
op_io();
break;
case 3:
op_io();
break;
case 4:
op_io();
regs.a = (regs.a >> 4) | (regs.a << 4); regs.a = (regs.a >> 4) | (regs.a << 4);
regs.p.n = !!(regs.a & 0x80); regs.p.n = !!(regs.a & 0x80);
regs.p.z = (regs.a == 0); regs.p.z = (regs.a == 0);
opcode_cycle = 0; opcode_cycle = 0;
break; break;
} }
break;
}
case 0xdf: { case 0xdf: {
switch(opcode_cycle++) { op_io(2);
case 1:
op_io();
break;
case 2:
op_io();
if(regs.p.c || (regs.a) > 0x99) { if(regs.p.c || (regs.a) > 0x99) {
regs.a += 0x60; regs.a += 0x60;
regs.p.c = 1; regs.p.c = 1;
@ -77,16 +41,9 @@ case 0xdf: {
opcode_cycle = 0; opcode_cycle = 0;
break; break;
} }
break;
}
case 0xbe: { case 0xbe: {
switch(opcode_cycle++) { op_io(2);
case 1:
op_io();
break;
case 2:
op_io();
if(!regs.p.c || (regs.a) > 0x99) { if(!regs.p.c || (regs.a) > 0x99) {
regs.a -= 0x60; regs.a -= 0x60;
regs.p.c = 0; regs.p.c = 0;
@ -99,92 +56,56 @@ case 0xbe: {
opcode_cycle = 0; opcode_cycle = 0;
break; break;
} }
break;
}
case 0x60: { case 0x60: {
switch(opcode_cycle++) {
case 1:
op_io(); op_io();
regs.p.c = 0; regs.p.c = 0;
opcode_cycle = 0; opcode_cycle = 0;
break; break;
} }
break;
}
case 0x20: { case 0x20: {
switch(opcode_cycle++) {
case 1:
op_io(); op_io();
regs.p.p = 0; regs.p.p = 0;
opcode_cycle = 0; opcode_cycle = 0;
break; break;
} }
break;
}
case 0x80: { case 0x80: {
switch(opcode_cycle++) {
case 1:
op_io(); op_io();
regs.p.c = 1; regs.p.c = 1;
opcode_cycle = 0; opcode_cycle = 0;
break; break;
} }
break;
}
case 0x40: { case 0x40: {
switch(opcode_cycle++) {
case 1:
op_io(); op_io();
regs.p.p = 1; regs.p.p = 1;
opcode_cycle = 0; opcode_cycle = 0;
break; break;
} }
break;
}
case 0xe0: { case 0xe0: {
switch(opcode_cycle++) {
case 1:
op_io(); op_io();
regs.p.v = 0; regs.p.v = 0;
regs.p.h = 0; regs.p.h = 0;
opcode_cycle = 0; opcode_cycle = 0;
break; break;
} }
break;
}
case 0xed: { case 0xed: {
switch(opcode_cycle++) { op_io(2);
case 1:
op_io();
break;
case 2:
op_io();
regs.p.c = !regs.p.c; regs.p.c = !regs.p.c;
opcode_cycle = 0; opcode_cycle = 0;
break; break;
} }
break;
}
case 0xa0: { case 0xa0: {
switch(opcode_cycle++) { op_io(2);
case 1:
op_io();
break;
case 2:
op_io();
regs.p.i = 1; regs.p.i = 1;
opcode_cycle = 0; opcode_cycle = 0;
break; break;
} }
break;
}
case 0xc0: { case 0xc0: {
switch(opcode_cycle++) { switch(opcode_cycle++) {
@ -473,158 +394,63 @@ case 0xf2: {
} }
case 0x2d: { case 0x2d: {
switch(opcode_cycle++) { op_io(2);
case 1:
op_io();
break;
case 2:
op_io();
break;
case 3:
op_writestack(regs.a); op_writestack(regs.a);
opcode_cycle = 0; opcode_cycle = 0;
break; break;
} }
break;
}
case 0x4d: { case 0x4d: {
switch(opcode_cycle++) { op_io(2);
case 1:
op_io();
break;
case 2:
op_io();
break;
case 3:
op_writestack(regs.x); op_writestack(regs.x);
opcode_cycle = 0; opcode_cycle = 0;
break; break;
} }
break;
}
case 0x6d: { case 0x6d: {
switch(opcode_cycle++) { op_io(2);
case 1:
op_io();
break;
case 2:
op_io();
break;
case 3:
op_writestack(regs.y); op_writestack(regs.y);
opcode_cycle = 0; opcode_cycle = 0;
break; break;
} }
break;
}
case 0x0d: { case 0x0d: {
switch(opcode_cycle++) { op_io(2);
case 1:
op_io();
break;
case 2:
op_io();
break;
case 3:
op_writestack(regs.p); op_writestack(regs.p);
opcode_cycle = 0; opcode_cycle = 0;
break; break;
} }
break;
}
case 0xae: { case 0xae: {
switch(opcode_cycle++) { op_io(2);
case 1:
op_io();
break;
case 2:
op_io();
break;
case 3:
regs.a = op_readstack(); regs.a = op_readstack();
opcode_cycle = 0; opcode_cycle = 0;
break; break;
} }
break;
}
case 0xce: { case 0xce: {
switch(opcode_cycle++) { op_io(2);
case 1:
op_io();
break;
case 2:
op_io();
break;
case 3:
regs.x = op_readstack(); regs.x = op_readstack();
opcode_cycle = 0; opcode_cycle = 0;
break; break;
} }
break;
}
case 0xee: { case 0xee: {
switch(opcode_cycle++) { op_io(2);
case 1:
op_io();
break;
case 2:
op_io();
break;
case 3:
regs.y = op_readstack(); regs.y = op_readstack();
opcode_cycle = 0; opcode_cycle = 0;
break; break;
} }
break;
}
case 0x8e: { case 0x8e: {
switch(opcode_cycle++) { op_io(2);
case 1:
op_io();
break;
case 2:
op_io();
break;
case 3:
regs.p = op_readstack(); regs.p = op_readstack();
opcode_cycle = 0; opcode_cycle = 0;
break; break;
} }
break;
}
case 0xcf: { case 0xcf: {
switch(opcode_cycle++) { op_io(8);
case 1:
op_io();
break;
case 2:
op_io();
break;
case 3:
op_io();
break;
case 4:
op_io();
break;
case 5:
op_io();
break;
case 6:
op_io();
break;
case 7:
op_io();
break;
case 8:
op_io();
ya = regs.y * regs.a; ya = regs.y * regs.a;
regs.a = ya; regs.a = ya;
regs.y = ya >> 8; regs.y = ya >> 8;
@ -634,43 +460,9 @@ case 0xcf: {
opcode_cycle = 0; opcode_cycle = 0;
break; break;
} }
break;
}
case 0x9e: { case 0x9e: {
switch(opcode_cycle++) { op_io(11);
case 1:
op_io();
break;
case 2:
op_io();
break;
case 3:
op_io();
break;
case 4:
op_io();
break;
case 5:
op_io();
break;
case 6:
op_io();
break;
case 7:
op_io();
break;
case 8:
op_io();
break;
case 9:
op_io();
break;
case 10:
op_io();
break;
case 11:
op_io();
ya = regs.ya; ya = regs.ya;
//overflow set if quotient >= 256 //overflow set if quotient >= 256
regs.p.v = !!(regs.y >= regs.x); regs.p.v = !!(regs.y >= regs.x);
@ -691,6 +483,4 @@ case 0x9e: {
opcode_cycle = 0; opcode_cycle = 0;
break; break;
} }
break;
}

View File

@ -1,101 +1,65 @@
case 0xbc: { case 0xbc: {
switch(opcode_cycle++) {
case 1:
op_io(); op_io();
regs.a = op_inc(regs.a); regs.a = op_inc(regs.a);
opcode_cycle = 0; opcode_cycle = 0;
break; break;
} }
break;
}
case 0x3d: { case 0x3d: {
switch(opcode_cycle++) {
case 1:
op_io(); op_io();
regs.x = op_inc(regs.x); regs.x = op_inc(regs.x);
opcode_cycle = 0; opcode_cycle = 0;
break; break;
} }
break;
}
case 0xfc: { case 0xfc: {
switch(opcode_cycle++) {
case 1:
op_io(); op_io();
regs.y = op_inc(regs.y); regs.y = op_inc(regs.y);
opcode_cycle = 0; opcode_cycle = 0;
break; break;
} }
break;
}
case 0x9c: { case 0x9c: {
switch(opcode_cycle++) {
case 1:
op_io(); op_io();
regs.a = op_dec(regs.a); regs.a = op_dec(regs.a);
opcode_cycle = 0; opcode_cycle = 0;
break; break;
} }
break;
}
case 0x1d: { case 0x1d: {
switch(opcode_cycle++) {
case 1:
op_io(); op_io();
regs.x = op_dec(regs.x); regs.x = op_dec(regs.x);
opcode_cycle = 0; opcode_cycle = 0;
break; break;
} }
break;
}
case 0xdc: { case 0xdc: {
switch(opcode_cycle++) {
case 1:
op_io(); op_io();
regs.y = op_dec(regs.y); regs.y = op_dec(regs.y);
opcode_cycle = 0; opcode_cycle = 0;
break; break;
} }
break;
}
case 0x1c: { case 0x1c: {
switch(opcode_cycle++) {
case 1:
op_io(); op_io();
regs.a = op_asl(regs.a); regs.a = op_asl(regs.a);
opcode_cycle = 0; opcode_cycle = 0;
break; break;
} }
break;
}
case 0x5c: { case 0x5c: {
switch(opcode_cycle++) {
case 1:
op_io(); op_io();
regs.a = op_lsr(regs.a); regs.a = op_lsr(regs.a);
opcode_cycle = 0; opcode_cycle = 0;
break; break;
} }
break;
}
case 0x3c: { case 0x3c: {
switch(opcode_cycle++) {
case 1:
op_io(); op_io();
regs.a = op_rol(regs.a); regs.a = op_rol(regs.a);
opcode_cycle = 0; opcode_cycle = 0;
break; break;
} }
break;
}
case 0x7c: { case 0x7c: {
switch(opcode_cycle++) { switch(opcode_cycle++) {

View File

@ -96,7 +96,9 @@ public:
Timer< 16> timer2; Timer< 16> timer2;
inline void tick(); inline void tick();
inline void tick(unsigned clocks);
alwaysinline void op_io(); alwaysinline void op_io();
alwaysinline void op_io(unsigned clocks);
debugvirtual alwaysinline uint8 op_read(uint16 addr); debugvirtual alwaysinline uint8 op_read(uint16 addr);
debugvirtual alwaysinline void op_write(uint16 addr, uint8 data); debugvirtual alwaysinline void op_write(uint16 addr, uint8 data);
debugvirtual alwaysinline void op_step(); debugvirtual alwaysinline void op_step();