Skip to content

Commit 422b97c

Browse files
committed
Added better sound
1 parent 0d6c1f5 commit 422b97c

File tree

1 file changed

+98
-112
lines changed

1 file changed

+98
-112
lines changed

main.asm

+98-112
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,12 @@ ColourCycle ds 1 ; used for pause screen
8989
; these point to memory locations that are to be played when music is on
9090
; music should be input in reverse order because of the way the counter works!
9191
SoundEnabled ds 1 ; set to how many frames are to be played
92+
SoundEnabled2 ds 1
9293
SoundTrackPtr ds 2 ; points to sound to be played
93-
SoundVolumePtr ds 1 ; points to volume for the track
94+
SoundTrackPtr2 ds 2 ; points to sound to be played
9495
SoundSpeed ds 1 ; speed of sound
95-
96-
NoiseEnabled ds 1 ; set to amount of frames to play noise
97-
NoiseTrackPtr ds 2 ; points to noise to be played
98-
NoiseVolumePtr ds 1 ; points to volume for the track
99-
NoiseSpeed ds 1 ; speed of noise
96+
SoundControl ds 2 ; sound control
97+
SoundControl2 ds 2 ; sound control
10098

10199
; used by Random for an 8 bit random number
102100
Rand8 ds 1
@@ -121,13 +119,11 @@ MAPCOUNT = 4
121119
OFFSETPERMAP = 6
122120

123121
; music volumes
124-
LEVELCLEARVOLUME = $09
125-
FOODCOLLECTEDVOLUME = $09
126-
BIRDHITPLAYERVOLUME = $09
127122

128123
; music speed
129-
S_HALFSPEED = $1 ; and fore very other frame
130-
S_QUARTERSPEED = %11111 ; and for every 4th frame
124+
;S_FULLSPEED = 0 ; no delay at all
125+
;S_HALFSPEED = $1 ; and fore very other frame
126+
;S_QUARTERSPEED = %11111 ; and for every 4th frame
131127

132128
;===============================================================================
133129
; Define Start of Cartridge
@@ -247,7 +243,9 @@ VerticalBlank
247243
jsr SetObjectColours
248244

249245
jsr PrepScoreForDisplay
250-
jsr NoiseHandle
246+
ldx #0 ; channel 1
247+
jsr SoundHandle
248+
ldx #1 ; channel 2
251249
jsr SoundHandle
252250
rts
253251

@@ -623,8 +621,8 @@ leftRightBirdMoveDone
623621

624622
GameProgress
625623
; first we check if required maps for next level have been reached
626-
ldx Level
627-
inx ; maps for level are always Level+1
624+
ldx Level ; maps for level are always Level
625+
;inx ; maps for level are always Level+1
628626
cpx MapsCleared ; if it is the same next level
629627
beq NextLevelProg
630628
ldx Score
@@ -792,122 +790,120 @@ CollisionDone
792790
sta CXCLR ; clear collision
793791
rts
794792

795-
NoiseHandle
796-
ldx NoiseEnabled
797-
cpx #0 ; if it is 0, clear song and return
798-
beq ClearNoiseSet
799-
jsr Noise ; else we call sound
800-
rts
801-
ClearNoiseSet
802-
jsr ClearNoise
803-
rts
804-
805793
; Plays the Intro noise
806794
SoundHandle
807-
ldx SoundEnabled
808-
cpx #0 ; if it is 0, clear song and return
795+
ldy SoundEnabled,x
796+
cpy #0 ; if it is 0, clear song and return
809797
beq ClearSongSet
810798
jsr Sound ; else we call sound
811799
rts
812800
ClearSongSet
813801
jsr ClearSong
814802
rts
815803

816-
Noise
817-
ldy SoundEnabled
818-
sty AUDC1
819-
lda (NoiseTrackPtr),y
820-
sta AUDF1
821-
822-
lda NoiseVolumePtr
823-
sta AUDV1
824-
825-
; dec every 2nd frame
826-
lda Framecount
827-
and NoiseSpeed
828-
beq DoNotDecNoise
829-
dec NoiseEnabled
830-
DoNotDecNoise
831-
rts
832-
833804
Sound
834-
ldy SoundEnabled
835-
sty AUDC0
805+
ldy SoundEnabled,x
806+
cpx #0
807+
bne LoadTrackPtr2
836808
lda (SoundTrackPtr),y
837-
sta AUDF0
809+
sta AUDF0,x
838810

839-
lda SoundVolumePtr
840-
sta AUDV0
811+
812+
lda (SoundControl),y ; get the combined Control and Volume value
813+
jmp TrackPtrLoaded
814+
LoadTrackPtr2
815+
lda (SoundTrackPtr2),y
816+
sta AUDF0,x
817+
lda (SoundControl2),y
818+
TrackPtrLoaded
819+
820+
sta AUDV0,x ; update the Volume register
821+
lsr
822+
lsr
823+
lsr
824+
lsr ; the lower nibble is control
825+
sta AUDC0,x
841826

842827
; dec every 2nd frame
843-
lda Framecount
844-
and SoundSpeed
845-
beq DoNotDecSound
846-
dec SoundEnabled
828+
;lda Framecount
829+
;and SoundSpeed
830+
;beq DoNotDecSound
831+
dec SoundEnabled,x
847832
DoNotDecSound
848833
rts
849834

850835
ClearSong
851836
; song done, now we quit
852837
lda #0
853-
sta AUDC0
854-
sta AUDF0
855-
sta AUDV0
856-
rts
857-
858-
ClearNoise
859-
lda #0
860-
sta AUDC1
861-
sta AUDF1
862-
sta AUDV1
838+
sta AUDC0,x
839+
sta AUDF0,x
840+
sta AUDV0,x
863841
rts
864842

865843
PlayBirdHitPlayerSong
866-
lda BirdHitPlayerTrack
844+
lda #<(BirdHitPlayerTrack)
867845
sta SoundTrackPtr
868-
lda BirdHitPlayerTrack+1
846+
lda #>(BirdHitPlayerTrack)
869847
sta SoundTrackPtr+1
870848

871-
lda #BIRDHITPLAYERVOLUME
872-
sta SoundVolumePtr
849+
;lda #BIRDHITPLAYERVOLUME
850+
;sta SoundVolumePtr
873851

874852
lda #BIRDHITPLAYERTRACKSIZE ; 4 frames long
875853
sta SoundEnabled
876854

877-
lda #S_HALFSPEED
878-
sta SoundSpeed
855+
lda #<(BirdHitPlayerControl)
856+
sta SoundControl
857+
858+
lda #>(BirdHitPlayerControl)
859+
sta SoundControl+1
860+
861+
;lda #S_FULLSPEED
862+
;sta SoundSpeed
879863
rts
880864

881865
PlayFoodCollectedSong
882-
lda FoodCollectedTrack
866+
lda #<(FoodCollectedTrack)
883867
sta SoundTrackPtr
884-
lda FoodCollectedTrack+1
868+
lda #>(FoodCollectedTrack)
885869
sta SoundTrackPtr+1
886870

887-
lda #FOODCOLLECTEDVOLUME
888-
sta SoundVolumePtr
871+
;lda #FOODCOLLECTEDVOLUME
872+
;sta SoundVolumePtr
889873

890874
lda #FOODCOLLECTEDTRACKSIZE ; 4 frames long
891875
sta SoundEnabled
892876

893-
lda #S_HALFSPEED
894-
sta SoundSpeed
877+
lda #<(FoodCollectedControl)
878+
sta SoundControl
879+
880+
lda #>(FoodCollectedControl)
881+
sta SoundControl+1
882+
883+
;lda #S_HALFSPEED
884+
;sta SoundSpeed
895885
rts
896886

897887
PlayLevelClearSong
898-
lda LevelClearTrack
888+
lda #<(LevelClearTrack)
899889
sta SoundTrackPtr
900-
lda LevelClearTrack+1
890+
lda #>(LevelClearTrack)
901891
sta SoundTrackPtr+1
902892

903-
lda #LEVELCLEARVOLUME
904-
sta SoundVolumePtr
893+
;lda #LEVELCLEARVOLUME
894+
;sta SoundVolumePtr
905895

906896
lda #LEVELCLEARTRACKSIZE ; 4 frames long
907897
sta SoundEnabled
908898

909-
lda #S_HALFSPEED
910-
sta SoundSpeed
899+
lda #<(LevelClearControl)
900+
sta SoundControl
901+
902+
lda #>(LevelClearControl)
903+
sta SoundControl+1
904+
905+
;lda #S_HALFSPEED
906+
;sta SoundSpeed
911907
rts
912908

913909
SetM0Pos
@@ -1295,6 +1291,9 @@ noeor
12951291
sta Rand8
12961292
rts
12971293

1294+
; Free memory check
1295+
ECHO ([$FFFA-*]d), "bytes free before end data segment ($FFFA)"
1296+
12981297
#if SYSTEM = NTSC
12991298
Colours:
13001299
.byte $C6 ; green - goes into COLUP0, color for player1 and missile0
@@ -1826,43 +1825,30 @@ RoomTable:
18261825
ROOMTABLESIZE = * - RoomTable
18271826

18281827
; Sound tables
1828+
; frequencies in order
18291829
BirdHitPlayerTrack
1830-
.byte $D9
1831-
.byte $D8
1832-
.byte $D7
1833-
.byte $D6
1834-
.byte $D5
1835-
.byte $D4
1836-
.byte $D3
1837-
.byte $D2
1838-
.byte $D1
1839-
BIRDHITPLAYERTRACKSIZE = * - BirdHitPlayerTrack
1830+
.byte 0, 31, 29, 27, 25, 23, 21, 19, 17, 15, 13, 11
1831+
BIRDHITPLAYERTRACKSIZE = * - BirdHitPlayerTrack-1
1832+
1833+
; the control tables hold the control instrumnet in the first number and the volume in the 2nd
1834+
BirdHitPlayerControl
1835+
.byte 0, $8F, $8F, $8F, $8F, $8F, $8F, $8F, $8F, $8F, $8F, $8F
18401836

18411837
FoodCollectedTrack
1842-
.byte $78
1843-
.byte $79
1844-
.byte $7A
1845-
.byte $7B
1846-
.byte $7C
1847-
.byte $7D
1848-
FOODCOLLECTEDTRACKSIZE = * - FoodCollectedTrack
1838+
.byte 0, 26, 25, 24, 25, 26
1839+
FOODCOLLECTEDTRACKSIZE = * - FoodCollectedTrack-1
1840+
1841+
FoodCollectedControl
1842+
.byte 0, $1B, $1C, $4D, $4E, $4F
18491843

18501844
LevelClearTrack
1851-
.byte $0F
1852-
.byte $0F
1853-
.byte $0F
1854-
.byte $0F
1855-
.byte $0F
1856-
.byte $0F
1857-
.byte $0F
1858-
.byte $0F
1859-
.byte $0F
1860-
.byte $0F
1861-
.byte $0F
1862-
LEVELCLEARTRACKSIZE = * - LevelClearTrack
1863-
1864-
GameOverTrack
1865-
GAMEOVERTRACKSIZE = * - GameOverTrack
1845+
.byte 0, 21, 21, 22, 22, 23, 23, 20, 20, 21, 21, 22, 22, 19, 19, 20, 20, 21, 21
1846+
LEVELCLEARTRACKSIZE = * - LevelClearTrack-1
1847+
1848+
LevelClearControl
1849+
.byte 0, $4F, $4F, $4F, $4F, $4F, $4F, $4F, $4F, $4F, $4F
1850+
.byte $4F, $4F, $4F, $4F, $4F, $4F, $4F, $4F, $4F, $4F
1851+
18661852

18671853
; Free memory check
18681854
ECHO ([$FFFA-*]d), "bytes free before end of cart ($FFFA)"

0 commit comments

Comments
 (0)