implements PLN-0054
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
use super::*;
|
||||
use crate::services::memcard::{MemcardSlotState, MemcardStatus};
|
||||
use crate::fs::{FsState, VirtualFS};
|
||||
use crate::services::memcard::{MemcardService, MemcardSlotState, MemcardStatus};
|
||||
use prometeu_bytecode::{TRAP_INVALID_SYSCALL, TRAP_OOB, TRAP_TYPE, Value};
|
||||
use prometeu_hal::asset::{AssetId, AssetOpStatus, BankType, SlotRef};
|
||||
use prometeu_hal::cartridge::AppMode;
|
||||
@@ -13,6 +14,7 @@ use prometeu_hal::{
|
||||
AudioOpStatus, ComposerOpStatus, HostContext, HostReturn, NativeInterface, SyscallId,
|
||||
expect_bool, expect_int,
|
||||
};
|
||||
use std::collections::HashMap;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use std::panic::{AssertUnwindSafe, catch_unwind};
|
||||
use std::sync::atomic::Ordering;
|
||||
@@ -20,6 +22,11 @@ use std::sync::atomic::Ordering;
|
||||
pub(crate) struct VmRuntimeHost<'a> {
|
||||
pub runtime: &'a mut VirtualMachineRuntime,
|
||||
pub log_service: &'a mut LogService,
|
||||
pub fs: &'a mut VirtualFS,
|
||||
pub fs_state: &'a mut FsState,
|
||||
pub memcard: &'a mut MemcardService,
|
||||
pub open_files: &'a mut HashMap<u32, String>,
|
||||
pub next_handle: &'a mut u32,
|
||||
}
|
||||
|
||||
impl Deref for VmRuntimeHost<'_> {
|
||||
@@ -419,13 +426,13 @@ impl NativeInterface for VmRuntimeHost<'_> {
|
||||
}
|
||||
Syscall::FsOpen => {
|
||||
let path = expect_string(args, 0, "path")?;
|
||||
if self.fs_state != FsState::Mounted {
|
||||
if *self.fs_state != FsState::Mounted {
|
||||
ret.push_int(-1);
|
||||
return Ok(());
|
||||
}
|
||||
let handle = self.next_handle;
|
||||
let handle = *self.next_handle;
|
||||
self.open_files.insert(handle, path);
|
||||
self.next_handle += 1;
|
||||
*self.next_handle += 1;
|
||||
ret.push_int(handle as i64);
|
||||
Ok(())
|
||||
}
|
||||
@@ -542,14 +549,8 @@ impl NativeInterface for VmRuntimeHost<'_> {
|
||||
return Ok(());
|
||||
}
|
||||
let payload = hex_decode(&payload_hex)?;
|
||||
let runtime = &mut self.runtime;
|
||||
let write = runtime.memcard.slot_write(
|
||||
&runtime.fs,
|
||||
runtime.current_app_id,
|
||||
slot,
|
||||
offset,
|
||||
&payload,
|
||||
);
|
||||
let app_id = self.current_app_id;
|
||||
let write = self.memcard.slot_write(&self.fs, app_id, slot, offset, &payload);
|
||||
ret.push_int(write.status as i64);
|
||||
ret.push_int(write.bytes_written as i64);
|
||||
Ok(())
|
||||
@@ -561,10 +562,10 @@ impl NativeInterface for VmRuntimeHost<'_> {
|
||||
return Ok(());
|
||||
}
|
||||
let status = {
|
||||
let runtime = &mut self.runtime;
|
||||
let memcard = &mut runtime.memcard;
|
||||
let fs = &mut runtime.fs;
|
||||
memcard.slot_commit(fs, runtime.current_app_id, slot)
|
||||
let app_id = self.current_app_id;
|
||||
let memcard = &mut self.memcard;
|
||||
let fs = &mut self.fs;
|
||||
memcard.slot_commit(fs, app_id, slot)
|
||||
};
|
||||
ret.push_int(status as i64);
|
||||
Ok(())
|
||||
@@ -576,10 +577,10 @@ impl NativeInterface for VmRuntimeHost<'_> {
|
||||
return Ok(());
|
||||
}
|
||||
let status = {
|
||||
let runtime = &mut self.runtime;
|
||||
let memcard = &mut runtime.memcard;
|
||||
let fs = &mut runtime.fs;
|
||||
memcard.slot_clear(fs, runtime.current_app_id, slot)
|
||||
let app_id = self.current_app_id;
|
||||
let memcard = &mut self.memcard;
|
||||
let fs = &mut self.fs;
|
||||
memcard.slot_clear(fs, app_id, slot)
|
||||
};
|
||||
ret.push_int(status as i64);
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user