2022-11-18 00:38:21 +00:00
|
|
|
* MAINMEM.MOCK.S
|
|
|
|
* (c) Bobbi 2022 GPLv3
|
|
|
|
*
|
|
|
|
* Mockingboard Driver.
|
2022-11-29 00:59:19 +00:00
|
|
|
* Simulates Hitachi SN76489 sound generator chip found in BBC Micro.
|
2022-11-18 00:38:21 +00:00
|
|
|
*
|
2022-11-18 03:26:46 +00:00
|
|
|
*
|
|
|
|
* I borrowed some ideas from Deater:
|
|
|
|
* https://github.com/deater/dos33fsprogs/blob/master/music/pt3_lib/pt3_lib_mockingboard_setup.s
|
|
|
|
*
|
|
|
|
|
2022-11-18 00:38:21 +00:00
|
|
|
* Mockingboard control registers
|
2022-11-18 03:26:46 +00:00
|
|
|
* ASSUMES SLOT 4
|
|
|
|
MOCK_6522_ORB1 EQU $C400 ; 6522 #1 port b data
|
|
|
|
MOCK_6522_ORA1 EQU $C401 ; 6522 #1 port a data
|
|
|
|
MOCK_6522_DDRB1 EQU $C402 ; 6522 #1 data direction port B
|
|
|
|
MOCK_6522_DDRA1 EQU $C403 ; 6522 #1 data direction port A
|
|
|
|
MOCK_6522_T1CL EQU $C404 ; 6522 #1 t1 low order latches
|
|
|
|
MOCK_6522_T1CH EQU $C405 ; 6522 #1 t1 high order counter
|
|
|
|
MOCK_6522_T1LL EQU $C406 ; 6522 #1 t1 low order latches
|
|
|
|
MOCK_6522_T1LH EQU $C407 ; 6522 #1 t1 high order latches
|
|
|
|
MOCK_6522_T2CL EQU $C408 ; 6522 #1 t2 low order latches
|
|
|
|
MOCK_6522_T2CH EQU $C409 ; 6522 #1 t2 high order counters
|
|
|
|
MOCK_6522_SR EQU $C40A ; 6522 #1 shift register
|
|
|
|
MOCK_6522_ACR EQU $C40B ; 6522 #1 auxilliary control register
|
|
|
|
MOCK_6522_PCR EQU $C40C ; 6522 #1 peripheral control register
|
|
|
|
MOCK_6522_IFR EQU $C40D ; 6522 #1 interrupt flag register
|
|
|
|
MOCK_6522_IER EQU $C40E ; 6522 #1 interrupt enable register
|
|
|
|
MOCK_6522_ORANH EQU $C40F ; 6522 #1 port a data no handshake
|
|
|
|
MOCK_6522_ORB2 EQU $C480 ; 6522 #2 port b data
|
|
|
|
MOCK_6522_ORA2 EQU $C481 ; 6522 #2 port a data
|
|
|
|
MOCK_6522_DDRB2 EQU $C482 ; 6522 #2 data direction port B
|
|
|
|
MOCK_6522_DDRA2 EQU $C483 ; 6522 #2 data direction port A
|
|
|
|
|
|
|
|
; AY-3-8910 commands on port B
|
|
|
|
MOCK_AY_RESET EQU $0
|
|
|
|
MOCK_AY_INACTIVE EQU $4
|
|
|
|
MOCK_AY_READ EQU $5
|
|
|
|
MOCK_AY_WRITE EQU $6
|
|
|
|
MOCK_AY_LATCH_ADDR EQU $7
|
|
|
|
|
2022-11-18 00:38:21 +00:00
|
|
|
|
|
|
|
* Initialize Mockingboard
|
2022-11-18 03:26:46 +00:00
|
|
|
MOCKINIT LDA #$FF ; All VIA pins output
|
|
|
|
STA MOCK_6522_DDRB1
|
|
|
|
STA MOCK_6522_DDRA1
|
|
|
|
STA MOCK_6522_DDRB2
|
|
|
|
STA MOCK_6522_DDRA2
|
|
|
|
|
|
|
|
LDA #MOCK_AY_RESET ; Reset left AY-3
|
|
|
|
STA MOCK_6522_ORB1
|
|
|
|
LDA #MOCK_AY_INACTIVE
|
|
|
|
STA MOCK_6522_ORB1
|
|
|
|
|
|
|
|
LDA #MOCK_AY_RESET ; Reset right AY-3
|
|
|
|
STA MOCK_6522_ORB2
|
|
|
|
LDA #MOCK_AY_INACTIVE
|
|
|
|
STA MOCK_6522_ORB2
|
|
|
|
|
2022-11-18 23:29:36 +00:00
|
|
|
LDA #<MOCKISR ; Set up ISR with ALLOC_INTERRUPT
|
|
|
|
STA ALLOCPL+2
|
2022-11-18 03:26:46 +00:00
|
|
|
LDA #>MOCKISR
|
2022-11-18 23:29:36 +00:00
|
|
|
STA ALLOCPL+3
|
|
|
|
JSR MLI
|
|
|
|
DB ALLOCCMD
|
|
|
|
DW ALLOCPL
|
2022-11-18 00:38:21 +00:00
|
|
|
|
2022-11-18 03:26:46 +00:00
|
|
|
PHP
|
|
|
|
SEI
|
|
|
|
LDA #$40 ; Configure VIA interrupt
|
|
|
|
STA MOCK_6522_ACR
|
2022-11-22 21:10:06 +00:00
|
|
|
LDA #$7F ; Clear all bits
|
2022-11-18 03:26:46 +00:00
|
|
|
STA MOCK_6522_IER
|
2022-11-22 21:10:06 +00:00
|
|
|
LDA #$C0 ; Set bit 6
|
2022-11-18 03:26:46 +00:00
|
|
|
STA MOCK_6522_IFR
|
|
|
|
STA MOCK_6522_IER
|
|
|
|
LDA #$F4 ; $27F4 => 100Hz
|
|
|
|
STA MOCK_6522_T1CL
|
|
|
|
LDA #$27
|
|
|
|
STA MOCK_6522_T1CH
|
|
|
|
PLP
|
2022-11-18 00:38:21 +00:00
|
|
|
|
|
|
|
* Silence all channels
|
2022-11-18 03:26:46 +00:00
|
|
|
MOCKSILENT LDX #13 ; Clear all 14 AY-3 regs
|
|
|
|
LDA #$00
|
2022-11-28 02:55:40 +00:00
|
|
|
:L0 JSR MOCKWRT1
|
|
|
|
JSR MOCKWRT2
|
2022-11-18 03:26:46 +00:00
|
|
|
DEX
|
|
|
|
BPL :L0
|
2022-11-19 05:39:38 +00:00
|
|
|
LDA #$38 ; Turn off noise
|
|
|
|
LDX #07
|
2022-11-28 02:55:40 +00:00
|
|
|
JSR MOCKWRT1 ; First AY-3
|
|
|
|
LDA #$14 ; A,B=tone; C=noise
|
|
|
|
JSR MOCKWRT2 ; Second AY-3
|
2022-11-18 00:38:21 +00:00
|
|
|
RTS
|
|
|
|
|
|
|
|
|
2022-11-22 21:10:06 +00:00
|
|
|
* Stop Mockingboard interrupt
|
|
|
|
MOCKSTOP JSR MOCKSILENT
|
|
|
|
LDA #$7F ; Clear all bits
|
|
|
|
STA MOCK_6522_IER
|
|
|
|
LDA ALLOCPL+1 ; Interrupt number
|
|
|
|
STA DEALLOCPL+1
|
|
|
|
JSR MLI ; Deallocate ISR
|
|
|
|
DB DEALLOCCMD
|
|
|
|
DW DEALLOCPL
|
|
|
|
RTS
|
|
|
|
|
|
|
|
|
2022-11-18 00:38:21 +00:00
|
|
|
* Configure a Mockingboard oscillator to play a note
|
2022-11-18 23:29:36 +00:00
|
|
|
* On entry: X - oscillator number 0-3, A - frequency, Y - amplitude
|
2022-11-18 00:38:21 +00:00
|
|
|
* Preserves all registers
|
2022-11-19 04:58:53 +00:00
|
|
|
MOCKNOTE PHA
|
|
|
|
PHY
|
|
|
|
TAY
|
|
|
|
JSR MOCKFREQ ; Set frequency
|
|
|
|
PLY
|
|
|
|
JSR MOCKAMP ; Set amplitude
|
|
|
|
PLA
|
2022-11-18 00:38:21 +00:00
|
|
|
RTS
|
|
|
|
|
|
|
|
|
|
|
|
* Adjust frequency of note already playing
|
2022-11-18 23:29:36 +00:00
|
|
|
* On entry: X - oscillator number 0-3, Y - frequency to set
|
2022-11-18 00:38:21 +00:00
|
|
|
* Preserves X & Y
|
2022-11-18 23:29:36 +00:00
|
|
|
MOCKFREQ PHX
|
2022-11-29 00:59:19 +00:00
|
|
|
CPX #$00 ; Oscillator 0 is noise channel
|
2022-11-28 02:55:40 +00:00
|
|
|
BEQ :NOISE
|
2022-11-29 00:59:19 +00:00
|
|
|
CPX #$01 ; Oscillator 1 controls noise freq
|
|
|
|
BNE :S0 ; Not 1? Skip
|
|
|
|
CMP #$00 ; If frequency is zero ..
|
|
|
|
BEQ :S0 ; .. skip
|
|
|
|
STA :CH1NOTE ; Store frequency for noise gen
|
|
|
|
:S0 TXA
|
2022-11-19 04:58:53 +00:00
|
|
|
DEC A ; Subtract 1
|
|
|
|
ASL ; Double to get fine register
|
|
|
|
TAX
|
|
|
|
LDA MFREQLOW,Y ; LSB of divider
|
2022-11-28 02:55:40 +00:00
|
|
|
JSR MOCKWRT1 ; Write value to AY-3 register
|
2022-11-19 04:58:53 +00:00
|
|
|
INX ; Add one for course register
|
|
|
|
LDA MFREQHIGH,Y ; MSB of divider
|
2022-11-28 02:55:40 +00:00
|
|
|
JSR MOCKWRT1 ; Write value to AY-3 register
|
|
|
|
PLX
|
|
|
|
RTS
|
2022-11-29 00:59:19 +00:00
|
|
|
:NOISE TYA ; Parameter P
|
|
|
|
AND #$03 ; Keep least significant 2 bits
|
|
|
|
TAY
|
|
|
|
LDA :NOISENOTE,Y ; Get value of note
|
|
|
|
EOR #$FF ; Negate
|
|
|
|
INC A
|
|
|
|
CLC ; Add 255
|
|
|
|
ADC #$FF
|
|
|
|
LSR ; Convert 0..255 to 0..31
|
|
|
|
LSR
|
|
|
|
LSR
|
|
|
|
LDX #6 ; Noise period register
|
2022-11-28 02:55:40 +00:00
|
|
|
JSR MOCKWRT2 ; Write value to AY-3 register
|
|
|
|
PLX
|
2022-11-18 00:38:21 +00:00
|
|
|
RTS
|
2022-11-29 00:59:19 +00:00
|
|
|
:NOISENOTE DB $FF ; BBC Micro note P=0 or 4
|
|
|
|
DB $80 ; BBC Micro note P=1 or 5
|
|
|
|
DB $00 ; BBC Micro note P=2 or 6
|
|
|
|
:CH1NOTE DB $00 ; Note on channel 1
|
2022-11-18 00:38:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
* Adjust amplitude of note already playing
|
2022-11-18 23:29:36 +00:00
|
|
|
* On entry: X - oscillator number 0-3, Y - amplitude to set
|
2022-11-18 00:38:21 +00:00
|
|
|
* Preserves X & Y
|
|
|
|
MOCKAMP PHX
|
2022-11-18 23:29:36 +00:00
|
|
|
CPX #$00 ; Noise channel
|
2022-11-28 02:55:40 +00:00
|
|
|
BEQ :NOISE
|
2022-11-18 23:29:36 +00:00
|
|
|
TXA ; Add 7 to get register
|
|
|
|
CLC
|
|
|
|
ADC #7
|
|
|
|
TAX
|
2022-11-19 05:39:38 +00:00
|
|
|
TYA ; Amplitude 0..255
|
|
|
|
LSR ; Divide by 16
|
|
|
|
LSR
|
2022-11-18 23:29:36 +00:00
|
|
|
LSR
|
|
|
|
LSR ; Now 0..15
|
2022-11-28 02:55:40 +00:00
|
|
|
JSR MOCKWRT1 ; Write value to AY-3 register
|
|
|
|
PLX
|
|
|
|
RTS
|
|
|
|
:NOISE LDX #10 ; Chan C
|
|
|
|
TYA ; Amplitude 0..255
|
|
|
|
LSR ; Divide by 16
|
|
|
|
LSR
|
|
|
|
LSR
|
|
|
|
LSR ; Now 0..15
|
|
|
|
JSR MOCKWRT2 ; Write value to AY-3 register
|
|
|
|
PLX
|
2022-11-19 04:58:53 +00:00
|
|
|
RTS
|
2022-11-18 00:38:21 +00:00
|
|
|
|
|
|
|
|
2022-11-18 03:26:46 +00:00
|
|
|
* Mockingboard interrupt service routine - just calls generic audio ISR
|
2022-11-18 23:29:36 +00:00
|
|
|
MOCKISR CLD
|
2022-12-08 01:35:57 +00:00
|
|
|
LDA MOCK_6522_IFR ; Interrupt flag register
|
|
|
|
AND #$40 ; Bit 6
|
|
|
|
BEQ :NOTMB ; Wasn't Mockingboard IRQ
|
2022-11-28 02:55:40 +00:00
|
|
|
BIT MOCK_6522_T1CL ; Clear interrupt
|
2022-11-19 03:43:24 +00:00
|
|
|
JSR AUDIOISR
|
2022-11-19 00:26:20 +00:00
|
|
|
CLC ; CC indicates we serviced irq
|
|
|
|
RTS
|
2022-12-08 01:35:57 +00:00
|
|
|
:NOTMB SEC ; We did not handle irq
|
|
|
|
RTS
|
2022-11-18 03:26:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
**
|
|
|
|
** Private functions follow (ie: not part of driver API)
|
|
|
|
**
|
|
|
|
|
2022-11-28 02:55:40 +00:00
|
|
|
* Write to first AY-3
|
2022-11-18 03:26:46 +00:00
|
|
|
* On entry: A - value, X - register
|
2022-11-19 04:58:53 +00:00
|
|
|
* On exit: All regs preserved.
|
2022-11-28 02:55:40 +00:00
|
|
|
MOCKWRT1 PHY
|
2022-11-19 04:58:53 +00:00
|
|
|
STX MOCK_6522_ORA1 ; Latch the address
|
2022-11-18 03:26:46 +00:00
|
|
|
LDY #MOCK_AY_LATCH_ADDR
|
|
|
|
STY MOCK_6522_ORB1
|
|
|
|
|
|
|
|
LDY #MOCK_AY_INACTIVE ; Go inactive
|
|
|
|
STY MOCK_6522_ORB1
|
|
|
|
|
|
|
|
STA MOCK_6522_ORA1 ; Write data
|
|
|
|
LDY #MOCK_AY_WRITE
|
|
|
|
STY MOCK_6522_ORB1
|
|
|
|
|
|
|
|
LDY #MOCK_AY_INACTIVE ; Go inactive
|
|
|
|
STY MOCK_6522_ORB1
|
2022-11-28 02:55:40 +00:00
|
|
|
PLY
|
|
|
|
RTS
|
|
|
|
|
|
|
|
|
|
|
|
* Write to second AY-3
|
|
|
|
* On entry: A - value, X - register
|
|
|
|
* On exit: All regs preserved.
|
|
|
|
MOCKWRT2 PHY
|
|
|
|
STX MOCK_6522_ORA2 ; Latch the address
|
|
|
|
LDY #MOCK_AY_LATCH_ADDR
|
|
|
|
STY MOCK_6522_ORB2
|
|
|
|
|
|
|
|
LDY #MOCK_AY_INACTIVE ; Go inactive
|
|
|
|
STY MOCK_6522_ORB2
|
|
|
|
|
|
|
|
STA MOCK_6522_ORA2 ; Write data
|
|
|
|
LDY #MOCK_AY_WRITE
|
|
|
|
STY MOCK_6522_ORB2
|
|
|
|
|
|
|
|
LDY #MOCK_AY_INACTIVE ; Go inactive
|
2022-11-18 03:26:46 +00:00
|
|
|
STY MOCK_6522_ORB2
|
2022-11-19 04:58:53 +00:00
|
|
|
PLY
|
2022-11-18 03:26:46 +00:00
|
|
|
RTS
|
|
|
|
|