From d8b012a749ce2aab83a35262a43396dda1dc12bf Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Wed, 16 Dec 2020 13:31:23 -0500 Subject: [PATCH] duke: hook up more sound effects --- duke/Makefile | 2 +- duke/actions.s | 2 ++ duke/duke.s | 1 + duke/move_duke.s | 4 +++ duke/sound_effects.s | 77 ++++++++++++++++++++++++++++++++++++++++++-- duke/speaker_tone.s | 67 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 150 insertions(+), 3 deletions(-) create mode 100644 duke/speaker_tone.s diff --git a/duke/Makefile b/duke/Makefile index a072de2b..7d43f010 100644 --- a/duke/Makefile +++ b/duke/Makefile @@ -48,7 +48,7 @@ duke.o: duke.s zp.inc hardware.inc duke.s \ maps/level1_map.lzsa \ status_bar.s draw_duke.s move_duke.s gr_putsprite_crop.s \ draw_tilemap.s \ - sound_effects.s \ + sound_effects.s speaker_tone.s \ keyboard.s handle_laser.s ca65 -o duke.o duke.s -l duke.lst diff --git a/duke/actions.s b/duke/actions.s index 9e3bd21b..90b02099 100644 --- a/duke/actions.s +++ b/duke/actions.s @@ -83,6 +83,8 @@ not_red_tile: jsr copy_tilemap_subset + jsr rumble_noise + jmp done_up_action diff --git a/duke/duke.s b/duke/duke.s index 3def8274..39f2eb09 100644 --- a/duke/duke.s +++ b/duke/duke.s @@ -228,6 +228,7 @@ done_with_duke: .include "actions.s" .include "sound_effects.s" + .include "speaker_tone.s" level1_data_lzsa: .incbin "maps/level1_map.lzsa" diff --git a/duke/move_duke.s b/duke/move_duke.s index 4da6a378..bbae6f3e 100644 --- a/duke/move_duke.s +++ b/duke/move_duke.s @@ -129,6 +129,8 @@ duke_collide: lda #1 sta DUKE_FALLING + jsr head_noise + collide_left_right: ;=================== ; collide left/right @@ -327,6 +329,8 @@ feet_on_ground: lda #0 sta DUKE_WALKING + jsr land_noise + was_not_falling: ; check to see if Y still hi, if so scroll back down diff --git a/duke/sound_effects.s b/duke/sound_effects.s index f9bdbb74..e592089f 100644 --- a/duke/sound_effects.s +++ b/duke/sound_effects.s @@ -1,5 +1,5 @@ - - + ;====================== + ; noise when jump jump_noise: lda SOUND_STATUS @@ -9,3 +9,76 @@ jump_noise: done_jump_noise: rts + + + ;====================== + ; noise when bump head +head_noise: + + lda SOUND_STATUS + bmi done_head_noise + + bit $C030 + bit $C030 + +done_head_noise: + rts + + + ;====================== + ; noise when land after jump +land_noise: + + lda SOUND_STATUS + bmi done_land_noise + + bit $C030 + +done_land_noise: + rts + + + ;====================== + ; rumble noise +rumble_noise: + + lda SOUND_STATUS + bmi done_rumble_noise + + ldx #50 +rumble_red: + bit $C030 + lda #100 + jsr WAIT + dex + bne rumble_red + +done_rumble_noise: + rts + + + ;====================== + ; pickup noise + ; C, two octaves+C? +pickup_noise: + + lda SOUND_STATUS + bmi done_pickup_noise + + lda #NOTE_C3 + sta speaker_frequency + lda #25 + sta speaker_duration + jsr speaker_tone + + lda #NOTE_C5 + sta speaker_frequency + lda #20 + sta speaker_duration + jsr speaker_tone + +done_pickup_noise: + rts + + + diff --git a/duke/speaker_tone.s b/duke/speaker_tone.s new file mode 100644 index 00000000..069cf498 --- /dev/null +++ b/duke/speaker_tone.s @@ -0,0 +1,67 @@ +; based on code from here +; http://eightbitsoundandfury.ld8.org/programming.html + +; A,X,Y trashed +; duration also trashed + +NOTE_C3 = 255 +NOTE_CSHARP3 = 241 +NOTE_D3 = 227 +NOTE_DSHARP3 = 214 +NOTE_E3 = 202 +NOTE_F3 = 191 +NOTE_FSHARP3 = 180 +NOTE_G3 = 170 +NOTE_GSHARP3 = 161 +NOTE_A3 = 152 +NOTE_ASHARP3 = 143 +NOTE_B3 = 135 + +NOTE_C4 = 128 +NOTE_CSHARP4 = 121 +NOTE_D4 = 114 +NOTE_DSHARP4 = 108 +NOTE_E4 = 102 +NOTE_F4 = 96 +NOTE_FSHARP4 = 91 +NOTE_G4 = 85 +NOTE_GSHARP4 = 81 +NOTE_A4 = 76 +NOTE_ASHARP4 = 72 +NOTE_B4 = 68 + +NOTE_C5 = 64 +NOTE_CSHARP5 = 60 +NOTE_D5 = 57 +NOTE_DSHARP5 = 54 +NOTE_E5 = 51 +NOTE_F5 = 48 +NOTE_FSHARP5 = 45 +NOTE_G5 = 43 +NOTE_GSHARP5 = 40 +NOTE_A5 = 38 +NOTE_ASHARP5 = 36 +NOTE_B5 = 34 + + + +speaker_tone: + lda $C030 ; click speaker +speaker_loop: + dey ; y never set? + bne slabel1 ; duration roughly 256*? + dec speaker_duration ; (Duration) + beq done_tone +slabel1: + dex + bne speaker_loop + ldx speaker_frequency ; (Frequency) + jmp speaker_tone +done_tone: + rts + +speaker_duration: + .byte $00 +speaker_frequency: + .byte $00 +