mirror of
https://github.com/bsnes-emu/bsnes.git
synced 2025-10-04 16:31:34 +02:00
bsnes now supports SPC700 emulation (no DSP or sound support, however), and has greatly improved compatibility. It also now contains a keyboard-only joypad configuration tool.
296 lines
6.2 KiB
C++
296 lines
6.2 KiB
C++
//op_read
|
|
inline void bCPU::op_adc_b() {
|
|
int32 r = regs.a.l + rd.l + regs.p.c;
|
|
//bcd
|
|
if(regs.p.d) {
|
|
if(((r ) & 15) > 9)r += 6;
|
|
if(((r >> 4) & 15) > 9)r += 6 << 4;
|
|
}
|
|
regs.p.n = !!(r & 0x80);
|
|
regs.p.v = !!(~(regs.a.l ^ rd.l) & (regs.a.l ^ r) & 0x80);
|
|
regs.p.z = ((uint8)r == 0);
|
|
regs.p.c = (r > 0xff);
|
|
regs.a.l = r;
|
|
}
|
|
|
|
inline void bCPU::op_adc_w() {
|
|
int32 r = regs.a.w + rd.w + regs.p.c;
|
|
//bcd
|
|
if(regs.p.d) {
|
|
if(((r ) & 15) > 9)r += 6;
|
|
if(((r >> 4) & 15) > 9)r += 6 << 4;
|
|
if(((r >> 8) & 15) > 9)r += 6 << 8;
|
|
if(((r >> 12) & 15) > 9)r += 6 << 12;
|
|
}
|
|
regs.p.n = !!(r & 0x8000);
|
|
regs.p.v = !!(~(regs.a.w ^ rd.w) & (regs.a.w ^ r) & 0x8000);
|
|
regs.p.z = ((uint16)r == 0);
|
|
regs.p.c = (r > 0xffff);
|
|
regs.a.w = r;
|
|
}
|
|
|
|
inline void bCPU::op_and_b() {
|
|
regs.a.l &= rd.l;
|
|
regs.p.n = !!(regs.a.l & 0x80);
|
|
regs.p.z = (regs.a.l == 0);
|
|
}
|
|
|
|
inline void bCPU::op_and_w() {
|
|
regs.a.w &= rd.w;
|
|
regs.p.n = !!(regs.a.w & 0x8000);
|
|
regs.p.z = (regs.a.w == 0);
|
|
}
|
|
|
|
inline void bCPU::op_bit_b() {
|
|
regs.p.n = !!(rd.l & 0x80);
|
|
regs.p.v = !!(rd.l & 0x40);
|
|
regs.p.z = ((rd.l & regs.a.l) == 0);
|
|
}
|
|
|
|
inline void bCPU::op_bit_w() {
|
|
regs.p.n = !!(rd.w & 0x8000);
|
|
regs.p.v = !!(rd.w & 0x4000);
|
|
regs.p.z = ((rd.w & regs.a.w) == 0);
|
|
}
|
|
|
|
inline void bCPU::op_cmp_b() {
|
|
int32 r = regs.a.l - rd.l;
|
|
regs.p.n = !!(r & 0x80);
|
|
regs.p.z = ((uint8)r == 0);
|
|
regs.p.c = (r >= 0);
|
|
}
|
|
|
|
inline void bCPU::op_cmp_w() {
|
|
int32 r = regs.a.w - rd.w;
|
|
regs.p.n = !!(r & 0x8000);
|
|
regs.p.z = ((uint16)r == 0);
|
|
regs.p.c = (r >= 0);
|
|
}
|
|
|
|
inline void bCPU::op_cpx_b() {
|
|
int32 r = regs.x.l - rd.l;
|
|
regs.p.n = !!(r & 0x80);
|
|
regs.p.z = ((uint8)r == 0);
|
|
regs.p.c = (r >= 0);
|
|
}
|
|
|
|
inline void bCPU::op_cpx_w() {
|
|
int32 r = regs.x.w - rd.w;
|
|
regs.p.n = !!(r & 0x8000);
|
|
regs.p.z = ((uint16)r == 0);
|
|
regs.p.c = (r >= 0);
|
|
}
|
|
|
|
inline void bCPU::op_cpy_b() {
|
|
int32 r = regs.y.l - rd.l;
|
|
regs.p.n = !!(r & 0x80);
|
|
regs.p.z = ((uint8)r == 0);
|
|
regs.p.c = (r >= 0);
|
|
}
|
|
|
|
inline void bCPU::op_cpy_w() {
|
|
int32 r = regs.y.w - rd.w;
|
|
regs.p.n = !!(r & 0x8000);
|
|
regs.p.z = ((uint16)r == 0);
|
|
regs.p.c = (r >= 0);
|
|
}
|
|
|
|
inline void bCPU::op_eor_b() {
|
|
regs.a.l ^= rd.l;
|
|
regs.p.n = !!(regs.a.l & 0x80);
|
|
regs.p.z = (regs.a.l == 0);
|
|
}
|
|
|
|
inline void bCPU::op_eor_w() {
|
|
regs.a.w ^= rd.w;
|
|
regs.p.n = !!(regs.a.w & 0x8000);
|
|
regs.p.z = (regs.a.w == 0);
|
|
}
|
|
|
|
inline void bCPU::op_lda_b() {
|
|
regs.a.l = rd.l;
|
|
regs.p.n = !!(regs.a.l & 0x80);
|
|
regs.p.z = (regs.a.l == 0);
|
|
}
|
|
|
|
inline void bCPU::op_lda_w() {
|
|
regs.a.w = rd.w;
|
|
regs.p.n = !!(regs.a.w & 0x8000);
|
|
regs.p.z = (regs.a.w == 0);
|
|
}
|
|
|
|
inline void bCPU::op_ldx_b() {
|
|
regs.x.l = rd.l;
|
|
regs.p.n = !!(regs.x.l & 0x80);
|
|
regs.p.z = (regs.x.l == 0);
|
|
}
|
|
|
|
inline void bCPU::op_ldx_w() {
|
|
regs.x.w = rd.w;
|
|
regs.p.n = !!(regs.x.w & 0x8000);
|
|
regs.p.z = (regs.x.w == 0);
|
|
}
|
|
|
|
inline void bCPU::op_ldy_b() {
|
|
regs.y.l = rd.l;
|
|
regs.p.n = !!(regs.y.l & 0x80);
|
|
regs.p.z = (regs.y.l == 0);
|
|
}
|
|
|
|
inline void bCPU::op_ldy_w() {
|
|
regs.y.w = rd.w;
|
|
regs.p.n = !!(regs.y.w & 0x8000);
|
|
regs.p.z = (regs.y.w == 0);
|
|
}
|
|
|
|
inline void bCPU::op_ora_b() {
|
|
regs.a.l |= rd.l;
|
|
regs.p.n = !!(regs.a.l & 0x80);
|
|
regs.p.z = (regs.a.l == 0);
|
|
}
|
|
|
|
inline void bCPU::op_ora_w() {
|
|
regs.a.w |= rd.w;
|
|
regs.p.n = !!(regs.a.w & 0x8000);
|
|
regs.p.z = (regs.a.w == 0);
|
|
}
|
|
|
|
inline void bCPU::op_sbc_b() {
|
|
int32 r = regs.a.l - rd.l - !regs.p.c;
|
|
//bcd
|
|
if(regs.p.d) {
|
|
if(((r ) & 15) > 9)r -= 6;
|
|
if(((r >> 4) & 15) > 9)r -= 6 << 4;
|
|
}
|
|
regs.p.n = !!(r & 0x80);
|
|
regs.p.v = !!((regs.a.l ^ rd.l) & (regs.a.l ^ r) & 0x80);
|
|
regs.p.z = ((byte)r == 0);
|
|
regs.p.c = (r >= 0);
|
|
regs.a.l = r;
|
|
}
|
|
|
|
inline void bCPU::op_sbc_w() {
|
|
int32 r = regs.a.w - rd.w - !regs.p.c;
|
|
//bcd
|
|
if(regs.p.d) {
|
|
if(((r ) & 15) > 9)r -= 6;
|
|
if(((r >> 4) & 15) > 9)r -= 6 << 4;
|
|
if(((r >> 8) & 15) > 9)r -= 6 << 8;
|
|
if(((r >> 12) & 15) > 9)r -= 6 << 12;
|
|
}
|
|
regs.p.n = !!(r & 0x8000);
|
|
regs.p.v = !!((regs.a.w ^ rd.w) & (regs.a.w ^ r) & 0x8000);
|
|
regs.p.z = ((word)r == 0);
|
|
regs.p.c = (r >= 0);
|
|
regs.a.w = r;
|
|
}
|
|
|
|
//op_rmw
|
|
inline void bCPU::op_inc_b() {
|
|
rd.l++;
|
|
regs.p.n = !!(rd.l & 0x80);
|
|
regs.p.z = (rd.l == 0);
|
|
}
|
|
|
|
inline void bCPU::op_inc_w() {
|
|
rd.w++;
|
|
regs.p.n = !!(rd.w & 0x8000);
|
|
regs.p.z = (rd.w == 0);
|
|
}
|
|
|
|
inline void bCPU::op_dec_b() {
|
|
rd.l--;
|
|
regs.p.n = !!(rd.l & 0x80);
|
|
regs.p.z = (rd.l == 0);
|
|
}
|
|
|
|
inline void bCPU::op_dec_w() {
|
|
rd.w--;
|
|
regs.p.n = !!(rd.w & 0x8000);
|
|
regs.p.z = (rd.w == 0);
|
|
}
|
|
|
|
inline void bCPU::op_asl_b() {
|
|
regs.p.c = !!(rd.l & 0x80);
|
|
rd.l <<= 1;
|
|
regs.p.n = !!(rd.l & 0x80);
|
|
regs.p.z = (rd.l == 0);
|
|
}
|
|
|
|
inline void bCPU::op_asl_w() {
|
|
regs.p.c = !!(rd.w & 0x8000);
|
|
rd.w <<= 1;
|
|
regs.p.n = !!(rd.w & 0x8000);
|
|
regs.p.z = (rd.w == 0);
|
|
}
|
|
|
|
inline void bCPU::op_lsr_b() {
|
|
regs.p.c = rd.l & 1;
|
|
rd.l >>= 1;
|
|
regs.p.n = !!(rd.l & 0x80);
|
|
regs.p.z = (rd.l == 0);
|
|
}
|
|
|
|
inline void bCPU::op_lsr_w() {
|
|
regs.p.c = rd.w & 1;
|
|
rd.w >>= 1;
|
|
regs.p.n = !!(rd.w & 0x8000);
|
|
regs.p.z = (rd.w == 0);
|
|
}
|
|
|
|
inline void bCPU::op_rol_b() {
|
|
uint16 c = regs.p.c;
|
|
regs.p.c = !!(rd.l & 0x80);
|
|
rd.l <<= 1;
|
|
rd.l |= c;
|
|
regs.p.n = !!(rd.l & 0x80);
|
|
regs.p.z = (rd.l == 0);
|
|
}
|
|
|
|
inline void bCPU::op_rol_w() {
|
|
uint16 c = regs.p.c;
|
|
regs.p.c = !!(rd.w & 0x8000);
|
|
rd.w <<= 1;
|
|
rd.w |= c;
|
|
regs.p.n = !!(rd.w & 0x8000);
|
|
regs.p.z = (rd.w == 0);
|
|
}
|
|
|
|
inline void bCPU::op_ror_b() {
|
|
uint16 c = (regs.p.c)?0x80:0;
|
|
regs.p.c = rd.l & 1;
|
|
rd.l >>= 1;
|
|
rd.l |= c;
|
|
regs.p.n = !!(rd.l & 0x80);
|
|
regs.p.z = (rd.l == 0);
|
|
}
|
|
|
|
inline void bCPU::op_ror_w() {
|
|
uint16 c = (regs.p.c)?0x8000:0;
|
|
regs.p.c = rd.w & 1;
|
|
rd.w >>= 1;
|
|
rd.w |= c;
|
|
regs.p.n = !!(rd.w & 0x8000);
|
|
regs.p.z = (rd.w == 0);
|
|
}
|
|
|
|
inline void bCPU::op_trb_b() {
|
|
regs.p.z = ((rd.l & regs.a.l) == 0);
|
|
rd.l &= ~regs.a.l;
|
|
}
|
|
|
|
inline void bCPU::op_trb_w() {
|
|
regs.p.z = ((rd.w & regs.a.w) == 0);
|
|
rd.w &= ~regs.a.w;
|
|
}
|
|
|
|
inline void bCPU::op_tsb_b() {
|
|
regs.p.z = ((rd.l & regs.a.l) == 0);
|
|
rd.l |= regs.a.l;
|
|
}
|
|
|
|
inline void bCPU::op_tsb_w() {
|
|
regs.p.z = ((rd.w & regs.a.w) == 0);
|
|
rd.w |= regs.a.w;
|
|
}
|