double: add mockingboard files

This commit is contained in:
Vince Weaver 2023-05-11 00:42:40 -04:00
parent 2ecf50f2c6
commit 5211fd633a
5 changed files with 369 additions and 5 deletions

View File

@ -27,6 +27,7 @@ double.o: double.s \
pt3_lib_mockingboard_setup.s pt3_lib_detect_model.s \
zx02_optim.s copy_400.s gr_offsets.s vblank.s \
lc_detect.s text_print.s title.s gr_fast_clear.s \
interrupt_handler.s pt3_lib_mockingboard_patch.s \
graphics/sworg_hgr.hgr.zx02 \
graphics/sworg_dhgr.aux.zx02 \
graphics/sworg_dhgr.bin.zx02 \

View File

@ -154,6 +154,41 @@ no_language_card:
done_language_card:
;===================================
; Detect Mockingboard
;===================================
PT3_ENABLE_APPLE_IIC = 1
; detect mockingboard
jsr mockingboard_detect
bcc mockingboard_notfound
mockingboard_found:
; print detected location
lda #'S'+$80 ; change NO to slot
sta $7d0+30
lda MB_ADDR_H ; $C4 = 4, want $B4 1100 -> 1011
and #$87
ora #$30
sta $7d0+31 ; 23,31
; NOTE: in this game we need both language card && mockingboard
; to enable mockingboard music
lda SOUND_STATUS
and #SOUND_IN_LC
beq dont_enable_mc
lda SOUND_STATUS
ora #SOUND_MOCKINGBOARD
sta SOUND_STATUS
dont_enable_mc:
mockingboard_notfound:
skip_all_checks:
@ -500,8 +535,10 @@ wait_until_keypress:
.include "pt3_lib_detect_model.s"
; .include "pt3_lib_mockingboard_setup.s"
; .include "pt3_lib_mockingboard_detect.s"
.include "pt3_lib_mockingboard_detect.s"
.include "pt3_lib_mockingboard_setup.s"
.include "interrupt_handler.s"
.include "pt3_lib_mockingboard_patch.s"
.include "zx02_optim.s"

View File

@ -0,0 +1,187 @@
;================================
;================================
; mockingboard 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
; Note: the IIc is much more complicated
; its firmware tries to decode the proper source
; based on various things, including screen hole values
; we bypass that by switching out ROM and replacing the
; $fffe vector with this, but that does mean we have
; to be sure status flag and accumulator set properly
interrupt_handler:
php ; save status flags
cld ; clear decimal mode
pha ; save A ; 3
; A is saved in $45 by firmware
txa
pha ; save X
tya
pha ; save Y
; inc $0404 ; debug (flashes char onscreen)
inc TIMER_COUNT
pt3_irq_smc1:
bit MOCK_6522_T1CL ; clear 6522 interrupt by reading T1C-L ; 4
lda DONE_PLAYING ; 3
beq ym_play_music ; if song done, don't play music ; 3/2nt
jmp done_pt3_irq_handler ; 3
;============
; 13
ym_play_music:
; see if need to pre-load next chunk
lda BASE_FRAME_L
cmp #1
bne no_preload_chunk
lda BASE_FRAME_H
and #1
bne no_preload_chunk
inc LOAD_NEXT_CHUNK ; defer this until after interrupt
no_preload_chunk:
lda BASE_FRAME_L ; reset frame pointer to beginning
sta CURRENT_FRAME_L
lda BASE_FRAME_H
sta CURRENT_FRAME_H
ldx #0
frame_loop:
ldy #0
lda (CURRENT_FRAME_L),Y
cmp #$ff
bne all_good
cpx #1 ; see if A coarse is $FF
beq go_next_chunk ; if so, end of song, loop
all_good:
jsr update_ay_register ; output to the AY
clc
lda CURRENT_FRAME_H ; next register set is 2 pages away
adc #$2 ; was 4
sta CURRENT_FRAME_H
inx
cpx #12 ; only output 11 regs
bne frame_loop
inc BASE_FRAME_L ; increment frame ptr (16bit)
bne not_oflo
inc BASE_FRAME_H ; wrap to next page
lda BASE_FRAME_H ; if too big, go to next chunk
and #$3
cmp #$2 ; was D4
bne not_oflo
go_next_chunk:
lda CHUNK_NEXT_PLAY ; toggle $D0/$E8
eor #$38
sta CHUNK_NEXT_PLAY
sta BASE_FRAME_H
lda #0
sta BASE_FRAME_L ; in case song ended early
inc CURRENT_CHUNK ; point to next chunk
; inc LOAD_NEXT_CHUNK ; defer this until after interrupt
; jsr load_song_chunk
not_oflo:
exit_interrupt:
pla
tay ; restore Y
pla
tax ; restore X
pla ; restore a ; 4
; on II+/IIe (but not IIc) we need to do this?
interrupt_smc:
lda $45 ; restore A
plp
rti ; return from interrupt ; 6
;============
; typical
; ???? cycles
;=========================
; update ay_register
; reg in X
; value in A
update_ay_register:
pt3_irq_smc2:
stx MOCK_6522_ORA1 ; put address on PA1 ; 4
stx MOCK_6522_ORA2 ; put address on PA2 ; 4
ldy #MOCK_AY_LATCH_ADDR ; latch_address for PB1 ; 2
pt3_irq_smc3:
sty MOCK_6522_ORB1 ; latch_address on PB1 ; 4
sty MOCK_6522_ORB2 ; latch_address on PB2 ; 4
ldy #MOCK_AY_INACTIVE ; go inactive ; 2
pt3_irq_smc4:
sty MOCK_6522_ORB1 ; 4
sty MOCK_6522_ORB2 ; 4
; value
pt3_irq_smc5:
sta MOCK_6522_ORA1 ; put value on PA1 ; 4
sta MOCK_6522_ORA2 ; put value on PA2 ; 4
lda #MOCK_AY_WRITE ; ; 2
pt3_irq_smc6:
sta MOCK_6522_ORB1 ; write on PB1 ; 4
sty MOCK_6522_ORB1 ; 4
pt3_irq_smc7:
sta MOCK_6522_ORB2 ; write on PB2 ; 4
sty MOCK_6522_ORB2 ; 4
rts
done_pt3_irq_handler:
disable_music:
sei
ldx #1
stx DONE_PLAYING
jsr clear_ay_both
; mute the sound
ldx #7
lda #$ff
jsr update_ay_register
rts

View File

@ -0,0 +1,120 @@
;===================================================================
; code to patch mockingboard if not in slot#4
;===================================================================
; this is the brute force version, we have to patch 39 locations
; see further below if you want to try a smaller, more dangerous, patch
.if 0
mockingboard_patch:
lda MB_ADDR_H
sta pt3_irq_smc1+2 ; 1
sta pt3_irq_smc2+2 ; 2
sta pt3_irq_smc2+5 ; 3
sta pt3_irq_smc3+2 ; 4
sta pt3_irq_smc3+5 ; 5
sta pt3_irq_smc4+2 ; 6
sta pt3_irq_smc4+5 ; 7
sta pt3_irq_smc5+2 ; 8
sta pt3_irq_smc5+5 ; 9
sta pt3_irq_smc6+2 ; 10
sta pt3_irq_smc6+5 ; 11
sta pt3_irq_smc7+2 ; 12
sta pt3_irq_smc7+5 ; 13
sta mock_init_smc1+2 ; 14
sta mock_init_smc1+5 ; 15
sta mock_init_smc2+2 ; 16
sta mock_init_smc2+5 ; 17
sta reset_ay_smc1+2 ; 18
sta reset_ay_smc2+2 ; 19
sta reset_ay_smc3+2 ; 20
sta reset_ay_smc4+2 ; 21
sta write_ay_smc1+2 ; 22
sta write_ay_smc1+5 ; 23
sta write_ay_smc2+2 ; 24
sta write_ay_smc2+5 ; 25
sta write_ay_smc3+2 ; 26
sta write_ay_smc3+5 ; 27
sta write_ay_smc4+2 ; 28
sta write_ay_smc4+5 ; 29
sta write_ay_smc5+2 ; 30
sta write_ay_smc5+5 ; 31
sta write_ay_smc6+2 ; 32
sta write_ay_smc6+5 ; 33
sta setup_irq_smc1+2 ; 34
sta setup_irq_smc2+2 ; 35
sta setup_irq_smc3+2 ; 36
sta setup_irq_smc4+2 ; 37
sta setup_irq_smc5+2 ; 38
sta setup_irq_smc6+2 ; 39
rts
.endif
;===================================================================
; dangerous code to patch mockingboard if not in slot#4
;===================================================================
; this code patches any $C4 value to the proper slot# if not slot4
; this can be dangerous, it might over-write other important values
; that should be $C4
; safer ways to do this:
; only do this if 2 bytes after a LDA/STA/LDX/STX
; count total and if not 39 then print error message
mockingboard_patch:
; from mockingboard_init $1BBF
; to done_pt3_irq_handler $1D85
ldx MB_ADDR_H
ldy #0
lda #<mockingboard_init
sta MB_ADDR_L
lda #>mockingboard_init
sta MB_ADDR_H
mb_patch_loop:
lda (MB_ADDR_L),Y
cmp #$C4
bne mb_patch_nomatch
txa
sta (MB_ADDR_L),Y
mb_patch_nomatch:
; 16-bit increment
inc MB_ADDR_L
bne mb_patch_oflo
inc MB_ADDR_H
mb_patch_oflo:
lda MB_ADDR_H
cmp #>done_pt3_irq_handler
bne mb_patch_loop
lda MB_ADDR_L
cmp #<done_pt3_irq_handler
bne mb_patch_loop
mb_patch_done:
rts

View File

@ -20,8 +20,23 @@ BASH = $29
V2 = $2D
COLOR = $30
; ym player
CURRENT_FRAME_L = $70
CURRENT_FRAME_H = $71
BASE_FRAME_L = $72
BASE_FRAME_H = $73
CURRENT_CHUNK = $74
TIME_MINUTES = $75
TIME_SECONDS = $76
CURSOR_X = $77
DRAW_PAGE = $7A
CHUNK_NEXT_LOAD = $7D
CHUNK_NEXT_PLAY = $7E
LOAD_NEXT_CHUNK = $7F
TIMER_COUNT = $81
APPLEII_MODEL = $8B
SOUND_STATUS = $DE
@ -39,11 +54,15 @@ HGRPAGE = $E6
TEMPY = $F0
XX = $F1
; rest of pt3_player
LOOP = $F4
MB_VALUE = $F5
MB_ADDR_L = $F6
MB_ADDR_H = $F7
DONE_PLAYING = $F8
DONE_SONG = $F9
MB_VALUE = $F7
MB_ADDR_L = $F8
MB_ADDR_H = $F9
YPOS = $FA
TCOLOR = $FB