Skip to content

Commit 11e4190

Browse files
committed
Auto detect if arm7 block validation is needed
1 parent 802a461 commit 11e4190

File tree

5 files changed

+24
-25
lines changed

5 files changed

+24
-25
lines changed

src/core/cycle_manager.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::core::emu::Emu;
44
use crate::core::CpuType;
55
use crate::core::CpuType::{ARM7, ARM9};
66
use std::cmp::max;
7-
use std::intrinsics::likely;
7+
use std::intrinsics::{likely, unlikely};
88
use std::mem;
99

1010
#[repr(u8)]
@@ -130,7 +130,11 @@ impl CycleManager {
130130
}
131131

132132
pub fn schedule(&mut self, in_cycles: u32, event_type: EventType) {
133-
let event_cycle = self.cycle_count + max(in_cycles, 1);
133+
let mut in_cycles = max(in_cycles, 1);
134+
if unlikely(u32::MAX - in_cycles < self.cycle_count) {
135+
in_cycles = u32::MAX - self.cycle_count;
136+
}
137+
let event_cycle = self.cycle_count + in_cycles;
134138
self.events[event_type as usize] = event_cycle;
135139
self.active_events |= 1 << (31 - event_type as u8);
136140
if event_cycle < self.next_event_cycle {

src/core/emu.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ pub struct NitroSdkVersion {
3131
major: u8,
3232
}
3333

34+
impl NitroSdkVersion {
35+
pub fn is_valid(self) -> bool {
36+
u32::from(self) != u32::MAX
37+
}
38+
}
39+
40+
impl Default for NitroSdkVersion {
41+
fn default() -> Self {
42+
NitroSdkVersion::from(u32::MAX)
43+
}
44+
}
45+
3446
pub struct Emu {
3547
pub ipc: Ipc,
3648
pub cartridge: Cartridge,
@@ -76,7 +88,7 @@ impl Emu {
7688
wifi: Wifi::new(),
7789
jit,
7890
settings: DEFAULT_SETTINGS.clone(),
79-
nitro_sdk_version: NitroSdkVersion::from(u32::MAX),
91+
nitro_sdk_version: NitroSdkVersion::default(),
8092
breakout_imm: false,
8193
initialized: true,
8294
}
@@ -102,7 +114,7 @@ impl Emu {
102114
self.timers = [Timers::new(), Timers::new()];
103115
self.wifi = Wifi::new();
104116
}
105-
self.nitro_sdk_version = NitroSdkVersion::from(u32::MAX);
117+
self.nitro_sdk_version = NitroSdkVersion::default();
106118
self.initialized = false;
107119
}
108120
}

src/jit/jit_asm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ fn emit_code_block_internal(asm: &mut JitAsm, guest_pc: u32, thumb: bool) {
470470
let mut block_asm = BlockAsm::new(asm.cpu, thumb);
471471
block_asm.prologue(asm.analyzer.basic_blocks.len());
472472

473-
if asm.cpu == ARM7 && guest_pc & 0xFF000000 != regions::VRAM_OFFSET && asm.emu.settings.arm7_block_validation() {
473+
if asm.cpu == ARM7 && guest_pc & 0xFF000000 != regions::VRAM_OFFSET && !asm.emu.nitro_sdk_version.is_valid() {
474474
let guest_ptr = ARM7.mmu_tcm_addr() + (guest_pc as usize & 0xFFFFFFF);
475475
let size = (guest_pc_end - guest_pc + pc_step) as usize;
476476
let hash = xxh32(unsafe { slice::from_raw_parts(guest_ptr as _, size) }, 0);

src/presenter/linux.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,12 @@ impl Presenter {
7272
.arg(arg!(framelimit: -f "Enable framelimit").required(false).action(ArgAction::SetTrue))
7373
.arg(arg!(audio: -a "Enable audio").required(false).action(ArgAction::SetTrue))
7474
.arg(
75-
arg!(-e <arm7_emu> "0: Accurate, 1: Partial, 2: Partial with Sound, 3: Hle")
75+
arg!(-e <arm7_emu> "0: Accurate, 1: SoundHle, 2: Hle")
7676
.num_args(1)
7777
.required(false)
7878
.default_value("0")
7979
.value_parser(value_parser!(u8)),
8080
)
81-
.arg(arg!(enable_arm7_block_validation: -b "Enable arm7 block validation").required(false).action(ArgAction::SetTrue))
8281
.arg(arg!(ui: --ui "Use UI").required(false).action(ArgAction::SetTrue))
8382
.arg(arg!([nds_rom] "NDS rom to run").num_args(1).required(true).value_parser(value_parser!(String)))
8483
.get_matches();
@@ -164,7 +163,6 @@ impl Presenter {
164163
settings.set_framelimit(self.arg_matches.get_flag("framelimit"));
165164
settings.set_audio(self.arg_matches.get_flag("audio"));
166165
settings.set_arm7_emu(Arm7Emu::from(*self.arg_matches.get_one::<u8>("arm7_emu").unwrap_or(&0)));
167-
settings.set_arm7_block_validation(self.arg_matches.get_flag("enable_arm7_block_validation"));
168166

169167
let file_name = file_path.file_name().unwrap().to_str().unwrap();
170168
let save_path = file_path.parent().unwrap().join(format!("{file_name}.sav"));

src/settings.rs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -173,18 +173,12 @@ lazy_static! {
173173
Setting::new("Bottom screen scale", "Press PS + Circle to cycle screen sizes", ScreenLayout::scale_settings_value(), true),
174174
Setting::new("Language", "Some ROMs only come with one language. Make sure yours is multilingual.", Language::iter().into(), false),
175175
Setting::new("Joystick as D-Pad", "", SettingValue::Bool(true), true),
176-
Setting::new(
177-
"Arm7 jit block validation",
178-
"Only needed for nds homebrew. Commercial games usually don't need to have this enabled.",
179-
SettingValue::Bool(false),
180-
false,
181-
),
182176
],
183177
);
184178
}
185179

186180
#[derive(Clone)]
187-
pub struct Settings([Setting; 11]);
181+
pub struct Settings([Setting; 10]);
188182

189183
#[repr(u8)]
190184
enum SettingIndices {
@@ -198,7 +192,6 @@ enum SettingIndices {
198192
BottomScreenScale,
199193
Language,
200194
JoystickAsDpad,
201-
Arm7BlockValidation,
202195
}
203196

204197
impl Settings {
@@ -229,10 +222,6 @@ impl Settings {
229222
unsafe { Arm7Emu::from(self.0[SettingIndices::Arm7Emu as usize].value.as_list().unwrap_unchecked().0 as u8) }
230223
}
231224

232-
pub fn arm7_block_validation(&self) -> bool {
233-
unsafe { self.0[SettingIndices::Arm7BlockValidation as usize].value.as_bool().unwrap_unchecked() }
234-
}
235-
236225
pub fn audio_stretching(&self) -> bool {
237226
unsafe { self.0[SettingIndices::AudioStretching as usize].value.as_bool().unwrap_unchecked() }
238227
}
@@ -258,11 +247,7 @@ impl Settings {
258247
*self.0[SettingIndices::Arm7Emu as usize].value.as_list_mut().unwrap().0 = value as usize
259248
}
260249

261-
pub fn set_arm7_block_validation(&mut self, value: bool) {
262-
*self.0[SettingIndices::Arm7BlockValidation as usize].value.as_bool_mut().unwrap() = value;
263-
}
264-
265-
pub fn get_all_mut(&mut self) -> &mut [Setting; 11] {
250+
pub fn get_all_mut(&mut self) -> &mut [Setting; 10] {
266251
&mut self.0
267252
}
268253
}

0 commit comments

Comments
 (0)