mode7_demo: work on the starfields part

This commit is contained in:
Vince Weaver 2018-01-30 00:55:40 -05:00
parent 666f596033
commit 0118de5eee
5 changed files with 506 additions and 48 deletions

View File

@ -31,12 +31,11 @@ NUMSTARS EQU 16
sta RANDOM_POINTER ; 3 sta RANDOM_POINTER ; 3
sta STATE sta STATE
lda #5
sta SPEED
; always multiply with low byte as zero ; always multiply with low byte as zero
sta NUM2L ; 3 sta NUM2L ; 3
lda #5
sta SPEED
ldy #(NUMSTARS-1) ; 2 ldy #(NUMSTARS-1) ; 2
init_stars: init_stars:

View File

@ -27,7 +27,7 @@ mode7_demo.o: mode7_demo.s mode7_demo_backgrounds.inc sprites.inc \
../asm_routines/gr_fade.s \ ../asm_routines/gr_fade.s \
../asm_routines/gr_copy.s \ ../asm_routines/gr_copy.s \
../asm_routines/gr_scroll.s \ ../asm_routines/gr_scroll.s \
mode7.s starfield_demo.s mode7.s rasterbars.s starfield_demo.s
ca65 -o mode7_demo.o mode7_demo.s -l mode7_demo.lst ca65 -o mode7_demo.o mode7_demo.s -l mode7_demo.lst

View File

@ -22,6 +22,7 @@ main_loop:
jsr checkerboard_demo jsr checkerboard_demo
jsr island_demo jsr island_demo
jsr star_demo jsr star_demo
jsr star_credits
jmp main_loop jmp main_loop
@ -107,11 +108,28 @@ island_demo:
star_demo: star_demo:
; initialize ; initialize
lda #48
sta y_limit_smc+1
jsr starfield_demo jsr starfield_demo
rts rts
;===========================
; Star Credits
;===========================
star_credits:
; initialize
lda #40
sta y_limit_smc+1
jsr starfield_credits
rts
;=========================== ;===========================
; Title routine ; Title routine
;=========================== ;===========================

331
mode7_demo/rasterbars.s Normal file
View File

@ -0,0 +1,331 @@
; Not quite a raster-bar, but why not
.include "zp.inc"
;===========
; CONSTANTS
;===========
ELEMENTS EQU 64
;=====================
; Rasterbars
;=====================
;================================
; Clear screen and setup graphics
;================================
jsr clear_screens ; clear top/bottom of page 0/1
jsr set_gr_page0
;===============
; Init Variables
;===============
lda #0 ; 2
sta DRAW_PAGE ; 3
sta SCREEN_Y
;===========================
;===========================
; Main Loop
;===========================
;===========================
raster_loop:
; clear rows
ldy #19 ; 2
lda #0
init_rows:
sta row_color,Y
dey
bpl init_rows
jsr clear_top
;================
; set colors
lda #COLOR_BOTH_AQUA ; aqua
sta COLOR
ldy SCREEN_Y
jsr set_row_color
lda #COLOR_BOTH_MEDIUMBLUE ; medium blue
sta COLOR
iny
jsr set_row_color
lda #COLOR_BOTH_LIGHTGREEN ; light green
sta COLOR
iny
jsr set_row_color
lda #COLOR_BOTH_DARKGREEN ; green
sta COLOR
iny
jsr set_row_color
lda #COLOR_BOTH_YELLOW ; yellow
sta COLOR
iny
jsr set_row_color
lda #COLOR_BOTH_ORANGE ; orange
sta COLOR
iny
jsr set_row_color
lda #COLOR_BOTH_PINK ; pink
sta COLOR
iny
jsr set_row_color
lda #COLOR_BOTH_RED ; red
sta COLOR
iny
jsr set_row_color
;=================
; draw rows
ldy #19
draw_rows_loop:
lda row_color,Y
sta COLOR
tya
pha
asl
ldy #39 ; 2
sty V2 ; 3
ldy #0 ; 2
jsr hlin_double ; hlin y,V2 at A ; 63+(X*16)
pla ; 4
tay
dey
bpl draw_rows_loop
;==================
; flip pages
;==================
jsr page_flip ; 6
;==================
; delay?
;==================
;==================
; update y pointer
;==================
ldy SCREEN_Y
iny
cpy #ELEMENTS
bne not_there
ldy #0
not_there:
sty SCREEN_Y
;==================
; loop forever
;==================
jmp raster_loop ; 3
;===================
; set_row_color
;===================
; color in COLOR
; Y=offset
; Y preserved?
set_row_color:
tya ; wrap y offset
and #(ELEMENTS-1)
tax
lda fine_sine,X ; lookup sign value
cpx #33 ; check if > pi and
bpl sin_negative ; need to make negative
sin_positive:
clc ; shift right by 4, zero-extend
ror
clc
ror
clc
ror
clc
ror
clc
adc #18 ; add in 18 to center on screen
; lsr ; shift once more
jmp sin_no_more
; FIXME: precalculate as we shift same each time
sin_negative:
sec
ror
sec
ror
sec
ror
sec
ror
clc
adc #18
; lsr
sin_no_more:
pha
lsr
tax
pla
pha
jsr put_color
pla
tax
cpy 32
beq no_inc
bmi yes_inc
dex
dex
yes_inc:
inx
no_inc:
txa ; horrific
pha
lsr
tax
pla
jsr put_color
rts
put_color:
and #$1 ; see if even or odd
beq even_line
lda COLOR
and #$f0
sta COLOR2
lda row_color,X
and #$0f
jmp done_line
even_line:
lda COLOR
and #$0f
sta COLOR2
lda row_color,X
and #$f0
done_line:
ora COLOR2
sta row_color,X
rts
;===============================================
; External modules
;===============================================
.include "../asm_routines/pageflip.s"
.include "../asm_routines/gr_setpage.s"
;.include "../asm_routines/keypress.s"
.include "../asm_routines/gr_offsets.s"
.include "../asm_routines/gr_fast_clear.s"
.include "../asm_routines/gr_hlin.s"
;======================
; some arrays
;======================
row_color:
.byte $00,$00,$00,$00,$00, $00,$00,$00,$00,$00
.byte $00,$00,$00,$00,$00, $00,$00,$00,$00,$00
fine_sine:
.byte $00 ; 0.000000
.byte $19 ; 0.098017
.byte $31 ; 0.195090
.byte $4A ; 0.290285
.byte $61 ; 0.382683
.byte $78 ; 0.471397
.byte $8E ; 0.555570
.byte $A2 ; 0.634393
.byte $B5 ; 0.707107
.byte $C5 ; 0.773010
.byte $D4 ; 0.831470
.byte $E1 ; 0.881921
.byte $EC ; 0.923880
.byte $F4 ; 0.956940
.byte $FB ; 0.980785
.byte $FE ; 0.995185
.byte $FF ; 1.000000
.byte $FE ; 0.995185
.byte $FB ; 0.980785
.byte $F4 ; 0.956940
.byte $EC ; 0.923880
.byte $E1 ; 0.881921
.byte $D4 ; 0.831470
.byte $C5 ; 0.773010
.byte $B5 ; 0.707107
.byte $A2 ; 0.634393
.byte $8E ; 0.555570
.byte $78 ; 0.471397
.byte $61 ; 0.382683
.byte $4A ; 0.290285
.byte $31 ; 0.195090
.byte $19 ; 0.098017
.byte $00 ; 0.000000
.byte $E7 ; -0.098017
.byte $CF ; -0.195090
.byte $B6 ; -0.290285
.byte $9F ; -0.382683
.byte $88 ; -0.471397
.byte $72 ; -0.555570
.byte $5E ; -0.634393
.byte $4B ; -0.707107
.byte $3B ; -0.773010
.byte $2C ; -0.831470
.byte $1F ; -0.881921
.byte $14 ; -0.923880
.byte $0C ; -0.956940
.byte $05 ; -0.980785
.byte $02 ; -0.995185
.byte $00 ; -1.000000
.byte $02 ; -0.995185
.byte $05 ; -0.980785
.byte $0C ; -0.956940
.byte $14 ; -0.923880
.byte $1F ; -0.881921
.byte $2C ; -0.831470
.byte $3B ; -0.773010
.byte $4B ; -0.707107
.byte $5E ; -0.634393
.byte $72 ; -0.555570
.byte $88 ; -0.471397
.byte $9F ; -0.382683
.byte $B6 ; -0.290285
.byte $CF ; -0.195090
.byte $E7 ; -0.098017

View File

@ -5,8 +5,21 @@
NUMSTARS EQU 16 NUMSTARS EQU 16
; Plan:
; Ship at rest 0 - 4
; Flash 5
; Ship at warp 25
; Crazy background
; Ship moves off
; Back to stars
; Rasterbars+credits
; Done
;===================== ;=====================
; Starfield ; Starfield Demo
;===================== ;=====================
starfield_demo: starfield_demo:
@ -14,8 +27,9 @@ starfield_demo:
; Clear screen and setup graphics ; Clear screen and setup graphics
;================================ ;================================
jsr clear_screens ; clear top/bottom of page 0/1 jsr clear_screens_notext ; clear top/bottom of page 0/1
jsr set_gr_page0 jsr set_gr_page0
bit FULLGR
;=============== ;===============
; Init Variables ; Init Variables
@ -25,7 +39,7 @@ starfield_demo:
sta RANDOM_POINTER ; 3 sta RANDOM_POINTER ; 3
; always multiply with low byte as zero ; always multiply with low byte as zero
sta NUM2L ; 3 sta NUM2L ; 3
sta FRAME_COUNT
ldy #(NUMSTARS-1) ; 2 ldy #(NUMSTARS-1) ; 2
init_stars: init_stars:
@ -44,17 +58,142 @@ starfield_loop:
;=============== ;===============
; clear screen ; clear screen
;=============== ;===============
jsr clear_top ; 6+ jsr clear_all ; 6+
; 6047 ; 6047
;=============== ;===============
; draw the stars
;===============
jsr draw_stars
;================
; draw the ship
;================
lda #>ship_forward
sta INH
lda #<ship_forward
sta INL
lda #15
sta XPOS
lda #30
sta YPOS
jsr put_sprite
;==================
; flip pages
;==================
jsr page_flip ; 6
inc FRAME_COUNT
lda FRAME_COUNT
cmp #$ff
beq done_stars
;==================
; loop
;==================
jmp starfield_loop ; 3
done_stars:
rts
;=====================
; Starfield Credits
;=====================
starfield_credits:
;================================
; Clear screen and setup graphics
;================================
jsr clear_screens ; clear top/bottom of page 0/1
jsr set_gr_page0
;===============
; Init Variables
;===============
lda #0 ; 2
sta DRAW_PAGE ; 3
sta RANDOM_POINTER ; 3
; always multiply with low byte as zero
sta NUM2L ; 3
sta FRAME_COUNT
ldy #(NUMSTARS-1) ; 2
init_stars2:
jsr random_star ; 6
dey ; 2
bpl init_stars2 ; 2nt/3
;===========================
;===========================
; StarCredits Loop
;===========================
;===========================
starcredits_loop:
;===============
; clear screen
;===============
jsr clear_all ; 6+
; 6047
;===============
; draw the stars
;===============
jsr draw_stars
;====================
; draw the rasterbars
;====================
;====================
; draw the credits
;====================
;==================
; flip pages
;==================
jsr page_flip ; 6
inc FRAME_COUNT
lda FRAME_COUNT
cmp #$ff
beq done_star_credits
;==================
; loop
;==================
jmp starcredits_loop ; 3
done_star_credits:
rts
;======================================================
;======================================================
; draw stars ; draw stars
;=============== ;======================================================
;======================================================
; draws stars
draw_stars:
; start at 15 and count down (rather than 0 and count up) ; start at 15 and count down (rather than 0 and count up)
ldx #(NUMSTARS-1) ; 2 ldx #(NUMSTARS-1) ; 2
draw_stars: draw_stars_loop:
stx XX ; 3 stx XX ; 3
;================ ;================
@ -151,8 +290,8 @@ no_adjust:
; Check Limits ; Check Limits
;============================ ;============================
; ldy YPOS
bmi new_star ; 2nt/3 bmi new_star ; 2nt/3
y_limit_smc:
cpy #40 ; 2 cpy #40 ; 2
bpl new_star ; if < 0 or > 40 then done ; 2nt/3 bpl new_star ; if < 0 or > 40 then done ; 2nt/3
@ -180,9 +319,7 @@ plot_star_continue:
dex ; 2 dex ; 2
bmi move_stars ; 2nt/3 bmi move_stars ; 2nt/3
bpl draw_stars ; 2nt/3 bpl draw_stars_loop ; 2nt/3
; jmp draw_stars
;============================= ;=============================
; Move stars ; Move stars
@ -203,46 +340,15 @@ move_loop_skip:
dey ; 2 dey ; 2
bpl move_stars_loop ; 2nt/3 bpl move_stars_loop ; 2nt/3
rts
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 #<ship_forward
sta INL
lda #15
sta XPOS
lda #30
sta YPOS
jsr put_sprite
;==================
; flip pages
;==================
jsr page_flip ; 6
;==================
; loop forever
;==================
jmp starfield_loop ; 3
; matches scroll_row1 - row3 ; matches scroll_row1 - row3
@ -250,7 +356,11 @@ star_x EQU $8A00
star_y EQU $8B00 star_y EQU $8B00
star_z EQU $8C00 star_z EQU $8C00
;=================== ;==================================================
;==================================================
; Random Star
;==================================================
;==================================================
; star number in Y ; star number in Y
; FIXME: increment at end? ; FIXME: increment at end?
; X trashed ; X trashed