Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- INCLUDE "charmap.asm"
- ; bit 0-1: sram bank
- ; bit 2: bootstrap or execute
- ; bit 3: specify bootstrap mail buffer scratch dest
- ; bit 4: base16 or hex encoding. base16 assumes little endian, hex encoding assumes big endian
- ; if upper 7 bits are %1110001 (- or /), execute directly. bit 4 corresponds to jump encoding
- wBoxNames EQU $d8bf
- OpenSRAM EQU $30e1
- CloseSRAM EQU $30f1
- jp_de EQU $30fd
- CopyBytes EQU $311a
- wOverworldMap EQU $c700
- _ComposeMailMessage EQU $6242
- wJumptableIndex EQU $ce63
- SECTION "Bootstrap", ROM0
- callw: MACRO
- if _NARG == 1
- call \1 + $d6f3
- else
- call \1, \2 + $d6f3
- endc
- ENDM
- Bootstrap::
- ld a, [wJumptableIndex]
- push af
- callw _Bootstrap
- pop af
- ld [wJumptableIndex], a
- ret
- _Bootstrap:
- ld hl, wBoxNames
- ld a, [hli]
- ld b, a
- callw DecodeCharPairPointer
- ld h, d
- ld l, e ; hl = bootstrap dest or execute src
- ld a, b
- and "-"
- cp "-"
- jr nz, .notDirectExecute
- jp hl
- .notDirectExecute
- bit 2, b
- jr z, .bootstrap
- ld a, b
- and $3
- call OpenSRAM
- ld a, [hli]
- ld b, a
- ld a, [hli]
- ld c, a
- ld a, [hli]
- ld e, a
- ld a, [hli]
- ld d, a
- push de ; execute dest
- call CopyBytes
- call jp_de + 1 ; skip push de as de is already pushed
- jr .closeSRAM
- .bootstrap
- push bc ; save flags for later
- push de ; save dest for later
- bit 3, b
- ld de, wOverworldMap + $55 ; mail buffer dest
- ld hl, wBoxNames + 9
- callw nz, DecodeCharPairPointer
- push de ; save mail buffer dest for later
- .getBootstrapCharsLoop
- ld hl, _ComposeMailMessage
- ld a, $4
- rst $08
- dec de
- ld a, [de]
- inc de
- cp "!"
- jr nz, .getBootstrapCharsLoop
- pop hl ; mail buffer
- pop de ; dest
- pop af ; save a byte here as b goes into a
- and $3 ; bank
- call OpenSRAM
- callw CharPairDecode
- ld [de], a
- inc de
- callw CharPairDecode
- ld [de], a
- inc de
- push de ; save count dest for later
- inc de
- inc de
- ld bc, 0
- .bootstrapCopyLoop
- callw CharPairDecode
- ld [de], a
- inc de
- inc bc
- ld a, [hl]
- cp "!"
- jr nz, .bootstrapCopyLoop
- pop hl
- ld a, b
- ld [hli], a
- ld [hl], c
- .closeSRAM
- jp CloseSRAM
- DecodeCharPairPointer:
- callw CharPairDecode
- ld d, a
- callw CharPairDecode
- ld e, a
- ret
- CharPairDecode:
- push bc
- ld a, [wBoxNames]
- bit 4, a
- jr nz, .HexDecode
- ; fallthrough
- .Base16Decode:
- callw ReadAndFilterChar
- add a
- add a
- add a
- add a
- ld b, a
- callw ReadAndFilterChar
- and $f
- jr .orPopAndReturn
- .HexDecode:
- callw HexDecodeChar
- add a
- add a
- add a
- add a
- ld b, a
- callw HexDecodeChar
- .orPopAndReturn
- or b
- pop bc
- ret
- HexDecodeChar:
- ; saves 1 byte
- callw ReadAndFilterChar
- sub "0"
- ret nc
- add ("0" - "A" + $0a)
- ret
- ReadAndFilterChar:
- ld a, [hli]
- cp $4e
- ret nz
- ld a, [hli]
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement