keen: clean up variable initialization

some things should be initialized at the title, some at the level
This commit is contained in:
Vince Weaver 2024-03-20 01:03:28 -04:00
parent afaea8e59c
commit f3f4681194
8 changed files with 135 additions and 137 deletions

View File

@ -40,7 +40,7 @@ loader.o: loader.s
KEEN_TITLE: keen_title.o KEEN_TITLE: keen_title.o
ld65 -o KEEN_TITLE keen_title.o -C ../../linker_scripts/apple2_4000.inc ld65 -o KEEN_TITLE keen_title.o -C ../../linker_scripts/apple2_4000.inc
keen_title.o: keen_title.s zp.inc hardware.inc init_vars.s \ keen_title.o: keen_title.s zp.inc hardware.inc \
zx02_optim.s \ zx02_optim.s \
graphics/keen1_title.hgr.zx02 graphics/keen1_title.hgr.zx02
ca65 -o keen_title.o keen_title.s -l keen_title.lst ca65 -o keen_title.o keen_title.s -l keen_title.lst

View File

@ -45,7 +45,7 @@ hit_something:
jsr enemy_noise jsr enemy_noise
jsr inc_score_by_10 ; jsr inc_score_by_10
jmp exit_laser_enemy jmp exit_laser_enemy

View File

@ -1,31 +0,0 @@
;=====================
; init vars
;=====================
init_vars:
lda #0
sta ANIMATE_FRAME
sta FRAMEL
sta FRAMEH
sta JOYSTICK_ENABLED
sta KEEN_WALKING
sta KEEN_JUMPING
sta LEVEL_OVER
sta LASER_OUT
sta KEEN_XL
sta SCORE0
sta SCORE1
sta SCORE2
sta KEEN_FALLING
sta KEEN_SHOOTING
sta KICK_UP_DUST
sta DOOR_ACTIVATED
sta INVENTORY
lda #1
sta FIREPOWER
lda #4
sta KEENS
rts

View File

@ -33,20 +33,15 @@ keen_start:
sta ANIMATE_FRAME sta ANIMATE_FRAME
sta FRAMEL sta FRAMEL
sta FRAMEH sta FRAMEH
sta JOYSTICK_ENABLED
sta KEEN_WALKING sta KEEN_WALKING
sta KEEN_JUMPING sta KEEN_JUMPING
sta LEVEL_OVER sta LEVEL_OVER
sta LASER_OUT sta LASER_OUT
sta KEEN_XL sta KEEN_XL
sta SCORE0
sta SCORE1
sta SCORE2
sta KEEN_FALLING sta KEEN_FALLING
sta KEEN_SHOOTING sta KEEN_SHOOTING
sta KICK_UP_DUST sta KICK_UP_DUST
sta DOOR_ACTIVATED sta KEYCARDS
sta INVENTORY
lda #<enemy_data lda #<enemy_data
sta ENEMY_DATAL sta ENEMY_DATAL
@ -61,11 +56,7 @@ keen_start:
; lda #$10 ; lda #$10
; sta SCORE0 ; sta SCORE0
lda #1
sta FIREPOWER
; lda #7
; sta HEALTH
lda #4 lda #4
sta DRAW_PAGE sta DRAW_PAGE

View File

@ -31,42 +31,16 @@ keen_start:
sta ANIMATE_FRAME sta ANIMATE_FRAME
sta FRAMEL sta FRAMEL
sta FRAMEH sta FRAMEH
sta JOYSTICK_ENABLED
sta KEEN_WALKING sta KEEN_WALKING
sta KEEN_JUMPING sta KEEN_JUMPING
sta LEVEL_OVER sta LEVEL_OVER
sta LASER_OUT sta LASER_OUT
sta KEEN_XL sta KEEN_XL
sta SCORE0
sta SCORE1
sta SCORE2
sta KEEN_FALLING sta KEEN_FALLING
sta KEEN_SHOOTING sta KEEN_SHOOTING
sta KICK_UP_DUST sta KICK_UP_DUST
sta DOOR_ACTIVATED
sta INVENTORY
; lda #<enemy_data
; sta ENEMY_DATAL
; lda #>enemy_data
; sta ENEMY_DATAH
; FIXME: temporary
; lda INVENTORY
; ora #INV_RED_KEY
; sta INVENTORY
; lda #$10
; sta SCORE0
lda #1
sta FIREPOWER
lda #2 ; draw twice (both pages)
sta UPDATE_STATUS
lda #4
sta KEENS
lda #4 lda #4
sta DRAW_PAGE sta DRAW_PAGE

View File

@ -176,11 +176,28 @@ done_intro:
bit FULLGR bit FULLGR
bit LORES bit LORES
;============================ ;=====================
; init vars ; init vars
;=====================
init_vars:
lda #0
sta ANIMATE_FRAME
sta FRAMEL
sta FRAMEH
sta JOYSTICK_ENABLED
sta LEVEL_OVER
jsr init_vars sta SCORE0 ; set score to 0
sta SCORE1
sta SCORE2
sta RAYGUNS ; number of laser blasts
sta KEYCARDS
sta SHIP_PARTS
sta POGO
lda #4 ; number of lives
sta KEENS
;============================ ;============================
@ -206,7 +223,6 @@ done_intro:
.include "gr_fast_clear.s" .include "gr_fast_clear.s"
.include "text_print.s" .include "text_print.s"
.include "init_vars.s"
; .include "graphics_title/title_graphics.inc" ; .include "graphics_title/title_graphics.inc"
; .include "lc_detect.s" ; .include "lc_detect.s"

View File

@ -1,15 +1,17 @@
; Draw Status Bar ; Draw Status Bar
;=========================== ;===========================
; inc_score_by_10 ; inc_score
;=========================== ;===========================
; FIXME: make sure interrupt routine handles d flag properly ; make sure any interrupt routine handles d flag properly
inc_score_by_10: ; value to add by in A (BCD/100)
; for Keen assume always a multiple of 100
inc_score:
sed sed
lda SCORE0
clc clc
adc #$10 adc SCORE0
sta SCORE0 sta SCORE0
lda SCORE1 lda SCORE1
@ -21,8 +23,6 @@ inc_score_by_10:
sta SCORE2 sta SCORE2
cld cld
jsr update_score
rts rts
;=========================== ;===========================
@ -34,7 +34,7 @@ update_score:
lda SCORE0 lda SCORE0
and #$f and #$f
ora #$b0 ; 0 -> $b0 ora #$b0 ; 0 -> $b0
sta status_string+6 sta score_string+6
lda SCORE0 lda SCORE0
lsr lsr
@ -42,12 +42,12 @@ update_score:
lsr lsr
lsr lsr
ora #$b0 ; 0 -> $b0 ora #$b0 ; 0 -> $b0
sta status_string+5 sta score_string+5
lda SCORE1 lda SCORE1
and #$f and #$f
ora #$b0 ; 0 -> $b0 ora #$b0 ; 0 -> $b0
sta status_string+4 sta score_string+4
lda SCORE1 lda SCORE1
lsr lsr
@ -55,15 +55,12 @@ update_score:
lsr lsr
lsr lsr
ora #$b0 ; 0 -> $b0 ora #$b0 ; 0 -> $b0
sta status_string+3 sta score_string+3
lda SCORE2 lda SCORE2
and #$f and #$f
ora #$b0 ; 0 -> $b0 ora #$b0 ; 0 -> $b0
sta status_string+2 sta score_string+2
lda #2
sta UPDATE_STATUS
rts rts
@ -72,8 +69,9 @@ update_score:
; update health ; update health
;=========================== ;===========================
update_health:
.if 0 .if 0
update_health:
ldx #0 ldx #0
update_health_loop: update_health_loop:
cpx HEALTH cpx HEALTH
@ -83,13 +81,14 @@ update_health_loop:
health_on: health_on:
lda #' ' lda #' '
done_health: done_health:
sta status_string+9,X sta score_string+9,X
inx inx
cpx #8 cpx #8
bne update_health_loop bne update_health_loop
.endif
rts rts
.endif
;=========================== ;===========================
; update items ; update items
@ -97,23 +96,23 @@ done_health:
update_items: update_items:
lda INVENTORY lda KEYCARDS
and #INV_RED_KEY and #INV_RED_KEY
beq done_red_key beq done_red_key
lda #'R'&$3f lda #'R'&$3f
sta status_string+33 sta score_string+33
done_red_key: done_red_key:
lda INVENTORY lda KEYCARDS
and #INV_BLUE_KEY and #INV_BLUE_KEY
beq done_blue_key beq done_blue_key
lda #'B'&$3f lda #'B'&$3f
sta status_string+35 sta score_string+35
done_blue_key: done_blue_key:
@ -125,42 +124,92 @@ done_blue_key:
;=========================== ;===========================
; update the status bar ; update the status bar
;=========================== ;===========================
update_status_bar: ;update_status_bar:
;
jsr update_score ; jsr update_score
;
jsr update_health ; jsr update_health
;
jsr update_items ; jsr update_items
;
lda #2 ; lda #2
sta UPDATE_STATUS ; sta UPDATE_STATUS
;
rts ; rts
;=========================== ;===========================
; draw the status bar ; draw the status bar
;=========================== ;===========================
; only draw when ENTER pressed, not always ; only draw when ENTER pressed, not always
draw_status_bar: draw_status_bar:
bit TEXTGR
jsr update_score
bit TEXTGR ; split graphics/text
; draw to visible frame ; draw to visible frame
lda DRAW_PAGE lda DRAW_PAGE
eor #$4 eor #$4
sta DRAW_PAGE sta DRAW_PAGE
jsr inverse_text ; print help node ; draw white box
lda #<help_string
ldx #30
draw_box_loop:
lda gr_offsets,X
sta OUTL sta OUTL
lda #>help_string lda gr_offsets+1,X
clc
adc DRAW_PAGE
sta OUTH
ldy #39
lda #$FF
draw_box_inner:
sta (OUTL),Y
dey
bpl draw_box_inner
inx
inx
cpx #40
bne draw_box_loop
; draw keens
ldx #<keen_sprite_stand_right
stx INL
lda #>keen_sprite_stand_right
sta INH
; XPOS, YPOS
lda #2
sta XPOS
lda #32
sta YPOS
jsr put_sprite_crop
; TODO: draw keycards
; TODO: draw parts
; draw text at bottom
jsr inverse_text
lda #<status_string
sta OUTL
lda #>status_string
sta OUTH sta OUTH
jsr move_and_print jsr move_and_print
jsr move_and_print
jsr normal_text ; (normal) jsr move_and_print
jsr move_and_print ; print explain text jsr move_and_print
jsr raw_text
jsr move_and_print ; print status line
; wait for keypress ; wait for keypress
@ -181,18 +230,11 @@ wait_status_bar:
rts rts
help_string:
.byte 3,20," PRESS 'H' FOR HELP ",0
score_string:
; 012456789012345678901234567890123456789
.byte 0,22,"SCORE HEALTH FIREPOWER INVENTORY",0
status_string: status_string:
; .byte 0,23,"ZZZZZ XXXXXXXX =- ",0 ; 0123456789012345678901234567890123456789
.byte 0,23,"ZZZZZ" .byte 0,20," KEENS KEYCARDS PARTS ",0
.byte ' '|$80,' '|$80 .byte 0,21," ",0
.byte "XXXXXXXX" .byte 0,22," SCORE NEXT KEEN RAYGUN POGO ",0
.byte ' '|$80,' '|$80 score_string:
.byte '='|$80,'-'|$80,' '|$80,' '|$80,' '|$80,' '|$80,' '|$80,' '|$80,' '|$80,' '|$80 .byte 0,23," 00000000 20000 0 N ",0
.byte ' '|$80,' '|$80,' '|$80,' '|$80,' '|$80,' '|$80,' '|$80,' '|$80,' '|$80,' '|$80,' '|$80,' '|$80,0

View File

@ -104,17 +104,23 @@ TILEMAP_Y = $8C
KEEN_FOOT_OFFSET = $8D KEEN_FOOT_OFFSET = $8D
FIREPOWER = $8E RAYGUNS = $8E
INVENTORY = $8F KEYCARDS = $8F
INV_RED_KEY = $80 INV_RED_KEY = $01
INV_BLUE_KEY = $20 INV_BLUE_KEY = $02
INV_SHOE = $08 INV_YELLOW_KEY = $04
INV_GRIP = $02 INV_GREEN_KEY = $08
KEENS = $90 KEENS = $90
SCORE0 = $91 SCORE0 = $91
SCORE1 = $92 SCORE1 = $92
SCORE2 = $93 SCORE2 = $93
UPDATE_STATUS = $94
SHIP_PARTS = $94
PARTS_BOTTLE = $01
PARTS_VACUUM = $02
PARTS_BATTERY = $04
PARTS_JOYSTICK = $08
KEEN_FALLING = $95 KEEN_FALLING = $95
KEEN_SHOOTING = $96 KEEN_SHOOTING = $96
@ -122,7 +128,7 @@ KICK_UP_DUST = $97
SUPPRESS_WALK = $98 SUPPRESS_WALK = $98
ENEMY_DATAL = $99 ENEMY_DATAL = $99
ENEMY_DATAH = $9A ENEMY_DATAH = $9A
DOOR_ACTIVATED = $9B POGO = $9B
LASER_TILE = $9C LASER_TILE = $9C
TILE_TEMP = $9D TILE_TEMP = $9D