change the way static RAM variable are declared and used

This commit is contained in:
2026-04-24 09:31:04 +02:00
parent e6b2d8b086
commit 6cdb7304c2
5 changed files with 55 additions and 47 deletions

View File

@@ -13,7 +13,6 @@ const asmFilePaths = [
"src/consts/game.asm",
"src/consts/keyboard.asm",
"src/consts/map.asm",
"src/consts/offsets.asm",
"src/consts/scene.asm",
"src/consts/screen.asm",
"src/consts/sprites.asm",
@@ -24,6 +23,7 @@ const asmFilePaths = [
"src/lib/drawing.asm",
"src/lib/sprite_rotation.asm",
];
const reservedSpacePath = 'src/reserved_space.asm';
const mapWidth = 15;
const spriteWidth = 17;
@@ -93,6 +93,14 @@ for (const [label, path] of Object.entries(spritesPath)) {
console.log(asmRawRepresentations.join("\n\n"));
console.log(`
;
; RESERVED RAM SPACE
;
`);
console.log(await Deno.readTextFile(reservedSpacePath))
/**
* Return an ASM representation of the given data
*

View File

@@ -1,16 +0,0 @@
;const free_ram_start = 8000
pub const offsets.screen = 8000 ; screen size: 80x60 = 4800
pub const offsets.tick_duration_high = 12800
pub const offsets.tick_duration_low = 12804
pub const offsets.next_tick_high = 12808
pub const offsets.next_tick_low = 128012
; State:
; U8 x coord
; U8 y coord
; U8 direction
pub const offsets.state_robot = 12816
pub const offsets.state_ghost = 12819

View File

@@ -77,7 +77,7 @@ get_tile_address:
cmp r3, sprites.height
jne get_tile_address_offset_per_row_loop
mov r13, offsets.screen
add r13, zr, ptr.screen
mov r3, 0
get_tile_address_margin_top_loop:

View File

@@ -9,7 +9,8 @@ mov r1, screen.mode_index
screen r1, screen.mode_value
mov r1, screen.offset_index
screen r1, offsets.screen
add r2, zr, ptr.screen
screen r1, r2
mov r1, screen.resolution_index
screen r1, screen.resolution_value
@@ -27,7 +28,7 @@ const robot_initial_direction = game.direction_down
mov r1, robot_initial_x
mov r2, robot_initial_y
mov r5, robot_initial_direction
mov r6, offsets.state_robot
add r6, zr, ptr.state_robot
store_8 [r6], r1
add r6, r6, 1
store_8 [r6], r2
@@ -46,7 +47,7 @@ const ghost_initial_direction = game.direction_down
mov r1, ghost_initial_x
mov r2, ghost_initial_y
mov r5, ghost_initial_direction
mov r6, offsets.state_ghost
add r6, zr, ptr.state_ghost
store_8 [r6], r1
add r6, r6, 1
store_8 [r6], r2
@@ -60,17 +61,10 @@ call drawing.draw_sprite_at_map_coord
;
; Time initialization
;
mov r2, game.tick_duration_1
movt r2, r2
movb r2, game.tick_duration_0
mov r1, offsets.tick_duration_low
store_32 [r1], r2
mov r3, game.tick_duration_3
movt r3, r3
movb r3, game.tick_duration_2
mov r1, offsets.tick_duration_high
store_32 [r1], r3
add r1, zr, ptr.tick_duration_low
load_32 r2, [r1]
add r1, zr, ptr.tick_duration_high
load_32 r3, [r1]
time_0 r4
time_1 r5
@@ -81,9 +75,9 @@ jae init_store_next_tick
add r5, r5, 1 ; overflow
init_store_next_tick:
mov r1, offsets.next_tick_low
add r1, zr, ptr.next_tick_low
store_32 [r1], r4
mov r1, offsets.next_tick_high
add r1, zr, ptr.next_tick_high
store_32 [r1], r5
game_loop:
@@ -125,7 +119,7 @@ game_loop:
; jmp game_loop_event_handling_end
game_loop_event_handling_store_direction:
add r2, zr, offsets.state_robot
add r2, zr, ptr.state_robot
add r2, r2, 2
store_8 [r2], r1
@@ -143,9 +137,9 @@ game_loop:
time_0 r2
time_1 r3
mov r1, offsets.next_tick_low
add r1, zr, ptr.next_tick_low
load_32 r4, [r1]
mov r1, offsets.next_tick_high
add r1, zr, ptr.next_tick_high
load_32 r5, [r1]
cmp r3, r5
@@ -155,9 +149,9 @@ game_loop:
jb game_loop
update_next_tick:
mov r1, offsets.tick_duration_low
add r1, zr, ptr.tick_duration_low
load_32 r2, [r1]
mov r1, offsets.tick_duration_high
add r1, zr, ptr.tick_duration_high
load_32 r3, [r1]
add r4, r4, r2
add r5, r5, r3
@@ -166,9 +160,9 @@ game_loop:
add r5, r5, 1
store_next_tick:
mov r1, offsets.next_tick_low
add r1, zr, ptr.next_tick_low
store_32 [r1], r4
mov r1, offsets.next_tick_high
add r1, zr, ptr.next_tick_high
store_32 [r1], r5
@@ -184,7 +178,7 @@ game_loop:
; r7 = new position address
; r8 = new position content
; r9 = jump address
mov r1, offsets.state_robot
add r1, zr, ptr.state_robot
load_8 r2, [r1]
add r1, r1, 1
load_8 r3, [r1]
@@ -229,7 +223,7 @@ game_loop:
cmp r8, map.tiles.wall
jne game_loop_robot_movement_some
; hit wall
mov r1, offsets.state_robot
add r1, zr, ptr.state_robot
add r1, r1, 2
mov r4, game.direction_still
store_8 [r1], r4
@@ -240,7 +234,7 @@ game_loop:
mov r8, map.tiles.empty
store_8 [r7], r8
mov r1, offsets.state_robot
add r1, zr, ptr.state_robot
store_8 [r1], r5
add r1, r1, 1
store_8 [r1], r6
@@ -276,7 +270,7 @@ game_loop:
; r9: new position address
; r10: new position content
; r11: jump address
mov r1, offsets.state_ghost
add r1, zr, ptr.state_ghost
load_8 r2, [r1]
add r1, r1, 1
load_8 r3, [r1]
@@ -308,7 +302,7 @@ game_loop:
game_loop_ghost_movement_make_move:
add r7, r2, r5
add r8, r3, r6
mov r1, offsets.state_ghost
add r1, zr, ptr.state_ghost
store_8 [r1], r7
add r1, r1, 1
store_8 [r1], r8
@@ -355,7 +349,7 @@ game_loop:
cmp r10, map.tiles.wall
jne game_loop_ghost_movement_end
; increment direction
mov r1, offsets.state_ghost
add r1, zr, ptr.state_ghost
add r1, r1, 2
load_8 r4, [r1]
add r4, r4, 1

22
src/reserved_space.asm Normal file
View File

@@ -0,0 +1,22 @@
; 0.5 second = 500_000_000 nano second = 0x0000_0000_1DCD_6500
pub ptr.tick_duration_high: U32 0x0000_0000
pub ptr.tick_duration_low: U32 0x1DCD_6500
; 1 second = 1_000_000_000 nano second = 0x0000_0000_3B9A_CA00
; pub ptr.tick_duration_high: U32 0x0000_0000
; pub ptr.tick_duration_low: U32 0x3B9A_CA00
pub ptr.next_tick_high: U32 0
pub ptr.next_tick_low: U32 0
pub ptr.state_robot:
U8 0 ; x coord
U8 0 ; y coord
U8 0 ; direction
pub ptr.state_ghost:
U8 0 ; x coord
U8 0 ; y coord
U8 0 ; direction
pub ptr.screen: