98 lines
1.8 KiB
NASM
98 lines
1.8 KiB
NASM
/* Timer comparison / update
|
|
r1, r2: tick duration high, low [IN]
|
|
r3, r4: next tick high, low
|
|
r5, r6: tick after this one high, low
|
|
r7, r8: now high, low [IN]
|
|
r9: pointer
|
|
*/
|
|
add r9, zr, ptr.timer_ghost_next_tick_high
|
|
load_32 r3, [r9]
|
|
add r9, zr, ptr.timer_ghost_next_tick_low
|
|
load_32 r4, [r9]
|
|
|
|
cmp r7, r3
|
|
jb timer_ghost.end
|
|
ja timer_ghost.trigger
|
|
cmp r8, r4
|
|
jb timer_ghost.end
|
|
|
|
pub timer_ghost.trigger:
|
|
; udate next_tick
|
|
call u64.add
|
|
add r9, zr, ptr.timer_ghost_next_tick_high
|
|
store_32 [r9], r5
|
|
add r9, zr, ptr.timer_ghost_next_tick_low
|
|
store_32 [r9], r6
|
|
|
|
|
|
/* Movement
|
|
r1, r2: x, y
|
|
r3: sprite id
|
|
r4: direction
|
|
r5, r6: increments x, y
|
|
r7, r8: [RESERVED]
|
|
r9: pointer
|
|
r10: tile content
|
|
r13: tile address
|
|
*/
|
|
add r9, zr, ptr.state_ghost
|
|
load_8 r1, [r9]
|
|
add r9, r9, 1
|
|
load_8 r2, [r9]
|
|
add r9, r9, 1
|
|
load_8 r4, [r9]
|
|
|
|
call drawing.clear_tile
|
|
|
|
mov r5, 0
|
|
mov r6, 0
|
|
|
|
lsl r9, r4, 3 ; 2 * instruction size = 8
|
|
add r9, r9, timer_ghost.direction_jump_table
|
|
jmp r9
|
|
|
|
pub timer_ghost.direction_jump_table:
|
|
; direction_up
|
|
sub r6, r6, 1
|
|
jmp timer_ghost.move
|
|
; direction_right
|
|
add r5, r5, 1
|
|
jmp timer_ghost.move
|
|
; direction_down
|
|
add r6, r6, 1
|
|
jmp timer_ghost.move
|
|
; direction_left
|
|
sub r5, r5, 1
|
|
;jmp timer_ghost.move
|
|
|
|
pub timer_ghost.move:
|
|
add r1, r1, r5
|
|
add r2, r2, r6
|
|
add r9, zr, ptr.state_ghost
|
|
store_8 [r9], r1
|
|
add r9, r9, 1
|
|
store_8 [r9], r2
|
|
|
|
; draw ghost on new position
|
|
add r3, r4, sprites.ghost
|
|
call drawing.draw_sprite_at_map_coord
|
|
|
|
/*
|
|
Check ahead for direction change
|
|
*/
|
|
add r1, r1, r5
|
|
add r2, r2, r6
|
|
call game.get_tile_address_from_map_coord
|
|
|
|
load_8 r10, [r13]
|
|
cmp r10, map.tiles.wall
|
|
jne timer_ghost.end
|
|
; increment direction
|
|
add r9, zr, ptr.state_ghost
|
|
add r9, r9, 2
|
|
load_8 r4, [r9]
|
|
add r4, r4, 1
|
|
and r4, r4, 0b11 ; modulo 3
|
|
store_8 [r9], r4
|
|
|
|
pub timer_ghost.end: |