implemented intrinsecs de input and specs adjustment
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
use super::*;
|
||||
use prometeu_bytecode::{TRAP_INVALID_SYSCALL, TRAP_OOB, TRAP_TYPE, Value};
|
||||
use prometeu_hal::asset::{BankType, LoadStatus, SlotRef};
|
||||
use prometeu_hal::button::Button;
|
||||
use prometeu_hal::color::Color;
|
||||
use prometeu_hal::log::{LogLevel, LogSource};
|
||||
use prometeu_hal::sprite::Sprite;
|
||||
@@ -51,51 +50,6 @@ impl VirtualMachineRuntime {
|
||||
pub(crate) fn get_color(&self, value: i64) -> Color {
|
||||
Color::from_raw(value as u16)
|
||||
}
|
||||
|
||||
pub(crate) fn get_button<'a>(
|
||||
&self,
|
||||
id: u32,
|
||||
hw: &'a dyn prometeu_hal::HardwareBridge,
|
||||
) -> Option<&'a 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(crate) fn is_button_down(
|
||||
&self,
|
||||
id: u32,
|
||||
hw: &mut dyn prometeu_hal::HardwareBridge,
|
||||
) -> bool {
|
||||
match id {
|
||||
0 => hw.pad().up().down,
|
||||
1 => hw.pad().down().down,
|
||||
2 => hw.pad().left().down,
|
||||
3 => hw.pad().right().down,
|
||||
4 => hw.pad().a().down,
|
||||
5 => hw.pad().b().down,
|
||||
6 => hw.pad().x().down,
|
||||
7 => hw.pad().y().down,
|
||||
8 => hw.pad().l().down,
|
||||
9 => hw.pad().r().down,
|
||||
10 => hw.pad().start().down,
|
||||
11 => hw.pad().select().down,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl NativeInterface for VirtualMachineRuntime {
|
||||
@@ -232,111 +186,6 @@ impl NativeInterface for VirtualMachineRuntime {
|
||||
hw.gfx_mut().clear(Color::from_raw(color_val as u16));
|
||||
Ok(())
|
||||
}
|
||||
Syscall::InputGetPad => {
|
||||
ret.push_bool(self.is_button_down(expect_int(args, 0)? as u32, hw));
|
||||
Ok(())
|
||||
}
|
||||
Syscall::InputGetPadPressed => {
|
||||
let val = self
|
||||
.get_button(expect_int(args, 0)? as u32, hw)
|
||||
.map(|b| b.pressed)
|
||||
.unwrap_or(false);
|
||||
ret.push_bool(val);
|
||||
Ok(())
|
||||
}
|
||||
Syscall::InputGetPadReleased => {
|
||||
let val = self
|
||||
.get_button(expect_int(args, 0)? as u32, hw)
|
||||
.map(|b| b.released)
|
||||
.unwrap_or(false);
|
||||
ret.push_bool(val);
|
||||
Ok(())
|
||||
}
|
||||
Syscall::InputGetPadHold => {
|
||||
let val = self
|
||||
.get_button(expect_int(args, 0)? as u32, hw)
|
||||
.map(|b| b.hold_frames)
|
||||
.unwrap_or(0);
|
||||
ret.push_int(val as i64);
|
||||
Ok(())
|
||||
}
|
||||
Syscall::TouchGetX => {
|
||||
ret.push_int(hw.touch().x() as i64);
|
||||
Ok(())
|
||||
}
|
||||
Syscall::TouchGetY => {
|
||||
ret.push_int(hw.touch().y() as i64);
|
||||
Ok(())
|
||||
}
|
||||
Syscall::TouchIsDown => {
|
||||
ret.push_bool(hw.touch().f().down);
|
||||
Ok(())
|
||||
}
|
||||
Syscall::TouchIsPressed => {
|
||||
ret.push_bool(hw.touch().f().pressed);
|
||||
Ok(())
|
||||
}
|
||||
Syscall::TouchIsReleased => {
|
||||
ret.push_bool(hw.touch().f().released);
|
||||
Ok(())
|
||||
}
|
||||
Syscall::TouchGetHold => {
|
||||
ret.push_int(hw.touch().f().hold_frames as i64);
|
||||
Ok(())
|
||||
}
|
||||
Syscall::TouchGetFinger => {
|
||||
let btn = hw.touch().f();
|
||||
ret.push_bool(btn.pressed);
|
||||
ret.push_bool(btn.released);
|
||||
ret.push_bool(btn.down);
|
||||
ret.push_int(btn.hold_frames as i64);
|
||||
Ok(())
|
||||
}
|
||||
Syscall::InputPadSnapshot => {
|
||||
let pad = hw.pad();
|
||||
for btn in [
|
||||
pad.up(),
|
||||
pad.down(),
|
||||
pad.left(),
|
||||
pad.right(),
|
||||
pad.a(),
|
||||
pad.b(),
|
||||
pad.x(),
|
||||
pad.y(),
|
||||
pad.l(),
|
||||
pad.r(),
|
||||
pad.start(),
|
||||
pad.select(),
|
||||
] {
|
||||
ret.push_bool(btn.pressed);
|
||||
ret.push_bool(btn.released);
|
||||
ret.push_bool(btn.down);
|
||||
ret.push_int(btn.hold_frames as i64);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
Syscall::InputTouchSnapshot => {
|
||||
let touch = hw.touch();
|
||||
ret.push_bool(touch.f().pressed);
|
||||
ret.push_bool(touch.f().released);
|
||||
ret.push_bool(touch.f().down);
|
||||
ret.push_int(touch.f().hold_frames as i64);
|
||||
ret.push_int(touch.x() as i64);
|
||||
ret.push_int(touch.y() as i64);
|
||||
Ok(())
|
||||
}
|
||||
Syscall::PadGetUp => push_button(ret, hw.pad().up()),
|
||||
Syscall::PadGetDown => push_button(ret, hw.pad().down()),
|
||||
Syscall::PadGetLeft => push_button(ret, hw.pad().left()),
|
||||
Syscall::PadGetRight => push_button(ret, hw.pad().right()),
|
||||
Syscall::PadGetA => push_button(ret, hw.pad().a()),
|
||||
Syscall::PadGetB => push_button(ret, hw.pad().b()),
|
||||
Syscall::PadGetX => push_button(ret, hw.pad().x()),
|
||||
Syscall::PadGetY => push_button(ret, hw.pad().y()),
|
||||
Syscall::PadGetL => push_button(ret, hw.pad().l()),
|
||||
Syscall::PadGetR => push_button(ret, hw.pad().r()),
|
||||
Syscall::PadGetStart => push_button(ret, hw.pad().start()),
|
||||
Syscall::PadGetSelect => push_button(ret, hw.pad().select()),
|
||||
Syscall::AudioPlaySample => {
|
||||
let sample_id = expect_int(args, 0)? as u32;
|
||||
let voice_id = expect_int(args, 1)? as usize;
|
||||
@@ -521,14 +370,6 @@ impl NativeInterface for VirtualMachineRuntime {
|
||||
}
|
||||
}
|
||||
|
||||
fn push_button(ret: &mut HostReturn, button: &Button) -> Result<(), VmFault> {
|
||||
ret.push_bool(button.pressed);
|
||||
ret.push_bool(button.released);
|
||||
ret.push_bool(button.down);
|
||||
ret.push_int(button.hold_frames as i64);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn expect_string(args: &[Value], index: usize, field: &str) -> Result<String, VmFault> {
|
||||
match args.get(index).ok_or_else(|| VmFault::Panic(format!("Missing {}", field)))? {
|
||||
Value::String(value) => Ok(value.clone()),
|
||||
|
||||
Reference in New Issue
Block a user