Skip to content

Commit

Permalink
Add "DS ROM info" debug view
Browse files Browse the repository at this point in the history
  • Loading branch information
kelpsyberry committed Mar 30, 2024
1 parent 35012a7 commit 43640f0
Show file tree
Hide file tree
Showing 9 changed files with 517 additions and 53 deletions.
56 changes: 29 additions & 27 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions core/src/ds_slot/rom/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,8 @@ pub enum Region {

impl<'a> Header<'a> {
#[inline]
pub fn new(bytes: &'a [u8]) -> Option<Self> {
if bytes.len() < 0x170 {
return None;
}
Some(Header(bytes))
pub fn new(bytes: &'a [u8; 0x170]) -> Self {
Header(bytes)
}

#[inline]
Expand Down
12 changes: 10 additions & 2 deletions core/src/ds_slot/rom/icon_title.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,12 @@ impl Titles {
}
let mut bytes = [0; 0x100];
rom_contents.read_slice(icon_title_offset + $offset, &mut bytes);
String::from_utf16le(&bytes).map_err(|_| Box::new(bytes))
let end_index = bytes
.array_chunks::<2>()
.position(|c| *c == [0; 2])
.unwrap_or(bytes.len())
<< 1;
String::from_utf16le(&bytes[..end_index]).map_err(|_| Box::new(bytes))
}};
}

Expand Down Expand Up @@ -260,8 +265,11 @@ impl IconTitle {
}

pub fn read_icon_title_offset(rom_contents: &mut (impl Contents + ?Sized)) -> Option<usize> {
if 0x170 > rom_contents.len() {
return None;
}
let mut header_bytes = Bytes::new([0; 0x170]);
rom_contents.read_header(&mut header_bytes);
let header = Header::new(&*header_bytes)?;
let header = Header::new(&header_bytes);
Some(header.icon_title_offset() as usize)
}
5 changes: 2 additions & 3 deletions core/src/emu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,10 +376,9 @@ impl<E: cpu::Engine> Emu<E> {
// TODO: More accurate direct boot

let mut header_bytes = Bytes::new([0; 0x170]);
// NOTE: The ROM file's size is ensured beforehand, this should never panic.
self.ds_slot.rom.read_header(&mut header_bytes);
let header = ds_slot::rom::header::Header::new(&*header_bytes)
// NOTE: The ROM file's size is ensured beforehand, this should never occur.
.expect("couldn't read DS slot ROM header");
let header = ds_slot::rom::header::Header::new(&header_bytes);
let chip_id = self.ds_slot.rom.chip_id();

macro_rules! write_main_mem {
Expand Down
3 changes: 2 additions & 1 deletion core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
portable_simd,
new_uninit,
str_from_utf16_endian,
array_try_from_fn
array_try_from_fn,
array_chunks
)]
#![warn(clippy::pedantic)]
#![allow(
Expand Down
6 changes: 5 additions & 1 deletion frontend/desktop/src/debug_views.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ mod bg_maps_2d;
use bg_maps_2d::BgMaps2d;
mod audio_channels;
use audio_channels::AudioChannels;
mod ds_rom_info;
use ds_rom_info::DsRomInfo;

use super::ui::window::Window;
use ahash::AHashMap as HashMap;
Expand Down Expand Up @@ -773,5 +775,7 @@ declare_structs!(
(bg_maps_2d, BgMaps2d, InitBgMaps2d, DestroyBgMaps2d, BgMaps2dVisibility, BgMaps2dCustom),
(audio_channels, AudioChannels, InitAudioChannels, DestroyAudioChannels, AudioChannelsVisibility, AudioChannelsCustom)
],
[]
[
(ds_rom_info, DsRomInfo, FetchDsRomInfo, ReplyDsRomInfo)
]
);
Loading

0 comments on commit 43640f0

Please sign in to comment.