From af3d4581d306f00c4a7f0aba62f9d79962a3ff79 Mon Sep 17 00:00:00 2001 From: Greg King Date: Sun, 30 May 2021 13:30:08 -0400 Subject: [PATCH] Moved Creativision's playsound() into a separate file. It won't waste space in a cartridge if it isn't used. --- asminc/creativision.inc | 47 ++++++++++++++++++--------------- libsrc/creativision/playsound.s | 40 ++++++++++++++++++++++++++++ libsrc/creativision/psg.s | 43 +++--------------------------- 3 files changed, 69 insertions(+), 61 deletions(-) create mode 100644 libsrc/creativision/playsound.s diff --git a/asminc/creativision.inc b/asminc/creativision.inc index 49d55a342..a0259ecce 100644 --- a/asminc/creativision.inc +++ b/asminc/creativision.inc @@ -5,21 +5,21 @@ ;** Screen SCREEN_ROWS = 24 SCREEN_COLS = 32 -SCREEN_PTR = $3A -CURSOR_X = $3C -CURSOR_Y = $3D +SCREEN_PTR := $3A +CURSOR_X := $3C +CURSOR_Y := $3D ;** VDP -VDP_DATA_R = $2000 -VDP_STATUS_R = $2001 -VDP_DATA_W = $3000 -VDP_CONTROL_W = $3001 +VDP_DATA_R := $2000 +VDP_STATUS_R := $2001 +VDP_DATA_W := $3000 +VDP_CONTROL_W := $3001 ;** PIA -PIA0_DATA = $1000 -PIA0_STATUS = $1001 -PIA1_DATA = $1002 -PIA1_STATUS = $1003 +PIA0_DATA := $1000 +PIA0_STATUS := $1001 +PIA1_DATA := $1002 +PIA1_STATUS := $1003 ;** General CH_VLINE = 33 @@ -30,11 +30,11 @@ CH_LLCORNER = 37 CH_LRCORNER = 38 ;** I/O (Zero-page variables) -ZP_KEYBOARD = $10 -ZP_JOY0_DIR = $11 -ZP_JOY1_DIR = $13 -ZP_JOY0_BUTTONS = $16 -ZP_JOY1_BUTTONS = $17 +ZP_KEYBOARD := $10 +ZP_JOY0_DIR := $11 +ZP_JOY1_DIR := $13 +ZP_JOY0_BUTTONS := $16 +ZP_JOY1_BUTTONS := $17 ;** Joystick direction values (ZP_JOY0_DIR/ZP_JOY1_DIR) JOY_N = $49 @@ -54,8 +54,13 @@ JOY_WNW = $4C JOY_NW = $4B JOY_NNW = $4A -;** BIOS -BIOS_IRQ1_ADDR = $FF3F -BIOS_IRQ2_ADDR = $FF52 -BIOS_NMI_RESET_ADDR = $F808 -BIOS_WRITE_VDP_REG = $FE1F +;** BIOS routines +BIOS_NMI_RESET_ADDR := $F808 +BIOS_PLAY_TUNE1 := $FBD6 +BIOS_PLAY_SONG := $FBED +BIOS_PLAY_TUNE2 := $FCE6 +BIOS_WRITE_VDP_REG := $FE1F +BIOS_QUIET_PSG := $FE54 +BIOS_POKE_PSG := $FE77 +BIOS_IRQ1_ADDR := $FF3F +BIOS_IRQ2_ADDR := $FF52 diff --git a/libsrc/creativision/playsound.s b/libsrc/creativision/playsound.s new file mode 100644 index 000000000..55c7a3fed --- /dev/null +++ b/libsrc/creativision/playsound.s @@ -0,0 +1,40 @@ +; void __fastcall__ bios_playsound (void *a, unsigned char b); + + + .export _bios_playsound + + .import popax + + .include "creativision.inc" + + +songptr := $00 ; Points to current tune data +volptr := $04 ; Points to current volume table + + +;* Creativision Sound Player +;* Based on BIOS song player. +;* +;* Pass a pointer to a set of note triples, terminated with a tempo byte; +;* and pass the length of the triples and tempo (max 255). +;* +;* Note: tune data must be stored backwards. + +_bios_playsound: + php + pha ; Save tune length + sei + + lda #<$FCD5 ; BIOS decreasing-volume table + ldx #>$FCD5 + sta volptr + stx volptr+1 + + jsr popax ; Get tune array pointer + sta songptr + stx songptr+1 + + pla + tay + dey ; Point to tempo byte + jmp BIOS_PLAY_SONG ; Let BIOS do its thing diff --git a/libsrc/creativision/psg.s b/libsrc/creativision/psg.s index c84f92f43..ec878af31 100644 --- a/libsrc/creativision/psg.s +++ b/libsrc/creativision/psg.s @@ -1,27 +1,18 @@ ; void __fastcall__ psg_outb (unsigned char b); ; void __fastcall__ psg_delay (unsigned char b); -; void __fastcall__ bios_playsound (void *a, unsigned char b); ; void psg_silence (void); .export _psg_outb, _psg_silence, _psg_delay - .export _bios_playsound - - .import popax .include "creativision.inc" -songptr := $00 ; Points to current tune data -volptr := $04 ; Points to current volume table - -_psg_outb: - ;* Let BIOS output the value. - jmp $FE77 +;* Let BIOS output the value. +_psg_outb := BIOS_POKE_PSG -_psg_silence: - jmp $FE54 +_psg_silence := BIOS_QUIET_PSG _psg_delay: @@ -37,31 +28,3 @@ l3: sbc #1 dey bne l1 rts - - -;* Creativision Sound Player -;* Based on BIOS song player. -;* -;* Pass a pointer to a set of note triples, terminated with a tempo byte; -;* and pass the length of the triples and tempo (max 255). -;* -;* Note: tune data must be stored backwards. - -_bios_playsound: - php - pha ; Save tune length - sei - - lda #<$FCD5 ; A BIOS volume table - ldx #>$FCD5 - sta volptr - stx volptr+1 - - jsr popax ; Get tune array pointer - sta songptr - stx songptr+1 - - pla - tay - dey ; Point to tempo byte - jmp $FBED ; Let BIOS do its thing