diff --git a/racebeam/Makefile b/racebeam/Makefile new file mode 100644 index 00000000..124e9652 --- /dev/null +++ b/racebeam/Makefile @@ -0,0 +1,34 @@ +include ../Makefile.inc + +DOS33 = ../dos33fs-utils/dos33 +B2D = ../bmp2dhr/b2d +PNG_TO_40x48D = ../gr-utils/png_to_40x48d + +all: racebeam.dsk + +racebeam.dsk: HELLO RACEBEAM + $(DOS33) -y racebeam.dsk SAVE HELLO + $(DOS33) -y racebeam.dsk BSAVE -a 0x1000 RACEBEAM + + + +#### + +RACEBEAM: racebeam.o + ld65 -o RACEBEAM racebeam.o -C ../linker_scripts/apple2_1000.inc + +racebeam.o: racebeam.s + ca65 -o racebeam.o racebeam.s -l racebeam.lst + + +#background_final.inc: background_final.png +# $(PNG_TO_40x48D) asm background_final.png bg_final > background_final.inc + + +#### + +HELLO: hello.bas + ../asoft_basic-utils/tokenize_asoft < hello.bas > HELLO + +clean: + rm -f *~ *.o *.lst *.inc RACEBEAM HELLO diff --git a/racebeam/README b/racebeam/README new file mode 100644 index 00000000..a5f422d5 --- /dev/null +++ b/racebeam/README @@ -0,0 +1,6 @@ +Apple II Racing the Beam demo + by Vince "Deater" Weaver + vince@deater.net + http://www.deater.net/weave/vmwprod/ + + diff --git a/racebeam/delay_a.s b/racebeam/delay_a.s new file mode 100644 index 00000000..2d0802da --- /dev/null +++ b/racebeam/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/racebeam/gr_copy.s b/racebeam/gr_copy.s new file mode 100644 index 00000000..f03ed362 --- /dev/null +++ b/racebeam/gr_copy.s @@ -0,0 +1,58 @@ + ;========================================================= + ; gr_copy_to_current, 40x48 version + ;========================================================= + ; copy 0xc00 to DRAW_PAGE + ; + ; 45 + 2 + 120*(8*9 + 5) -1 + 6 = 9292 +.align $100 +gr_copy_to_current: + + lda DRAW_PAGE ; 3 + clc ; 2 + adc #$4 ; 2 + sta gr_copy_line+5 ; 4 + sta gr_copy_line+11 ; 4 + adc #$1 ; 2 + sta gr_copy_line+17 ; 4 + sta gr_copy_line+23 ; 4 + adc #$1 ; 2 + sta gr_copy_line+29 ; 4 + sta gr_copy_line+35 ; 4 + adc #$1 ; 2 + sta gr_copy_line+41 ; 4 + sta gr_copy_line+47 ; 4 + ;=========== + ; 45 + + ldy #119 ; for early ones, copy 120 bytes ; 2 + +gr_copy_line: + lda $C00,Y ; load a byte (self modified) ; 4 + sta $400,Y ; store a byte (self modified) ; 5 + + lda $C80,Y ; load a byte (self modified) ; 4 + sta $480,Y ; store a byte (self modified) ; 5 + + lda $D00,Y ; load a byte (self modified) ; 4 + sta $500,Y ; store a byte (self modified) ; 5 + + lda $D80,Y ; load a byte (self modified) ; 4 + sta $580,Y ; store a byte (self modified) ; 5 + + lda $E00,Y ; load a byte (self modified) ; 4 + sta $600,Y ; store a byte (self modified) ; 5 + + lda $E80,Y ; load a byte (self modified) ; 4 + sta $680,Y ; store a byte (self modified) ; 5 + + lda $F00,Y ; load a byte (self modified) ; 4 + sta $700,Y ; store a byte (self modified) ; 5 + + lda $F80,Y ; load a byte (self modified) ; 4 + sta $780,Y ; store a byte (self modified) ; 5 + + dey ; decrement pointer ; 2 + bpl gr_copy_line ; ; 2nt/3 + + rts ; 6 + diff --git a/racebeam/gr_hline.s b/racebeam/gr_hline.s new file mode 100644 index 00000000..9c77b4a4 --- /dev/null +++ b/racebeam/gr_hline.s @@ -0,0 +1,40 @@ + ;================================== + ; HLINE + ;================================== + + ; Color in A + ; Y has which line +hline: + pha ; 3 + ldx gr_offsets,y ; 4+ + stx hline_loop+1 ; 4 + lda gr_offsets+1,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 #46 +clear_page_loop: + jsr hline + dey + dey + bpl clear_page_loop + rts + +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/racebeam/hello.bas b/racebeam/hello.bas new file mode 100644 index 00000000..78aea788 --- /dev/null +++ b/racebeam/hello.bas @@ -0,0 +1,2 @@ + 5 HOME + 200 PRINT CHR$ (4)"RACEBEAM" diff --git a/racebeam/racebeam.dsk b/racebeam/racebeam.dsk new file mode 100644 index 00000000..b4f8e4b8 Binary files /dev/null and b/racebeam/racebeam.dsk differ diff --git a/racebeam/racebeam.s b/racebeam/racebeam.s new file mode 100644 index 00000000..7f86d2e5 --- /dev/null +++ b/racebeam/racebeam.s @@ -0,0 +1,279 @@ +; Race the Beam + +; try for 40x192 15-color graphics on stock Apple II / Apple II+ +; this means, no double-hires + +; by racing the beam we can possibly update at least 10 blocks +; per line to the 192-line resolution + +; we can get 40x96 resolution simply by page flipping + +; this all requires vapor lock cycle-counting + + +; by deater (Vince Weaver) + +; Zero Page +FRAMEBUFFER = $00 ; $00 - $0F +YPOS = $10 +YPOS_SIN = $11 +CH = $24 +CV = $25 +GBASL = $26 +GBASH = $27 +BASL = $28 +BASH = $29 +FRAME = $60 +WAITING = $62 +LETTERL = $63 +LETTERH = $64 +LETTERX = $65 +LETTERY = $66 +LETTERD = $67 +LETTER = $68 +BLARGH = $69 +HGR_COLOR = $E4 +STATE = $ED +DRAW_PAGE = $EE +LASTKEY = $F1 +PADDLE_STATUS = $F2 +TEMP = $FA +WHICH = $FB + +; Soft Switches +KEYPRESS= $C000 +KEYRESET= $C010 +SPEAKER = $C030 +SET_GR = $C050 ; Enable graphics +SET_TEXT= $C051 ; Enable text +FULLGR = $C052 ; Full screen, no text +TEXTGR = $C053 ; Split screen +PAGE0 = $C054 ; Page0 +PAGE1 = $C055 ; Page1 +LORES = $C056 ; Enable LORES graphics +HIRES = $C057 ; Enable HIRES graphics + +PADDLE_BUTTON0 = $C061 +PADDL0 = $C064 +PTRIG = $C070 + +; ROM routines +;HGR = $F3E2 +;HPLOT0 = $F457 +;HGLIN = $F53A +;COLORTBL= $F6F6 +TEXT = $FB36 ;; Set text mode +HOME = $FC58 ;; Clear the text screen +WAIT = $FCA8 ;; delay 1/2(26+27A+5A^2) us + + + ;================================== + ;================================== + + +setup_background: + + ;=================== + ; init screen + jsr TEXT + jsr HOME + bit LORES + bit SET_GR + bit FULLGR + bit PAGE0 + bit KEYRESET + + ;=================== + ; init vars + + lda #0 + sta DRAW_PAGE + sta STATE + sta WAITING + + + ;============================= + ; Load graphic page0 + +; lda #$0c +; sta BASH +; lda #$00 +; sta BASL ; load image to $c00 + +; lda #bg_final_low +; sta GBASH +; jsr load_rle_gr + +; lda #4 +; sta DRAW_PAGE + +; jsr gr_copy_to_current ; copy to page1 + + ; GR part +; bit PAGE1 +; bit LORES ; 4 +; bit SET_GR ; 4 +; bit FULLGR ; 4 + +; jsr wait_until_keypressed + + + ;============================= + ; Load graphic page1 + +; lda #$0c +; sta BASH +; lda #$00 +; sta BASL ; load image to $c00 + +; lda #bg_final_high +; sta GBASH +; jsr load_rle_gr + +; lda #0 +; sta DRAW_PAGE + +; jsr gr_copy_to_current + + ; GR part +; bit PAGE0 + +; jsr wait_until_keypressed + + + ;============================== + ; setup graphics for vapor lock + ;============================== + + jsr vapor_lock ; 6 + + ; vapor lock returns with us at beginning of hsync in line + ; 114 (7410 cycles), so with 5070 lines to go + + ; so we have 5070 + 4550 = 9620 to kill + + jsr gr_copy_to_current ; 6+ 9292 + + ; now we have 322 left + + ; GR part + bit LORES ; 4 + bit SET_GR ; 4 + bit FULLGR ; 4 + + ; 322 - 12 = 310 + ; - 3 for jmp + ; 307 + + ; Try X=9 Y=6 cycles=307 + + ldy #6 ; 2 +loopA: + ldx #9 ; 2 +loopB: + dex ; 2 + bne loopB ; 2nt/3 + + dey ; 2 + bne loopA ; 2nt/3 + + jmp display_loop ; 3 +.align $100 + + + ;================================================ + ; Display Loop + ;================================================ + ; 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 + + ; We want to alternate between page1 and page2 every 65 cycles + ; vblank = 4550 cycles to do scrolling + + + ; 2 + 48*( (4+2+25*(2+3)) + (4+2+23*(2+3)+4+5)) + 9) + ; 48*[(6+125)-1] + [(6+115+10)-1] + +display_loop: + + ;=================================== + ; 192 lines, alternate PAGE0/PAGE1 every 2 lines + ;=================================== + + + ldy #96 ; *2=192 lines ; 2 + + ; we set PAGE0 (4) then want to NOP (61) for a total of 65 +bouter_loop: + bit PAGE0 ; 4 + ldx #12 ; 65 cycles with PAGE0 ; 2 +bpage0_loop: ; delay 61+bit + dex ; 2 + bne bpage0_loop ; 2/3 + ;============= + ; 6+(12*5)-1=65 + + ; we set PAGE1 (4) as well as dey (2) and bne (3) then nop (55) + ; + + bit PAGE1 ; 4 + ldx #11 ; 65 cycles with PAGE1 ; 2 +bpage1_loop: + dex ; 2 + bne bpage1_loop ; 2/3 + ;============= + ; 6+(11*5)-1=60 + + dey ; 2 + bne bouter_loop ; 2/3 + ;============== + ; 5 to make 65 + + ;====================================================== + ; We have 4550 cycles in the vblank, use them wisely + ;====================================================== + ; 4550 + ; +1 fallthrough + ; -2 for ldy in previous + ; -35 call through jumptable + ; -7 keyboard + ; -3 jmp + ; ======== + ; 4504 + ;======================== + ; each subunit should take 4504 cycles + +firework_state_machine: + +check_keyboard: + + lda KEYPRESS ; 4 + bpl no_keypress ; 3 + jmp restart +no_keypress: + + jmp display_loop ; 3 + + + +restart: + + jmp setup_background + + +.include "gr_hline.s" +;.include "../asm_routines/gr_unrle.s" +;.include "../asm_routines/keypress.s" +.include "gr_copy.s" +;.include "random16.s" +.include "vapor_lock.s" +.include "delay_a.s" + + diff --git a/racebeam/random16.s b/racebeam/random16.s new file mode 100644 index 00000000..4ab4a384 --- /dev/null +++ b/racebeam/random16.s @@ -0,0 +1,119 @@ +; 16-bit 6502 Random Number Generator (cycle-invariant version) + +; Linear feedback shift register PRNG by White Flame +; http://codebase64.org/doku.php?id=base:small_fast_16-bit_prng + +; The Apple II KEYIN routine increments SEEDL:SEEDH +; while waiting for keypress + +SEEDL = $4E +SEEDH = $4F + +XOR_MAGIC = $7657 ; "vW" + + ;============================= + ; random16 + ;============================= + ; takes: + ; not 0, cs = 6(r16)+12(lnz)+5(nop)+ 19(deo) = 42 + ; not 0, cc = 6(r16)+14(lnz)+2(nop)+ 20(neo) = 42 + + ; $0000 = 6(r16)+ 6(loz)+11nops+ 19(deo) = 42 + ; $8000 = 6(r16)+ 6(loz)+ 4(ceo) + 6nops+ 20(neo) = 42 + + ; $XX00 cc = 6(r16)+ 6(loz)+4(ceo)+2(cep) +4nops+ 20(neo) = 42 + ; $XX00 cs = 6(r16)+ 6(loz)+4(ceo)+4(cep) +3nops+ 19(deo) = 42* +random16: + + lda SEEDL ; 3 + beq low_zero ; $0000 and $8000 are special values ; 3 + ;========== + ; 6 +lownz: + ; -1 + asl SEEDL ; Do a normal shift ; 5 + lda SEEDH ; 3 + rol ; 2 + bcs five_cycle_do_eor ; 3 + ;=========== + ; 12 + + bcc two_cycle_no_eor ; 3 + ;========== + ; 12+3-1 = 14 + + +;=================================================================== + +eleven_cycle_do_eor: + nop ; 2 + nop ; 2 + nop ; 2 +five_cycle_do_eor: + nop ; 2 +three_cycle_do_eor: + sta SEEDH ; nop ; 3 + +do_eor: + ; high byte is in A + + eor #>XOR_MAGIC ; 2 + sta SEEDH ; 3 + lda SEEDL ; 3 + eor #