57 lines
2.8 KiB
Rust
57 lines
2.8 KiB
Rust
use prometeu_core::hardware::Syscall;
|
|
|
|
/// Maps a high-level function name to its corresponding Syscall ID in the Virtual Machine.
|
|
///
|
|
/// This logic resides in the TypeScript frontend because string name resolution
|
|
/// from the source code is dependent on the language and the provided SDK.
|
|
pub fn map_syscall(name: &str) -> Option<u32> {
|
|
// Check if the name corresponds to a standard syscall defined in the core firmware
|
|
from_name(name)
|
|
}
|
|
|
|
/// Converts a textual name (e.g., "gfx.fillRect") to the numeric ID of the syscall.
|
|
fn from_name(name: &str) -> Option<u32> {
|
|
let id = match name.to_lowercase().as_str() {
|
|
"system.hascart" | "system.has_cart" => Syscall::SystemHasCart,
|
|
"system.runcart" | "system.run_cart" => Syscall::SystemRunCart,
|
|
"gfx.clear" => Syscall::GfxClear,
|
|
"gfx.fillrect" | "gfx.draw_rect" => Syscall::GfxFillRect,
|
|
"gfx.drawline" | "gfx.draw_line" => Syscall::GfxDrawLine,
|
|
"gfx.drawcircle" | "gfx.draw_circle" => Syscall::GfxDrawCircle,
|
|
"gfx.drawdisc" | "gfx.draw_disc" => Syscall::GfxDrawDisc,
|
|
"gfx.drawsquare" | "gfx.draw_square" => Syscall::GfxDrawSquare,
|
|
"gfx.setsprite" | "gfx.set_sprite" => Syscall::GfxSetSprite,
|
|
"gfx.drawtext" | "gfx.draw_text" => Syscall::GfxDrawText,
|
|
"input.getpad" | "input.get_pad" => Syscall::InputGetPad,
|
|
"input.getpadpressed" | "input.get_pad_pressed" => Syscall::InputGetPadPressed,
|
|
"input.getpadreleased" | "input.get_pad_released" => Syscall::InputGetPadReleased,
|
|
"input.getpadhold" | "input.get_pad_hold" => Syscall::InputGetPadHold,
|
|
"touch.getx" | "touch.get_x" => Syscall::TouchGetX,
|
|
"touch.gety" | "touch.get_y" => Syscall::TouchGetY,
|
|
"touch.isdown" | "touch.is_down" => Syscall::TouchIsDown,
|
|
"touch.ispressed" | "touch.is_pressed" => Syscall::TouchIsPressed,
|
|
"touch.isreleased" | "touch.is_released" => Syscall::TouchIsReleased,
|
|
"touch.gethold" | "touch.get_hold" => Syscall::TouchGetHold,
|
|
"audio.playsample" | "audio.play_sample" => Syscall::AudioPlaySample,
|
|
"audio.play" => Syscall::AudioPlay,
|
|
"fs.open" => Syscall::FsOpen,
|
|
"fs.read" => Syscall::FsRead,
|
|
"fs.write" => Syscall::FsWrite,
|
|
"fs.close" => Syscall::FsClose,
|
|
"fs.listdir" | "fs.list_dir" => Syscall::FsListDir,
|
|
"fs.exists" => Syscall::FsExists,
|
|
"fs.delete" => Syscall::FsDelete,
|
|
"log.write" => Syscall::LogWrite,
|
|
"log.writetag" | "log.write_tag" => Syscall::LogWriteTag,
|
|
"asset.load" => Syscall::AssetLoad,
|
|
"asset.status" => Syscall::AssetStatus,
|
|
"asset.commit" => Syscall::AssetCommit,
|
|
"asset.cancel" => Syscall::AssetCancel,
|
|
"bank.info" => Syscall::BankInfo,
|
|
"bank.slotinfo" | "bank.slot_info" => Syscall::BankSlotInfo,
|
|
_ => return None,
|
|
};
|
|
Some(id as u32)
|
|
}
|
|
|