mirror of
https://github.com/toyoshim/Applerm-II.git
synced 2024-06-11 08:29:34 +00:00
Fix branch operation bugs
- address calculation on not taken - use macro to implement each branch operation
This commit is contained in:
parent
8d94c76d47
commit
ff1f7b8b2f
69
6502.S
69
6502.S
|
@ -401,8 +401,27 @@
|
||||||
1:
|
1:
|
||||||
.endm
|
.endm
|
||||||
|
|
||||||
|
.macro _bxc reg
|
||||||
|
adds PC, PC, #1
|
||||||
|
movs r0, #\reg
|
||||||
|
tst SR, r0
|
||||||
|
bne 1f
|
||||||
|
_bxx
|
||||||
|
1:
|
||||||
|
.endm
|
||||||
|
|
||||||
|
.macro _bxs reg
|
||||||
|
adds PC, PC, #1
|
||||||
|
movs r0, #\reg
|
||||||
|
tst SR, r0
|
||||||
|
beq 1f
|
||||||
|
_bxx
|
||||||
|
1:
|
||||||
|
.endm
|
||||||
|
|
||||||
.macro _bxx
|
.macro _bxx
|
||||||
_fromImmb
|
mov r0, PC
|
||||||
|
_ldb
|
||||||
sxtb r0, r0
|
sxtb r0, r0
|
||||||
add PC, PC, r0
|
add PC, PC, r0
|
||||||
.endm
|
.endm
|
||||||
|
@ -807,11 +826,7 @@ op0e: // ASL - Absolute
|
||||||
_decode
|
_decode
|
||||||
|
|
||||||
op10: // BPL (N==0)
|
op10: // BPL (N==0)
|
||||||
movs r0, #FLAG_N
|
_bxc FLAG_N
|
||||||
tst SR, r0
|
|
||||||
bne 1f
|
|
||||||
_bxx
|
|
||||||
1:
|
|
||||||
_decode
|
_decode
|
||||||
|
|
||||||
op11: // ORA - (Indirect), Y
|
op11: // ORA - (Indirect), Y
|
||||||
|
@ -913,11 +928,7 @@ op2e: // ROL - Absolute
|
||||||
_decode
|
_decode
|
||||||
|
|
||||||
op30: // BMI (N==1)
|
op30: // BMI (N==1)
|
||||||
movs r0, #FLAG_N
|
_bxs FLAG_N
|
||||||
tst SR, r0
|
|
||||||
beq 1f
|
|
||||||
_bxx
|
|
||||||
1:
|
|
||||||
_decode
|
_decode
|
||||||
|
|
||||||
op31: // AND - (Indirect), Y
|
op31: // AND - (Indirect), Y
|
||||||
|
@ -1010,11 +1021,7 @@ op4e: // LSR - Absolute
|
||||||
_decode
|
_decode
|
||||||
|
|
||||||
op50: // BVC (V==0)
|
op50: // BVC (V==0)
|
||||||
movs r0, #FLAG_V
|
_bxc FLAG_V
|
||||||
tst SR, r0
|
|
||||||
bne 1f
|
|
||||||
_bxx
|
|
||||||
1:
|
|
||||||
_decode
|
_decode
|
||||||
|
|
||||||
op51: // EOR - (Indirect), Y
|
op51: // EOR - (Indirect), Y
|
||||||
|
@ -1111,11 +1118,7 @@ op6e: // ROR - Absolute
|
||||||
_decode
|
_decode
|
||||||
|
|
||||||
op70: // BVS (V==1)
|
op70: // BVS (V==1)
|
||||||
movs r0, #FLAG_V
|
_bxs FLAG_V
|
||||||
tst SR, r0
|
|
||||||
beq 1f
|
|
||||||
_bxx
|
|
||||||
1:
|
|
||||||
_decode
|
_decode
|
||||||
|
|
||||||
op71: // ADC - (Indirect), Y
|
op71: // ADC - (Indirect), Y
|
||||||
|
@ -1199,11 +1202,7 @@ op8e: // STX - Absolute
|
||||||
_decode
|
_decode
|
||||||
|
|
||||||
op90: // BCC (C==0)
|
op90: // BCC (C==0)
|
||||||
movs r0, #FLAG_C
|
_bxc FLAG_C
|
||||||
tst SR, r0
|
|
||||||
bne 1f
|
|
||||||
_bxx
|
|
||||||
1:
|
|
||||||
_decode
|
_decode
|
||||||
|
|
||||||
op91: // STA - (Indirect), Y
|
op91: // STA - (Indirect), Y
|
||||||
|
@ -1308,11 +1307,7 @@ opae: // LDX - Absolute
|
||||||
_decode
|
_decode
|
||||||
|
|
||||||
opb0: // BCS (C==1)
|
opb0: // BCS (C==1)
|
||||||
movs r0, #FLAG_C
|
_bxs FLAG_C
|
||||||
tst SR, r0
|
|
||||||
beq 1f
|
|
||||||
_bxx
|
|
||||||
1:
|
|
||||||
_decode
|
_decode
|
||||||
|
|
||||||
opb1: // LDA - (Indirect), Y
|
opb1: // LDA - (Indirect), Y
|
||||||
|
@ -1423,11 +1418,7 @@ opce: // DEC - Absolute
|
||||||
_decode
|
_decode
|
||||||
|
|
||||||
opd0: // BNE (Z==0)
|
opd0: // BNE (Z==0)
|
||||||
movs r0, #FLAG_Z
|
_bxc FLAG_Z
|
||||||
tst SR, r0
|
|
||||||
bne 1f
|
|
||||||
_bxx
|
|
||||||
1:
|
|
||||||
_decode
|
_decode
|
||||||
|
|
||||||
opd1: // CMP - (Indirect), Y
|
opd1: // CMP - (Indirect), Y
|
||||||
|
@ -1520,11 +1511,7 @@ opee: // INC - Absolute
|
||||||
_decode
|
_decode
|
||||||
|
|
||||||
opf0: // BEQ (Z==1)
|
opf0: // BEQ (Z==1)
|
||||||
movs r0, #FLAG_Z
|
_bxs FLAG_Z
|
||||||
tst SR, r0
|
|
||||||
beq 1f
|
|
||||||
_bxx
|
|
||||||
1:
|
|
||||||
_decode
|
_decode
|
||||||
|
|
||||||
opf1: // SBC - (Indirect), Y
|
opf1: // SBC - (Indirect), Y
|
||||||
|
|
3
test.c
3
test.c
|
@ -14,15 +14,18 @@ void cpu6502_dump(
|
||||||
"NV-B_DIZC=%d%d-%d_%d%d%d%d\n",
|
"NV-B_DIZC=%d%d-%d_%d%d%d%d\n",
|
||||||
pc, a, x, y, sp, (sr >> 7) & 1, (sr >> 6) & 1, (sr >> 4) & 1,
|
pc, a, x, y, sp, (sr >> 7) & 1, (sr >> 6) & 1, (sr >> 4) & 1,
|
||||||
(sr >> 3) & 1, (sr >> 2) & 1, (sr >> 1) & 1, sr & 1);
|
(sr >> 3) & 1, (sr >> 2) & 1, (sr >> 1) & 1, sr & 1);
|
||||||
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t cpu6502_load(uint16_t addr) {
|
uint8_t cpu6502_load(uint16_t addr) {
|
||||||
printf("load $%04x => $%02x\n", addr, mem[addr]);
|
printf("load $%04x => $%02x\n", addr, mem[addr]);
|
||||||
|
fflush(stdout);
|
||||||
return mem[addr];
|
return mem[addr];
|
||||||
}
|
}
|
||||||
|
|
||||||
void cpu6502_store(uint16_t addr, uint8_t data) {
|
void cpu6502_store(uint16_t addr, uint8_t data) {
|
||||||
printf("store $%04x <= $%02x\n", addr, data);
|
printf("store $%04x <= $%02x\n", addr, data);
|
||||||
|
fflush(stdout);
|
||||||
mem[addr] = data;
|
mem[addr] = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user