rasterbars_sound: sound actually works

This commit is contained in:
Vince Weaver 2019-06-18 16:12:26 -04:00
parent aa1ad5752a
commit 9b3ebf7c93
2 changed files with 167 additions and 17 deletions

View File

@ -129,18 +129,6 @@ mb_no_write:
mb_skip_13:
; stop playing for now
; quiet down the Mockingboard
; (otherwise will be stuck on last note)
quiet_exit:
stx DONE_PLAYING
jsr clear_ay_both
;ldx #$ff ; also mute the channel
stx AY_REGISTERS+7 ; just in case
;=================================
; Finally done with this interrupt
;=================================
@ -168,3 +156,17 @@ interrupt_smc:
; ???? cycles
; stop playing for now
; quiet down the Mockingboard
; (otherwise will be stuck on last note)
quiet_exit:
stx DONE_PLAYING
jsr clear_ay_both
;ldx #$ff ; also mute the channel
stx AY_REGISTERS+7 ; just in case
jmp done_interrupt

View File

@ -24,6 +24,144 @@ start_rasterbars:
lda #0
sta DRAW_PAGE
sta DONE_PLAYING
sta DONE_SONG
lda #1
sta LOOP
;=================
; Configure mockingboard
;============================
; Check for Apple II/II+/IIc
;============================
lda $FBB3 ; IIe and newer is $06
cmp #6
beq apple_iie_or_newer
; Apple II/II+
bne done_apple_detect
apple_iie_or_newer:
lda $FBC0 ; 0 on a IIc
bne done_apple_detect
apple_iic:
; activate IIc mockingboard?
; this might only be necessary to allow detection
; I get the impression the Mockingboard 4c activates
; when you access any of the 6522 ports in Slot 4
lda #$ff
sta $C403
sta $C404
; bypass the firmware interrupt handler
; should we do this on IIe too? probably faster
sei ; disable interrupts
lda $c08b ; disable ROM (enable language card)
lda $c08b
lda #<interrupt_handler
sta $fffe
lda #>interrupt_handler
sta $ffff
lda #$EA ; nop out the "lda $45" in the irq hand
sta interrupt_smc
sta interrupt_smc+1
done_apple_detect:
;=======================
; Detect mockingboard
;========================
; Note, we do this, but then ignore it, as sometimes
; the test fails and then you don't get music.
; In theory this could do bad things if you had something
; easily confused in slot4, but that's probably not an issue.
; print detection message
; lda #<mocking_message ; load loading message
; sta OUTL
; lda #>mocking_message
; sta OUTH
; jsr move_and_print ; print it
jsr mockingboard_detect_slot4 ; call detection routine
cpx #$1
beq mockingboard_found
; lda #<not_message ; if not found, print that
; sta OUTL
; lda #>not_message
; sta OUTH
; inc CV
; jsr move_and_print
; jmp forever_loop ; and wait forever
mockingboard_found:
; lda #<found_message ; print found message
; sta OUTL
; lda #>found_message
; sta OUTH
; inc CV
; jsr move_and_print
;============================
; Init the Mockingboard
;============================
jsr mockingboard_init
jsr reset_ay_both
jsr clear_ay_both
;=========================
; Setup Interrupt Handler
;=========================
; Vector address goes to 0x3fe/0x3ff
; FIXME: should chain any existing handler
lda #<interrupt_handler
sta $03fe
lda #>interrupt_handler
sta $03ff
;============================
; Enable 50Hz clock on 6522
;============================
sei ; disable interrupts just in case
lda #$40 ; Continuous interrupts, don't touch PB7
sta $C40B ; ACR register
lda #$7F ; clear all interrupt flags
sta $C40E ; IER register (interrupt enable)
lda #$C0
sta $C40D ; IFR: 1100, enable interrupt on timer one oflow
sta $C40E ; IER: 1100, enable timer one interrupt
lda #$E7
sta $C404 ; write into low-order latch
lda #$4f
sta $C405 ; write into high-order latch,
; load both values into counter
; clear interrupt and start counting
; 4fe7 / 1e6 = .020s, 50Hz
;==================
; init song
;==================
jsr pt3_init_song
;=============================
; Load graphic page0
@ -105,18 +243,28 @@ start_rasterbars:
; ====
; 310
; - 3 for jmp
; 307
; -3 for jmp
; -2 for cli
; 305
; Try X=9 Y=6 cycles=307
; Try X=14 Y=4 cycles=305
ldy #6 ; 2
loopA: ldx #9 ; 2
ldy #4 ; 2
loopA: ldx #14 ; 2
loopB: dex ; 2
bne loopB ; 2nt/3
dey ; 2
bne loopA ; 2nt/3
;============================
; Enable 6502 interrupts
;============================
start_interrupts:
cli ; clear interrupt mask ; 2
jmp display_loop ; 3
.align $100