assets loaded by bank id instead of name

This commit is contained in:
2026-03-24 13:40:55 +00:00
parent d576f7ddbd
commit 17878e481c
6 changed files with 44 additions and 87 deletions
@@ -135,7 +135,7 @@ impl NativeInterface for VirtualMachineRuntime {
Ok(())
}
Syscall::GfxSetSprite => {
let asset_name = expect_string(args, 0, "asset_name")?;
let bank_id = expect_int(args, 0)? as u8;
let index = expect_int(args, 1)? as usize;
let x = expect_int(args, 2)? as i32;
let y = expect_int(args, 3)? as i32;
@@ -154,10 +154,6 @@ impl NativeInterface for VirtualMachineRuntime {
ret.push_int(GfxOpStatus::ArgRangeInvalid as i64);
return Ok(());
}
let Some(bank_id) = hw.assets().find_slot_by_name(&asset_name, BankType::TILES) else {
ret.push_int(GfxOpStatus::AssetNotFound as i64);
return Ok(());
};
*hw.gfx_mut().sprite_mut(index) = Sprite {
tile: Tile { id: tile_id, flip_x: false, flip_y: false, palette_id },
@@ -225,7 +221,7 @@ impl NativeInterface for VirtualMachineRuntime {
Ok(())
}
Syscall::AudioPlay => {
let asset_name = expect_string(args, 0, "asset_name")?;
let bank_id = expect_int(args, 0)? as u8;
let sample_id_raw = expect_int(args, 1)?;
let voice_id_raw = expect_int(args, 2)?;
let volume_raw = expect_int(args, 3)?;
@@ -252,10 +248,6 @@ impl NativeInterface for VirtualMachineRuntime {
return Ok(());
}
let Some(bank_id) = hw.assets().find_slot_by_name(&asset_name, BankType::SOUNDS) else {
ret.push_int(AudioOpStatus::AssetNotFound as i64);
return Ok(());
};
let status = hw.audio_mut().play(
bank_id,
sample_id_raw as u16,
@@ -357,12 +357,11 @@ fn tick_gfx_set_sprite_operational_error_returns_status_not_crash() {
let mut hardware = Hardware::new();
let signals = InputSignals::default();
let code = assemble(
"PUSH_CONST 0\nPUSH_I32 0\nPUSH_I32 0\nPUSH_I32 0\nPUSH_I32 0\nPUSH_I32 0\nPUSH_BOOL 1\nPUSH_BOOL 0\nPUSH_BOOL 0\nPUSH_I32 0\nHOSTCALL 0\nHALT",
"PUSH_I32 0\nPUSH_I32 0\nPUSH_I32 0\nPUSH_I32 0\nPUSH_I32 0\nPUSH_I32 0\nPUSH_BOOL 1\nPUSH_BOOL 0\nPUSH_BOOL 0\nPUSH_I32 0\nHOSTCALL 0\nHALT",
)
.expect("assemble");
let program = serialized_single_function_module_with_consts(
let program = serialized_single_function_module(
code,
vec![ConstantPoolEntry::String("missing_tile_bank".into())],
vec![SyscallDecl {
module: "gfx".into(),
name: "set_sprite".into(),
@@ -377,7 +376,7 @@ fn tick_gfx_set_sprite_operational_error_returns_status_not_crash() {
let report = runtime.tick(&mut vm, &signals, &mut hardware);
assert!(report.is_none(), "operational error must not crash");
assert!(vm.is_halted());
assert_eq!(vm.operand_stack_top(1), vec![Value::Int64(GfxOpStatus::AssetNotFound as i64)]);
assert_eq!(vm.operand_stack_top(1), vec![Value::Int64(GfxOpStatus::Ok as i64)]);
}
#[test]
@@ -387,12 +386,11 @@ fn tick_gfx_set_sprite_invalid_index_returns_status_not_crash() {
let mut hardware = Hardware::new();
let signals = InputSignals::default();
let code = assemble(
"PUSH_CONST 0\nPUSH_I32 512\nPUSH_I32 0\nPUSH_I32 0\nPUSH_I32 0\nPUSH_I32 0\nPUSH_BOOL 1\nPUSH_BOOL 0\nPUSH_BOOL 0\nPUSH_I32 0\nHOSTCALL 0\nHALT",
"PUSH_I32 0\nPUSH_I32 512\nPUSH_I32 0\nPUSH_I32 0\nPUSH_I32 0\nPUSH_I32 0\nPUSH_BOOL 1\nPUSH_BOOL 0\nPUSH_BOOL 0\nPUSH_I32 0\nHOSTCALL 0\nHALT",
)
.expect("assemble");
let program = serialized_single_function_module_with_consts(
let program = serialized_single_function_module(
code,
vec![ConstantPoolEntry::String("missing_tile_bank".into())],
vec![SyscallDecl {
module: "gfx".into(),
name: "set_sprite".into(),
@@ -420,12 +418,11 @@ fn tick_gfx_set_sprite_invalid_range_returns_status_not_crash() {
let mut hardware = Hardware::new();
let signals = InputSignals::default();
let code = assemble(
"PUSH_CONST 0\nPUSH_I32 0\nPUSH_I32 0\nPUSH_I32 0\nPUSH_I32 0\nPUSH_I32 64\nPUSH_BOOL 1\nPUSH_BOOL 0\nPUSH_BOOL 0\nPUSH_I32 0\nHOSTCALL 0\nHALT",
"PUSH_I32 0\nPUSH_I32 0\nPUSH_I32 0\nPUSH_I32 0\nPUSH_I32 0\nPUSH_I32 64\nPUSH_BOOL 1\nPUSH_BOOL 0\nPUSH_BOOL 0\nPUSH_I32 0\nHOSTCALL 0\nHALT",
)
.expect("assemble");
let program = serialized_single_function_module_with_consts(
let program = serialized_single_function_module(
code,
vec![ConstantPoolEntry::String("missing_tile_bank".into())],
vec![SyscallDecl {
module: "gfx".into(),
name: "set_sprite".into(),
@@ -477,12 +474,11 @@ fn tick_audio_play_voice_invalid_returns_status_not_crash() {
let mut hardware = Hardware::new();
let signals = InputSignals::default();
let code = assemble(
"PUSH_CONST 0\nPUSH_I32 0\nPUSH_I32 16\nPUSH_I32 255\nPUSH_I32 128\nPUSH_I32 1\nPUSH_I32 0\nHOSTCALL 0\nHALT",
"PUSH_I32 0\nPUSH_I32 0\nPUSH_I32 16\nPUSH_I32 255\nPUSH_I32 128\nPUSH_I32 1\nPUSH_I32 0\nHOSTCALL 0\nHALT",
)
.expect("assemble");
let program = serialized_single_function_module_with_consts(
let program = serialized_single_function_module(
code,
vec![ConstantPoolEntry::String("missing_sound_bank".into())],
vec![SyscallDecl {
module: "audio".into(),
name: "play".into(),
@@ -507,12 +503,11 @@ fn tick_audio_play_missing_asset_returns_status_not_crash() {
let mut hardware = Hardware::new();
let signals = InputSignals::default();
let code = assemble(
"PUSH_CONST 0\nPUSH_I32 0\nPUSH_I32 0\nPUSH_I32 255\nPUSH_I32 128\nPUSH_I32 1\nPUSH_I32 0\nHOSTCALL 0\nHALT",
"PUSH_I32 0\nPUSH_I32 0\nPUSH_I32 0\nPUSH_I32 255\nPUSH_I32 128\nPUSH_I32 1\nPUSH_I32 0\nHOSTCALL 0\nHALT",
)
.expect("assemble");
let program = serialized_single_function_module_with_consts(
let program = serialized_single_function_module(
code,
vec![ConstantPoolEntry::String("missing_sound_bank".into())],
vec![SyscallDecl {
module: "audio".into(),
name: "play".into(),
@@ -527,7 +522,7 @@ fn tick_audio_play_missing_asset_returns_status_not_crash() {
let report = runtime.tick(&mut vm, &signals, &mut hardware);
assert!(report.is_none(), "missing audio asset must not crash");
assert!(vm.is_halted());
assert_eq!(vm.operand_stack_top(1), vec![Value::Int64(AudioOpStatus::AssetNotFound as i64)]);
assert_eq!(vm.operand_stack_top(1), vec![Value::Int64(AudioOpStatus::SampleNotFound as i64)]);
}
#[test]
@@ -559,7 +554,7 @@ fn tick_audio_play_type_mismatch_surfaces_trap_not_panic() {
match report {
CrashReport::VmTrap { trap } => {
assert_eq!(trap.code, TRAP_TYPE);
assert!(trap.message.contains("Expected string asset_name"));
assert!(trap.message.contains("Expected integer at index 0"));
}
other => panic!("expected VmTrap crash report, got {:?}", other),
}
@@ -889,17 +884,15 @@ fn tick_status_first_surface_smoke_across_gfx_audio_and_asset() {
let mut hardware = Hardware::new();
let signals = InputSignals::default();
let code = assemble(
"PUSH_CONST 0\nPUSH_I32 0\nPUSH_I32 0\nPUSH_I32 0\nPUSH_I32 0\nPUSH_I32 0\nPUSH_BOOL 1\nPUSH_BOOL 0\nPUSH_BOOL 0\nPUSH_I32 0\nHOSTCALL 0\n\
PUSH_CONST 1\nPUSH_I32 0\nPUSH_I32 0\nPUSH_I32 255\nPUSH_I32 128\nPUSH_I32 1\nPUSH_I32 0\nHOSTCALL 1\n\
PUSH_CONST 2\nPUSH_I32 0\nPUSH_I32 0\nHOSTCALL 2\n\
"PUSH_I32 0\nPUSH_I32 0\nPUSH_I32 0\nPUSH_I32 0\nPUSH_I32 0\nPUSH_I32 0\nPUSH_BOOL 1\nPUSH_BOOL 0\nPUSH_BOOL 0\nPUSH_I32 0\nHOSTCALL 0\n\
PUSH_I32 0\nPUSH_I32 0\nPUSH_I32 0\nPUSH_I32 255\nPUSH_I32 128\nPUSH_I32 1\nPUSH_I32 0\nHOSTCALL 1\n\
PUSH_CONST 0\nPUSH_I32 0\nPUSH_I32 0\nHOSTCALL 2\n\
HALT"
)
.expect("assemble");
let program = serialized_single_function_module_with_consts(
code,
vec![
ConstantPoolEntry::String("missing_tile_bank".into()),
ConstantPoolEntry::String("missing_sound_bank".into()),
ConstantPoolEntry::String("missing_asset".into()),
],
vec![
@@ -937,8 +930,8 @@ fn tick_status_first_surface_smoke_across_gfx_audio_and_asset() {
vec![
Value::Int64(0),
Value::Int64(AssetLoadError::AssetNotFound as i64),
Value::Int64(AudioOpStatus::AssetNotFound as i64),
Value::Int64(GfxOpStatus::AssetNotFound as i64),
Value::Int64(AudioOpStatus::SampleNotFound as i64),
Value::Int64(GfxOpStatus::Ok as i64),
]
);
}
@@ -972,7 +965,7 @@ fn tick_gfx_set_sprite_type_mismatch_surfaces_trap_not_panic() {
match report {
CrashReport::VmTrap { trap } => {
assert_eq!(trap.code, TRAP_TYPE);
assert!(trap.message.contains("Expected string asset_name"));
assert!(trap.message.contains("Expected integer at index 0"));
}
other => panic!("expected VmTrap crash report, got {:?}", other),
}