From 45094f7b9f01624aaf79ca5543d95d9ef744fe47 Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Sat, 12 Jun 2021 12:36:43 -0400 Subject: [PATCH] starfield: Finally just make the math inaccurate --- basic/appleiibot/Makefile | 8 ++- basic/appleiibot/starfield.bas | 2 + graphics/gr/starfield/Makefile | 4 +- graphics/gr/starfield/starbot.s | 38 ++++++++++--- graphics/gr/starfield/starsmall.s | 93 +++++++++++++++++++------------ linker_scripts/apple2_36d.inc | 12 ++++ 6 files changed, 111 insertions(+), 46 deletions(-) create mode 100644 basic/appleiibot/starfield.bas create mode 100644 linker_scripts/apple2_36d.inc diff --git a/basic/appleiibot/Makefile b/basic/appleiibot/Makefile index 85ebdad2..b21f8de9 100644 --- a/basic/appleiibot/Makefile +++ b/basic/appleiibot/Makefile @@ -16,7 +16,7 @@ appleiibot.dsk: E2.BAS FLAME.BAS FLAME2.BAS HELLO \ C64.BAS SIERPINSKI.BAS FAKES.BAS SIER.BAS DROPS.BAS RR.BAS RR_HGR.BAS \ COMBO.BAS WIRES.BAS PATTERN.BAS BALL.BAS LINES.BAS MOD9.BAS \ XOR_ZOOM.BAS MOD9_HGR.BAS SIER_HGR.BAS MOVE.BAS SINE.BAS XDRAW128.BAS \ - GATOR.BAS CURSOR.BAS STARGATE.BAS TUNNEL.BAS + GATOR.BAS CURSOR.BAS STARGATE.BAS TUNNEL.BAS STARFIELD.BAS # cp $(EMPTY_DISK)/empty.dsk appleiibot.dsk cp empty.dsk appleiibot.dsk @@ -85,6 +85,7 @@ appleiibot.dsk: E2.BAS FLAME.BAS FLAME2.BAS HELLO \ $(DOS33) -y appleiibot.dsk SAVE A CURSOR.BAS $(DOS33) -y appleiibot.dsk SAVE A STARGATE.BAS $(DOS33) -y appleiibot.dsk SAVE A TUNNEL.BAS + $(DOS33) -y appleiibot.dsk SAVE A STARFIELD.BAS #### @@ -268,6 +269,11 @@ STARGATE.BAS: stargate.bas TUNNEL.BAS: tunnel.bas $(TOKENIZE) < tunnel.bas > TUNNEL.BAS +#### + +STARFIELD.BAS: starfield.bas + $(TOKENIZE) < starfield.bas > STARFIELD.BAS + #### diff --git a/basic/appleiibot/starfield.bas b/basic/appleiibot/starfield.bas new file mode 100644 index 00000000..a134dcb0 --- /dev/null +++ b/basic/appleiibot/starfield.bas @@ -0,0 +1,2 @@ +1FORI=0TO138:POKE877+I,4*PEEK(2125+I)-192+(PEEK(2264+I/3)-35)/4^(I-INT(I/3)*3):NEXT +2&",=nU38U.b*lX2ZD8ZoV/Q<]L]P8,m]L5f(::b:\0Oo]T8c0Z<7`:\6eHl3a39 + sta YY ; YY ;============================== ; get X/Z @@ -181,11 +199,15 @@ done_star: dex bpl star_loop - lda #120 - jsr WAIT ; A is 0 after +; lda #120 +; jsr WAIT ; A is 0 after + +; jsr $FBE2 ; BEEP +; jsr $FBE4 ; BEEP ; GOTO2 - beq big_loop ; bra +; beq big_loop ; bra + bmi big_loop ; bra ;=========================== @@ -246,8 +268,8 @@ div_loop: bpl pos_add eor #$ff - sec - bcs do_add +; sec +; bcs do_add pos_add: clc @@ -261,5 +283,5 @@ early_out: ; for BASIC bot load ; need this to be at $3F5 - ; it's at 8A, so 6B + ; it's at 8C, so 6D jmp small_starfield diff --git a/graphics/gr/starfield/starsmall.s b/graphics/gr/starfield/starsmall.s index 7adf825f..ee5cb8c7 100644 --- a/graphics/gr/starfield/starsmall.s +++ b/graphics/gr/starfield/starsmall.s @@ -1,8 +1,10 @@ - +; starfield +; actually too fast +; original 189 bytes COLOR = $30 -COUNT = $FA +QUOTIENT = $FA DIVISOR = $FB DIVIDEND = $FC XX = $FD @@ -24,7 +26,7 @@ HGR2 = $F3D8 HGR = $F3E2 PLOT = $F800 ; PLOT AT Y,A (A colors output, Y preserved) SETGR = $FB40 - +WAIT = $FCA8 ; delay 1/2(26+27A+5A^2) us small_starfield: @@ -35,31 +37,49 @@ small_starfield: ; init the X/Z tables ldy #63 ; Y==z for(z=1;z<64;z++) { +xloop: ldx #0 ; X==x zloop: lda #$ff - sta COUNT + sta QUOTIENT stx DIVIDEND sty DIVISOR div_loop: - inc COUNT + inc QUOTIENT sec lda DIVIDEND sbc DIVISOR sta DIVIDEND bpl div_loop - lda COUNT + ; write out quotient + + lda QUOTIENT + pha + clc + adc #20 to_smc: - sta $5F00,X + sta $5F80,X inx - bne zloop + bpl zloop ; loop until 128 + + ldx #0 +negative_loop: + pla + eor #$ff + sec + adc #20 +to2_smc: + sta $5F00,X + inx + bpl negative_loop dec to_smc+2 + dec to2_smc+2 dey - bne zloop + bne xloop ;=================================== @@ -81,40 +101,41 @@ star_loop: ; get X/Z ; X=V(A(P),Z(P)) + ; position Z lda star_z,X - asl - asl - asl - asl - ora #$20 + clc + adc #$20 sta xload_smc+2 sta xload2_smc+2 + ; get XX ldy star_x,X - xload_smc: lda $5F00,Y sta XX - bmi new_star - cmp #39 - bcs new_star + + bmi new_star ; if <0 + cmp #40 + bcs new_star ; bge >40 ;============================== ; get Y/Z ; Y=V(B(P),Z(P)) - ldy star_y,X + ; get YY + ldy star_y,X xload2_smc: lda $5F00,Y sta YY - bmi new_star - cmp #39 - bcs new_star + + bmi new_star ; if <0 + cmp #40 + bcs new_star ; bge >39 ;Z(P)=Z(P)-1 dec star_z,X - bne draw_star + bne draw_star ; if Z!=0, draw star new_star: ;IFX<0ORX>39ORY<0ORY>39ORZ(P)<1THEN @@ -124,16 +145,17 @@ new_star: ldy FRAME lda $F000,Y -; and #$3f - sta star_x,X + sta star_x,X ; random XX + lda $F001,Y -; and #$3f - sta star_y,X + sta star_y,X ; random YY + lda $F002,Y - and #$3f + and #$3f ; random ZZ 0..63 ora #$1 ; avoid 0 sta star_z,X - iny + + iny ; FIXME iny iny sty FRAME @@ -149,24 +171,22 @@ draw_star: ;PLOT O(P),Q(P) ldy oldx,X - lda oldy,Y + lda oldy,X jsr PLOT ; PLOT AT Y,A ; COLOR=15 dec COLOR ;PLOT X,Y - - ldy XX - lda YY - jsr PLOT ; PLOT AT Y,A - ; O(P)=X:Q(P)=Y lda XX sta oldx,X + tay lda YY sta oldy,X + jsr PLOT ; PLOT AT Y,A + done_star: ;7NEXT @@ -174,6 +194,9 @@ done_star: dex bpl star_loop + lda #100 + jsr WAIT + ; GOTO2 jmp big_loop diff --git a/linker_scripts/apple2_36d.inc b/linker_scripts/apple2_36d.inc new file mode 100644 index 00000000..f899f931 --- /dev/null +++ b/linker_scripts/apple2_36d.inc @@ -0,0 +1,12 @@ +MEMORY { + ZP: start = $00, size = $1A, type = rw; + RAM: start = $36d, size = $8E00, file = %O; +} + +SEGMENTS { +CODE: load = RAM, type = ro; +RODATA: load = RAM, type = ro; +DATA: load = RAM, type = rw; +BSS: load = RAM, type = bss, define = yes; +ZEROPAGE: load = ZP, type = zp; +}