replace texture jump table with dispatch table

(cherry picked from commit 88f10f9f06)
This commit is contained in:
2026-04-24 10:12:23 +02:00
parent b0758c6976
commit f0656aca40
6 changed files with 92 additions and 47 deletions

View File

@@ -10,6 +10,7 @@ if (Deno.args.length !== 0) {
import { TextLineStream } from "jsr:@std/streams@1.1.0"; import { TextLineStream } from "jsr:@std/streams@1.1.0";
const asmFilePaths = [ const asmFilePaths = [
"src/consts/arch.asm",
"src/consts/game.asm", "src/consts/game.asm",
"src/consts/keyboard.asm", "src/consts/keyboard.asm",
"src/consts/map.asm", "src/consts/map.asm",
@@ -17,6 +18,7 @@ const asmFilePaths = [
"src/consts/screen.asm", "src/consts/screen.asm",
"src/consts/sprites.asm", "src/consts/sprites.asm",
"src/init.asm",
"src/main.asm", "src/main.asm",
"src/lib/game.asm", "src/lib/game.asm",

2
src/consts/arch.asm Normal file
View File

@@ -0,0 +1,2 @@
pub const arch.instruction_size = 4
pub const arch.instruction_increment_shift = 2

70
src/init.asm Normal file
View File

@@ -0,0 +1,70 @@
;
; Jump table initialisation
;
; r1: sprite id
; r2: pointer address
; r3: pointer value
; sprite_empty
add r1, zr, sprites.empty
lsl r2, r1, arch.instruction_increment_shift
add r2, r2, ptr.textures_addresses
add r3, zr, sprite_empty
store_32 [r2], r3
; sprite_unimplemented
add r1, zr, sprites.unimplemented
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
add r1, zr, sprites.robot
lsl r2, r1, arch.instruction_increment_shift
add r2, r2, ptr.textures_addresses
add r3, zr, sprite_robot
store_32 [r2], r3
; sprite_ghost
add r1, zr, sprites.ghost
lsl r2, r1, arch.instruction_increment_shift
add r2, r2, ptr.textures_addresses
add r3, zr, sprite_ghost
store_32 [r2], r3
; sprite_coin
add r1, zr, sprites.coin
lsl r2, r1, arch.instruction_increment_shift
add r2, r2, ptr.textures_addresses
add r3, zr, sprite_coin
store_32 [r2], r3
;
; Screen initialization
;
; r1 = screen parameter value
mov r1, screen.mode_index
screen r1, screen.mode_value
mov r1, screen.offset_index
add r2, zr, ptr.screen
screen r1, r2
mov r1, screen.resolution_index
screen r1, screen.resolution_value

View File

@@ -120,48 +120,21 @@ get_tile_address:
; r13: address ; r13: address
; Locals: ; Locals:
; r2: jump address ; r2: pointer address
; */ ; */
get_sprite_address: get_sprite_address:
push r1 push r1
push r2 push r2
cmp r1, sprites.max cmp r1, sprites.max
jbe get_sprite_address_jmp_table_init jbe get_sprite_address_ptr
mov r1, sprites.unimplemented mov r1, sprites.unimplemented
get_sprite_address_jmp_table_init: get_sprite_address_ptr:
lsl r2, r1, 3 ; 2*instruction_size = *8 = <<3 lsl r2, r1, arch.instruction_increment_shift
add r2, r2, get_sprite_address_jmp_table_start add r2, r2, ptr.textures_addresses
jmp r2 load_32 r13, [r2]
get_sprite_address_jmp_table_start:
; sprite_empty
add r13, zr, sprite_empty
jmp get_sprite_address_return
; sprite_unimplemented:
add r13, zr, sprite_unimplemented
jmp get_sprite_address_return
; sprite_wall_end
add r13, zr, sprite_wall_end
jmp get_sprite_address_return
; sprite_wall_straight
add r13, zr, sprite_wall_straight
jmp get_sprite_address_return
; sprite_wall_corner
add r13, zr, sprite_wall_corner
jmp get_sprite_address_return
; sprite_robot
add r13, zr, sprite_robot
jmp get_sprite_address_return
; sprite_ghost
add r13, zr, sprite_ghost
jmp get_sprite_address_return
; sprite_coin:
add r13, zr, sprite_coin
;jmp get_sprite_address_return
get_sprite_address_return:
pop r2 pop r2
pop r1 pop r1
ret ret

View File

@@ -1,19 +1,6 @@
include consts/screen include consts/screen
; include init
; Screen initialization
;
; r1 = screen parameter value
mov r1, screen.mode_index
screen r1, screen.mode_value
mov r1, screen.offset_index
add r2, zr, ptr.screen
screen r1, r2
mov r1, screen.resolution_index
screen r1, screen.resolution_value
call drawing.draw_whole_map call drawing.draw_whole_map

View File

@@ -1,3 +1,14 @@
; Sprite addresses jump table
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
U32 0 ; ghost
U32 0 ; coin
; 0.5 second = 500_000_000 nano second = 0x0000_0000_1DCD_6500 ; 0.5 second = 500_000_000 nano second = 0x0000_0000_1DCD_6500
pub ptr.tick_duration_high: U32 0x0000_0000 pub ptr.tick_duration_high: U32 0x0000_0000
pub ptr.tick_duration_low: U32 0x1DCD_6500 pub ptr.tick_duration_low: U32 0x1DCD_6500