This commit is contained in:
Logan McNaughton
2023-10-04 22:43:36 -06:00
parent 20b0d88727
commit 06738ea965
4 changed files with 25 additions and 18 deletions
+1
View File
@@ -6,6 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
sha2 = "0.10"
sdl2-sys = { git = "https://github.com/Rust-SDL2/rust-sdl2.git" }
[dependencies.sdl2]
+2
View File
@@ -47,6 +47,7 @@ pub struct Device {
ai: ai::Ai,
si: si::Si,
ri: ri::Ri,
game: String,
}
impl Device {
@@ -59,6 +60,7 @@ impl Device {
byte_swap = 3;
}
Device {
game: String::new(),
ui: ui::Ui::new(),
byte_swap: byte_swap,
cpu: cpu::Cpu {
+18 -14
View File
@@ -1,6 +1,5 @@
use crate::device;
use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher};
use sha2::{Digest, Sha256};
pub enum CicType {
CicNus6101,
@@ -95,7 +94,12 @@ pub fn dma_write(device: &mut device::Device, cart_addr: u32, dram_addr: u32, le
pub fn init(device: &mut device::Device, rom_file: Vec<u8>) {
device.cart.rom = rom_file;
set_system_region(device, device.cart.rom[0x3E]);
set_cic(device)
set_cic(device);
let data =
std::str::from_utf8(&device.cart.rom[0x20 as usize..(0x20 + 0x14) as usize]).unwrap();
let hash = calculate_hash(&device.cart.rom);
device.game = format!("{}-{}", data.trim(), hash);
}
pub fn set_system_region(device: &mut device::Device, country: u8) {
@@ -109,28 +113,28 @@ pub fn set_system_region(device: &mut device::Device, country: u8) {
pub fn set_cic(device: &mut device::Device) {
let hash = calculate_hash(&device.cart.rom[0x40..0x1000]);
match hash {
0x83a9a60ad75b3ed9 => {
match hash.as_str() {
"B99F06C4802C2377E31E388435955EF3E99C618A6D55D24699D828EB1075F1EB" => {
device.cart.cic_type = CicType::CicNus6101;
device.cart.cic_seed = 0x3F;
device.cart.rdram_size_offset = 0x318;
}
0x3c1e2f5171ec2b8 => {
"61E88238552C356C23D19409FE5570EE6910419586BC6FC740F638F761ADC46E" => {
device.cart.cic_type = CicType::CicNus6102;
device.cart.cic_seed = 0x3F;
device.cart.rdram_size_offset = 0x318;
}
0xdbdb0cb696006257 => {
"BF3620D30817007091EBE9BDDD1B88C23B8A0052170B3309CDE5B6B4238E45E7" => {
device.cart.cic_type = CicType::CicNus6103;
device.cart.cic_seed = 0x78;
device.cart.rdram_size_offset = 0x318;
}
0x3d51ac3a48960357 => {
"04B7BC6717A9F0EB724CF927E74AD3876C381CBB280D841736FC5E55580B756B" => {
device.cart.cic_type = CicType::CicNus6105;
device.cart.cic_seed = 0x91;
device.cart.rdram_size_offset = 0x3F0;
}
0x90135a02ea97ba9f => {
"36ADC40148AF56F0D78CD505EB6A90117D1FD6F11C6309E52ED36BC4C6BA340E" => {
device.cart.cic_type = CicType::CicNus6106;
device.cart.cic_seed = 0x85;
device.cart.rdram_size_offset = 0x318;
@@ -139,13 +143,13 @@ pub fn set_cic(device: &mut device::Device) {
device.cart.cic_type = CicType::CicNus6102;
device.cart.cic_seed = 0x3F;
device.cart.rdram_size_offset = 0x318;
println!("unknown IPL3 {:#01x}", hash)
println!("unknown IPL3 {}", hash)
}
}
}
fn calculate_hash<T: Hash>(t: &[T]) -> u64 {
let mut s = DefaultHasher::new();
t.hash(&mut s);
s.finish()
fn calculate_hash(data: &[u8]) -> String {
let mut hasher = Sha256::new();
hasher.update(data);
format!("{:X}", hasher.finalize())
}
+4 -4
View File
@@ -1,5 +1,4 @@
use crate::device;
use std::str;
pub const IS_VIEWER_MASK: usize = 0xFFFF;
@@ -20,9 +19,10 @@ pub fn write_mem(device: &mut device::Device, address: u64, value: u32, mask: u3
let masked_address = address as usize & IS_VIEWER_MASK;
if masked_address == 0x14 {
let length = (value & mask) as u64;
let data =
str::from_utf8(&device.cart.is_viewer_buffer[0x20 as usize..(0x20 + length) as usize])
.unwrap();
let data = std::str::from_utf8(
&device.cart.is_viewer_buffer[0x20 as usize..(0x20 + length) as usize],
)
.unwrap();
print!("{}", data);
} else {
let mut data = u32::from_be_bytes(