Skip to content

Commit

Permalink
Document Golf and Audio stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
ElectroDeoxys committed Jun 20, 2024
1 parent 1649ac9 commit 7451c6d
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 41 deletions.
3 changes: 3 additions & 0 deletions src/audio/engine.asm
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,9 @@ _PlayNewMusic_SetNoise::
jr z, Func_302e4
jp ReturnFromAudioJump

; loops through all music channels and
; if either CHANFLAGS_5 or CHANFLAGS_6 are set
; then set it as active
Func_302e4::
xor a
ld [w3d025], a
Expand Down
5 changes: 3 additions & 2 deletions src/constants/golf_constants.asm
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ DEF GOLF_BUILDING_PRICE EQU $50
const GOLF_COURSE_4 ; $3
DEF NUM_GOLF_COURSES EQU const_value

DEF GOLF_BASE_SCORE EQU 20
DEF golf_score EQUS "GOLF_BASE_SCORE +"
DEF NUM_GOLF_COURSE_LEVELS EQU 4 ; how many levels in a golf course

; maximum number of strokes over par
; for golf levels inside the various courses
DEF MAX_GOLF_COURSE_STROKES EQU 19
DEF GOLF_BASE_SCORE EQU MAX_GOLF_COURSE_STROKES + 1
DEF golf_score EQUS "GOLF_BASE_SCORE +"

; golf level constants
const_def
Expand Down
10 changes: 5 additions & 5 deletions src/engine/bank2b.asm
Original file line number Diff line number Diff line change
Expand Up @@ -1833,7 +1833,7 @@ _InitTempleScene:
xor a
ld [w2d013], a
ld [w2d014], a
ld a, [w1d800]
ld a, [wLCDCFlagsToFlip]
ld b, a
and a
ld a, LCDCF_BGON | LCDCF_OBJON | LCDCF_OBJ16 | LCDCF_WIN9C00 | LCDCF_ON
Expand All @@ -1843,7 +1843,7 @@ _InitTempleScene:
ldh [rLCDC], a

xor a
ld [w1d800], a
ld [wLCDCFlagsToFlip], a

ld hl, wSubState
inc [hl]
Expand Down Expand Up @@ -2563,7 +2563,7 @@ HiddenFigureRevealScene:
and a
ret nz
ld a, LCDCF_BG9C00
ld [w1d800], a
ld [wLCDCFlagsToFlip], a
jp Func_ad016

.LoadHiddenFigureGfx1
Expand Down Expand Up @@ -3010,8 +3010,8 @@ HandleEnterTempleWithAllMusicBoxesScene:
ret z
xor a
ld [wSceneObj1State], a
ld a, $02
ld [w1da00], a
ld a, TEMPLE_SCENE_EXITING
ld [wTempleScene], a
xor a
ld [wTempleSceneCounter], a
ret
Expand Down
17 changes: 9 additions & 8 deletions src/engine/golf/building.asm
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ Func_1c8586:
jr nz, .asm_1c85b3
ld a, $01
ld [w1d800], a

.asm_1c85b3
; clear all Golf RAM starting from wPredeterminedGolfLevel onwards
ld hl, wPredeterminedGolfLevel
ld bc, $7fe
ld bc, SIZEOF("Golf RAM") - (wPredeterminedGolfLevel - STARTOF("Golf RAM"))
.loop
xor a
ld [hli], a
Expand Down Expand Up @@ -97,7 +99,7 @@ Func_1c8604:
ld [wGolfCourse], a
call Func_1c87db
call GetGolfCourseTargetSCX
ld hl, w1d900
ld hl, wGolfCourseTileMap
debgcoord 0, 6
ld b, 7 * BG_MAP_WIDTH
call CopyHLToDE
Expand Down Expand Up @@ -334,7 +336,7 @@ Func_1c86f8:
dw Frameset_1cb5de
dw Frameset_1cb5e1

; loads attribute map to w1d900
; loads attribute map to wGolfCourseTileMap
; and palettes to w1db00
; depending on value in wGolfCourse
Func_1c87db:
Expand All @@ -354,8 +356,8 @@ Func_1c87db:
push hl
ld h, d
ld l, e
ld de, w1d900
ld bc, $e0
ld de, wGolfCourseTileMap
ld bc, 7 * BG_MAP_WIDTH
call FarCopyHLToDE_BC2
pop hl
ld a, [hli]
Expand Down Expand Up @@ -396,7 +398,6 @@ Func_1c882b:
dw Func_1c88dc
dw Func_1c8907
dw Func_1c8911
; 0x1C8837

Func_1c8837:
ld a, [wJoypadPressed]
Expand Down Expand Up @@ -541,12 +542,12 @@ Func_1c8911:
ret
.done_subtracting
play_sfx SFX_SELECTION
call .Func_1c8944
call .SetGolfLevel
ld a, $04
ld [wSubState], a
ret

.Func_1c8944
.SetGolfLevel:
ld hl, .first_golf_levels
ld a, [wGolfMenuOption]
ld b, $00
Expand Down
50 changes: 28 additions & 22 deletions src/engine/golf/level.asm
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ InitGolfLevel:
call ShowGolfLevelFlagAndPar
jp SetUpGolfLevelObjects

; if there's a golf level already loaded in wPredeterminedGolfLevel
; then pick that one, otherwise, determine the golf level tier
; given the number of collected treasures, and select a random
; level up to that tier
PickAndLoadGolfLevel:
ld a, BANK("Golf Gfx 1")
ld [wTempBank], a
Expand All @@ -104,7 +108,7 @@ PickAndLoadGolfLevel:
.no_predetermined_golf_level
; tier 3
ld a, GOLF_LEVEL_TIER_3
ld [w1dc0e], a
ld [wGolfLevelTier], a
ld a, [wNumCollectedTreasures + 0]
and a
jr nz, .got_tier
Expand All @@ -115,14 +119,15 @@ PickAndLoadGolfLevel:
jr nc, .tier_2
; tier 1
ld a, GOLF_LEVEL_TIER_1
ld [w1dc0e], a
ld [wGolfLevelTier], a
jr .got_tier
.tier_2
ld a, GOLF_LEVEL_TIER_2
ld [w1dc0e], a
ld [wGolfLevelTier], a

.got_tier
ld a, [w1dc0e]
; golfLevel = rDIV % wGolfLevelTier
ld a, [wGolfLevelTier]
ld b, a
ldh a, [rDIV]
ld c, a
Expand Down Expand Up @@ -242,7 +247,7 @@ ShowGolfLevelFlagAndPar:
ld a, [wGolfPar]
add MAX_GOLF_COURSE_STROKES
ld [wGolfMaxStrokes], a
ld a, [w1d803]
ld a, [wGolfCourseLevel]
jr .got_max_strokes
.asm_1c8ba3
ld a, [wGolfPar]
Expand Down Expand Up @@ -2544,18 +2549,19 @@ GolfLevelState_Cleared:
ld a, [wGolfCourseScore]
add c
ld [wGolfCourseScore], a
ld hl, w1d803
ld hl, wGolfCourseLevel
ld a, [hl]
cp $04
jr z, .asm_1c9b00
cp NUM_GOLF_COURSE_LEVELS
jr z, .finished_course
; still more levels left
inc [hl]
ld hl, wPredeterminedGolfLevel
inc [hl]
ld a, $04
ld [wSubState], a
ret

.asm_1c9b00
.finished_course
xor a
ld [wGolfCounter], a
ld [wGolfWarioDuration], a
Expand Down Expand Up @@ -2892,15 +2898,15 @@ VBlank_1c9d1d:
ld a, [wGolfLCDConfig]
ldh [rLCDC], a
ld hl, rHDMA1
ld a, HIGH(w1d900)
ld a, HIGH(wGolfPinFlagTiles)
ld [hli], a
ld a, LOW(w1d900)
ld a, LOW(wGolfPinFlagTiles)
ld [hli], a
ld a, $17
ld [hli], a
ld a, $40
ld [hli], a
ld a, $03
ld a, 4 dma_tiles
ld [hl], a
xor a
ldh [rVBK], a
Expand All @@ -2918,18 +2924,18 @@ VBlank_1c9d1d:
cp $08
jr nc, .frame_1
; frame 0
ld hl, GolfPinFlag tile $00
ld hl, GolfPinFlagGfx tile $00
jr .got_tiles
.frame_1
ld hl, GolfPinFlag tile $04
ld hl, GolfPinFlagGfx tile $04
jr .got_tiles
.frame_2
ld hl, GolfPinFlag tile $08
ld hl, GolfPinFlagGfx tile $08
jr .got_tiles
.frame_3
ld hl, GolfPinFlag tile $0c
ld hl, GolfPinFlagGfx tile $0c
.got_tiles
ld de, w1d900
ld de, wGolfPinFlagTiles
ld b, 4 tiles
call CopyHLToDE

Expand All @@ -2940,7 +2946,7 @@ VBlank_1c9d1d:
ld [hl], a
ret

GolfPinFlag: INCBIN "gfx/golf/golf_pin_flag.2bpp"
GolfPinFlagGfx: INCBIN "gfx/golf/golf_pin_flag.2bpp"

VBlank_1c9e8d:
ld hl, .Func
Expand Down Expand Up @@ -3098,7 +3104,7 @@ VBlank_1c9f7a:
xor a
ld [hli], a
ld [hli], a
ld a, $7f
ld a, $80 dma_tiles
ld [hl], a
ld a, HIGH(wVirtualOAM)
jp hTransferVirtualOAM
Expand Down Expand Up @@ -3155,7 +3161,7 @@ VBlank_1c9ffa:
ld [wdc11 + 0], a
ld a, $c0
ld [wdc11 + 1], a
ld a, 14 - 1
ld a, $e dma_tiles
ld [w1dc13], a

ld hl, .Func
Expand Down Expand Up @@ -3204,7 +3210,7 @@ VBlank_1ca056:
ld [wdc11 + 0], a
ld a, $c0
ld [wdc11 + 1], a
ld a, 14 - 1
ld a, $e dma_tiles
ld [w1dc13], a

ld hl, .Func
Expand All @@ -3221,7 +3227,7 @@ VBlank_1ca056:
ldh [rSCX], a
ld a, BANK("VRAM1")
ldh [rVBK], a
ld hl, w1d900
ld hl, wGolfPinFlagTiles
call Func_2c30
xor a
ldh [rVBK], a
Expand Down
23 changes: 19 additions & 4 deletions src/wram.asm
Original file line number Diff line number Diff line change
Expand Up @@ -1112,7 +1112,8 @@ wGolfMenuOption::
wPredeterminedGolfLevel::
db

w1d803::
; current level number of golf course
wGolfCourseLevel::
db

; GOLF_COURSE_* constant
Expand All @@ -1128,8 +1129,22 @@ wGolfCourseScore::
; start of the RAM related to the Golf levels
wGolfLevelRAMStart::

w1d900::
ds 16 tiles
UNION

; BGMap values to draw the golf course
; currently shown in the Golf Building menu
wGolfCourseTileMap::
ds 7 * BG_MAP_WIDTH

NEXTU

; golf flag animation tiles to draw to VRAM
wGolfPinFlagTiles::
ds 4 tiles

ENDU

ds $20

w1da00::
ds $100
Expand Down Expand Up @@ -1184,7 +1199,7 @@ wGolfLCDConfig::
wGolfWarioTilesBank::
db

w1dc0e::
wGolfLevelTier::
db

wGolfPrice::
Expand Down

0 comments on commit 7451c6d

Please sign in to comment.