trogdor: probably ill-advised new demo

This commit is contained in:
Vince Weaver 2024-01-11 01:25:38 -05:00
parent c358d404b6
commit bf0693a7c6
51 changed files with 6528 additions and 0 deletions

149
demos/trogdor/Makefile Normal file
View File

@ -0,0 +1,149 @@
include ../../Makefile.inc
DOS33 = ../../utils/dos33fs-utils/dos33
DOS33_RAW = ../../utils/dos33fs-utils/dos33_raw
EMPTY_DISK = ../../empty_disk/empty.dsk
TOKENIZE = ../../utils/asoft_basic-utils/tokenize_asoft
LINKER_SCRIPTS = ../../linker_scripts/
all: trogdor.dsk
trogdor.dsk: QBOOT QLOAD music.inc qload.inc \
MUSIC TROGDOR
cp $(EMPTY_DISK) trogdor.dsk
$(DOS33_RAW) trogdor.dsk 0 0 QBOOT 0 1
$(DOS33_RAW) trogdor.dsk 0 2 QBOOT 1 1
$(DOS33_RAW) trogdor.dsk 0 4 QBOOT 2 1
$(DOS33_RAW) trogdor.dsk 1 0 QLOAD 0 0
$(DOS33_RAW) trogdor.dsk 4 0 MUSIC 0 0
$(DOS33_RAW) trogdor.dsk 12 0 TROGDOR 0 0
####
QBOOT: qboot_sector.o
ld65 -o QBOOT qboot_sector.o -C $(LINKER_SCRIPTS)/apple2_800.inc
qboot_sector.o: qboot_sector.s qboot_stage2.s
ca65 -o qboot_sector.o qboot_sector.s -l qboot_sector.lst
####
QLOAD: qload.o
ld65 -o QLOAD qload.o -C $(LINKER_SCRIPTS)/apple2_1200.inc
qload.o: zp.inc hardware.inc music.inc qload.s \
gr_offsets.s \
wait.s wait_a_bit.s \
lc_detect.s \
text_print.s start.s \
hgr_table.s gs_interrupt.s \
zx02_optim.s wait_keypress.s hardware_detect.s \
pt3_lib_detect_model.s pt3_lib_mockingboard_detect.s \
pt3_lib_mockingboard_setup.s interrupt_handler.s \
pt3_lib_mockingboard_patch.s
ca65 -o qload.o qload.s -l qload.lst
####
QLOAD2: qload2.o
ld65 -o QLOAD2 qload2.o -C $(LINKER_SCRIPTS)/apple2_1200.inc
qload2.o: qload2.s \
zp.inc hardware.inc music2.inc \
gr_offsets.s \
wait.s wait_a_bit.s \
lc_detect.s gr_fast_clear.s \
text_print.s start2.s \
hardware_detect.s \
hgr_table.s \
pt3_lib_detect_model.s pt3_lib_mockingboard_detect.s \
pt3_lib_mockingboard_setup.s interrupt_handler.s \
pt3_lib_mockingboard_patch.s
ca65 -o qload2.o qload2.s -l qload2.lst
####
qload.inc: generate_common QLOAD
./generate_common -a 0x1200 -s load_file qload.lst > qload.inc
./generate_common -a 0x1200 -s detect_appleii_model qload.lst >> qload.inc
./generate_common -a 0x1200 -s clear_all qload.lst >> qload.inc
./generate_common -a 0x1200 -s clear_all_color qload.lst >> qload.inc
./generate_common -a 0x1200 -s set_normal qload.lst >> qload.inc
./generate_common -a 0x1200 -s set_inverse qload.lst >> qload.inc
./generate_common -a 0x1200 -s wait qload.lst >> qload.inc
./generate_common -a 0x1200 -s wait_a_bit qload.lst >> qload.inc
./generate_common -a 0x1200 -s move_and_print qload.lst >> qload.inc
./generate_common -a 0x1200 -s detect_language_card qload.lst >> qload.inc
./generate_common -a 0x1200 -s mockingboard_detect qload.lst >> qload.inc
./generate_common -a 0x1200 -s clear_bottom qload.lst >> qload.inc
./generate_common -a 0x1200 -s clear_bottoms qload.lst >> qload.inc
./generate_common -a 0x1200 -s clear_screens qload.lst >> qload.inc
./generate_common -a 0x1200 -s clear_top qload.lst >> qload.inc
./generate_common -a 0x1200 -s zx02_full_decomp qload.lst >> qload.inc
./generate_common -a 0x1200 -s zx_src_h qload.lst >> qload.inc
./generate_common -a 0x1200 -s zx_src_l qload.lst >> qload.inc
####
music.inc: generate_common MUSIC
./generate_common -a 0xd000 -s pt3_init_song music.lst > music.inc
./generate_common -a 0xd000 -s mockingboard_init music.lst >> music.inc
./generate_common -a 0xd000 -s reset_ay_both music.lst >> music.inc
./generate_common -a 0xd000 -s clear_ay_both music.lst >> music.inc
./generate_common -a 0xd000 -s mockingboard_setup_interrupt music.lst >> music.inc
./generate_common -a 0xd000 -s mockingboard_disable_interrupt music.lst >> music.inc
./generate_common -a 0xd000 -s done_pt3_irq_handler music.lst >> music.inc
./generate_common -a 0xd000 -s PT3_LOC music.lst >> music.inc
./generate_common -a 0xd000 -s current_pattern_smc music.lst >> music.inc
./generate_common -a 0xd000 -s pt3_set_pattern music.lst >> music.inc
./generate_common -a 0xd000 -s mute_ay_both music.lst >> music.inc
./generate_common -a 0xd000 -s unmute_ay_both music.lst >> music.inc
./generate_common -a 0xd000 -s interrupt_handler music.lst >> music.inc
####
MUSIC: music.o
ld65 -o MUSIC music.o -C $(LINKER_SCRIPTS)/apple2_d000.inc
music.o: music.s zp.inc \
pt3_lib_core.s \
pt3_lib_mockingboard_detect.s \
pt3_lib_mockingboard.inc \
pt3_lib_init.s \
pt3_lib_mockingboard_setup.s \
pt3_lib_irq_handler.s
ca65 -o music.o music.s -l music.lst
###
TROGDOR: trogdor.o
ld65 -o TROGDOR trogdor.o -C $(LINKER_SCRIPTS)/apple2_8000.inc
trogdor.o: trogdor.s \
zp.inc hardware.inc qload.inc \
graphics/trog00_trogdor.hgr.zx02
ca65 -o trogdor.o trogdor.s -l trogdor.lst
###
graphics/trog00_trogdor.hgr.zx02:
cd graphics && make
###
generate_common: generate_common.o
$(CC) $(LFLAGS) -o generate_common generate_common.o
generate_common.o: generate_common.c
$(CC) $(CFLAGS) -c generate_common.c
###
clean:
rm -f *~ *.o *.lst QBOOT QLOAD MUSIC TROGDOR
rm -f qload.inc music.inc generate_common

32
demos/trogdor/NOTES Normal file
View File

@ -0,0 +1,32 @@
Crop to 635x472
Levels: middle to 0.40
Scale to: 280x208
Levels: to 0.35
Indexed, B+W, Floyd Steinberg
Crop to 280x192 with top at 8 pixels down
+ zoom trogdor right to left
+ blank screen with flames
+ trogdor zoom up from bottom
+ village scroll from right to left
+ Man
+ Flames appear
+ Dragon man
+ Dragon
+ Zoom in/out
+ Scroll Down
+ Flames on Dragon Man again
+ Flip rapidly between dragon/man
+ Back to village
+ Flames over village
+ Burning peasant scrolls
+ dragon up/down
+ Lots of peasants
+ cottage scrolls up
+ back/forth dragon/cottage
+ cottags scrolls in upside down from top? with flames?
+ rapid cut between tilted man/peasant/few others

View File

@ -0,0 +1,201 @@
clear_screens:
;===================================
; Clear top/bottom of page 0
;===================================
lda #$0
sta DRAW_PAGE
jsr clear_top
jsr clear_bottom
;===================================
; Clear top/bottom of page 1
;===================================
lda #$4
sta DRAW_PAGE
jsr clear_top
jsr clear_bottom
rts
;=========================================================
; clear_top
;=========================================================
; clear DRAW_PAGE
; original = 14,558 cycles(?) 15ms, 70Hz
; OPTIMIZED MAX (page0,48rows): 45*120+4+6 = 5410 = 5.4ms 185Hz
; (pageX,40rows): 50*120+4+6 = 6010 = 6.0ms 166Hz
; 50*120+4+6+37 = 6055 = 6.0ms 166Hz
clear_top:
lda #0 ; 2
clear_top_a:
sta COLOR ; 3
clc ; 2
lda DRAW_PAGE ; 3
adc #4 ; 2
sta __ctf+2 ; 3
sta __ctf+5 ; 3
adc #1 ; 2
sta __ctf+8 ; 3
sta __ctf+11 ; 3
adc #1 ; 2
sta __ctf2+2 ; 3
sta __ctf2+5 ; 3
adc #1 ; 2
sta __ctf2+8 ; 3
sta __ctf2+11 ; 3
ldy #120 ; 2
lda COLOR ; 3
clear_top_fast_loop:
__ctf:
sta $400,Y ; 5
sta $480,Y ; 5
sta $500,Y ; 5
sta $580,Y ; 5
cpy #80 ; 2
bpl no_draw_bottom ; 2nt/3
__ctf2:
sta $600,Y ; 5
sta $680,Y ; 5
sta $700,Y ; 5
sta $780,Y ; 5
no_draw_bottom:
dey ; 2
bpl clear_top_fast_loop ; 2nt/3
rts ; 6
;=========================================================
; clear_bottom
;=========================================================
; clear bottom of draw page
clear_bottom:
clc ; 2
lda DRAW_PAGE ; 3
adc #6 ; 2
sta __cbf2+2 ; 3
sta __cbf2+5 ; 3
adc #1 ; 2
sta __cbf2+8 ; 3
sta __cbf2+11 ; 3
ldy #120 ; 2
lda #$a0 ; Normal Space ; 2
clear_bottom_fast_loop:
__cbf2:
sta $600,Y ; 5
sta $680,Y ; 5
sta $700,Y ; 5
sta $780,Y ; 5
dey ; 2
cpy #80 ; 2
bpl clear_bottom_fast_loop ; 2nt/3
rts ; 6
;clear_screens_notext:
;===================================
; Clear top/bottom of page 0
;===================================
; lda #$0
; sta DRAW_PAGE
; jsr clear_all
;===================================
; Clear top/bottom of page 1
;===================================
; lda #$4
; sta DRAW_PAGE
; jsr clear_all
; rts
clear_bottoms:
lda DRAW_PAGE
pha
;===================================
; Clear bottom of page 0
;===================================
lda #$0
sta DRAW_PAGE
jsr clear_bottom
;===================================
; Clear bottom of page 1
;===================================
lda #$4
sta DRAW_PAGE
jsr clear_bottom
pla
sta DRAW_PAGE
rts
;=========================================================
; clear_all
;=========================================================
; clear 48 rows
clear_all:
clc ; 2
lda DRAW_PAGE ; 3
adc #4 ; 2
sta __caf+2 ; 3
sta __caf+5 ; 3
adc #1 ; 2
sta __caf+8 ; 3
sta __caf+11 ; 3
adc #1 ; 2
sta __caf2+2 ; 3
sta __caf2+5 ; 3
adc #1 ; 2
sta __caf2+8 ; 3
sta __caf2+11 ; 3
ldy #120 ; 2
clear_all_color:
lda #' '|$80 ; 2
clear_all_fast_loop:
__caf:
sta $400,Y ; 5
sta $480,Y ; 5
sta $500,Y ; 5
sta $580,Y ; 5
__caf2:
sta $600,Y ; 5
sta $680,Y ; 5
sta $700,Y ; 5
sta $780,Y ; 5
dey ; 2
bpl clear_all_fast_loop ; 2nt/3
rts ; 6

View File

@ -0,0 +1,5 @@
gr_offsets:
.word $400,$480,$500,$580,$600,$680,$700,$780
.word $428,$4a8,$528,$5a8,$628,$6a8,$728,$7a8
.word $450,$4d0,$550,$5d0,$650,$6d0,$750,$7d0

View File

@ -0,0 +1,116 @@
include ../../../Makefile.inc
ZX02 = ~/research/6502_compression/zx02.git/build/zx02 -f
PNG_TO_HGR = ../../../utils/hgr-utils/png2hgr
PNG2GR = ../../../utils/gr-utils/png2gr
HGR_SPRITE = ../../../utils/hgr-utils/hgr_make_sprite
all: \
trog00_trogdor.hgr.zx02 \
trog01_countryside.hgr.zx02 \
trog02_countryside.hgr.zx02 \
trog03_man.hgr.zx02 \
trog04_dragonman.hgr.zx02 \
trog05_zoom.hgr.zx02 \
trog07_peasant.hgr.zx02 \
trog08_close1.hgr.zx02 \
trog09_close.hgr.zx02 \
trog10_peasants.hgr.zx02 \
trog11_cottage.hgr.zx02
####
trog00_trogdor.hgr.zx02: trog00_trogdor.hgr
$(ZX02) trog00_trogdor.hgr trog00_trogdor.hgr.zx02
trog00_trogdor.hgr: trog00_trogdor.png
$(PNG_TO_HGR) trog00_trogdor.png > trog00_trogdor.hgr
####
trog01_countryside.hgr.zx02: trog01_countryside.hgr
$(ZX02) trog01_countryside.hgr trog01_countryside.hgr.zx02
trog01_countryside.hgr: trog01_countryside.png
$(PNG_TO_HGR) trog01_countryside.png > trog01_countryside.hgr
####
trog02_countryside.hgr.zx02: trog02_countryside.hgr
$(ZX02) trog02_countryside.hgr trog02_countryside.hgr.zx02
trog02_countryside.hgr: trog02_countryside.png
$(PNG_TO_HGR) trog02_countryside.png > trog02_countryside.hgr
####
trog03_man.hgr.zx02: trog03_man.hgr
$(ZX02) trog03_man.hgr trog03_man.hgr.zx02
trog03_man.hgr: trog03_man.png
$(PNG_TO_HGR) trog03_man.png > trog03_man.hgr
####
trog04_dragonman.hgr.zx02: trog04_dragonman.hgr
$(ZX02) trog04_dragonman.hgr trog04_dragonman.hgr.zx02
trog04_dragonman.hgr: trog04_dragonman.png
$(PNG_TO_HGR) trog04_dragonman.png > trog04_dragonman.hgr
####
trog05_zoom.hgr.zx02: trog05_zoom.hgr
$(ZX02) trog05_zoom.hgr trog05_zoom.hgr.zx02
trog05_zoom.hgr: trog05_zoom.png
$(PNG_TO_HGR) trog05_zoom.png > trog05_zoom.hgr
####
trog07_peasant.hgr.zx02: trog07_peasant.hgr
$(ZX02) trog07_peasant.hgr trog07_peasant.hgr.zx02
trog07_peasant.hgr: trog07_peasant.png
$(PNG_TO_HGR) trog07_peasant.png > trog07_peasant.hgr
####
trog08_close1.hgr.zx02: trog08_close1.hgr
$(ZX02) trog08_close1.hgr trog08_close1.hgr.zx02
trog08_close1.hgr: trog08_close1.png
$(PNG_TO_HGR) trog08_close1.png > trog08_close1.hgr
####
trog09_close.hgr.zx02: trog09_close.hgr
$(ZX02) trog09_close.hgr trog09_close.hgr.zx02
trog09_close.hgr: trog09_close.png
$(PNG_TO_HGR) trog09_close.png > trog09_close.hgr
####
trog10_peasants.hgr.zx02: trog10_peasants.hgr
$(ZX02) trog10_peasants.hgr trog10_peasants.hgr.zx02
trog10_peasants.hgr: trog10_peasants.png
$(PNG_TO_HGR) trog10_peasants.png > trog10_peasants.hgr
####
trog11_cottage.hgr.zx02: trog11_cottage.hgr
$(ZX02) trog11_cottage.hgr trog11_cottage.hgr.zx02
trog11_cottage.hgr: trog11_cottage.png
$(PNG_TO_HGR) trog11_cottage.png > trog11_cottage.hgr
####
clean:
rm -f *~ *.zx02

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

@ -0,0 +1,9 @@
gs_interrupt_handler:
; swap back in language card
; read/write RAM, use $d000 bank1
bit $C083
bit $C083
jmp interrupt_handler

101
demos/trogdor/hardware.inc Normal file
View File

@ -0,0 +1,101 @@
; HARDWARE LOCATIONS
KEYPRESS = $C000
KEYRESET = $C010
; SOFT SWITCHES
CLR80COL = $C000 ; PAGE1/PAGE1 normal
SET80COL = $C001 ; PAGE1/PAGE2 switches PAGE1 in Aux instead
EIGHTYCOLOFF = $C00C
EIGHTYCOLON = $C00D
TBCOLOR = $C022 ; IIgs text fg/bg colors
NEWVIDEO = $C029 ; IIgs graphics modes
SPEAKER = $C030
CLOCKCTL = $C034 ; bits 0-3 are IIgs border color
CYAREG = $C036 ; iigs motor detect and clock speed
SET_GR = $C050
SET_TEXT = $C051
FULLGR = $C052
TEXTGR = $C053
PAGE1 = $C054
PAGE2 = $C055
LORES = $C056 ; Enable LORES graphics
HIRES = $C057 ; Enable HIRES graphics
AN3 = $C05E ; Annunciator 3
PADDLE_BUTTON0 = $C061
PADDL0 = $C064
PTRIG = $C070
; APPLESOFT BASIC ROUTINES
NORMAL = $F273
HGR2 = $F3D8
HGR = $F3E2
BKGND0 = $F3F4 ; clear current page to A
HPOSN = $F411 ; (Y,X),(A) (values stores in HGRX,XH,Y)
HPLOT0 = $F457 ; plot at (Y,X), (A)
COLOR_SHIFT = $F47E
HLINRL = $F530 ; (X,A),(Y)
HGLIN = $F53A ; line to (X,A),(Y)
COLORTBL = $F6F6
; MONITOR ROUTINES
HLINE = $F819 ; HLINE Y,$2C at A
VLINE = $F828 ; VLINE A,$2D at Y
CLRSCR = $F832 ; Clear low-res screen
CLRTOP = $F836 ; clear only top of low-res screen
SETCOL = $F864 ; COLOR=A
ROM_TEXT2COPY = $F962 ; iigs
TEXT = $FB36
TABV = $FB5B ; VTAB to A
ROM_MACHINEID = $FBB3 ; iigs
BASCALC = $FBC1 ;
BELL = $FBDD ; ring the bell
VTAB = $FC22 ; VTAB to CV
HOME = $FC58 ; Clear the text screen
WAIT = $FCA8 ; delay 1/2(26+27A+5A^2) us
SETINV = $FE80 ; INVERSE
SETNORM = $FE84 ; NORMAL
COUT = $FDED ; output A to screen
COUT1 = $FDF0 ; output A to screen
COLOR_BLACK = 0
COLOR_RED = 1
COLOR_DARKBLUE = 2
COLOR_PURPLE = 3
COLOR_DARKGREEN = 4
COLOR_GREY = 5
COLOR_MEDIUMBLUE = 6
COLOR_LIGHTBLUE = 7
COLOR_BROWN = 8
COLOR_ORANGE = 9
COLOR_GREY2 = 10
COLOR_PINK = 11
COLOR_LIGHTGREEN = 12
COLOR_YELLOW = 13
COLOR_AQUA = 14
COLOR_WHITE = 15
COLOR_BOTH_BLACK = $00
COLOR_BOTH_RED = $11
COLOR_BOTH_DARKBLUE = $22
COLOR_BOTH_DARKGREEN = $44
COLOR_BOTH_GREY = $55
COLOR_BOTH_MEDIUMBLUE = $66
COLOR_BOTH_LIGHTBLUE = $77
COLOR_BOTH_BROWN = $88
COLOR_BOTH_ORANGE = $99
COLOR_BOTH_PINK = $BB
COLOR_BOTH_LIGHTGREEN = $CC
COLOR_BOTH_YELLOW = $DD
COLOR_BOTH_AQUA = $EE
COLOR_BOTH_WHITE = $FF

View File

@ -0,0 +1,80 @@
;====================
; Hardware Detect
; called for disk1 and disk2
; simplified version that just detects model and mockingboard
; for the fake BIOS we do a bit more, but we do rely
; on this being run first
hardware_detect:
;=======================
; Hardware Detect Model
;=======================
; Yes Michaelangel007 I will eventually update linux_logo 6502
jsr detect_appleii_model
lda APPLEII_MODEL
cmp #'g'
bne not_iigs
is_a_iigs:
; enable 1MHz mode
; see hw.accel.a in 4cade
setspeed:
lda CYAREG
and #$7f
sta CYAREG
; gr/text page2 handling broken on early IIgs models
; this enables the workaround
jsr ROM_TEXT2COPY ; set alternate display mode on IIgs
; set background color to black instead of blue
lda NEWVIDEO
and #%00011111 ; bit 7 = 0 -> IIgs Apple II-compat video modes
; bit 6 = 0 -> IIgs 128K memory map same as IIe
; bit 5 = 0 -> IIgs DHGR is color, not mono
; bits 0-4 unchanged
sta NEWVIDEO
lda #$F0
sta TBCOLOR ; white text on black background
lda #$00
sta CLOCKCTL ; black border
sta CLOCKCTL ; set twice for VidHD
; gs always swaps in RAM
lda #<gs_interrupt_handler
sta $3FE
lda #>gs_interrupt_handler
sta $3FF
not_iigs:
;======================
; detect mockingboard
lda #0
sta SOUND_STATUS
;PT3_ENABLE_APPLE_IIC = 1 ; we set this earlier
jsr mockingboard_detect
bcc mockingboard_notfound
mockingboard_found:
lda SOUND_STATUS
ora #SOUND_MOCKINGBOARD
sta SOUND_STATUS
mockingboard_notfound:
rts
.include "pt3_lib_mockingboard.inc"

View File

@ -0,0 +1,89 @@
hgr_clear_screen:
lda DRAW_PAGE
beq hgr_page1_clearscreen
lda #0
beq hgr_page2_clearscreen
hgr_page1_clearscreen:
ldy #0
hgr_page1_cls_loop:
sta $2000,Y
sta $2100,Y
sta $2200,Y
sta $2300,Y
sta $2400,Y
sta $2500,Y
sta $2600,Y
sta $2700,Y
sta $2800,Y
sta $2900,Y
sta $2A00,Y
sta $2B00,Y
sta $2C00,Y
sta $2D00,Y
sta $2E00,Y
sta $2F00,Y
sta $3000,Y
sta $3100,Y
sta $3200,Y
sta $3300,Y
sta $3400,Y
sta $3500,Y
sta $3600,Y
sta $3700,Y
sta $3800,Y
sta $3900,Y
sta $3A00,Y
sta $3B00,Y
sta $3C00,Y
sta $3D00,Y
sta $3E00,Y
sta $3F00,Y
iny
bne hgr_page1_cls_loop
rts
hgr_page2_clearscreen:
ldy #0
hgr_page2_cls_loop:
sta $4000,Y
sta $4100,Y
sta $4200,Y
sta $4300,Y
sta $4400,Y
sta $4500,Y
sta $4600,Y
sta $4700,Y
sta $4800,Y
sta $4900,Y
sta $4A00,Y
sta $4B00,Y
sta $4C00,Y
sta $4D00,Y
sta $4E00,Y
sta $4F00,Y
sta $5000,Y
sta $5100,Y
sta $5200,Y
sta $5300,Y
sta $5400,Y
sta $5500,Y
sta $5600,Y
sta $5700,Y
sta $5800,Y
sta $5900,Y
sta $5A00,Y
sta $5B00,Y
sta $5C00,Y
sta $5D00,Y
sta $5E00,Y
sta $5F00,Y
iny
bne hgr_page2_cls_loop
rts

View File

@ -0,0 +1,18 @@
hgr_page_flip:
lda DRAW_PAGE
beq flip_to_page1
flip_to_page2:
bit PAGE2
lda #0
beq done_hgr_page_flip ; bra
flip_to_page1:
bit PAGE1
lda #$20
done_hgr_page_flip:
sta DRAW_PAGE
rts

View File

@ -0,0 +1,205 @@
;===========================================
; hgr draw sprite (only at 7-bit boundaries)
;===========================================
; can handle sprites bigger than a 256 byte page
; Note this is optimized for blue/orange sprites
; it treats black0 as transparent
; SPRITE in INL/INH
; Location at SPRITE_X SPRITE_Y
; xsize, ysize in first two bytes
; sprite AT INL/INH
; orange = color5 1 101 0101 1 010 1010
hgr_draw_sprite_big:
lda SPRITE_X
ror
bcs hgr_draw_sprite_big_odd
hgr_draw_sprite_big_even:
ldy #0
lda (INL),Y ; load xsize
clc
adc SPRITE_X
sta big_sprite_width_end_smc+1 ; self modify for end of line
iny ; load ysize
lda (INL),Y
sta big_sprite_ysize_smc+1 ; self modify
; point smc to sprite
lda INL ; 16-bit add
sta big_sprite_smc1+1
lda INH
sta big_sprite_smc1+2
ldx #0 ; X is pointer offset
stx CURRENT_ROW ; actual row
ldx #2
hgr_big_sprite_yloop:
lda CURRENT_ROW ; row
clc
adc SPRITE_Y ; add in cursor_y
; calc GBASL/GBASH
tay ; get output ROW into GBASL/H
lda hposn_low,Y
sta GBASL
lda hposn_high,Y
clc
adc DRAW_PAGE
sta GBASH
ldy SPRITE_X
big_sprite_inner_loop:
big_sprite_smc1:
lda $f000,X ; load sprite data
beq big_sprite_transparent
sta (GBASL),Y ; store to screen
big_sprite_transparent:
inx ; increment sprite offset
; if > 1 page
bne big_sprite_no_page_cross
inc big_sprite_smc1+2
big_sprite_no_page_cross:
iny ; increment output position
big_sprite_width_end_smc:
cpy #6 ; see if reached end of row
bne big_sprite_inner_loop ; if not, loop
inc CURRENT_ROW ; row
lda CURRENT_ROW ; row
big_sprite_ysize_smc:
cmp #31 ; see if at end
bne hgr_big_sprite_yloop ; if not, loop
rts
hgr_draw_sprite_big_odd:
ldy #0
lda (INL),Y ; load xsize
clc
adc SPRITE_X
sta osprite_width_end_smc+1 ; self modify for end of line
iny ; load ysize
lda (INL),Y
sta osprite_ysize_smc+1 ; self modify
; point smc to sprite
lda INL ; 16-bit add
sta osprite_smc1+1
lda INH
sta osprite_smc1+2
ldx #0 ; X is pointer offset
stx CURRENT_ROW ; actual row
ldx #2
ohgr_sprite_yloop:
lda CURRENT_ROW ; row
clc
adc SPRITE_Y ; add in cursor_y
; calc GBASL/GBASH
tay ; get output ROW into GBASL/H
lda hposn_low,Y
sta GBASL
lda hposn_high,Y
clc
adc DRAW_PAGE
sta GBASH
ldy SPRITE_X
clc
php ; store 0 carry on stack
osprite_inner_loop:
osprite_smc1:
lda $f000,X ; load sprite data
bne osprite_not_transparent
; we can't just skip if 0 because we might shift a bit in
; from previous byte
plp
bcs osprite_oops
clc
php
bcc osprite_transparent_done
osprite_not_transparent:
plp ; restore carry from last
osprite_oops:
rol ; rotate in carry
asl ; one more time, bit6 in carry
php ; save on stack
sec ; assume blur/orange
ror ; rotate it back down
sta (GBASL),Y ; store to screen
osprite_transparent_done:
inx ; increment sprite offset
; if > 1 page
bne osprite_no_page_cross
inc osprite_smc1+2
osprite_no_page_cross:
iny ; increment output position
osprite_width_end_smc:
cpy #6 ; see if reached end of row
bne osprite_inner_loop ; if not, loop
plp ; restore stack
inc CURRENT_ROW ; row
lda CURRENT_ROW ; row
osprite_ysize_smc:
cmp #31 ; see if at end
bne ohgr_sprite_yloop ; if not, loop
rts

97
demos/trogdor/hgr_table.s Normal file
View File

@ -0,0 +1,97 @@
;div7_table = $b800
;mod7_table = $b900
;hposn_high = $ba00
;hposn_low = $bb00
hgr_make_tables:
;=====================
; make /7 %7 tables
;=====================
hgr_make_7_tables:
ldy #0
lda #0
ldx #0
div7_loop:
sta div7_table,Y
inx
cpx #7
bne div7_not7
clc
adc #1
ldx #0
div7_not7:
iny
bne div7_loop
ldy #0
lda #0
mod7_loop:
sta mod7_table,Y
clc
adc #1
cmp #7
bne mod7_not7
lda #0
mod7_not7:
iny
bne mod7_loop
; Hposn table
; hposn_low, hposn_high will each be filled with $C0 bytes
; based on routine by John Brooks
; posted on comp.sys.apple2 on 2018-07-11
; https://groups.google.com/d/msg/comp.sys.apple2/v2HOfHOmeNQ/zD76fJg_BAAJ
; clobbers A,X
; preserves Y
; vmw note: version I was using based on applesoft HPOSN was ~64 bytes
; this one is 37 bytes
build_hposn_tables:
ldx #0
btmi:
txa
and #$F8
bpl btpl1
ora #5
btpl1:
asl
bpl btpl2
ora #5
btpl2:
asl
asl
sta hposn_low, X
txa
and #7
rol
asl hposn_low, X
rol
ora #$20
sta hposn_high, X
inx
cpx #$C0
bne btmi
; go 16 beyond, which allows our text scrolling routine
ldx #16
extra_table_loop:
lda hposn_low,X
sta hposn_low+192,X
lda hposn_high,X
eor #$60
sta hposn_high+192,X
dex
bpl extra_table_loop
rts

View File

@ -0,0 +1,74 @@
;================================
;================================
; 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)
lda IRQ_COUNTDOWN
beq skip_irq_dec
dec IRQ_COUNTDOWN
skip_irq_dec:
.include "pt3_lib_irq_handler.s"
jmp exit_interrupt
;=================================
; Finally done with this interrupt
;=================================
quiet_exit:
stx DONE_PLAYING
jsr clear_ay_both
ldx #$ff ; also mute the channel
stx AY_REGISTERS+7 ; just in case
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

94
demos/trogdor/irq_wait.s Normal file
View File

@ -0,0 +1,94 @@
;============================
; wait for music pattern
; also check for keypress
;============================
; pattern # in A
wait_for_pattern:
cmp current_pattern_smc+1
bcc done_check_pattern_done ; blt
beq done_check_pattern_done ; ble
lda KEYPRESS
bpl done_check_pattern_notdone
bit KEYRESET
jmp done_check_pattern_done
;============================
; setup timeout of A seconds
;============================
setup_timeout:
sta SECOND_COUNTDOWN
lda #0
sta IRQ_COUNTDOWN
rts
;===========================
; countodown second timeout
; also check for keypress
;===========================
; carry set = done
check_timeout:
; check keyboard first
lda KEYPRESS
bpl timeout_not_keypress
bit KEYRESET
; lda #0 ; reset, is this necessary?
; sta IRQ_COUNTDOWN
; sta SECOND_COUNTDOWN
jmp done_check_timeout_done
timeout_not_keypress:
lda IRQ_COUNTDOWN
bne done_check_timeout_notdone
irq_countdown_zero:
lda SECOND_COUNTDOWN
beq done_check_timeout_done
; otherwise we need to decrement and update
dec SECOND_COUNTDOWN
lda #50
sta IRQ_COUNTDOWN
done_check_pattern_notdone:
done_check_timeout_notdone:
clc
rts
done_check_pattern_done:
done_check_timeout_done:
sec
rts
;==========================
; busy wait A * 1 50Hz tick
;==========================
wait_ticks:
sta IRQ_COUNTDOWN
wait_tick_loop:
lda IRQ_COUNTDOWN
bne wait_tick_loop
wait_tick_done:
rts
;====================
; busy wait A seconds
;====================
; exit early if key pressed
wait_seconds:
tax
wait_seconds_loop:
lda #50 ; wait 1s
jsr wait_ticks
lda KEYPRESS
bmi wait_seconds_done
dex
bpl wait_seconds_loop
wait_seconds_done:
bit KEYRESET
rts

40
demos/trogdor/lc_detect.s Normal file
View File

@ -0,0 +1,40 @@
; Code from TotalReplay by 4am and qkumba
;------------------------------------------------------------------------------
; Has64K
; Checks whether computer has functioning language card (64K)
;
; in: none
; out: C clear if 64K detected
; C set if 64K not detected
; all other flags and registers clobbered
; ROM in memory (not LC RAM bank)
;------------------------------------------------------------------------------
detect_language_card:
; enable language card
; READ_RAM1_WRITE_RAM1
bit $C08B
bit $C08B
lda #$AA ; test #1 for $D0 page
sta $D000
eor $D000
bne no_lc
lsr $D000 ; test #2 for $D0 page
lda #$55
eor $D000
bne no_lc
clc
bcc done_detect
no_lc:
sec
done_detect:
; READ_ROM_NO_WRITE
bit $C08A
rts

30
demos/trogdor/music.s Normal file
View File

@ -0,0 +1,30 @@
; music, music
; by Vince `deater` Weaver vince@deater.net
.include "hardware.inc"
.include "zp.inc"
;.include "qload.inc"
music_lib:
PT3_ENABLE_APPLE_IIC = 1
; nop ; urgh to keep interrupt_handler from starting at $C4
; which broke auto-patcher
; pt3 player
; .include "pt3_lib_detect_model.s"
.include "pt3_lib_core.s"
.include "pt3_lib_init.s"
.include "pt3_lib_mockingboard_setup.s"
.include "interrupt_handler.s"
.include "pt3_lib_mockingboard_detect.s"
; only load one music track, self modify to make other
.align $100
PT3_LOC:
;.incbin "music/Walking_In_The_Air_mA2E.pt3"

2023
demos/trogdor/pt3_lib_core.s Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,95 @@
;===========================
; Check Apple II model
;===========================
; this is mostly for IIc support
; as it does interrupts differently
; some of this info from the document:
; Apple II Family Identification Routines 2.2
;
; ' ' = Apple II
; '+' = Apple II+
; 'e' = Apple IIe
; 'c' = Apple IIc
; 'g' = Apple IIgs
; 'm' = mac L/C with board
; 'j' = jplus
; '3' = Apple III
detect_appleii_model:
lda #' '
ldx $FBB3
; II is $38
; J-plus is $C9
; II+ is $EA (so is III)
; IIe and newer is $06
cpx #$38 ; ii
beq done_apple_detect
; ii+ is EA FB1E=AD
; iii is EA FB1E=8A 00
cpx #$EA
bne not_ii_iii
ii_or_iii:
lda #'+' ; ii+/iii
ldx $FB1E
cpx #$AD
beq done_apple_detect ; ii+
lda #'3'
bne done_apple_detect ; bra iii
not_ii_iii:
lda #'j' ; jplus
cpx #$C9
beq done_apple_detect
cpx #$06
bne done_apple_detect
apple_iie_or_newer:
ldx $FBC0 ; $EA on a IIe
; $E0 on a IIe enhanced
; $00 on a IIc/IIc+
; $FE1F = $60, IIgs
beq apple_iic
lda #'e'
cpx #$EA
beq done_apple_detect
; cpx #$E0
; beq done_apple_detect
; should do something if not $E0
; GS and IIe enhanced are the same, need to check
sec ; set carry
jsr $FE1F
bcs done_apple_detect ;If carry then IIe enhanced
; get here we're a IIgs?
lda #'g'
bne done_apple_detect
apple_iic:
lda #'c'
done_apple_detect:
sta APPLEII_MODEL
rts

View File

@ -0,0 +1,575 @@
; pt3_lib_init.s
; Initialize a song
; this is done before song starts playing so it is not
; as performance / timing critical
;====================================
; pt3_init_song
;====================================
;
pt3_init_song:
lda #$0
sta DONE_SONG ; 3
ldx #(end_vars-begin_vars)
zero_song_structs_loop:
dex
sta note_a,X
bne zero_song_structs_loop
sta pt3_noise_period_smc+1 ; 4
sta pt3_noise_add_smc+1 ; 4
sta pt3_envelope_period_l_smc+1 ; 4
sta pt3_envelope_period_h_smc+1 ; 4
sta pt3_envelope_slide_l_smc+1 ; 4
sta pt3_envelope_slide_h_smc+1 ; 4
sta pt3_envelope_slide_add_l_smc+1 ; 4
sta pt3_envelope_slide_add_h_smc+1 ; 4
sta pt3_envelope_add_smc+1 ; 4
sta pt3_envelope_type_smc+1 ; 4
sta pt3_envelope_type_old_smc+1 ; 4
sta pt3_envelope_delay_smc+1 ; 4
sta pt3_envelope_delay_orig_smc+1 ; 4
sta PT3_MIXER_VAL ; 3
sta current_pattern_smc+1 ; 4
sta current_line_smc+1 ; 4
sta current_subframe_smc+1 ; 4
lda #$f ; 2
sta note_a+NOTE_VOLUME ; 4
sta note_b+NOTE_VOLUME ; 4
sta note_c+NOTE_VOLUME ; 4
; default ornament/sample in A
; X is zero coming in here
;ldx #(NOTE_STRUCT_SIZE*0) ; 2
jsr load_ornament0_sample1 ; 6+93
; default ornament/sample in B
ldx #(NOTE_STRUCT_SIZE*1) ; 2
jsr load_ornament0_sample1 ; 6+93
; default ornament/sample in C
ldx #(NOTE_STRUCT_SIZE*2) ; 2
jsr load_ornament0_sample1 ; 6+93
;=======================
; load default speed
lda PT3_LOC+PT3_SPEED ; 4
sta pt3_speed_smc+1 ; 4
;=======================
; load loop
lda PT3_LOC+PT3_LOOP ; 4
sta pt3_loop_smc+1 ; 4
;========================
;========================
; set up note/freq table
; this saves some space and makes things marginally faster longrun
;========================
;========================
; note (heh) that there are separate tables if version 3.3
; but we are going to assume we are only going to be playing
; newer 3.4+ version files so only need the newer tables
ldx PT3_LOC+PT3_HEADER_FREQUENCY ; 4
beq use_freq_table_0
dex
beq use_freq_table_1
dex
beq use_freq_table_2
; fallthrough (freq table 3)
use_freq_table_3:
;=================================================
; Create Table #3, v4+, "PT3NoteTable_REAL_34_35"
;=================================================
ldy #11 ; !2
freq_table_3_copy_loop:
; note, high lookup almost same as 2v4, just need to adjust one value
lda base2_v4_high,Y ; !3
sta NoteTable_high,Y ; !3
lda base3_low,Y ; !3
sta NoteTable_low,Y ; !3
dey ; !1
bpl freq_table_3_copy_loop ; !2
dec NoteTable_high ; adjust to right value
jsr NoteTablePropogate ; !3
lda #<table3_v4_adjust
sta note_table_adjust_smc+1
lda #>table3_v4_adjust
sta note_table_adjust_smc+2
jsr NoteTableAdjust
jmp done_set_freq_table
use_freq_table_2:
;=================================================
; Create Table #2, v4+, "PT3NoteTable_ASM_34_35"
;=================================================
ldy #11
freq_table_2_copy_loop:
lda base2_v4_high,Y
sta NoteTable_high,Y
lda base2_v4_low,Y
sta NoteTable_low,Y
dey
bpl freq_table_2_copy_loop
jsr NoteTablePropogate ; !3
lda #<table2_v4_adjust
sta note_table_adjust_smc+1
lda #>table2_v4_adjust
sta note_table_adjust_smc+2
jsr NoteTableAdjust
jmp done_set_freq_table
use_freq_table_1:
;=================================================
; Create Table #1, "PT3NoteTable_ST"
;=================================================
ldy #11
freq_table_1_copy_loop:
lda base1_high,Y
sta NoteTable_high,Y
lda base1_low,Y
sta NoteTable_low,Y
dey
bpl freq_table_1_copy_loop
jsr NoteTablePropogate ; !3
; last adjustments
lda #$FD ; Tone[23]=$3FD
sta NoteTable_low+23
dec NoteTable_low+46 ; Tone[46]-=1;
jmp done_set_freq_table
use_freq_table_0:
;=================================================
; Create Table #0, "PT3NoteTable_PT_34_35"
;=================================================
ldy #11
freq_table_0_copy_loop:
lda base0_v4_high,Y
sta NoteTable_high,Y
lda base0_v4_low,Y
sta NoteTable_low,Y
dey
bpl freq_table_0_copy_loop
jsr NoteTablePropogate ; !3
lda #<table0_v4_adjust
sta note_table_adjust_smc+1
lda #>table0_v4_adjust
sta note_table_adjust_smc+2
jsr NoteTableAdjust
done_set_freq_table:
;======================
; calculate version
ldx #6 ; 2
lda PT3_LOC+PT3_VERSION ; 4
sec ; 2
sbc #'0' ; 2
cmp #9 ; 2
bcs not_ascii_number ; bge ; 2/3
tax ; 2
not_ascii_number:
; adjust version<6 SMC code in the slide code
; FIXME: I am sure there's a more clever way to do this
lda #$2C ; BIT ; 2
cpx #$6 ; 2
bcs version_greater_than_or_equal_6 ; bgt ; 3
; less than 6, jump
; also carry is known to be clear
adc #$20 ; BIT->JMP 2C->4C ; 2
version_greater_than_or_equal_6:
sta version_smc ; 4
pick_volume_table:
;=======================
; Pick which volume number, based on version
; if (PlParams.PT3.PT3_Version <= 4)
cpx #5 ; 2
; carry clear = 3.3/3.4 table
; carry set = 3.5 table
;==========================
; VolTableCreator
;==========================
; Creates the appropriate volume table
; based on z80 code by Ivan Roshin ZXAYHOBETA/VTII10bG.asm
;
; Called with carry==0 for 3.3/3.4 table
; Called with carry==1 for 3.5 table
; 177f-1932 = 435 bytes, not that much better than 512 of lookup
VolTableCreator:
; Init initial variables
lda #$0
sta z80_d_smc+1
ldy #$11
; Set up self modify
ldx #$2A ; ROL for self-modify
bcs vol_type_35
vol_type_33:
; For older table, we set initial conditions a bit
; different
dey
tya
ldx #$ea ; NOP for self modify
vol_type_35:
sty z80_l_smc+1 ; l=16 or 17
sta z80_e_smc+1 ; e=16 or 0
stx vol_smc ; set the self-modify code
ldy #16 ; skip first row, all zeros
ldx #16 ; c=16
vol_outer:
clc ; add HL,DE
z80_l_smc:
lda #$d1
z80_e_smc:
adc #$d1
sta z80_e_smc+1
lda #0
z80_d_smc:
adc #$d1
sta z80_d_smc+1 ; carry is important
; sbc hl,hl
lda #0
adc #$ff
eor #$ff
vol_write:
sta z80_h_smc+1
pha
vol_inner:
pla
pha
vol_smc:
nop ; nop or ROL depending
z80_h_smc:
lda #$d1
adc #$0 ; a=a+carry;
sta VolumeTable,Y
iny
pla ; add HL,DE
adc z80_e_smc+1
pha
lda z80_h_smc+1
adc z80_d_smc+1
sta z80_h_smc+1
inx ; inc C
txa ; a=c
and #$f
bne vol_inner
pla
lda z80_e_smc+1 ; a=e
cmp #$77
bne vol_m3
inc z80_e_smc+1
vol_m3:
txa ; a=c
bne vol_outer
vol_done:
rts
;=========================================
; copy note table seed to proper location
;=========================================
; faster inlined
;NoteTableCopy:
; ldy #11 ; !2
;note_table_copy_loop:
;ntc_smc1:
; lda base1_high,Y ; !3
; sta NoteTable_high,Y ; !3
;ntc_smc2:
; lda base1_low,Y ; !3
; sta NoteTable_low,Y ; !3
; dey ; !1
; bpl note_table_copy_loop ; !2
; rts ; !1
;==========================================
; propogate the freq down, dividing by two
;==========================================
NoteTablePropogate:
ldy #0
note_table_propogate_loop:
clc
lda NoteTable_high,Y
ror
sta NoteTable_high+12,Y
lda NoteTable_low,Y
ror
sta NoteTable_low+12,Y
iny
cpy #84
bne note_table_propogate_loop
rts
;================================================
; propogation isn't enough, various values
; are often off by one, so adjust using a bitmask
;================================================
NoteTableAdjust:
ldx #0
note_table_adjust_outer:
note_table_adjust_smc:
lda table0_v4_adjust,X
sta PT3_TEMP
; reset smc
lda #<NoteTable_low
sta ntl_smc+1
lda #>NoteTable_low
sta ntl_smc+2
ldy #7
note_table_adjust_inner:
ror PT3_TEMP
bcc note_table_skip_adjust
ntl_smc:
inc NoteTable_low,X
note_table_skip_adjust:
clc
lda #12
adc ntl_smc+1
sta ntl_smc+1
lda #0
adc ntl_smc+2 ; unnecessary if aligned
sta ntl_smc+2
skip_adjust_done:
dey
bpl note_table_adjust_inner
inx
cpx #12
bne note_table_adjust_outer
rts
;base0_v3_high:
;.byte $0C,$0B,$0A,$0A,$09,$09,$08,$08,$07,$07,$06,$06
;base0_v3_low:
;.byte $21,$73,$CE,$33,$A0,$16,$93,$18,$A4,$36,$CE,$6D
; note: same as base0_v3_high
base0_v4_high:
.byte $0C,$0B,$0A,$0A,$09,$09,$08,$08,$07,$07,$06,$06
base0_v4_low:
.byte $22,$73,$CF,$33,$A1,$17,$94,$19,$A4,$37,$CF,$6D
base1_high:
.byte $0E,$0E,$0D,$0C,$0B,$0B,$0A,$09,$09,$08,$08,$07
base1_low:
.byte $F8,$10,$60,$80,$D8,$28,$88,$F0,$60,$E0,$58,$E0
;base2_v3_high:
;.byte $0D,$0C,$0B,$0B,$0A,$09,$09,$08,$08,$07,$07,$07
;base2_v3_low:
;.byte $3E,$80,$CC,$22,$82,$EC,$5C,$D6,$58,$E0,$6E,$04
; note almost same as above
base2_v4_high:
.byte $0D,$0C,$0B,$0A,$0A,$09,$09,$08,$08,$07,$07,$06
base2_v4_low:
.byte $10,$55,$A4,$FC,$5F,$CA,$3D,$B8,$3B,$C5,$55,$EC
; note almost same as above
;base3_high:
;.byte $0C,$0C,$0B,$0A,$0A,$09,$09,$08,$08,$07,$07,$06
base3_low:
.byte $DA,$22,$73,$CF,$33,$A1,$17,$94,$19,$A4,$37,$CF
; Adjustment factors
table0_v4_adjust:
.byte $40,$e6,$9c,$66,$40,$2c,$20,$30,$48,$6c,$1c,$5a
table2_v4_adjust:
.byte $20,$a8,$40,$f8,$bc,$90,$78,$70,$74,$08,$2a,$50
table3_v4_adjust:
.byte $B4,$40,$e6,$9c,$66,$40,$2c,$20,$30,$48,$6c,$1c
; Table #1 of Pro Tracker 3.3x - 3.5x
;PT3NoteTable_ST_high:
;.byte $0E,$0E,$0D,$0C,$0B,$0B,$0A,$09
;.byte $09,$08,$08,$07,$07,$07,$06,$06
;.byte $05,$05,$05,$04,$04,$04,$04,$03
;.byte $03,$03,$03,$03,$02,$02,$02,$02
;.byte $02,$02,$02,$01,$01,$01,$01,$01
;.byte $01,$01,$01,$01,$01,$01,$01,$00
;.byte $00,$00,$00,$00,$00,$00,$00,$00
;.byte $00,$00,$00,$00,$00,$00,$00,$00
;.byte $00,$00,$00,$00,$00,$00,$00,$00
;.byte $00,$00,$00,$00,$00,$00,$00,$00
;.byte $00,$00,$00,$00,$00,$00,$00,$00
;.byte $00,$00,$00,$00,$00,$00,$00,$00
;PT3NoteTable_ST_low:
;.byte $F8,$10,$60,$80,$D8,$28,$88,$F0
;.byte $60,$E0,$58,$E0,$7C,$08,$B0,$40
;.byte $EC,$94,$44,$F8,$B0,$70,$2C,$FD
;.byte $BE,$84,$58,$20,$F6,$CA,$A2,$7C
;.byte $58,$38,$16,$F8,$DF,$C2,$AC,$90
;.byte $7B,$65,$51,$3E,$2C,$1C,$0A,$FC
;.byte $EF,$E1,$D6,$C8,$BD,$B2,$A8,$9F
;.byte $96,$8E,$85,$7E,$77,$70,$6B,$64
;.byte $5E,$59,$54,$4F,$4B,$47,$42,$3F
;.byte $3B,$38,$35,$32,$2F,$2C,$2A,$27
;.byte $25,$23,$21,$1F,$1D,$1C,$1A,$19
;.byte $17,$16,$15,$13,$12,$11,$10,$0F
; Table #2 of Pro Tracker 3.4x - 3.5x
;PT3NoteTable_ASM_34_35_high:
;.byte $0D,$0C,$0B,$0A,$0A,$09,$09,$08
;.byte $08,$07,$07,$06,$06,$06,$05,$05
;.byte $05,$04,$04,$04,$04,$03,$03,$03
;.byte $03,$03,$02,$02,$02,$02,$02,$02
;.byte $02,$01,$01,$01,$01,$01,$01,$01
;.byte $01,$01,$01,$01,$01,$00,$00,$00
;.byte $00,$00,$00,$00,$00,$00,$00,$00
;.byte $00,$00,$00,$00,$00,$00,$00,$00
;.byte $00,$00,$00,$00,$00,$00,$00,$00
;.byte $00,$00,$00,$00,$00,$00,$00,$00
;.byte $00,$00,$00,$00,$00,$00,$00,$00
;.byte $00,$00,$00,$00,$00,$00,$00,$00
;PT3NoteTable_ASM_34_35_low:
;.byte $10,$55,$A4,$FC,$5F,$CA,$3D,$B8
;.byte $3B,$C5,$55,$EC,$88,$2A,$D2,$7E
;.byte $2F,$E5,$9E,$5C,$1D,$E2,$AB,$76
;.byte $44,$15,$E9,$BF,$98,$72,$4F,$2E
;.byte $0F,$F1,$D5,$BB,$A2,$8B,$74,$60
;.byte $4C,$39,$28,$17,$07,$F9,$EB,$DD
;.byte $D1,$C5,$BA,$B0,$A6,$9D,$94,$8C
;.byte $84,$7C,$75,$6F,$69,$63,$5D,$58
;.byte $53,$4E,$4A,$46,$42,$3E,$3B,$37
;.byte $34,$31,$2F,$2C,$29,$27,$25,$23
;.byte $21,$1F,$1D,$1C,$1A,$19,$17,$16
;.byte $15,$14,$12,$11,$10,$0F,$0E,$0D
;PT3VolumeTable_33_34:
;.byte $0,$0,$0,$0,$0,$0,$0,$0,$0,$0,$0,$0,$0,$0,$0,$0
;.byte $0,$0,$0,$0,$0,$0,$0,$0,$1,$1,$1,$1,$1,$1,$1,$1
;.byte $0,$0,$0,$0,$0,$0,$1,$1,$1,$1,$1,$2,$2,$2,$2,$2
;.byte $0,$0,$0,$0,$1,$1,$1,$1,$2,$2,$2,$2,$3,$3,$3,$3
;.byte $0,$0,$0,$0,$1,$1,$1,$2,$2,$2,$3,$3,$3,$4,$4,$4
;.byte $0,$0,$0,$1,$1,$1,$2,$2,$3,$3,$3,$4,$4,$4,$5,$5
;.byte $0,$0,$0,$1,$1,$2,$2,$3,$3,$3,$4,$4,$5,$5,$6,$6
;.byte $0,$0,$1,$1,$2,$2,$3,$3,$4,$4,$5,$5,$6,$6,$7,$7
;.byte $0,$0,$1,$1,$2,$2,$3,$3,$4,$5,$5,$6,$6,$7,$7,$8
;.byte $0,$0,$1,$1,$2,$3,$3,$4,$5,$5,$6,$6,$7,$8,$8,$9
;.byte $0,$0,$1,$2,$2,$3,$4,$4,$5,$6,$6,$7,$8,$8,$9,$A
;.byte $0,$0,$1,$2,$3,$3,$4,$5,$6,$6,$7,$8,$9,$9,$A,$B
;.byte $0,$0,$1,$2,$3,$4,$4,$5,$6,$7,$8,$8,$9,$A,$B,$C
;.byte $0,$0,$1,$2,$3,$4,$5,$6,$7,$7,$8,$9,$A,$B,$C,$D
;.byte $0,$0,$1,$2,$3,$4,$5,$6,$7,$8,$9,$A,$B,$C,$D,$E
;.byte $0,$1,$2,$3,$4,$5,$6,$7,$8,$9,$A,$B,$C,$D,$E,$F
;PT3VolumeTable_35:
;.byte $0,$0,$0,$0,$0,$0,$0,$0,$0,$0,$0,$0,$0,$0,$0,$0
;.byte $0,$0,$0,$0,$0,$0,$0,$0,$1,$1,$1,$1,$1,$1,$1,$1
;.byte $0,$0,$0,$0,$1,$1,$1,$1,$1,$1,$1,$1,$2,$2,$2,$2
;.byte $0,$0,$0,$1,$1,$1,$1,$1,$2,$2,$2,$2,$2,$3,$3,$3
;.byte $0,$0,$1,$1,$1,$1,$2,$2,$2,$2,$3,$3,$3,$3,$4,$4
;.byte $0,$0,$1,$1,$1,$2,$2,$2,$3,$3,$3,$4,$4,$4,$5,$5
;.byte $0,$0,$1,$1,$2,$2,$2,$3,$3,$4,$4,$4,$5,$5,$6,$6
;.byte $0,$0,$1,$1,$2,$2,$3,$3,$4,$4,$5,$5,$6,$6,$7,$7
;.byte $0,$1,$1,$2,$2,$3,$3,$4,$4,$5,$5,$6,$6,$7,$7,$8
;.byte $0,$1,$1,$2,$2,$3,$4,$4,$5,$5,$6,$7,$7,$8,$8,$9
;.byte $0,$1,$1,$2,$3,$3,$4,$5,$5,$6,$7,$7,$8,$9,$9,$A
;.byte $0,$1,$1,$2,$3,$4,$4,$5,$6,$7,$7,$8,$9,$A,$A,$B
;.byte $0,$1,$2,$2,$3,$4,$5,$6,$6,$7,$8,$9,$A,$A,$B,$C
;.byte $0,$1,$2,$3,$3,$4,$5,$6,$7,$8,$9,$A,$A,$B,$C,$D
;.byte $0,$1,$2,$3,$4,$5,$6,$7,$7,$8,$9,$A,$B,$C,$D,$E
;.byte $0,$1,$2,$3,$4,$5,$6,$7,$8,$9,$A,$B,$C,$D,$E,$F

View File

@ -0,0 +1,116 @@
pt3_irq_handler:
pt3_irq_smc1:
bit MOCK_6522_T1CL ; clear 6522 interrupt by reading T1C-L ; 4
lda DONE_PLAYING ; 3
beq pt3_play_music ; if song done, don't play music ; 3/2nt
jmp done_pt3_irq_handler ; 3
;============
; 13
pt3_play_music:
; decode a frame of music
jsr pt3_make_frame
; handle song over condition
lda DONE_SONG
beq mb_write_frame ; if not done, continue
lda LOOP ; see if looping
beq move_to_next
pt3_loop_smc:
lda #$d1 ; looping, move to loop location
; non-zero to avoid the temptation
; to merge with following lda #$0
sta current_pattern_smc+1
lda #$0
sta current_line_smc+1
sta current_subframe_smc+1
sta DONE_SONG ; undo the next song
beq done_pt3_irq_handler ; branch always
move_to_next:
; same as "press right"
ldx #$20
jmp quiet_exit
;======================================
; Write frames to Mockingboard
;======================================
; for speed could merge this into
; the decode code
mb_write_frame:
tax ; set up reg count ; 2
;============
; 2
;==================================
; loop through the 14 registers
; reading the value, then write out
;==================================
mb_write_loop:
lda AY_REGISTERS,X ; load register value ; 4
; special case R13. If it is 0xff, then don't update
; otherwise might spuriously reset the envelope settings
cpx #13 ; 2
bne mb_not_13 ; 3/2nt
cmp #$ff ; 2
beq mb_skip_13 ; 3/2nt
;============
; typ 5
mb_not_13:
; address
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
;===========
; 56
mb_no_write:
inx ; point to next register ; 2
cpx #14 ; if 14 we're done ; 2
bmi mb_write_loop ; otherwise, loop ; 3/2nt
;============
; 7
mb_skip_13:
;=================================
; Finally done with this interrupt
;=================================
done_pt3_irq_handler:

View File

@ -0,0 +1,54 @@
; Mockingboad programming:
; + Has two 6522 I/O chips connected to two AY-3-8910 chips
; + Optionally has some speech chips controlled via the outport on the AY
; + Often in slot 4
; TODO: how to auto-detect?
; References used:
; http://macgui.com/usenet/?group=2&id=8366
; 6522 Data Sheet
; AY-3-8910 Data Sheet
;========================
; Mockingboard card
; Essentially two 6522s hooked to the Apple II bus
; Connected to AY-3-8910 chips
; PA0-PA7 on 6522 connected to DA0-DA7 on AY
; PB0 on 6522 connected to BC1
; PB1 on 6522 connected to BDIR
; PB2 on 6522 connected to RESET
; left speaker
MOCK_6522_ORB1 = $C400 ; 6522 #1 port b data
MOCK_6522_ORA1 = $C401 ; 6522 #1 port a data
MOCK_6522_DDRB1 = $C402 ; 6522 #1 data direction port B
MOCK_6522_DDRA1 = $C403 ; 6522 #1 data direction port A
MOCK_6522_T1CL = $C404 ; 6522 #1 t1 low order latches
MOCK_6522_T1CH = $C405 ; 6522 #1 t1 high order counter
MOCK_6522_T1LL = $C406 ; 6522 #1 t1 low order latches
MOCK_6522_T1LH = $C407 ; 6522 #1 t1 high order latches
MOCK_6522_T2CL = $C408 ; 6522 #1 t2 low order latches
MOCK_6522_T2CH = $C409 ; 6522 #1 t2 high order counters
MOCK_6522_SR = $C40A ; 6522 #1 shift register
MOCK_6522_ACR = $C40B ; 6522 #1 auxilliary control register
MOCK_6522_PCR = $C40C ; 6522 #1 peripheral control register
MOCK_6522_IFR = $C40D ; 6522 #1 interrupt flag register
MOCK_6522_IER = $C40E ; 6522 #1 interrupt enable register
MOCK_6522_ORANH = $C40F ; 6522 #1 port a data no handshake
; right speaker
MOCK_6522_ORB2 = $C480 ; 6522 #2 port b data
MOCK_6522_ORA2 = $C481 ; 6522 #2 port a data
MOCK_6522_DDRB2 = $C482 ; 6522 #2 data direction port B
MOCK_6522_DDRA2 = $C483 ; 6522 #2 data direction port A
; AY-3-8910 commands on port B
; RESET BDIR BC1
MOCK_AY_RESET = $0 ; 0 0 0
MOCK_AY_INACTIVE = $4 ; 1 0 0
MOCK_AY_READ = $5 ; 1 0 1
MOCK_AY_WRITE = $6 ; 1 1 0
MOCK_AY_LATCH_ADDR = $7 ; 1 1 1

View File

@ -0,0 +1,222 @@
;===================================================================
; code to detect mockingboard
;===================================================================
; this isn't always easy
; my inclination is to just assume slot #4 but that isn't always realistic
; code below based on "hw.mockingboard.a" from "Total Replay"
;license:MIT
; By Andrew Roughan
; in the style of 4am for Total Replay
;
; Mockingboard support functions
;
;------------------------------------------------------------------------------
; HasMockingboard
; detect Mockingboard card by searching for 6522 timers across all slots
; access 6522 timers with deterministic cycle counts
;
; based on prior art in Mockingboard Developers Toolkit
; with optimisation from deater/french touch
; also takes into account FastChip //e clock difference
;
; in: none
; accelerators should be off
; out: C set if Mockingboard found in any slot
; if card was found, X = #$Cn where n is the slot number of the card
; C clear if no Mockingboard found
; other flags clobbered
; A/Y clobbered
;------------------------------------------------------------------------------
mockingboard_detect:
; activate Mockingboard IIc
; + the Mockingboard has to take over Slot#4 (IIc has no slots)
; in theory any write to the firmware area in $C400 will
; activate it, but that might not be fast enough when detecting
; so writing $FF to $C403/$C404 is official way to enable
; + Note this disables permanently the mouse firmware in $C400
; so "normal" interrupts are broken :( The hack to fix things
; is to switch in RAM for $F000 and just replace the IRQ
; vectors at $FFFE/$FFFF instead of $3FE/$3FF but that makes
; it difficult if you actually wanted to use any
; Applesoft/Monitor ROM routines
.ifdef PT3_ENABLE_APPLE_IIC
lda APPLEII_MODEL
cmp #'c'
bne not_iic
lda #$ff
; don't bother patching these, IIc mockingboard always slot 4
sta MOCK_6522_DDRA1 ; $C403
sta MOCK_6522_T1CL ; $C404
.endif
not_iic:
lda #$00
sta MB_ADDR_L
ldx #$C7 ; start at slot #7
mb_slot_loop:
stx MB_ADDR_H
ldy #$04 ; 6522 #1 $Cx04
jsr mb_timer_check
bne mb_next_slot
ldy #$84 ; 6522 #2 $Cx84
jsr mb_timer_check
bne mb_next_slot
mb_found:
sec ; found
rts
mb_next_slot:
dex
cpx #$C0
bne mb_slot_loop
clc ; not found
rts
mb_timer_check:
lda (MB_ADDR_L),Y ; read 6522 timer low byte
sta MB_VALUE
lda (MB_ADDR_L),Y ; second time
sec
sbc MB_VALUE
cmp #$F8 ; looking for (-)8 cycles between reads
beq mb_timer_check_done
cmp #$F7 ; FastChip //e clock is different
mb_timer_check_done:
rts
.if 0
;=======================================
; Detect a Mockingboard card
;=======================================
; Based on code from the French Touch "Pure Noise" Demo
; Attempts to time an instruction sequence with a 6522
;
; If found, puts in bMB
; MB_ADDRL:MB_ADDRH has address of Mockingboard
; returns X=0 if not found, X=1 if found
mockingboard_detect:
lda #0
sta MB_ADDRL
mb_detect_loop: ; self-modifying
lda #$07 ; we start in slot 7 ($C7) and go down to 0 ($C0)
ora #$C0 ; make it start with C
sta MB_ADDRH
ldy #04 ; $CX04
ldx #02 ; 2 tries?
mb_check_cycle_loop:
lda (MB_ADDRL),Y ; timer 6522 (Low Order Counter)
; count down
sta PT3_TEMP ; 3 cycles
lda (MB_ADDRL),Y ; + 5 cycles = 8 cycles
; between the two accesses to the timer
sec
sbc PT3_TEMP ; subtract to see if we had 8 cycles
cmp #$f8 ; -8
bne mb_not_in_this_slot
dex ; decrement, try one more time
bne mb_check_cycle_loop ; loop detection
inx ; Mockingboard found (X=1)
done_mb_detect:
;stx bMB ; store result to bMB
rts ; return
mb_not_in_this_slot:
dec mb_detect_loop+1 ; decrement the "slot" (self_modify)
bne mb_detect_loop ; loop down to one
ldx #00
beq done_mb_detect
;alternative MB detection from Nox Archaist
; lda #$04
; sta MB_ADDRL
; ldx #$c7
;
;find_mb:
; stx MB_ADDRH
;
; ;detect sound I
;
; sec
; ldy #$00
; lda (MB_ADDRL), y
; sbc (MB_ADDRL), y
; cmp #$05
; beq found_mb
; dex
; cpx #$c0
; bne find_mb
; ldx #$00 ;no mockingboard found
; rts
;
;found_mb:
; ldx #$01 ;mockingboard found
; rts
;
; ;optionally detect sound II
;
; sec
; ldy #$80
; lda (MB_ADDRL), y
; sbc (MB_ADDRL), y
; cmp #$05
; beq found_mb
;=======================================
; Detect a Mockingboard card in Slot4
;=======================================
; Based on code from the French Touch "Pure Noise" Demo
; Attempts to time an instruction sequence with a 6522
;
; MB_ADDRL:MB_ADDRH has address of Mockingboard
; returns X=0 if not found, X=1 if found
mockingboard_detect_slot4:
lda #0
sta MB_ADDRL
mb4_detect_loop: ; self-modifying
lda #$04 ; we're only looking in Slot 4
ora #$C0 ; make it start with C
sta MB_ADDRH
ldy #04 ; $CX04
ldx #02 ; 2 tries?
mb4_check_cycle_loop:
lda (MB_ADDRL),Y ; timer 6522 (Low Order Counter)
; count down
sta PT3_TEMP ; 3 cycles
lda (MB_ADDRL),Y ; + 5 cycles = 8 cycles
; between the two accesses to the timer
sec
sbc PT3_TEMP ; subtract to see if we had 8 cycles
cmp #$f8 ; -8
bne mb4_not_in_this_slot
dex ; decrement, try one more time
bne mb4_check_cycle_loop ; loop detection
inx ; Mockingboard found (X=1)
done_mb4_detect:
rts ; return
mb4_not_in_this_slot:
ldx #00
beq done_mb4_detect
.endif

View File

@ -0,0 +1,121 @@
;===================================================================
; 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:
stx MB_ADDR_H ; restore slot for later
rts

View File

@ -0,0 +1,295 @@
; Mockingboad programming:
; + Has two 6522 I/O chips connected to two AY-3-8910 chips
; + Optionally has some speech chips controlled via the outport on the AY
; + Often in slot 4
; TODO: how to auto-detect?
; References used:
; http://macgui.com/usenet/?group=2&id=8366
; 6522 Data Sheet
; AY-3-8910 Data Sheet
;========================
; Mockingboard card
; Essentially two 6522s hooked to the Apple II bus
; Connected to AY-3-8910 chips
; PA0-PA7 on 6522 connected to DA0-DA7 on AY
; PB0 on 6522 connected to BC1
; PB1 on 6522 connected to BDIR
; PB2 on 6522 connected to RESET
; left speaker
MOCK_6522_ORB1 = $C400 ; 6522 #1 port b data
MOCK_6522_ORA1 = $C401 ; 6522 #1 port a data
MOCK_6522_DDRB1 = $C402 ; 6522 #1 data direction port B
MOCK_6522_DDRA1 = $C403 ; 6522 #1 data direction port A
MOCK_6522_T1CL = $C404 ; 6522 #1 t1 low order latches
MOCK_6522_T1CH = $C405 ; 6522 #1 t1 high order counter
MOCK_6522_T1LL = $C406 ; 6522 #1 t1 low order latches
MOCK_6522_T1LH = $C407 ; 6522 #1 t1 high order latches
MOCK_6522_T2CL = $C408 ; 6522 #1 t2 low order latches
MOCK_6522_T2CH = $C409 ; 6522 #1 t2 high order counters
MOCK_6522_SR = $C40A ; 6522 #1 shift register
MOCK_6522_ACR = $C40B ; 6522 #1 auxilliary control register
MOCK_6522_PCR = $C40C ; 6522 #1 peripheral control register
MOCK_6522_IFR = $C40D ; 6522 #1 interrupt flag register
MOCK_6522_IER = $C40E ; 6522 #1 interrupt enable register
MOCK_6522_ORANH = $C40F ; 6522 #1 port a data no handshake
; right speaker
MOCK_6522_ORB2 = $C480 ; 6522 #2 port b data
MOCK_6522_ORA2 = $C481 ; 6522 #2 port a data
MOCK_6522_DDRB2 = $C482 ; 6522 #2 data direction port B
MOCK_6522_DDRA2 = $C483 ; 6522 #2 data direction port A
; AY-3-8910 commands on port B
; RESET BDIR BC1
MOCK_AY_RESET = $0 ; 0 0 0
MOCK_AY_INACTIVE = $4 ; 1 0 0
MOCK_AY_READ = $5 ; 1 0 1
MOCK_AY_WRITE = $6 ; 1 1 0
MOCK_AY_LATCH_ADDR = $7 ; 1 1 1
;========================
; Mockingboard Init
;========================
; Initialize the 6522s
; set the data direction for all pins of PortA/PortB to be output
mockingboard_init:
lda #$ff ; all output (1)
mock_init_smc1:
sta MOCK_6522_DDRB1
sta MOCK_6522_DDRA1
mock_init_smc2:
sta MOCK_6522_DDRB2
sta MOCK_6522_DDRA2
rts
;===================================
;===================================
; Reset Both AY-3-8910s
;===================================
;===================================
;======================
; Reset Left AY-3-8910
;======================
reset_ay_both:
lda #MOCK_AY_RESET
reset_ay_smc1:
sta MOCK_6522_ORB1
lda #MOCK_AY_INACTIVE
reset_ay_smc2:
sta MOCK_6522_ORB1
;======================
; Reset Right AY-3-8910
;======================
;reset_ay_right:
;could be merged with both
lda #MOCK_AY_RESET
reset_ay_smc3:
sta MOCK_6522_ORB2
lda #MOCK_AY_INACTIVE
reset_ay_smc4:
sta MOCK_6522_ORB2
rts
; Write sequence
; Inactive -> Latch Address -> Inactive -> Write Data -> Inactive
;=========================================
; Write Right/Left to save value AY-3-8910
;=========================================
; register in X
; value in MB_VALUE
write_ay_both:
; address
write_ay_smc1:
stx MOCK_6522_ORA1 ; put address on PA1 ; 4
stx MOCK_6522_ORA2 ; put address on PA2 ; 4
lda #MOCK_AY_LATCH_ADDR ; latch_address on PB1 ; 2
write_ay_smc2:
sta MOCK_6522_ORB1 ; latch_address on PB1 ; 4
sta MOCK_6522_ORB2 ; latch_address on PB2 ; 4
ldy #MOCK_AY_INACTIVE ; go inactive ; 2
write_ay_smc3:
sty MOCK_6522_ORB1 ; 4
sty MOCK_6522_ORB2 ; 4
;===========
; 28
; value
lda MB_VALUE ; 3
write_ay_smc4:
sta MOCK_6522_ORA1 ; put value on PA1 ; 4
sta MOCK_6522_ORA2 ; put value on PA2 ; 4
lda #MOCK_AY_WRITE ; ; 2
write_ay_smc5:
sta MOCK_6522_ORB1 ; write on PB1 ; 4
sta MOCK_6522_ORB2 ; write on PB2 ; 4
write_ay_smc6:
sty MOCK_6522_ORB1 ; 4
sty MOCK_6522_ORB2 ; 4
;===========
; 29
rts ; 6
;===========
; 63
write_ay_both_end:
;.assert >write_ay_both = >write_ay_both_end, error, "write_ay_both crosses page"
;=======================================
; clear ay -- clear all 14 AY registers
; should silence the card
;=======================================
; 7+(74*14)+5=1048
clear_ay_both:
ldx #13 ; 2
lda #0 ; 2
sta MB_VALUE ; 3
clear_ay_left_loop:
jsr write_ay_both ; 6+63
dex ; 2
bpl clear_ay_left_loop ; 3
; -1
rts ; 6
;=======================================
; mute AY -- just turn off all 3 channels
; should silence the card
;
;=======================================
mute_ay_both:
ldx #7 ;
lda #$FF ;
sta MB_VALUE ;
mute_ay_left_loop:
jsr write_ay_both ;
rts ;
;=======================================
; unmute AY
; restore to value we had before muting
;=======================================
unmute_ay_both:
ldx #7 ;
lda ENABLE ;
sta MB_VALUE ;
unmute_ay_left_loop:
jsr write_ay_both ;
rts ;
clear_ay_end:
;.assert >clear_ay_both = >clear_ay_end, error, "clear_ay_both crosses page"
;=============================
; Setup
;=============================
mockingboard_setup_interrupt:
; for this game with things in language card including
; irq handler, always force IIc mode (where RAM swapped in
; and we put the irq handler address directly up at $FFFE)
lda #<interrupt_handler
sta $fffe
lda #>interrupt_handler
sta $ffff
; note elsewhere we put gs_interrupt_handler in $3FE/$3FF
; nop out the "lda $45" since we are bypassing the ROM irq handler
; that puts A in $45
lda #$EA
sta interrupt_smc
sta interrupt_smc+1
;=========================
; 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
;============================
; Note, on Apple II the clock isn't 1MHz but is actually closer to
; roughly 1.023MHz, and every 65th clock is stretched (it's complicated)
; 4fe7 / 1.023e6 = .020s, 50Hz
; 9c40 / 1.023e6 = .040s, 25Hz
; 411a / 1.023e6 = .016s, 60Hz
; French Touch uses
; 4e20 / 1.000e6 = .020s, 50Hz, which assumes 1MHz clock freq
sei ; disable interrupts just in case
lda #$40 ; Continuous interrupts, don't touch PB7
setup_irq_smc1:
sta MOCK_6522_ACR ; ACR register
lda #$7F ; clear all interrupt flags
setup_irq_smc2:
sta MOCK_6522_IER ; IER register (interrupt enable)
lda #$C0
setup_irq_smc3:
sta MOCK_6522_IFR ; IFR: 1100, enable interrupt on timer one oflow
setup_irq_smc4:
sta MOCK_6522_IER ; IER: 1100, enable timer one interrupt
lda #$E7
; lda #$20
setup_irq_smc5:
sta MOCK_6522_T1CL ; write into low-order latch
lda #$4f
; lda #$4E
setup_irq_smc6:
sta MOCK_6522_T1CH ; write into high-order latch,
; load both values into counter
; clear interrupt and start counting
rts
;=============================
; Disable Interrupt
;=============================
mockingboard_disable_interrupt:
sei ; disable interrupts just in case
lda #$40 ; Continuous interrupts, don't touch PB7
disable_irq_smc1:
sta MOCK_6522_ACR ; ACR register
lda #$7F ; clear all interrupt flags
disable_irq_smc2:
sta MOCK_6522_IER ; IER register (interrupt enable)
rts

8
demos/trogdor/qboot.inc Normal file
View File

@ -0,0 +1,8 @@
seek = $1126
driveon = $119D
driveoff = $1122
load_new = $11AB
load_address=$11C4
load_track=load_address+1
load_sector=load_address+2
load_length=load_address+3

View File

@ -0,0 +1,244 @@
; fast seek/multi-read
; copyright (c) Peter Ferrie 2015-16
; Paramaters for loading QLOAD
sectors = 14 ; user-defined
firsttrk = 1 ; user-defined, first track to read
firstsec = 0 ; user-defined, first sector to read
address = $12 ; user-defined
entry = $1200 ; user-defined
version = 1
;memory usage:
;256 bytes ($200-2ff) static table
grouped = $200
; stay away from interrupt vectors at $3fe !!!
;106 bytes ($300-369) static table
preshift = $300
zvalue = $fd ; only during init
znibble = $fe ; only during init
zmask = $ff ; only during init
WHICH_SLOT = $DA
; $26/$27 sector read location (ROM)
; $3D sector number (ROM)
; at entry (at least on AppleWin) A=1, X=60 (slot<<4), Y=0
; qkumba says cffa cards leave Y at $10
; 26/27 = 00/09
; 3D = 1
; For Disk II booting, the firmware loads track0/sector0
; to $800 and then jumps to $801
.org $800
.byte 1 ; number of sectors for ROM to load
boot_entry:
; this code loads two sectors up to $10/$11
; assume A=1 coming in here
lsr ; check sector number
; A=0, carry=1
tay ; Y=0
adc #$0f ; A=$10 (destintation)
sta $27 ; set or update address as needed
cmp #$12
; 10 11 12 (1 1 1)
; be, bf, c0 (1011 1011 1100)
; so if hit $c000 we are done
beq done_load_2 ; branch if loaded 2
inc $3d ; increment sector (faster to find)
; call to the read routine in proper slot
; using rts to jump indirect to
; $CX5C
; this routine reads sector in $3D on track in $41
; to address in $26/$27
; when it's done it jumps back to $801
stx WHICH_SLOT ; save for later
txa ; x is slot# << 4
lsr
lsr
lsr
lsr
ora #$c0 ; slot to PROM base
pha
lda #$5b ;read-1
pha
rts ; return used to call $CX5C in DISK II ROM
done_load_2:
; patch self modifying code for Q6L read
txa
ora #$8c ; slot to Q6L
; Q6L?
; if slot 6, after this A is $EC
; Y should be 2 here
patch_loop:
iny
ldx patchtbl-3, Y
sta code_begin, X ; replace placeholders with Q6L
; BE02 = EC? lda c0ec
; so sets to c08c (Q6L)
bne patch_loop
; patch self-modifying code for turning motor off
and #$f8 ; MOTOROFF (c088) -> c0e8
sta slotpatch7+1
; patch self-modifying code for turning motor on
clc
adc #1 ; MOTORON (c089) -> c0e9
sta slotpatch9+1
; patch self-modifying code for phase off
eor #9 ; PHASEOFF (c080)
sta slotpatch8+1
ldx #$3f
stx zmask
inx
ldy #$7f
bne skip_ahead ; branch always
; pad with zeros until $839
; $839 is the entry point
; adjusts address at $8FE to be entry point
; jumps to boot 2
;.res $839-*
; lda #>(entry-1)
; pha
; lda #<(entry-1)
; pha
; jsr preread
; jmp $1000 ; stage2 entry point
patchtbl:
.byte <(slotpatch1+1), <(slotpatch2+1), <(slotpatch3+1)
.byte <(slotpatch4+1), <(slotpatch5+1), <(slotpatch6+1)
indextbl: ;the 0 also terminates the patchtbl list!
.byte 0, 2, 1, 3
;construct denibbilisation table
;pre-shifted for interleave read
skip_ahead:
loopaa:
sty znibble
tya
asl
bit znibble
beq loopz
ora znibble
eor #$ff
and #$7e
loopa:
bcs loopz
lsr
bne loopa
dex
txa
asl
asl
sta preshift-$16, Y
loopz:
dey
bne loopaa
;construct 2-bit group table
sty zvalue
loopbb:
lsr zmask
lsr zmask
loopb:
lda indextbl, X
sta grouped, Y
inc zvalue
lda zvalue
and zmask
bne loopy
inx
txa
and #3
tax
loopy:
iny
iny
iny
iny
cpy #3
bcs loopb
iny
cpy #3
bcc loopbb
lda #>(entry-1)
pha
lda #<(entry-1)
pha
jsr preread
; seek backward support
; sty startsec+1
; sta tmpadr+1
; stx total+1
jmp seekread
preread:
;copy post-read if necessary
;push post-read address here
; pla
; tax
; pla
; tay
; lda #>(postread-1)
; pha
; lda #<(postread-1)
; pha
; tya
; pha
; txa
; pha
lda #<(firsttrk*2)
sta phase+1
ldx #sectors
lda #address
ldy #firstsec
rts
end_code:
.res $8fe-*
; traditionally, entry point to jump to at end of loading
; $1000 in this case
;*=$8fe
.byte $10, $00
.include "qboot_stage2.s"

View File

@ -0,0 +1,382 @@
; the following lives on sectors $0E and $0D
; why?
; request sector 2 and 4, and the interleave is
; beneath apple dos (3-23)
; Physical (firmware) : 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
; DOS33 mapping : 0, 7, 14, 6, 13, 5, 12, 4, 11, 3, 10, 2, 9, 1, 8, 15
; Beneath Apple DOS
; p86 (dos reference)
;
;WAIT = $FCA8 ;; delay 1/2(26+27A+5A^2) us
WAIT = norom_wait
.org $1000
code_begin:
.byte version
readnib:
slotpatch1: ; smc
lda $c0d1 ; gets set to C08C (Q6L) read
bpl readnib
rts
;fill address array for one track
seekread:
sty startsec+1
sta tmpadr+1
stx total+1
inittrk:
sec
lda #$10
sbc startsec+1
cmp total+1
bcs it_skip
tax
it_skip:
stx partial1
stx partial2
jsr seek
startsec:
ldy #$d1
tmpadr:
tmpadr_loop:
lda #$d1
sta addrtbl, y
inc tmpadr+1
iny
dec partial1
bne tmpadr_loop
;====================================
; read a sector
;====================================
; first address field
;====================================
; starts with $D5 $AA $96
; then XX YY volume
; then XX YY track
; then XX YY sector
; then XX YY checksum
; then ends with $DE $AA $EB
;====================================
; data field
;====================================
; starts with $D5 $AA $AD
; 342 bytes of data
; XX checksum
; ends with $DE $AA $EB
read:
outer_read:
jsr readnib
inner_read:
cmp #$d5 ; look for $D5 part of addr field
bne outer_read
jsr readnib ; look for $D5 $AA
cmp #$aa
bne inner_read
; look for $D5 $AA $AD
tay ; we need Y=#$AA later
jsr readnib
eor #$ad ; zero A if match
beq check_mode
; if not #$AD, then #$96 is assumed
; so in address field
ldy #2 ; volume, track, sector
another:
jsr readnib
rol ; set carry
sta sector+1
jsr readnib
and sector+1
dey
bpl another
tay
ldx addrtbl, Y ; fetch corresponding address
beq read ; done?
sta sector+1 ; store index for later
stx adrpatch1+2
stx adrpatch8+2
stx adrpatch2+2
stx adrpatch3+2
stx adrpatch5+2
stx adrpatch7+2
inx
stx adrpatch9+2
dex
dex
stx adrpatch4+2
stx adrpatch6+2
ldy #$fe
loop2:
adrpatch1:
lda $d102, Y
pha
iny
bne loop2
branch_read:
bcs read ; branch always
check_mode:
cpx #0
beq read ; loop if not expecting #$AD
loop33:
sta tmpval+1 ; zero rolling checksum
slotpatch2:
loop4:
ldx $c0d1
bpl loop4
lda preshift-$96, X
adrpatch2:
sta $d102, Y ; store 2-bit array
tmpval:
eor #$d1
iny
bne loop33
ldy #$aa
slotpatch3:
loop5:
ldx $c0d1
bpl loop5
eor preshift-$96, X
adrpatch3:
ldx $d102, Y ; bit2tbl
eor grouped+2, X ; first 86 nibbles use group bits 0-1
adrpatch4:
sta $d156, y
iny
bne loop5
and #$fc
ldy #$aa
slotpatch4:
loop6:
ldx $c0d1
bpl loop6
eor preshift-$96, X
adrpatch5:
ldx $d102, Y ; bit2tbl
eor grouped+1, X ; second 86 nibbles use group bits 2-3
adrpatch6:
sta $d1ac, Y
iny
bne loop6
and #$fc
ldx #$ac
slotpatch5:
loop7:
ldy $c0d1
bpl loop7
eor preshift-$96, Y
adrpatch7:
ldy $d100, X ; bit2tbl
eor grouped, Y ; last 84 nibbles use group bits 4-5
adrpatch8:
sta $d100, x
inx
bne loop7
and #$fc
slotpatch6:
loop8:
ldy $c0d1
bpl loop8
eor preshift-$96, Y
cmp #1 ; carry = !zero
ldy #1
loop9:
pla
adrpatch9:
sta $d100, Y
dey
bpl loop9
branch_read2:
bcs branch_read ; branch if checksum failure
sector:
ldy #$d1
txa
sta addrtbl, Y ; zero corresponding address
dec total+1
dec partial2 ; adjust remaining count
; (faster than looping over array)
sec
bne branch_read2 ; read all requested sectors in one track
sta startsec+1 ; this was missing from original code
; leading to trouble on wrap around
; it not starting at sector0
total:
ldx #$d1
beq driveoff
inc phase+1
inc phase+1 ; update current track
jmp inittrk
driveoff:
slotpatch7:
lda $c0d1
seekret:
rts
seek:
ldx #0
stx step+1
copy_cur:
curtrk:
lda #0
sta tmpval+1
sec
phase:
sbc #$d1
beq seekret
; if seek backwards
bcs sback
eor #$ff
inc curtrk+1
bcc ssback
sback:
adc #$fe
dec curtrk+1
ssback:
cmp step+1
bcc loop10
step:
lda #$d1
loop10:
cmp #8
bcs loop11
tay
sec
loop11:
lda curtrk+1
ldx step1, Y
bne loop12
loopmmm:
clc
lda tmpval+1
ldx step2, Y
loop12:
stx sector+1
and #3
rol
tax
slotpatch8:
sta $c0d1, X
loopmm:
ldx #$13
loopm:
dex
bne loopm
dec sector+1
bne loopmm
lsr
bcs loopmmm
inc step+1
bne copy_cur
step1: .byte 1, $30, $28, $24, $20, $1e, $1d, $1c
step2: .byte $70, $2c, $26, $22, $1f, $1e, $1d, $1c
addrtbl: .res 16
partial1: .byte $00
partial2: .byte $00
code_end:
;==========================
; enable drive motor
;==========================
driveon:
slotpatch9:
lda $c0d1
; wait 1s
ldx #6
wait_1s:
lda #255
jsr WAIT
dex
bne wait_1s
rts
load_new:
jsr driveon
lda load_track
asl ; track to start*2
sta phase+1
lda load_sector
tay ; sector to start
lda load_length ; length
tax
lda load_address ; address to load
jsr seekread
rts
load_address:
.byte $00
load_track:
.byte $00
load_sector:
.byte $00
load_length:
.byte $00
; copy of ROM wait
; because we might disable ROM
norom_wait:
sec
wait2:
pha
wait3:
sbc #$01
bne wait3
pla
sbc #$01
bne wait2
rts
wait_end:

208
demos/trogdor/qload.s Normal file
View File

@ -0,0 +1,208 @@
; Loader
.include "zp.inc"
.include "hardware.inc"
.include "music.inc"
;.include "common_defines.inc"
.include "qboot.inc"
qload_start:
; init the write code
; lda WHICH_SLOT
; jsr popwr_init
; first time entry
; start by loading text title
; lda #0 ; load ZW engine
; sta WHICH_LOAD
lda #1
sta CURRENT_DISK ; current disk number
; jsr load_file
jmp xmas_start
; jmp $2000 ; jump to ZW
;====================================
; loads file specified by WHICH_LOAD
;====================================
load_file:
ldx WHICH_LOAD
lda which_disk_array,X
cmp CURRENT_DISK
bne change_disk
load_file_no_diskcheck:
lda load_address_array,X
sta load_address
lda track_array,X
sta load_track
lda sector_array,X
sta load_sector
lda length_array,X
sta load_length
jsr load_new
rts
;===================================================
;===================================================
; change disk
;===================================================
;===================================================
change_disk:
.if 0
; turn off disk drive light
jsr driveoff
jsr TEXT
jsr HOME
lda #<error_string
sta OUTL
lda #>error_string
sta OUTH
ldx WHICH_LOAD
lda which_disk_array,X
clc
adc #48
ldy #19
sta (OUTL),Y
ldy #0
quick_print:
lda (OUTL),Y
beq quick_print_done
jsr COUT1
iny
jmp quick_print
quick_print_done:
fnf_keypress:
lda KEYPRESS
bpl fnf_keypress
bit KEYRESET
;==============================================
; actually verify proper disk is there
; read T0:S0 and verify proper disk
lda WHICH_LOAD
pha
ldx #LOAD_FIRST_SECTOR ; load track 0 sector 0
stx WHICH_LOAD
jsr load_file_no_diskcheck
pla
sta WHICH_LOAD
tax
; first sector now in $c00
; offset 59
; disk1 = $0a
; disk2 = $32 ('2')
; disk3 = $33 ('3')
lda $c59
cmp #$0a
beq is_disk1
cmp #$32
beq is_disk2
cmp #$33
beq is_disk3
bne change_disk ; unknown disk
is_disk1:
lda #1
bne disk_compare
is_disk2:
lda #2
bne disk_compare
is_disk3:
lda #3
disk_compare:
cmp which_disk_array,X
bne change_disk ; disk mismatch
;==============================================
; all good, retry original load
jsr HOME
ldx WHICH_LOAD
lda which_disk_array,X
sta CURRENT_DISK
jmp load_file
; offset for disk number is 19
error_string:
.byte "PLEASE INSERT DISK 1, PRESS RETURN",0
.endif
which_disk_array:
.byte 1,1 ; MUSIC, XMAS
load_address_array:
.byte $D0,$80 ; MUSIC, XMAS
start_address:
.byte $D0,$80 ; MUSIC, XMAS
track_array:
.byte 4,12 ; MUSIC, XMAS
sector_array:
.byte 0,0 ; MUSIC, XMAS
length_array:
.byte 32,32 ; MUSIC, XMAS
PT3_ENABLE_APPLE_IIC = 1
.include "wait.s"
.include "start.s"
.include "lc_detect.s"
.include "wait_a_bit.s"
.include "gr_fast_clear.s"
.include "text_print.s"
.include "gr_offsets.s"
.include "pt3_lib_detect_model.s"
.include "pt3_lib_mockingboard_detect.s"
mod7_table = $1c00
div7_table = $1d00
hposn_low = $1e00
hposn_high = $1f00
.include "hgr_table.s"
qload_end:
.assert (>qload_end - >qload_start) < $e , error, "loader too big"

197
demos/trogdor/start.s Normal file
View File

@ -0,0 +1,197 @@
; XMAS 2023
;
; by deater (Vince Weaver) <vince@deater.net>
xmas_start:
;=====================
; initializations
;=====================
jsr hardware_detect
jsr hgr_make_tables
;===================
; restart?
;===================
restart:
lda #0
sta DRAW_PAGE
;==================================
; load music into the language card
; into $D000 set 1
;==================================
; read/write RAM, use $d000 bank1
bit $C083
bit $C083
lda #0 ; load MUSIC from disk
sta WHICH_LOAD
jsr load_file
lda #0
sta DONE_PLAYING
lda #1
sta LOOP
; patch mockingboard
lda SOUND_STATUS
beq skip_mbp1
jsr mockingboard_patch ; patch to work in slots other than 4?
skip_mbp1:
;=======================
; Set up 50Hz interrupt
;========================
jsr mockingboard_init
jsr mockingboard_setup_interrupt
;============================
; Init the Mockingboard
;============================
jsr reset_ay_both
jsr clear_ay_both
;==================
; init song
;==================
jsr pt3_init_song
dont_enable_mc:
skip_all_checks:
;=======================
;=======================
; Print message
;=======================
;=======================
; print non-inverse
jsr set_normal
lda SOUND_STATUS
and #SOUND_MOCKINGBOARD
beq print_no_mock
print_mock:
lda MB_ADDR_H
and #$7
clc
adc #$B0
sta mockingboard_string+29
lda #<mockingboard_string
sta OUTL
lda #>mockingboard_string
jmp done_set_message
print_no_mock:
lda #<no_mockingboard_string
sta OUTL
lda #>no_mockingboard_string
done_set_message:
sta OUTH
; print the text
jsr move_and_print
;=======================
;=======================
; Load xmas
;=======================
;=======================
load_xmas:
; load from disk
lda #1 ; XMAS
sta WHICH_LOAD
jsr load_file
;=======================
;=======================
; Run intro
;=======================
;=======================
; cli ; start music
jsr $8000
; bit PAGE1 ; be sure we're on PAGE1
; clear text screen
; lda #$A0
; sta clear_all_color+1
; jsr clear_all
; switch to text/gr
; bit TEXTGR
; print non-inverse
; jsr set_normal
; print messages
; lda #<disk_change_string
; sta OUTL
; lda #>disk_change_string
; sta OUTH
; print the text
; jsr move_and_print
; bit KEYRESET ; just to be safe
; jsr wait_until_keypress
forever:
jmp forever
.include "wait_keypress.s"
.include "zx02_optim.s"
.include "gs_interrupt.s"
;.include "title.s"
; 0123456789012345678901234567890123456789
mockingboard_string:
.byte 6,22,"MOCKINGBOARD DETECTED SLOT 4",0
no_mockingboard_string:
.byte 3,22,"NO MOCKINGBOARD, CONTINUING ANYWAY",0
.include "pt3_lib_mockingboard_patch.s"
.include "hardware_detect.s"

View File

@ -0,0 +1,93 @@
;================================
; move_and_print
;================================
; get X,Y from OUTL/OUTH
; then print following string to that address
; stop at NUL
; convert to APPLE ASCII (or with 0x80)
; leave OUTL/OUTH pointing to next string
move_and_print:
ldy #0
lda (OUTL),Y
sta CH
iny
lda (OUTL),Y
asl
tay
lda gr_offsets,Y ; lookup low-res memory address
clc
adc CH ; add in xpos
sta BASL ; store out low byte of addy
lda gr_offsets+1,Y ; look up high byte
adc DRAW_PAGE ;
sta BASH ; and store it out
; BASH:BASL now points at right place
clc
lda OUTL
adc #2
sta OUTL
lda OUTH
adc #0
sta OUTH
;================================
; print_string
;================================
print_string:
ldy #0
print_string_loop:
lda (OUTL),Y
beq done_print_string
ps_smc1:
and #$3f ; make sure we are inverse
sta (BASL),Y
iny
bne print_string_loop
done_print_string:
iny
clc
tya
adc OUTL
sta OUTL
lda OUTH
adc #0
sta OUTH
rts
; set normal text
set_normal:
lda #$80
sta ps_smc1+1
lda #09 ; ora
sta ps_smc1
rts
; restore inverse text
set_inverse:
lda #$29
sta ps_smc1
lda #$3f
sta ps_smc1+1
rts
;================================
; move and print a list of lines
;================================
; look for negative X meaning done
move_and_print_list:
jsr move_and_print
ldy #0
lda (OUTL),Y
bpl move_and_print_list
rts

85
demos/trogdor/trogdor.s Normal file
View File

@ -0,0 +1,85 @@
; TROGDOR 2024
.include "hardware.inc"
.include "zp.inc"
.include "qload.inc"
.include "music.inc"
trogdor_main:
;======================================
; init
;======================================
lda #$00
sta DRAW_PAGE
sta clear_all_color+1
lda #$04
sta DRAW_PAGE
jsr clear_all
;======================================
; draw opening scene
;======================================
lda #<trog00_graphics
sta zx_src_l+1
lda #>trog00_graphics
sta zx_src_h+1
lda #$20
jsr zx02_full_decomp
bit SET_GR
bit HIRES
bit FULLGR
bit PAGE1
jsr wait_until_keypress
; second
lda #<trog03_graphics
sta zx_src_l+1
lda #>trog03_graphics
sta zx_src_h+1
lda #$20
jsr zx02_full_decomp
finished:
jmp finished
; start music
lda SOUND_STATUS
and #SOUND_MOCKINGBOARD
beq no_music
cli ; enable sound
no_music:
;0123456789012345678901234567890123456789
merry_text:
.byte " MERRY CHRISTMAS!!! MERRY CHRISTMAS!!! ME"
trog00_graphics:
.incbin "graphics/trog00_trogdor.hgr.zx02"
trog03_graphics:
.incbin "graphics/trog03_man.hgr.zx02"
.include "wait_keypress.s"
.include "irq_wait.s"

18
demos/trogdor/wait.s Normal file
View File

@ -0,0 +1,18 @@
; copy of ROM wait
; because we might disable ROM
wait:
sec
wait2:
pha
wait3:
sbc #$01
bne wait3
pla
sbc #$01
bne wait2
rts
wait_end:
.assert (>wait_end - >wait) < 1 , error, "wait crosses page boundary"

View File

@ -0,0 +1,37 @@
;====================================
; wait for keypress or a few seconds
;====================================
; A is length to wait
wait_a_bit:
bit KEYRESET
tax
keyloop:
lda #200 ; delay a bit
jsr wait
lda KEYPRESS
bmi done_keyloop
dex
bne keyloop
; beq no_escape
done_keyloop:
; and #$7f
; cmp #27
; bne no_escape
; inc ESC_PRESSED
;no_escape:
bit KEYRESET
rts

View File

@ -0,0 +1,5 @@
wait_until_keypress:
lda KEYPRESS ; 4
bpl wait_until_keypress ; 3
bit KEYRESET ; clear the keyboard buffer
rts ; 6

251
demos/trogdor/zp.inc Normal file
View File

@ -0,0 +1,251 @@
;==================
;==================
; Zero Page Usage
;==================
;==================
; ZX0 decompression addresses
ZX0_src = $00
ZX0_dst = $02
offset = $04
bitr = $06
pntr = $07
WHICH_LOAD = $09
CURRENT_DISK = $0A
; Zero page monitor routines addresses
; We don't use the monitor but we use some of these anyway
WNDLFT = $20
WNDWDTH = $21
WNDTOP = $22
WNDBTM = $23
CH = $24
CV = $25
GBASL = $26
GBASH = $27
BASL = $28
BASH = $29
H2 = $2C
V2 = $2D
MASK = $2E
COLOR = $30
;INVFLG = $32
;==========================
; $60-$6F unused currently
;==========================
;==========================
; $70-$7F for PT3 Player
;==========================
AY_REGISTERS = $70
A_FINE_TONE = $70
A_COARSE_TONE = $71
B_FINE_TONE = $72
B_COARSE_TONE = $73
C_FINE_TONE = $74
C_COARSE_TONE = $75
NOISE = $76
ENABLE = $77
PT3_MIXER_VAL = $77
A_VOLUME = $78
B_VOLUME = $79
C_VOLUME = $7A
ENVELOPE_FINE = $7B
ENVELOPE_COARSE = $7C
ENVELOPE_SHAPE = $7D
PATTERN_L = $7E
PATTERN_H = $7F
;============================
; $80-$8D rest of pt3_player
;============================
PT3_TEMP = $80
ORNAMENT_L = $81
ORNAMENT_H = $82
SAMPLE_L = $83
SAMPLE_H = $84
LOOP = $85
MB_VALUE = $86
MB_ADDR_L = $87
MB_ADDR_H = $88
DONE_PLAYING = $89
DONE_SONG = $8A
APPLEII_MODEL = $8B
SOUND_STATUS = $8C
SOUND_DISABLED = $80
SOUND_IN_LC = $01 ; $01 sound effects in language card
SOUND_MOCKINGBOARD = $02 ; mockingboard detected
;=============================
; not sure why these are here
;=============================
DISP_PAGE = $8D
DRAW_PAGE = $8E
TOTAL_RAM = $8F
;=============================
; $90-$CF currently free
;=============================
;=============================
; $D0-$D9 = hgr move
;=============================
HGR_X1 = $D0
HGR_X2 = $D1
HGR_Y1 = $D2
HGR_Y2 = $D3
HGR_DEST= $D4
BOARD_COUNT = $D5
WHICH_SLOT = $DA ; from boot sector
;==============================================
; $E0-$EF use for common things, don't re-use
;==============================================
IRQ_COUNTDOWN = $E0
SECOND_COUNTDOWN= $E1
COUNT = $E2
XSAVE = $E3
TEMPY = $E4
XPOS = $E5 ; gr_plot
YPOS = $E6 ; gr_plot
COLOR_MASK = $E7 ; gr_plot
FRAMEL = $E8
FRAMEH = $E9
BTC_L = $EA ; audio
BTC_H = $EB ; audio
MASKL = $EC ; gr_putsprite_mask
MASKH = $ED
FRAME = $EE
;==============================================
; $F0-$FB can re-use in each file
;==============================================
; tunnel
XX = $F2
MINUSXX = $F3
YY = $F4
MINUSYY = $F5
D = $F6
R = $F7
CX = $F8
CY = $F9
RR = $FA
; Credits
BACKUP_OUTL = $F2
BACKUP_OUTH = $F3
; Nuts/ opener
SPRITE_Y = $F2
SPRITE_X = $F3
CURRENT_ROW = $F4
; PLASMACUBE
OUT1 = $F0
OUT1H = $F1
OUT2 = $F2
OUT2H = $F3
COMPT1 = $F4
COMPT2 = $F5
PARAM1 = $F6
PARAM2 = $F7
PARAM3 = $F8
PARAM4 = $F9
GRLINE = $FA
GRLINEH = $FB
; PLASMA
; CUBE
SAVEX = $F3
SAVEY = $F4
SUM = $F5
; CIRCLES/DRAW_BOXES
COLOR2 = $F3
X1 = $F4
X2 = $F5
Y1 = $F6
Y2 = $F7
SCENE_COUNT = $F8
LAST_TYPE = $F9
; lens
LENS_X = $F0
LENS_Y = $F1
XADD = $F2
YADD = $F3
; rotozoom
NUM1L = $F0
NUM1H = $F1
NUM2L = $F2
NUM2H = $F3
RESULT = $F4 ; F5,F6,F7
SCALE_I = $F8
SCALE_F = $F9
ANGLE = $FA
; credits
SCROLL_X = $F0
; polar
SCROLL_START = $F0
YDEST = $F1
; hgr_copy
HGR_COPY_Y1 = $F1
HGR_COPY_Y2 = $F2
FIRE_COLOR = $F3
SCROLL_LENGTH = $F4
OFFSET = $F5
TREE_COUNT = $F6
;==============================================
; $FC-$FF we use for in/out pointers
;==============================================
INL = $FC
INH = $FD
OUTL = $FE
OUTH = $FF
; read any file slot 6 version
; based on FASTLD6 and RTS copyright (c) Peter Ferrie 2011-2013,2018
; modified to assembled with ca64 -- vmw
; added code to patch it to run from current disk slot -- vmw
adrlo = $26 ; constant from boot prom
adrhi = $27 ; constant from boot prom
tmpsec = $3c ; constant from boot prom
reqsec = $3d ; constant from boot prom
sizelo = $44
sizehi = $45
secsize = $46
ldsizel = $f0
ldsizeh = $f1
namlo = $fb
namhi = $fc
step = $fd ; state for stepper motor
tmptrk = $fe ; temporary copy of current track
phase = $ff ; current phase for /seek

159
demos/trogdor/zx02_optim.s Normal file
View File

@ -0,0 +1,159 @@
; De-compressor for ZX02 files
; ----------------------------
;
; Decompress ZX02 data (6502 optimized format), optimized for speed and size
; 138 bytes code, 58.0 cycles/byte in test file.
;
; Compress with:
; zx02 input.bin output.zx0
;
; (c) 2022 DMSC
; Code under MIT license, see LICENSE file.
;ZP=$80
;offset = ZP+0
;ZX0_src = ZP+2
;ZX0_dst = ZP+4
;bitr = ZP+6
;pntr = ZP+7
; Initial values for offset, source, destination and bitr
;zx0_ini_block:
; .byte $00, $00, <comp_data, >comp_data, <out_addr, >out_addr, $80
;--------------------------------------------------
; Decompress ZX0 data (6502 optimized format)
zx02_full_decomp:
; ; Get initialization block
; ldy #7
;
;copy_init: lda zx0_ini_block-1, y
; sta offset-1, y
; dey
; bne copy_init
sta ZX0_dst+1 ; page to output to in A
zx_src_l:
ldy #$dd
sty ZX0_src
zx_src_h:
ldy #$dd
sty ZX0_src+1
ldy #$80
sty bitr
ldy #0
sty offset
sty offset+1
sty ZX0_dst ; always on even page
; Decode literal: Ccopy next N bytes from compressed file
; Elias(length) byte[1] byte[2] ... byte[N]
decode_literal:
jsr get_elias
cop0: lda (ZX0_src), y
inc ZX0_src
bne plus1
inc ZX0_src+1
plus1: sta (ZX0_dst),y
inc ZX0_dst
bne plus2
inc ZX0_dst+1
plus2: dex
bne cop0
asl bitr
bcs dzx0s_new_offset
; Copy from last offset (repeat N bytes from last offset)
; Elias(length)
jsr get_elias
dzx0s_copy:
lda ZX0_dst
sbc offset ; C=0 from get_elias
sta pntr
lda ZX0_dst+1
sbc offset+1
sta pntr+1
cop1:
lda (pntr), y
inc pntr
bne plus3
inc pntr+1
plus3: sta (ZX0_dst),y
inc ZX0_dst
bne plus4
inc ZX0_dst+1
plus4: dex
bne cop1
asl bitr
bcc decode_literal
; Copy from new offset (repeat N bytes from new offset)
; Elias(MSB(offset)) LSB(offset) Elias(length-1)
dzx0s_new_offset:
; Read elias code for high part of offset
jsr get_elias
beq exit ; Read a 0, signals the end
; Decrease and divide by 2
dex
txa
lsr ; @
sta offset+1
; Get low part of offset, a literal 7 bits
lda (ZX0_src), y
inc ZX0_src
bne plus5
inc ZX0_src+1
plus5:
; Divide by 2
ror ; @
sta offset
; And get the copy length.
; Start elias reading with the bit already in carry:
ldx #1
jsr elias_skip1
inx
bcc dzx0s_copy
; Read an elias-gamma interlaced code.
; ------------------------------------
get_elias:
; Initialize return value to #1
ldx #1
bne elias_start
elias_get: ; Read next data bit to result
asl bitr
rol ; @
tax
elias_start:
; Get one bit
asl bitr
bne elias_skip1
; Read new bit from stream
lda (ZX0_src), y
inc ZX0_src
bne plus6
inc ZX0_src+1
plus6: ;sec ; not needed, C=1 guaranteed from last bit
rol ;@
sta bitr
elias_skip1:
txa
bcs elias_get
; Got ending bit, stop reading
exit:
rts