.include "zp.inc" ;=========== ; CONSTANTS ;=========== NUMSTARS EQU 16 ;===================== ; Starfield ;===================== ;================================ ; Clear screen and setup graphics ;================================ jsr clear_screens ; clear top/bottom of page 0/1 jsr set_gr_page0 ; Initialize the 2kB of multiply lookup tables jsr init_multiply_tables ;=============== ; Init Variables ;=============== lda #0 ; 2 sta DRAW_PAGE ; 3 sta RANDOM_POINTER ; 3 ; always multiply with low byte as zero sta NUM2L ; 3 ldy #(NUMSTARS-1) ; 2 init_stars: jsr random_star ; 6 dey ; 2 bpl init_stars ; 2nt/3 ;=========================== ;=========================== ; Main Loop ;=========================== ;=========================== starfield_loop: ;=============== ; clear screen ;=============== jsr clear_top ; 6+ ; 6047 ;=============== ; draw stars ;=============== ; start at 15 and count down (rather than 0 and count up) ldx #(NUMSTARS-1) ; 2 draw_stars: stx XX ; 3 ;================ ; calculate color ;================ lda #$ff ; want if z<16, color = 5 ; 2 sta COLOR ; if 16 40 then done ; 2nt/3 lda XPOS ; 3 bmi new_star ; 2nt/3 cmp #40 ; 2 bpl new_star ; if < 0 or > 40 then done ; 2nt/3 ; FIXME: sort out all of these jumps to be more efficient bmi plot_star ; 2 new_star: ldy XX ; 3 jsr random_star ; 6 jmp plot_star_continue ; 3 plot_star: jsr plot ; 6 plot_star_continue: ;============================== ldx XX ; 3 dex ; 2 bmi move_stars ; 2nt/3 bpl draw_stars ; 2nt/3 ; jmp draw_stars ;============================= ; Move stars move_stars: ldy #(NUMSTARS-1) ; 2 move_stars_loop: ; increment z clc ; if z >= 64 new star ; 2 lda star_z,Y ; 4 adc #1 ; 2 sta star_z,Y ; 4 and #64 ; 2 beq move_loop_skip ; 2nt/3 jsr random_star ; new random star ; 6 move_loop_skip: dey ; 2 bpl move_stars_loop ; 2nt/3 starfield_keyboard: ; jsr get_key ; get keypress ; 6 ; lda LASTKEY ; 3 ; beq starfield_keyboard ; cmp #('Q') ; if quit, then return ; bne skipskip ; rts skipskip: lda #>ship_forward sta INH lda #