From 35766d90b94ed9dec7586bc38059a60ca9d337d9 Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Thu, 12 Sep 2019 00:21:08 -0400 Subject: [PATCH] pt3_lib: move most things to lib files now --- pt3_lib/Makefile | 5 +- pt3_lib/OPTIMIZATION.txt | 47 ------ ...ockingboard_a.s => pt3_lib_mockingboard.s} | 141 ++++++++++++++++++ pt3_lib/pt3_test.s | 131 +++------------- 4 files changed, 161 insertions(+), 163 deletions(-) delete mode 100644 pt3_lib/OPTIMIZATION.txt rename pt3_lib/{mockingboard_a.s => pt3_lib_mockingboard.s} (67%) diff --git a/pt3_lib/Makefile b/pt3_lib/Makefile index 3600bb13..4c1c5f1b 100644 --- a/pt3_lib/Makefile +++ b/pt3_lib/Makefile @@ -22,8 +22,9 @@ PT3_TEST: pt3_test.o ld65 -o PT3_TEST pt3_test.o -C ../linker_scripts/apple2_1000.inc pt3_test.o: pt3_test.s \ - pt3_lib_init.s pt3_lib_core.s interrupt_handler.s \ - zp.inc + pt3_lib_init.s pt3_lib_core.s pt3_lib_irq_handler.s \ + pt3_lib_mockingboard.s \ + interrupt_handler.s zp.inc ca65 -o pt3_test.o pt3_test.s -l pt3_test.lst # diff --git a/pt3_lib/OPTIMIZATION.txt b/pt3_lib/OPTIMIZATION.txt deleted file mode 100644 index 8c40f6b7..00000000 --- a/pt3_lib/OPTIMIZATION.txt +++ /dev/null @@ -1,47 +0,0 @@ -Code Optimization -~~~~~~~~~~~~~~~~~ - - The original working code is about 4k (not counting the pt3 file) - and has an overhead of roughly 20% when playing a song interrupt-driven - at 50Hz. - - I'm keeping some stats here as I try to optimize the size and speed. - - Song: "Summer of Rain" SR.PT3 - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - lz4 compressed - pt3 size: raw size: ym5 size: pt3.lz4: - 3871 137015 7637 1793 - - - Size=pt3lib_end - note_a - - Decoder Type size ZP use raw decode total CPU overhead - ------------------------------------------------------------- - Original 3407 22B 1F.22 31s 171s 18% - VolTableGen 3302 22B 20.0E 32s 171s 19% - SizeOpts 3262 22B 20.0A 32s 171s 19% - MoreSizeOpt 3203 22B 1F.1D 31s 171s 18% - Qkumba#1 2937 ?? 1D.18 29s 171s 17% - Qkumba#2 2879 ?? 1C.18 28s 171s 16% - Qkumba#3+vmw 2816 ?? 1C.22 28s 171s 16% - -Times: Validated - BH.PT3: 10.0B 16 1:33 93 17.2% - CH.PT3: 1D.12 29 2:49 169 17.2% - CR.PT3: 0F.25 15 1:30 90 16.7% Yes - DF.PT3: 19.1C 25 2:27 147 17.0% - EA.PT3: 1E.13 30 2:53 173 17.3% Yes - F4.PT3: 18.1D 24 2:16 136 17.6% - FC.PT3: 20.24 32 3:12 192 16.7% - FR.PT3: 0B.0A 11 1:01 61 18.0% - HI.PT3: 11.19 17 1:34 94 18.0% - I2.PT3: 1E.0C 30 2:59 179 16.8% - IT.PT3: 16.19 22 2:11 131 16.8% Yes - MB.PT3: 14.08 20 1:59 119 16.8% - ND.PT3: 14.1C 20 1:52 112 17.9% - OS.PT3: 13.24 19 1:48 108 17.6% - RI.PT3: 0F.03 15 1:26 86 17.4% - SD.PT3: 11.16 17 1:40 100 17.0% - SR.PT3: 1F.22 31 2:51 171 18.1% - VC.PT3: 1B.20 27 2:40 160 16.9% diff --git a/pt3_lib/mockingboard_a.s b/pt3_lib/pt3_lib_mockingboard.s similarity index 67% rename from pt3_lib/mockingboard_a.s rename to pt3_lib/pt3_lib_mockingboard.s index dd92ff55..42c07b9e 100644 --- a/pt3_lib/mockingboard_a.s +++ b/pt3_lib/pt3_lib_mockingboard.s @@ -239,3 +239,144 @@ mb4_not_in_this_slot: ldx #00 beq done_mb4_detect + + ;============================= + ; Setup + ;============================= +pt3_setup_interrupt: + + ;=========================== + ; Check for Apple IIc + ;=========================== + ; it does interrupts differently + + lda $FBB3 ; IIe and newer is $06 + cmp #6 + beq apple_iie_or_newer + + jmp 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 $ffff + + lda #$EA ; nop out the "lda $45" in the irq hand + sta interrupt_smc + sta interrupt_smc+1 + +done_apple_detect: + + + ;========================= + ; 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 + ;============================ + + 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 + + rts + + + + ;================================== + ; Print mockingboard detect message + ;================================== + ; note: on IIc must do this before enabling interrupt + ; as we disable ROM (COUT won't work?) + +print_mockingboard_detect: + + ; print detection message + ldy #0 +print_mocking_message: + lda mocking_message,Y ; load loading message + beq done_mocking_message + ora #$80 + jsr COUT + iny + jmp print_mocking_message +done_mocking_message: + jsr CROUT1 + + rts + +print_mocking_notfound: + + ldy #0 +print_not_message: + lda not_message,Y ; load loading message + beq print_not_message_done + ora #$80 + jsr COUT + iny + jmp print_not_message +print_not_message_done: + rts + +print_mocking_found: + ldy #0 +print_found_message: + lda found_message,Y ; load loading message + beq done_found_message + ora #$80 + jsr COUT + iny + jmp print_found_message +done_found_message: + + rts + +;========= +; strings +;========= +mocking_message: .asciiz "LOOKING FOR MOCKINGBOARD IN SLOT #4" +not_message: .byte "NOT " +found_message: .asciiz "FOUND" + + diff --git a/pt3_lib/pt3_test.s b/pt3_lib/pt3_test.s index 6178e0a9..6f1688f8 100644 --- a/pt3_lib/pt3_test.s +++ b/pt3_lib/pt3_test.s @@ -28,45 +28,6 @@ pt3_setup: jsr HOME jsr TEXT - ;=========================== - ; Check for Apple IIc - ;=========================== - ; it does interrupts differently - - lda $FBB3 ; IIe and newer is $06 - cmp #6 - beq apple_iie_or_newer - - jmp 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 $ffff - - lda #$EA ; nop out the "lda $45" in the irq hand - sta interrupt_smc - sta interrupt_smc+1 - -done_apple_detect: - ;=============== ; init variables ;=============== @@ -75,47 +36,31 @@ done_apple_detect: sta DONE_PLAYING sta LOOP - ;======================= ; Detect mockingboard ;======================== - ; print detection message - ldy #0 -print_mocking_message: - lda mocking_message,Y ; load loading message - beq done_mocking_message - ora #$80 - jsr COUT - iny - jmp print_mocking_message -done_mocking_message: - jsr CROUT1 + jsr print_mockingboard_detect jsr mockingboard_detect_slot4 ; call detection routine cpx #$1 beq mockingboard_found - ldy #0 -print_not_message: - lda not_message,Y ; load loading message - beq forever_loop - ora #$80 - jsr COUT - iny - jmp print_not_message - + jsr print_mocking_notfound + ;jmp forever_loop + ; can't detect on IIc so just run with it anyway + jmp setup_interrupt mockingboard_found: - ldy #0 -print_found_message: - lda found_message,Y ; load loading message - beq done_found_message - ora #$80 - jsr COUT - iny - jmp print_found_message -done_found_message: + + jsr print_mocking_found + +setup_interrupt: + ;======================= + ; Set up 50Hz interrupt + ;======================== + + jsr pt3_setup_interrupt ;============================ ; Init the Mockingboard @@ -125,42 +70,6 @@ done_found_message: 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 $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 ;================== @@ -196,17 +105,11 @@ forever_loop: ;========= ;routines ;========= -.include "mockingboard_a.s" -.include "interrupt_handler.s" + .include "pt3_lib_core.s" .include "pt3_lib_init.s" - -;========= -; strings -;========= -mocking_message: .asciiz "LOOKING FOR MOCKINGBOARD IN SLOT #4" -not_message: .byte "NOT " -found_message: .asciiz "FOUND" +.include "pt3_lib_mockingboard.s" +.include "interrupt_handler.s" ;============= ; include song