mockingboard: work out a bit more how the 6522 works

This commit is contained in:
Vince Weaver 2018-02-03 17:50:32 -05:00
parent be03724db6
commit 54690d0f94
2 changed files with 178 additions and 44 deletions

View File

@ -1850,4 +1850,5 @@ ksptheme:
.byte $EE,$00,$3E,$01,$00,$00,$00,$38,$0B,$0B,$00,$00,$00,$FF ; 01821
.byte $EE,$00,$3E,$01,$00,$00,$00,$38,$04,$04,$00,$00,$00,$FF ; 01822
.byte $EE,$00,$3E,$01,$00,$00,$00,$38,$00,$00,$00,$00,$00,$FF ; 01823
.byte $FF,$FF
; Total size = 21888 bytes

View File

@ -1,51 +1,10 @@
; http://macgui.com/usenet/?group=2&id=8366
; Mockingboad programming:
; + Has two 6522 I/O chips
; + Has two 6522 I/O chips connected to two AY-3-8910 chips
; + Optionally has some speech chips controlled via the outport on the AY
; + Often in slot 4
; $C400 ORB1 function to perform, OUT 1
; $C401 ORA1 data, OUT 1
; $C402 DDRB1 data direction, OUT 1
; $C403 DDRA1 data direction, OUT 1
; $C480 ORB2 function to perform, OUT 2
; $C481 ORA2 data, OUT 2
; $C482 DDRB2 data direction, OUT 2
; $C483 DDRA2 data direction, OUT 2
; To Initialize the 6522s: Store $FF at the DDRxx addresses
; Your program gets access to a PSG via the 6522 by using a few basic
; Function codes which set the PSG's I/O control lines:
;
; Set Inactive = $04 Set PSG Reg# = $07 Write Data = $06 Reset = $00
;
; To Write to a PSG register: Tell the PSG which Register you wish to access
; (i.e. Set the "current register" #) and Write the data. This is easiest to
; do with subroutines to handle the basic Functions.
;
; Example Subroutines (for Output Channel 1):
;
; Set Reg # 1000: A9 07 8D 00 C4 A9 04 8D 00 C4 60
; Write Data 100B: A9 06 8D 00 C4 A9 04 8D 00 C4 60
; Notice that each Function sub ends by setting the PSG control lines to
; Inactive.
; Similarly, to do a Reset (set all PSG regs to zero) ...
; Reset 1016: A9 00 8D 00 C4 A9 04 8D 00 C4 60
; To put the value $55 in PSG Register 02 (Channel B Freq. fine) ....
; 1080: A9 02 put Reg# in A
; 1082: 8D 01 C4 store A at the Data address ORA1
; 1085: 20 00 10 JSR to Set Reg# (sets "current register" to Register
; 2)
; 1088: A9 55 put the value $55 in A
; 108A: 8D 01 C4 store A at the Data address ORA1
; 108D: 20 0B 10 JSR to Write Data ($55 goes into PSG Register 2)
; 1090: 60 Exit from subroutine
; TODO: how to auto-detect?
.include "zp.inc"
@ -55,7 +14,181 @@
jsr HOME
jsr TEXT
lda #0
sta DRAW_PAGE
sta CH
sta CV
lda #<mocking_message
sta OUTL
lda #>mocking_message
sta OUTH
jsr move_and_print
;============================
; Init the Mockingboard
;============================
jsr mockingboard_init
jsr reset_ay_left
jsr reset_ay_right
;===========================
; load pointer to the music
;===========================
lda #<ksptheme
sta INL
lda #>ksptheme
sta OUTL
play_loop:
delay_a_bit:
lda #86
jsr WAIT ; delay 1/2(26+27A+5A^2) us
; 50Hz = 20ms = 20000us
; 40000 = 26+27A+5A^2
; 5a^2+27a-39974 = 0
; A = 86.75
done_play:
lda #0
sta CH
lda #2
sta CV
lda #<done_message
sta OUTL
lda #>done_message
sta OUTH
jsr move_and_print
forever_loop:
jmp forever_loop
; left speaker
MOCK_6522_ORB1 EQU $C400 ; function to perform, OUT 1
MOCK_6522_ORA1 EQU $C401 ; data, OUT 1
MOCK_6522_DDRB1 EQU $C402 ; data direction, OUT 1
MOCK_6522_DDRA1 EQU $C403 ; data direction, OUT 1
; right speaker
MOCK_6522_ORB2 EQU $C480 ; function to perform, OUT 2
MOCK_6522_ORA2 EQU $C481 ; data, OUT 2
MOCK_6522_DDRB2 EQU $C482 ; data direction, OUT 2
MOCK_6522_DDRA2 EQU $C483 ; data direction, OUT 2
; AY-3-8910 commands on port B
; RESET BDIR BC1
MOCK_AY_RESET EQU $0 ; 0 0 0
MOCK_AY_INACTIVE EQU $4 ; 1 0 0
MOCK_AY_READ EQU $5 ; 1 0 1
MOCK_AY_WRITE EQU $6 ; 1 1 0
MOCK_AY_LATCH_ADDR EQU $7 ; 1 1 1
;========================
; Mockingboard card
; Essentially two 6522s hooked to the Apple II bus
; Connected to AY-3-8910 chips
; PA0-PA7 on 6522 connected to DA0-DA7 on AY
; PB0 on 6522 connected to BC1
; PB1 on 6522 connected to BDIR
; PB2 on 6522 connected to RESET
;========================
; Mockingboard Init
;========================
mockingboard_init:
; Initialize the 6522s
; set the data direction for all pins of PortA/PortB to be output
lda #$ff ; all output (1)
sta MOCK_6522_DDRB1
sta MOCK_6522_DDRA1
sta MOCK_6522_DDRB2
sta MOCK_6522_DDRA2
rts
;======================
; Reset Left AY-3-8910
;======================
reset_ay_left:
lda #MOCK_AY_RESET
sta MOCK_6522_ORB1
lda #MOCK_AY_INACTIVE
sta MOCK_6522_ORB1
rts
;======================
; Reset Right AY-3-8910
;======================
reset_ay_right:
lda #MOCK_AY_RESET
sta MOCK_6522_ORB2
lda #MOCK_AY_INACTIVE
sta MOCK_6522_ORB2
rts
; Write sequence
; Inactive -> Latch Address -> Inactive -> Write Data -> Inactive
;=======================
; Write Right AY-3-8910
;=======================
; register in X
; value in Y
write_right_ay:
; address
stx MOCK_6522_ORA1 ; put address on PA
lda #MOCK_AY_LATCH_ADDR ; latch_address on PB
sta MOCK_6522_ORB1
lda #MOCK_AY_INACTIVE ; go inactive
sta MOCK_6522_ORB1
; value
sty MOCK_6522_ORA1 ; put value on PA
lda #MOCK_AY_WRITE ; write on PB
sta MOCK_6522_ORB1
lda #MOCK_AY_INACTIVE ; go inactive
sta MOCK_6522_ORB1
rts
;=======================
; Write Left AY-3-8910
;=======================
; register in X
; value in Y
write_left_ay:
; address
stx MOCK_6522_ORA2 ; put address on PA
lda #MOCK_AY_LATCH_ADDR ; latch_address on PB
sta MOCK_6522_ORB2
lda #MOCK_AY_INACTIVE ; go inactive
sta MOCK_6522_ORB2
; value
sty MOCK_6522_ORA2 ; put value on PA
lda #MOCK_AY_WRITE ; write on PB
sta MOCK_6522_ORB2
lda #MOCK_AY_INACTIVE ; go inactive
sta MOCK_6522_ORB2
rts
;routines
.include "../asm_routines/gr_offsets.s"
.include "../asm_routines/text_print.s"
; music
.include "ksptheme_uncompressed.inc"
mocking_message: .asciiz "ASSUMING MOCKINGBOARD IN SLOT #4"
done_message: .asciiz "DONE PLAYING"