xmas_2023: hook up vapor lock

This commit is contained in:
Vince Weaver 2023-12-18 01:00:54 -05:00
parent 3d39890a27
commit a741425e4a
4 changed files with 359 additions and 4 deletions

View File

@ -125,6 +125,7 @@ XMAS: xmas.o
xmas.o: xmas.s plasma_tree.s fireplace.s \
zp.inc hardware.inc qload.inc \
vapor_lock.s \
graphics/merry.hgr.zx02 \
graphics/tree01.gr.zx02
ca65 -o xmas.o xmas.s -l xmas.lst

25
demos/xmas_2023/delay_a.s Normal file
View File

@ -0,0 +1,25 @@
; From http://6502org.wikidot.com/software-delay
; 25+A cycles (including JSR), 19 bytes (excluding JSR)
;
; The branches must not cross page boundaries!
;
; Cycles Accumulator Carry flag
; 0 1 2 3 4 5 6 (hex) 0 1 2 3 4 5 6
; jsr delay_a ; 6 6 6 6 6 6 6 00 01 02 03 04 05 06
dly0: sbc #7
delay_a:cmp #7 ; 2 2 2 2 2 2 2 00 01 02 03 04 05 06 0 0 0 0 0 0 0
bcs dly0 ; 2 2 2 2 2 2 2 00 01 02 03 04 05 06 0 0 0 0 0 0 0
lsr ; 2 2 2 2 2 2 2 00 00 01 01 02 02 03 0 1 0 1 0 1 0
bcs dly1 ; 2 3 2 3 2 3 2 00 00 01 01 02 02 03 0 1 0 1 0 1 0
dly1: beq dly2 ; 3 3 2 2 2 2 2 00 00 01 01 02 02 03 0 1 0 1 0 1 0
lsr ; 2 2 2 2 2 00 00 01 01 01 1 1 0 0 1
beq dly3 ; 3 3 2 2 2 00 00 01 01 01 1 1 0 0 1
bcc dly3 ; 3 3 2 01 01 01 0 0 1
dly2: bne dly3 ; 2 2 3 00 00 01 0 1 0
dly3: rts ; 6 6 6 6 6 6 6 00 00 00 00 01 01 01 0 1 1 1 0 0 1
;
; Total cycles: 25 26 27 28 29 30 31

View File

@ -1,7 +1,7 @@
fireplace:
bit SET_GR
bit HIRES
bit LORES
bit FULLGR
bit PAGE1
@ -12,15 +12,15 @@ fireplace:
lda #$20
jsr zx02_full_decomp
jsr wait_until_keypress
; jsr wait_until_keypress
bit SET_GR
bit LORES
bit FULLGR
bit PAGE1
bit PAGE2
lda #0
lda #4
sta DRAW_PAGE
bit KEYRESET
@ -32,8 +32,61 @@ fireplace:
jsr draw_scene
bit PAGE1
jsr vapor_lock
bit PAGE2
; vapor lock returns with us at beginning of hsync in line
; 114 (7410 cycles), so with 5070 lines to go to vblank
; then we want another 4550 cycles to end, so 9620
loop_forever:
;================================================
; each scan line 65 cycles
; 1 cycle each byte (40cycles) + 25 for horizontal
; Total of 12480 cycles to draw screen
; Vertical blank = 4550 cycles (70 scan lines)
; Total of 17030 cycles to get back to where was
; 8515 cycles as lores
; -4
bit LORES ; 4
; Try X=8 Y=185 cycles=8511
ldy #185 ; 2
loop1: ldx #8 ; 2
loop2: dex ; 2
bne loop2 ; 2nt/3
dey ; 2
bne loop1 ; 2nt/3
; Try X=15 Y=105 cycles=8506
bit HIRES ; 4
nop
ldy #105 ; 2
loop3: ldx #15 ; 2
loop4: dex ; 2
bne loop4 ; 2nt/3
dey ; 2
bne loop3 ; 2nt/3
jmp loop_forever ; 3
jsr wait_until_keypress
cli ; enable sound: FIXME check if mockingboard there
rts
fireplace_data:
@ -738,3 +791,6 @@ gr_offsets_h:
merry_graphics:
.incbin "graphics/merry.hgr.zx02"
.include "vapor_lock.s"
.include "delay_a.s"

View File

@ -0,0 +1,273 @@
; This took a while to track down
; On Apple II/II+ the horiz blanking addr are $1000 higher than on IIe
; So on II+ were outside video area, so unlikely to be our set value
; (unless I foolishly use $ff which some uninitialized mem is set to)
; Lots of this color fiddling is to make sure you don't accidentally
; get runs of colors on IIe due to the horiz blank
; 0-5 aqua 6-12 = grey, 13 - 20 = yellow, 21-23 = aqua rainbow 14
;
;
;16 0 YA
;17 1 YA
;18 2 YA
;19 3 YA
;20 4 YA
;21 5 AA
;22 6 AG
;23 7 AG
;0 8 AG
;1 9 AG
;2 10 AG
;3 11 AG
;4 12 AG
;5 13 AY ****
;6 14 GY RAINBOW
;7 15 GY
;8 16 GY
;9 17 GY
;10 18 GY
;11 19 GY
;12 20 GY
;13 21 YA
;14 22 YA
;15 23 YA
;==============================
; setup graphics for vapor lock
;==============================
vapor_lock:
; Clear Page0
lda #$0
sta DRAW_PAGE
lda #$ee ; full screen white $ff
jsr clear_gr
lda #$dd
ldy #20
jsr clear_page_loop ; make bottom half yellow $dd
lda #$aa
ldy #12
jsr clear_page_loop ; make middle grey2 $aa
lda #$ee
ldy #5
jsr clear_page_loop ; make top half aqua $ee
; set up a rainbow to aid in exact lock
ldy #00
rainbow_loop:
tya
sta $728+20,Y
iny
cpy #20
bne rainbow_loop
;btt:
; jmp btt
;=====================================================
; attempt vapor lock
; by reading the "floating bus" we can see most recently
; written value of the display
;=====================================================
; See:
; Have an Apple Split by Bob Bishop
; Softalk, October 1982
; Challenges: each scan line scans 40 bytes.
; The blanking happens at the *beginning*
; So 65 bytes are scanned, starting at adress of the line - 25
; the scan takes 8 cycles, look for 4 repeats of the value
; to avoid false positive found if the horiz blanking is mirroring
; the line (max 3 repeats in that case)
vapor_lock_loop:
; first make sure we have a full line of $aa
lda #$aa ; 2
zxloop:
ldx #$04 ; 2
wiloop:
cmp $C052 ; read the floating bus ; 4
bne zxloop ; if not, start from scratch ; 2/3
dex ; we were, dec ; 2
bne wiloop ; if not 4 of them, restart ; 3/2
; if we get here we read 4 proper pixels, 11 apart (2+4+2+2+3)
; 0 11 22 33, clock at 34
; 1 12 23 34, clock at 35
; 2 13 24 35, clock at 36
; 3 14 25 36, clock at 37
; 4 15 26 37, clock at 38
; 5 16 27 38, clock at 39
; 6 17 28 39, clock at 40
; X X X X
; X X X X
; X X X X
; X X X X
; X X X X
; X X X X
; X X X X
; 0123456789012345678901234 0123456789012345678901234567890123456789
; 1 2 1 2 3
; hsync pixels
; XXXXXXXXXXXXXXXXXXXXXXXXX 4444444444444444444444444444440123456789
; now look for the color change that
; happens at line 13*8 = 104
lda #$dd ; 2
zloop:
ldx #$04 ; 2
qloop:
cmp $C052 ; read floating bus ; 4
bne zloop ; 2/3
dex ; 2
bne qloop ; 3/2
;============
; 11
; Found it!
; if we get here we read 4 proper pixels, 11 apart (2+4+2+2+3)
; 0 11 22 33, clock at 34
; 1 12 23 34, clock at 35
; 2 13 24 35, clock at 36
; 3 14 25 36, clock at 37
; 4 15 26 37, clock at 38
; 5 16 27 38, clock at 39
; 6 17 28 39, clock at 40
;btt:
; jmp btt
; In theory near end of line 104
; now skip ahead 8 lines and read from the rainbow pattern we set
; up to find our exact location
; delay 65 * 8 = 520
; we back off a few to make sure we're not in the horiz blank
; try to delay 510
; *NOTE* sometimes we end up going one (or rarely, two??) lines too far
; so instead try going 7 lines ahead, and if still dd then one more
; so single step until we get a rainbow color
; go to next line, -10
lda #28 ; 2
jsr delay_a ; delay 25+28 = 53
; total delay = 55
vl_try_again:
lda #29 ; 2
jsr delay_a ; delay 25+29 = 54
; total delay = 56
lda $C052 ; 4
cmp #$dd ; 2
beq vl_try_again ; 3
; -1
; now near end of line 112
;lda $0 ; nop to match old code ; 3
; nop ; nop to match old code ; 2
lda $C052 ; 4
;kbb:
; jmp kbb
; we are in theory on line $728 = 14*8 = 112
; so 112*65 = 7280 cycles from start
; we are actualy 25+20+A pixels in
; 7325+A
; Our goal is line 114 at 7410 cycles
; 7410 - 7325 = 85
; so kill 85-A cycles
; -6 to do subtraction
; -6 for rts
; -25 for delay_a overhead
eor #$ff ; 2
sec ; 2
adc #48 ; 2
jsr delay_a ; should total 48 cycles
done_vapor_lock:
rts ; 6
;==================================
; Vapor HLINE
;==================================
; FIXME: merge with generic hline code?
; Color in A
; Y has which line
hline:
pha ; 3
ldx gr_offsets_l,y ; 4+
stx hline_loop+1 ; 4
lda gr_offsets_h,y ; 4+
clc ; 2
adc DRAW_PAGE ; 3
sta hline_loop+2 ; 4
pla ; 4
ldx #39 ; 2
hline_loop:
sta $5d0,X ; 38 ; 5
dex ; 2
bpl hline_loop ; 2nt/3
rts ; 6
;==========================
; Clear gr screen
;==========================
; Color in A
clear_gr:
ldy #23
clear_page_loop:
jsr hline
dey
bpl clear_page_loop
rts
; Some random related work
; Docs:
; Lancaster
; Bishop
; Sather
; Vaguely relevant but no help with the Apple II+ issue
;
; Eamon: Screen display and timing synchronization
; on the Apple IIe and Apple IIgs
;
; Adams: Visually presented verbal stimuli by assembly
; language on the Apple II computer.
; Cavanagh and Anstis: Visual psychophysics on the
; Apple II: Getting started