From efc8cc5dd78c9126c9e3ced9be2c99c6b962703a Mon Sep 17 00:00:00 2001 From: Joshua Wise Date: Wed, 21 May 2008 16:12:51 -0400 Subject: [PATCH] Fix POP AF test (from blargg's CPU tests) --- auxboot.c | 9 +-- core/insn_pop_reg.v | 2 +- flashboot.asm | 80 +++++++++++++++++++++++ flashdiag.asm | 65 +++++++++++++++++++ flashprog.asm | 151 ++++++++++++++++++++++++++++++++++++++++++++ fpgaboot.asm | 6 +- 6 files changed, 303 insertions(+), 10 deletions(-) create mode 100644 flashboot.asm create mode 100644 flashdiag.asm create mode 100644 flashprog.asm diff --git a/auxboot.c b/auxboot.c index c5ce3af..2024bfe 100644 --- a/auxboot.c +++ b/auxboot.c @@ -13,11 +13,8 @@ void main() { char buf[259]; int sz; - buf[0] = 0x1B; - buf[1] = 'A'; - buf[2] = buf[3] = buf[4] = 0; - dowrite(buf, 5); + buf[0] = '\e'; buf[1] = 'P'; - read(0, buf+2, 127); - dowrite(buf, 129); + read(0, buf+2, 256); + dowrite(buf, 257); } \ No newline at end of file diff --git a/core/insn_pop_reg.v b/core/insn_pop_reg.v index 55d12ec..dbe601c 100644 --- a/core/insn_pop_reg.v +++ b/core/insn_pop_reg.v @@ -19,7 +19,7 @@ 0: begin end 1: begin case (opcode[5:4]) - `INSN_stack_AF: `_F <= rdata; + `INSN_stack_AF: `_F <= rdata & 8'hF0; `INSN_stack_BC: `_C <= rdata; `INSN_stack_DE: `_E <= rdata; `INSN_stack_HL: `_L <= rdata; diff --git a/flashboot.asm b/flashboot.asm new file mode 100644 index 0000000..3987ac3 --- /dev/null +++ b/flashboot.asm @@ -0,0 +1,80 @@ + SECTION "wee",HOME[$0] + ld sp, $CFFF + + ld hl, loading+$D800 + call puts+$D800 + + ld a, $FF ; Put the thing in read array mode. + ld [$FF65], a + + xor a + ld d, a + ld e, a + +loop: ld a, $04 + cp d + jr z,done + + xor c +ifl: ld a, d ; Set up for the flash read. + ld [$FF60], a + ld a, e + ld [$FF61], a + ld a, c + ld [$FF62], a + ld a, [$FF65] + ld b, a + ld a, d ; Set up for the flash read. + ld [$FF60], a + ld a, e + ld [$FF61], a + ld a, c + ld [$FF62], a + ld a, b + ld [$FF63], a + inc c + jr nz, ifl + + ld a, $2E ;. + call putc+$D800 + + inc de + jr loop +done: + ld hl, booting+$D800 + call puts+$D800 + + xor a + ld h, a + ld l, a + ld [hl], $01 ; Select the GB boot rom + + rst $00 ; Boot + +putc: + push bc + ld c, $53 + push af +.waitport: + ld a,[c] + and $01 + jr nz,.waitport + pop af + ld [$FF52],a + pop bc + ret + +loading: + db "Loading...",0 +booting: + db $0D,$0A,"Booting...",$0D,$0A,0 + +puts: + ld a, [hli] + cp $00 + ret z + call putc+$D800 + jr puts + + section "a", HOME[$FF] + nop diff --git a/flashdiag.asm b/flashdiag.asm new file mode 100644 index 0000000..2d0738c --- /dev/null +++ b/flashdiag.asm @@ -0,0 +1,65 @@ + SECTION "wee",HOME[$0] + ld sp, $CFFF + ld hl, $FF60 + ld a, $FF + ld [hli], a + ld [hli], a + ld [hli], a + ld a, $90 ; device info + ld [$FF65], a + + call rn+$FF80 + + ld a, [$FF65] ; 0000 + call puthex + $FF80 + + call rn+$FF80 + + ld a, [$FF65] ; 0000 + call puthex + $FF80 + + call rn+$FF80 + + jp $0000 + +puthex: + push af + swap a + and $0F + ld hl, hexdig+$FF80 + add l + ld l, a + ld a, [hl] + call putc+$FF80 + pop af + and $0F + ld hl, hexdig+$FF80 + add l + ld l, a + ld a, [hl] + call putc+$FF80 + ret + +hexdig: + db "0123456789ABCDEF" + +putc: + ld c, $53 + push af +.waitport: + ld a,[c] + and $01 + jr nz,.waitport + pop af + ld [$FF52],a + ret + +rn: + ld a, 13 + call putc+$FF80 + ld a, 10 + jr putc + + + section "a", HOME[$7E] + nop diff --git a/flashprog.asm b/flashprog.asm new file mode 100644 index 0000000..c0f74da --- /dev/null +++ b/flashprog.asm @@ -0,0 +1,151 @@ + SECTION "wee",HOME[$0] + ld hl, $D000 + ld sp, hl + + xor a + ld [$FF60], a + ld [$FF61], a + ld [$FF62], a + + ld a, $50 ; Clear SR + ld [$FF65], a + + call unlock+$D800 + xor a + ld d, a + ld e, a + call erase+$D800 + + xor a + ld d, a + ld e, a + +loop: ld a, $04 + cp d + jr z,done + + xor a + ld c, a ; Count + +ifl: call program+$D800 + xor a + cp c + jr nz, ifl +ifldone: + + ld a, $70 + ld [$FF65], a + ld a, [$FF65] ; Load from the status register + call puthex+$D800 + +; ld a, $2E ;. +; call putc+$D800 + + inc de + jr loop +done: + rst $00 + +putc: + push af +.wport: + ld a,[$FF53] + and $01 + jr nz,.wport + pop af + ld [$FF52],a + ret + +puthex: + push hl + ld hl, hexdig+$D800 + push hl + push af + swap a + and $0F + add l + ld l, a + ld a, [hl] + call putc+$D800 + pop af + and $0F + pop hl + add l + ld l, a + ld a, [hl] + pop hl + jr putc + +hexdig: + db "0123456789ABCDEF" + +unlock: + ld a, $55 + call putc+$D800 + ld a, $60 ; Unlock the device + ld [$FF65], a + ld a, $D0 + ld [$FF65], a + call waitrdy+$D800 + ld a, [$FF65] + call puthex+$D800 + ret + +erase: + ld a, $45 + call putc+$D800 + ld a, d + ld [$FF60], a + ld a, e + ld [$FF61], a + xor a + ld [$FF62], a + ld a, $20 ; Unlock the device + ld [$FF65], a + ld a, $D0 + ld [$FF65], a + call waitrdy+$D800 + ld a, [$FF65] + call puthex+$D800 + ret + +; need to save d, e, and c +program: + ld a, d + ld [$FF60], a + ld a, e + ld [$FF61], a + ld a, c + ld [$FF62], a + ld a, $40 + ld [$FF65], a + ld a, d + ld [$FF60], a + ld a, e + ld [$FF61], a + ld a, c + ld [$FF62], a + ld a, [$FF63] + ld b, a + ld a, d + ld [$FF60], a + ld a, e + ld [$FF61], a + ld a, c + ld [$FF62], a + ld a, b + ld [$FF65], a + call waitrdy+$D800 + inc c + ret + +waitrdy: + ld a, $70 ; Wait status register. + ld [$FF65], a +.wrl: ld a, [$FF65] ; Wait for bit 7 to come back on again. + bit 7,a + jr z, .wrl + ret + + section "a", HOME[$FF] + nop diff --git a/fpgaboot.asm b/fpgaboot.asm index 6cb9613..dfb4ec9 100644 --- a/fpgaboot.asm +++ b/fpgaboot.asm @@ -107,8 +107,8 @@ bootcmd: jr putc .prog: - ld hl, $FF80 - ld c, $7F + ld hl, $D800 + ld c, $00 .pl: dec c jp z, .progboot call getc @@ -117,7 +117,7 @@ bootcmd: .progboot: ld a, $50 ;P call putc - jp $FF80 + jp $D800 SECTION "a", HOME[$100] nop ; Make sure we don't overflow. -- 2.43.0