space_bars: clean up the code a bit

This commit is contained in:
Vince Weaver 2019-06-13 21:12:02 -04:00
parent b8c72c5517
commit 4ca9d6f1c1
8 changed files with 251 additions and 143 deletions

View File

@ -66,4 +66,4 @@ install:
clean:
rm -f *~ *.o *.lst *.inc INTERLACE RASTERBARS SPRITES HELLO
rm -f *~ *.o *.lst INTERLACE RASTERBARS SPRITES HELLO

View File

@ -1,2 +1,2 @@
10 PRINT "INTERLACE V0.1"
100 PRINT CHR$ (4)"BRUN SPRITES"
10 PRINT "INTERLACE V0.2"
100 PRINT CHR$ (4)"BRUN RASTERBARS"

View File

@ -20,7 +20,8 @@ space_bars.o: space_bars.s instructions.s game.s \
game_over.s gr_copy.s text_print.s title.s \
spacebars_title.inc screen_split.s \
sprites.s sprites_table.s sprites_screen.s \
vapor_lock.s delay_a.s lz4_decode.s SB_BACKGROUNDC.BIN.lz4
vapor_lock.s delay_a.s lz4_decode.s SB_BACKGROUNDC.BIN.lz4 \
keypress.s zp.inc hardware.inc
ca65 -o space_bars.o space_bars.s -l space_bars.lst
####

View File

@ -0,0 +1,36 @@
;==================================
; HLINE
;==================================
; Color in A
; Y has which line
hline:
pha ; 3
ldx gr_offsets,y ; 4+
stx hline_loop+1 ; 4
lda gr_offsets+1,y ; 4+
clc ; 2
adc DRAW_PAGE ; 3
sta hline_loop+2 ; 4
pla ; 4
ldx #39 ; 2
hline_loop:
sta $5d0,X ; 38 ; 5
dex ; 2
bpl hline_loop ; 2nt/3
rts ; 6
;==========================
; Clear gr screen
;==========================
; Color in A
clear_gr:
ldy #46
clear_page_loop:
jsr hline
dey
dey
bpl clear_page_loop
rts

20
space_bars/hardware.inc Normal file
View File

@ -0,0 +1,20 @@
; Soft Switches
KEYPRESS= $C000
KEYRESET= $C010
SET_GR = $C050 ; Enable graphics
SET_TEXT= $C051 ; Enable text
FULLGR = $C052 ; Full screen, no text
PAGE0 = $C054 ; Page0
PAGE1 = $C055 ; Page1
LORES = $C056 ; Enable LORES graphics
HIRES = $C057 ; Enable HIRES graphics
PADDLE_BUTTON0 = $C061
PADDL0 = $C064
PTRIG = $C070
; ROM routines
TEXT = $FB36 ;; Set text mode
HOME = $FC58 ;; Clear the text screen
WAIT = $FCA8 ;; delay 1/2(26+27A+5A^2) us

112
space_bars/keypress.s Normal file
View File

@ -0,0 +1,112 @@
;==========================================================
; Wait until keypressed
;==========================================================
;
wait_until_keypressed:
inc RANDOM_PTR ; randomize things a bit
lda KEYPRESS ; check if keypressed
bpl wait_until_keypressed ; if not, loop
jmp figure_out_key
;==========================================================
; Get Key
;==========================================================
;
get_key:
check_paddle_button:
; check for paddle button
bit PADDLE_BUTTON0 ; 4
bpl no_button ; 2nt/3
lda #' '+128 ; 2
jmp save_key ; 3
no_button:
lda KEYPRESS ; 3
bpl no_key ; 2nt/3
figure_out_key:
cmp #' '+128 ; the mask destroys space ; 2
beq save_key ; so handle it specially ; 2nt/3
and #$5f ; mask, to make upper-case ; 2
check_right_arrow:
cmp #$15 ; 2
bne check_left_arrow ; 2nt/3
lda #'D' ; 2
check_left_arrow:
cmp #$08 ; 2
bne check_up_arrow ; 2nt/3
lda #'A' ; 2
check_up_arrow:
cmp #$0B ; 2
bne check_down_arrow ; 2nt/3
lda #'W' ; 2
check_down_arrow:
cmp #$0A ; 2
bne check_escape ; 2nt/3
lda #'S' ; 2
check_escape:
cmp #$1B ; 2
bne save_key ; 2nt/3
lda #'Q' ; 2
jmp save_key ; 3
no_key:
bit PADDLE_STATUS ; 3
bpl no_key_store ; 2nt/3
; check for paddle action
; code from http://web.pdx.edu/~heiss/technotes/aiie/tn.aiie.06.html
inc PADDLE_STATUS ; 5
lda PADDLE_STATUS ; 3
and #$03 ; 2
beq check_paddles ; 2nt/3
jmp no_key_store ; 3
check_paddles:
lda PADDLE_STATUS ; 3
and #$80 ; 2
sta PADDLE_STATUS ; 3
ldx #$0 ; 2
LDA PTRIG ;TRIGGER PADDLES ; 4
LDY #0 ;INIT COUNTER ; 2
NOP ;COMPENSATE FOR 1ST COUNT ; 2
NOP ; 2
PREAD2: LDA PADDL0,X ;COUNT EVERY 11 uSEC. ; 4
BPL RTS2D ;BRANCH WHEN TIMED OUT ; 2nt/3
INY ;INCREMENT COUNTER ; 2
BNE PREAD2 ;CONTINUE COUNTING ; 2nt/3
DEY ;COUNTER OVERFLOWED ; 2
RTS2D: ;RETURN W/VALUE 0-255
cpy #96 ; 2
bmi paddle_left ; 2nt/3
cpy #160 ; 2
bmi no_key_store ; 2nt/3
lda #'D' ; 2
jmp save_key ; 3
paddle_left:
lda #'A' ; 2
jmp save_key ; 3
no_key_store:
lda #0 ; no key, so save a zero ; 2
save_key:
sta LASTKEY ; save the key to our buffer ; 2
bit KEYRESET ; clear the keyboard buffer ; 4
rts ; 6
;============
; 33=nokey
; 48=worstkey

View File

@ -1,109 +1,19 @@
;=====================================
; Rasterbars in Space
;
; a cycle-counting game
; a cycle-counting racing-the-beam game
;
; by deater (Vince Weaver) <vince@deater.net>
;=====================================
; Zero Page
FRAMEBUFFER = $00 ; $00 - $0F
;; LZ4 addresses
LZ4_SRC = $00
LZ4_DST = $02
LZ4_END = $04
COUNT = $06
DELTA = $08
CH = $24
CV = $25
GBASL = $26
GBASH = $27
BASL = $28
BASH = $29
MASK = $2E
COLOR = $30
FRAME = $60
FRAMEH = $61
BLARGH = $69
ZPOS = $78
GREEN0 = $80
GREEN1 = $81
GREEN2 = $82
GREEN3 = $83
GREEN4 = $84
ZERO = $85
GAME_OVER = $86
SPRITE_XPOS = $E0
SPRITE_YPOS = $E1
RANDOM_PTR = $E2
ASTEROID_X = $E3
ASTEROID_Y = $E4
ASTEROID_SUBX = $E5
ASTEROID_EXPLODE= $E6
FIRE_X = $E7
FIRE_Y = $E8
YADD = $E9
BLAST1 = $EA
BLAST2 = $EB
FIRE = $EC
LEVEL_DONE = $ED
DRAW_PAGE = $EE
LASTKEY = $F1
PADDLE_STATUS = $F2
XPOS = $F3
YPOS = $F4
WHICH = $F5
ASTEROID_SPEED = $F6
TEMP = $FA
TEMPY = $FB
INL = $FC
INH = $FD
OUTL = $FE
OUTH = $FF
; Soft Switches
KEYPRESS= $C000
KEYRESET= $C010
SET_GR = $C050 ; Enable graphics
SET_TEXT= $C051 ; Enable text
FULLGR = $C052 ; Full screen, no text
PAGE0 = $C054 ; Page0
PAGE1 = $C055 ; Page1
LORES = $C056 ; Enable LORES graphics
HIRES = $C057 ; Enable HIRES graphics
PADDLE_BUTTON0 = $C061
PADDL0 = $C064
PTRIG = $C070
; ROM routines
TEXT = $FB36 ;; Set text mode
HOME = $FC58 ;; Clear the text screen
WAIT = $FCA8 ;; delay 1/2(26+27A+5A^2) us
.include "zp.inc"
; hardware addresses/soft_switches
.include "hardware.inc"
space_bars_begin:
;==================
; show title screen
@ -123,18 +33,18 @@ WAIT = $FCA8 ;; delay 1/2(26+27A+5A^2) us
; TODO
;==================
; 40x192 sprites
;==================
;=============================
; EARTH: 40x192 sprites
;=============================
jsr start_sprites
lda GAME_OVER
bne game_over_man
;==================
; Rasterbars
;==================
;============================
; SATURN: Rasterbars
;============================
jsr game
@ -148,44 +58,7 @@ loop_forever:
jmp loop_forever
;==================================
; HLINE
;==================================
; Color in A
; Y has which line
hline:
pha ; 3
ldx gr_offsets,y ; 4+
stx hline_loop+1 ; 4
lda gr_offsets+1,y ; 4+
clc ; 2
adc DRAW_PAGE ; 3
sta hline_loop+2 ; 4
pla ; 4
ldx #39 ; 2
hline_loop:
sta $5d0,X ; 38 ; 5
dex ; 2
bpl hline_loop ; 2nt/3
rts ; 6
;==========================
; Clear gr screen
;==========================
; Color in A
clear_gr:
ldy #46
clear_page_loop:
jsr hline
dey
dey
bpl clear_page_loop
rts
.include "gr_simple_clear.s"
.include "gr_offsets.s"

66
space_bars/zp.inc Normal file
View File

@ -0,0 +1,66 @@
; Zero Page
FRAMEBUFFER = $00 ; $00 - $0F
;; LZ4 addresses
LZ4_SRC = $00
LZ4_DST = $02
LZ4_END = $04
COUNT = $06
DELTA = $08
CH = $24
CV = $25
GBASL = $26
GBASH = $27
BASL = $28
BASH = $29
MASK = $2E
COLOR = $30
FRAME = $60
FRAMEH = $61
BLARGH = $69
ZPOS = $78
GREEN0 = $80
GREEN1 = $81
GREEN2 = $82
GREEN3 = $83
GREEN4 = $84
ZERO = $85
GAME_OVER = $86
SPRITE_XPOS = $E0
SPRITE_YPOS = $E1
RANDOM_PTR = $E2
ASTEROID_X = $E3
ASTEROID_Y = $E4
ASTEROID_SUBX = $E5
ASTEROID_EXPLODE= $E6
FIRE_X = $E7
FIRE_Y = $E8
YADD = $E9
BLAST1 = $EA
BLAST2 = $EB
FIRE = $EC
LEVEL_DONE = $ED
DRAW_PAGE = $EE
LASTKEY = $F1
PADDLE_STATUS = $F2
XPOS = $F3
YPOS = $F4
WHICH = $F5
ASTEROID_SPEED = $F6
TEMP = $FA
TEMPY = $FB
INL = $FC
INH = $FD
OUTL = $FE
OUTH = $FF