keen: more yorp movement

This commit is contained in:
Vince Weaver 2024-04-05 01:32:16 -04:00
parent fbe3c22f0e
commit 2fe318a13b
3 changed files with 191 additions and 7 deletions

View File

@ -205,5 +205,7 @@ level1_bg_zx02:
.include "level1_sfx.s"
.include "longer_sound.s"
.include "random16.s"
level1_data_zx02:
.incbin "maps/level1_map.zx02"

View File

@ -13,15 +13,15 @@ move_enemies_loop:
; only move if out
; only move every 4th frame
; only move every 4th frame to slow things down
lda FRAMEL
and #$3
bne ergh
bne move_enemy_frame_skip
lda enemy_data_out,X
bne enemy_is_out
ergh:
move_enemy_frame_skip:
jmp done_move_enemy
enemy_is_out:
@ -42,19 +42,75 @@ enemy_is_out:
load_foot1_smc:
lda tilemap,Y
cmp #ALLHARD_TILES
bcs no_enemy_fall ; if hard tile, don't fall
cmp #HARDTOP_TILES
bcs no_enemy_fall ; if hardtop tile, don't fall
inc enemy_data_tiley,X ; fall one tiles worth
no_enemy_fall:
no_enemy_fall:
;============================
; not falling, so do actions
;============================
; if walking, walk
; if searching, search
dec enemy_data_count,X
bne enemy_action
enemy_new_state:
jsr random16
lda SEEDL
and #$3
sta enemy_data_state,X
jsr random16
lda SEEDL
and #$f
clc
adc #4
sta enemy_data_count,X
enemy_action:
lda enemy_data_state,X
cmp #YORP_SEARCH
beq enemy_search
cmp #YORP_JUMP
beq enemy_jump
bne enemy_walk
enemy_search:
lda enemy_data_direction,X
eor #$FF
clc
adc #1
sta enemy_data_direction,X
; TODO: face keen when done
jmp done_move_enemy
enemy_jump:
; make sure we don't jump for too long
; hack
lda enemy_data_count,X
and #$3
sta enemy_data_count,X
; jump a bit
dec enemy_data_tiley,X
; fallthrough
;=======================================
; move sideways
; until you hit something
;=======================================
enemy_walk:
; check if moving right/left
lda enemy_data_direction,X
@ -308,6 +364,11 @@ enemy_explosion_sprite3:
.byte $A5,$A7
YORP = 0
YORP_WALK = 0
YORP_JUMP = 1
YORP_SEARCH = 2
LEFT = $FF
RIGHT = $1
@ -319,6 +380,8 @@ enemy_data_tilex: .byte 5, 19, 38, 45, 69, 81, 89, 92,100
enemy_data_tiley: .byte 6, 13, 4, 4, 13, 4, 4, 13,10
enemy_data_x: .byte 0, 0, 0, 0, 0, 0, 0, 0,0
enemy_data_y: .byte 0, 0, 0, 0, 0, 0, 0, 0,0
enemy_data_state: .byte 0, 0, 0, 0, 0, 0, 0, 0,0
enemy_data_count: .byte 8, 8, 8, 8, 8, 8, 8, 8,8
; question: when do they activate? When do they move when offscreen?

119
games/keen/random16.s Normal file
View File

@ -0,0 +1,119 @@
; 16-bit 6502 Random Number Generator (cycle-invariant version)
; Linear feedback shift register PRNG by White Flame
; http://codebase64.org/doku.php?id=base:small_fast_16-bit_prng
; The Apple II KEYIN routine increments SEEDL:SEEDH
; while waiting for keypress
;SEEDL = $4E
;SEEDH = $4F
XOR_MAGIC = $7657 ; "vW"
;=============================
; random16
;=============================
; takes:
; not 0, cs = 6(r16)+12(lnz)+5(nop)+ 19(deo) = 42
; not 0, cc = 6(r16)+14(lnz)+2(nop)+ 20(neo) = 42
; $0000 = 6(r16)+ 6(loz)+11nops+ 19(deo) = 42
; $8000 = 6(r16)+ 6(loz)+ 4(ceo) + 6nops+ 20(neo) = 42
; $XX00 cc = 6(r16)+ 6(loz)+4(ceo)+2(cep) +4nops+ 20(neo) = 42
; $XX00 cs = 6(r16)+ 6(loz)+4(ceo)+4(cep) +3nops+ 19(deo) = 42*
random16:
lda SEEDL ; 3
beq low_zero ; $0000 and $8000 are special values ; 3
;==========
; 6
lownz:
; -1
asl SEEDL ; Do a normal shift ; 5
lda SEEDH ; 3
rol ; 2
bcs five_cycle_do_eor ; 3
;===========
; 12
bcc two_cycle_no_eor ; 3
;==========
; 12+3-1 = 14
;===================================================================
eleven_cycle_do_eor:
nop ; 2
nop ; 2
nop ; 2
five_cycle_do_eor:
nop ; 2
three_cycle_do_eor:
sta SEEDH ; nop ; 3
do_eor:
; high byte is in A
eor #>XOR_MAGIC ; 2
sta SEEDH ; 3
lda SEEDL ; 3
eor #<XOR_MAGIC ; 2
sta SEEDL ; 3
eor_rts:
rts ; 6
;===========
; 19
;=========================================================================
six_cycles_no_eor:
nop ; 2
four_cycle_no_eor:
nop ; 2
two_cycle_no_eor:
nop ; 2
no_eor:
nop ; 2
nop ; 2
nop ; 2
nop ; 2
sta SEEDH ; 3
jmp eor_rts ; 3+6
;===========
; 20
;======================================================================
;======================================================================
low_zero:
lda SEEDH ; 3
beq eleven_cycle_do_eor ; High byte is also zero ; 3
; so apply the EOR
;============
; 6
ceo:
; -1
; wasn't zero, check for $8000
asl ; 2
beq six_cycles_no_eor ; if $00 is left after the shift; 3
; then it was $80
;===========
; 4
; else, do the EOR based on the carry
cep:
; -1
bcc four_cycle_no_eor ; 3
;============
; 2
bcs three_cycle_do_eor ; 2+3-1 = 4