SECTION "boot", HOME[$0]
- ld a, $AA
+boot: ld a, $AA
ld [$FF51], A ; Poke the LEDs
+
+ ld sp, $FFFE
- ; Write a little bit to the RAM
- ld H, $01
- ld L, $00
- ld A, $00
- ld [HLI], A
- ld [HLI], A
- ld [HLI], A
- ld [HLI], A
- ld [HLI], A
- ld [HLI], A
- ld [HLI], A
- ld [HLI], A
+ ld hl, signon
+ call puts
+
+.wait: ld a, [$FF53]
+ and $02
+ jr z, .nodata
+ ld a, [$FF52]
+ ld [$FF51], a
+
+ cp $1B ; Escape
+ jp z, .cbc
+ ld [$FF52], a
+.cbc: call z, bootcmd
+
+.nodata: ld a, [$FF51]
+ cp $00
+ jr nz, .wait
+
+doboot: xor a
+ ld h, a
+ ld l, a
+ ld [hl], $01 ; Select the GB boot rom
ld a, $55
- ld [$FF51], A ; Poke the LEDs
+ ld [c], a
- ld A, $FF
- ld [HLI], A
- ld [HLI], A
- ld [HLI], A
- ld [HLI], A
- ld [HLI], A
- ld [HLI], A
- ld [HLI], A
- ld [HLI], A
+ ld hl, booting
+ call puts
- ld H, $00
- ld L, $00
- ld [HL], $01 ; Select the GB boot rom
rst $00 ; Boot
+
+signon:
+ db $0D,$0A,$1B,"[1mFPGABoy Boot ROM",$1B,"[0m",$0D,$0A,0
+booting:
+ db "Booting...",$0D,$0A,0
+
+putc:
+ ld c, $53
+ push af
+.waitport:
+ ld a,[c]
+ and $01
+ jr nz,.waitport
+ pop af
+ ld [$FF52],a
+ ret
+
+puts:
+ ld a, [hli]
+ cp $00
+ ret z
+ call putc
+ jr puts
+
+getc:
+ ld a, [$FF53]
+ and $02
+ jr z, getc
+ ld a, [$FF52]
+ ret
+
+bootcmd:
+ call getc
+ cp $56 ;V
+ jr z,.version
+ cp $41 ;A
+ jr z,.addr
+ cp $44 ;D
+ jr z,.data
+ cp $50 ;P
+ jr z,.prog
+ cp $42 ;B
+ jr z,doboot
+ cp $1B
+ jr z,bootcmd ; If you keep yelling, you're bound to get the thing's attention.
+ ld a, $3f ;?
+ jr putc
+.version:
+ ld hl, .verstr
+ jr puts
+.verstr:
+ db "V1.00",0
+.addr:
+ call getc
+ ld [$FF60], A
+ call getc
+ ld [$FF61], A
+ call getc
+ ld [$FF62], A
+ ld A, $41 ;A
+ jr putc
+.data:
+ call getc ; byte count
+ ld c, a
+.dl: dec c
+ jr z, .done
+ call getc
+ ld [$FF63], A
+ jr .dl
+.done: ld A, $44 ;D
+ jr putc
+
+.prog:
+ ld hl, $FF80
+ ld c, $7F
+.pl: dec c
+ jp z, .progboot
+ call getc
+ ld [hli], a
+ jr .pl
+.progboot:
+ ld a, $50 ;P
+ call putc
+ jp $FF80
SECTION "a", HOME[$100]
nop ; Make sure we don't overflow.