Compare commits

...

2 Commits

Author SHA1 Message Date
Vince Weaver 5bd0d77d18 keen1: closer to getting mars working again 2024-04-11 00:33:20 -04:00
Vince Weaver eb68006055 keen: move to 128x80 tilemap
more difficult than 256x40, but all levels should fit
2024-04-11 00:09:42 -04:00
6 changed files with 432 additions and 290 deletions

View File

@ -52,9 +52,10 @@ MARS: mars.o
mars.o: mars.s zp.inc hardware.inc game_over.s \
gr_fade.s \
mars_keyboard.s draw_tilemap.s \
mars_sfx.s longer_sound.s \
text_help.s \
maps/mars_map.gr.zx02 graphics/parts.gr.zx02
maps/mars_new.zx02 graphics/parts.gr.zx02
ca65 -o mars.o mars.s -l mars.lst
####

View File

@ -108,8 +108,9 @@ done_move_to_line:
; local tilemap subset is 20x12 tiles = 240 bytes
; nicely fits in one page
;
; big tilemap is 256*40
; so each row is a page
; big tilemap is 128x80
; sad, was much cleaner to implement when 256x40
; TILEMAP_X, TILEMAP_Y specify where in big
@ -118,19 +119,33 @@ TILEMAP_Y_COPY_SIZE = 12
copy_tilemap_subset:
; TODO: lookup table?
; would be sorta big
lda #0
sta tilemap_count_smc+1
; set start
lda TILEMAP_Y
lsr
; set odd/even
ldx #0
bcc skip_odd_row
ldx #$80
skip_odd_row:
stx cptl1_smc+1
clc ; set start
adc #>big_tilemap ; each row is a page, so adding
adc #>big_tilemap ; each even row is a page, so adding
; Y to top byte is indexing to row
sta cptl1_smc+2 ; set proper row in big tilemap
adc #TILEMAP_Y_COPY_SIZE
sta cptl3_smc+1 ; set loop limit (end)
; reset row
lda #<tilemap
sta cptl2_smc+1 ; set small tilemap to row0
sta cptl2_smc+1 ; reset small tilemap to row0
cp_tilemap_outer_loop:
@ -138,6 +153,8 @@ cp_tilemap_outer_loop:
ldy #0
cp_tilemap_inner_loop:
; TODO: optimize, totally unroll?
cptl1_smc:
lda $9400,X
cptl2_smc:
@ -148,14 +165,23 @@ cptl2_smc:
bne cp_tilemap_inner_loop
; next line
inc cptl1_smc+2 ; incremement page
clc
lda cptl1_smc+1
adc #$80
sta cptl1_smc+1
lda #$0
adc cptl1_smc+2
sta cptl1_smc+2
clc
lda cptl2_smc+1 ; increment row
adc #TILEMAP_X_COPY_SIZE
sta cptl2_smc+1
lda cptl1_smc+2
cptl3_smc:
inc tilemap_count_smc+1
tilemap_count_smc:
lda #0
cmp #TILEMAP_Y_COPY_SIZE
bne cp_tilemap_outer_loop
@ -163,7 +189,8 @@ done_tilemap_subset:
; activate yorps
ldx #0
ldx NUM_ENEMIES
beq done_yorps
clc
lda TILEMAP_X
@ -181,8 +208,8 @@ activate_yorp_loop:
sta enemy_data_out,X
next_yorp:
inx
cpx #NUM_ENEMIES
bne activate_yorp_loop
dex
bpl activate_yorp_loop
done_yorps:
rts

View File

@ -62,7 +62,6 @@ keen_start:
lda #0 ; offset from tile location
sta KEEN_X
lda #0
sta KEEN_Y
lda #RIGHT ; direction
@ -72,14 +71,14 @@ keen_start:
; load level1 background
;====================================
lda #<level1_bg_zx02
sta ZX0_src
lda #>level1_bg_zx02
sta ZX0_src+1
; lda #<level1_bg_zx02
; sta ZX0_src
; lda #>level1_bg_zx02
; sta ZX0_src+1
lda #$c ; load to page $c00
; lda #$c ; load to page $c00
jsr full_decomp
; jsr full_decomp
;====================================
@ -272,8 +271,8 @@ level1_levelover:
;==========================
; level graphics
level1_bg_zx02:
.incbin "graphics/level1_bg.gr.zx02"
;level1_bg_zx02:
; .incbin "graphics/level1_bg.gr.zx02"
.include "text_print.s"
.include "gr_offsets.s"

View File

@ -1,8 +1,5 @@
; Keen MARS main map
; TODO: should make it scrollable, etc / tilemap
; TODO: fade in effect (from mode7 demo)
;
; by deater (Vince Weaver) <vince@deater.net>
; Zero Page
@ -10,6 +7,11 @@
.include "hardware.inc"
.include "common_defines.inc"
; or are there?
NUM_ENEMIES = 0
TILE_COLS = 20 ; define this elsewhere?
mars_start:
;===================
; init screen
@ -25,7 +27,11 @@ mars_start:
jsr clear_all ; avoid grey stripes at load
lda KEENS
bmi return_to_title
bpl plenty_of_keens
jmp return_to_title
plenty_of_keens:
;=====================
; init vars
@ -59,20 +65,46 @@ mars_start:
cmp #GAME_OVER
beq return_to_title
; TODO: set this in title, don't over-write
lda #1
sta MARS_TILEX
lda #6
sta MARS_TILEY
lda #0
sta MARS_X
sta MARS_Y
;====================================
; load mars background
; load mars tilemap
;====================================
lda #<mars_zx02
lda #<mars_data_zx02
sta ZX0_src
lda #>mars_zx02
lda #>mars_data_zx02
sta ZX0_src+1
lda #$c ; load to page $c00
lda #$90 ; load to page $9000
jsr full_decomp
;====================================
; copy in tilemap subset
;====================================
; FIXME: start values
; center around MARS_TILEX, MARS_TILEY
lda MARS_TILEX
sta TILEMAP_X
lda MARS_TILEY
sta TILEMAP_Y
jsr copy_tilemap_subset
lda #1
sta INITIAL_SOUND
@ -87,11 +119,10 @@ mars_start:
;====================================
;====================================
keen_loop:
mars_loop:
; draw tilemap
; copy over background
jsr gr_copy_to_current
jsr draw_tilemap
; draw keen
@ -129,7 +160,7 @@ no_frame_oflo:
bne done_with_keen
do_keen_loop:
do_mars_loop:
;=====================
; sound effect
@ -148,7 +179,7 @@ skip_initial_sound:
; lda #200
; jsr WAIT
jmp keen_loop
jmp mars_loop
done_with_keen:
@ -189,38 +220,6 @@ return_to_title:
;==========================
; includes
;==========================
; level graphics
mars_zx02:
.incbin "maps/mars_map.gr.zx02"
parts_zx02:
.incbin "graphics/parts.gr.zx02"
.include "text_print.s"
.include "gr_offsets.s"
.include "gr_fast_clear.s"
.include "gr_copy.s"
.include "gr_pageflip.s"
; .include "gr_putsprite_crop.s"
.include "zx02_optim.s"
.include "gr_fade.s"
.include "joystick.s"
.include "text_drawbox.s"
.include "text_help.s"
.include "text_quit_yn.s"
.include "game_over.s"
.include "mars_sfx.s"
.include "longer_sound.s"
;=========================
; draw keen
@ -312,212 +311,11 @@ draw_keen_even:
rts
;==============================
; Handle Keypress
;==============================
handle_keypress:
; first handle joystick
lda JOYSTICK_ENABLED
beq actually_handle_keypress
; only check joystick every-other frame
lda FRAMEL
and #$1
beq actually_handle_keypress
check_button:
lda PADDLE_BUTTON0
bpl button_clear
lda JS_BUTTON_STATE
bne js_check
lda #1
sta JS_BUTTON_STATE
lda #' '
jmp check_sound
button_clear:
lda #0
sta JS_BUTTON_STATE
js_check:
jsr handle_joystick
js_check_left:
lda value0
cmp #$20
bcs js_check_right ; if less than 32, left
lda #'A'
bne check_sound
js_check_right:
cmp #$40
bcc js_check_up
lda #'D'
bne check_sound
js_check_up:
lda value1
cmp #$20
bcs js_check_down
lda #'W'
bne check_sound
js_check_down:
cmp #$40
bcc done_joystick
lda #'S'
bne check_sound
done_joystick:
actually_handle_keypress:
lda KEYPRESS
bmi keypress
jmp no_keypress
keypress:
and #$7f ; clear high bit
cmp #' '
beq check_sound ; make sure not to lose space
and #$df ; convert uppercase to lower case
check_sound:
cmp #$14 ; control-T
bne check_help
lda SOUND_STATUS
eor #SOUND_DISABLED
sta SOUND_STATUS
jmp done_keypress
check_help:
cmp #'H' ; H (^H is same as left)
bne check_joystick
jsr print_help
jmp done_keypress
; can't be ^J as that's the same as down
check_joystick:
cmp #'J' ; J
bne check_left
lda JOYSTICK_ENABLED
eor #1
sta JOYSTICK_ENABLED
jmp done_keypress
check_left:
cmp #'A'
beq left_pressed
cmp #8 ; left key
bne check_right
left_pressed:
ldy MARS_X
dey
ldx MARS_Y
jsr check_valid_feet
bcc done_left_pressed
dec MARS_X
done_left_pressed:
jmp done_keypress
check_right:
cmp #'D'
beq right_pressed
cmp #$15 ; right key
bne check_up
right_pressed:
ldy MARS_X
iny
ldx MARS_Y
jsr check_valid_feet
bcc done_right_pressed
inc MARS_X
done_right_pressed:
jmp done_keypress
check_up:
cmp #'W'
beq up_pressed
cmp #$0B ; up key
bne check_down
up_pressed:
ldy MARS_X
ldx MARS_Y
dex
jsr check_valid_feet
bcc done_up_pressed
dec MARS_Y
done_up_pressed:
jmp done_keypress
check_down:
cmp #'S'
beq down_pressed
cmp #$0A
bne check_space
down_pressed:
ldy MARS_X
ldx MARS_Y
inx
jsr check_valid_feet
bcc done_up_pressed
inc MARS_Y
done_down_pressed:
jmp done_keypress
check_space:
cmp #' '
bne check_return
space_pressed:
jsr do_action
jmp done_keypress
check_return:
cmp #13
bne check_escape
return_pressed:
;inc LEVEL_OVER
jsr do_action
done_return:
jmp no_keypress
check_escape:
cmp #27
bne done_keypress
jsr print_quit
jmp done_keypress
done_keypress:
no_keypress:
bit KEYRESET
rts
;=================================
;=================================
; check valid feet
;=================================
;=================================
; essentially if SCRN(Y,X+2)=9
check_valid_feet:
txa
@ -554,16 +352,20 @@ feet_valid:
sec
rts
feet_invalid:
clc
; clc
sec
rts
;====================================
;====================================
; show parts screen
;====================================
;====================================
; TODO: color in if found
do_parts:
lda #<parts_zx02
sta ZX0_src
@ -590,18 +392,23 @@ done_parts:
bit FULLGR
lda #<mars_zx02
sta ZX0_src
lda #>mars_zx02
sta ZX0_src+1
; lda #<mars_zx02
; sta ZX0_src
; lda #>mars_zx02
; sta ZX0_src+1
lda #$c ; load to page $c00
; lda #$c ; load to page $c00
jsr full_decomp ; tail call
; jsr full_decomp ; tail call
rts
;====================================
;====================================
; Mars action
;====================================
;====================================
; if enter pressed on map
do_action:
lda MARS_X
@ -640,3 +447,46 @@ maybe_exit:
star_colors:
.byte $05,$07,$07,$0f
.byte $0f,$07,$05,$0a
;==========================
; includes
;==========================
; level graphics
mars_zx02:
.incbin "maps/mars_map.gr.zx02"
parts_zx02:
.incbin "graphics/parts.gr.zx02"
.include "text_print.s"
.include "gr_offsets.s"
.include "gr_fast_clear.s"
.include "gr_copy.s"
.include "gr_pageflip.s"
; .include "gr_putsprite_crop.s"
.include "zx02_optim.s"
.include "gr_fade.s"
.include "joystick.s"
.include "text_drawbox.s"
.include "text_help.s"
.include "text_quit_yn.s"
.include "game_over.s"
.include "mars_keyboard.s"
.include "draw_tilemap.s"
.include "mars_sfx.s"
.include "longer_sound.s"
mars_data_zx02:
.incbin "maps/mars_new.zx02"
; dummy
enemy_data_out:
enemy_data_tilex:

263
games/keen/mars_keyboard.s Normal file
View File

@ -0,0 +1,263 @@
;==============================
; Handle Keypress
;==============================
handle_keypress:
; first handle joystick
lda JOYSTICK_ENABLED
beq actually_handle_keypress
; only check joystick every-other frame
lda FRAMEL
and #$1
beq actually_handle_keypress
check_button:
lda PADDLE_BUTTON0
bpl button_clear
lda JS_BUTTON_STATE
bne js_check
lda #1
sta JS_BUTTON_STATE
lda #' '
jmp check_sound
button_clear:
lda #0
sta JS_BUTTON_STATE
js_check:
jsr handle_joystick
js_check_left:
lda value0
cmp #$20
bcs js_check_right ; if less than 32, left
lda #'A'
bne check_sound
js_check_right:
cmp #$40
bcc js_check_up
lda #'D'
bne check_sound
js_check_up:
lda value1
cmp #$20
bcs js_check_down
lda #'W'
bne check_sound
js_check_down:
cmp #$40
bcc done_joystick
lda #'S'
bne check_sound
done_joystick:
actually_handle_keypress:
lda KEYPRESS
bmi keypress
jmp no_keypress
keypress:
and #$7f ; clear high bit
cmp #' '
beq check_sound ; make sure not to lose space
and #$df ; convert uppercase to lower case
check_sound:
cmp #$14 ; control-T
bne check_help
lda SOUND_STATUS
eor #SOUND_DISABLED
sta SOUND_STATUS
jmp done_keypress
check_help:
cmp #'H' ; H (^H is same as left)
bne check_joystick
jsr print_help
jmp done_keypress
; can't be ^J as that's the same as down
check_joystick:
cmp #'J' ; J
bne check_left
lda JOYSTICK_ENABLED
eor #1
sta JOYSTICK_ENABLED
jmp done_keypress
check_left:
cmp #'A'
beq left_pressed
cmp #8 ; left key
bne check_right
left_pressed:
lda TILEMAP_X
beq keen_walk_left
sec
lda MARS_TILEX
sbc TILEMAP_X
cmp #7
bcs keen_walk_left
keen_scroll_left:
dec TILEMAP_X
dec MARS_TILEX
jsr copy_tilemap_subset
jmp done_move_keen
keen_walk_left:
dec MARS_X
bpl dwl_noflo
lda #1
sta MARS_X
dec MARS_TILEX
dwl_noflo:
; ldy MARS_X
; dey
; ldx MARS_Y
; jsr check_valid_feet
; bcc done_left_pressed
; dec MARS_X
done_left_pressed:
jmp done_keypress
check_right:
cmp #'D'
beq right_pressed
cmp #$15 ; right key
bne check_up
right_pressed:
move_right:
lda TILEMAP_X
cmp #50 ; 70-20
bcs keen_walk_right
sec
lda MARS_TILEX
sbc TILEMAP_X
cmp #11
bcc keen_walk_right
keen_scroll_right:
inc TILEMAP_X
inc MARS_TILEX
jsr copy_tilemap_subset
jmp done_move_keen
keen_walk_right:
inc MARS_X
lda MARS_X
cmp #2
bne dwr_noflo
lda #0
sta MARS_X
inc MARS_TILEX
dwr_noflo:
; ldy MARS_X
; iny
; ldx MARS_Y
; jsr check_valid_feet
; bcc done_right_pressed
; inc MARS_X
done_right_pressed:
jmp done_keypress
check_up:
cmp #'W'
beq up_pressed
cmp #$0B ; up key
bne check_down
up_pressed:
ldy MARS_X
ldx MARS_Y
dex
jsr check_valid_feet
bcc done_up_pressed
dec MARS_Y
done_up_pressed:
jmp done_keypress
check_down:
cmp #'S'
beq down_pressed
cmp #$0A
bne check_space
down_pressed:
ldy MARS_X
ldx MARS_Y
inx
jsr check_valid_feet
bcc done_up_pressed
inc MARS_Y
done_down_pressed:
jmp done_keypress
check_space:
cmp #' '
bne check_return
space_pressed:
jsr do_action
jmp done_keypress
check_return:
cmp #13
bne check_escape
return_pressed:
;inc LEVEL_OVER
jsr do_action
done_return:
jmp no_keypress
check_escape:
cmp #27
bne done_keypress
jsr print_quit
jmp done_keypress
done_move_keen:
done_keypress:
no_keypress:
bit KEYRESET
rts

View File

@ -138,9 +138,11 @@ TILEMAP_OFFSET = $9F
MARS_X = $A0
MARS_Y = $A1
INITIAL_SOUND = $A2
PLAY_END_SOUND = $A3
APPLEII_MODEL = $A4
MARS_TILEX = $A2
MARS_TILEY = $A3
INITIAL_SOUND = $A4
PLAY_END_SOUND = $A5
APPLEII_MODEL = $A6
WHICH_SLOT = $DA
JS_BUTTON_STATE = $DB