From d1a0ac9144c949d81780d3eadceedf78e6b15ac5 Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Sat, 30 Dec 2017 00:43:39 -0500 Subject: [PATCH] mode7: more starfield work --- asm_routines/hlin_clearscreen.s | 2 +- gr-sim/starfield_fixed.c | 10 ++-- mode7/starfield_demo.s | 88 +++++++++++++++++++++++++++++++-- mode7/zp.inc | 1 + 4 files changed, 92 insertions(+), 9 deletions(-) diff --git a/asm_routines/hlin_clearscreen.s b/asm_routines/hlin_clearscreen.s index 46dab7b6..1024ca21 100644 --- a/asm_routines/hlin_clearscreen.s +++ b/asm_routines/hlin_clearscreen.s @@ -183,7 +183,7 @@ clear_top_a: ; HLIN Y, V2 AT A - lda #40 + lda #39 sta V2 lda #0 diff --git a/gr-sim/starfield_fixed.c b/gr-sim/starfield_fixed.c index 8af16522..37c02828 100644 --- a/gr-sim/starfield_fixed.c +++ b/gr-sim/starfield_fixed.c @@ -83,13 +83,13 @@ static void random_star(int i) { stars[i].x.i=random_table[random_pointer++]; if (random_pointer>255) random_pointer=0; - stars[i].x.f=random_table[random_pointer++]; - if (random_pointer>255) random_pointer=0; +// stars[i].x.f=random_table[random_pointer++]; +// if (random_pointer>255) random_pointer=0; stars[i].y.i=random_table[random_pointer++]; if (random_pointer>255) random_pointer=0; - stars[i].y.f=random_table[random_pointer++]; - if (random_pointer>255) random_pointer=0; +// stars[i].y.f=random_table[random_pointer++]; +// if (random_pointer>255) random_pointer=0; // double_to_fixed( (drand48()-0.5)*spreadx,&stars[i].x); // double_to_fixed( (drand48()-0.5)*spready,&stars[i].y); @@ -97,7 +97,7 @@ static void random_star(int i) { /* 0 to 63 corresponding to */ stars[i].z=random_table[random_pointer++]&0x3f; if (random_pointer>255) random_pointer=0; - if (stars[i].z>58) stars[i].z=0; +// if (stars[i].z>58) stars[i].z=0; // double_to_fixed( ((drand48())*spreadz)+0.1,&stars[i].z); // print_fixed(&stars[i].x); diff --git a/mode7/starfield_demo.s b/mode7/starfield_demo.s index e40210a8..be6e0f1f 100644 --- a/mode7/starfield_demo.s +++ b/mode7/starfield_demo.s @@ -27,19 +27,49 @@ NUMSTARS EQU 16 ;=============== lda #0 sta DRAW_PAGE + sta RANDOM_POINTER + + ldy #NUMSTARS +init_stars: + jsr random_star + dey + bpl init_stars + + ;=========================== + ;=========================== + ; Main Loop + ;=========================== + ;=========================== starfield_loop: + ;=============== + ; clear screen + ;=============== + jsr clear_top + ;=============== ; draw stars ;=============== -draw_stars: ldx #NUMSTARS +draw_stars: + txa + tay + + ; calculate color + + lda #$ff + sta COLOR + + ; calculate x and y + lda #20 ldy #20 + ;================================ + ; plot routine ;================================ ; put address in GBASL/GBASH ; Xcoord in A, Ycoord in Y @@ -57,12 +87,33 @@ draw_stars: ;=========== ; + lda TEMPY + and #$1 + bne plot_odd +plot_even: + lda COLOR + and #$f0 + sta COLOR + lda (GBASL),Y + and #$0f + jmp plot_write +plot_odd: + lda COLOR + and #$0f + sta COLOR + lda (GBASL),Y + and #$f0 + +plot_write: ldy #0 - lda #$ff + ora COLOR sta (GBASL),Y + + ;============================== + dex - bne draw_stars + bpl draw_stars starfield_keyboard: @@ -90,6 +141,37 @@ skipskip: jmp starfield_loop ; 3 +; matches scroll_row1 - row3 +star_x EQU $8A00 +star_y EQU $8B00 +star_z EQU $8C00 + + ;=================== + ; star number in Y + ; FIXME: increment at end? + ; X trashed +random_star: + ; random x location + ldx RANDOM_POINTER + lda random_table,X + inc RANDOM_POINTER + sta star_x,Y + + ; random y location + ldx RANDOM_POINTER + lda random_table,X + inc RANDOM_POINTER + sta star_y,Y + + ; random z location + ldx RANDOM_POINTER + lda random_table,X + inc RANDOM_POINTER + and #$3f + sta star_z,Y + + rts + ;=============================================== ; External modules ;=============================================== diff --git a/mode7/zp.inc b/mode7/zp.inc index 095b624c..0d865cdd 100644 --- a/mode7/zp.inc +++ b/mode7/zp.inc @@ -95,6 +95,7 @@ LAST_SPACEY_I EQU $88 LAST_MAP_COLOR EQU $89 DRAW_SKY EQU $8A COLOR_MASK EQU $8B +RANDOM_POINTER EQU $8C SHIPY EQU $E4