aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAstatin <[email protected]>2025-07-12 02:45:00 +0200
committerAstatin <[email protected]>2025-07-12 02:45:00 +0200
commitd77b156de83e8a93e3fa9832642824089593d1db (patch)
treef33a5a1f8bb54680b89db41e1ed8c26595a2231e
parente9dc1a32f8e7199e020123e0377c665c0e1443a1 (diff)
Play music from included vgm file
-rw-r--r--Makefile4
-rw-r--r--definitions.gbasm2
-rw-r--r--entity/utils.gbasm1
-rw-r--r--init.gbasm4
-rw-r--r--main.gbasm8
-rw-r--r--modes/dialoguemenu.gbasm2
-rw-r--r--modes/dungeon.gbasm2
-rw-r--r--modes/dungeongeneration.gbasm47
-rw-r--r--modes/loading.gbasm2
-rw-r--r--music/load.gbasm90
-rw-r--r--music/test.vgmbin0 -> 2093 bytes
11 files changed, 152 insertions, 10 deletions
diff --git a/Makefile b/Makefile
index e4330c9..ec62e0a 100644
--- a/Makefile
+++ b/Makefile
@@ -25,7 +25,7 @@ build/main.rom: build/main.rom.unsigned
cp build/main.rom.unsigned build/main.rom
python scripts/set_checksums.py build/main.rom
-build/main.rom.unsigned: main.gbasm tileset.gbasm text.gbasm dialogues/text.gbasm map/maps.gbasm $(wildcard ./*.gbasm) $(wildcard ./**/*.gbasm) $(wildcard ./**/**/*.gbasm)
+build/main.rom.unsigned: main.gbasm tileset.gbasm text.gbasm dialogues/text.gbasm map/maps.gbasm $(wildcard ./*.gbasm) $(wildcard ./**/*.gbasm) $(wildcard ./**/**/*.gbasm) $(wildcard ./music/*.vgm)
mkdir -p build
$(GBASM) $< $@ > build/main.sym
@@ -58,7 +58,7 @@ build/game_linux_x86-64: build/makeself/start.sh build/makeself/main.rom build/m
run: build/main.rom
mkdir -p recordings
- gb $< --record-input "./recordings/$(shell date -Iseconds).record"
+ gb $< --record-input "./recordings/$(shell date -Iseconds).record" -k
sameboy: build/main.rom
sameboy build/main.rom
diff --git a/definitions.gbasm b/definitions.gbasm
index 60fcf2b..d5f4bbb 100644
--- a/definitions.gbasm
+++ b/definitions.gbasm
@@ -171,6 +171,8 @@
.DEFINE mem_rom_collision_map_addr $c067 ; Takes $c067 to $c069 (bank + ptr)
+.DEFINE mem_current_vgm_pc $c070 ; Takes $c070 to $c072 (bank + ptr)
+
; ## WARNING THE SPACE BETWEEN $c400 and $c800 is used as a buffer for the loading map function during dungeon generation
.DEFINE mem_map_loading_buffer $c400
diff --git a/entity/utils.gbasm b/entity/utils.gbasm
index e16e37a..935073c 100644
--- a/entity/utils.gbasm
+++ b/entity/utils.gbasm
@@ -103,6 +103,7 @@ Entity_idx_to_entity_list_ptr: ; loaded idx in A, return in BC
LD A, B
ADC high(=Entity_list)
LD B, A
+ .LOAD_BANK_OF =Entity_list
POP DE
RET
diff --git a/init.gbasm b/init.gbasm
index e4706e9..af4616f 100644
--- a/init.gbasm
+++ b/init.gbasm
@@ -25,13 +25,13 @@ Header:
.PADTO 0x13f
.Manufacturer_code:
-.PADTO 0x142
+.PADTO 0x143
.CGB_Flag: .DB $69
.Licensee_code_new: .DB $00, $00
.SGB_Flag: .DB $00
.MBC: .DB $01
-.ROM_size: .DB $00
+.ROM_size: .DB $08
.RAM_size: .DB $00 ; The .sav cartridge kind of ram
.Destination_code: .DB $01 ; Overseas
.Licensee_code_old: .DB $00
diff --git a/main.gbasm b/main.gbasm
index d68c342..b69d881 100644
--- a/main.gbasm
+++ b/main.gbasm
@@ -1,5 +1,6 @@
.INCLUDE "definitions.gbasm"
.INCLUDE "init.gbasm"
+.INCLUDE "utils.gbasm"
.MACRODEF HBLANK_WAIT
LD A, $reg_lcd_controller
@@ -135,9 +136,10 @@ Entrypoint:
CALL =Load_Tile
+ CALL =Load_Music
+
JP =New_Dungeon
-.INCLUDE "utils.gbasm"
.INCLUDE "tiles.gbasm"
.INCLUDE "rng.gbasm"
.INCLUDE "dialogues/utils.gbasm"
@@ -162,6 +164,7 @@ Entrypoint:
.INCLUDE "enemiesattacks.gbasm"
.INCLUDE "dialogues/functions.gbasm"
.INCLUDE "map/loading/dungeoninfos.gbasm"
+.INCLUDE "music/load.gbasm"
.PADTO $4000
.INCLUDE "tileset.gbasm"
@@ -169,3 +172,6 @@ Entrypoint:
.INCLUDE "dialogues/dialogues.gbasm"
.INCLUDE "map/maps.gbasm"
.INCLUDE "map/dungeons.gbasm"
+
+_music_Test:
+.INCLUDEBIN "music/test.vgm"
diff --git a/modes/dialoguemenu.gbasm b/modes/dialoguemenu.gbasm
index ad0b3be..306ea50 100644
--- a/modes/dialoguemenu.gbasm
+++ b/modes/dialoguemenu.gbasm
@@ -48,5 +48,7 @@ Dialogue_VBLANK_Entrypoint:
INC A
LD $mem_loop_frame_timer, A
+ CALL =Play_Music
+
.ENABLE_VBLANK_INTERRUPTS
RETI
diff --git a/modes/dungeon.gbasm b/modes/dungeon.gbasm
index 1d27cc1..9062425 100644
--- a/modes/dungeon.gbasm
+++ b/modes/dungeon.gbasm
@@ -187,5 +187,7 @@ Dungeon_VBLANK_Entrypoint:
INC A
LD $mem_loop_frame_timer, A
+ CALL =Play_Music
+
.ENABLE_VBLANK_INTERRUPTS
RETI
diff --git a/modes/dungeongeneration.gbasm b/modes/dungeongeneration.gbasm
index bfbe58c..11824de 100644
--- a/modes/dungeongeneration.gbasm
+++ b/modes/dungeongeneration.gbasm
@@ -14,6 +14,15 @@
LD $reg_interrupt_enable, A
.END
+.MACRODEF ENABLE_MUSIC_INTERRUPT
+ LD A, low(=Dungeon_1st_step_VBlank)
+ LD ($mem_vblank_jump_destination), A
+ LD A, high(=Dungeon_1st_step_VBlank)
+ LD ($mem_vblank_jump_destination+1), A
+ .RESET_INTERRUPTS
+ .ENABLE_VBLANK_INTERRUPTS
+.END
+
.MACRODEF DISABLE_MODE_2_INTERRUPT
LD A, $00
LD $reg_lcd_status, A
@@ -40,6 +49,8 @@ New_Dungeon:
New_Floor:
LD SP, $fffe
+ .ENABLE_MUSIC_INTERRUPT
+ EI
LD A, $00
LD $mem_display_flag, A
@@ -209,15 +220,12 @@ Dungeon_generation_VBlank:
LD A, $mem_floor_count
CALL =Print_8bit
- CALL =Update_VBlank_Handler
+ CALL =Reset_Entities_Collision_Map
DI
.DISABLE_MODE_2_INTERRUPT
-
- CALL =Reset_Entities_Collision_Map
-
+ CALL =Update_VBlank_Handler
.ENABLE_VBLANK_INTERRUPTS
- .RESET_INTERRUPTS
EI
.Wait_for_Interrupt.loop:
@@ -227,8 +235,37 @@ Dungeon_generation_VBlank:
Dungeon_generation_Out_Of_VBlank:
PUSH AF
+ PUSH BC
+ PUSH DE
+ PUSH HL
+ LD A, $saved_rom_bank
+ PUSH AF
+ CALL =Play_Music
CALL =VBlank_Wait
.ENABLE_MODE_2_INTERRUPT
.RESET_INTERRUPTS
POP AF
+ .CHANGE_BANK_TO_A
+ POP HL
+ POP DE
+ POP BC
+ POP AF
+ RETI
+
+Dungeon_1st_step_VBlank:
+ PUSH AF
+ PUSH BC
+ PUSH DE
+ PUSH HL
+ LD A, $saved_rom_bank
+ PUSH AF
+ CALL =Play_Music
+ .ENABLE_VBLANK_INTERRUPTS
+ .RESET_INTERRUPTS
+ POP AF
+ .CHANGE_BANK_TO_A
+ POP HL
+ POP DE
+ POP BC
+ POP AF
RETI
diff --git a/modes/loading.gbasm b/modes/loading.gbasm
index df1bd24..649d474 100644
--- a/modes/loading.gbasm
+++ b/modes/loading.gbasm
@@ -32,5 +32,7 @@ Loading_VBLANK_Entrypoint:
INC A
LD $mem_loop_frame_timer, A
+ CALL =Play_Music
+
.ENABLE_VBLANK_INTERRUPTS
RETI
diff --git a/music/load.gbasm b/music/load.gbasm
new file mode 100644
index 0000000..400fa1d
--- /dev/null
+++ b/music/load.gbasm
@@ -0,0 +1,90 @@
+Load_Music:
+ .LOAD_BANK_OF =_music_Test
+
+ LD HL, ptr(=_music_Test+52)
+ LD A, L
+ ADD (HL)
+ LD L, A
+ LD A, H
+ ADC $00
+ LD H, A
+
+ LD A, bank(=_music_Test)
+ LD ($mem_current_vgm_pc), A
+ LD A, H
+ LD ($mem_current_vgm_pc+1), A
+ LD A, L
+ LD ($mem_current_vgm_pc+2), A
+ RET
+
+Inc_HL_Fix_Bank:
+ PUSH AF
+ INC HL
+ LD A, H
+ CP $80
+ JR C, =.end
+ SUB $40
+ LD H, A
+
+ LD A, $saved_rom_bank
+ INC A
+ DBG
+ .CHANGE_BANK_TO_A
+
+ .end:
+ POP AF
+ RET
+
+Play_Music:
+ LD A, ($mem_current_vgm_pc)
+ .CHANGE_BANK_TO_A
+ LD A, ($mem_current_vgm_pc+1)
+ LD H, A
+ LD A, ($mem_current_vgm_pc+2)
+ LD L, A
+
+ .next:
+ LD A, (HL)
+ DBG
+ CALL =Inc_HL_Fix_Bank
+ CP $b3
+ JR NZ, =.set_register.end
+ .set_register:
+ LD A, (HL)
+ CALL =Inc_HL_Fix_Bank
+ ADD $10
+ LD C, A
+ LD A, (HL)
+ CALL =Inc_HL_Fix_Bank
+ LD (C), A
+ JR =.next
+ .set_register.end:
+
+ CP $66
+ JR Z, =Load_Music
+
+
+ CP $62
+ JR Z, =.panic.end
+ CP $61
+ JR NZ, =.the61thingy.end
+ .the61thingy:
+ CALL =Inc_HL_Fix_Bank
+ CALL =Inc_HL_Fix_Bank
+ JR =.panic.end
+ .the61thingy.end:
+
+ .panic:
+ LD A, $saved_rom_bank
+ DBG
+ STOP
+ .panic.end:
+
+ LD A, H
+ LD ($mem_current_vgm_pc+1), A
+ LD A, L
+ LD ($mem_current_vgm_pc+2), A
+ LD A, $saved_rom_bank
+ DBG
+ LD ($mem_current_vgm_pc), A
+ RET
diff --git a/music/test.vgm b/music/test.vgm
new file mode 100644
index 0000000..9922409
--- /dev/null
+++ b/music/test.vgm
Binary files differ