Topic: Help with Steve Turner sound effect
While searching around for different sound effects to use / play around with, I found the sound effect engine used in Steve Turner games. The code I found was
....
;Steve Turner / Hewson Cons
;sfx engine
;used in Ranarama, Quazatron,IronMan
;you can use this routine on interrupts
;or in main game cicle
sound
ld a,(sonreq) ;new sound play?
and a
jr z,nonew ;No new sound
;да
ld (sonnow),a
dec a
jr z,noise ;#01 noise
ld hl,sfx_data
dec a
add a,a
add a,a
add a,a
ld e,a
xor a
ld (sonreq),a
ld d,a
add hl,de
ld bc,08
ld de,sonfrq
ldir
jr process
nonew ld a,(sonnow) ;the old sound is?
and a
ret z
dec a ;continue noise?
jr nz,process ;continue sound
jr cnois
noise ld a,0ah
ld (sonlen),a
xor a
ld (sonreq),a
cnois ld b,30h
gain call random
and 10h
out (0feh),a
ld c,02h
make dec c
jr nz,make
djnz gain
ld hl,sonlen
dec (hl)
ret nz
xor a
ld (sonnow),a
ret
process ld a,(sonfrq)
ld h,a
ld a,10h
ld d,0ffh
sonlp ld e,h
out (0feh),a
xor 10h
freq dec d
jr z,mod
dec e
jr nz,freq
jr sonlp
mod ld a,(soncfg)
add a,h
ld (sonfrq),a
ld hl,sonmod
dec (hl)
ret nz
ld hl,sonlen
dec (hl)
jr nz,modify
xor a
ld (sonnow),a
ld a,(sonnex)
and a
ret z
ld (sonreq),a
ret
modify ld a,(sobrsf)
ld c,a
ld a,(sontyp)
and a
jr z,reset
dec a
jr z,typ1
dec a
jr z,typ2
typoth ld a,(soncfg)
neg
ld (soncfg),a
jr mode
typ2 inc c
inc c
ld a,c
ld (sobrsf),a
jr reset
typ1 dec c
dec c
ld a,c
ld (sobrsf),a
jr reset
reset ld a,c
ld (sonfrq),a
mode ld a,(sonrnd)
ld (sonmod),a
ret
random push hl
ld hl,(rnseed)
inc hl
ld a,h
and 03
ld h,a
rok ld (rnseed),a
ld a,r
xor (hl)
pop hl
ret
rnseed defw 1000h
sonfrq defb 00 ;inital frequency
soncfg defb 00 ;frequency change rate
sonmod defb 00 ;number of sound modulations
sonlen defb 00 ;number of times to repeat
sontyp defb 00 ;modulate type
;0 sawtooth
;1 2nd mod down
;2 2nd mod up
;3+ triangle
sobrsf defb 00 reset frequency
sonrnd defb 00 ;change rate of reset frequency
sonnex defb 00 ;linked sfx
sonnow defb 00 ;what is being played
sonreq defb 00 ;which effect?
sfx_data
;here all souned excepts number 1 reserved for random noise
; defb 0, 5, 5, 1, 0, 0, 0, 0
; defb 28h, 5, 0Ah, 1, 0, 0, 0, 0
; defb 0, 80h, 1Eh, 1, 0, 0, 0, 0
; defb 0, 2, 1Eh, 1, 0, 0, 0, 0
; defb 0, 7Dh, 20h, 1, 0, 0, 0, 0
; defb 0FFh, 83h, 20h, 1, 0, 0, 0, 0
; defb 0FFh, 83h, 28h, 20h, 1, 3Ch, 1, 0
; defb 0F0h,0F0h, 8, 3, 0, 3Ch, 6, 0
; defb 2, 80h, 0Ah, 1, 0, 0, 0, 0
; defb 28h,0FAh, 8, 1, 0, 0, 0, 0
; defb 0FAh, 2Ch, 6, 0Ah, 1, 5Ah, 1, 0
; defb 0,0FCh, 14h, 8, 1, 50h, 8, 0
; defb 0E6h,0E6h, 4, 1, 1, 0, 0, 0
; defb 2Dh, 43h, 14h, 1, 1, 0, 0, 0
Now to the real question(s). I tried placing this in a C wrapper for usage in Z88DK, so I could call the effects within a single call. It appears according to the comments that when this is called, only produces a small portion of the sound and returns back to the main loop.
Can this be easily changed?
What would be more code friendly within Z88dk is to outpulse the entire sound at once and then return back to the game. I realize that the game would pause while the effect takes place, I'm OK with that, just produce a really short sound while in action.
In Z88dk, I pass onto an assembly routine, L for char, HL for int and DEHL for long. I am currently just sending L to the assembly and passing that onto a. My wrapper for this is:
extern void __FASTCALL__ SFX(unsigned char fx)
{
#asm
ld a,l ;32758
;rest of STEVE TURNER code ....
#endasm
}
Is that proper? Sorry I am extremely weak on assembly and was hoping that someone much more experienced could help me out on this.
Thank you.
Andy