From 32a242e9d156cf4a31db6a22eed88cdb623b22e5 Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Wed, 26 Sep 2018 16:42:06 -0400 Subject: [PATCH] credits: start making it use common infrastructure --- split_screen/Makefile | 2 +- split_screen/credits.s | 134 ++++++++--------------- split_screen/delay_a.s | 25 +++++ split_screen/gr_hline.s | 48 +++++++++ split_screen/vapor_lock.s | 216 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 332 insertions(+), 93 deletions(-) create mode 100644 split_screen/delay_a.s create mode 100644 split_screen/gr_hline.s create mode 100644 split_screen/vapor_lock.s diff --git a/split_screen/Makefile b/split_screen/Makefile index bf131236..c3aa4313 100644 --- a/split_screen/Makefile +++ b/split_screen/Makefile @@ -33,7 +33,7 @@ RAINBOW.BAS: rainbow.bas $(TOKENIZE) < rainbow.bas > RAINBOW.BAS credits.o: credits.s tfv_sprites.inc mockingboard.s \ - lz4_decode.s \ + lz4_decode.s vapor_lock.s \ KATC.BIN.lz4 ca65 -o credits.o credits.s -l credits.lst diff --git a/split_screen/credits.s b/split_screen/credits.s index 5e8fedde..3706cfad 100644 --- a/split_screen/credits.s +++ b/split_screen/credits.s @@ -1,3 +1,7 @@ +; +; Cycle-counting text/hgr/lowres demo +; by Vince Weaver + .include "zp.inc" FRAME = $60 @@ -85,61 +89,40 @@ no_init_mb: ;========================== ; setup text screen - lda #0 - sta CH - sta CV - lda #line1 - sta OUTH - jsr move_and_print + ; clear top 6 lines to space - inc CV - jsr move_and_print + ; takes (Y/2)*(6+435+7)+5 = ? + lda #$A0 ; space ; 2 + ldy #10 ; 6 lines ; 2 + jsr clear_page_loop ; 2693??? - inc CV - jsr move_and_print - - inc CV - jsr move_and_print - - inc CV - jsr move_and_print - - inc CV - jsr move_and_print +; 1 2 +; 0123456789abcdef0123456789abcdef0123456 +;line1:.asciiz " * . " $400 +;line2:.asciiz " * . . " $480 +;line3:.asciiz " * " $500 +;line4:.asciiz " * " $580 +;line5:.asciiz " . . . " $600 +;line6:.asciiz " . " $680 + lda #'.'|$80 ; print star ; 2 + sta $420 ; 4 + sta $487 ; 4 + sta $4A4 ; 4 + sta $601 ; 4 + sta $61c ; 4 + sta $621 ; 4 + sta $68d ; 4 + ;============ + ; 30 ; draw the moon - lda #0 - sta CV - lda #3 - sta CH - jsr htab_vtab ; vtab(1); htab(4) - lda #32 ; inverse space - ldy #0 - sta (BASL),Y - - inc CV - dec CH - jsr htab_vtab - lda #32 - ldy #0 - sta (BASL),Y - - inc CV - jsr htab_vtab - lda #32 - ldy #0 - sta (BASL),Y - - inc CV - inc CH - jsr htab_vtab - lda #32 - ldy #0 - sta (BASL),Y - - + lda #' ' ; print inv space ; 2 + sta $403 ; 4 + sta $482 ; 4 + sta $502 ; 4 + sta $583 ; 4 + ;============ + ; 18 ; test letters ;letter_loop: ; lda #80 @@ -149,7 +132,7 @@ no_init_mb: ; Wait -; jsr wait_until_keypressed + jsr wait_until_keypressed ; GR part bit LORES @@ -171,41 +154,9 @@ no_init_mb: ;===================================================== ; attempt vapor lock - ; by reading the "floating bus" we can see most recently - ; written value of the display - ; we look for $44 (which is the green grass on low-res) ;===================================================== - ; See: - ; Have an Apple Split by Bob Bishop - ; Softalk, October 1982 + jsr vapor_lock - ; 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: - LDA #$A0 -zxloop: - LDX #$04 -wiloop: - CMP $C051 - BNE zxloop - DEX - BNE wiloop - - LDA #$44 -zloop: - LDX #$04 -qloop: - CMP $C051 - BNE zloop - DEX - BNE qloop ; found first line of low-res green, need to kill time ; until we can enter at top of screen @@ -960,18 +911,17 @@ letters: .byte 255 -line1:.asciiz " * . " -line2:.asciiz " * . . " -line3:.asciiz " * " -line4:.asciiz " * " -line5:.asciiz " . . . " -line6:.asciiz " . " + + +.include "vapor_lock.s" +.include "delay_a.s" +.include "gr_hline.s" .include "../asm_routines/text_print.s" .include "mockingboard.s" +.include "../asm_routines/keypress.s" .align $100 -.include "../asm_routines/gr_offsets.s" .include "tfv_sprites.inc" .include "lz4_decode.s" diff --git a/split_screen/delay_a.s b/split_screen/delay_a.s new file mode 100644 index 00000000..2d0802da --- /dev/null +++ b/split_screen/delay_a.s @@ -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 diff --git a/split_screen/gr_hline.s b/split_screen/gr_hline.s new file mode 100644 index 00000000..9465bc7b --- /dev/null +++ b/split_screen/gr_hline.s @@ -0,0 +1,48 @@ + ;================================== + ; HLINE + ;================================== + ; Color in A + ; Y has which line + ; takes 435 cycles +hline: + pha ; 3 + ldx gr_offsets,y ; 4+ + stx hline_loop+1 ; self-modify code ; 4 + lda gr_offsets+1,y ; 4+ + clc ; 2 + adc DRAW_PAGE ; 3 + sta hline_loop+2 ; self-modify code ; 4 + pla ; 4 + ldx #39 ; 2 + ;=========== + ; 30 +hline_loop: + sta $5d0,X ; 38 ; 5 + dex ; 2 + bpl hline_loop ; 2nt/3 + ;=========== + ; 40*(10)=400 + + ; -1 + rts ; 6 + + ;========================== + ; Clear gr screen + ;========================== + ; Color in A, Clears 0 to and including Y + ; clear_gr: takes 2+(48/2)*(6+435+7)+5 = 10759 + ; cpl: takes (Y/2)*(6+435+7)+5 = ? +clear_gr: + ldy #46 ; 2 +clear_page_loop: + jsr hline ; 6+435 + dey ; 2 + dey ; 2 + bpl clear_page_loop ; 2/3 + rts ; 6 + +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 + diff --git a/split_screen/vapor_lock.s b/split_screen/vapor_lock.s new file mode 100644 index 00000000..b6bba96a --- /dev/null +++ b/split_screen/vapor_lock.s @@ -0,0 +1,216 @@ +; 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 #40 + jsr clear_page_loop ; make top half grey2 $aa + + lda #$aa + ldy #24 + jsr clear_page_loop ; make top half grey2 $aa + + lda #$ee + ldy #10 + jsr clear_page_loop ; make top half grey2 $aa + + ; 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 $C051 ; 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 $C051 ; 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 + + + ; 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 + + lda #230 ; 2 + jsr delay_a ; delay 25+230 = 255 + + lda #226 ; 2 + jsr delay_a ; delay 25+226 = 251 + + + ; now near end of line 112 + + + lda $C051 ; 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 + + + + + ; 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