ootw: start making the keyboard handler a common routine

This commit is contained in:
Vince Weaver 2019-01-18 22:27:01 -05:00
parent 181ab41c59
commit 01b0dd2024
6 changed files with 144 additions and 138 deletions

View File

@ -17,6 +17,7 @@ OOTW: ootw.o
ootw.o: ootw.s \
gr_copy.s gr_fast_clear.s gr_pageflip.s gr_unrle.s gr_putsprite.s \
keyboard.s \
ootw_pool.s ootw_cavern.s physicist.s random16.s slug_cutscene.s \
ootw_pool.inc ootw_cavern.inc ootw_quake.inc ootw_sprites.inc
ca65 -o ootw.o ootw.s -l ootw.lst

View File

@ -1,6 +1,7 @@
5 HOME
10 PRINT "OOTW PROOF-OF-CONCEPT V1.0 BY DEATER"
20 PRINT:PRINT
20 PRINT
25 PRINT " ,"
30 PRINT "ORIGINAL BY ERIC CHAHI"
40 PRINT "INSPIRED BY PAUL NICHOLAS PICO-8 VERSION"
50 PRINT

128
ootw/keyboard.s Normal file
View File

@ -0,0 +1,128 @@
;======================================
; handle keypress
;======================================
handle_keypress:
lda KEYPRESS ; 4
bmi keypress ; 3
rts ; nothing pressed, return
keypress:
; -1
and #$7f ; clear high bit
check_quit:
cmp #'Q'
beq quit
cmp #27
bne check_left
quit:
lda #$ff ; could just dec
sta GAME_OVER
rts
check_left:
cmp #'A'
beq left
cmp #$8 ; left arrow
bne check_right
left:
; walk left
lda #0
sta CROUCHING ; stanid crouching
lda DIRECTION ; if facing right, turn to face left
bne face_left
dec PHYSICIST_X ; walk left
lda PHYSICIST_X
cmp LEFT_LIMIT
bpl just_fine_left
too_far_left:
inc PHYSICIST_X
lda #1
sta GAME_OVER
just_fine_left:
inc GAIT ; cycle through animation
inc GAIT
jmp done_keypress ; done
face_left:
lda #0
sta DIRECTION
sta GAIT
jmp done_keypress
check_right:
cmp #'D'
beq right
cmp #$15
bne check_down
right:
lda #0
sta CROUCHING
lda DIRECTION
beq face_right
inc PHYSICIST_X
lda PHYSICIST_X
cmp RIGHT_LIMIT
bne just_fine_right
too_far_right:
lda #2
sta GAME_OVER
rts
just_fine_right:
inc GAIT
inc GAIT
jmp done_keypress
face_right:
lda #0
sta GAIT
lda #1
sta DIRECTION
jmp done_keypress
check_down:
cmp #'S'
beq down
cmp #$0A
bne check_space
down:
lda #48
sta CROUCHING
lda #0
sta GAIT
jmp done_keypress
check_space:
cmp #' '
beq space
cmp #$15
bne unknown
space:
lda #15
sta KICKING
lda #0
sta GAIT
unknown:
done_keypress:
bit KEYRESET ; clear the keyboard strobe ; 4
rts ; 6

View File

@ -126,6 +126,7 @@ end_message:
.include "gr_putsprite.s"
.include "gr_offsets.s"
.include "random16.s"
.include "keyboard.s"
.include "ootw_pool.inc"
.include "ootw_cavern.inc"
.include "ootw_quake.inc"

View File

@ -8,7 +8,6 @@ ootw_pool:
bit SET_GR
bit FULLGR
;=============
; disable earthquake
@ -16,21 +15,20 @@ ootw_pool:
sta EARTH_OFFSET
;===========================
; Clear both bottoms
; lda #$4
; sta DRAW_PAGE
; jsr clear_bottom
; lda #$0
; sta DRAW_PAGE
; jsr clear_bottom
; Setup pages (is this necessary?)
lda #0
sta DRAW_PAGE
lda #1
sta DISP_PAGE
;===========================
; Setup right/left exit paramaters
lda #37
sta RIGHT_LIMIT
lda #0
sta LEFT_LIMIT
;=============================
; Load background to $c00
@ -253,7 +251,7 @@ no_tentacle:
;===============================
; check keyboard
jsr handle_keypress_pool
jsr handle_keypress
;===============
@ -311,7 +309,7 @@ frame_no_oflo:
beq done_pool
; check if done this level
cmp #$1
cmp #$2
bne not_done_pool
lda #0
@ -327,125 +325,3 @@ not_done_pool:
done_pool:
rts
;======================================
; handle keypress (pool)
;======================================
handle_keypress_pool:
lda KEYPRESS ; 4
bmi keypress_pool ; 3
rts
keypress_pool:
; -1
and #$7f ; clear high bit
check_quit:
cmp #'Q'
beq quit
cmp #27
bne check_left
quit:
lda #$ff ; could just dec
sta GAME_OVER
rts
check_left:
cmp #'A'
beq left
cmp #$8 ; left arrow
bne check_right
left:
lda #0
sta CROUCHING
lda DIRECTION
bne face_left
dec PHYSICIST_X
bpl just_fine_left
too_far_left:
inc PHYSICIST_X
just_fine_left:
inc GAIT
inc GAIT
jmp done_keypress
face_left:
lda #0
sta DIRECTION
sta GAIT
jmp done_keypress
check_right:
cmp #'D'
beq right
cmp #$15
bne check_down
right:
lda #0
sta CROUCHING
lda DIRECTION
beq face_right
inc PHYSICIST_X
lda PHYSICIST_X
cmp #37
bne just_fine_right
too_far_right:
lda #1
sta GAME_OVER
rts
just_fine_right:
inc GAIT
inc GAIT
jmp done_keypress
face_right:
lda #0
sta GAIT
lda #1
sta DIRECTION
jmp done_keypress
check_down:
cmp #'S'
beq down
cmp #$0A
bne check_space
down:
lda #48
sta CROUCHING
lda #0
sta GAIT
jmp done_keypress
check_space:
cmp #' '
beq space
cmp #$15
bne unknown
space:
lda #15
sta KICKING
lda #0
sta GAIT
unknown:
done_keypress:
bit KEYRESET ; clear the keyboard strobe ; 4
no_keypress:
rts ; 6

View File

@ -129,9 +129,8 @@ CURSOR = $9D
; More zero-page addresses
; we try not to conflict with anything DOS, MONITOR or BASIC related
;COLOR1 = $E0
;COLOR2 = $E1
;MATCH = $E2
LEFT_LIMIT = $E0
RIGHT_LIMIT = $E1
WHICH_SLUG = $E2
XX = $E3
YY = $E4