summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcus Huderle <huderlem@gmail.com>2015-02-22 13:25:04 -0800
committerMarcus Huderle <huderlem@gmail.com>2015-02-22 13:25:04 -0800
commit3292c7d4d1d3f7acec663688bdf10fe3fefd43fe (patch)
tree39b00e182da09a9e65839e2aba0cf11a0cd4402d
parentab90af156e9ce2f4432506623afb6385db6293b1 (diff)
Dump and document Sound Test selection routines.
-rwxr-xr-xconstants.asm2
-rwxr-xr-xconstants/joy_constants.asm17
-rwxr-xr-xconstants/song_constants.asm2
-rwxr-xr-xconstants/sound_effect_constants.asm1
-rwxr-xr-xmacros.asm7
-rwxr-xr-xmain.asm132
-rwxr-xr-xwram.asm7
7 files changed, 165 insertions, 3 deletions
diff --git a/constants.asm b/constants.asm
index 1925b28..2b2dbe5 100755
--- a/constants.asm
+++ b/constants.asm
@@ -1,4 +1,6 @@
INCLUDE "hram.asm"
INCLUDE "vram.asm"
+INCLUDE "constants/joy_constants.asm"
INCLUDE "constants/song_constants.asm"
+INCLUDE "constants/sound_effect_constants.asm"
diff --git a/constants/joy_constants.asm b/constants/joy_constants.asm
new file mode 100755
index 0000000..1ece577
--- /dev/null
+++ b/constants/joy_constants.asm
@@ -0,0 +1,17 @@
+BIT_A_BUTTON EQU 0
+BIT_B_BUTTON EQU 1
+BIT_SELECT EQU 2
+BIT_START EQU 3
+BIT_D_RIGHT EQU 4
+BIT_D_LEFT EQU 5
+BIT_D_UP EQU 6
+BIT_D_DOWN EQU 7
+
+A_BUTTON EQU %00000001
+B_BUTTON EQU %00000010
+SELECT EQU %00000100
+START EQU %00001000
+D_RIGHT EQU %00010000
+D_LEFT EQU %00100000
+D_UP EQU %01000000
+D_DOWN EQU %10000000
diff --git a/constants/song_constants.asm b/constants/song_constants.asm
index aa95c9c..b1aae4d 100755
--- a/constants/song_constants.asm
+++ b/constants/song_constants.asm
@@ -1,3 +1,5 @@
+NUM_SONGS EQU $17
+
MUSIC_NOTHING_0F EQU $00
MUSIC_BLUE_FIELD EQU $01
MUSIC_CATCH_EM_RED EQU $02
diff --git a/constants/sound_effect_constants.asm b/constants/sound_effect_constants.asm
new file mode 100755
index 0000000..a3cd474
--- /dev/null
+++ b/constants/sound_effect_constants.asm
@@ -0,0 +1 @@
+NUM_SOUND_EFFECTS EQU $4e
diff --git a/macros.asm b/macros.asm
index a53faf4..0cf0516 100755
--- a/macros.asm
+++ b/macros.asm
@@ -24,3 +24,10 @@ x = x + -8
bigdw: MACRO ; big-endian word
dx 2, \1
ENDM
+
+;\1 = X
+;\2 = Y
+;\3 = Reference Background Map (e.g. vBGMap0 or vBGMap1)
+hlCoord: MACRO
+ ld hl, \3 + $20 * \2 + \1
+ ENDM
diff --git a/main.asm b/main.asm
index 24b2473..e803874 100755
--- a/main.asm
+++ b/main.asm
@@ -301,7 +301,45 @@ InitialHRAM:
; These $a bytes are initially load into $ff80 - $ff8a by InitializeHRAM.
db $3e, $d0, $e0, $46, $3e, $28, $3d, $20, $fd, $c9
-INCBIN "baserom.gbc",$60f,$654 - $60f
+WaitForLCD: ; 0x60f
+; Wait for LCD controller to stop reading from both OAM and VRAM because
+; CPU can't access OAM, VRAM, or palette data ($ff69, $ff6b) during this time.
+ ld a, [$ff41] ; LCDC Status register
+ and $3
+ jr nz, WaitForLCD
+ ld a, $a
+.delay10Cycles
+ dec a
+ jr nz, .delay10Cycles
+ ret
+
+Func_61b: ; 0x61b
+ ld a, [$ff44] ; LY register (LCDC Y-Coordinate)
+ cp $40
+ jr c, .asm_625
+ cp $80
+ jr c, .asm_63d
+.asm_625
+ ld a, [$ff44] ; LY register (LCDC Y-Coordinate)
+ cp $40
+ jr c, .asm_625
+ cp $80
+ jr nc, .asm_625
+.asm_62f
+ ld a, [$ff41]
+ 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
+
+INCBIN "baserom.gbc",$63e,$654 - $63e
ClearData: ; 0x654
; Clears bc bytes starting at hl.
@@ -437,7 +475,24 @@ Func_724: ; 0x724
jr z, .copyByte
ret
-INCBIN "baserom.gbc",$735,$916 - $735
+INCBIN "baserom.gbc",$735,$848 - $735
+
+PutTileInVRAM: ; 0x848
+; Puts a tile in VRAM.
+; input: a = tile number
+; hl = pointer to VRAM location where tile should be placed
+ push af
+ call WaitForLCD
+ call Func_61b
+.asm_84f
+ ld a, [$ff41]
+ and $3
+ jr nz, .asm_84f ; wait for lcd controller to finish transferring data
+ pop af
+ ld [hl], a ; Store tile number in VRAM background map
+ ret
+
+INCBIN "baserom.gbc",$858,$916 - $858
ClearOAMBuffer: ; 0x916
; Clears the OAM buffer by loading $f0 into all of the entries.
@@ -1409,7 +1464,78 @@ DataArray_c3d4: ; 0xc3d4
db $FF, $FF ; terminators
-INCBIN "baserom.gbc",$c400,$c77e - $c400
+INCBIN "baserom.gbc",$c400,$c715 - $c400
+
+UpdateSoundTestBackgroundMusicSelection: ; 0xc715
+ ld a, [$ff9a] ; joypad state
+ ld b, a
+ ld a, [wSoundTestCurrentBackgroundMusic]
+ bit BIT_D_LEFT, b ; was the left dpad button pressed?
+ jr z, .checkIfRightPressed
+ dec a ; decrement background music id
+ bit 7, a ; did it wrap around to $ff?
+ jr z, .saveBackgroundMusicID
+ ld a, NUM_SONGS - 1
+ jr .saveBackgroundMusicID
+.checkIfRightPressed
+ bit BIT_D_RIGHT, b ; was the right dpad button pressed?
+ ret z
+ inc a ; increment background music id
+ cp NUM_SONGS ; should it wrap around to 0?
+ jr nz, .saveBackgroundMusicID
+ xor a
+.saveBackgroundMusicID
+ ld [wSoundTestCurrentBackgroundMusic], a
+ hlCoord 7, 11, vBGMap0
+ jp RedrawSoundTestID
+
+UpdateSoundTestSoundEffectSelection: ; 0xc73a
+ ld a, [$ff99] ; joypad state
+ bit BIT_A_BUTTON, a
+ jr z, .didntPressAButton
+ ld a, [wSoundTextCurrentSoundEffect]
+ ld e, a
+ ld d, $0
+ call $04af ; todo: play sound effect, probably
+ ret
+.didntPressAButton
+ ld a, [$ff9a] ; joypad state
+ ld b, a
+ ld a, [wSoundTextCurrentSoundEffect]
+ bit BIT_D_LEFT, b ; was the left dpad button pressed?
+ jr z, .checkIfRightPressed
+ dec a ; decrement sound effect id
+ bit 7, a ; did it wrap around to $ff?
+ jr z, .saveSoundEffectID
+ ld a, NUM_SOUND_EFFECTS - 1
+ jr .saveSoundEffectID
+.checkIfRightPressed
+ bit BIT_D_RIGHT, b ; was the right dpad button pressed?
+ ret z
+ inc a ; increment background music id
+ cp NUM_SOUND_EFFECTS ; should it wrap around to 0?
+ jr nz, .saveSoundEffectID
+ xor a
+.saveSoundEffectID
+ ld [wSoundTextCurrentSoundEffect], a
+ hlCoord 7, 13, vBGMap0
+ ; fall through
+
+RedrawSoundTestID:
+; Redraws the 2-digit id number for the sound test's current background music or sound effect id.
+; input: a = id number
+; hl = pointer to bg map location where the new 2-digit id should be drawn
+ push af ; save music or sound effect id number
+ swap a
+ and $f ; a contains high nybble of music id
+ call .drawDigit
+ pop af
+ and $f ; a contains low nybble of music id
+.drawDigit
+ add $b7 ; hexadecimal digit tiles start at tile number $b7
+ call PutTileInVRAM
+ inc hl
+ ret
SongBanks: ; 0xc77e
db MUSIC_NOTHING_0F,BANK(Music_Nothing0F)
diff --git a/wram.asm b/wram.asm
index 3f2534f..0836af6 100755
--- a/wram.asm
+++ b/wram.asm
@@ -12,3 +12,10 @@ SECTION "WRAM Bank 1", WRAMX, BANK[1]
wOAMBuffer:: ; d000
; buffer for OAM data. Copied to OAM by DMA
ds 4 * 40
+
+ ds $87a
+
+wSoundTestCurrentBackgroundMusic:: ; d91a
+ ds 1
+wSoundTextCurrentSoundEffect:: ; 0xd91b
+ ds 1