.include "zp.inc" ;=========== ; CONSTANTS ;=========== NUMSTARS EQU 16 ;===================== ; Starfield ;===================== ;================================ ; Clear screen and setup graphics ;================================ jsr clear_screens_notext ; clear top/bottom of page 0/1 jsr set_gr_page0 bit FULLGR ; Initialize the 2kB of multiply lookup tables jsr init_multiply_tables ;=============== ; Init Variables ;=============== lda #0 ; 2 sta DRAW_PAGE ; 3 sta RANDOM_POINTER ; 3 sta STATE ; always multiply with low byte as zero sta NUM2L ; 3 lda #5 sta SPEED ldy #(NUMSTARS-1) ; 2 init_stars: jsr random_star ; 6 dey ; 2 bpl init_stars ; 2nt/3 ;=========================== ;=========================== ; Main Loop ;=========================== ;=========================== starfield_loop: ;=============== ; clear screen ;=============== lda STATE cmp #5 bne quick_skip lda #0 sta STATE lda #5 sta SPEED quick_skip: cmp #3 beq no_clear cmp #1 bne black_back dec SPEED lda SPEED bne not_done inc STATE not_done: lda #COLOR_BOTH_LIGHTBLUE jmp back_color black_back: lda #0 back_color: sta clear_all_color+1 jsr clear_all ; 6+ ; 6047 ;=============== ; draw stars ;=============== no_clear: ; 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 skipskip: lda #>ship_forward sta INH lda #