implements PLN-0076 render capability split
This commit is contained in:
@@ -188,6 +188,17 @@ impl NativeInterface for VmRuntimeHost<'_> {
|
||||
hw.gfx_mut().clear(color);
|
||||
Ok(())
|
||||
}
|
||||
Syscall::GfxUiClear => {
|
||||
if self.current_cartridge_app_mode != AppMode::Shell {
|
||||
return Err(VmFault::Trap(
|
||||
TRAP_INVALID_SYSCALL,
|
||||
format!("{} is only available to the Shell profile", syscall.name()),
|
||||
));
|
||||
}
|
||||
let color = self.get_color(expect_int(args, 0)?)?;
|
||||
hw.gfx_mut().clear(color);
|
||||
Ok(())
|
||||
}
|
||||
Syscall::GfxFillRect => {
|
||||
let x = expect_int(args, 0)? as i32;
|
||||
let y = expect_int(args, 1)? as i32;
|
||||
@@ -197,6 +208,21 @@ impl NativeInterface for VmRuntimeHost<'_> {
|
||||
hw.gfx_mut().fill_rect(x, y, w, h, color);
|
||||
Ok(())
|
||||
}
|
||||
Syscall::GfxUiFillRect => {
|
||||
if self.current_cartridge_app_mode != AppMode::Shell {
|
||||
return Err(VmFault::Trap(
|
||||
TRAP_INVALID_SYSCALL,
|
||||
format!("{} is only available to the Shell profile", syscall.name()),
|
||||
));
|
||||
}
|
||||
let x = expect_int(args, 0)? as i32;
|
||||
let y = expect_int(args, 1)? as i32;
|
||||
let w = expect_int(args, 2)? as i32;
|
||||
let h = expect_int(args, 3)? as i32;
|
||||
let color = self.get_color(expect_int(args, 4)?)?;
|
||||
hw.gfx_mut().fill_rect(x, y, w, h, color);
|
||||
Ok(())
|
||||
}
|
||||
Syscall::GfxDrawLine => {
|
||||
let x1 = expect_int(args, 0)? as i32;
|
||||
let y1 = expect_int(args, 1)? as i32;
|
||||
@@ -206,6 +232,21 @@ impl NativeInterface for VmRuntimeHost<'_> {
|
||||
hw.gfx_mut().draw_line(x1, y1, x2, y2, color);
|
||||
Ok(())
|
||||
}
|
||||
Syscall::GfxUiDrawLine => {
|
||||
if self.current_cartridge_app_mode != AppMode::Shell {
|
||||
return Err(VmFault::Trap(
|
||||
TRAP_INVALID_SYSCALL,
|
||||
format!("{} is only available to the Shell profile", syscall.name()),
|
||||
));
|
||||
}
|
||||
let x1 = expect_int(args, 0)? as i32;
|
||||
let y1 = expect_int(args, 1)? as i32;
|
||||
let x2 = expect_int(args, 2)? as i32;
|
||||
let y2 = expect_int(args, 3)? as i32;
|
||||
let color = self.get_color(expect_int(args, 4)?)?;
|
||||
hw.gfx_mut().draw_line(x1, y1, x2, y2, color);
|
||||
Ok(())
|
||||
}
|
||||
Syscall::GfxDrawCircle => {
|
||||
let x = expect_int(args, 0)? as i32;
|
||||
let y = expect_int(args, 1)? as i32;
|
||||
@@ -214,6 +255,20 @@ impl NativeInterface for VmRuntimeHost<'_> {
|
||||
hw.gfx_mut().draw_circle(x, y, r, color);
|
||||
Ok(())
|
||||
}
|
||||
Syscall::GfxUiDrawCircle => {
|
||||
if self.current_cartridge_app_mode != AppMode::Shell {
|
||||
return Err(VmFault::Trap(
|
||||
TRAP_INVALID_SYSCALL,
|
||||
format!("{} is only available to the Shell profile", syscall.name()),
|
||||
));
|
||||
}
|
||||
let x = expect_int(args, 0)? as i32;
|
||||
let y = expect_int(args, 1)? as i32;
|
||||
let r = expect_int(args, 2)? as i32;
|
||||
let color = self.get_color(expect_int(args, 3)?)?;
|
||||
hw.gfx_mut().draw_circle(x, y, r, color);
|
||||
Ok(())
|
||||
}
|
||||
Syscall::GfxDrawDisc => {
|
||||
let x = expect_int(args, 0)? as i32;
|
||||
let y = expect_int(args, 1)? as i32;
|
||||
@@ -223,6 +278,21 @@ impl NativeInterface for VmRuntimeHost<'_> {
|
||||
hw.gfx_mut().draw_disc(x, y, r, border_color, fill_color);
|
||||
Ok(())
|
||||
}
|
||||
Syscall::GfxUiDrawDisc => {
|
||||
if self.current_cartridge_app_mode != AppMode::Shell {
|
||||
return Err(VmFault::Trap(
|
||||
TRAP_INVALID_SYSCALL,
|
||||
format!("{} is only available to the Shell profile", syscall.name()),
|
||||
));
|
||||
}
|
||||
let x = expect_int(args, 0)? as i32;
|
||||
let y = expect_int(args, 1)? as i32;
|
||||
let r = expect_int(args, 2)? as i32;
|
||||
let border_color = self.get_color(expect_int(args, 3)?)?;
|
||||
let fill_color = self.get_color(expect_int(args, 4)?)?;
|
||||
hw.gfx_mut().draw_disc(x, y, r, border_color, fill_color);
|
||||
Ok(())
|
||||
}
|
||||
Syscall::GfxDrawSquare => {
|
||||
let x = expect_int(args, 0)? as i32;
|
||||
let y = expect_int(args, 1)? as i32;
|
||||
@@ -233,6 +303,22 @@ impl NativeInterface for VmRuntimeHost<'_> {
|
||||
hw.gfx_mut().draw_square(x, y, w, h, border_color, fill_color);
|
||||
Ok(())
|
||||
}
|
||||
Syscall::GfxUiDrawSquare => {
|
||||
if self.current_cartridge_app_mode != AppMode::Shell {
|
||||
return Err(VmFault::Trap(
|
||||
TRAP_INVALID_SYSCALL,
|
||||
format!("{} is only available to the Shell profile", syscall.name()),
|
||||
));
|
||||
}
|
||||
let x = expect_int(args, 0)? as i32;
|
||||
let y = expect_int(args, 1)? as i32;
|
||||
let w = expect_int(args, 2)? as i32;
|
||||
let h = expect_int(args, 3)? as i32;
|
||||
let border_color = self.get_color(expect_int(args, 4)?)?;
|
||||
let fill_color = self.get_color(expect_int(args, 5)?)?;
|
||||
hw.gfx_mut().draw_square(x, y, w, h, border_color, fill_color);
|
||||
Ok(())
|
||||
}
|
||||
Syscall::GfxDrawText => {
|
||||
let x = expect_int(args, 0)? as i32;
|
||||
let y = expect_int(args, 1)? as i32;
|
||||
@@ -241,6 +327,20 @@ impl NativeInterface for VmRuntimeHost<'_> {
|
||||
hw.gfx_mut().draw_text(x, y, &msg, color);
|
||||
Ok(())
|
||||
}
|
||||
Syscall::GfxUiDrawText => {
|
||||
if self.current_cartridge_app_mode != AppMode::Shell {
|
||||
return Err(VmFault::Trap(
|
||||
TRAP_INVALID_SYSCALL,
|
||||
format!("{} is only available to the Shell profile", syscall.name()),
|
||||
));
|
||||
}
|
||||
let x = expect_int(args, 0)? as i32;
|
||||
let y = expect_int(args, 1)? as i32;
|
||||
let msg = expect_string(args, 2, "message")?;
|
||||
let color = self.get_color(expect_int(args, 3)?)?;
|
||||
hw.gfx_mut().draw_text(x, y, &msg, color);
|
||||
Ok(())
|
||||
}
|
||||
Syscall::ComposerBindScene => {
|
||||
let scene_bank_id = match Self::int_arg_to_usize_status(expect_int(args, 0)?) {
|
||||
Ok(id) => id,
|
||||
|
||||
@@ -195,7 +195,7 @@ fn initialize_vm_applies_cartridge_capabilities_before_loader_resolution() {
|
||||
let program = serialized_single_function_module(
|
||||
code,
|
||||
vec![SyscallDecl {
|
||||
module: "gfx".into(),
|
||||
module: "gfx2d".into(),
|
||||
name: "clear".into(),
|
||||
version: 1,
|
||||
arg_slots: 1,
|
||||
@@ -221,7 +221,7 @@ fn initialize_vm_succeeds_when_cartridge_capabilities_cover_hostcalls() {
|
||||
let program = serialized_single_function_module(
|
||||
code,
|
||||
vec![SyscallDecl {
|
||||
module: "gfx".into(),
|
||||
module: "gfx2d".into(),
|
||||
name: "clear".into(),
|
||||
version: 1,
|
||||
arg_slots: 1,
|
||||
@@ -253,7 +253,7 @@ fn tick_returns_error_when_vm_ends_slice_with_trap() {
|
||||
let program = serialized_single_function_module(
|
||||
code,
|
||||
vec![SyscallDecl {
|
||||
module: "gfx".into(),
|
||||
module: "gfx2d".into(),
|
||||
name: "clear".into(),
|
||||
version: 1,
|
||||
arg_slots: 1,
|
||||
@@ -304,7 +304,7 @@ fn tick_system_profile_rejects_gfx_game_surface() {
|
||||
let program = serialized_single_function_module(
|
||||
code,
|
||||
vec![SyscallDecl {
|
||||
module: "gfx".into(),
|
||||
module: "gfx2d".into(),
|
||||
name: "clear".into(),
|
||||
version: 1,
|
||||
arg_slots: 1,
|
||||
@@ -388,6 +388,55 @@ fn tick_system_profile_rejects_composer_game_surface() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tick_game_profile_rejects_gfxui_shell_surface() {
|
||||
let mut runtime = VirtualMachineRuntime::new(None);
|
||||
let mut log_service = LogService::new(4096);
|
||||
let mut fs = VirtualFS::new();
|
||||
let mut fs_state = FsState::Unmounted;
|
||||
let mut memcard = MemcardService::new();
|
||||
let mut open_files: HashMap<u32, String> = HashMap::new();
|
||||
let mut next_handle = 1;
|
||||
let mut vm = VirtualMachine::default();
|
||||
let mut hardware = Hardware::new();
|
||||
let signals = InputSignals::default();
|
||||
let code = assemble("PUSH_I32 0\nHOSTCALL 0\nHALT").expect("assemble");
|
||||
let program = serialized_single_function_module(
|
||||
code,
|
||||
vec![SyscallDecl {
|
||||
module: "gfxui".into(),
|
||||
name: "clear".into(),
|
||||
version: 1,
|
||||
arg_slots: 1,
|
||||
ret_slots: 0,
|
||||
}],
|
||||
);
|
||||
let cartridge = cartridge_with_program_and_mode(program, caps::GFXUI, AppMode::Game);
|
||||
|
||||
runtime.initialize_vm(&mut log_service, &mut vm, &cartridge).expect("runtime must initialize");
|
||||
let report = runtime
|
||||
.tick(
|
||||
&mut log_service,
|
||||
&mut fs,
|
||||
&mut fs_state,
|
||||
&mut memcard,
|
||||
&mut open_files,
|
||||
&mut next_handle,
|
||||
&mut vm,
|
||||
&signals,
|
||||
&mut hardware,
|
||||
)
|
||||
.expect("game gfxui call must trap");
|
||||
|
||||
match report {
|
||||
CrashReport::VmTrap { trap } => {
|
||||
assert_eq!(trap.code, prometeu_bytecode::TRAP_INVALID_SYSCALL);
|
||||
assert!(trap.message.contains("GfxUiClear is only available to the Shell profile"));
|
||||
}
|
||||
other => panic!("expected VmTrap crash report, got {:?}", other),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tick_system_profile_rejects_bank_game_surface() {
|
||||
let mut runtime = VirtualMachineRuntime::new(None);
|
||||
@@ -655,7 +704,7 @@ fn tick_draw_text_survives_no_scene_frame_path() {
|
||||
code,
|
||||
vec![ConstantPoolEntry::String("I".into())],
|
||||
vec![SyscallDecl {
|
||||
module: "gfx".into(),
|
||||
module: "gfx2d".into(),
|
||||
name: "draw_text".into(),
|
||||
version: 1,
|
||||
arg_slots: 4,
|
||||
@@ -696,7 +745,7 @@ fn initialize_vm_success_clears_previous_crash_report() {
|
||||
let program = serialized_single_function_module(
|
||||
code,
|
||||
vec![SyscallDecl {
|
||||
module: "gfx".into(),
|
||||
module: "gfx2d".into(),
|
||||
name: "clear".into(),
|
||||
version: 1,
|
||||
arg_slots: 1,
|
||||
@@ -856,7 +905,7 @@ fn initialize_vm_failure_clears_previous_identity_and_handles() {
|
||||
let good_program = serialized_single_function_module(
|
||||
assemble("PUSH_I32 0\nHOSTCALL 0\nHALT").expect("assemble"),
|
||||
vec![SyscallDecl {
|
||||
module: "gfx".into(),
|
||||
module: "gfx2d".into(),
|
||||
name: "clear".into(),
|
||||
version: 1,
|
||||
arg_slots: 1,
|
||||
@@ -878,7 +927,7 @@ fn initialize_vm_failure_clears_previous_identity_and_handles() {
|
||||
let bad_program = serialized_single_function_module(
|
||||
assemble("PUSH_I32 0\nHOSTCALL 0\nHALT").expect("assemble"),
|
||||
vec![SyscallDecl {
|
||||
module: "gfx".into(),
|
||||
module: "gfx2d".into(),
|
||||
name: "clear".into(),
|
||||
version: 1,
|
||||
arg_slots: 1,
|
||||
|
||||
Reference in New Issue
Block a user