Compare commits
5 Commits
v0.2.0
...
res-0-prer
| Author | SHA1 | Date | |
|---|---|---|---|
| dc42d7c5b6 | |||
| c88f67559d | |||
| 2344a2e874 | |||
| 54ba73c177 | |||
| d5e9dde21d |
BIN
assets/screen.ppm
Normal file
BIN
assets/screen.ppm
Normal file
Binary file not shown.
4
build.ts
4
build.ts
@@ -15,9 +15,6 @@ const mapPath = "assets/map.ppm";
|
||||
const spritesPath = {
|
||||
"sprite_empty": "assets/sprites/empty.ppm",
|
||||
"sprite_unimplemented": "assets/sprites/placeholder.ppm",
|
||||
"sprite_wall_end": "assets/sprites/wall_end.ppm",
|
||||
"sprite_wall_straight": "assets/sprites/wall_straight.ppm",
|
||||
"sprite_wall_corner": "assets/sprites/wall_corner.ppm",
|
||||
"sprite_robot_up": "assets/sprites/robot_up.ppm",
|
||||
"sprite_robot_right": "assets/sprites/robot_right.ppm",
|
||||
"sprite_robot_down": "assets/sprites/robot_down.ppm",
|
||||
@@ -27,6 +24,7 @@ const spritesPath = {
|
||||
"sprite_ghost_down": "assets/sprites/ghost_down.ppm",
|
||||
"sprite_ghost_left": "assets/sprites/ghost_left.ppm",
|
||||
"sprite_coin": "assets/sprites/coin.ppm",
|
||||
"screen": "assets/screen.ppm",
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,21 +9,18 @@ pub const sprites.rotation_270 = 3
|
||||
|
||||
pub const sprites.empty = 0 ; must stay 0 (some code avoid addition when it knows the tile is empty)
|
||||
pub const sprites.unimplemented = 1
|
||||
pub const sprites.wall_end = 2
|
||||
pub const sprites.wall_straight = 3
|
||||
pub const sprites.wall_corner = 4
|
||||
|
||||
pub const sprites.robot = 5
|
||||
pub const sprites.robot_up = 5
|
||||
pub const sprites.robot_right = 6
|
||||
pub const sprites.robot_down = 7
|
||||
pub const sprites.robot_left = 8
|
||||
pub const sprites.robot = 2
|
||||
pub const sprites.robot_up = 2
|
||||
pub const sprites.robot_right = 3
|
||||
pub const sprites.robot_down = 4
|
||||
pub const sprites.robot_left = 5
|
||||
|
||||
pub const sprites.ghost = 9
|
||||
pub const sprites.ghost_up = 9
|
||||
pub const sprites.ghost_right = 10
|
||||
pub const sprites.ghost_down = 11
|
||||
pub const sprites.ghost_left = 12
|
||||
pub const sprites.ghost = 6
|
||||
pub const sprites.ghost_up = 6
|
||||
pub const sprites.ghost_right = 7
|
||||
pub const sprites.ghost_down = 8
|
||||
pub const sprites.ghost_left = 9
|
||||
|
||||
pub const sprites.coin = 13
|
||||
pub const sprites.max = 13 ; for lookup table
|
||||
pub const sprites.coin = 10
|
||||
pub const sprites.max = 10 ; for lookup table
|
||||
@@ -1,46 +1,3 @@
|
||||
/* Draw the whole map (fill the screen memory with the values of the sprites based on the map)
|
||||
|
||||
Locals:
|
||||
r1: x map coord
|
||||
r2: y map coord
|
||||
r3: sprite rotation
|
||||
r4: sprite id
|
||||
r12: rotation (returned by `sprite and rotation`)
|
||||
r13: sprite (returned by `get_sprite_id_and_rotation`)
|
||||
*/
|
||||
pub drawing.draw_whole_map:
|
||||
push r1
|
||||
push r2
|
||||
push r3
|
||||
push r4
|
||||
push r12
|
||||
push r13
|
||||
|
||||
mov r1, 0
|
||||
mov r2, 0
|
||||
|
||||
draw_whole_map_loop:
|
||||
call sprite_rotation.get_sprite_id_and_rotation
|
||||
mov r3, r12
|
||||
mov r4, r13
|
||||
call drawing.draw_sprite_at_map_coord
|
||||
add r1, r1, 1
|
||||
cmp r1, map.width
|
||||
jne draw_whole_map_loop
|
||||
mov r1, 0
|
||||
add r2, r2, 1
|
||||
cmp r2, map.height
|
||||
jne draw_whole_map_loop
|
||||
|
||||
pop r13
|
||||
pop r12
|
||||
pop r4
|
||||
pop r3
|
||||
pop r2
|
||||
pop r1
|
||||
|
||||
ret
|
||||
|
||||
/* Draw the tile corresponding to the given coordinate with it's map content
|
||||
|
||||
Inputs:
|
||||
@@ -118,7 +75,7 @@ get_tile_address:
|
||||
cmp r3, sprites.height
|
||||
jne get_tile_address_offset_per_row_loop
|
||||
|
||||
add r13, zr, ptr.screen
|
||||
add r13, zr, screen
|
||||
|
||||
mov r3, 0
|
||||
get_tile_address_margin_top_loop:
|
||||
@@ -186,8 +143,7 @@ get_sprite_address:
|
||||
Inputs:
|
||||
r1: map x coord
|
||||
r2: map y coord
|
||||
r3: sprite rotation
|
||||
r4: sprite id
|
||||
r3: sprite id
|
||||
|
||||
Locals:
|
||||
r1: screen address
|
||||
@@ -198,42 +154,36 @@ pub drawing.draw_sprite_at_map_coord:
|
||||
push r1
|
||||
push r2
|
||||
push r3
|
||||
push r4
|
||||
push r13
|
||||
|
||||
call get_tile_address
|
||||
mov r1, r13
|
||||
push r1
|
||||
push r13
|
||||
|
||||
mov r1, r4
|
||||
mov r1, r3
|
||||
call get_sprite_address
|
||||
mov r2, r13
|
||||
pop r1
|
||||
|
||||
mov r2, r13
|
||||
pop r13
|
||||
mov r1, r13
|
||||
call draw_sprite
|
||||
|
||||
pop r13
|
||||
pop r4
|
||||
pop r3
|
||||
pop r2
|
||||
pop r1
|
||||
ret
|
||||
|
||||
/* Draw given sprite (by address) at given screen position (by address) with given rotation
|
||||
|
||||
Inputs:
|
||||
r1: screen address
|
||||
r2: sprite address
|
||||
r3: rotation
|
||||
|
||||
Locals:
|
||||
r1: current screen pixel address
|
||||
r4: x
|
||||
r5: y
|
||||
r6: current sprite pixel address
|
||||
r7: color
|
||||
r8: x increment
|
||||
r9: y increment
|
||||
r2: current sprite pixel address
|
||||
r3: x
|
||||
r4: color
|
||||
r5: sprite last pixel address + 1
|
||||
*/
|
||||
draw_sprite:
|
||||
push r1
|
||||
@@ -241,67 +191,25 @@ draw_sprite:
|
||||
push r3
|
||||
push r4
|
||||
push r5
|
||||
push r6
|
||||
push r7
|
||||
push r8
|
||||
push r9
|
||||
|
||||
mov r6, r2
|
||||
|
||||
; rotation
|
||||
draw_sprite_cmp_rotation_0:
|
||||
cmp r3, sprites.rotation_0
|
||||
jne draw_sprite_cmp_rotation_90
|
||||
mov r8, 1
|
||||
mov r9, 0
|
||||
jmp draw_sprite_loop_init
|
||||
draw_sprite_cmp_rotation_90:
|
||||
cmp r3, sprites.rotation_90
|
||||
jne draw_sprite_cmp_rotation_180
|
||||
add r6, r6, sprites.size
|
||||
sub r6, r6, sprites.width
|
||||
sub r8, zr, sprites.width
|
||||
mov r9, sprites.size
|
||||
add r9, r9, 1
|
||||
jmp draw_sprite_loop_init
|
||||
draw_sprite_cmp_rotation_180:
|
||||
cmp r3, sprites.rotation_180
|
||||
jne draw_sprite_cmp_rotation_270
|
||||
add r6, r6, sprites.size
|
||||
sub r6, r6, 1
|
||||
sub r8, zr, 1
|
||||
mov r9, 0
|
||||
jmp draw_sprite_loop_init
|
||||
draw_sprite_cmp_rotation_270:
|
||||
add r6, r6, sprites.width
|
||||
sub r6, r6, 1
|
||||
mov r8, sprites.width
|
||||
sub r9, zr, sprites.size
|
||||
sub r9, r9, 1
|
||||
|
||||
draw_sprite_loop_init:
|
||||
mov r4, 0
|
||||
mov r5, 0
|
||||
add r5, r2, sprites.size
|
||||
|
||||
mov r3, 0
|
||||
draw_sprite_loop:
|
||||
load_8 r7, [r6]
|
||||
store_8 [r1], r7
|
||||
add r4, r4, 1
|
||||
load_8 r4, [r2]
|
||||
store_8 [r1], r4
|
||||
|
||||
add r1, r1, 1
|
||||
add r6, r6, r8
|
||||
cmp r4, sprites.width
|
||||
add r2, r2, 1
|
||||
add r3, r3, 1
|
||||
cmp r3, sprites.width
|
||||
jne draw_sprite_loop
|
||||
mov r4, 0
|
||||
add r6, r6, r9
|
||||
mov r3, 0
|
||||
add r1, r1, screen.width
|
||||
sub r1, r1, sprites.width
|
||||
add r5, r5, 1
|
||||
cmp r5, sprites.width
|
||||
cmp r5, r2
|
||||
jne draw_sprite_loop
|
||||
|
||||
pop r9
|
||||
pop r8
|
||||
pop r7
|
||||
pop r6
|
||||
pop r5
|
||||
pop r4
|
||||
pop r3
|
||||
|
||||
@@ -1,167 +0,0 @@
|
||||
/* Return the sprite id and rotation for the given map coordinates
|
||||
|
||||
Inputs:
|
||||
r1: x map coord
|
||||
r2: y map coord
|
||||
|
||||
Outputs:
|
||||
r12: sprite rotation
|
||||
r13: sprite id
|
||||
|
||||
Locals:
|
||||
r3: tile id
|
||||
r4: map offset
|
||||
r5: counter
|
||||
r6: left tile id
|
||||
r7: up tile id
|
||||
r8: right tile id
|
||||
r9: down tile id
|
||||
*/
|
||||
pub sprite_rotation.get_sprite_id_and_rotation:
|
||||
push r1
|
||||
push r2
|
||||
push r3
|
||||
push r4
|
||||
push r5
|
||||
push r6
|
||||
push r7
|
||||
push r8
|
||||
push r9
|
||||
|
||||
add r4, r1, map
|
||||
mov r5, 0
|
||||
get_sprite_id_and_rotation_map_row_loop:
|
||||
cmp r5, r2
|
||||
je get_sprite_id_and_rotation_map_row_loop_end
|
||||
add r4, r4, map.width
|
||||
add r5, r5, 1
|
||||
jmp get_sprite_id_and_rotation_map_row_loop
|
||||
get_sprite_id_and_rotation_map_row_loop_end:
|
||||
|
||||
mov r12, sprites.rotation_0 ; default rotation
|
||||
|
||||
load_8 r3, [r4]
|
||||
lsl r3, r3, 3 ; 2*instruction_size = *8 = <<3
|
||||
add r3, r3, get_sprite_id_and_rotation_jump_table
|
||||
jmp r3
|
||||
|
||||
get_sprite_id_and_rotation_jump_table:
|
||||
; tile_empty
|
||||
mov r13, sprites.empty
|
||||
jmp get_sprite_id_and_rotation_return
|
||||
; tiles_wall
|
||||
jmp get_sprite_id_and_rotation_wall
|
||||
nop
|
||||
; tile_coin
|
||||
mov r13, sprites.coin
|
||||
jmp get_sprite_id_and_rotation_return
|
||||
|
||||
get_sprite_id_and_rotation_wall:
|
||||
mov r6, 0
|
||||
mov r7, 0
|
||||
mov r8, 0
|
||||
mov r9, 0
|
||||
|
||||
get_sprite_id_and_rotation_cmp_left:
|
||||
cmp r1, 0
|
||||
je get_sprite_id_and_rotation_cmp_up
|
||||
sub r4, r4, 1
|
||||
load_8 r6, [r4]
|
||||
add r4, r4, 1
|
||||
get_sprite_id_and_rotation_cmp_up:
|
||||
cmp r2, 0
|
||||
je get_sprite_id_and_rotation_cmp_right
|
||||
sub r4, r4, map.width
|
||||
load_8 r7, [r4]
|
||||
add r4, r4, map.width
|
||||
get_sprite_id_and_rotation_cmp_right:
|
||||
cmp r1, map.max_x
|
||||
je get_sprite_id_and_rotation_cmp_down
|
||||
add r4, r4, 1
|
||||
load_8 r8, [r4]
|
||||
sub r4, r4, 1
|
||||
get_sprite_id_and_rotation_cmp_down:
|
||||
cmp r2, map.max_y
|
||||
je get_sprite_id_and_rotation_check_connections
|
||||
add r4, r4, map.width
|
||||
load_8 r9, [r4]
|
||||
sub r4, r4, map.width
|
||||
|
||||
get_sprite_id_and_rotation_check_connections:
|
||||
get_sprite_id_and_rotation_straight_0:
|
||||
cmp r7, map.tiles.wall
|
||||
jne get_sprite_id_and_rotation_straight_90
|
||||
cmp r9, map.tiles.wall
|
||||
jne get_sprite_id_and_rotation_straight_90
|
||||
mov r12, sprites.rotation_0
|
||||
mov r13, sprites.wall_straight
|
||||
jmp get_sprite_id_and_rotation_return
|
||||
get_sprite_id_and_rotation_straight_90:
|
||||
cmp r6, map.tiles.wall
|
||||
jne get_sprite_id_and_rotation_corner_0
|
||||
cmp r8, map.tiles.wall
|
||||
jne get_sprite_id_and_rotation_corner_0
|
||||
mov r12, sprites.rotation_90
|
||||
mov r13, sprites.wall_straight
|
||||
jmp get_sprite_id_and_rotation_return
|
||||
|
||||
get_sprite_id_and_rotation_corner_0:
|
||||
cmp r6, map.tiles.wall
|
||||
jne get_sprite_id_and_rotation_corner_180
|
||||
cmp r9, map.tiles.wall
|
||||
jne get_sprite_id_and_rotation_corner_90
|
||||
mov r12,sprites.rotation_0
|
||||
mov r13, sprites.wall_corner
|
||||
jmp get_sprite_id_and_rotation_return
|
||||
get_sprite_id_and_rotation_corner_90:
|
||||
cmp r7, map.tiles.wall
|
||||
jne get_sprite_id_and_rotation_end_90
|
||||
mov r12,sprites.rotation_90
|
||||
mov r13, sprites.wall_corner
|
||||
jmp get_sprite_id_and_rotation_return
|
||||
get_sprite_id_and_rotation_corner_180:
|
||||
cmp r8, map.tiles.wall
|
||||
jne get_sprite_id_and_rotation_end_0
|
||||
cmp r7, map.tiles.wall
|
||||
jne get_sprite_id_and_rotation_corner_270
|
||||
mov r12,sprites.rotation_180
|
||||
mov r13, sprites.wall_corner
|
||||
jmp get_sprite_id_and_rotation_return
|
||||
get_sprite_id_and_rotation_corner_270:
|
||||
cmp r9, map.tiles.wall
|
||||
jne get_sprite_id_and_rotation_end_270
|
||||
mov r12,sprites.rotation_270
|
||||
mov r13, sprites.wall_corner
|
||||
jmp get_sprite_id_and_rotation_return
|
||||
|
||||
get_sprite_id_and_rotation_end_0:
|
||||
cmp r9, map.tiles.wall
|
||||
jne get_sprite_id_and_rotation_end_180
|
||||
mov r12,sprites.rotation_0
|
||||
mov r13, sprites.wall_end
|
||||
jmp get_sprite_id_and_rotation_return
|
||||
get_sprite_id_and_rotation_end_90:
|
||||
mov r12,sprites.rotation_90
|
||||
mov r13, sprites.wall_end
|
||||
jmp get_sprite_id_and_rotation_return
|
||||
get_sprite_id_and_rotation_end_180:
|
||||
mov r12,sprites.rotation_180
|
||||
mov r13, sprites.wall_end
|
||||
jmp get_sprite_id_and_rotation_return
|
||||
get_sprite_id_and_rotation_end_270:
|
||||
mov r12,sprites.rotation_270
|
||||
mov r13, sprites.wall_end
|
||||
;jmp get_sprite_id_and_rotation_return
|
||||
|
||||
get_sprite_id_and_rotation_return:
|
||||
pop r9
|
||||
pop r8
|
||||
pop r7
|
||||
pop r6
|
||||
pop r5
|
||||
pop r4
|
||||
pop r3
|
||||
pop r2
|
||||
pop r1
|
||||
|
||||
ret
|
||||
@@ -9,8 +9,6 @@ include consts/sprites
|
||||
include sections/init_sprite_lookup_table
|
||||
include sections/init_screen
|
||||
|
||||
call drawing.draw_whole_map
|
||||
|
||||
include sections/init_robot_state
|
||||
include sections/init_ghost_state
|
||||
include sections/init_timers
|
||||
@@ -47,13 +45,9 @@ jmp game_loop
|
||||
include lib/u64
|
||||
include lib/game
|
||||
include lib/drawing
|
||||
include lib/sprite_rotation
|
||||
|
||||
include dist/empty
|
||||
include dist/placeholder
|
||||
include dist/wall_end
|
||||
include dist/wall_straight
|
||||
include dist/wall_corner
|
||||
include dist/robot_up
|
||||
include dist/robot_right
|
||||
include dist/robot_down
|
||||
@@ -67,3 +61,5 @@ include dist/coin
|
||||
include dist/map
|
||||
|
||||
include reserved_space
|
||||
|
||||
include dist/screen
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
pub ptr.textures_addresses:
|
||||
U32 0 ; empty
|
||||
U32 0 ; placeholder
|
||||
U32 0 ; wall_end
|
||||
U32 0 ; wall_straight
|
||||
U32 0 ; wall_corner
|
||||
U32 0 ; robot up
|
||||
U32 0 ; robot right
|
||||
U32 0 ; robot down
|
||||
@@ -40,5 +37,3 @@ U8 0 ; x coord
|
||||
U8 0 ; y coord
|
||||
U8 0 ; direction
|
||||
U8 0 ; [padding]
|
||||
|
||||
pub ptr.screen:
|
||||
@@ -12,6 +12,5 @@ store_8 [r6], r2
|
||||
add r6, r6, 1
|
||||
store_8 [r6], r5
|
||||
|
||||
mov r3, sprites.rotation_0
|
||||
mov r4, sprites.ghost_down
|
||||
mov r3, sprites.ghost_down
|
||||
call drawing.draw_sprite_at_map_coord
|
||||
@@ -12,6 +12,5 @@ store_8 [r6], r2
|
||||
add r6, r6, 1
|
||||
store_8 [r6], r5
|
||||
|
||||
mov r3, sprites.rotation_0
|
||||
mov r4, sprites.robot_down
|
||||
mov r3, sprites.robot_down
|
||||
call drawing.draw_sprite_at_map_coord
|
||||
@@ -3,7 +3,7 @@ mov r1, screen.mode_index
|
||||
screen r1, screen.mode_value
|
||||
|
||||
mov r1, screen.offset_index
|
||||
add r2, zr, ptr.screen
|
||||
add r2, zr, screen
|
||||
screen r1, r2
|
||||
|
||||
mov r1, screen.resolution_index
|
||||
|
||||
@@ -17,24 +17,6 @@ lsl r2, r1, arch.instruction_increment_shift
|
||||
add r2, r2, ptr.textures_addresses
|
||||
add r3, zr, sprite_unimplemented
|
||||
store_32 [r2], r3
|
||||
; sprite_wall_end
|
||||
add r1, zr, sprites.wall_end
|
||||
lsl r2, r1, arch.instruction_increment_shift
|
||||
add r2, r2, ptr.textures_addresses
|
||||
add r3, zr, sprite_wall_end
|
||||
store_32 [r2], r3
|
||||
; sprite_wall_straight
|
||||
add r1, zr, sprites.wall_straight
|
||||
lsl r2, r1, arch.instruction_increment_shift
|
||||
add r2, r2, ptr.textures_addresses
|
||||
add r3, zr, sprite_wall_straight
|
||||
store_32 [r2], r3
|
||||
; sprite_wall_corner
|
||||
add r1, zr, sprites.wall_corner
|
||||
lsl r2, r1, arch.instruction_increment_shift
|
||||
add r2, r2, ptr.textures_addresses
|
||||
add r3, zr, sprite_wall_corner
|
||||
store_32 [r2], r3
|
||||
|
||||
; sprite_robot_up
|
||||
add r1, zr, sprites.robot_up
|
||||
|
||||
@@ -27,8 +27,8 @@ store_32 [r9], r6
|
||||
|
||||
/* Movement
|
||||
r1, r2: x, y
|
||||
r3: rotation
|
||||
r4: direction / sprite id
|
||||
r3: sprite id
|
||||
r4: direction
|
||||
r5, r6: increments x, y
|
||||
r7, r8: [RESERVED]
|
||||
r9: pointer
|
||||
@@ -74,8 +74,7 @@ add r9, r9, 1
|
||||
store_8 [r9], r2
|
||||
|
||||
; draw ghost on new position
|
||||
mov r3, sprites.rotation_0
|
||||
add r4, r4, sprites.ghost
|
||||
add r3, r4, sprites.ghost
|
||||
call drawing.draw_sprite_at_map_coord
|
||||
|
||||
/*
|
||||
|
||||
@@ -27,8 +27,8 @@ store_32 [r9], r6
|
||||
|
||||
/* Movement
|
||||
r1, r2: x, y
|
||||
r3: rotation
|
||||
r4: direction / sprite id
|
||||
r3: sprite id
|
||||
r4: direction
|
||||
r5, r6: increments x, y
|
||||
r7, r8: [RESERVED]
|
||||
r9: pointer
|
||||
@@ -92,8 +92,7 @@ store_8 [r9], r2
|
||||
|
||||
pub timer_robot.draw:
|
||||
; draw robot on new position
|
||||
mov r3, sprites.rotation_0
|
||||
add r4, r4, sprites.robot
|
||||
add r3, r4, sprites.robot
|
||||
call drawing.draw_sprite_at_map_coord
|
||||
|
||||
pub timer_robot.end:
|
||||
Reference in New Issue
Block a user