asset manager load by asset id and slot index

This commit is contained in:
2026-03-27 15:05:37 +00:00
parent e6978397ab
commit 201226b892
13 changed files with 154 additions and 186 deletions
@@ -1,7 +1,7 @@
use super::*;
use prometeu_bytecode::{TRAP_INVALID_SYSCALL, TRAP_OOB, TRAP_TYPE, Value};
use crate::services::memcard::{MemcardSlotState, MemcardStatus};
use prometeu_hal::asset::{AssetOpStatus, BankType, SlotRef};
use prometeu_bytecode::{TRAP_INVALID_SYSCALL, TRAP_OOB, TRAP_TYPE, Value};
use prometeu_hal::asset::{AssetId, AssetOpStatus, BankType, SlotRef};
use prometeu_hal::cartridge::AppMode;
use prometeu_hal::color::Color;
use prometeu_hal::log::{LogLevel, LogSource};
@@ -446,15 +446,13 @@ impl NativeInterface for VirtualMachineRuntime {
Ok(())
}
Syscall::AssetLoad => {
let asset_id = expect_string(args, 0, "asset_id")?;
let asset_type = match expect_int(args, 1)? as u32 {
0 => BankType::TILES,
1 => BankType::SOUNDS,
_ => return Err(VmFault::Trap(TRAP_TYPE, "Invalid asset type".to_string())),
};
let slot = SlotRef { asset_type, index: expect_int(args, 2)? as usize };
let raw_asset_id = expect_int(args, 0)?;
let asset_id = AssetId::try_from(raw_asset_id).map_err(|_| {
VmFault::Trap(TRAP_TYPE, format!("asset_id out of i32 range: {}", raw_asset_id))
})?;
let slot_index = expect_int(args, 1)? as usize;
match hw.assets().load(&asset_id, slot) {
match hw.assets().load(asset_id, slot_index) {
Ok(handle) => {
ret.push_int(AssetOpStatus::Ok as i64);
ret.push_int(handle as i64);
@@ -566,10 +564,12 @@ fn hex_decode(s: &str) -> Result<Vec<u8>, VmFault> {
let mut out = Vec::with_capacity(bytes.len() / 2);
let mut i = 0usize;
while i < bytes.len() {
let hi = nibble(bytes[i])
.ok_or_else(|| VmFault::Trap(TRAP_TYPE, "payload_hex contains invalid hex".to_string()))?;
let lo = nibble(bytes[i + 1])
.ok_or_else(|| VmFault::Trap(TRAP_TYPE, "payload_hex contains invalid hex".to_string()))?;
let hi = nibble(bytes[i]).ok_or_else(|| {
VmFault::Trap(TRAP_TYPE, "payload_hex contains invalid hex".to_string())
})?;
let lo = nibble(bytes[i + 1]).ok_or_else(|| {
VmFault::Trap(TRAP_TYPE, "payload_hex contains invalid hex".to_string())
})?;
out.push((hi << 4) | lo);
i += 2;
}