-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from jsmolina/feature/sounds_asm_int
Feature/sounds asm int
- Loading branch information
Showing
13 changed files
with
327 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,197 @@ | ||
;BeepFX player by Shiru | ||
;You are free to do whatever you want with this code | ||
SECTION code_user | ||
|
||
PUBLIC _playBasic | ||
|
||
|
||
_playBasic: | ||
ld a,0 | ||
play: | ||
ld hl,sfxData ;address of sound effects data | ||
|
||
di | ||
push ix | ||
push iy | ||
|
||
ld b,0 | ||
ld c,a | ||
add hl,bc | ||
add hl,bc | ||
ld e,(hl) | ||
inc hl | ||
ld d,(hl) | ||
push de | ||
pop ix ;put it into ix | ||
|
||
ld a,(23624) ;get border color from BASIC vars to keep it unchanged | ||
rra | ||
rra | ||
rra | ||
and 7 | ||
ld (sfxRoutineToneBorder +1),a | ||
ld (sfxRoutineNoiseBorder +1),a | ||
ld (sfxRoutineSampleBorder+1),a | ||
|
||
|
||
readData: | ||
ld a,(ix+0) ;read block type | ||
ld c,(ix+1) ;read duration 1 | ||
ld b,(ix+2) | ||
ld e,(ix+3) ;read duration 2 | ||
ld d,(ix+4) | ||
push de | ||
pop iy | ||
|
||
dec a | ||
jr z,sfxRoutineTone | ||
dec a | ||
jr z,sfxRoutineNoise | ||
dec a | ||
jr z,sfxRoutineSample | ||
pop iy | ||
pop ix | ||
ei | ||
ret | ||
|
||
|
||
|
||
;play sample | ||
|
||
sfxRoutineSample: | ||
ex de,hl | ||
sfxRS0: | ||
ld e,8 | ||
ld d,(hl) | ||
inc hl | ||
sfxRS1: | ||
ld a,(ix+5) | ||
sfxRS2: | ||
dec a | ||
jr nz,sfxRS2 | ||
rl d | ||
sbc a,a | ||
and 16 | ||
sfxRoutineSampleBorder: | ||
or 0 | ||
out (254),a | ||
dec e | ||
jr nz,sfxRS1 | ||
dec bc | ||
ld a,b | ||
or c | ||
jr nz,sfxRS0 | ||
|
||
ld c,6 | ||
|
||
nextData: | ||
add ix,bc ;skip to the next block | ||
jr readData | ||
|
||
|
||
|
||
;generate tone with many parameters | ||
|
||
sfxRoutineTone: | ||
ld e,(ix+5) ;freq | ||
ld d,(ix+6) | ||
ld a,(ix+9) ;duty | ||
ld (sfxRoutineToneDuty+1),a | ||
ld hl,0 | ||
|
||
sfxRT0: | ||
push bc | ||
push iy | ||
pop bc | ||
sfxRT1: | ||
add hl,de | ||
ld a,h | ||
sfxRoutineToneDuty: | ||
cp 0 | ||
sbc a,a | ||
and 16 | ||
sfxRoutineToneBorder: | ||
or 0 | ||
out (254),a | ||
|
||
dec bc | ||
ld a,b | ||
or c | ||
jr nz,sfxRT1 | ||
|
||
ld a,(sfxRoutineToneDuty+1) ;duty change | ||
add a,(ix+10) | ||
ld (sfxRoutineToneDuty+1),a | ||
|
||
ld c,(ix+7) ;slide | ||
ld b,(ix+8) | ||
ex de,hl | ||
add hl,bc | ||
ex de,hl | ||
|
||
pop bc | ||
dec bc | ||
ld a,b | ||
or c | ||
jr nz,sfxRT0 | ||
|
||
ld c,11 | ||
jr nextData | ||
|
||
|
||
|
||
;generate noise with two parameters | ||
|
||
sfxRoutineNoise: | ||
ld e,(ix+5) ;pitch | ||
|
||
ld d,1 | ||
ld h,d | ||
ld l,d | ||
sfxRN0: | ||
push bc | ||
push iy | ||
pop bc | ||
sfxRN1: | ||
ld a,(hl) | ||
and 16 | ||
sfxRoutineNoiseBorder: | ||
or 0 | ||
and 248 ;keep border colour the same | ||
out (254),a | ||
dec d | ||
jr nz,sfxRN2 | ||
ld d,e | ||
inc hl | ||
ld a,h | ||
and 31 | ||
ld h,a | ||
sfxRN2: | ||
dec bc | ||
ld a,b | ||
or c | ||
jr nz,sfxRN1 | ||
|
||
ld a,e | ||
add a,(ix+6) ;slide | ||
ld e,a | ||
|
||
pop bc | ||
dec bc | ||
ld a,b | ||
or c | ||
jr nz,sfxRN0 | ||
|
||
ld c,7 | ||
jr nextData | ||
|
||
|
||
sfxData: | ||
|
||
SoundEffectsData: | ||
defw SoundEffect0Data | ||
|
||
SoundEffect0Data: | ||
defb 2 ;noise | ||
defw 2,1,512 | ||
defb 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
BeepFX |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,5 +5,6 @@ | |
#include <arch/zx.h> | ||
|
||
extern void print_points(); | ||
extern void make_sound(); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
EXTERN _tick | ||
EXTERN _pick | ||
EXTERN _playBasic | ||
|
||
;;;;;;;;;;;;;;;;;;;;;; | ||
; void setup_int(void) | ||
;;;;;;;;;;;;;;;;;;;;;; | ||
|
||
SECTION code_user | ||
|
||
|
||
PUBLIC _setup_int | ||
|
||
_setup_int: | ||
|
||
; im2 table @ 0xd000 | ||
|
||
ld hl,0xd000 | ||
ld de,0xd001 | ||
ld bc,256 | ||
|
||
ld (hl),0xd1 | ||
ldir | ||
|
||
; jump to isr | ||
|
||
ld a,0xc3 | ||
ld (0xd1d1),a | ||
|
||
ld hl,isr | ||
ld (0xd1d2),hl | ||
|
||
; I register | ||
|
||
ld a,0xd0 | ||
ld i,a | ||
|
||
im 2 | ||
ei | ||
|
||
ret | ||
|
||
;;;;;;;;;;;;;;;;;;; | ||
; interrupt routine | ||
;;;;;;;;;;;;;;;;;;; | ||
|
||
SECTION code_crt_common ;; place very low in memory, out of top 16k | ||
|
||
PUBLIC isr | ||
PUBLIC isr_skip | ||
|
||
|
||
|
||
isr: | ||
|
||
push af | ||
push bc | ||
push de | ||
push hl | ||
exx | ||
ex af,af' | ||
push af | ||
push bc | ||
push de | ||
push hl | ||
push ix | ||
push iy | ||
|
||
; update clock | ||
|
||
ld a,(_tick) | ||
inc a | ||
ld (_tick),a | ||
|
||
|
||
|
||
isr_skip: | ||
|
||
; music | ||
|
||
ld a,0x80 | ||
ld i,a ; point I at uncontended bank | ||
|
||
ld a,h | ||
or l | ||
|
||
; FX | ||
ld a,(_pick) | ||
or a | ||
JR Z, it_was_zero ; skip if it reaches zero | ||
|
||
dec a ; else decrement | ||
ld (_pick),a | ||
; https://www.sounds-resource.com/nes/mspacmannamco/sound/5206/ | ||
call _playBasic | ||
|
||
it_was_zero: | ||
ld a,0xd0 | ||
ld i,a ; restore I | ||
|
||
pop iy | ||
pop ix | ||
pop hl | ||
pop de | ||
pop bc | ||
pop af | ||
ex af,af' | ||
exx | ||
pop hl | ||
pop de | ||
pop bc | ||
pop af | ||
|
||
ei | ||
reti |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.