2021-06-12 02:35:36 +00:00
|
|
|
; starfield tiny -- Apple II Lores
|
|
|
|
|
|
|
|
; by Vince `deater` Weaver
|
|
|
|
|
|
|
|
; actually too fast
|
|
|
|
|
|
|
|
; 189 bytes - original
|
|
|
|
; 184 bytes - move DIVIDEND to A
|
|
|
|
; 173 bytes - move variables to 0 page. limits to 16 stars but that's fine?
|
|
|
|
; 171 bytes - adjust random # generator
|
|
|
|
; 170 bytes - can do sty zp,x
|
2021-06-12 03:02:52 +00:00
|
|
|
; 163 bytes - lose the cool HGR intro
|
|
|
|
; 161 bytes - re-arrange RNG location
|
2021-06-12 15:37:42 +00:00
|
|
|
; 158 bytes - ra-arrange a lot to remove need for XX
|
|
|
|
; 133 bytes -- undo opt, no lookup table, just raw divide
|
|
|
|
; 145 bytes -- init stars at beginning, so don't initially run bacward if Z=FF
|
|
|
|
; 135 bytes -- optimize divide some more
|
2021-06-12 16:36:43 +00:00
|
|
|
; 143 bytes -- add in different color star
|
|
|
|
; 142 bytes -- closer :(
|
|
|
|
; trying all kinds of stuff, including using BELL for WAIT
|
|
|
|
; 139 bytes -- just made math innacurate (remove sec in sign correction)
|
|
|
|
|
2021-06-12 17:01:26 +00:00
|
|
|
; zero page locations
|
2021-06-12 02:35:36 +00:00
|
|
|
|
|
|
|
COLOR = $30
|
|
|
|
|
2021-06-12 17:01:26 +00:00
|
|
|
star_z = $60
|
|
|
|
oldx = $70
|
|
|
|
oldy = $80
|
|
|
|
star_x = $90
|
|
|
|
star_y = $A0
|
|
|
|
|
2021-06-12 15:37:42 +00:00
|
|
|
NEGATIVE = $F9
|
2021-06-12 02:35:36 +00:00
|
|
|
QUOTIENT = $FA
|
|
|
|
DIVISOR = $FB
|
|
|
|
DIVIDEND = $FC
|
|
|
|
XX = $FD
|
|
|
|
YY = $FE
|
|
|
|
FRAME = $FF
|
|
|
|
|
2021-06-12 17:01:26 +00:00
|
|
|
; soft-switches
|
2021-06-12 02:35:36 +00:00
|
|
|
|
|
|
|
LORES = $C056 ; Enable LORES graphics
|
|
|
|
|
2021-06-12 17:01:26 +00:00
|
|
|
; ROM routines
|
|
|
|
|
2021-06-12 17:04:16 +00:00
|
|
|
HGR2 = $F3D8 ; set hires page2 and clear $4000-$5fff
|
|
|
|
HGR = $F3E2 ; set hires page1 and clear $2000-$3fff
|
2021-06-12 02:35:36 +00:00
|
|
|
PLOT = $F800 ; PLOT AT Y,A (A colors output, Y preserved)
|
2021-06-12 17:04:16 +00:00
|
|
|
NEXTCOL = $F85F ; COLOR=COLOR+3
|
2021-06-12 15:37:42 +00:00
|
|
|
SETCOL = $F864 ; COLOR=A
|
2021-06-12 17:04:16 +00:00
|
|
|
SETGR = $FB40 ; set graphics and clear LO-RES screen
|
2021-06-12 02:35:36 +00:00
|
|
|
WAIT = $FCA8 ; delay 1/2(26+27A+5A^2) us
|
|
|
|
|
|
|
|
small_starfield:
|
|
|
|
|
|
|
|
;0GR:DIMV(64,48):FORZ=1TO48:FORX=0TO64:V(X,Z)=(X*4-128)/Z+20:NEXTX,Z
|
|
|
|
|
2021-06-12 15:37:42 +00:00
|
|
|
jsr SETGR ; A is D0 after?
|
2021-06-12 02:35:36 +00:00
|
|
|
|
|
|
|
;===================================
|
|
|
|
; draw the stars
|
|
|
|
;===================================
|
|
|
|
|
2021-06-12 17:01:26 +00:00
|
|
|
; there are ways to skip this, but on real hardware there's
|
|
|
|
; no guarantee star_z will be in a valid state, so waste the bytes
|
2021-06-12 15:37:42 +00:00
|
|
|
|
|
|
|
ldx #15
|
|
|
|
make_orig_stars:
|
|
|
|
jsr make_new_star
|
|
|
|
dex
|
|
|
|
bpl make_orig_stars
|
|
|
|
|
2021-06-12 02:35:36 +00:00
|
|
|
;===================================
|
|
|
|
; starloop
|
|
|
|
|
2021-06-12 17:01:26 +00:00
|
|
|
;2FORP=0TO15
|
|
|
|
|
2021-06-12 02:35:36 +00:00
|
|
|
big_loop:
|
|
|
|
ldx #15
|
2021-06-12 16:36:43 +00:00
|
|
|
|
2021-06-12 17:01:26 +00:00
|
|
|
; really tried hard not to have to set this value
|
|
|
|
; hard to judge best value for this
|
2021-06-12 16:36:43 +00:00
|
|
|
|
|
|
|
lda #80
|
|
|
|
jsr WAIT
|
2021-06-12 17:01:26 +00:00
|
|
|
; jsr $FBE4 ; BEEP delays too
|
2021-06-12 16:36:43 +00:00
|
|
|
|
|
|
|
; A now 0
|
|
|
|
|
2021-06-12 02:35:36 +00:00
|
|
|
star_loop:
|
2021-06-12 16:36:43 +00:00
|
|
|
; X=FF
|
2021-06-12 02:35:36 +00:00
|
|
|
|
2021-06-12 15:37:42 +00:00
|
|
|
;===================
|
2021-06-12 17:01:26 +00:00
|
|
|
; erase old star
|
2021-06-12 15:37:42 +00:00
|
|
|
|
|
|
|
;4 COLOR=0
|
2021-06-12 17:01:26 +00:00
|
|
|
lda #$00 ; color to black
|
2021-06-12 15:37:42 +00:00
|
|
|
sta COLOR
|
|
|
|
|
|
|
|
;PLOT O(P),Q(P)
|
2021-06-12 02:35:36 +00:00
|
|
|
|
2021-06-12 15:37:42 +00:00
|
|
|
ldy oldx,X
|
|
|
|
lda oldy,X
|
|
|
|
jsr PLOT ; PLOT AT Y,A
|
|
|
|
|
|
|
|
;===========================
|
2021-06-12 02:35:36 +00:00
|
|
|
; position Z
|
|
|
|
|
2021-06-12 15:37:42 +00:00
|
|
|
; lda star_z,X
|
|
|
|
; beq new_star ; should never happen
|
|
|
|
; sta DIVISOR
|
2021-06-12 02:35:36 +00:00
|
|
|
|
2021-06-12 17:01:26 +00:00
|
|
|
; DIVISOR always star_z,X so can hard code this in divide routine
|
2021-06-12 02:35:36 +00:00
|
|
|
|
|
|
|
;==============================
|
|
|
|
; get Y/Z
|
|
|
|
; Y=V(B(P),Z(P))
|
|
|
|
|
|
|
|
; get YY
|
|
|
|
|
2021-06-12 15:37:42 +00:00
|
|
|
lda star_y,X ; get Y of star
|
|
|
|
|
|
|
|
jsr do_divide
|
|
|
|
|
2021-06-12 17:01:26 +00:00
|
|
|
; if off-screen then need new star
|
|
|
|
|
2021-06-12 02:35:36 +00:00
|
|
|
bmi new_star ; if <0
|
|
|
|
cmp #40
|
|
|
|
bcs new_star ; bge >39
|
|
|
|
|
2021-06-12 16:36:43 +00:00
|
|
|
sta YY ; YY
|
2021-06-12 15:37:42 +00:00
|
|
|
|
|
|
|
;==============================
|
|
|
|
; get X/Z
|
|
|
|
; X=V(A(P),Z(P))
|
|
|
|
|
|
|
|
; get XX
|
|
|
|
|
|
|
|
lda star_x,X ; get X of start
|
|
|
|
|
|
|
|
jsr do_divide
|
|
|
|
|
2021-06-12 17:01:26 +00:00
|
|
|
tay ; put XX in Y
|
|
|
|
|
|
|
|
; if offscreen then draw new star
|
2021-06-12 15:37:42 +00:00
|
|
|
|
|
|
|
bmi new_star ; if <0
|
|
|
|
cpy #40
|
|
|
|
bcs new_star ; bge >40
|
|
|
|
|
|
|
|
;========================
|
|
|
|
; adjust Z
|
|
|
|
|
2021-06-12 02:35:36 +00:00
|
|
|
;Z(P)=Z(P)-1
|
|
|
|
dec star_z,X
|
2021-06-12 03:02:52 +00:00
|
|
|
beq new_star ; if Z=0 new star
|
2021-06-12 02:35:36 +00:00
|
|
|
|
2021-06-12 03:02:52 +00:00
|
|
|
; draw the star
|
2021-06-12 02:35:36 +00:00
|
|
|
|
|
|
|
draw_star:
|
|
|
|
|
|
|
|
; COLOR=15
|
2021-06-12 15:37:42 +00:00
|
|
|
dec COLOR ; color from $00 (black) to $ff (white)
|
2021-06-12 17:01:26 +00:00
|
|
|
|
|
|
|
; trouble causing code, wanted it two-tone
|
|
|
|
; this will make it white or blue depending on if odd or even star
|
|
|
|
|
|
|
|
; initially tried distance based color on Z, didn't look as good
|
|
|
|
|
2021-06-12 15:37:42 +00:00
|
|
|
txa
|
|
|
|
ror
|
|
|
|
bcs not_far
|
|
|
|
jsr NEXTCOL
|
|
|
|
|
|
|
|
not_far:
|
2021-06-12 02:35:36 +00:00
|
|
|
|
2021-06-12 17:01:26 +00:00
|
|
|
;===========================
|
|
|
|
; actually plot the star
|
|
|
|
|
2021-06-12 02:35:36 +00:00
|
|
|
;PLOT X,Y
|
|
|
|
; O(P)=X:Q(P)=Y
|
|
|
|
|
2021-06-12 15:37:42 +00:00
|
|
|
; ldy XX ; XX already in Y
|
|
|
|
sty oldx,X ; save for next time to erase
|
2021-06-12 02:35:36 +00:00
|
|
|
|
2021-06-12 15:37:42 +00:00
|
|
|
lda YY ; YY
|
|
|
|
sta oldy,X ; ;save for next time to erase
|
2021-06-12 02:35:36 +00:00
|
|
|
jsr PLOT ; PLOT AT Y,A
|
|
|
|
|
2021-06-12 15:37:42 +00:00
|
|
|
; a should be F0/20 or 0F/02 here?
|
|
|
|
bne done_star ; bra
|
2021-06-12 03:02:52 +00:00
|
|
|
|
|
|
|
new_star:
|
2021-06-12 15:37:42 +00:00
|
|
|
jsr make_new_star ;
|
|
|
|
|
|
|
|
done_star:
|
|
|
|
;7NEXT
|
|
|
|
|
|
|
|
dex
|
|
|
|
bpl star_loop
|
|
|
|
|
|
|
|
; GOTO2
|
2021-06-12 16:36:43 +00:00
|
|
|
bmi big_loop ; bra
|
2021-06-12 15:37:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
;===========================
|
|
|
|
; NEW STAR
|
|
|
|
;===========================
|
|
|
|
|
|
|
|
make_new_star:
|
2021-06-12 03:02:52 +00:00
|
|
|
;IFX<0ORX>39ORY<0ORY>39ORZ(P)<1THEN
|
|
|
|
; A(P)=RND(1)*64
|
|
|
|
; B(P)=RND(1)*64
|
|
|
|
; Z(P)=RND(1)*48+1:GOTO7
|
|
|
|
|
|
|
|
ldy FRAME
|
|
|
|
lda $F000,Y
|
|
|
|
sta star_x,X ; random XX
|
|
|
|
|
2021-06-12 15:37:42 +00:00
|
|
|
color_lookup:
|
|
|
|
lda $F100,Y
|
2021-06-12 03:02:52 +00:00
|
|
|
sta star_y,X ; random YY
|
|
|
|
|
|
|
|
lda $F002,Y
|
|
|
|
and #$3f ; random ZZ 0..63
|
|
|
|
ora #$1 ; avoid 0
|
|
|
|
sta star_z,X
|
|
|
|
|
|
|
|
inc FRAME
|
|
|
|
|
2021-06-12 15:37:42 +00:00
|
|
|
rts
|
2021-06-12 02:35:36 +00:00
|
|
|
|
2021-06-12 15:37:42 +00:00
|
|
|
;=============================
|
2021-06-12 17:01:26 +00:00
|
|
|
; do signed divide
|
|
|
|
; the signed part is the pain
|
2021-06-12 15:37:42 +00:00
|
|
|
;=============================
|
|
|
|
; Z is in divisor
|
|
|
|
; x/y is in A
|
2021-06-12 02:35:36 +00:00
|
|
|
|
2021-06-12 15:37:42 +00:00
|
|
|
do_divide:
|
|
|
|
; A was just loaded so flags still valid
|
|
|
|
php
|
|
|
|
bpl not_negative
|
2021-06-12 02:35:36 +00:00
|
|
|
|
2021-06-12 17:01:26 +00:00
|
|
|
eor #$ff ; make positive for division
|
|
|
|
clc ; is this necessary?
|
|
|
|
adc #1
|
2021-06-12 15:37:42 +00:00
|
|
|
|
|
|
|
not_negative:
|
|
|
|
|
|
|
|
ldy #$ff ; QUOTIENT
|
|
|
|
div_loop:
|
|
|
|
iny ; inc QUOTIENT
|
|
|
|
sec
|
|
|
|
sbc star_z,X ; DIVIDEND=DIVIDEND-DIVISOR
|
|
|
|
bpl div_loop
|
|
|
|
|
|
|
|
; write out quotient
|
|
|
|
tya ; lda QUOTIENT
|
|
|
|
|
|
|
|
plp
|
|
|
|
bpl pos_add
|
|
|
|
|
|
|
|
eor #$ff
|
2021-06-12 17:01:26 +00:00
|
|
|
; sec ; FIXME: made math inaccurate to save room
|
2021-06-12 16:36:43 +00:00
|
|
|
; bcs do_add
|
2021-06-12 15:37:42 +00:00
|
|
|
|
|
|
|
pos_add:
|
|
|
|
clc
|
|
|
|
do_add:
|
2021-06-12 17:01:26 +00:00
|
|
|
adc #20 ; pre-adjust to have star origin mid screen
|
2021-06-12 15:37:42 +00:00
|
|
|
|
|
|
|
early_out:
|
|
|
|
rts
|
2021-06-12 02:35:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
; for BASIC bot load
|
|
|
|
|
2021-06-12 03:02:52 +00:00
|
|
|
; need this to be at $3F5
|
2021-06-12 16:36:43 +00:00
|
|
|
; it's at 8C, so 6D
|
2021-06-12 02:35:36 +00:00
|
|
|
jmp small_starfield
|