Implement reading from real memory

This commit is contained in:
2025-01-02 01:10:19 -05:00
parent 82c3104ab9
commit be8cdd958a
4 changed files with 101 additions and 21 deletions
+10 -1
View File
@@ -1,4 +1,4 @@
use std::{ffi::c_void, ptr, slice};
use std::{ffi::c_void, ops::Range, ptr, slice};
use anyhow::{anyhow, Result};
use bitflags::bitflags;
@@ -101,6 +101,8 @@ extern "C" {
fn vb_get_user_data(sim: *mut VB) -> *mut c_void;
#[link_name = "vbInit"]
fn vb_init(sim: *mut VB) -> *mut VB;
#[link_name = "vbRead"]
fn vb_read(sim: *mut VB, address: u32, typ_: VBDataType) -> i32;
#[link_name = "vbReset"]
fn vb_reset(sim: *mut VB);
#[link_name = "vbSetCartRAM"]
@@ -314,6 +316,13 @@ impl Sim {
VBRegister::PC => unsafe { vb_get_program_counter(self.sim) },
}
}
pub fn read_memory(&mut self, addresses: Range<u32>, into: &mut Vec<u8>) {
for address in addresses {
let byte = unsafe { vb_read(self.sim, address, VBDataType::U8) };
into.push(byte as u8);
}
}
}
impl Drop for Sim {