;
;  gameSound.s
;  BuGS
;
;  Created by Jeremy Rand on 2020-12-16.
;Copyright © 2020 Jeremy Rand. All rights reserved.
;

        case on
        mcopy gameSound.macros
        keep gameSound

gameSound start
        using globalData
        using tileData
		using screenData


SOUND_REG_FREQ_LOW	equ $0000
SOUND_REG_FREQ_HIGH	equ $0020
SOUND_REG_VOLUME	equ $0040
SOUND_REG_POINTER	equ $0080
SOUND_REG_CONTROL	equ $00a0
SOUND_REG_SIZE		equ $00c0
		
SOUND_HALTED		equ 1
SOUND_STARTED		equ 0

SOUND_SWAP_MODE		equ 6
SOUND_ONE_SHOT_MODE	equ 2

; According to all of the documentation I can find, $00 should be the right speaker and
; $10 should be the left.  But based on GSPlus and mame, I see the opposite.  Still need
; to check on my HW.  But in the end, it could be that some HW demultiplexed them backwards
; so there could be either out there in the wild.
SOUND_RIGHT_SPEAKER	equ $10
SOUND_LEFT_SPEAKER	equ $00

; OSC 16 - 19 for L/R channels in swap mode
SPIDER_SOUND_ADDR	equ $0000
SPIDER_OSC_NUM		equ 16
SPIDER_FREQ_HIGH	equ 0
SPIDER_FREQ_LOW		equ 214
SPIDER_CONTROL		equ SOUND_SWAP_MODE
SPIDER_SIZE			equ $36

; OSC 10 & 11 for L/R channels
DEATH_SOUND_ADDR	equ $4000
DEATH_OSC_NUM		equ 10
DEATH_FREQ_HIGH		equ 0
DEATH_FREQ_LOW		equ 214
DEATH_CONTROL		equ SOUND_ONE_SHOT_MODE
DEATH_SIZE			equ $2d

; OSC 12 - 15 for L/R channels in swap mode
SEGMENTS_SOUND_ADDR	equ $7000
SEGMENTS_OSC_NUM	equ 12
SEGMENTS_FREQ_HIGH	equ 0
SEGMENTS_FREQ_LOW	equ 214
SEGMENTS_VOLUME		equ 128
SEGMENTS_CONTROL	equ SOUND_SWAP_MODE
SEGMENTS_SIZE		equ $24

; OSC 20 & 21 for L/R channels
EXTRA_LIFE_SOUND_ADDR	equ $8000
EXTRA_LIFE_OSC_NUM		equ 20
EXTRA_LIFE_FREQ_HIGH	equ 0
EXTRA_LIFE_FREQ_LOW		equ 107
EXTRA_LIFE_VOLUME		equ 128
EXTRA_LIFE_CONTROL		equ SOUND_ONE_SHOT_MODE
EXTRA_LIFE_SIZE		equ $36

; OSC 0 - 5 to have 3x L/R channels
BONUS_SOUND_ADDR	equ $b000
BONUS_OSC_NUM		equ 0
BONUS_FREQ_HIGH		equ 0
BONUS_FREQ_LOW		equ 214
BONUS_CONTROL		equ SOUND_ONE_SHOT_MODE
BONUS_SIZE			equ $24

; OSC 8 & 9 for L/R channels
KILL_SOUND_ADDR		equ $c000
KILL_OSC_NUM		equ 8
KILL_FREQ_HIGH		equ 0
KILL_FREQ_LOW		equ 214
KILL_CONTROL		equ SOUND_ONE_SHOT_MODE
KILL_SIZE			equ $24

; OSC 6 & 7 for L/R channels
FIRE_SOUND_ADDR 	equ $d000
FIRE_OSC_NUM		equ 6
FIRE_FREQ_HIGH		equ 0
FIRE_FREQ_LOW		equ 214
FIRE_CONTROL		equ SOUND_ONE_SHOT_MODE
FIRE_SIZE			equ $1b

; OSC 22 - 25 for L/R channels in swap mode
FLEA_SOUND_ADDR		equ $3a00
FLEA_OSC_NUM		equ 22
FLEA_CONTROL		equ SOUND_SWAP_MODE
FLEA_SIZE			equ $00

; OSC 26 - 30 for L/R channels in swap mode
SCORPION_SOUND_ADDR	equ $e000
SCORPION_OSC_NUM	equ 26
SCORPION_FREQ_HIGH	equ 0
SCORPION_FREQ_LOW	equ 214
SCORPION_CONTROL	equ SOUND_SWAP_MODE
SCORPION_SIZE		equ $2d
		
	
; Y has the register to write to (16 bit mode)
; A has the value to write (8 bit mode)
; Assuming not in increment mode
writeReg entry
		sta registerValue
writeReg_loop anop
		tya
		sta >SOUND_ADDR_LOW
		_docWait
		lda registerValue
		sta >SOUND_DATA_REG
		tya
		sta >SOUND_ADDR_LOW
		_docWait
		lda >SOUND_DATA_REG
		lda >SOUND_DATA_REG
		cmp registerValue
		bne writeReg_loop
		rts

		
; Y has the register to write to (16 bit mode)
; A has the value to write (8 bit mode)
; Assuming not in increment mode
writeRegNoRead entry
		sta registerValue
		tya
		sta >SOUND_ADDR_LOW
		_docWait
		lda registerValue
		sta >SOUND_DATA_REG
		rts

		
soundInit entry
; Spider sound
		pea SPIDER_SOUND_ADDR
		jsl loadSpiderSound
		
; Death sound
		pea DEATH_SOUND_ADDR
		jsl loadDeathSound
		
; Segments sound
		pea SEGMENTS_SOUND_ADDR
		jsl loadSegmentsSound
		
; Bonus sound
		pea BONUS_SOUND_ADDR
		jsl loadBonusSound
		
; Kill sound
		pea KILL_SOUND_ADDR
		jsl loadKillSound
		
; Fire sound
		pea FIRE_SOUND_ADDR
		jsl loadFireSound
		
; Extra life sound
		pea EXTRA_LIFE_SOUND_ADDR
		jsl loadExtraLifeSound
		
; Flea sound
		pea FLEA_SOUND_ADDR
		jsl loadFleaSound
		
; Scorpion sound
		pea SCORPION_SOUND_ADDR
		jsl loadScorpionSound
		
; Set registers
		short m
		_docWait
		lda >SOUND_SYSTEM_VOLUME
		and #$0f
		sta >SOUND_CONTROL_REG
		
		ldx #soundRegDefaults
soundInit_loop anop
		lda |$0,x
		tay
		lda |$1,x
		jsr writeRegNoRead
		inx
		inx
		cpx #soundRegDefaultsEnd
		blt soundInit_loop
		long m
		
		rtl


updateSounds entry
		lda gameState
		beq updateSounds_done
		lda fleaSoundIsPlaying
		bne updateSounds_done
		
updateSounds_changeFreq anop
		ldy fleaSoundFreqOffset
		iny
		iny
		cpy #NUM_FLEA_FREQS*2
		blt updateSounds_notDone
		jmp stopFleaSound
updateSounds_notDone anop
		sty fleaSoundFreqOffset
		
		short m
		lda >SOUND_SYSTEM_VOLUME
		and #$0f
		ora #$20
		sta >SOUND_CONTROL_REG
		
		lda #SOUND_REG_FREQ_LOW+FLEA_OSC_NUM
		sta >SOUND_ADDR_LOW
		lda fleaFreqs,y
		sta >SOUND_DATA_REG
		sta >SOUND_DATA_REG
		sta >SOUND_DATA_REG
		sta >SOUND_DATA_REG
		
		lda #SOUND_REG_FREQ_HIGH+FLEA_OSC_NUM
		sta >SOUND_ADDR_LOW
		lda fleaFreqs+1,y
		sta >SOUND_DATA_REG
		sta >SOUND_DATA_REG
		sta >SOUND_DATA_REG
		sta >SOUND_DATA_REG
		long m
		
updateSounds_done anop
		rtl


playBonusSound entry
		short m
		_docWait
		
		lda >SOUND_SYSTEM_VOLUME
		and #$0f
		sta >SOUND_CONTROL_REG
		
		_writeReg bonusSoundOscReg,#BONUS_CONTROL+SOUND_HALTED+SOUND_RIGHT_SPEAKER
		iny
		lda #BONUS_CONTROL+SOUND_HALTED+SOUND_LEFT_SPEAKER
		jsr writeReg
		
		lda bonusSoundOscReg
		and #$1f
		ora #SOUND_REG_VOLUME
		tay
		lda tileRightVolume,x
		jsr writeReg
		iny
		lda tileRightVolume,x
		eor #$ff
		jsr writeReg
		
		_writeReg bonusSoundOscReg,#BONUS_CONTROL+SOUND_RIGHT_SPEAKER
		iny
		lda #BONUS_CONTROL+SOUND_LEFT_SPEAKER
		jsr writeReg
		long m
		
		lda bonusSoundOscReg
		inc a
		inc a
		cmp #SOUND_REG_CONTROL+BONUS_OSC_NUM+6
		blt playBonusSound_noWrap
		lda #SOUND_REG_CONTROL+BONUS_OSC_NUM
playBonusSound_noWrap anop
		sta bonusSoundOscReg
		rtl


playDeathSound entry
		jsl stopSpiderSound
		jsl stopFleaSound
		jsl stopScorpionSound
		jsl stopSegmentSound
		
		lda mouseAddress
		sec
		sbc #SCREEN_ADDRESS
		and #$fffc
		tax
		lda >screenToTileOffset,x
		tax
		
		short m
		_docWait
		
		lda >SOUND_SYSTEM_VOLUME
		and #$0f
		sta >SOUND_CONTROL_REG
		
		_writeReg #SOUND_REG_CONTROL+DEATH_OSC_NUM,#DEATH_CONTROL+SOUND_HALTED+SOUND_RIGHT_SPEAKER
		_writeReg #SOUND_REG_CONTROL+DEATH_OSC_NUM+1,#DEATH_CONTROL+SOUND_HALTED+SOUND_LEFT_SPEAKER
		
		ldy #SOUND_REG_VOLUME+DEATH_OSC_NUM
		lda tileRightVolume,x
		jsr writeReg
		iny
		lda tileRightVolume,x
		eor #$ff
		jsr writeReg
		
		_writeReg #SOUND_REG_CONTROL+DEATH_OSC_NUM,#DEATH_CONTROL+SOUND_RIGHT_SPEAKER
		_writeReg #SOUND_REG_CONTROL+DEATH_OSC_NUM+1,#DEATH_CONTROL+SOUND_LEFT_SPEAKER
		long m
		
		rtl


playKillSound entry
		short m
		_docWait
		
		lda >SOUND_SYSTEM_VOLUME
		and #$0f
		sta >SOUND_CONTROL_REG
		
		_writeReg #SOUND_REG_CONTROL+KILL_OSC_NUM,#KILL_CONTROL+SOUND_HALTED+SOUND_RIGHT_SPEAKER
		_writeReg #SOUND_REG_CONTROL+KILL_OSC_NUM+1,#KILL_CONTROL+SOUND_HALTED+SOUND_LEFT_SPEAKER
		
		ldy #SOUND_REG_VOLUME+KILL_OSC_NUM
		lda tileRightVolume,x
		jsr writeReg
		iny
		lda tileRightVolume,x
		eor #$ff
		jsr writeReg
		
		_writeReg #SOUND_REG_CONTROL+KILL_OSC_NUM,#KILL_CONTROL+SOUND_RIGHT_SPEAKER
		_writeReg #SOUND_REG_CONTROL+KILL_OSC_NUM+1,#KILL_CONTROL+SOUND_LEFT_SPEAKER
		long m
		
		rtl


playFireSound entry
		short m
		_docWait
		
		lda >SOUND_SYSTEM_VOLUME
		and #$0f
		sta >SOUND_CONTROL_REG
		
		_writeReg #SOUND_REG_CONTROL+FIRE_OSC_NUM,#FIRE_CONTROL+SOUND_HALTED+SOUND_RIGHT_SPEAKER
		_writeReg #SOUND_REG_CONTROL+FIRE_OSC_NUM+1,#FIRE_CONTROL+SOUND_HALTED+SOUND_LEFT_SPEAKER
		
		ldy #SOUND_REG_VOLUME+FIRE_OSC_NUM
		lda tileRightVolume,x
		jsr writeReg
		iny
		lda tileRightVolume,x
		eor #$ff
		jsr writeReg
		
		_writeReg #SOUND_REG_CONTROL+FIRE_OSC_NUM,#FIRE_CONTROL+SOUND_RIGHT_SPEAKER
		_writeReg #SOUND_REG_CONTROL+FIRE_OSC_NUM+1,#FIRE_CONTROL+SOUND_LEFT_SPEAKER
		
		long m
		rtl
		

playExtraLifeSound entry
		short m
		_docWait
		
		lda >SOUND_SYSTEM_VOLUME
		and #$0f
		sta >SOUND_CONTROL_REG
		
		_writeReg #SOUND_REG_CONTROL+EXTRA_LIFE_OSC_NUM,#EXTRA_LIFE_CONTROL+SOUND_HALTED+SOUND_RIGHT_SPEAKER
		_writeReg #SOUND_REG_CONTROL+EXTRA_LIFE_OSC_NUM+1,#EXTRA_LIFE_CONTROL+SOUND_HALTED+SOUND_LEFT_SPEAKER
		
		_writeReg #SOUND_REG_CONTROL+EXTRA_LIFE_OSC_NUM,#EXTRA_LIFE_CONTROL+SOUND_RIGHT_SPEAKER
		_writeReg #SOUND_REG_CONTROL+EXTRA_LIFE_OSC_NUM+1,#EXTRA_LIFE_CONTROL+SOUND_LEFT_SPEAKER
		long m
		rtl

		
		
startSegmentSound entry
		lda segmentSoundIsPlaying
		bne startSegmentSound_doIt
		rtl
		
startSegmentSound_doIt anop
		stz segmentSoundIsPlaying
		
		short m
		_docWait
		
		lda >SOUND_SYSTEM_VOLUME
		and #$0f
		sta >SOUND_CONTROL_REG
		
		_writeReg #SOUND_REG_CONTROL+SEGMENTS_OSC_NUM,#SEGMENTS_CONTROL+SOUND_HALTED+SOUND_RIGHT_SPEAKER
		_writeReg #SOUND_REG_CONTROL+SEGMENTS_OSC_NUM+1,#SEGMENTS_CONTROL+SOUND_RIGHT_SPEAKER
		_writeReg #SOUND_REG_CONTROL+SEGMENTS_OSC_NUM+2,#SEGMENTS_CONTROL+SOUND_HALTED+SOUND_LEFT_SPEAKER
		_writeReg #SOUND_REG_CONTROL+SEGMENTS_OSC_NUM+3,#SEGMENTS_CONTROL+SOUND_LEFT_SPEAKER
		
		_writeReg #SOUND_REG_VOLUME+SEGMENTS_OSC_NUM,#SEGMENTS_VOLUME
		_writeReg #SOUND_REG_VOLUME+SEGMENTS_OSC_NUM+1,#SEGMENTS_VOLUME
		_writeReg #SOUND_REG_VOLUME+SEGMENTS_OSC_NUM+2,#SEGMENTS_VOLUME
		_writeReg #SOUND_REG_VOLUME+SEGMENTS_OSC_NUM+3,#SEGMENTS_VOLUME
		long m
		
		rtl
		
		
stopSegmentSound entry
		lda segmentSoundIsPlaying
		beq stopSegmentSound_doIt
		rtl
		
stopSegmentSound_doIt anop
		lda #1
		sta segmentSoundIsPlaying
		
		short m
		_docWait
		
		lda >SOUND_SYSTEM_VOLUME
		and #$0f
		sta >SOUND_CONTROL_REG
		
		_writeReg #SOUND_REG_VOLUME+SEGMENTS_OSC_NUM,#0
		_writeReg #SOUND_REG_VOLUME+SEGMENTS_OSC_NUM+1,#0
		_writeReg #SOUND_REG_VOLUME+SEGMENTS_OSC_NUM+2,#0
		_writeReg #SOUND_REG_VOLUME+SEGMENTS_OSC_NUM+3,#0
		
		_writeReg #SOUND_REG_CONTROL+SEGMENTS_OSC_NUM,#SOUND_ONE_SHOT_MODE+SOUND_RIGHT_SPEAKER
		_writeReg #SOUND_REG_CONTROL+SEGMENTS_OSC_NUM+1,#SOUND_ONE_SHOT_MODE+SOUND_RIGHT_SPEAKER
		_writeReg #SOUND_REG_CONTROL+SEGMENTS_OSC_NUM+2,#SOUND_ONE_SHOT_MODE+SOUND_LEFT_SPEAKER
		_writeReg #SOUND_REG_CONTROL+SEGMENTS_OSC_NUM+3,#SOUND_ONE_SHOT_MODE+SOUND_LEFT_SPEAKER
		
		_writeReg #SOUND_REG_CONTROL+SEGMENTS_OSC_NUM,#SOUND_ONE_SHOT_MODE+SOUND_HALTED+SOUND_RIGHT_SPEAKER
		_writeReg #SOUND_REG_CONTROL+SEGMENTS_OSC_NUM+1,#SOUND_ONE_SHOT_MODE+SOUND_HALTED+SOUND_RIGHT_SPEAKER
		_writeReg #SOUND_REG_CONTROL+SEGMENTS_OSC_NUM+2,#SOUND_ONE_SHOT_MODE+SOUND_HALTED+SOUND_LEFT_SPEAKER
		_writeReg #SOUND_REG_CONTROL+SEGMENTS_OSC_NUM+3,#SOUND_ONE_SHOT_MODE+SOUND_HALTED+SOUND_LEFT_SPEAKER
		long m
		
		rtl
		
		
startSpiderSound entry
		lda spiderSoundIsPlaying
		bne startSpiderSound_doIt
		rtl
		
startSpiderSound_doIt anop
		stz spiderSoundIsPlaying
		
		short m
		_docWait
		
		lda >SOUND_SYSTEM_VOLUME
		and #$0f
		sta >SOUND_CONTROL_REG
		
		_writeReg #SOUND_REG_CONTROL+SPIDER_OSC_NUM,#SPIDER_CONTROL+SOUND_HALTED+SOUND_RIGHT_SPEAKER
		_writeReg #SOUND_REG_CONTROL+SPIDER_OSC_NUM+1,#SPIDER_CONTROL+SOUND_RIGHT_SPEAKER
		_writeReg #SOUND_REG_CONTROL+SPIDER_OSC_NUM+2,#SPIDER_CONTROL+SOUND_HALTED+SOUND_LEFT_SPEAKER
		_writeReg #SOUND_REG_CONTROL+SPIDER_OSC_NUM+3,#SPIDER_CONTROL+SOUND_LEFT_SPEAKER
		
		ldy #SOUND_REG_VOLUME+SPIDER_OSC_NUM
		lda tileRightVolume,x
		jsr writeReg
		iny
		lda tileRightVolume,x
		jsr writeReg
		iny
		lda tileRightVolume,x
		eor #$ff
		jsr writeReg
		iny
		lda tileRightVolume,x
		eor #$ff
		jsr writeReg
		long m
		
		rtl

		
updateSpiderSound entry
		lda spiderSoundIsPlaying
		beq updateSpiderSound_doIt
		rtl

updateSpiderSound_doIt anop
		short m
		_docWait
		
		lda >SOUND_SYSTEM_VOLUME
		and #$0f
		sta >SOUND_CONTROL_REG
		
		ldy #SOUND_REG_VOLUME+SPIDER_OSC_NUM
		lda tileRightVolume,x
		jsr writeReg
		iny
		lda tileRightVolume,x
		jsr writeReg
		iny
		lda tileRightVolume,x
		eor #$ff
		jsr writeReg
		iny
		lda tileRightVolume,x
		eor #$ff
		jsr writeReg
		
		long m
		rtl
		

stopSpiderSound entry
		lda spiderSoundIsPlaying
		beq stopSpiderSound_doIt
		rtl
		
stopSpiderSound_doIt anop
		lda #1
		sta spiderSoundIsPlaying
		
		short m
		_docWait
		
		lda >SOUND_SYSTEM_VOLUME
		and #$0f
		sta >SOUND_CONTROL_REG
		
		_writeReg #SOUND_REG_VOLUME+SPIDER_OSC_NUM,#0
		_writeReg #SOUND_REG_VOLUME+SPIDER_OSC_NUM+1,#0
		_writeReg #SOUND_REG_VOLUME+SPIDER_OSC_NUM+2,#0
		_writeReg #SOUND_REG_VOLUME+SPIDER_OSC_NUM+3,#0
		
		
		_writeReg #SOUND_REG_CONTROL+SPIDER_OSC_NUM,#SOUND_ONE_SHOT_MODE+SOUND_RIGHT_SPEAKER
		_writeReg #SOUND_REG_CONTROL+SPIDER_OSC_NUM+1,#SOUND_ONE_SHOT_MODE+SOUND_RIGHT_SPEAKER
		_writeReg #SOUND_REG_CONTROL+SPIDER_OSC_NUM+2,#SOUND_ONE_SHOT_MODE+SOUND_LEFT_SPEAKER
		_writeReg #SOUND_REG_CONTROL+SPIDER_OSC_NUM+3,#SOUND_ONE_SHOT_MODE+SOUND_LEFT_SPEAKER
		
		_writeReg #SOUND_REG_CONTROL+SPIDER_OSC_NUM,#SOUND_ONE_SHOT_MODE+SOUND_HALTED+SOUND_RIGHT_SPEAKER
		_writeReg #SOUND_REG_CONTROL+SPIDER_OSC_NUM+1,#SOUND_ONE_SHOT_MODE+SOUND_HALTED+SOUND_RIGHT_SPEAKER
		_writeReg #SOUND_REG_CONTROL+SPIDER_OSC_NUM+2,#SOUND_ONE_SHOT_MODE+SOUND_HALTED+SOUND_LEFT_SPEAKER
		_writeReg #SOUND_REG_CONTROL+SPIDER_OSC_NUM+3,#SOUND_ONE_SHOT_MODE+SOUND_HALTED+SOUND_LEFT_SPEAKER
		long m
		
		rtl


startScorpionSound entry
		lda scorpionSoundIsPlaying
		bne startScorpionSound_doIt
		rtl
		
startScorpionSound_doIt anop
		stz scorpionSoundIsPlaying
		
		short m
		_docWait
		
		lda >SOUND_SYSTEM_VOLUME
		and #$0f
		sta >SOUND_CONTROL_REG
		
		_writeReg #SOUND_REG_CONTROL+SCORPION_OSC_NUM,#SCORPION_CONTROL+SOUND_HALTED+SOUND_RIGHT_SPEAKER
		_writeReg #SOUND_REG_CONTROL+SCORPION_OSC_NUM+1,#SCORPION_CONTROL+SOUND_RIGHT_SPEAKER
		_writeReg #SOUND_REG_CONTROL+SCORPION_OSC_NUM+2,#SCORPION_CONTROL+SOUND_HALTED+SOUND_LEFT_SPEAKER
		_writeReg #SOUND_REG_CONTROL+SCORPION_OSC_NUM+3,#SCORPION_CONTROL+SOUND_LEFT_SPEAKER
		
		ldy #SOUND_REG_VOLUME+SCORPION_OSC_NUM
		lda tileRightVolume,x
		jsr writeReg
		iny
		lda tileRightVolume,x
		jsr writeReg
		iny
		lda tileRightVolume,x
		eor #$ff
		jsr writeReg
		iny
		lda tileRightVolume,x
		eor #$ff
		jsr writeReg
		long m
		rtl
		
		
updateScorpionSound entry
		lda scorpionSoundIsPlaying
		beq updateScorpionSound_doIt
		rtl
		
updateScorpionSound_doIt anop
		short m
		_docWait
		lda >SOUND_SYSTEM_VOLUME
		and #$0f
		sta >SOUND_CONTROL_REG

		ldy #SOUND_REG_VOLUME+SCORPION_OSC_NUM
		lda tileRightVolume,x
		jsr writeReg
		iny
		lda tileRightVolume,x
		jsr writeReg
		iny
		lda tileRightVolume,x
		eor #$ff
		jsr writeReg
		iny
		lda tileRightVolume,x
		eor #$ff
		jsr writeReg
		long m
		
		rtl
		

stopScorpionSound entry
		lda scorpionSoundIsPlaying
		beq stopScorpionSound_doIt
		rtl
		
stopScorpionSound_doIt anop
		lda #1
		sta scorpionSoundIsPlaying
		
		short m
		_docWait
		lda >SOUND_SYSTEM_VOLUME
		and #$0f
		sta >SOUND_CONTROL_REG
		
		_writeReg #SOUND_REG_VOLUME+SCORPION_OSC_NUM,#0
		_writeReg #SOUND_REG_VOLUME+SCORPION_OSC_NUM+1,#0
		_writeReg #SOUND_REG_VOLUME+SCORPION_OSC_NUM+1,#0
		_writeReg #SOUND_REG_VOLUME+SCORPION_OSC_NUM+1,#0
		
		_writeReg #SOUND_REG_CONTROL+SCORPION_OSC_NUM,#SOUND_ONE_SHOT_MODE+SOUND_RIGHT_SPEAKER
		_writeReg #SOUND_REG_CONTROL+SCORPION_OSC_NUM+1,#SOUND_ONE_SHOT_MODE+SOUND_RIGHT_SPEAKER
		_writeReg #SOUND_REG_CONTROL+SCORPION_OSC_NUM+2,#SOUND_ONE_SHOT_MODE+SOUND_LEFT_SPEAKER
		_writeReg #SOUND_REG_CONTROL+SCORPION_OSC_NUM+3,#SOUND_ONE_SHOT_MODE+SOUND_LEFT_SPEAKER
		
		_writeReg #SOUND_REG_CONTROL+SCORPION_OSC_NUM,#SOUND_ONE_SHOT_MODE+SOUND_HALTED+SOUND_RIGHT_SPEAKER
		_writeReg #SOUND_REG_CONTROL+SCORPION_OSC_NUM+1,#SOUND_ONE_SHOT_MODE+SOUND_HALTED+SOUND_RIGHT_SPEAKER
		_writeReg #SOUND_REG_CONTROL+SCORPION_OSC_NUM+2,#SOUND_ONE_SHOT_MODE+SOUND_HALTED+SOUND_LEFT_SPEAKER
		_writeReg #SOUND_REG_CONTROL+SCORPION_OSC_NUM+3,#SOUND_ONE_SHOT_MODE+SOUND_HALTED+SOUND_LEFT_SPEAKER
		long m

		rtl


startFleaSound entry
		lda fleaSoundIsPlaying
		bne startFleaSound_doIt
		rtl
		
startFleaSound_doIt anop
		stz fleaSoundIsPlaying
		stz fleaSoundFreqOffset
		
		short m
		_docWait
		lda >SOUND_SYSTEM_VOLUME
		and #$0f
		sta >SOUND_CONTROL_REG
		
		_writeReg #SOUND_REG_FREQ_LOW+FLEA_OSC_NUM,fleaFreqs
		_writeReg #SOUND_REG_FREQ_LOW+FLEA_OSC_NUM+1,fleaFreqs
		_writeReg #SOUND_REG_FREQ_LOW+FLEA_OSC_NUM+2,fleaFreqs
		_writeReg #SOUND_REG_FREQ_LOW+FLEA_OSC_NUM+3,fleaFreqs
		
		_writeReg #SOUND_REG_FREQ_HIGH+FLEA_OSC_NUM,fleaFreqs+1
		_writeReg #SOUND_REG_FREQ_HIGH+FLEA_OSC_NUM+1,fleaFreqs+1
		_writeReg #SOUND_REG_FREQ_HIGH+FLEA_OSC_NUM+2,fleaFreqs+1
		_writeReg #SOUND_REG_FREQ_HIGH+FLEA_OSC_NUM+3,fleaFreqs+1
		
		_writeReg #SOUND_REG_CONTROL+FLEA_OSC_NUM,#FLEA_CONTROL+SOUND_HALTED+SOUND_RIGHT_SPEAKER
		_writeReg #SOUND_REG_CONTROL+FLEA_OSC_NUM+1,#FLEA_CONTROL+SOUND_RIGHT_SPEAKER
		_writeReg #SOUND_REG_CONTROL+FLEA_OSC_NUM+2,#FLEA_CONTROL+SOUND_HALTED+SOUND_LEFT_SPEAKER
		_writeReg #SOUND_REG_CONTROL+FLEA_OSC_NUM+3,#FLEA_CONTROL+SOUND_LEFT_SPEAKER
		
		ldy #SOUND_REG_VOLUME+FLEA_OSC_NUM
		lda tileRightVolume,x
		sta fleaVolume
		jsr writeReg
		iny
		lda fleaVolume
		jsr writeReg
		iny
		lda fleaVolume
		eor #$ff
		jsr writeReg
		iny
		lda fleaVolume
		eor #$ff
		jsr writeReg
		long m
		rtl


stopFleaSound entry
		lda fleaSoundIsPlaying
		beq stopFleaSound_doIt
		rtl
		
stopFleaSound_doIt anop
		lda #1
		sta fleaSoundIsPlaying
		
		short m
		_docWait
		lda >SOUND_SYSTEM_VOLUME
		and #$0f
		sta >SOUND_CONTROL_REG
		
		_writeReg #SOUND_REG_VOLUME+FLEA_OSC_NUM,#$0
		_writeReg #SOUND_REG_VOLUME+FLEA_OSC_NUM+1,#$0
		_writeReg #SOUND_REG_VOLUME+FLEA_OSC_NUM+2,#$0
		_writeReg #SOUND_REG_VOLUME+FLEA_OSC_NUM+3,#$0
		
		_writeReg #SOUND_REG_CONTROL+FLEA_OSC_NUM,#SOUND_ONE_SHOT_MODE+SOUND_RIGHT_SPEAKER
		_writeReg #SOUND_REG_CONTROL+FLEA_OSC_NUM+1,#SOUND_ONE_SHOT_MODE+SOUND_RIGHT_SPEAKER
		_writeReg #SOUND_REG_CONTROL+FLEA_OSC_NUM+2,#SOUND_ONE_SHOT_MODE+SOUND_LEFT_SPEAKER
		_writeReg #SOUND_REG_CONTROL+FLEA_OSC_NUM+3,#SOUND_ONE_SHOT_MODE+SOUND_LEFT_SPEAKER
		
		_writeReg #SOUND_REG_CONTROL+FLEA_OSC_NUM,#SOUND_ONE_SHOT_MODE+SOUND_RIGHT_SPEAKER+SOUND_HALTED
		_writeReg #SOUND_REG_CONTROL+FLEA_OSC_NUM+1,#SOUND_ONE_SHOT_MODE+SOUND_RIGHT_SPEAKER+SOUND_HALTED
		_writeReg #SOUND_REG_CONTROL+FLEA_OSC_NUM+2,#SOUND_ONE_SHOT_MODE+SOUND_LEFT_SPEAKER+SOUND_HALTED
		_writeReg #SOUND_REG_CONTROL+FLEA_OSC_NUM+3,#SOUND_ONE_SHOT_MODE+SOUND_LEFT_SPEAKER+SOUND_HALTED
		long m
		rtl

		
pauseSound entry
		short m
		_docWait
		lda >SOUND_SYSTEM_VOLUME
		and #$0f
		sta >SOUND_CONTROL_REG
		
		_writeReg #SOUND_REG_VOLUME+SEGMENTS_OSC_NUM,#0
		_writeReg #SOUND_REG_VOLUME+SEGMENTS_OSC_NUM+1,#0
		_writeReg #SOUND_REG_VOLUME+SEGMENTS_OSC_NUM+2,#0
		_writeReg #SOUND_REG_VOLUME+SEGMENTS_OSC_NUM+3,#0

		_writeReg #SOUND_REG_VOLUME+SPIDER_OSC_NUM,#$0
		_writeReg #SOUND_REG_VOLUME+SPIDER_OSC_NUM+1,#$0
		_writeReg #SOUND_REG_VOLUME+SPIDER_OSC_NUM+2,#$0
		_writeReg #SOUND_REG_VOLUME+SPIDER_OSC_NUM+3,#$0
		
		_writeReg #SOUND_REG_VOLUME+SCORPION_OSC_NUM,#0
		_writeReg #SOUND_REG_VOLUME+SCORPION_OSC_NUM+1,#0
		_writeReg #SOUND_REG_VOLUME+SCORPION_OSC_NUM+2,#0
		_writeReg #SOUND_REG_VOLUME+SCORPION_OSC_NUM+3,#0
		
		_writeReg #SOUND_REG_VOLUME+FLEA_OSC_NUM,#$0
		_writeReg #SOUND_REG_VOLUME+FLEA_OSC_NUM+1,#$0
		_writeReg #SOUND_REG_VOLUME+FLEA_OSC_NUM+2,#$0
		_writeReg #SOUND_REG_VOLUME+FLEA_OSC_NUM+3,#$0
		
		long m
		rtl
		
		
unpauseSound entry
		lda segmentSoundIsPlaying
		bne unpauseSound_skipSegment
		
		short m
		_docWait
		lda >SOUND_SYSTEM_VOLUME
		and #$0f
		sta >SOUND_CONTROL_REG
		
		_writeReg #SOUND_REG_VOLUME+SEGMENTS_OSC_NUM,#SEGMENTS_VOLUME
		_writeReg #SOUND_REG_VOLUME+SEGMENTS_OSC_NUM+1,#SEGMENTS_VOLUME
		_writeReg #SOUND_REG_VOLUME+SEGMENTS_OSC_NUM+2,#SEGMENTS_VOLUME
		_writeReg #SOUND_REG_VOLUME+SEGMENTS_OSC_NUM+3,#SEGMENTS_VOLUME
		long m
		
unpauseSound_skipSegment anop
		lda fleaSoundIsPlaying
		bne unpauseSound_skipFlea
		
		short m
		_docWait
		lda >SOUND_SYSTEM_VOLUME
		and #$0f
		sta >SOUND_CONTROL_REG
		
		ldy #SOUND_REG_VOLUME+FLEA_OSC_NUM
		lda fleaVolume
		jsr writeReg
		iny
		lda fleaVolume
		jsr writeReg
		iny
		lda fleaVolume
		eor #$ff
		jsr writeReg
		iny
		lda fleaVolume
		eor #$ff
		jsr writeReg
		long m
		
unpauseSound_skipFlea anop
		rtl
		
		
swapStereoChannels entry
		ldx #SIZEOF_TILE_INFO*NUM_GAME_TILES-SIZEOF_TILE_INFO
swapStereoChannels_loop anop
		lda tileRightVolume,x
		eor #$ff
		sta tileRightVolume,x
		dex
		dex
		bpl swapStereoChannels_loop

		rtl
		

bonusSoundOscReg	dc i2'SOUND_REG_CONTROL+BONUS_OSC_NUM'
fleaSoundIsPlaying		dc i2'1'
fleaSoundFreqOffset		dc i2'0'
fleaVolume			dc i2'0'
segmentSoundIsPlaying	dc i2'1'
spiderSoundIsPlaying	dc i2'1'
scorpionSoundIsPlaying	dc i2'1'
registerValue		dc i2'0'

soundRegDefaults	anop
; Spider registers
		dc i1'SOUND_REG_FREQ_LOW+SPIDER_OSC_NUM',i1'SPIDER_FREQ_LOW'
		dc i1'SOUND_REG_FREQ_LOW+SPIDER_OSC_NUM+1',i1'SPIDER_FREQ_LOW'
		dc i1'SOUND_REG_FREQ_LOW+SPIDER_OSC_NUM+2',i1'SPIDER_FREQ_LOW'
		dc i1'SOUND_REG_FREQ_LOW+SPIDER_OSC_NUM+3',i1'SPIDER_FREQ_LOW'
		dc i1'SOUND_REG_FREQ_HIGH+SPIDER_OSC_NUM',i1'SPIDER_FREQ_HIGH'
		dc i1'SOUND_REG_FREQ_HIGH+SPIDER_OSC_NUM+1',i1'SPIDER_FREQ_HIGH'
		dc i1'SOUND_REG_FREQ_HIGH+SPIDER_OSC_NUM+2',i1'SPIDER_FREQ_HIGH'
		dc i1'SOUND_REG_FREQ_HIGH+SPIDER_OSC_NUM+3',i1'SPIDER_FREQ_HIGH'
		dc i1'SOUND_REG_VOLUME+SPIDER_OSC_NUM',i1'0'
		dc i1'SOUND_REG_VOLUME+SPIDER_OSC_NUM+1',i1'0'
		dc i1'SOUND_REG_VOLUME+SPIDER_OSC_NUM+2',i1'0'
		dc i1'SOUND_REG_VOLUME+SPIDER_OSC_NUM+3',i1'0'
		dc i1'SOUND_REG_SIZE+SPIDER_OSC_NUM',i1'SPIDER_SIZE'
		dc i1'SOUND_REG_SIZE+SPIDER_OSC_NUM+1',i1'SPIDER_SIZE'
		dc i1'SOUND_REG_SIZE+SPIDER_OSC_NUM+2',i1'SPIDER_SIZE'
		dc i1'SOUND_REG_SIZE+SPIDER_OSC_NUM+3',i1'SPIDER_SIZE'
		dc i1'SOUND_REG_POINTER+SPIDER_OSC_NUM',i1'SPIDER_SOUND_ADDR/256'
		dc i1'SOUND_REG_POINTER+SPIDER_OSC_NUM+1',i1'SPIDER_SOUND_ADDR/256'
		dc i1'SOUND_REG_POINTER+SPIDER_OSC_NUM+2',i1'SPIDER_SOUND_ADDR/256'
		dc i1'SOUND_REG_POINTER+SPIDER_OSC_NUM+3',i1'SPIDER_SOUND_ADDR/256'
		dc i1'SOUND_REG_CONTROL+SPIDER_OSC_NUM',i1'SOUND_ONE_SHOT_MODE+SOUND_HALTED+SOUND_RIGHT_SPEAKER'
		dc i1'SOUND_REG_CONTROL+SPIDER_OSC_NUM+1',i1'SOUND_ONE_SHOT_MODE+SOUND_HALTED+SOUND_RIGHT_SPEAKER'
		dc i1'SOUND_REG_CONTROL+SPIDER_OSC_NUM+2',i1'SOUND_ONE_SHOT_MODE+SOUND_HALTED+SOUND_LEFT_SPEAKER'
		dc i1'SOUND_REG_CONTROL+SPIDER_OSC_NUM+3',i1'SOUND_ONE_SHOT_MODE+SOUND_HALTED+SOUND_LEFT_SPEAKER'
		
; Death registers
		dc i1'SOUND_REG_FREQ_LOW+DEATH_OSC_NUM',i1'DEATH_FREQ_LOW'
		dc i1'SOUND_REG_FREQ_LOW+DEATH_OSC_NUM+1',i1'DEATH_FREQ_LOW'
		dc i1'SOUND_REG_FREQ_HIGH+DEATH_OSC_NUM',i1'DEATH_FREQ_HIGH'
		dc i1'SOUND_REG_FREQ_HIGH+DEATH_OSC_NUM+1',i1'DEATH_FREQ_HIGH'
		dc i1'SOUND_REG_SIZE+DEATH_OSC_NUM',i1'DEATH_SIZE'
		dc i1'SOUND_REG_SIZE+DEATH_OSC_NUM+1',i1'DEATH_SIZE'
		dc i1'SOUND_REG_POINTER+DEATH_OSC_NUM',i1'DEATH_SOUND_ADDR/256'
		dc i1'SOUND_REG_POINTER+DEATH_OSC_NUM+1',i1'DEATH_SOUND_ADDR/256'
		dc i1'SOUND_REG_CONTROL+DEATH_OSC_NUM',i1'DEATH_CONTROL+SOUND_HALTED+SOUND_RIGHT_SPEAKER'
		dc i1'SOUND_REG_CONTROL+DEATH_OSC_NUM+1',i1'DEATH_CONTROL+SOUND_HALTED+SOUND_LEFT_SPEAKER'
		
; Segments registers
		dc i1'SOUND_REG_FREQ_LOW+SEGMENTS_OSC_NUM',i1'SEGMENTS_FREQ_LOW'
		dc i1'SOUND_REG_FREQ_LOW+SEGMENTS_OSC_NUM+1',i1'SEGMENTS_FREQ_LOW'
		dc i1'SOUND_REG_FREQ_LOW+SEGMENTS_OSC_NUM+2',i1'SEGMENTS_FREQ_LOW'
		dc i1'SOUND_REG_FREQ_LOW+SEGMENTS_OSC_NUM+3',i1'SEGMENTS_FREQ_LOW'
		dc i1'SOUND_REG_FREQ_HIGH+SEGMENTS_OSC_NUM',i1'SEGMENTS_FREQ_HIGH'
		dc i1'SOUND_REG_FREQ_HIGH+SEGMENTS_OSC_NUM+1',i1'SEGMENTS_FREQ_HIGH'
		dc i1'SOUND_REG_FREQ_HIGH+SEGMENTS_OSC_NUM+2',i1'SEGMENTS_FREQ_HIGH'
		dc i1'SOUND_REG_FREQ_HIGH+SEGMENTS_OSC_NUM+3',i1'SEGMENTS_FREQ_HIGH'
		dc i1'SOUND_REG_VOLUME+SEGMENTS_OSC_NUM',i1'0'
		dc i1'SOUND_REG_VOLUME+SEGMENTS_OSC_NUM+1',i1'0'
		dc i1'SOUND_REG_VOLUME+SEGMENTS_OSC_NUM+2',i1'0'
		dc i1'SOUND_REG_VOLUME+SEGMENTS_OSC_NUM+3',i1'0'
		dc i1'SOUND_REG_SIZE+SEGMENTS_OSC_NUM',i1'SEGMENTS_SIZE'
		dc i1'SOUND_REG_SIZE+SEGMENTS_OSC_NUM+1',i1'SEGMENTS_SIZE'
		dc i1'SOUND_REG_SIZE+SEGMENTS_OSC_NUM+2',i1'SEGMENTS_SIZE'
		dc i1'SOUND_REG_SIZE+SEGMENTS_OSC_NUM+3',i1'SEGMENTS_SIZE'
		dc i1'SOUND_REG_POINTER+SEGMENTS_OSC_NUM',i1'SEGMENTS_SOUND_ADDR/256'
		dc i1'SOUND_REG_POINTER+SEGMENTS_OSC_NUM+1',i1'SEGMENTS_SOUND_ADDR/256'
		dc i1'SOUND_REG_POINTER+SEGMENTS_OSC_NUM+2',i1'SEGMENTS_SOUND_ADDR/256'
		dc i1'SOUND_REG_POINTER+SEGMENTS_OSC_NUM+3',i1'SEGMENTS_SOUND_ADDR/256'
		dc i1'SOUND_REG_CONTROL+SEGMENTS_OSC_NUM',i1'SOUND_ONE_SHOT_MODE+SOUND_HALTED+SOUND_RIGHT_SPEAKER'
		dc i1'SOUND_REG_CONTROL+SEGMENTS_OSC_NUM+1',i1'SOUND_ONE_SHOT_MODE+SOUND_HALTED+SOUND_RIGHT_SPEAKER'
		dc i1'SOUND_REG_CONTROL+SEGMENTS_OSC_NUM+2',i1'SOUND_ONE_SHOT_MODE+SOUND_HALTED+SOUND_LEFT_SPEAKER'
		dc i1'SOUND_REG_CONTROL+SEGMENTS_OSC_NUM+3',i1'SOUND_ONE_SHOT_MODE+SOUND_HALTED+SOUND_LEFT_SPEAKER'
		
; Bonus registers
		dc i1'SOUND_REG_FREQ_LOW+BONUS_OSC_NUM',i1'BONUS_FREQ_LOW'
		dc i1'SOUND_REG_FREQ_LOW+BONUS_OSC_NUM+1',i1'BONUS_FREQ_LOW'
		dc i1'SOUND_REG_FREQ_LOW+BONUS_OSC_NUM+2',i1'BONUS_FREQ_LOW'
		dc i1'SOUND_REG_FREQ_LOW+BONUS_OSC_NUM+3',i1'BONUS_FREQ_LOW'
		dc i1'SOUND_REG_FREQ_LOW+BONUS_OSC_NUM+4',i1'BONUS_FREQ_LOW'
		dc i1'SOUND_REG_FREQ_LOW+BONUS_OSC_NUM+5',i1'BONUS_FREQ_LOW'
		dc i1'SOUND_REG_FREQ_HIGH+BONUS_OSC_NUM',i1'BONUS_FREQ_HIGH'
		dc i1'SOUND_REG_FREQ_HIGH+BONUS_OSC_NUM+1',i1'BONUS_FREQ_HIGH'
		dc i1'SOUND_REG_FREQ_HIGH+BONUS_OSC_NUM+2',i1'BONUS_FREQ_HIGH'
		dc i1'SOUND_REG_FREQ_HIGH+BONUS_OSC_NUM+3',i1'BONUS_FREQ_HIGH'
		dc i1'SOUND_REG_FREQ_HIGH+BONUS_OSC_NUM+4',i1'BONUS_FREQ_HIGH'
		dc i1'SOUND_REG_FREQ_HIGH+BONUS_OSC_NUM+5',i1'BONUS_FREQ_HIGH'
		dc i1'SOUND_REG_SIZE+BONUS_OSC_NUM',i1'BONUS_SIZE'
		dc i1'SOUND_REG_SIZE+BONUS_OSC_NUM+1',i1'BONUS_SIZE'
		dc i1'SOUND_REG_SIZE+BONUS_OSC_NUM+2',i1'BONUS_SIZE'
		dc i1'SOUND_REG_SIZE+BONUS_OSC_NUM+3',i1'BONUS_SIZE'
		dc i1'SOUND_REG_SIZE+BONUS_OSC_NUM+4',i1'BONUS_SIZE'
		dc i1'SOUND_REG_SIZE+BONUS_OSC_NUM+5',i1'BONUS_SIZE'
		dc i1'SOUND_REG_POINTER+BONUS_OSC_NUM',i1'BONUS_SOUND_ADDR/256'
		dc i1'SOUND_REG_POINTER+BONUS_OSC_NUM+1',i1'BONUS_SOUND_ADDR/256'
		dc i1'SOUND_REG_POINTER+BONUS_OSC_NUM+2',i1'BONUS_SOUND_ADDR/256'
		dc i1'SOUND_REG_POINTER+BONUS_OSC_NUM+3',i1'BONUS_SOUND_ADDR/256'
		dc i1'SOUND_REG_POINTER+BONUS_OSC_NUM+4',i1'BONUS_SOUND_ADDR/256'
		dc i1'SOUND_REG_POINTER+BONUS_OSC_NUM+5',i1'BONUS_SOUND_ADDR/256'
		dc i1'SOUND_REG_CONTROL+BONUS_OSC_NUM',i1'BONUS_CONTROL+SOUND_HALTED+SOUND_RIGHT_SPEAKER'
		dc i1'SOUND_REG_CONTROL+BONUS_OSC_NUM+1',i1'BONUS_CONTROL+SOUND_HALTED+SOUND_LEFT_SPEAKER'
		dc i1'SOUND_REG_CONTROL+BONUS_OSC_NUM+2',i1'BONUS_CONTROL+SOUND_HALTED+SOUND_RIGHT_SPEAKER'
		dc i1'SOUND_REG_CONTROL+BONUS_OSC_NUM+3',i1'BONUS_CONTROL+SOUND_HALTED+SOUND_LEFT_SPEAKER'
		dc i1'SOUND_REG_CONTROL+BONUS_OSC_NUM+4',i1'BONUS_CONTROL+SOUND_HALTED+SOUND_RIGHT_SPEAKER'
		dc i1'SOUND_REG_CONTROL+BONUS_OSC_NUM+5',i1'BONUS_CONTROL+SOUND_HALTED+SOUND_LEFT_SPEAKER'
		
; Kill registers
		dc i1'SOUND_REG_FREQ_LOW+KILL_OSC_NUM',i1'KILL_FREQ_LOW'
		dc i1'SOUND_REG_FREQ_LOW+KILL_OSC_NUM+1',i1'KILL_FREQ_LOW'
		dc i1'SOUND_REG_FREQ_HIGH+KILL_OSC_NUM',i1'KILL_FREQ_HIGH'
		dc i1'SOUND_REG_FREQ_HIGH+KILL_OSC_NUM+1',i1'KILL_FREQ_HIGH'
		dc i1'SOUND_REG_SIZE+KILL_OSC_NUM',i1'KILL_SIZE'
		dc i1'SOUND_REG_SIZE+KILL_OSC_NUM+1',i1'KILL_SIZE'
		dc i1'SOUND_REG_POINTER+KILL_OSC_NUM',i1'KILL_SOUND_ADDR/256'
		dc i1'SOUND_REG_POINTER+KILL_OSC_NUM+1',i1'KILL_SOUND_ADDR/256'
		dc i1'SOUND_REG_CONTROL+KILL_OSC_NUM',i1'KILL_CONTROL+SOUND_HALTED+SOUND_RIGHT_SPEAKER'
		dc i1'SOUND_REG_CONTROL+KILL_OSC_NUM+1',i1'KILL_CONTROL+SOUND_HALTED+SOUND_LEFT_SPEAKER'
		
; Fire registers
		dc i1'SOUND_REG_FREQ_LOW+FIRE_OSC_NUM',i1'FIRE_FREQ_LOW'
		dc i1'SOUND_REG_FREQ_LOW+FIRE_OSC_NUM+1',i1'FIRE_FREQ_LOW'
		dc i1'SOUND_REG_FREQ_HIGH+FIRE_OSC_NUM',i1'FIRE_FREQ_HIGH'
		dc i1'SOUND_REG_FREQ_HIGH+FIRE_OSC_NUM+1',i1'FIRE_FREQ_HIGH'
		dc i1'SOUND_REG_SIZE+FIRE_OSC_NUM',i1'FIRE_SIZE'
		dc i1'SOUND_REG_SIZE+FIRE_OSC_NUM+1',i1'FIRE_SIZE'
		dc i1'SOUND_REG_POINTER+FIRE_OSC_NUM',i1'FIRE_SOUND_ADDR/256'
		dc i1'SOUND_REG_POINTER+FIRE_OSC_NUM+1',i1'FIRE_SOUND_ADDR/256'
		dc i1'SOUND_REG_CONTROL+FIRE_OSC_NUM',i1'FIRE_CONTROL+SOUND_HALTED+SOUND_RIGHT_SPEAKER'
		dc i1'SOUND_REG_CONTROL+FIRE_OSC_NUM+1',i1'FIRE_CONTROL+SOUND_HALTED+SOUND_LEFT_SPEAKER'
		
; Extra life registers
		dc i1'SOUND_REG_FREQ_LOW+EXTRA_LIFE_OSC_NUM',i1'EXTRA_LIFE_FREQ_LOW'
		dc i1'SOUND_REG_FREQ_LOW+EXTRA_LIFE_OSC_NUM+1',i1'EXTRA_LIFE_FREQ_LOW'
		dc i1'SOUND_REG_FREQ_HIGH+EXTRA_LIFE_OSC_NUM',i1'EXTRA_LIFE_FREQ_HIGH'
		dc i1'SOUND_REG_FREQ_HIGH+EXTRA_LIFE_OSC_NUM+1',i1'EXTRA_LIFE_FREQ_HIGH'
		dc i1'SOUND_REG_VOLUME+EXTRA_LIFE_OSC_NUM',i1'EXTRA_LIFE_VOLUME'
		dc i1'SOUND_REG_VOLUME+EXTRA_LIFE_OSC_NUM+1',i1'EXTRA_LIFE_VOLUME'
		dc i1'SOUND_REG_SIZE+EXTRA_LIFE_OSC_NUM',i1'EXTRA_LIFE_SIZE'
		dc i1'SOUND_REG_SIZE+EXTRA_LIFE_OSC_NUM+1',i1'EXTRA_LIFE_SIZE'
		dc i1'SOUND_REG_POINTER+EXTRA_LIFE_OSC_NUM',i1'EXTRA_LIFE_SOUND_ADDR/256'
		dc i1'SOUND_REG_POINTER+EXTRA_LIFE_OSC_NUM+1',i1'EXTRA_LIFE_SOUND_ADDR/256'
		dc i1'SOUND_REG_CONTROL+EXTRA_LIFE_OSC_NUM',i1'EXTRA_LIFE_CONTROL+SOUND_HALTED+SOUND_RIGHT_SPEAKER'
		dc i1'SOUND_REG_CONTROL+EXTRA_LIFE_OSC_NUM+1',i1'EXTRA_LIFE_CONTROL+SOUND_HALTED+SOUND_LEFT_SPEAKER'

; Flea registers
		dc i1'SOUND_REG_VOLUME+FLEA_OSC_NUM',i1'0'
		dc i1'SOUND_REG_VOLUME+FLEA_OSC_NUM+1',i1'0'
		dc i1'SOUND_REG_VOLUME+FLEA_OSC_NUM+2',i1'0'
		dc i1'SOUND_REG_VOLUME+FLEA_OSC_NUM+3',i1'0'
		dc i1'SOUND_REG_SIZE+FLEA_OSC_NUM',i1'FLEA_SIZE'
		dc i1'SOUND_REG_SIZE+FLEA_OSC_NUM+1',i1'FLEA_SIZE'
		dc i1'SOUND_REG_SIZE+FLEA_OSC_NUM+2',i1'FLEA_SIZE'
		dc i1'SOUND_REG_SIZE+FLEA_OSC_NUM+3',i1'FLEA_SIZE'
		dc i1'SOUND_REG_POINTER+FLEA_OSC_NUM',i1'FLEA_SOUND_ADDR/256'
		dc i1'SOUND_REG_POINTER+FLEA_OSC_NUM+1',i1'FLEA_SOUND_ADDR/256'
		dc i1'SOUND_REG_POINTER+FLEA_OSC_NUM+2',i1'FLEA_SOUND_ADDR/256'
		dc i1'SOUND_REG_POINTER+FLEA_OSC_NUM+3',i1'FLEA_SOUND_ADDR/256'
		dc i1'SOUND_REG_CONTROL+FLEA_OSC_NUM',i1'SOUND_ONE_SHOT_MODE+SOUND_HALTED+SOUND_RIGHT_SPEAKER'
		dc i1'SOUND_REG_CONTROL+FLEA_OSC_NUM+1',i1'SOUND_ONE_SHOT_MODE+SOUND_HALTED+SOUND_RIGHT_SPEAKER'
		dc i1'SOUND_REG_CONTROL+FLEA_OSC_NUM+2',i1'SOUND_ONE_SHOT_MODE+SOUND_HALTED+SOUND_LEFT_SPEAKER'
		dc i1'SOUND_REG_CONTROL+FLEA_OSC_NUM+3',i1'SOUND_ONE_SHOT_MODE+SOUND_HALTED+SOUND_LEFT_SPEAKER'

; Scorpion registers
		dc i1'SOUND_REG_FREQ_LOW+SCORPION_OSC_NUM',i1'SCORPION_FREQ_LOW'
		dc i1'SOUND_REG_FREQ_LOW+SCORPION_OSC_NUM+1',i1'SCORPION_FREQ_LOW'
		dc i1'SOUND_REG_FREQ_LOW+SCORPION_OSC_NUM+2',i1'SCORPION_FREQ_LOW'
		dc i1'SOUND_REG_FREQ_LOW+SCORPION_OSC_NUM+3',i1'SCORPION_FREQ_LOW'
		dc i1'SOUND_REG_FREQ_HIGH+SCORPION_OSC_NUM',i1'SCORPION_FREQ_HIGH'
		dc i1'SOUND_REG_FREQ_HIGH+SCORPION_OSC_NUM+1',i1'SCORPION_FREQ_HIGH'
		dc i1'SOUND_REG_FREQ_HIGH+SCORPION_OSC_NUM+2',i1'SCORPION_FREQ_HIGH'
		dc i1'SOUND_REG_FREQ_HIGH+SCORPION_OSC_NUM+3',i1'SCORPION_FREQ_HIGH'
		dc i1'SOUND_REG_VOLUME+SCORPION_OSC_NUM',i1'0'
		dc i1'SOUND_REG_VOLUME+SCORPION_OSC_NUM+1',i1'0'
		dc i1'SOUND_REG_VOLUME+SCORPION_OSC_NUM+2',i1'0'
		dc i1'SOUND_REG_VOLUME+SCORPION_OSC_NUM+3',i1'0'
		dc i1'SOUND_REG_SIZE+SCORPION_OSC_NUM',i1'SCORPION_SIZE'
		dc i1'SOUND_REG_SIZE+SCORPION_OSC_NUM+1',i1'SCORPION_SIZE'
		dc i1'SOUND_REG_SIZE+SCORPION_OSC_NUM+2',i1'SCORPION_SIZE'
		dc i1'SOUND_REG_SIZE+SCORPION_OSC_NUM+3',i1'SCORPION_SIZE'
		dc i1'SOUND_REG_POINTER+SCORPION_OSC_NUM',i1'SCORPION_SOUND_ADDR/256'
		dc i1'SOUND_REG_POINTER+SCORPION_OSC_NUM+1',i1'SCORPION_SOUND_ADDR/256'
		dc i1'SOUND_REG_POINTER+SCORPION_OSC_NUM+2',i1'SCORPION_SOUND_ADDR/256'
		dc i1'SOUND_REG_POINTER+SCORPION_OSC_NUM+3',i1'SCORPION_SOUND_ADDR/256'
		dc i1'SOUND_REG_CONTROL+SCORPION_OSC_NUM',i1'SOUND_ONE_SHOT_MODE+SOUND_HALTED+SOUND_RIGHT_SPEAKER'
		dc i1'SOUND_REG_CONTROL+SCORPION_OSC_NUM+1',i1'SOUND_ONE_SHOT_MODE+SOUND_HALTED+SOUND_RIGHT_SPEAKER'
		dc i1'SOUND_REG_CONTROL+SCORPION_OSC_NUM+2',i1'SOUND_ONE_SHOT_MODE+SOUND_HALTED+SOUND_LEFT_SPEAKER'
		dc i1'SOUND_REG_CONTROL+SCORPION_OSC_NUM+3',i1'SOUND_ONE_SHOT_MODE+SOUND_HALTED+SOUND_LEFT_SPEAKER'
		
soundRegDefaultsEnd	anop

        end
