summaryrefslogtreecommitdiff
path: root/home.asm
diff options
context:
space:
mode:
Diffstat (limited to 'home.asm')
-rw-r--r--home.asm599
1 files changed, 63 insertions, 536 deletions
diff --git a/home.asm b/home.asm
index 29ca3d8..1f1e6fa 100644
--- a/home.asm
+++ b/home.asm
@@ -124,8 +124,8 @@ Start: ; 0x150
ld a, $a6
ld [hli], a
ld a, $0
- ld [wd849], a
- ld [wd84a], a
+ ld [wUpdateAudioEngineUsingTimerInterrupt], a
+ ld [wToggleAudioEngineUpdateMethod], a
ld a, Bank(PlaySong_BankF)
call SetSongBank
call Func_23b
@@ -222,8 +222,8 @@ SoftReset:
ld a, $a6
ld [hli], a
ld a, $0
- ld [wd849], a
- ld [wd84a], a
+ ld [wUpdateAudioEngineUsingTimerInterrupt], a
+ ld [wToggleAudioEngineUpdateMethod], a
ld a, BANK(Func_3c000)
call SetSongBank
ld a, [hSGBFlag]
@@ -329,29 +329,30 @@ VBlank: ; 0x2f2
ld a, [wd8e1]
and a
call nz, Func_167b
- ld a, [wd849]
+ ld a, [wUpdateAudioEngineUsingTimerInterrupt]
and a
- jr nz, .asm_37d
- ld a, [wd85d]
+ jr nz, .skipAudioEngineUpdate
+ ld a, [wAudioEngineEnabled]
and a
call nz, UpdateSFX
-.asm_37d
- ld a, [wd84a]
+.skipAudioEngineUpdate
+ ld a, [wToggleAudioEngineUpdateMethod]
and a
- jr z, .asm_39d
+ jr z, .skipTimerToggle
+ ; Enable timer interrupts for audio engine updating.
xor a
- ld [wd84a], a
+ ld [wToggleAudioEngineUpdateMethod], a
ld a, $1
- ld [wd849], a
- ld a, $bc
+ ld [wUpdateAudioEngineUsingTimerInterrupt], a
+ ld a, -68
ld [rTMA], a
ld a, $0
ld [rTAC], a
ld hl, rIE
set 2, [hl]
ld a, $4
- ld [rTAC], a
-.asm_39d
+ ld [rTAC], a ; Timer interrupt will fire ~60 times per second
+.skipTimerToggle
ld hl, MBC5SRamBank
ld a, [wd917]
and a
@@ -439,24 +440,25 @@ Timer: ; 0x418
push bc
push de
push hl
- ld a, [wd849]
+ ld a, [wUpdateAudioEngineUsingTimerInterrupt]
and a
jr z, .asm_42a
- ld a, [wd85d]
+ ld a, [wAudioEngineEnabled]
and a
call nz, UpdateSFX
.asm_42a
- ld a, [wd84a]
+ ld a, [wToggleAudioEngineUpdateMethod]
and a
- jr z, .asm_440
+ jr z, .skipTimer
xor a
- ld [wd84a], a
- ld [wd849], a
+ ld [wToggleAudioEngineUpdateMethod], a
+ ld [wUpdateAudioEngineUsingTimerInterrupt], a
+ ; disable timer
ld a, $0
ld [rTAC], a
ld hl, rIE
res 2, [hl]
-.asm_440
+.skipTimer
pop hl
pop de
pop bc
@@ -718,32 +720,6 @@ WaitForLCD: ; 0x60f
jr nz, .delay40Cycles
ret
-Func_61b: ; 0x61b
- ld a, [rLY] ; LY register (LCDC Y-Coordinate)
- cp $40
- jr c, .asm_625
- cp $80
- jr c, .asm_63d
-.asm_625
- ld a, [rLY] ; LY register (LCDC Y-Coordinate)
- cp $40
- jr c, .asm_625
- cp $80
- jr nc, .asm_625
-.asm_62f
- ld a, [rSTAT]
- and $3
- jr nz, .asm_62f ; wait for lcd controller to finish transferring data
- ld a, $15
-.wait
- dec a
- jr nz, .wait
- nop
- nop
- nop
-.asm_63d
- ret
-
INCLUDE "home/copy.asm"
ClearOAMBuffer: ; 0x916
@@ -807,472 +783,7 @@ SGBWait1750: ; 0x948
INCLUDE "home/random.asm"
INCLUDE "home/joypad.asm"
-
-Func_b66: ; 0xb66
- ld a, [hGameBoyColorFlag]
- and a
- jr nz, .asm_b73
- xor a
- ld [hBGP], a
- ld [hOBP0], a
- ld [hOBP1], a
- ret
-
-.asm_b73
- ld de, rBGPI
- ld hl, wPaletteData
- ld b, $0
- ld c, $20
-.asm_b7d
- ld a, b
- ld [rBGPI], a
- inc b
- ld a, [rBGPD]
- ld [hli], a
- ld a, b
- ld [rBGPI], a
- inc b
- ld a, [rBGPD]
- ld [hli], a
- dec c
- jr nz, .asm_b7d
- ld b, $0
- ld c, $20
-.asm_b92
- ld a, b
- ld [rOBPI], a
- inc b
- ld a, [rOBPD]
- ld [hli], a
- ld a, b
- ld [rOBPI], a
- inc b
- ld a, [rOBPD]
- ld [hli], a
- dec c
- jr nz, .asm_b92
- ld de, rBGPI
- ld b, $2
-.asm_ba8
- ld a, $80
- ld [de], a
- inc de
- ld c, $20
-.asm_bae
- ld a, $ff
- ld [de], a
- ld [hli], a
- ld a, $7f
- ld [de], a
- ld [hli], a
- dec c
- jr nz, .asm_bae
- inc de
- dec b
- jr nz, .asm_ba8
- ret
-
-FadeIn: ; 0xbbe
-; Fades palettes in from white screen.
- ld a, [hGameBoyColorFlag]
- and a
- jp nz, FadeIn_GameboyColor
- ; Regular Gameboy
- ld hl, hBGP
- ld de, wBGP
- ld b, $3
-.loop
- ld a, [de]
- and $55
- ld c, a
- ld a, [de]
- and $aa
- srl a
- and c
- ld [hli], a
- inc de
- dec b
- jr nz, .loop
- ld bc, $0002
- call AdvanceFrames
- ld hl, hBGP
- ld de, wBGP
- ld b, $3
-.loop2
- ld a, [de]
- and $aa
- srl a
- add [hl]
- ld [hli], a
- inc de
- dec b
- jr nz, .loop2
- ld bc, $0002
- call AdvanceFrames
- ld hl, hBGP
- ld de, wBGP
- ld b, $3
-.loop3
- ld a, [de]
- and $55
- ld c, a
- ld a, [de]
- and $aa
- srl a
- or c
- add [hl]
- ld [hli], a
- inc de
- dec b
- jr nz, .loop3
- ld bc, $0002
- call AdvanceFrames
- ret
-
-FadeIn_GameboyColor: ; 0xc19
-; Fades in to the target palette data in wPaletteData from wFadeBGPaletteData and wFadeOBJPaletteData
-; Fade is completed after 16 frames of incrementally updating the palettes.
- ld b, 16 ; fade takes 16 frames to complete
-.loop
- push bc
- ld de, wPaletteData
- ld hl, wFadeBGPaletteData
- call FadeInStep
- call SetFadedPalettes
- pop bc
- dec b
- jr nz, .loop
- ret
-
-FadeInStep: ; 0xc2d
-; de = base palette data
-; hl = faded palette data
- ld a, b
- cp $1
- jr z, .lastStep
- ld c, $40 ; total number of colors in BG and OBJ palettes
-.loop
- push bc
- ld a, [hli]
- sub $42
- ld c, a
- ld a, [hld]
- sbc $8
- ld b, a ; subtracted 2 from each RGB value of the color
- call GetNextFadedPalette
- ld a, c
- ld [hli], a
- ld a, b
- ld [hli], a
- pop bc
- dec c
- jr nz, .loop
- ret
-
-.lastStep
- ld c, $40 ; total number of colors in BG and OBJ palettes
-.loop2
- push bc
- ld a, [hli]
- sub $21
- ld c, a
- ld a, [hld]
- sbc $4
- ld b, a
- call GetNextFadedPalette
- ld a, c
- ld [hli], a
- ld a, b
- ld [hli], a
- pop bc
- dec c
- jr nz, .loop2
- ret
-
-GetNextFadedPalette: ; 0xc60
-; de = source palette data
-; bc = target palette RGB - 2
-; Places the resulting palette RGB into bc
- push hl
- ld a, [de]
- and %00011111 ; Target RGB Blue value
- ld l, a
- ld a, c
- and %00011111 ; Current faded RBG Blue value - 2
- cp l
- jr nc, .brighter
- ; set the current faded Blue value to the target blue value.
- ld a, c
- and %11100000
- or l
- ld c, a
-.brighter
- ld a, [de]
- and %11100000
- ld l, a
- inc de
- ld a, [de]
- srl a
- rr l
- srl a
- rr l
- ld a, c
- and %11100000
- ld h, a
- ld a, b
- srl a
- rr h
- srl a
- rr h
- ld a, h
- cp l
- jr nc, .asm_ca3
- ld h, $0
- sla l
- rl h
- sla l
- rl h
- ld a, c
- and $1f
- or l
- ld c, a
- ld a, b
- and $7c
- or h
- ld b, a
-.asm_ca3
- ld a, [de]
- and $7c
- ld l, a
- ld a, b
- and $7c
- cp l
- jr nc, .asm_cb2
- ld a, b
- and $3
- or l
- ld b, a
-.asm_cb2
- inc de
- pop hl
- ret
-
-FadeOut: ; 0xcb5
-; Fades palettes out to a white screen.
- ld a, [hGameBoyColorFlag]
- and a
- jp nz, FadeOut_GameboyColor
- ; Regular Gameboy
- ld hl, hBGP
- ld b, $3
-.loop
- push bc
- push hl
- ld b, $3
-.loop2
- ld a, [hl]
- and $55
- ld c, a
- ld a, [hl]
- and $aa
- srl a
- or c
- cpl
- inc a
- add [hl]
- ld [hli], a
- dec b
- jr nz, .loop2
- ld bc, $0002
- call AdvanceFrames
- pop hl
- pop bc
- dec b
- jr nz, .loop
- xor a
- ld hl, hBGP
- ld [hli], a
- ld [hli], a
- ld [hl], a
- ld bc, $0002
- call AdvanceFrames
- ret
-
-FadeOut_GameboyColor: ; 0xcee
-; Fades out to white RGB colors from the currently-loaded palettes.
-; Fade is completed after 16 frames of incrementally updating the palettes.
- ld hl, wFadeBGPaletteData
- ld de, rBGPI
- call LoadCurrentPalettesIntoFadePalettes
- ld hl, wFadeOBJPaletteData
- ld de, rOBPI
- call LoadCurrentPalettesIntoFadePalettes
- ld b, 16 ; fade takes 16 frames to complete
-.loop
- push bc
- ld hl, wFadeBGPaletteData
- call FadeOutStep
- call SetFadedPalettes
- pop bc
- dec b
- jr nz, .loop
- ret
-
-FadeOutStep: ; 0xd11
-; hl = faded palette data
- ld b, $40
-.asm_d13
- ld a, [hl]
- and $1f
- add $2
- ld e, a
- cp $1f
- jr c, .asm_d1f
- ld e, $1f
-.asm_d1f
- ld a, [hl]
- and $e0
- or e
- ld [hl], a
- ld a, [hli]
- and $e0
- ld e, [hl]
- dec hl
- srl e
- rr a
- srl e
- rr a
- add $10
- ld e, a
- jr nc, .asm_d38
- ld e, $f8
-.asm_d38
- ld d, $0
- sla e
- rl d
- sla e
- rl d
- ld a, [hl]
- and $1f
- or e
- ld [hli], a
- ld a, [hl]
- and $7c
- or d
- ld [hl], a
- ld a, [hl]
- and $7c
- add $8
- ld e, a
- cp $7c
- jr c, .asm_d58
- ld e, $7c
-.asm_d58
- ld a, [hl]
- and $3
- or e
- ld [hli], a
- dec b
- jr nz, .asm_d13
- ret
-
-SetFadedPalettes: ; 0d61
-; Sets the current palette data to the faded palettes.
- ld a, [rIE]
- res 0, a
- ld [rIE], a
- ld hl, wFadeBGPaletteData
- ld de, rBGPI
- ld a, $80
- ld [de], a
- inc de
-.waitForVBlank
- ld a, [rLY]
- cp $90
- jr c, .waitForVBlank
- ld b, $10
-.loadBGColorsLoop
- ld a, [hli]
- ld [de], a
- ld a, [hli]
- ld [de], a
- ld a, [hli]
- ld [de], a
- ld a, [hli]
- ld [de], a
- dec b
- jr nz, .loadBGColorsLoop
- inc de
- ld a, $80
- ld [de], a
- inc de
- ld b, $10
-.loadOBJColorsLoop
- ld a, [hli]
- ld [de], a
- ld a, [hli]
- ld [de], a
- ld a, [hli]
- ld [de], a
- ld a, [hli]
- ld [de], a
- dec b
- jr nz, .loadOBJColorsLoop
- ld a, [rIE]
- set 0, a
- ld [rIE], a
- ret
-
-LoadCurrentPalettesIntoFadePalettes: ; 0xd9d
-; hl = destination for palette data
-; de = source of palettes (rBGPI or rOBPI)
- ld b, $0
- ld c, e
- inc c
- call WaitForLCD
-.asm_da4
- call Func_61b
-.asm_da7
- ld a, [rSTAT]
- and $3
- jr nz, .asm_da7 ; wait for lcd controller to finish transferring data
- ld a, b
- ld [de], a
- ld a, [$ff00+c]
- ld [hli], a
- inc b
- ld a, b
- ld [de], a
- ld a, [$ff00+c]
- ld [hli], a
- inc b
- ld a, b
- ld [de], a
- ld a, [$ff00+c]
- ld [hli], a
- inc b
- ld a, b
- ld [de], a
- ld a, [$ff00+c]
- ld [hli], a
- inc b
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- ld a, b
- cp $40
- jr nz, .asm_da4
- ret
+INCLUDE "home/palettes.asm"
Func_dd4: ; 0xdd4
; Return a * l to hl
@@ -1391,13 +902,18 @@ Modulo_C: ; 0xe55
and a
ret
-Func_e5d: ; 0xe5d
+ToggleAudioEngineUpdateMethod: ; 0xe5d
+; The audio engine is normally updated once every V-Blank interrupt. However, during pinball gameplay,
+; the LCD is disabled (no V-Blanks) when the pinball is transitioning between the Top- and Bottom-halfs of
+; the Red and Blue Fields. Therefore, the audio engine wouldn't get updated for a fraction of a second, which
+; would has a noticeable pause in the music. To solve this, the Timer interrupt is enabled while the V-Blank is
+; disabled, and the audio engine gets updated during the Timer interrupt.
ld a, $1
- ld [wd84a], a
-.asm_e62
- ld a, [wd84a]
+ ld [wToggleAudioEngineUpdateMethod], a
+.wait
+ ld a, [wToggleAudioEngineUpdateMethod]
and a
- jr nz, .asm_e62
+ jr nz, .wait
ret
DrawBottomMessageBox: ; 0xe69
@@ -1657,10 +1173,16 @@ Func_10a4: ; 0x10a4
Func_10a7: ; 0x10a7
jp Func_3ff
-Func_10aa: ; 0x10aa
+QueueGraphicsToLoad: ; 0x10aa
+; Queues graphics data to be loaded into VRAM at the next available time.
+; See the data/queued_tiledata/ directory to view the data that is loaded by this function.
+; Input: hl = pointer to async tile data header
+; byte 1 = number of chunks to load
+; 2*(byte 1) = list of pointers to chunks
+; a = bank of async tile data
ld c, a
ld a, [hli]
- ld b, a ;bc = [hl]a
+ ld b, a
.loop
push bc
ld a, c
@@ -1677,14 +1199,19 @@ Func_10aa: ; 0x10aa
inc bc
pop af
push hl
- call Func_10c5
+ call QueueGraphicsToLoadWithFunc
pop hl
pop bc
dec b
jr nz, .loop
ret
-Func_10c5: ; 0x10c5
+QueueGraphicsToLoadWithFunc: ; 0x10c5
+; Queues graphics data to be loaded into VRAM with the given function at the next available time.
+; See the data/queued_tiledata/ directory to view the data that is loaded by this function.
+; Input: de: function that is responsible for loading the chunk of VRAM data
+; hl: pointer to data
+; a: bank of data
push af
ld a, [rLCDC]
bit 7, a
@@ -2552,7 +2079,7 @@ Func_1ffc: ; 0x1ffc
ld [wd807], a
callba Func_3c000
ld a, $1
- ld [wd85d], a
+ ld [wAudioEngineEnabled], a
ld a, $37 ; space character for player high scores name
ld [wPlayerName], a
ld [wPlayerName + 1], a
@@ -3865,9 +3392,9 @@ HandleLeftTilt: ; 0x358c
dec a ; move ball's position to the left by 1 pixel
ld [wBallXPos + 1], a
.skipBallMovement
- ld a, [wd79f]
+ ld a, [wLeftAndRightTiltPixelsOffset]
inc a
- ld [wd79f], a
+ ld [wLeftAndRightTiltPixelsOffset], a
ld a, $1
ld [wLeftTiltPushing], a
ret
@@ -3883,9 +3410,9 @@ HandleLeftTilt: ; 0x358c
jr z, .done
dec a
ld [wLeftTiltCounter], a
- ld a, [wd79f]
+ ld a, [wLeftAndRightTiltPixelsOffset]
dec a
- ld [wd79f], a
+ ld [wLeftAndRightTiltPixelsOffset], a
ret
.done
@@ -3921,9 +3448,9 @@ HandleRightTilt: ; 0x35f3
inc a ; move ball's position to the right by 1 pixel
ld [wBallXPos + 1], a
.skipBallMovement
- ld a, [wd79f]
+ ld a, [wLeftAndRightTiltPixelsOffset]
dec a
- ld [wd79f], a
+ ld [wLeftAndRightTiltPixelsOffset], a
ld a, $1
ld [wRightTiltPushing], a
ret
@@ -3939,9 +3466,9 @@ HandleRightTilt: ; 0x35f3
jr z, .done
dec a
ld [wRightTiltCounter], a
- ld a, [wd79f]
+ ld a, [wLeftAndRightTiltPixelsOffset]
inc a
- ld [wd79f], a
+ ld [wLeftAndRightTiltPixelsOffset], a
ret
.done
@@ -3977,9 +3504,9 @@ HandleUpperTilt: ; 0x365a
inc a ; move ball's position down by 1 pixel
ld [wBallYPos + 1], a
.skipBallMovement
- ld a, [wd7a0]
+ ld a, [wUpperTiltPixelsOffset]
dec a
- ld [wd7a0], a
+ ld [wUpperTiltPixelsOffset], a
ld a, $1
ld [wUpperTiltPushing], a
ret
@@ -3995,9 +3522,9 @@ HandleUpperTilt: ; 0x365a
jr z, .done
dec a
ld [wUpperTiltCounter], a
- ld a, [wd7a0]
+ ld a, [wUpperTiltPixelsOffset]
inc a
- ld [wd7a0], a
+ ld [wUpperTiltPixelsOffset], a
ret
.done