mirror of
https://github.com/FranLMSP/rultra64.git
synced 2026-01-01 07:51:34 -05:00
HLEing boot process
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
|||||||
/target
|
/target
|
||||||
|
/roms
|
||||||
@@ -92,6 +92,13 @@ impl CPU {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn new_hle() -> Self {
|
||||||
|
Self {
|
||||||
|
registers: CPURegisters::new_hle(),
|
||||||
|
cp0: CP0Registers::new_hle(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn fetch_opcode(address: i64, mmu: &MMU) -> u32 {
|
pub fn fetch_opcode(address: i64, mmu: &MMU) -> u32 {
|
||||||
let data = mmu.read_virtual(address, 4);
|
let data = mmu.read_virtual(address, 4);
|
||||||
let opcode = ((data[0] as u32) << 24) | ((data[1] as u32) << 16) | ((data[2] as u32) << 8) | ((data[3] as u32) << 8);
|
let opcode = ((data[0] as u32) << 24) | ((data[1] as u32) << 16) | ((data[2] as u32) << 8) | ((data[3] as u32) << 8);
|
||||||
|
|||||||
27
src/emulator.rs
Normal file
27
src/emulator.rs
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
use crate::mmu::MMU;
|
||||||
|
use crate::cpu::CPU;
|
||||||
|
|
||||||
|
pub struct Emulator {
|
||||||
|
cpu: CPU,
|
||||||
|
mmu: MMU,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Emulator {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
cpu: CPU::new(),
|
||||||
|
mmu: MMU::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new_hle() -> Self {
|
||||||
|
Self {
|
||||||
|
cpu: CPU::new_hle(),
|
||||||
|
mmu: MMU::new_hle(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn tick(&mut self) {
|
||||||
|
self.cpu.fetch_and_exec_opcode(&mut self.mmu);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,3 +3,4 @@ pub mod cpu;
|
|||||||
pub mod mmu;
|
pub mod mmu;
|
||||||
pub mod rom;
|
pub mod rom;
|
||||||
pub mod rdram;
|
pub mod rdram;
|
||||||
|
pub mod emulator;
|
||||||
|
|||||||
16
src/mmu.rs
16
src/mmu.rs
@@ -62,6 +62,22 @@ impl MMU {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn new_hle() -> Self {
|
||||||
|
let mut mmu = Self::new();
|
||||||
|
// Skip IPL1 and IPL2
|
||||||
|
for i in 0..0x1000 {
|
||||||
|
let byte = mmu.read_virtual(0x10001000 + i, 1);
|
||||||
|
mmu.write_virtual(0x00001000 + i, vec![byte]);
|
||||||
|
}
|
||||||
|
// Skip IPL3
|
||||||
|
for i in 0..0x100000 {
|
||||||
|
let byte = mmu.read_physical_byte(0x10001000 + i);
|
||||||
|
mmu.write_physical_byte(0x00001000 + i, byte);
|
||||||
|
}
|
||||||
|
|
||||||
|
mmu
|
||||||
|
}
|
||||||
|
|
||||||
pub fn convert(address: i64) -> i64 {
|
pub fn convert(address: i64) -> i64 {
|
||||||
if KUSEG.contains(&address) {
|
if KUSEG.contains(&address) {
|
||||||
return address - KUSEG.min().unwrap();
|
return address - KUSEG.min().unwrap();
|
||||||
|
|||||||
@@ -79,6 +79,21 @@ impl CPURegisters {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn new_hle() -> Self {
|
||||||
|
let mut registers = Self::new();
|
||||||
|
registers.set_by_name("t3", 0xFFFFFFFFA4000040_u64 as i64);
|
||||||
|
registers.set_by_name("s4", 0x0000000000000001);
|
||||||
|
registers.set_by_name("s6", 0x000000000000003F);
|
||||||
|
registers.set_by_name("sp", 0xFFFFFFFFA4001FF0_u64 as i64);
|
||||||
|
|
||||||
|
registers.set_program_counter(0x80001000);
|
||||||
|
registers.set_next_program_counter(0x80001000 + 4);
|
||||||
|
/* registers.set_program_counter(0xA4000040);
|
||||||
|
registers.set_next_program_counter(0xA4000040 + 4); */
|
||||||
|
|
||||||
|
registers
|
||||||
|
}
|
||||||
|
|
||||||
pub fn set_load_link(&mut self, val: bool) {
|
pub fn set_load_link(&mut self, val: bool) {
|
||||||
self.load_link = val;
|
self.load_link = val;
|
||||||
}
|
}
|
||||||
@@ -238,6 +253,16 @@ impl CP0Registers {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn new_hle() -> Self {
|
||||||
|
let mut cp0 = Self::new();
|
||||||
|
cp0.set_by_name_32("random", 0x0000001F);
|
||||||
|
cp0.set_by_name_32("status", 0x70400004);
|
||||||
|
cp0.set_by_name_32("PRId", 0x00000B00);
|
||||||
|
cp0.set_by_name_32("config", 0x0006E463);
|
||||||
|
|
||||||
|
cp0
|
||||||
|
}
|
||||||
|
|
||||||
fn find_index(name: &'static str) -> usize {
|
fn find_index(name: &'static str) -> usize {
|
||||||
CP0_REGISTER_NAMES.iter().position(|v| *v == name).unwrap()
|
CP0_REGISTER_NAMES.iter().position(|v| *v == name).unwrap()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user