Skip to content

Commit

Permalink
Merge pull request #15 from jsmolina/feature/sounds_asm_int
Browse files Browse the repository at this point in the history
Feature/sounds asm int
  • Loading branch information
jsmolina authored May 12, 2019
2 parents 6556975 + a639a5a commit a1167ef
Show file tree
Hide file tree
Showing 13 changed files with 327 additions and 37 deletions.
Binary file modified .DS_Store
Binary file not shown.
7 changes: 0 additions & 7 deletions font.asm

This file was deleted.

197 changes: 197 additions & 0 deletions fx/BeepFX.asm
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
1 change: 1 addition & 0 deletions fx/fx.lst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
BeepFX
Binary file removed game.font
Binary file not shown.
4 changes: 2 additions & 2 deletions game_zx.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
#include "globals.h"

extern uint8_t strlen(char * chars);

// https://arda.kisafilm.org/fish/ay8910-2.htm
// temporary buffer to print points (e.g. 65535)
char * chars = "0000000\0";


// reversed order digit extract
void print_points() {
utoa(points, chars, 10);
Expand All @@ -25,4 +24,5 @@ void print_points() {
sp1_PrintAtInv(0, 26 + idx + col, INK_CYAN | PAPER_BLACK, chars[idx]);
++idx;
}

}
1 change: 1 addition & 0 deletions game_zx.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
#include <arch/zx.h>

extern void print_points();
extern void make_sound();

#endif
115 changes: 115 additions & 0 deletions int.asm
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
26 changes: 3 additions & 23 deletions int.c
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
#include <im2.h>
#include <intrinsic.h>
#include <stdlib.h>
#include <string.h>
#include <z80.h>
#include "int.h"

// timer
#include <stdlib.h>
#include <intrinsic.h>

unsigned char tick;
unsigned char timer;
unsigned char pick;

IM2_DEFINE_ISR(isr)
{
// update the clock
++tick;

}

void
wait(void)
Expand All @@ -25,15 +17,3 @@ wait(void)

timer = tick;
}

void
setup_int(void)
{
im2_init((void *)0xd000); // CRT_ORG = 25124
memset((void *)0xd000, 0xd1, 257);

z80_bpoke(0xd1d1, 0xc3);
z80_wpoke(0xd1d2, (unsigned int)isr);

intrinsic_ei();
}
1 change: 1 addition & 0 deletions int.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEAL
#define clock(x) (tick)

extern unsigned char tick;
extern unsigned char pick;

extern void wait(void);
extern void setup_int(void);
Expand Down
Loading

0 comments on commit a1167ef

Please sign in to comment.