From cbae19e92f75860f270cfca9c54b388e8b9f8063 Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Wed, 7 Feb 2018 12:44:37 -0500 Subject: [PATCH] mockingboard: interrupt playing works now --- mockingboard/interrupt_test.s | 14 +-- mockingboard/ksp_theme_interrupt.s | 160 +++++++++++++++++++++-------- mockingboard/mock_test.dsk | Bin 143360 -> 143360 bytes mockingboard/zp.inc | 2 + 4 files changed, 127 insertions(+), 49 deletions(-) diff --git a/mockingboard/interrupt_test.s b/mockingboard/interrupt_test.s index 4da80d55..e5781007 100644 --- a/mockingboard/interrupt_test.s +++ b/mockingboard/interrupt_test.s @@ -95,13 +95,15 @@ forever_loop: ;============================= ; simple interrupt handler ;============================= -interrupt_handler: - lda $45 ; the Apple II firmware messes with A when - ; detecting BRK, so the value in $45 is the real one? - ; also DISK II support uses this so you should disable - ; interrupts if messing with the disk? + ; On Apple II/6502 the interrupt handler jumps to address in 0xfffe + ; This is in the ROM, which saves the registers + ; on older IIe it saved A to $45 (which could mess with DISK II) + ; newer IIe doesn't do that. + ; It then calculates if it is a BRK or not (which trashes A) + ; Then it sets up the stack like an interrupt and calls 0x3fe - pha ; save A (hardware saved Pflags for us) +interrupt_handler: + pha ; save A bit $C404 ; can clear interrupt by reading T1C-L diff --git a/mockingboard/ksp_theme_interrupt.s b/mockingboard/ksp_theme_interrupt.s index c040eb66..4f956ee9 100644 --- a/mockingboard/ksp_theme_interrupt.s +++ b/mockingboard/ksp_theme_interrupt.s @@ -14,6 +14,11 @@ sta DRAW_PAGE sta CH sta CV + sta DONE_PLAYING + + lda #1 + sta MB_FRAME_DIFF + lda #mocking_message @@ -61,21 +66,108 @@ mockingboard_found: lda #>ksptheme sta INH -new_frame: - ldy #0 lda (INL),Y ; read in frame delay - cmp #$ff ; see if end - beq done_play ; if so, done + sta MB_FRAME_DIFF + inc INL ; FIXME: should check if we oflowed - tax -old_frame: - dex ; decrement the frame diff - beq bottom_regs ; if not there yet, delay - jsr delay_50Hz - jmp old_frame + ;========================= + ; Setup Interrupt Handler + ;========================= + ; Vector address goes to 0x3fe/0x3ff + ; FIXME: should chain any existing handler + lda #interrupt_handler + sta $03ff + + ;============================ + ; Enable 50Hz clock on 6522 + ;============================ + + lda #$40 ; Generate 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 + + ;============================ + ; Enable 6502 interrupts + ;============================ + ; + cli ; clear interrupt mask + + + ;============================ + ; Loop forever + ;============================ +playing_loop: + lda DONE_PLAYING + beq playing_loop + +done_play: + + ; FIXME: disable timer on 6522 + ; FIXME: unhook interrupt handler + + sei ; disable interrupts + + jsr clear_ay_left + jsr clear_ay_right + + lda #0 + sta CH + lda #3 + sta CV + lda #done_message + sta OUTH + jsr move_and_print + +forever_loop: + jmp forever_loop + + ;============================= + ;============================= + ; simple interrupt handler + ;============================= + ;============================= + ; On Apple II/6502 the interrupt handler jumps to address in 0xfffe + ; This is in the ROM, which saves the registers + ; on older IIe it saved A to $45 (which could mess with DISK II) + ; newer IIe doesn't do that. + ; It then calculates if it is a BRK or not (which trashes A) + ; Then it sets up the stack like an interrupt and calls 0x3fe + +interrupt_handler: + pha ; save A + ; Should we save X and Y too? + + bit $C404 ; can clear 6522 interrupt by reading T1C-L + + inc $0401 ; DEBUG: increment text char + + dec MB_FRAME_DIFF + bne done_interrupt + + + + + ldy #0 bottom_regs: - iny lda (INL),Y ; load low reg bitmask sta MASK ldx #$ff ; init to -1 @@ -139,6 +231,16 @@ top_regs_loop: jmp top_regs_loop done_with_masks: +new_frame_diff: + iny + lda (INL),Y ; read in frame delay + cmp #$ff ; see if end + bne not_done ; if so, done + inc DONE_PLAYING ; set done playing flag + jmp done_interrupt +not_done: + sta MB_FRAME_DIFF + iny clc tya @@ -148,40 +250,12 @@ done_with_masks: adc INH sta INH - jsr delay_50Hz - - jmp new_frame - -done_play: - - jsr clear_ay_left - jsr clear_ay_right - - lda #0 - sta CH - lda #3 - sta CV - lda #done_message - sta OUTH - jsr move_and_print - - -forever_loop: - jmp forever_loop +done_interrupt: + pla + rti -delay_50Hz: - - 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 - rts ;========= @@ -199,7 +273,7 @@ delay_50Hz: ;========= ; strings ;========= -mocking_message: .asciiz "ASSUMING MOCKINGBOARD IN SLOT #4" +mocking_message: .asciiz "LOOKING FOR MOCKINGBOARD IN SLOT #4" not_message: .byte "NOT " found_message: .asciiz "FOUND" done_message: .asciiz "DONE PLAYING" diff --git a/mockingboard/mock_test.dsk b/mockingboard/mock_test.dsk index 70905a22f37ff00e0dd9fa87d718d2e0c5917ed1..1177644629e1de1033fb0ed8b21e019c7ad9ade9 100644 GIT binary patch delta 1876 zcmZp8z|ru4V*`_+-7`joh(8KuzgIG}zH3!!Rb9Ed_1{Xt*8d7S1r*u^A25CpSa}{I z@=O&d=94C{@-l)y-C;GO!SvjVjCO*h0ureztr|Pa1XAC%Y9=TwoqW+mm1C#CN|x4l z3Ogr%G)(2u73>iBm9T(s5rcxz)(xkTBkhwvvNi6KjxJJz5kh4I`ncMSy|u9 zcVy*(Ufv@hdUBj0m)_FJAO2WCwKBA-tYiiTl?&VfK+8OISdP47WH~nFLe>I?$=Oj- z+}8ya_6RO}yyS_`?#UCPWYiJ-M*=4{{yF*o0_(HMKC*(XQ%*?CNc{tJ4@2tT*1wZ$ z49$h)1tFoSAP5Off5GW{FEXldBnyJWGkJ1CbSlqvM0oB2g(nlQ(Bv*7tg++h~*~D3BJVPnL6U`oOeg&;(q?(8vqhmFpP~3c)kM mbe>g=gCQ5xY+K97#5-srbBGjd7?F8lP()_OcAm?OUt$3M+&C8i delta 674 zcmZp8z|ru4V*`_+<7-BRh(8KuzgIG}zH3!!Rb9EE_1{Xt*8d9o1QdD%A25CpSa}5^ z@=O&d=94C{@&*!rW&Y%}C{^B-3=)})y^JhC>7}ld3k>Z9s{|xcRa!N6Rtu!QYt>9p zST*^gi7Mwlft4(+?||k^PE1MRF%s+$_?57LZxMrn_~eTzYD^h|ll5b?Ca*V&*vw=6 zg=bqcBcs4(#sEgH%}mMvSQjM}YzpMzn9OtI8&#dHKuu@g{>HYQsh05{@1_q-OF%3x zvFSXk7{A%QKo97((16}8pwI~k=!@`x-3<=ts|fyN2SWoUXwa5JgSG-1w9COkyBiX; zyCFfVj|f^3aL}g0g4TcAT1F;bn9D9Oesg?`?y?n7mu(YJXo0xw4BRE#1bk8iR$f5j wuS^Fe0al