many fixes on compiler

This commit is contained in:
Nilton Constantino
2026-01-21 07:48:06 +00:00
parent 1b091e6ce8
commit 11d9d31c2f
9 changed files with 266 additions and 94 deletions
@@ -331,6 +331,25 @@ impl PrometeuOS {
}
// Helper para syscalls
pub fn get_button<'a>(&self, id: u32, hw: &'a dyn HardwareBridge) -> Option<&'a crate::model::Button> {
let pad = hw.pad();
match id {
0 => Some(&pad.up),
1 => Some(&pad.down),
2 => Some(&pad.left),
3 => Some(&pad.right),
4 => Some(&pad.a),
5 => Some(&pad.b),
6 => Some(&pad.x),
7 => Some(&pad.y),
8 => Some(&pad.l),
9 => Some(&pad.r),
10 => Some(&pad.start),
11 => Some(&pad.select),
_ => None,
}
}
pub fn is_button_down(&self, id: u32, hw: &mut dyn HardwareBridge) -> bool {
match id {
0 => hw.pad().up.down,
@@ -650,6 +669,49 @@ impl NativeInterface for PrometeuOS {
vm.push(Value::Boolean(is_down));
Ok(50)
}
Syscall::InputGetPadPressed => {
let button_id = vm.pop_integer()? as u32;
let val = self.get_button(button_id, hw).map(|b| b.pressed).unwrap_or(false);
vm.push(Value::Boolean(val));
Ok(50)
}
Syscall::InputGetPadReleased => {
let button_id = vm.pop_integer()? as u32;
let val = self.get_button(button_id, hw).map(|b| b.released).unwrap_or(false);
vm.push(Value::Boolean(val));
Ok(50)
}
Syscall::InputGetPadHold => {
let button_id = vm.pop_integer()? as u32;
let val = self.get_button(button_id, hw).map(|b| b.hold_frames).unwrap_or(0);
vm.push(Value::Int32(val as i32));
Ok(50)
}
Syscall::TouchGetX => {
vm.push(Value::Int32(hw.touch().x));
Ok(50)
}
Syscall::TouchGetY => {
vm.push(Value::Int32(hw.touch().y));
Ok(50)
}
Syscall::TouchIsDown => {
vm.push(Value::Boolean(hw.touch().f.down));
Ok(50)
}
Syscall::TouchIsPressed => {
vm.push(Value::Boolean(hw.touch().f.pressed));
Ok(50)
}
Syscall::TouchIsReleased => {
vm.push(Value::Boolean(hw.touch().f.released));
Ok(50)
}
Syscall::TouchGetHold => {
vm.push(Value::Int32(hw.touch().f.hold_frames as i32));
Ok(50)
}
// --- Audio Syscalls ---
@@ -15,6 +15,16 @@ pub enum Syscall {
// Input
InputGetPad = 0x2001,
InputGetPadPressed = 0x2002,
InputGetPadReleased = 0x2003,
InputGetPadHold = 0x2004,
TouchGetX = 0x2101,
TouchGetY = 0x2102,
TouchIsDown = 0x2103,
TouchIsPressed = 0x2104,
TouchIsReleased = 0x2105,
TouchGetHold = 0x2106,
// Audio
AudioPlaySample = 0x3001,
@@ -45,6 +55,15 @@ impl Syscall {
0x1005 => Some(Self::GfxDrawDisc),
0x1006 => Some(Self::GfxDrawSquare),
0x2001 => Some(Self::InputGetPad),
0x2002 => Some(Self::InputGetPadPressed),
0x2003 => Some(Self::InputGetPadReleased),
0x2004 => Some(Self::InputGetPadHold),
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),
0x4001 => Some(Self::FsOpen),
0x4002 => Some(Self::FsRead),
@@ -59,75 +78,70 @@ impl Syscall {
}
}
pub fn as_str(&self) -> &'static str {
match self {
Self::SystemHasCart => "system.has_cart",
Self::SystemRunCart => "system.run_cart",
Self::GfxClear => "gfx.clear",
Self::GfxFillRect => "gfx.fillRect",
Self::GfxDrawLine => "gfx.drawLine",
Self::GfxDrawCircle => "gfx.drawCircle",
Self::GfxDrawDisc => "gfx.drawDisc",
Self::GfxDrawSquare => "gfx.drawSquare",
Self::InputGetPad => "input.get_pad",
Self::AudioPlaySample => "audio.playSample",
Self::FsOpen => "fs.open",
Self::FsRead => "fs.read",
Self::FsWrite => "fs.write",
Self::FsClose => "fs.close",
Self::FsListDir => "fs.listDir",
Self::FsExists => "fs.exists",
Self::FsDelete => "fs.delete",
Self::LogWrite => "log.write",
Self::LogWriteTag => "log.writeTag",
}
}
// pub fn as_str(&self) -> &'static str {
// match self {
// Self::SystemHasCart => "system.has_cart",
// Self::SystemRunCart => "system.run_cart",
// Self::GfxClear => "gfx.clear",
// Self::GfxFillRect => "gfx.fillRect",
// Self::GfxDrawLine => "gfx.drawLine",
// Self::GfxDrawCircle => "gfx.drawCircle",
// Self::GfxDrawDisc => "gfx.drawDisc",
// Self::GfxDrawSquare => "gfx.drawSquare",
// Self::InputGetPad => "input.get_pad",
// Self::InputGetPadPressed => "input.get_pad_pressed",
// Self::InputGetPadReleased => "input.get_pad_released",
// Self::InputGetPadHold => "input.get_pad_hold",
// Self::TouchGetX => "touch.getX",
// Self::TouchGetY => "touch.getY",
// Self::TouchIsDown => "touch.isDown",
// Self::TouchIsPressed => "touch.isPressed",
// Self::TouchIsReleased => "touch.isReleased",
// Self::TouchGetHold => "touch.getHold",
// Self::AudioPlaySample => "audio.playSample",
// Self::FsOpen => "fs.open",
// Self::FsRead => "fs.read",
// Self::FsWrite => "fs.write",
// Self::FsClose => "fs.close",
// Self::FsListDir => "fs.listDir",
// Self::FsExists => "fs.exists",
// Self::FsDelete => "fs.delete",
// Self::LogWrite => "log.write",
// Self::LogWriteTag => "log.writeTag",
// }
// }
pub fn from_name(name: &str) -> Option<Self> {
let name_lower = name.to_lowercase();
match name_lower.as_str() {
"system.has_cart" => Some(Self::SystemHasCart),
"system.run_cart" => Some(Self::SystemRunCart),
match name {
"system.hasCart" => Some(Self::SystemHasCart),
"gfx.clear" => Some(Self::GfxClear),
"gfx.fillrect" | "gfx.draw_rect" => Some(Self::GfxFillRect),
"gfx.drawline" | "gfx.draw_line" => Some(Self::GfxDrawLine),
"gfx.drawcircle" | "gfx.draw_circle" => Some(Self::GfxDrawCircle),
"gfx.drawdisc" | "gfx.draw_disc" => Some(Self::GfxDrawDisc),
"gfx.drawsquare" | "gfx.draw_square" => Some(Self::GfxDrawSquare),
"input.get_pad" => Some(Self::InputGetPad),
"audio.playsample" | "audio.play_sample" => Some(Self::AudioPlaySample),
"gfx.fillRect" | "gfx.draw_rect" => Some(Self::GfxFillRect),
"gfx.drawLine" | "gfx.draw_line" => Some(Self::GfxDrawLine),
"gfx.drawCircle" | "gfx.draw_circle" => Some(Self::GfxDrawCircle),
"fx.drawDisc" | "gfx.draw_disc" => Some(Self::GfxDrawDisc),
"gfx.drawSquare" | "gfx.draw_square" => Some(Self::GfxDrawSquare),
"input.getPad" => Some(Self::InputGetPad),
"input.getPadPressed" | "input.get_pad_pressed" => Some(Self::InputGetPadPressed),
"input.getPadReleased" | "input.get_pad_released" => Some(Self::InputGetPadReleased),
"input.getPadHold" | "input.get_pad_hold" => Some(Self::InputGetPadHold),
"touch.getX" | "touch.get_x" => Some(Self::TouchGetX),
"touch.getY" | "touch.get_y" => Some(Self::TouchGetY),
"touch.isDown" | "touch.is_down" => Some(Self::TouchIsDown),
"touch.isPressed" | "touch.is_pressed" => Some(Self::TouchIsPressed),
"touch.isReleased" | "touch.is_released" => Some(Self::TouchIsReleased),
"touch.getHold" | "touch.get_hold" => Some(Self::TouchGetHold),
"audio.playSample" | "audio.play_sample" => Some(Self::AudioPlaySample),
"fs.open" => Some(Self::FsOpen),
"fs.read" => Some(Self::FsRead),
"fs.write" => Some(Self::FsWrite),
"fs.close" => Some(Self::FsClose),
"fs.listdir" => Some(Self::FsListDir),
"fs.listDir" | "fs.list_dir" => Some(Self::FsListDir),
"fs.exists" => Some(Self::FsExists),
"fs.delete" => Some(Self::FsDelete),
"log.write" => Some(Self::LogWrite),
"log.writetag" | "log.write_tag" => Some(Self::LogWriteTag),
"log.writeTag" | "log.write_tag" => Some(Self::LogWriteTag),
_ => {
// Tenta corresponder exatamente se o lowercase falhar (para camelCase original)
match name {
"gfx.fillRect" => Some(Self::GfxFillRect),
"gfx.drawLine" => Some(Self::GfxDrawLine),
"gfx.drawCircle" => Some(Self::GfxDrawCircle),
"gfx.drawDisc" => Some(Self::GfxDrawDisc),
"gfx.drawSquare" => Some(Self::GfxDrawSquare),
"audio.playSample" => Some(Self::AudioPlaySample),
"fs.listDir" => Some(Self::FsListDir),
"log.writeTag" => Some(Self::LogWriteTag),
"Gfx.fillRect" => Some(Self::GfxFillRect),
"Gfx.drawLine" => Some(Self::GfxDrawLine),
"Gfx.drawCircle" => Some(Self::GfxDrawCircle),
"Gfx.drawDisc" => Some(Self::GfxDrawDisc),
"Gfx.drawSquare" => Some(Self::GfxDrawSquare),
"Audio.playSample" => Some(Self::AudioPlaySample),
"Fs.listDir" => Some(Self::FsListDir),
"Log.writeTag" => Some(Self::LogWriteTag),
"System.hasCart" | "System.has_cart" => Some(Self::SystemHasCart),
"System.runCart" | "System.run_cart" => Some(Self::SystemRunCart),
_ => None,
}
None
}
}
}