dos33fsprogs/games/keen/mars.s

694 lines
11 KiB
ArmAsm
Raw Normal View History

2024-03-11 05:37:08 +00:00
; Keen MARS main map
;
2024-03-11 05:37:08 +00:00
; by deater (Vince Weaver) <vince@deater.net>
; Zero Page
.include "zp.inc"
.include "hardware.inc"
.include "common_defines.inc"
; or are there?
2024-04-19 05:30:17 +00:00
;NUM_ENEMIES = 0
TILE_COLS = 20 ; define this elsewhere?
2024-03-30 05:28:34 +00:00
mars_start:
2024-03-11 05:37:08 +00:00
;===================
; init screen
2024-04-14 05:40:45 +00:00
2024-03-11 05:37:08 +00:00
bit KEYRESET
bit SET_GR
2024-03-16 05:28:25 +00:00
bit PAGE1
2024-03-11 05:37:08 +00:00
bit LORES
bit FULLGR
2024-04-14 05:40:45 +00:00
lda #0 ; clear screens
2024-04-13 15:16:43 +00:00
sta clear_all_color+1
2024-04-14 05:40:45 +00:00
jsr clear_all
2024-03-11 05:37:08 +00:00
2024-04-14 05:40:45 +00:00
lda KEENS ; check if out of lives
bpl plenty_of_keens
2024-04-14 05:40:45 +00:00
jmp return_to_title ; if none, game over
plenty_of_keens:
2024-03-30 05:28:34 +00:00
2024-03-11 05:37:08 +00:00
;=====================
; init vars
;=====================
lda #0
sta FRAMEL
sta FRAMEH
2024-03-11 05:37:08 +00:00
lda #4
sta DRAW_PAGE
2024-04-13 15:16:43 +00:00
; see if returning and if game over
2024-04-06 03:56:13 +00:00
lda LEVEL_OVER
cmp #GAME_OVER
2024-04-13 15:16:43 +00:00
bne not_game_over
jmp return_to_title
not_game_over:
2024-03-11 05:37:08 +00:00
;====================================
; load mars tilemap
2024-03-11 05:37:08 +00:00
;====================================
lda #<mars_data_zx02
2024-03-11 05:37:08 +00:00
sta ZX0_src
lda #>mars_data_zx02
2024-03-11 05:37:08 +00:00
sta ZX0_src+1
lda #$90 ; load to page $9000
jsr full_decomp
;====================================
; copy in tilemap subset
;====================================
2024-04-14 05:40:45 +00:00
2024-04-14 22:43:51 +00:00
; first center map around current location
2024-04-14 22:43:51 +00:00
jsr recenter_map
2024-04-14 05:40:45 +00:00
; copy mini tileset
2024-03-11 05:37:08 +00:00
jsr copy_tilemap_subset
2024-04-13 15:16:43 +00:00
2024-03-11 05:37:08 +00:00
; snapshot current tileset for fade purposes
2024-03-11 05:37:08 +00:00
jsr snapshot_tilemap
2024-04-04 04:36:15 +00:00
2024-04-04 05:27:11 +00:00
jsr fade_in
2024-03-11 05:37:08 +00:00
2024-04-06 03:56:13 +00:00
lda #0
sta LEVEL_OVER
2024-03-11 05:37:08 +00:00
;====================================
;====================================
; Main loop
;====================================
;====================================
mars_loop:
; draw tilemap
2024-03-11 05:37:08 +00:00
jsr draw_tilemap
2024-03-11 05:37:08 +00:00
; draw keen
jsr draw_keen
jsr page_flip
jsr handle_keypress
; jsr move_keen
;========================
; increment frame count
;========================
inc FRAMEL
bne no_frame_oflo
inc FRAMEH
no_frame_oflo:
2024-04-13 16:13:36 +00:00
; rotate star colors
; lda FRAMEL
; lsr
; lsr
; lsr
; and #$7
; tay
; lda star_colors,Y
; sta $F28 ; 0,28
2024-03-12 06:20:36 +00:00
2024-03-11 05:37:08 +00:00
;===========================
; check end of level
;===========================
lda LEVEL_OVER
2024-04-04 04:36:15 +00:00
bne done_with_keen
2024-03-11 05:37:08 +00:00
do_mars_loop:
2024-04-04 04:36:15 +00:00
;=====================
; sound effect
;=====================
2024-03-11 05:37:08 +00:00
2024-04-04 04:36:15 +00:00
lda INITIAL_SOUND
beq skip_initial_sound
2024-03-11 05:37:08 +00:00
2024-04-04 04:36:15 +00:00
ldy #SFX_KEENSLEFT
jsr play_sfx
dec INITIAL_SOUND
2024-03-11 05:37:08 +00:00
2024-04-04 04:36:15 +00:00
skip_initial_sound:
2024-03-11 05:37:08 +00:00
; delay
; lda #200
; jsr WAIT
jmp mars_loop
2024-03-11 05:37:08 +00:00
done_with_keen:
2024-03-30 05:28:34 +00:00
cmp #GAME_OVER
beq return_to_title
; else, start level
2024-03-11 05:37:08 +00:00
bit KEYRESET ; clear keypress
; sound effect
2024-04-04 04:36:15 +00:00
ldy #SFX_WLDENTRSND
jsr play_sfx
2024-03-11 05:37:08 +00:00
jsr snapshot_tilemap
2024-04-04 05:27:11 +00:00
jsr fade_out
; set up proper level to load
clc
lda CURRENT_LEVEL
adc #2 ; skip title and mars
2024-03-11 05:37:08 +00:00
sta WHICH_LOAD
rts ; exit back
2024-03-30 05:28:34 +00:00
return_to_title:
jsr game_over
2024-04-06 03:56:13 +00:00
; ldy #SFX_GAMEOVERSND
; jsr play_sfx
2024-03-30 05:28:34 +00:00
lda #LOAD_TITLE
sta WHICH_LOAD
rts
2024-03-11 05:37:08 +00:00
;=========================
; draw keen
;=========================
draw_keen:
2024-03-11 05:37:08 +00:00
sec
lda MARS_TILEX
sbc TILEMAP_X
asl
2024-03-12 04:58:15 +00:00
clc
adc MARS_X
sta XPOS
2024-03-12 04:58:15 +00:00
sec
lda MARS_TILEY
sbc TILEMAP_Y
asl
asl
2024-03-11 05:37:08 +00:00
clc
adc MARS_Y
sta YPOS
2024-03-12 04:58:15 +00:00
ldx #<keen_sprite_tiny
lda #>keen_sprite_tiny
stx INL
sta INH
jsr put_sprite_crop
2024-03-12 04:58:15 +00:00
rts ; tail call
2024-03-12 04:58:15 +00:00
draw_keen_even:
2024-03-30 04:55:12 +00:00
lda MARS_Y
2024-03-12 04:58:15 +00:00
; and #$FE ; no need to mask, know bottom bit is 0
tay
lda gr_offsets,Y
sta OUTL
lda gr_offsets+1,Y
clc
adc DRAW_PAGE
sta OUTH
2024-03-30 04:55:12 +00:00
ldy MARS_X ; adjust with Xpos
2024-03-12 04:58:15 +00:00
2024-03-11 05:37:08 +00:00
lda #$3D
sta (OUTL),Y
2024-03-30 04:55:12 +00:00
lda MARS_Y
2024-03-12 04:58:15 +00:00
clc
adc #2
; and #$FE ; no need to mask
tay
lda gr_offsets,Y
sta OUTL
lda gr_offsets+1,Y
clc
adc DRAW_PAGE
sta OUTH
2024-03-30 04:55:12 +00:00
ldy MARS_X ; adjust with Xpos
2024-03-12 04:58:15 +00:00
lda (OUTL),Y
and #$F0
ora #$02
sta (OUTL),Y
2024-03-11 05:37:08 +00:00
rts
;=================================
;=================================
; check valid feet
;=================================
;=================================
2024-03-12 04:58:15 +00:00
; essentially if SCRN(Y,X+2)=9
check_valid_feet:
2024-03-12 05:02:44 +00:00
txa
ror
bcc feet_mask_odd
feet_mask_even:
lda #$F0
bne feet_mask_done ; bra
feet_mask_odd:
lda #$0F
feet_mask_done:
sta feet_mask_smc+1
2024-03-12 04:58:15 +00:00
txa
clc
adc #2
and #$FE
tax
lda gr_offsets,X
sta OUTL
lda gr_offsets+1,X
clc
adc #$8 ; into $C00 page (bg lives here)
sta OUTH
lda (OUTL),Y
2024-03-12 05:02:44 +00:00
eor #$99
feet_mask_smc:
2024-03-12 04:58:15 +00:00
and #$F0
beq feet_valid
bne feet_invalid
feet_valid:
sec
rts
feet_invalid:
; clc
sec
2024-03-12 04:58:15 +00:00
rts
;====================================
2024-03-12 06:09:15 +00:00
;====================================
; show parts screen
;====================================
;====================================
; TODO: color in if found
2024-03-12 06:09:15 +00:00
do_parts:
lda #<parts_zx02
sta ZX0_src
lda #>parts_zx02
sta ZX0_src+1
lda #$c ; load to page $c00
jsr full_decomp
jsr gr_copy_to_current
jsr page_flip
bit TEXTGR
bit KEYRESET
parts_loop:
lda KEYPRESS
bpl parts_loop
done_parts:
bit KEYRESET
bit FULLGR
rts
;===============================
;===============================
; snapshot tile map
;===============================
;===============================
; copy current tilemap graphics
; to $c00 for fade-in/fade-out
snapshot_tilemap:
; make a copy in $c00 for fade-in purposes
lda DRAW_PAGE ; necssary
pha
lda #8
sta DRAW_PAGE
jsr draw_tilemap
pla
sta DRAW_PAGE
lda #1
sta INITIAL_SOUND
rts
;====================================
;====================================
2024-04-13 16:13:36 +00:00
; Mars action (enter pressed on map)
;====================================
;====================================
; if enter pressed on map
2024-04-13 16:13:36 +00:00
; off by one so the levels can fit in a two byte bitmap
;
; location tilex,tiley size
; 0 level1 (Border Town) 19,37 2
; 1 level2 (First Shrine) 22,28 1
; 2 level3 (Treasury) 9,21 2
; 3 level4 (Capital City) 22,23 2
; 4 level5 (Pogo Shrine) 13,16 1
; 5 level6 (Second Shrine) 16,11 1
; 6 level7 (Emerald City) 25,8 2
; 7 level8 (Ice City) 38,3 2
; 8 level9 (Third Shrine) 36,13 1
; 9 level10 (Ice Shrine 1) 43,5 1
; 10 level11 (Fourth Shrine) 52,16 1
; 11 level12 (Fifth Shrine) 36,21 1
; 12 level13 (Red Maze City) 44,24 2
; 13 level14 (Secret City) 60,28 2
; 14 level15 (Ice Shrine 2) 38,60 1
; 15 level16 (Vorticon Castle) 29,59 2
; 16 spaceship 10,37 1
; 17 left transporter 26,4 1
; 18 right transporter 34,3 1
; 19 secret transporter 60,35 1
NUM_LOCATIONS = 20
2024-03-12 06:09:15 +00:00
do_action:
2024-04-14 22:43:51 +00:00
ldx #(NUM_LOCATIONS-1)
2024-03-12 06:09:15 +00:00
2024-04-13 16:13:36 +00:00
do_action_loop:
2024-03-12 06:09:15 +00:00
2024-04-13 16:13:36 +00:00
; mtx-ltx
; -1 0 1 2
; 1234 1234 1234 1234
; XYY XY YX YYX
; YY YY YY YY
2024-03-12 06:09:15 +00:00
2024-04-13 16:13:36 +00:00
check_location_x:
sec
lda MARS_TILEX
sbc location_x,X
bmi check_location_nomatch
2024-03-12 06:09:15 +00:00
2024-04-13 16:13:36 +00:00
cmp location_size,X
bcs check_location_nomatch
2024-03-12 06:09:15 +00:00
2024-04-13 16:13:36 +00:00
check_location_y:
2024-03-12 06:09:15 +00:00
2024-04-13 16:13:36 +00:00
; mty-lty
; -2 -1 0 1 2
; 0 X
; 1 X X
; 2 YY YX YX YY YY
; 3 YY YY YX YX YY
; 4 X X
; 5 X
clc
lda MARS_TILEY
adc #1
sec
sbc location_y,X
bmi check_location_nomatch
cmp location_size,X
bcc check_location_match
2024-03-12 06:09:15 +00:00
2024-04-13 16:13:36 +00:00
; bcs check_location_nomatch
2024-03-12 06:09:15 +00:00
2024-04-13 16:13:36 +00:00
check_location_nomatch:
dex
bpl do_action_loop
2024-03-12 06:09:15 +00:00
rts
2024-03-12 06:20:36 +00:00
2024-04-13 16:13:36 +00:00
check_location_match:
; jump table
lda location_actions_high,X
pha
lda location_actions_low,X
pha
rts ; jump
;=====================================
;=====================================
; placeholder until action imlpemented
;=====================================
;=====================================
dummy_action:
rts
;=====================================
;=====================================
; enter level
;=====================================
;=====================================
; level number is in X
; FIXME: make sure level is not completed
enter_level:
2024-04-13 16:13:36 +00:00
stx CURRENT_LEVEL
2024-04-13 16:13:36 +00:00
inc LEVEL_OVER
2024-04-13 16:13:36 +00:00
rts
2024-03-12 06:20:36 +00:00
2024-04-14 22:43:51 +00:00
;=====================================
;=====================================
; transport_to_right
;=====================================
;=====================================
transport_right:
lda #34
sta MARS_TILEX
lda #3
transport_common:
2024-04-14 22:43:51 +00:00
sta MARS_TILEY
ldy #SFX_TELEPORTSND
jsr play_sfx
jsr recenter_map
2024-04-14 22:43:51 +00:00
jsr copy_tilemap_subset
rts
;=====================================
;=====================================
; transport_to_left
;=====================================
;=====================================
transport_left:
lda #26
sta MARS_TILEX
lda #4
bne transport_common ; bra
2024-04-14 22:43:51 +00:00
;=====================================
;=====================================
; transport_to_secret
;=====================================
;=====================================
transport_secret:
; TODO: verify we are transporting back to the right place
lda #44
sta MARS_TILEX
lda #24
bne transport_common ; bra
2024-04-14 22:43:51 +00:00
;=====================================
; recenter map around current location
;=====================================
; center around MARS_TILEX, MARS_TILEY
recenter_map:
lda #0 ; default at 0,0
sta TILEMAP_X
sta TILEMAP_Y
lda MARS_TILEX
cmp #10
bcc mars_tilex_fine ; if MARS_TILEX < 10, leave tilemap 0
sec ; otherwise tilemap=mars_tilex-10
2024-04-14 22:43:51 +00:00
sbc #10
sta TILEMAP_X
mars_tilex_fine:
lda MARS_TILEY
cmp #6
bcc mars_tiley_fine ; if MARS_TILEY < 6 leave tilemap 0
sec ; otherwise tilemap_y=mars_tiley-6
2024-04-14 22:43:51 +00:00
sbc #6
sta TILEMAP_Y
mars_tiley_fine:
rts
2024-04-13 16:13:36 +00:00
location_x:
.byte 19,22, 9,22,13,16,25,38
.byte 36,43,52,36,44,60,38,29
.byte 10,26,34,60
location_y:
.byte 37,28,21,23,16,11, 8, 3
.byte 13, 5,16,21,24,28,60,59
.byte 37, 4, 3,35
location_size:
.byte 2,1,2,2,1,1,2,2
.byte 1,1,1,1,2,2,1,2
.byte 1,1,1,1
location_actions_low:
2024-04-15 02:44:38 +00:00
.byte <(enter_level-1),<(enter_level-1) ; level1, level2
2024-04-19 05:41:52 +00:00
.byte <(enter_level-1),<(dummy_action-1) ; level3, level4
2024-04-13 16:13:36 +00:00
.byte <(dummy_action-1),<(dummy_action-1)
.byte <(dummy_action-1),<(dummy_action-1)
.byte <(dummy_action-1),<(dummy_action-1)
.byte <(dummy_action-1),<(dummy_action-1)
.byte <(dummy_action-1),<(dummy_action-1)
.byte <(dummy_action-1),<(dummy_action-1)
2024-04-14 22:43:51 +00:00
.byte <(do_parts-1),<(transport_right-1) ; ship, l transport
.byte <(transport_left-1),<(transport_secret-1) ; r trans, secret
2024-04-13 16:13:36 +00:00
location_actions_high:
2024-04-15 02:44:38 +00:00
.byte >(enter_level-1),>(enter_level-1) ; level1, level2
2024-04-19 05:41:52 +00:00
.byte >(enter_level-1),>(dummy_action-1) ; level3, level4
2024-04-13 16:13:36 +00:00
.byte >(dummy_action-1),>(dummy_action-1)
.byte >(dummy_action-1),>(dummy_action-1)
.byte >(dummy_action-1),>(dummy_action-1)
.byte >(dummy_action-1),>(dummy_action-1)
.byte >(dummy_action-1),>(dummy_action-1)
.byte >(dummy_action-1),>(dummy_action-1)
2024-04-14 22:43:51 +00:00
.byte >(do_parts-1),>(transport_right-1) ; ship, l transport
.byte >(transport_left-1),>(transport_secret-1) ; r trans, secret
2024-04-13 16:13:36 +00:00
;star_colors:
; .byte $05,$07,$07,$0f
; .byte $0f,$07,$05,$0a
;==========================
; includes
;==========================
; level graphics
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"
.include "tilemap_lookup.s"
mars_data_zx02:
.incbin "maps/mars_map.zx02"
; dummy
enemy_data_out:
enemy_data_tilex:
keen_sprite_tiny:
.byte 1,2
.byte $DA
.byte $23