Preparation for audio support - sound queues.

This commit is contained in:
Bobbi Webber-Manners 2022-09-27 23:17:40 -04:00
parent 9158a0f94f
commit 67b2972dcf
4 changed files with 76 additions and 0 deletions

View File

@ -198,6 +198,7 @@ MAINZP MAC
PUT AUXMEM.BYTWRD
PUT AUXMEM.CHARIO
PUT AUXMEM.MISC
PUT AUXMEM.AUDIO
* Automatically save the object file:
SAV APPLECORN

64
auxmem.audio.s Normal file
View File

@ -0,0 +1,64 @@
* AUXMEM.AUDIO.S
* (c) Bobbi 2022 GPLv3
*
* Applecorn audio code
*
SNDBUFSZ EQU 16 ; All audio buffers are 16 bytes
* Get address of sound buffer
* On entry: X is buffer number
* On exit: OSIRQWS points to start of buffer
* Called with interrupts disabled
GETBUFADDR LDA :BUFADDRL,X
STA OSINTWS+0
LDA :BUFADDRH,X
STA OSINTWS+1
RTS
:BUFADDRL DB $00
DB $00
DB $00
DB $00
DB <SNDBUF0
DB <SNDBUF1
DB <SNDBUF2
DB <SNDBUF3
DB $00
:BUFADDRH DB $00
DB $00
DB $00
DB $00
DB >SNDBUF0
DB >SNDBUF1
DB >SNDBUF2
DB >SNDBUF3
DB $00
* Insert value into buffer (INSV)
* On entry: A is value, X is buffer number.
* On exit: A, X preserved. C clear on success.
INSHND PHP ; Save flags, turn off interrupts
SEI
PHA
LDY ENDINDICES,X ; Get input pointer
INY ; Next byte
CPY #SNDBUFSZ
BNE :NOTEND ; See if it's the end
LDY #0 ; If so, wraparound
:NOTEND TYA
CMP STARTINDICES,X ; See if buffer is full
BEQ :FULL
LDY ENDINDICES,X ; Current position
STA ENDINDICES,X ; Write updated input pointer
JSR GETBUFADDR ; Buffer address into OSINTWS
PLA ; Get value back
STA (OSINTWS),Y ; Write to buffer
PLP ; Restore flags
CLC ; Exit with carry clear
RTS
:FULL PLA ; Restore A
PLP ; Restore flags
SEC ; Exit with carry set
RTS

View File

@ -126,6 +126,14 @@ MOSHIGH SEI ; Disable IRQ while initializing
DEX
BPL :INITPG2
LDX #3
LDA #$80 ; Initialize sound queues
:INITSND STA SND0EMPTY,X
STZ SND0STARTIDX,X
STZ SND0ENDIDX,X
DEX
BNE :INITSND
LDA $C036 ; GS speed register
AND #$80 ; Speed bit only
STA GSSPEED ; In Alt LC for IRQ/BRK hdlr

View File

@ -69,14 +69,17 @@ FSCV EQU $21E ; FSCV misc file ops
BYTEVARBASE EQU $190 ; Base of OSBYTE variables
EMPTYFLAGS EQU $2CF
SND0EMPTY EQU $2D3 ; Empty flag for sound bufs
SND1EMPTY EQU $2D4
SND2EMPTY EQU $2D5
SND3EMPTY EQU $2D6
STARTINDICES EQU $2D8
SND0STARTIDX EQU $2DC ; Start index for sound bufs
SND1STARTIDX EQU $2DD
SND2STARTIDX EQU $2DE
SND3STARTIDX EQU $2DF
ENDINDICES EQU $2E1
SND0ENDIDX EQU $2E5 ; End index for sound bufs
SND1ENDIDX EQU $2E6
SND2ENDIDX EQU $2E7