rename common/ to home/

This commit is contained in:
yenatch
2013-09-09 22:44:48 -04:00
parent 6439706943
commit 84a9b3907b
31 changed files with 30 additions and 30 deletions

431
home/copy.asm Normal file
View File

@@ -0,0 +1,431 @@
; Functions to copy data from ROM.
Functiondc9: ; dc9
ld a, [rLCDC]
bit 7, a
jp z, Copy2bpp
ld a, [hROMBank]
push af
ld a, BANK(Function104284)
rst Bankswitch
call Function104284
pop af
rst Bankswitch
ret
; ddc
Functionddc: ; ddc
ld a, [rLCDC]
bit 7, a
jp z, Copy1bpp
ld a, [hROMBank]
push af
ld a, BANK(Function1042b2)
rst Bankswitch
call Function1042b2
pop af
rst Bankswitch
ret
; def
Functiondef: ; def
ld [hBuffer], a
ld a, [hROMBank]
push af
ld a, [hBuffer]
rst Bankswitch
call FarCopyBytesDouble
pop af
rst Bankswitch
ret
; dfd
Functiondfd: ; dfd
dec c
ld a, [hBGMapMode]
push af
xor a
ld [hBGMapMode], a
ld a, [hROMBank]
push af
ld a, b
rst Bankswitch
.asm_e09
ld a, d
ld [rHDMA1], a
ld a, e
and $f0
ld [rHDMA2], a
ld a, h
and $1f
ld [rHDMA3], a
ld a, l
and $f0
ld [rHDMA4], a
ld a, c
cp $8
jr c, .asm_e3c
sub $8
ld c, a
ld a, $f
ld [hDMATransfer], a
call DelayFrame
ld a, l
add $0
ld l, a
ld a, h
adc $1
ld h, a
ld a, e
add $0
ld e, a
ld a, d
adc $1
ld d, a
jr .asm_e09
.asm_e3c
ld a, c
and $7f
ld [hDMATransfer], a
call DelayFrame
pop af
rst Bankswitch
pop af
ld [hBGMapMode], a
ret
; e4a
Functione4a: ; e4a
ld a, $5
ld hl, $4135
rst FarCall
ret
; e51
Functione51: ; e51
ld a, $3e
ld hl, $7449
rst FarCall
ret
; e58
Functione58: ; e58
ld a, $3e
ld hl, $74be
rst FarCall
ret
; e5f
Functione5f: ; e5f
ld a, $3e
ld hl, $748a
rst FarCall
ld a, $3e
ld hl, $74b0
rst FarCall
ret
; e6c
Functione6c: ; e6c
ld a, $3e
ld hl, $74b0
rst FarCall
ret
; e73
Functione73: ; e73
push de
ld a, $0
call GetSRAMBank
push bc
ld de, $a000
ld a, b
call FarDecompress
pop bc
pop hl
ld de, $a000
call Request2bpp
call CloseSRAM
ret
; e8d
FarCopyBytes: ; e8d
; copy bc bytes from a:hl to de
ld [hBuffer], a
ld a, [hROMBank]
push af
ld a, [hBuffer]
rst Bankswitch
call CopyBytes
pop af
rst Bankswitch
ret
; 0xe9b
FarCopyBytesDouble: ; e9b
; Copy bc bytes from a:hl to bc*2 bytes at de,
; doubling each byte in the process.
ld [hBuffer], a
ld a, [hROMBank]
push af
ld a, [hBuffer]
rst Bankswitch
; switcheroo, de <> hl
ld a, h
ld h, d
ld d, a
ld a, l
ld l, e
ld e, a
inc b
inc c
jr .dec
.loop
ld a, [de]
inc de
ld [hli], a
ld [hli], a
.dec
dec c
jr nz, .loop
dec b
jr nz, .loop
pop af
rst Bankswitch
ret
; 0xeba
Request2bpp: ; eba
ld a, [hBGMapMode]
push af
xor a
ld [hBGMapMode], a
ld a, [hROMBank]
push af
ld a, b
rst Bankswitch
ld a, [$ffd3]
push af
ld a, $8
ld [$ffd3], a
ld a, [InLinkBattle]
cp $4
jr nz, .asm_edc
ld a, [$ffe9]
and a
jr nz, .asm_edc
ld a, $6
ld [$ffd3], a
.asm_edc
ld a, e
ld [Requested2bppSource], a
ld a, d
ld [Requested2bppSource + 1], a
ld a, l
ld [Requested2bppDest], a
ld a, h
ld [Requested2bppDest + 1], a
.asm_eec
ld a, c
ld hl, $ffd3
cp [hl]
jr nc, .asm_f08
ld [Requested2bpp], a
.wait
call DelayFrame
ld a, [Requested2bpp]
and a
jr nz, .wait
pop af
ld [$ffd3], a
pop af
rst Bankswitch
pop af
ld [hBGMapMode], a
ret
.asm_f08
ld a, [$ffd3]
ld [Requested2bpp], a
.asm_f0d
call DelayFrame
ld a, [Requested2bpp]
and a
jr nz, .asm_f0d
ld a, c
ld hl, $ffd3
sub [hl]
ld c, a
jr .asm_eec
; f1e
Request1bpp: ; f1e
ld a, [hBGMapMode]
push af
xor a
ld [hBGMapMode], a
ld a, [hROMBank]
push af
ld a, b
rst Bankswitch
ld a, [$ffd3]
push af
ld a, $8
ld [$ffd3], a
ld a, [InLinkBattle]
cp $4
jr nz, .asm_f40
ld a, [$ffe9]
and a
jr nz, .asm_f40
ld a, $6
ld [$ffd3], a
.asm_f40
ld a, e
ld [Requested1bppSource], a
ld a, d
ld [Requested1bppSource + 1], a
ld a, l
ld [Requested1bppDest], a
ld a, h
ld [Requested1bppDest + 1], a
.asm_f50
ld a, c
ld hl, $ffd3
cp [hl]
jr nc, .asm_f6c
ld [Requested1bpp], a
.wait
call DelayFrame
ld a, [Requested1bpp]
and a
jr nz, .wait
pop af
ld [$ffd3], a
pop af
rst Bankswitch
pop af
ld [hBGMapMode], a
ret
.asm_f6c
ld a, [$ffd3]
ld [Requested1bpp], a
.asm_f71
call DelayFrame
ld a, [Requested1bpp]
and a
jr nz, .asm_f71
ld a, c
ld hl, $ffd3
sub [hl]
ld c, a
jr .asm_f50
; f82
Get2bpp: ; f82
ld a, [rLCDC]
bit 7, a
jp nz, Request2bpp
Copy2bpp: ; f89
; copy c 2bpp tiles from b:de to hl
push hl
ld h, d
ld l, e
pop de
; bank
ld a, b
; bc = c * $10
push af
swap c
ld a, $f
and c
ld b, a
ld a, $f0
and c
ld c, a
pop af
jp FarCopyBytes
; f9d
Get1bpp: ; f9d
ld a, [rLCDC]
bit 7, a
jp nz, Request1bpp
Copy1bpp: ; fa4
; copy c 1bpp tiles from b:de to hl
push de
ld d, h
ld e, l
; bank
ld a, b
; bc = c * $10 / 2
push af
ld h, 0
ld l, c
add hl, hl
add hl, hl
add hl, hl
ld b, h
ld c, l
pop af
pop hl
jp FarCopyBytesDouble
; fb6

134
home/copy2.asm Normal file
View File

@@ -0,0 +1,134 @@
CopyBytes: ; 0x3026
; copy bc bytes from hl to de
inc b ; we bail the moment b hits 0, so include the last run
inc c ; same thing; include last byte
jr .HandleLoop
.CopyByte
ld a, [hli]
ld [de], a
inc de
.HandleLoop
dec c
jr nz, .CopyByte
dec b
jr nz, .CopyByte
ret
SwapBytes: ; 0x3034
; swap bc bytes between hl and de
.Loop
; stash [hl] away on the stack
ld a, [hl]
push af
; copy a byte from [de] to [hl]
ld a, [de]
ld [hli], a
; retrieve the previous value of [hl]; put it in [de]
pop af
ld [de], a
inc de
; handle loop stuff
dec bc
ld a, b
or c
jr nz, .Loop
ret
ByteFill: ; 0x3041
; fill bc bytes with the value of a, starting at hl
inc b ; we bail the moment b hits 0, so include the last run
inc c ; same thing; include last byte
jr .HandleLoop
.PutByte
ld [hli], a
.HandleLoop
dec c
jr nz, .PutByte
dec b
jr nz, .PutByte
ret
GetFarByte: ; 0x304d
; retrieve a single byte from a:hl, and return it in a.
; bankswitch to new bank
ld [hBuffer], a
ld a, [hROMBank]
push af
ld a, [hBuffer]
rst Bankswitch
; get byte from new bank
ld a, [hl]
ld [hBuffer], a
; bankswitch to previous bank
pop af
rst Bankswitch
; return retrieved value in a
ld a, [hBuffer]
ret
GetFarHalfword: ; 0x305d
; retrieve a halfword from a:hl, and return it in hl.
; bankswitch to new bank
ld [hBuffer], a
ld a, [hROMBank]
push af
ld a, [hBuffer]
rst Bankswitch
; get halfword from new bank, put it in hl
ld a, [hli]
ld h, [hl]
ld l, a
; bankswitch to previous bank and return
pop af
rst Bankswitch
ret
; 0x306b
FarCopyWRAM: ; 306b
ld [hBuffer], a
ld a, [rSVBK]
push af
ld a, [hBuffer]
ld [rSVBK], a
call CopyBytes
pop af
ld [rSVBK], a
ret
; 307b
GetFarWRAMByte: ; 307b
ld [hBuffer], a
ld a, [rSVBK]
push af
ld a, [hBuffer]
ld [rSVBK], a
ld a, [hl]
ld [hBuffer], a
pop af
ld [rSVBK], a
ld a, [hBuffer]
ret
; 308d
GetFarWRAMWord: ; 308d
ld [hBuffer], a
ld a, [rSVBK]
push af
ld a, [hBuffer]
ld [rSVBK], a
ld a, [hli]
ld h, [hl]
ld l, a
pop af
ld [rSVBK], a
ret
; 309d

367
home/decompress.asm Normal file
View File

@@ -0,0 +1,367 @@
FarDecompress: ; b40
; Decompress graphics data at a:hl to de
; put a away for a sec
ld [$c2c4], a
; save bank
ld a, [hROMBank]
push af
; bankswitch
ld a, [$c2c4]
rst Bankswitch
; what we came here for
call Decompress
; restore bank
pop af
rst Bankswitch
ret
; b50
Decompress: ; b50
; Pokemon Crystal uses an lz variant for compression.
; This is mainly used for graphics, but the intro's
; tilemaps also use this compression.
; This function decompresses lz-compressed data at hl to de.
; Basic rundown:
; A typical control command consists of:
; -the command (bits 5-7)
; -the count (bits 0-4)
; -and any additional params
; $ff is used as a terminator.
; Commands:
; 0: literal
; literal data for some number of bytes
; 1: iterate
; one byte repeated for some number of bytes
; 2: alternate
; two bytes alternated for some number of bytes
; 3: zero (whitespace)
; 0x00 repeated for some number of bytes
; Repeater control commands have a signed parameter used to determine the start point.
; Wraparound is simulated:
; Positive values are added to the start address of the decompressed data
; and negative values are subtracted from the current position.
; 4: repeat
; repeat some number of bytes from decompressed data
; 5: flipped
; repeat some number of flipped bytes from decompressed data
; ex: $ad = %10101101 -> %10110101 = $b5
; 6: reverse
; repeat some number of bytes in reverse from decompressed data
; If the value in the count needs to be larger than 5 bits,
; control code 7 can be used to expand the count to 10 bits.
; A new control command is read in bits 2-4.
; The new 10-bit count is split:
; bits 0-1 contain the top 2 bits
; another byte is added containing the latter 8
; So, the structure of the control command becomes:
; 111xxxyy yyyyyyyy
; | | | |
; | | our new count
; | the control command for this count
; 7 (this command)
; For more information, refer to the code below and in extras/gfx.py .
; save starting output address
ld a, e
ld [$c2c2], a
ld a, d
ld [$c2c3], a
.loop
; get next byte
ld a, [hl]
; done?
cp $ff ; end
ret z
; get control code
and %11100000
; 10-bit param?
cp $e0 ; LZ_HI
jr nz, .normal
; 10-bit param:
; get next 3 bits (%00011100)
ld a, [hl]
add a
add a ; << 3
add a
; this is our new control code
and %11100000
push af
; get param hi
ld a, [hli]
and %00000011
ld b, a
; get param lo
ld a, [hli]
ld c, a
; read at least 1 byte
inc bc
jr .readers
.normal
; push control code
push af
; get param
ld a, [hli]
and %00011111
ld c, a
ld b, $0
; read at least 1 byte
inc c
.readers
; let's get started
; inc loop counts since we bail as soon as they hit 0
inc b
inc c
; get control code
pop af
; command type
bit 7, a ; 80, a0, c0
jr nz, .repeatertype
; literals
cp $20 ; LZ_ITER
jr z, .iter
cp $40 ; LZ_ALT
jr z, .alt
cp $60 ; LZ_ZERO
jr z, .zero
; else $00
; 00 ; LZ_LIT
; literal data for bc bytes
.loop1
; done?
dec c
jr nz, .next1
dec b
jp z, .loop
.next1
ld a, [hli]
ld [de], a
inc de
jr .loop1
; 20 ; LZ_ITER
; write byte for bc bytes
.iter
ld a, [hli]
.iterloop
dec c
jr nz, .iternext
dec b
jp z, .loop
.iternext
ld [de], a
inc de
jr .iterloop
; 40 ; LZ_ALT
; alternate two bytes for bc bytes
; next pair
.alt
; done?
dec c
jr nz, .alt0
dec b
jp z, .altclose0
; alternate for bc
.alt0
ld a, [hli]
ld [de], a
inc de
dec c
jr nz, .alt1
; done?
dec b
jp z, .altclose1
.alt1
ld a, [hld]
ld [de], a
inc de
jr .alt
; skip past the bytes we were alternating
.altclose0
inc hl
.altclose1
inc hl
jr .loop
; 60 ; LZ_ZERO
; write 00 for bc bytes
.zero
xor a
.zeroloop
dec c
jr nz, .zeronext
dec b
jp z, .loop
.zeronext
ld [de], a
inc de
jr .zeroloop
; repeats
; 80, a0, c0
; repeat decompressed data from output
.repeatertype
push hl
push af
; get next byte
ld a, [hli]
; absolute?
bit 7, a
jr z, .absolute
; relative
; a = -a
and %01111111 ; forget the bit we just looked at
cpl
; add de (current output address)
add e
ld l, a
ld a, $ff ; -1
adc d
ld h, a
jr .repeaters
.absolute
; get next byte (lo)
ld l, [hl]
; last byte (hi)
ld h, a
; add starting output address
ld a, [$c2c2]
add l
ld l, a
ld a, [$c2c3]
adc h
ld h, a
.repeaters
pop af
cp $80 ; LZ_REPEAT
jr z, .repeat
cp $a0 ; LZ_FLIP
jr z, .flip
cp $c0 ; LZ_REVERSE
jr z, .reverse
; e0 -> 80
; 80 ; LZ_REPEAT
; repeat some decompressed data
.repeat
; done?
dec c
jr nz, .repeatnext
dec b
jr z, .cleanup
.repeatnext
ld a, [hli]
ld [de], a
inc de
jr .repeat
; a0 ; LZ_FLIP
; repeat some decompressed data w/ flipped bit order
.flip
dec c
jr nz, .flipnext
dec b
jp z, .cleanup
.flipnext
ld a, [hli]
push bc
ld bc, $0008
.fliploop
rra
rl b
dec c
jr nz, .fliploop
ld a, b
pop bc
ld [de], a
inc de
jr .flip
; c0 ; LZ_REVERSE
; repeat some decompressed data in reverse
.reverse
dec c
jr nz, .reversenext
dec b
jp z, .cleanup
.reversenext
ld a, [hld]
ld [de], a
inc de
jr .reverse
.cleanup
; get type of repeat we just used
pop hl
; was it relative or absolute?
bit 7, [hl]
jr nz, .next
; skip two bytes for absolute
inc hl
; skip one byte for relative
.next
inc hl
jp .loop
; c2f

23
home/delay.asm Normal file
View File

@@ -0,0 +1,23 @@
DelayFrame: ; 45a
; Wait for one frame
ld a, 1
ld [VBlankOccurred], a
; Wait for the next VBlank, halting to conserve battery
.halt
halt ; rgbasm adds a nop after this instruction by default
ld a, [VBlankOccurred]
and a
jr nz, .halt
ret
; 468
DelayFrames: ; 468
; Wait c frames
call DelayFrame
dec c
jr nz, DelayFrames
ret
; 46f

31
home/double_speed.asm Normal file
View File

@@ -0,0 +1,31 @@
; The CGB hardware introduces Double Speed Mode.
; While active, the clock speed is doubled.
; The hardware can switch between normal speed
; and double speed at any time, but LCD output
; collapses during the switch.
DoubleSpeed: ; 2fef
ld hl, rKEY1
bit 7, [hl]
jr z, SwitchSpeed
ret
; 2ff7
NormalSpeed: ; 2ff7
ld hl, rKEY1
bit 7, [hl]
ret z
; 2ffd
SwitchSpeed: ; 2ffd
set 0, [hl]
xor a
ld [rIF], a
ld [rIE], a
ld a, $30
ld [rJOYP], a
stop ; rgbasm adds a nop after this instruction by default
ret
; 300b

134
home/fade.asm Normal file
View File

@@ -0,0 +1,134 @@
; Functions to fade the screen in and out.
Function48c: ; 48c
ld a, [TimeOfDayPal]
ld b, a
ld hl, IncGradGBPalTable_11
ld a, l
sub b
ld l, a
jr nc, .asm_499
dec h
.asm_499
ld a, [hli]
ld [rBGP], a
ld a, [hli]
ld [rOBP0], a
ld a, [hli]
ld [rOBP1], a
ret
; 4a3
Function4a3: ; 4a3
ld a, [hCGB]
and a
jr z, .asm_4af
ld hl, IncGradGBPalTable_00
ld b, 4
jr FadeOut
.asm_4af
ld hl, IncGradGBPalTable_08
ld b, 4
jr FadeOut
; 4b6
Function4b6: ; 4b6
ld a, [hCGB]
and a
jr z, .asm_4c2
ld hl, IncGradGBPalTable_05
ld b, 3
jr FadeOut
.asm_4c2
ld hl, IncGradGBPalTable_13
ld b, 3
; 4c7
FadeOut: ; 4c7
push de
ld a, [hli]
call DmgToCgbBGPals
ld a, [hli]
ld e, a
ld a, [hli]
ld d, a
call DmgToCgbObjPals
ld c, 8
call DelayFrames
pop de
dec b
jr nz, FadeOut
ret
; 4dd
Function4dd: ; 4dd
ld a, [hCGB]
and a
jr z, .asm_4e9
ld hl, IncGradGBPalTable_04 - 1
ld b, 4
jr FadeIn
.asm_4e9
ld hl, IncGradGBPalTable_12 - 1
ld b, 4
jr FadeIn
; 4f0
Function4f0: ; 4f0
ld a, [hCGB]
and a
jr z, .asm_4fc
ld hl, IncGradGBPalTable_07 - 1
ld b, 3
jr FadeIn
.asm_4fc
ld hl, IncGradGBPalTable_15 - 1
ld b, 3
; fallthrough
; 501
FadeIn: ; 501
push de
ld a, [hld]
ld d, a
ld a, [hld]
ld e, a
call DmgToCgbObjPals
ld a, [hld]
call DmgToCgbBGPals
ld c, 8
call DelayFrames
pop de
dec b
jr nz, FadeIn
ret
; 517
; 517
IncGradGBPalTable_00: db %11111111, %11111111, %11111111
IncGradGBPalTable_01: db %11111110, %11111110, %11111110
IncGradGBPalTable_02: db %11111001, %11111001, %11111001
IncGradGBPalTable_03: db %11100100, %11100100, %11100100
IncGradGBPalTable_04: db %11100100, %11100100, %11100100
IncGradGBPalTable_05: db %10010000, %10010000, %10010000
IncGradGBPalTable_06: db %01000000, %01000000, %01000000
IncGradGBPalTable_07: db %00000000, %00000000, %00000000
; bgp obp1 obp2
IncGradGBPalTable_08: db %11111111, %11111111, %11111111
IncGradGBPalTable_09: db %11111110, %11111110, %11111000
IncGradGBPalTable_10: db %11111001, %11100100, %11100100
IncGradGBPalTable_11: db %11100100, %11010000, %11100000
IncGradGBPalTable_12: db %11100100, %11010000, %11100000
IncGradGBPalTable_13: db %10010000, %10000000, %10010000
IncGradGBPalTable_14: db %01000000, %01000000, %01000000
IncGradGBPalTable_15: db %00000000, %00000000, %00000000
; 547

55
home/farcall.asm Normal file
View File

@@ -0,0 +1,55 @@
FarCall_de: ; 2d54
; Call a:de.
; Preserves other registers.
ld [hBuffer], a
ld a, [hROMBank]
push af
ld a, [hBuffer]
rst Bankswitch
call .de
jr ReturnFarCall
.de
push de
ret
; 2d63
FarCall_hl: ; 2d63
; Call a:hl.
; Preserves other registers.
ld [hBuffer], a
ld a, [hROMBank]
push af
ld a, [hBuffer]
rst Bankswitch
call Function2d82
; 2d6e
ReturnFarCall: ; 2d6e
; We want to retain the contents of f.
; To do this, we can pop to bc instead of af.
ld a, b
ld [$cfb9], a
ld a, c
ld [$cfba], a
; Restore the working bank.
pop bc
ld a, b
rst Bankswitch
ld a, [$cfb9]
ld b, a
ld a, [$cfba]
ld c, a
ret
; 2d82
Function2d82: ; 2d82
jp [hl]
; 2d83

113
home/flag.asm Normal file
View File

@@ -0,0 +1,113 @@
Function2e50: ; 2e50
xor a
ld hl, EventFlags
ld [hli], a
ret
; 2e56
Function2e56: ; 2e56
xor a
ld hl, BikeFlags
ld [hli], a
ld [hl], a
ret
; 2e5d
Function2e5d: ; 2e5d
ld a, [$d19a]
cp $2
jr z, .asm_2e69
cp $1
jr z, .asm_2e69
ret
.asm_2e69
ld hl, StatusFlags
res 2, [hl]
ret
; 2e6f
EventFlagAction: ; 0x2e6f
ld hl, EventFlags
call FlagAction
ret
FlagAction: ; 0x2e76
; Perform action b on bit de in flag array hl.
; inputs:
; b: function
; 0 clear bit
; 1 set bit
; 2 check bit
; de: bit number
; hl: index within bit table
; get index within the byte
ld a, e
and 7
; shift de right by three bits (get the index within memory)
srl d
rr e
srl d
rr e
srl d
rr e
add hl, de
; implement a decoder
ld c, 1
rrca
jr nc, .one
rlc c
.one
rrca
jr nc, .two
rlc c
rlc c
.two
rrca
jr nc, .three
swap c
.three
; check b's value: 0, 1, 2
ld a, b
cp 1
jr c, .clearbit ; 0
jr z, .setbit ; 1
; check bit
ld a, [hl]
and c
ld c, a
ret
.setbit
; set bit
ld a, [hl]
or c
ld [hl], a
ret
.clearbit
; clear bit
ld a, c
cpl
and [hl]
ld [hl], a
ret
; 0x2ead
Function2ead: ; 2ead
ld de, ENGINE_POKEDEX
ld b, CHECK_FLAG
callba EngineFlagAction
ld a, c
and a
ret
; 2ebb

132
home/game_time.asm Normal file
View File

@@ -0,0 +1,132 @@
ResetGameTime: ; 208a
xor a
ld [GameTimeCap], a
ld [GameTimeHours], a
ld [GameTimeHours + 1], a
ld [GameTimeMinutes], a
ld [GameTimeSeconds], a
ld [GameTimeFrames], a
ret
; 209e
GameTimer: ; 209e
nop
ld a, [rSVBK]
push af
ld a, 1
ld [rSVBK], a
call UpdateGameTimer
pop af
ld [rSVBK], a
ret
; 20ad
UpdateGameTimer: ; 20ad
; Increment the game timer by one frame.
; The game timer is capped at 999:59:59.00.
; Don't update if game logic is paused.
ld a, [$c2cd]
and a
ret nz
; Is the timer paused?
ld hl, GameTimerPause
bit 0, [hl]
ret z
; Is the timer already capped?
ld hl, GameTimeCap
bit 0, [hl]
ret nz
; +1 frame
ld hl, GameTimeFrames
ld a, [hl]
inc a
cp 60 ; frames/second
jr nc, .second
ld [hl], a
ret
.second
xor a
ld [hl], a
; +1 second
ld hl, GameTimeSeconds
ld a, [hl]
inc a
cp 60 ; seconds/minute
jr nc, .minute
ld [hl], a
ret
.minute
xor a
ld [hl], a
; +1 minute
ld hl, GameTimeMinutes
ld a, [hl]
inc a
cp 60 ; minutes/hour
jr nc, .hour
ld [hl], a
ret
.hour
xor a
ld [hl], a
; +1 hour
ld a, [GameTimeHours]
ld h, a
ld a, [GameTimeHours + 1]
ld l, a
inc hl
; Cap the timer after 1000 hours.
ld a, h
cp 1000 / $100
jr c, .ok
ld a, l
cp 1000 % $100
jr c, .ok
ld hl, GameTimeCap
set 0, [hl]
ld a, 59 ; 999:59:59.00
ld [GameTimeMinutes], a
ld [GameTimeSeconds], a
ret
.ok
ld a, h
ld [GameTimeHours], a
ld a, l
ld [GameTimeHours + 1], a
ret
; 210f

38
home/handshake.asm Normal file
View File

@@ -0,0 +1,38 @@
AskSerial: ; 2063
; send out a handshake while serial int is off
ld a, [$c2d4]
bit 0, a
ret z
ld a, [$c2d5]
and a
ret nz
; once every 6 frames
ld hl, $ca8a
inc [hl]
ld a, [hl]
cp 6
ret c
xor a
ld [hl], a
ld a, $c
ld [$c2d5], a
; handshake
ld a, $88
ld [rSB], a
; switch to internal clock
ld a, %00000001
ld [rSC], a
; start transfer
ld a, %10000001
ld [rSC], a
ret
; 208a

225
home/init.asm Normal file
View File

@@ -0,0 +1,225 @@
Reset: ; 150
di
call CleanSoundRestart
xor a
ld [$ffde], a
call ClearPalettes
xor a
ld [rIF], a
ld a, 1 ; VBlank int
ld [rIE], a
ei
ld hl, $cfbe
set 7, [hl]
ld c, 32
call DelayFrames
jr Init
; 16e
_Start: ; 16e
cp $11
jr z, .asm_175
xor a
jr .asm_177
.asm_175
ld a, $1
.asm_177
ld [hCGB], a
ld a, $1
ld [$ffea], a
; 17d
Init: ; 17d
di
xor a
ld [rIF], a
ld [rIE], a
ld [rRP], a
ld [rSCX], a
ld [rSCY], a
ld [rSB], a
ld [rSC], a
ld [rWX], a
ld [rWY], a
ld [rBGP], a
ld [rOBP0], a
ld [rOBP1], a
ld [rTMA], a
ld [rTAC], a
ld [$d000], a
ld a, %100 ; Start timer at 4096Hz
ld [rTAC], a
.wait
ld a, [rLY]
cp 145
jr nz, .wait
xor a
ld [rLCDC], a
; Clear WRAM bank 0
ld hl, $c000
ld bc, $d000 - $c000
.asm_1b1
ld [hl], 0
inc hl
dec bc
ld a, b
or c
jr nz, .asm_1b1
ld sp, Stack
; Clear HRAM
ld a, [hCGB]
push af
ld a, [$ffea]
push af
xor a
ld hl, $ff80
ld bc, $ffff - $ff80
call ByteFill
pop af
ld [$ffea], a
pop af
ld [hCGB], a
call ClearWRAM
ld a, 1
ld [rSVBK], a
call ClearVRAM
call ClearSprites
call Function270
ld a, BANK(LoadPushOAM)
rst Bankswitch
call LoadPushOAM
xor a
ld [$ffde], a
ld [hSCX], a
ld [hSCY], a
ld [rJOYP], a
ld a, $8 ; HBlank int enable
ld [rSTAT], a
ld a, $90
ld [hWY], a
ld [rWY], a
ld a, 7
ld [hWX], a
ld [rWX], a
ld a, %11100011
; LCD on
; Win tilemap 1
; Win on
; BG/Win tiledata 0
; BG Tilemap 0
; OBJ 8x8
; OBJ on
; BG on
ld [rLCDC], a
ld a, $ff
ld [$ffcb], a
callba Function9890
ld a, $9c
ld [$ffd7], a
xor a
ld [hBGMapAddress], a
callba StartClock
xor a
ld [MBC3LatchClock], a
ld [MBC3SRamEnable], a
ld a, [hCGB]
and a
jr z, .asm_22b
call NormalSpeed
.asm_22b
xor a
ld [rIF], a
ld a, %1111 ; VBlank, LCDStat, Timer, Serial interrupts
ld [rIE], a
ei
call DelayFrame
ld a, $30
call Predef
call CleanSoundRestart
xor a
ld [CurMusic], a
jp GameInit
; 245
ClearVRAM: ; 245
; Wipe VRAM banks 0 and 1
ld a, 1
ld [rVBK], a
call .clear
xor a
ld [rVBK], a
.clear
ld hl, VTiles0
ld bc, $2000
xor a
call ByteFill
ret
; 25a
ClearWRAM: ; 25a
; Wipe swappable WRAM banks (1-7)
ld a, 1
.asm_25c
push af
ld [rSVBK], a
xor a
ld hl, $d000
ld bc, $1000
call ByteFill
pop af
inc a
cp 8
jr nc, .asm_25c
ret
; 270
Function270: ; 270
ld a, $0
call GetSRAMBank
ld hl, $a000
ld bc, $0020
xor a
call ByteFill
call CloseSRAM
ret
; 283

76
home/item.asm Normal file
View File

@@ -0,0 +1,76 @@
DoItemEffect: ; 2f3f
callba _DoItemEffect
ret
; 2f46
CheckTossableItem: ; 2f46
push hl
push de
push bc
callba _CheckTossableItem
pop bc
pop de
pop hl
ret
; 2f53
TossItem: ; 2f53
push hl
push de
push bc
ld a, [hROMBank]
push af
ld a, BANK(_TossItem)
rst Bankswitch
call _TossItem
pop bc
ld a, b
rst Bankswitch
pop bc
pop de
pop hl
ret
; 2f66
ReceiveItem: ; 2f66
push bc
ld a, [hROMBank]
push af
ld a, BANK(_ReceiveItem)
rst Bankswitch
push hl
push de
call _ReceiveItem
pop de
pop hl
pop bc
ld a, b
rst Bankswitch
pop bc
ret
; 2f79
CheckItem: ; 2f79
push hl
push de
push bc
ld a, [hROMBank]
push af
ld a, BANK(_CheckItem)
rst Bankswitch
call _CheckItem
pop bc
ld a, b
rst Bankswitch
pop bc
pop de
pop hl
ret
; 2f8c

491
home/joypad.asm Normal file
View File

@@ -0,0 +1,491 @@
JoypadInt: ; 92e
; Replaced by Joypad, called from VBlank instead of the useless
; joypad interrupt.
; This is a placeholder in case the interrupt is somehow enabled.
reti
; 92f
ClearJoypadPublic: ; 92f
xor a
; Pressed this frame (delta)
ld [hJoyPressed], a
; Currently pressed
ld [hJoyDown], a
ret
; 935
Joypad: ; 935
; Read the joypad register and translate it to something more
; workable for use in-game. There are 8 buttons, so we can use
; one byte to contain all player input.
; Updates:
; hJoypadReleased: released this frame (delta)
; hJoypadPressed: pressed this frame (delta)
; hJoypadDown: currently pressed
; hJoypadSum: pressed so far
; Any of these three bits can be used to disable input.
ld a, [$cfbe]
and %11010000
ret nz
; If we're saving, input is disabled.
ld a, [$c2cd]
and a
ret nz
; We can only get four inputs at a time.
; We take d-pad first for no particular reason.
ld a, D_PAD
ld [rJOYP], a
; Read twice to give the request time to take.
ld a, [rJOYP]
ld a, [rJOYP]
; The Joypad register output is in the lo nybble (inversed).
; We make the hi nybble of our new container d-pad input.
cpl
and $f
swap a
; We'll keep this in b for now.
ld b, a
; Buttons make 8 total inputs (A, B, Select, Start).
; We can fit this into one byte.
ld a, BUTTONS
ld [rJOYP], a
; Wait for input to stabilize.
ld a, [rJOYP]
ld a, [rJOYP]
ld a, [rJOYP]
ld a, [rJOYP]
ld a, [rJOYP]
ld a, [rJOYP]
; Buttons take the lo nybble.
cpl
and $f
or b
ld b, a
; Reset the joypad register since we're done with it.
ld a, $30
ld [rJOYP], a
; To get the delta we xor the last frame's input with the new one.
ld a, [hJoypadDown] ; last frame
ld e, a
xor b
ld d, a
; Released this frame:
and e
ld [hJoypadReleased], a
; Pressed this frame:
ld a, d
and b
ld [hJoypadPressed], a
; Add any new presses to the list of collective presses:
ld c, a
ld a, [hJoypadSum]
or c
ld [hJoypadSum], a
; Currently pressed:
ld a, b
ld [hJoypadDown], a
; Now that we have the input, we can do stuff with it.
; For example, soft reset:
and A_BUTTON | B_BUTTON | SELECT | START
cp A_BUTTON | B_BUTTON | SELECT | START
jp z, Reset
ret
; 984
GetJoypadPublic: ; 984
; Update mirror joypad input from hJoypadDown (real input)
; hJoyReleased: released this frame (delta)
; hJoyPressed: pressed this frame (delta)
; hJoyDown: currently pressed
; bit 0 A
; 1 B
; 2 SELECT
; 3 START
; 4 RIGHT
; 5 LEFT
; 6 UP
; 7 DOWN
push af
push hl
push de
push bc
; The player input can be automated using an input stream.
; See more below.
ld a, [InputType]
cp a, AUTO_INPUT
jr z, .auto
; To get deltas, take this and last frame's input.
ld a, [hJoypadDown] ; real input
ld b, a
ld a, [hJoyDown] ; last frame mirror
ld e, a
; Released this frame:
xor b
ld d, a
and e
ld [hJoyReleased], a
; Pressed this frame:
ld a, d
and b
ld [hJoyPressed], a
; It looks like the collective presses got commented out here.
ld c, a
; Currently pressed:
ld a, b
ld [hJoyDown], a ; frame input
.quit
pop bc
pop de
pop hl
pop af
ret
.auto
; Use a predetermined input stream (used in the catching tutorial).
; Stream format: [input][duration]
; A value of $ff will immediately end the stream.
; Read from the input stream.
ld a, [hROMBank]
push af
ld a, [AutoInputBank]
rst Bankswitch
ld hl, AutoInputAddress
ld a, [hli]
ld h, [hl]
ld l, a
; We only update when the input duration has expired.
ld a, [AutoInputLength]
and a
jr z, .updateauto
; Until then, don't change anything.
dec a
ld [AutoInputLength], a
pop af
rst Bankswitch
jr .quit
.updateauto
; An input of $ff will end the stream.
ld a, [hli]
cp a, $ff
jr z, .stopauto
ld b, a
; A duration of $ff will end the stream indefinitely.
ld a, [hli]
ld [AutoInputLength], a
cp a, $ff
jr nz, .next
; The current input is overwritten.
dec hl
dec hl
ld b, NO_INPUT
jr .finishauto
.next
; On to the next input...
ld a, l
ld [AutoInputAddress], a
ld a, h
ld [AutoInputAddress+1], a
jr .finishauto
.stopauto
call StopAutoInput
ld b, NO_INPUT
.finishauto
pop af
rst Bankswitch
ld a, b
ld [hJoyPressed], a ; pressed
ld [hJoyDown], a ; input
jr .quit
; 9ee
StartAutoInput: ; 9ee
; Start reading automated input stream at a:hl.
ld [AutoInputBank], a
ld a, l
ld [AutoInputAddress], a
ld a, h
ld [AutoInputAddress+1], a
; Start reading the stream immediately.
xor a
ld [AutoInputLength], a
; Reset input mirrors.
xor a
ld [hJoyPressed], a ; pressed this frame
ld [hJoyReleased], a ; released this frame
ld [hJoyDown], a ; currently pressed
ld a, AUTO_INPUT
ld [InputType], a
ret
; a0a
StopAutoInput: ; a0a
; Clear variables related to automated input.
xor a
ld [AutoInputBank], a
ld [AutoInputAddress], a
ld [AutoInputAddress+1], a
ld [AutoInputLength], a
; Back to normal input.
ld [InputType], a
ret
; a1b
Functiona1b: ; a1b
call DelayFrame
push bc
call Functiona57
pop bc
ld a, [hJoyDown]
cp D_UP | SELECT | B_BUTTON
jr z, .asm_a34
ld a, [$ffa9]
and START | A_BUTTON
jr nz, .asm_a34
dec c
jr nz, Functiona1b
and a
ret
.asm_a34
scf
ret
; a36
Functiona36: ; a36
call DelayFrame
call GetJoypadPublic
ld a, [hJoyPressed]
and A_BUTTON | B_BUTTON
ret nz
call RTC
jr Functiona36
; a46
Functiona46: ; a46
ld a, [hOAMUpdate]
push af
ld a, 1
ld [hOAMUpdate], a
call WaitBGMap
call Functiona36
pop af
ld [hOAMUpdate], a
ret
; a57
Functiona57: ; a57
call GetJoypadPublic
ld a, [$ffaa]
and a
ld a, [hJoyPressed]
jr z, .asm_a63
ld a, [hJoyDown]
.asm_a63
ld [$ffa9], a
ld a, [hJoyPressed]
and a
jr z, .asm_a70
ld a, 15
ld [TextDelayFrames], a
ret
.asm_a70
ld a, [TextDelayFrames]
and a
jr z, .asm_a7a
xor a
ld [$ffa9], a
ret
.asm_a7a
ld a, 5
ld [TextDelayFrames], a
ret
; a80
Functiona80: ; a80
ld a, [$ffaf]
push af
ld a, [$ffb0]
push af
xor a
ld [$ffaf], a
ld a, $6
ld [$ffb0], a
.asm_a8d
push hl
ld hl, $c606
call Functionb06
pop hl
call Functiona57
ld a, [$ffa9]
and $3
jr z, .asm_a8d
pop af
ld [$ffb0], a
pop af
ld [$ffaf], a
ret
; aa5
Functionaa5: ; aa5
call Functiona57
ld a, [$ffa9]
and A_BUTTON | B_BUTTON
jr z, Functionaa5
ret
; aaf
Functionaaf: ; aaf
ld a, [InLinkBattle]
and a
jr nz, .asm_ac1
call Functionac6
push de
ld de, SFX_READ_TEXT_2
call StartSFX
pop de
ret
.asm_ac1
ld c, 65
jp DelayFrames
; ac6
Functionac6: ; ac6
ld a, [hOAMUpdate]
push af
ld a, $1
ld [hOAMUpdate], a
ld a, [InputType]
or a
jr z, .asm_ad9
callba Function1de28a
.asm_ad9
call Functionaf5
call Functiona57
ld a, [hJoyPressed]
and $3
jr nz, .asm_af1
call RTC
ld a, $1
ld [hBGMapMode], a
call DelayFrame
jr .asm_ad9
.asm_af1
pop af
ld [hOAMUpdate], a
ret
; af5
Functionaf5: ; af5
ld a, [$ff9b]
and $10
jr z, .asm_aff
ld a, $ee
jr .asm_b02
.asm_aff
ld a, [$c605]
.asm_b02
ld [$c606], a
ret
; b06
Functionb06: ; b06
push bc
ld a, [hl]
ld b, a
ld a, $ee
cp b
pop bc
jr nz, .asm_b27
ld a, [$ffaf]
dec a
ld [$ffaf], a
ret nz
ld a, [$ffb0]
dec a
ld [$ffb0], a
ret nz
ld a, $7a
ld [hl], a
ld a, $ff
ld [$ffaf], a
ld a, $6
ld [$ffb0], a
ret
.asm_b27
ld a, [$ffaf]
and a
ret z
dec a
ld [$ffaf], a
ret nz
dec a
ld [$ffaf], a
ld a, [$ffb0]
dec a
ld [$ffb0], a
ret nz
ld a, $6
ld [$ffb0], a
ld a, $ee
ld [hl], a
ret
; b40

81
home/lcd.asm Normal file
View File

@@ -0,0 +1,81 @@
; LCD handling
Function547: ; 547
ld a, [hLCDStatCustom]
cp rSCX & $ff
ret nz
ld c, a
ld a, [LYOverrides]
ld [$ff00+c], a
ret
; 552
LCD: ; 552
push af
ld a, [hLCDStatCustom]
and a
jr z, .done
; At this point it's assumed we're in WRAM bank 5!
push bc
ld a, [rLY]
ld c, a
ld b, LYOverrides >> 8
ld a, [bc]
ld b, a
ld a, [hLCDStatCustom]
ld c, a
ld a, b
ld [$ff00+c], a
pop bc
.done
pop af
reti
; 568
DisableLCD: ; 568
; Turn the LCD off
; Don't need to do anything if the LCD is already off
ld a, [rLCDC]
bit 7, a ; lcd enable
ret z
xor a
ld [rIF], a
ld a, [rIE]
ld b, a
; Disable VBlank
res 0, a ; vblank
ld [rIE], a
.wait
; Wait until VBlank would normally happen
ld a, [rLY]
cp 145
jr nz, .wait
ld a, [rLCDC]
and %01111111 ; lcd enable off
ld [rLCDC], a
xor a
ld [rIF], a
ld a, b
ld [rIE], a
ret
; 58a
EnableLCD: ; 58a
ld a, [rLCDC]
set 7, a ; lcd enable
ld [rLCDC], a
ret
; 591

2369
home/map.asm Normal file

File diff suppressed because it is too large Load Diff

683
home/map_objects.asm Normal file

File diff suppressed because it is too large Load Diff

76
home/math.asm Normal file
View File

@@ -0,0 +1,76 @@
SimpleMultiply: ; 3105
; Return a * c.
and a
ret z
push bc
ld b, a
xor a
.loop
add c
dec b
jr nz, .loop
pop bc
ret
; 3110
SimpleDivide: ; 3110
; Divide a by c. Return quotient b and remainder a.
ld b, 0
.loop
inc b
sub c
jr nc, .loop
dec b
add c
ret
; 3119
Multiply: ; 3119
; Multiply hMultiplicand (3 bytes) by hMultiplier. Result in hProduct.
; All values are big endian.
push hl
push bc
callab _Multiply
pop bc
pop hl
ret
; 3124
Divide: ; 3124
; Divide hDividend length b (max 4 bytes) by hDivisor. Result in hQuotient.
; All values are big endian.
push hl
push de
push bc
ld a, [hROMBank]
push af
ld a, BANK(_Divide)
rst Bankswitch
call _Divide
pop af
rst Bankswitch
pop bc
pop de
pop hl
ret
; 3136
SubtractSigned: ; 3136
; Return a - b, sign in carry.
sub b
ret nc
cpl
add 1
scf
ret
; 313d

603
home/menu.asm Normal file

File diff suppressed because it is too large Load Diff

347
home/palettes.asm Normal file
View File

@@ -0,0 +1,347 @@
; Functions dealing with palettes.
UpdatePalsIfCGB: ; c2f
; update bgp data from BGPals
; update obp data from OBPals
; return carry if successful
; check cgb
ld a, [hCGB]
and a
ret z
UpdateCGBPals: ; c33
; return carry if successful
; any pals to update?
ld a, [hCGBPalUpdate]
and a
ret z
ForceUpdateCGBPals: ; c37
ld a, [rSVBK]
push af
ld a, 5 ; BANK(BGPals)
ld [rSVBK], a
ld hl, BGPals ; 5:d080
; copy 8 pals to bgpd
ld a, %10000000 ; auto increment, index 0
ld [rBGPI], a
ld c, rBGPD % $100
ld b, 4 ; NUM_PALS / 2
.bgp
rept $10
ld a, [hli]
ld [$ff00+c], a
endr
dec b
jr nz, .bgp
; hl is now 5:d0c0 OBPals
; copy 8 pals to obpd
ld a, %10000000 ; auto increment, index 0
ld [rOBPI], a
ld c, rOBPD - rJOYP
ld b, 4 ; NUM_PALS / 2
.obp
rept $10
ld a, [hli]
ld [$ff00+c], a
endr
dec b
jr nz, .obp
pop af
ld [rSVBK], a
; clear pal update queue
xor a
ld [hCGBPalUpdate], a
scf
ret
; c9f
DmgToCgbBGPals: ; c9f
; exists to forego reinserting cgb-converted image data
; input: a -> bgp
ld [rBGP], a
push af
ld a, [hCGB]
and a
jr z, .end
push hl
push de
push bc
ld a, [rSVBK]
push af
ld a, 5
ld [rSVBK], a
; copy & reorder bg pal buffer
ld hl, BGPals ; to
ld de, Unkn1Pals ; from
; order
ld a, [rBGP]
ld b, a
; all pals
ld c, 8
call CopyPals
; request pal update
ld a, 1
ld [hCGBPalUpdate], a
pop af
ld [rSVBK], a
pop bc
pop de
pop hl
.end
pop af
ret
; ccb
DmgToCgbObjPals: ; ccb
; exists to forego reinserting cgb-converted image data
; input: d -> obp1
; e -> obp2
ld a, e
ld [rOBP0], a
ld a, d
ld [rOBP1], a
ld a, [hCGB]
and a
ret z
push hl
push de
push bc
ld a, [rSVBK]
push af
ld a, 5
ld [rSVBK], a
; copy & reorder obj pal buffer
ld hl, OBPals ; to
ld de, Unkn2Pals ; from
; order
ld a, [rOBP0]
ld b, a
; all pals
ld c, 8
call CopyPals
; request pal update
ld a, 1
ld [hCGBPalUpdate], a
pop af
ld [rSVBK], a
pop bc
pop de
pop hl
ret
; cf8
Functioncf8: ; cf8
ld [rOBP0], a
push af
ld a, [hCGB]
and a
jr z, .asm_d22
push hl
push de
push bc
ld a, [rSVBK]
push af
ld a, $5
ld [rSVBK], a
ld hl, $d0c0
ld de, MartPointer
ld a, [rOBP0]
ld b, a
ld c, $1
call CopyPals
ld a, $1
ld [hCGBPalUpdate], a
pop af
ld [rSVBK], a
pop bc
pop de
pop hl
.asm_d22
pop af
ret
; d24
Functiond24: ; d24
ld [rOBP1], a
push af
ld a, [hCGB]
and a
jr z, .asm_d4e
push hl
push de
push bc
ld a, [rSVBK]
push af
ld a, $5
ld [rSVBK], a
ld hl, $d0c8
ld de, $d048
ld a, [rOBP1]
ld b, a
ld c, $1
call CopyPals
ld a, $1
ld [hCGBPalUpdate], a
pop af
ld [rSVBK], a
pop bc
pop de
pop hl
.asm_d4e
pop af
ret
; d50
CopyPals: ; d50
; copy c palettes in order b from de to hl
push bc
ld c, 4 ; NUM_PAL_COLORS
.loop
push de
push hl
; get pal color
ld a, b
and %11 ; color
; 2 bytes per color
add a
ld l, a
ld h, 0
add hl, de
ld e, [hl]
inc hl
ld d, [hl]
; dest
pop hl
; write color
ld [hl], e
inc hl
ld [hl], d
inc hl
; next pal color
srl b
srl b
; source
pop de
; done pal?
dec c
jr nz, .loop
; de += 8 (next pal)
ld a, 8 ; NUM_PAL_COLORS * 2 ; bytes per pal
add e
jr nc, .ok
inc d
.ok
ld e, a
; how many more pals?
pop bc
dec c
jr nz, CopyPals
ret
; d79
Functiond79: ; d79
ld a, [hCGB]
and a
ret z
ld a, 1
ld [rVBK], a
ld hl, VTiles0
ld bc, $2000
xor a
call ByteFill
ld a, 0
ld [rVBK], a
ret
; d90
Functiond90: ; d90
ret
; d91
Functiond91: ; d91
ld a, [hCGB]
and a
ret z
ld a, [rSVBK]
push af
ld a, 5 ; BANK(BGPals)
ld [rSVBK], a
ld hl, BGPals
ld bc, $40 + $10
xor a
call ByteFill
pop af
ld [rSVBK], a
ld a, 1
ld [hCGBPalUpdate], a
call DelayFrame
ret
; db1
Functiondb1: ; db1
ld a, [hROMBank]
push af
ld a, BANK(Function4c000)
rst Bankswitch
call Function4c000
pop af
rst Bankswitch
ret
; dbd
Functiondbd: ; dbd
ld a, [hROMBank]
push af
ld a, BANK(Function4c03f)
rst Bankswitch
call Function4c03f
pop af
rst Bankswitch
ret
; dc9

54
home/predef.asm Normal file
View File

@@ -0,0 +1,54 @@
Predef: ; 2d83
; Call predefined function a.
; Preserves bc, de, hl and f.
ld [PredefID], a
ld a, [hROMBank]
push af
ld a, BANK(GetPredefPointer)
rst Bankswitch
call GetPredefPointer ; stores hl in PredefTemp
; Switch to the new function's bank
rst Bankswitch
; Instead of directly calling stuff,
; push it to the stack in reverse.
ld hl, .Return
push hl
; Call the Predef function
ld a, [PredefAddress]
ld h, a
ld a, [PredefAddress + 1]
ld l, a
push hl
; Get hl back
ld a, [PredefTemp]
ld h, a
ld a, [PredefTemp + 1]
ld l, a
ret
.Return
; Clean up after the Predef call
ld a, h
ld [PredefTemp], a
ld a, l
ld [PredefTemp+1], a
pop hl
ld a, h
rst Bankswitch
ld a, [PredefTemp]
ld h, a
ld a, [PredefTemp + 1]
ld l, a
ret
; 2dba

Some files were not shown because too many files have changed in this diff Show More