Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- IF 0
- ld a, [wJumptableIndex]
- push af
- callw _Bootstrap
- pop af
- ld [wJumptableIndex], a
- ret
- ENDC
- _Bootstrap:
- ld hl, wBoxNames
- ld a, [hli]
- ld b, a
- add a
- jr c, .headerNotInMail
- push hl
- ld de, wc1d5
- push de
- callba $4, _ComposeMailMessage
- pop de
- ld a, [de]
- res 7, a
- ld [de], a
- ld b, a
- ld hl, wBoxNames
- call CopyName2
- pop hl
- .headerNotInMail
- callw DecodeCharPairPointer
- ld h, d
- ld l, e ; hl = bootstrap dest or execute src
- ld a, b
- cp "-"
- jr nz, .notDirectExecute
- jp hl
- .notDirectExecute
- bit 2, b
- jr z, .bootstrap
- and $3
- call OpenSRAM
- ld a, [hli]
- ld b, a
- ld a, [hli]
- ld c, a
- ld a, [hli]
- ld d, a
- ld a, [hli]
- ld e, 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
- push de ; push mail buffer
- .retryMail
- callba $4, _ComposeMailMessage
- pop hl
- push de
- ld d, h
- ld e, l
- ld bc, 0
- ; hl & de = original mail buffer
- .checksumMsgLoop
- callw CharPairDecode
- ld [de], a
- inc de
- add c
- ld c, a
- jr nc, .noCarry
- inc b
- .noCarry
- ld a, [hl]
- cp "@"
- jr z, .doneChecksum
- cp "!"
- jr nz, .checksumMsgLoop
- .doneChecksum
- push af ; "!" flag
- push de ; end of compiled message
- push bc ; checksum
- ld hl, sp+$0
- ld d, h
- ld e, l
- coord hl, 5, 0
- ld c, PRINTNUM_LEADINGZEROS | PRINTNUM_LEFTALIGN | 2
- call PrintBCDNumber
- call YesNoBox
- pop bc
- pop de
- pop bc
- jr c, .retryMail
- pop de
- ld a, b
- cp "!"
- jr nz, .getBootstrapCharsLoop
- .bootstrapFinished
- pop hl ; mail buffer
- ld a, e
- sub l
- ld c, a
- ld a, d
- sbc h
- ld b, a ; get count
- dec bc
- dec bc
- pop de ; dest
- pop af ; save a byte here as b goes into a
- and $3 ; bank
- call OpenSRAM
- ; copy bootstrap dest
- ld a, [hli]
- ld [de], a
- inc de
- ld a, [hli]
- ld [de], a
- inc de
- ld a, b
- ld [de], a
- inc de
- ld a, c
- ld [de], a
- inc de
- call CopyBytes
- .closeSRAM
- jp CloseSRAM
- DecodeCharPairPointer:
- callw CharPairDecode
- ld d, a
- callw CharPairDecode
- ld e, a
- ret
- CharPairDecode:
- push bc
- callw ReadAndFilterChar
- add a
- add a
- add a
- add a
- ld b, a
- callw ReadAndFilterChar
- and $f
- or b
- pop bc
- ret
- ReadAndFilterChar:
- ld a, [hl]
- cp $4e
- jr nz, .notNewline
- inc hl
- .notNewline
- ld a, [wBoxNames]
- bit 4, a
- ld a, [hli]
- ret z
- add a, 10
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement