pt3_lib: move most things to lib files now

This commit is contained in:
Vince Weaver 2019-09-12 00:21:08 -04:00
parent eb5ea2c796
commit 35766d90b9
4 changed files with 161 additions and 163 deletions

View File

@ -22,8 +22,9 @@ PT3_TEST: pt3_test.o
ld65 -o PT3_TEST pt3_test.o -C ../linker_scripts/apple2_1000.inc ld65 -o PT3_TEST pt3_test.o -C ../linker_scripts/apple2_1000.inc
pt3_test.o: pt3_test.s \ pt3_test.o: pt3_test.s \
pt3_lib_init.s pt3_lib_core.s interrupt_handler.s \ pt3_lib_init.s pt3_lib_core.s pt3_lib_irq_handler.s \
zp.inc pt3_lib_mockingboard.s \
interrupt_handler.s zp.inc
ca65 -o pt3_test.o pt3_test.s -l pt3_test.lst ca65 -o pt3_test.o pt3_test.s -l pt3_test.lst
# #

View File

@ -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%

View File

@ -239,3 +239,144 @@ mb4_not_in_this_slot:
ldx #00 ldx #00
beq done_mb4_detect 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 $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:
;=========================
; 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
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"

View File

@ -28,45 +28,6 @@ pt3_setup:
jsr HOME jsr HOME
jsr TEXT 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 $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:
;=============== ;===============
; init variables ; init variables
;=============== ;===============
@ -75,47 +36,31 @@ done_apple_detect:
sta DONE_PLAYING sta DONE_PLAYING
sta LOOP sta LOOP
;======================= ;=======================
; Detect mockingboard ; Detect mockingboard
;======================== ;========================
; print detection message jsr print_mockingboard_detect
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 mockingboard_detect_slot4 ; call detection routine jsr mockingboard_detect_slot4 ; call detection routine
cpx #$1 cpx #$1
beq mockingboard_found beq mockingboard_found
ldy #0 jsr print_mocking_notfound
print_not_message: ;jmp forever_loop
lda not_message,Y ; load loading message ; can't detect on IIc so just run with it anyway
beq forever_loop jmp setup_interrupt
ora #$80
jsr COUT
iny
jmp print_not_message
mockingboard_found: mockingboard_found:
ldy #0
print_found_message: jsr print_mocking_found
lda found_message,Y ; load loading message
beq done_found_message setup_interrupt:
ora #$80 ;=======================
jsr COUT ; Set up 50Hz interrupt
iny ;========================
jmp print_found_message
done_found_message: jsr pt3_setup_interrupt
;============================ ;============================
; Init the Mockingboard ; Init the Mockingboard
@ -125,42 +70,6 @@ done_found_message:
jsr reset_ay_both jsr reset_ay_both
jsr clear_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 ; init song
;================== ;==================
@ -196,17 +105,11 @@ forever_loop:
;========= ;=========
;routines ;routines
;========= ;=========
.include "mockingboard_a.s"
.include "interrupt_handler.s"
.include "pt3_lib_core.s" .include "pt3_lib_core.s"
.include "pt3_lib_init.s" .include "pt3_lib_init.s"
.include "pt3_lib_mockingboard.s"
;========= .include "interrupt_handler.s"
; strings
;=========
mocking_message: .asciiz "LOOKING FOR MOCKINGBOARD IN SLOT #4"
not_message: .byte "NOT "
found_message: .asciiz "FOUND"
;============= ;=============
; include song ; include song