pr 00.1 move syscall to abi
This commit is contained in:
@@ -4,6 +4,7 @@ pub mod model;
|
||||
pub mod log;
|
||||
pub mod telemetry;
|
||||
pub mod debugger_protocol;
|
||||
pub mod syscalls;
|
||||
|
||||
// Tipos da VM que fazem parte do contrato (ex.: inspeção de pilha pelo debugger)
|
||||
pub mod virtual_machine {
|
||||
|
||||
@@ -0,0 +1,260 @@
|
||||
/// Enumeration of all System Calls (Syscalls) available in the Prometeu environment.
|
||||
///
|
||||
/// Syscalls are the primary mechanism for a program running in the Virtual Machine
|
||||
/// to interact with the outside world (Hardware, OS, Filesystem).
|
||||
///
|
||||
/// Each Syscall has a unique 32-bit ID. The IDs are grouped by category:
|
||||
/// - **0x0xxx**: System & OS Control
|
||||
/// - **0x1xxx**: Graphics (GFX)
|
||||
/// - **0x2xxx**: Input (Gamepad & Touch)
|
||||
/// - **0x3xxx**: Audio (PCM & Mixing)
|
||||
/// - **0x4xxx**: Filesystem (Sandboxed I/O)
|
||||
/// - **0x5xxx**: Logging & Debugging
|
||||
/// - **0x6xxx**: Asset Loading & Memory Banks
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[repr(u32)]
|
||||
pub enum Syscall {
|
||||
// --- System ---
|
||||
/// Checks if a cartridge is currently inserted in the virtual slot.
|
||||
SystemHasCart = 0x0001,
|
||||
/// Requests the OS to launch a specific cartridge.
|
||||
SystemRunCart = 0x0002,
|
||||
|
||||
// --- GFX (Graphics) ---
|
||||
/// Fills the entire back buffer with a single color.
|
||||
GfxClear = 0x1001,
|
||||
/// Draws a solid rectangle.
|
||||
GfxFillRect = 0x1002,
|
||||
/// Draws a 1-pixel wide line.
|
||||
GfxDrawLine = 0x1003,
|
||||
/// Draws a circle outline.
|
||||
GfxDrawCircle = 0x1004,
|
||||
/// Draws a filled circle (disc).
|
||||
GfxDrawDisc = 0x1005,
|
||||
/// Draws a rectangle outline.
|
||||
GfxDrawSquare = 0x1006,
|
||||
/// Configures one of the 512 hardware sprites.
|
||||
GfxSetSprite = 0x1007,
|
||||
/// Draws a text string at the specified coordinates.
|
||||
GfxDrawText = 0x1008,
|
||||
/// Fills the entire back buffer with a single RGB565 color (flattened).
|
||||
GfxClear565 = 0x1010,
|
||||
|
||||
// --- Input ---
|
||||
/// Returns the current raw state of the digital gamepad (bitmask).
|
||||
InputGetPad = 0x2001,
|
||||
/// Returns buttons that were pressed exactly in this frame.
|
||||
InputGetPadPressed = 0x2002,
|
||||
/// Returns buttons that were released exactly in this frame.
|
||||
InputGetPadReleased = 0x2003,
|
||||
/// Returns how many frames a button has been held down.
|
||||
InputGetPadHold = 0x2004,
|
||||
/// Returns the full snapshot of the gamepad state (48 slots).
|
||||
InputPadSnapshot = 0x2010,
|
||||
/// Returns the full snapshot of the touch state (6 slots).
|
||||
InputTouchSnapshot = 0x2011,
|
||||
|
||||
/// Returns the X coordinate of the touch/mouse pointer.
|
||||
TouchGetX = 0x2101,
|
||||
/// Returns the Y coordinate of the touch/mouse pointer.
|
||||
TouchGetY = 0x2102,
|
||||
/// Returns true if the pointer is currently touching the screen.
|
||||
TouchIsDown = 0x2103,
|
||||
/// Returns true if the touch started in this frame.
|
||||
TouchIsPressed = 0x2104,
|
||||
/// Returns true if the touch ended in this frame.
|
||||
TouchIsReleased = 0x2105,
|
||||
/// Returns how many frames the pointer has been held down.
|
||||
TouchGetHold = 0x2106,
|
||||
|
||||
// --- Audio ---
|
||||
/// Starts playback of a sound sample by its Bank and ID.
|
||||
AudioPlaySample = 0x3001,
|
||||
/// Low-level audio play command.
|
||||
AudioPlay = 0x3002,
|
||||
|
||||
// --- FS (Filesystem) ---
|
||||
/// Opens a file for reading or writing. Returns a File Handle (u32).
|
||||
FsOpen = 0x4001,
|
||||
/// Reads data from an open file handle into the VM heap.
|
||||
FsRead = 0x4002,
|
||||
/// Writes data from the VM heap into an open file handle.
|
||||
FsWrite = 0x4003,
|
||||
/// Closes an open file handle.
|
||||
FsClose = 0x4004,
|
||||
/// Lists entries in a directory.
|
||||
FsListDir = 0x4005,
|
||||
/// Checks if a file or directory exists.
|
||||
FsExists = 0x4006,
|
||||
/// Deletes a file or empty directory.
|
||||
FsDelete = 0x4007,
|
||||
|
||||
// --- Log ---
|
||||
/// Writes a generic string to the system log.
|
||||
LogWrite = 0x5001,
|
||||
/// Writes a string to the system log with a specific numerical tag.
|
||||
LogWriteTag = 0x5002,
|
||||
|
||||
// --- Asset (DMA) ---
|
||||
/// Starts an asynchronous load of a file into a memory bank.
|
||||
AssetLoad = 0x6001,
|
||||
/// Returns the status of a pending asset load (0=Loading, 1=Ready, 2=Error).
|
||||
AssetStatus = 0x6002,
|
||||
/// Finalizes the asset loading, making it available for GFX/Audio.
|
||||
AssetCommit = 0x6003,
|
||||
/// Cancels a pending asset load.
|
||||
AssetCancel = 0x6004,
|
||||
|
||||
// --- Bank (Memory) ---
|
||||
/// Returns information about a specific Memory Bank.
|
||||
BankInfo = 0x6101,
|
||||
/// Returns information about a slot within a Memory Bank.
|
||||
BankSlotInfo = 0x6102,
|
||||
}
|
||||
|
||||
impl Syscall {
|
||||
pub fn from_u32(id: u32) -> Option<Self> {
|
||||
match id {
|
||||
0x0001 => Some(Self::SystemHasCart),
|
||||
0x0002 => Some(Self::SystemRunCart),
|
||||
0x1001 => Some(Self::GfxClear),
|
||||
0x1002 => Some(Self::GfxFillRect),
|
||||
0x1003 => Some(Self::GfxDrawLine),
|
||||
0x1004 => Some(Self::GfxDrawCircle),
|
||||
0x1005 => Some(Self::GfxDrawDisc),
|
||||
0x1006 => Some(Self::GfxDrawSquare),
|
||||
0x1007 => Some(Self::GfxSetSprite),
|
||||
0x1008 => Some(Self::GfxDrawText),
|
||||
0x1010 => Some(Self::GfxClear565),
|
||||
0x2001 => Some(Self::InputGetPad),
|
||||
0x2002 => Some(Self::InputGetPadPressed),
|
||||
0x2003 => Some(Self::InputGetPadReleased),
|
||||
0x2004 => Some(Self::InputGetPadHold),
|
||||
0x2010 => Some(Self::InputPadSnapshot),
|
||||
0x2011 => Some(Self::InputTouchSnapshot),
|
||||
0x2101 => Some(Self::TouchGetX),
|
||||
0x2102 => Some(Self::TouchGetY),
|
||||
0x2103 => Some(Self::TouchIsDown),
|
||||
0x2104 => Some(Self::TouchIsPressed),
|
||||
0x2105 => Some(Self::TouchIsReleased),
|
||||
0x2106 => Some(Self::TouchGetHold),
|
||||
0x3001 => Some(Self::AudioPlaySample),
|
||||
0x3002 => Some(Self::AudioPlay),
|
||||
0x4001 => Some(Self::FsOpen),
|
||||
0x4002 => Some(Self::FsRead),
|
||||
0x4003 => Some(Self::FsWrite),
|
||||
0x4004 => Some(Self::FsClose),
|
||||
0x4005 => Some(Self::FsListDir),
|
||||
0x4006 => Some(Self::FsExists),
|
||||
0x4007 => Some(Self::FsDelete),
|
||||
0x5001 => Some(Self::LogWrite),
|
||||
0x5002 => Some(Self::LogWriteTag),
|
||||
0x6001 => Some(Self::AssetLoad),
|
||||
0x6002 => Some(Self::AssetStatus),
|
||||
0x6003 => Some(Self::AssetCommit),
|
||||
0x6004 => Some(Self::AssetCancel),
|
||||
0x6101 => Some(Self::BankInfo),
|
||||
0x6102 => Some(Self::BankSlotInfo),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn args_count(&self) -> usize {
|
||||
match self {
|
||||
Self::SystemHasCart => 0,
|
||||
Self::SystemRunCart => 0,
|
||||
Self::GfxClear => 1,
|
||||
Self::GfxFillRect => 5,
|
||||
Self::GfxDrawLine => 5,
|
||||
Self::GfxDrawCircle => 4,
|
||||
Self::GfxDrawDisc => 5,
|
||||
Self::GfxDrawSquare => 6,
|
||||
Self::GfxSetSprite => 10,
|
||||
Self::GfxDrawText => 4,
|
||||
Self::GfxClear565 => 1,
|
||||
Self::InputGetPad => 1,
|
||||
Self::InputGetPadPressed => 1,
|
||||
Self::InputGetPadReleased => 1,
|
||||
Self::InputGetPadHold => 1,
|
||||
Self::InputPadSnapshot => 0,
|
||||
Self::InputTouchSnapshot => 0,
|
||||
Self::TouchGetX => 0,
|
||||
Self::TouchGetY => 0,
|
||||
Self::TouchIsDown => 0,
|
||||
Self::TouchIsPressed => 0,
|
||||
Self::TouchIsReleased => 0,
|
||||
Self::TouchGetHold => 0,
|
||||
Self::AudioPlaySample => 5,
|
||||
Self::AudioPlay => 7,
|
||||
Self::FsOpen => 1,
|
||||
Self::FsRead => 1,
|
||||
Self::FsWrite => 2,
|
||||
Self::FsClose => 1,
|
||||
Self::FsListDir => 1,
|
||||
Self::FsExists => 1,
|
||||
Self::FsDelete => 1,
|
||||
Self::LogWrite => 2,
|
||||
Self::LogWriteTag => 3,
|
||||
Self::AssetLoad => 3,
|
||||
Self::AssetStatus => 1,
|
||||
Self::AssetCommit => 1,
|
||||
Self::AssetCancel => 1,
|
||||
Self::BankInfo => 1,
|
||||
Self::BankSlotInfo => 2,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn results_count(&self) -> usize {
|
||||
match self {
|
||||
Self::GfxClear565 => 0,
|
||||
Self::InputPadSnapshot => 48,
|
||||
Self::InputTouchSnapshot => 6,
|
||||
_ => 1,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn name(&self) -> &'static str {
|
||||
match self {
|
||||
Self::SystemHasCart => "SystemHasCart",
|
||||
Self::SystemRunCart => "SystemRunCart",
|
||||
Self::GfxClear => "GfxClear",
|
||||
Self::GfxFillRect => "GfxFillRect",
|
||||
Self::GfxDrawLine => "GfxDrawLine",
|
||||
Self::GfxDrawCircle => "GfxDrawCircle",
|
||||
Self::GfxDrawDisc => "GfxDrawDisc",
|
||||
Self::GfxDrawSquare => "GfxDrawSquare",
|
||||
Self::GfxSetSprite => "GfxSetSprite",
|
||||
Self::GfxDrawText => "GfxDrawText",
|
||||
Self::GfxClear565 => "GfxClear565",
|
||||
Self::InputGetPad => "InputGetPad",
|
||||
Self::InputGetPadPressed => "InputGetPadPressed",
|
||||
Self::InputGetPadReleased => "InputGetPadReleased",
|
||||
Self::InputGetPadHold => "InputGetPadHold",
|
||||
Self::InputPadSnapshot => "InputPadSnapshot",
|
||||
Self::InputTouchSnapshot => "InputTouchSnapshot",
|
||||
Self::TouchGetX => "TouchGetX",
|
||||
Self::TouchGetY => "TouchGetY",
|
||||
Self::TouchIsDown => "TouchIsDown",
|
||||
Self::TouchIsPressed => "TouchIsPressed",
|
||||
Self::TouchIsReleased => "TouchIsReleased",
|
||||
Self::TouchGetHold => "TouchGetHold",
|
||||
Self::AudioPlaySample => "AudioPlaySample",
|
||||
Self::AudioPlay => "AudioPlay",
|
||||
Self::FsOpen => "FsOpen",
|
||||
Self::FsRead => "FsRead",
|
||||
Self::FsWrite => "FsWrite",
|
||||
Self::FsClose => "FsClose",
|
||||
Self::FsListDir => "FsListDir",
|
||||
Self::FsExists => "FsExists",
|
||||
Self::FsDelete => "FsDelete",
|
||||
Self::LogWrite => "LogWrite",
|
||||
Self::LogWriteTag => "LogWriteTag",
|
||||
Self::AssetLoad => "AssetLoad",
|
||||
Self::AssetStatus => "AssetStatus",
|
||||
Self::AssetCommit => "AssetCommit",
|
||||
Self::AssetCancel => "AssetCancel",
|
||||
Self::BankInfo => "BankInfo",
|
||||
Self::BankSlotInfo => "BankSlotInfo",
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user