From b0758c69762e436c508c71ff04976cedb1b49715 Mon Sep 17 00:00:00 2001 From: Robin Chappatte Date: Fri, 24 Apr 2026 09:31:04 +0200 Subject: [PATCH] change the way static RAM variable are declared and used (cherry picked from commit 6cdb7304c23040726721844df4db855073f53a21) --- build.ts | 10 +++++++- src/consts/offsets.asm | 16 ------------- src/lib/drawing.asm | 2 +- src/main.asm | 52 +++++++++++++++++++----------------------- src/reserved_space.asm | 22 ++++++++++++++++++ 5 files changed, 55 insertions(+), 47 deletions(-) delete mode 100644 src/consts/offsets.asm create mode 100644 src/reserved_space.asm diff --git a/build.ts b/build.ts index 204f386..7892581 100755 --- a/build.ts +++ b/build.ts @@ -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 = 5; @@ -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 * diff --git a/src/consts/offsets.asm b/src/consts/offsets.asm deleted file mode 100644 index 53d2e4f..0000000 --- a/src/consts/offsets.asm +++ /dev/null @@ -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 \ No newline at end of file diff --git a/src/lib/drawing.asm b/src/lib/drawing.asm index 1bfdf0c..1f49b78 100644 --- a/src/lib/drawing.asm +++ b/src/lib/drawing.asm @@ -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: diff --git a/src/main.asm b/src/main.asm index 03923c4..312431f 100644 --- a/src/main.asm +++ b/src/main.asm @@ -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 diff --git a/src/reserved_space.asm b/src/reserved_space.asm new file mode 100644 index 0000000..6c8104c --- /dev/null +++ b/src/reserved_space.asm @@ -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: \ No newline at end of file