Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Grarak committed Nov 18, 2024
1 parent b1304de commit 3df4437
Show file tree
Hide file tree
Showing 13 changed files with 182 additions and 226 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ debug = true

[profile.release.package."*"]
opt-level = 3
debug = true

[profile.release]
panic = "abort"
lto = "fat"
debug = true
6 changes: 3 additions & 3 deletions src/bitset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ impl<const SIZE: usize> Bitset<SIZE> {
let bit = bit.into();
let array_index = bit >> 5;
let pos_index = bit & 31;
self.0[array_index] |= 1 << pos_index;
unsafe { *self.0.get_unchecked_mut(array_index) |= 1 << pos_index };
}

fn _sub(&mut self, bit: impl Into<usize>) {
let bit = bit.into();
let array_index = bit >> 5;
let pos_index = bit & 31;
self.0[array_index] &= !(1 << pos_index);
unsafe { *self.0.get_unchecked_mut(array_index) &= !(1 << pos_index) };
}

pub fn contains(&self, bit: impl Into<usize>) -> bool {
let bit = bit.into();
let array_index = bit >> 5;
let pos_index = bit & 31;
self.0[array_index] & (1 << pos_index) != 0
unsafe { *self.0.get_unchecked(array_index) & (1 << pos_index) != 0 }
}

pub const fn len(&self) -> usize {
Expand Down
4 changes: 2 additions & 2 deletions src/core/graphics/gpu_3d/registers_3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1387,13 +1387,13 @@ impl Gpu3DRegisters {
self.queue_entry(Entry::new(self.gx_fifo as u8, value & mask), emu);
self.cmd_fifo_param_count += 1;

if self.cmd_fifo_param_count == FIFO_PARAM_COUNTS[(self.gx_fifo & 0xFF) as usize] as u32 {
if self.cmd_fifo_param_count == unsafe { *FIFO_PARAM_COUNTS.get_unchecked((self.gx_fifo & 0xFF) as usize) } as u32 {
self.gx_fifo >>= 8;
self.cmd_fifo_param_count = 0;
}
}

while self.gx_fifo != 0 && FIFO_PARAM_COUNTS[(self.gx_fifo & 0xFF) as usize] == 0 {
while self.gx_fifo != 0 && unsafe { *FIFO_PARAM_COUNTS.get_unchecked((self.gx_fifo & 0xFF) as usize) } == 0 {
self.queue_entry(Entry::new(self.gx_fifo as u8, value & mask), emu);
self.gx_fifo >>= 8;
}
Expand Down
20 changes: 10 additions & 10 deletions src/core/hle/sound_nitro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ impl SoundNitro {

let mut main_cnt = MainSoundCnt::from(0);
main_cnt.set_master_volume(u7::new(0x7F));
main_cnt.set_master_enable(u1::new(1));
main_cnt.set_master_enable(true);
get_spu_mut!(emu).set_main_sound_cnt(!0, u16::from(main_cnt), emu);

get_cm_mut!(emu).schedule(174592, EventType::SoundCmdHle);
Expand Down Expand Up @@ -247,9 +247,9 @@ impl SoundNitro {
fn stop_channel(chan_id: usize, hold: bool, emu: &mut Emu) {
let spu = get_spu_mut!(emu);
let mut cnt = SoundCnt::from(spu.get_cnt(chan_id));
cnt.set_start_status(u1::new(0));
cnt.set_start_status(false);
if hold {
cnt.set_hold(u1::new(1));
cnt.set_hold(true);
}
spu.set_cnt(chan_id, !0, u32::from(cnt), emu);
}
Expand Down Expand Up @@ -488,7 +488,7 @@ impl SoundNitro {
if channel.status_flags & (1 << 3) != 0 {
let spu = get_spu_mut!(emu);
let mut cnt = SoundCnt::from(spu.get_cnt(i));
cnt.set_start_status(u1::new(1));
cnt.set_start_status(true);
spu.set_cnt(i, !0, u32::from(cnt), emu);
}

Expand Down Expand Up @@ -803,21 +803,21 @@ impl SoundNitro {

let spu = get_spu_mut!(emu);
let mut cnt = SoundCnt::from(spu.get_cnt(i));
cnt.set_start_status(u1::new(1));
cnt.set_start_status(true);
spu.set_cnt(i, !0, u32::from(cnt), emu);
}

if mask_cap & 0x1 != 0 {
let spu = get_spu_mut!(emu);
let mut cap_cnt = SoundCapCnt::from(spu.get_snd_cap_cnt(0));
cap_cnt.set_cap_start_status(u1::new(1));
cap_cnt.set_cap_start_status(true);
spu.set_snd_cap_cnt(0, u8::from(cap_cnt));
}

if mask_cap & 0x2 != 0 {
let spu = get_spu_mut!(emu);
let mut cap_cnt = SoundCapCnt::from(spu.get_snd_cap_cnt(1));
cap_cnt.set_cap_start_status(u1::new(1));
cap_cnt.set_cap_start_status(true);
spu.set_snd_cap_cnt(1, u8::from(cap_cnt));
}

Expand Down Expand Up @@ -1008,11 +1008,11 @@ impl SoundNitro {

let spu = get_spu_mut!(emu);
let mut cnt = MainSoundCnt::from(spu.get_main_sound_cnt());
cnt.set_master_enable(u1::new(1));
cnt.set_master_enable(true);
cnt.set_left_output_from(u2::new((output_l & 0x3) as u8));
cnt.set_right_output_from(u2::new((output_r & 0x3) as u8));
cnt.set_output_ch1_to_mixer(u1::new((mixch1 & 0x1) as u8));
cnt.set_output_ch3_to_mixer(u1::new((mixch3 & 0x1) as u8));
cnt.set_output_ch1_to_mixer((mixch1 & 0x1) != 0);
cnt.set_output_ch3_to_mixer((mixch3 & 0x1) != 0);
spu.set_main_sound_cnt(!0, u16::from(cnt), emu);
}
0x1A => {}
Expand Down
46 changes: 23 additions & 23 deletions src/core/spu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ pub struct SoundCnt {
not_used: u1,
pub volume_div: u2,
not_used1: u5,
pub hold: u1,
pub hold: bool,
pub panning: u7,
not_used2: u1,
pub wave_duty: u3,
pub repeat_mode: u2,
pub format: u2,
pub start_status: u1,
pub start_status: bool,
}

impl SoundCnt {
Expand Down Expand Up @@ -123,10 +123,10 @@ pub struct MainSoundCnt {
not_used: u1,
pub left_output_from: u2,
pub right_output_from: u2,
pub output_ch1_to_mixer: u1,
pub output_ch3_to_mixer: u1,
pub output_ch1_to_mixer: bool,
pub output_ch3_to_mixer: bool,
not_used2: u1,
pub master_enable: u1,
pub master_enable: bool,
}

#[derive(Copy, Clone, Default)]
Expand Down Expand Up @@ -159,12 +159,12 @@ struct AdpcmHeader {
#[bitsize(8)]
#[derive(FromBits)]
pub struct SoundCapCnt {
pub cnt_associated_channels: u1,
pub cap_src_select: u1,
pub cap_repeat: u1,
pub cap_format: u1,
pub cnt_associated_channels: bool,
pub cap_src_select: bool,
pub cap_repeat: bool,
pub cap_format: bool,
not_used: u3,
pub cap_start_status: u1,
pub cap_start_status: bool,
}

pub struct Spu {
Expand Down Expand Up @@ -211,7 +211,7 @@ impl Spu {
}

pub fn set_cnt(&mut self, channel: usize, mut mask: u32, value: u32, emu: &mut Emu) {
let was_disabled = !bool::from(self.channels[channel].cnt.start_status());
let was_disabled = !self.channels[channel].cnt.start_status();

mask &= 0xFF7F837F;
self.channels[channel].cnt = ((u32::from(self.channels[channel].cnt) & !mask) | (value & mask)).into();
Expand All @@ -222,12 +222,12 @@ impl Spu {
self.channels[channel].volume = volume;

if was_disabled
&& bool::from(self.channels[channel].cnt.start_status())
&& bool::from(self.main_sound_cnt.master_enable())
&& self.channels[channel].cnt.start_status()
&& self.main_sound_cnt.master_enable()
&& (self.channels[channel].sad != 0 || self.channels[channel].cnt.get_format() == SoundChannelFormat::PsgNoise)
{
self.start_channel(channel, emu);
} else if !bool::from(self.channels[channel].cnt.start_status()) {
} else if !self.channels[channel].cnt.start_status() {
self.channels[channel].active = false;
}
}
Expand All @@ -237,7 +237,7 @@ impl Spu {
self.channels[channel].sad = (self.channels[channel].sad & !mask) | (value & mask);

if self.channels[channel].cnt.get_format() != SoundChannelFormat::PsgNoise {
if self.channels[channel].sad != 0 && (bool::from(self.main_sound_cnt.master_enable()) && bool::from(self.channels[channel].cnt.start_status())) {
if self.channels[channel].sad != 0 && (self.main_sound_cnt.master_enable() && self.channels[channel].cnt.start_status()) {
self.start_channel(channel, emu);
} else {
self.channels[channel].active = false;
Expand All @@ -259,7 +259,7 @@ impl Spu {
}

pub fn set_main_sound_cnt(&mut self, mut mask: u16, value: u16, emu: &mut Emu) {
let was_disabled = !bool::from(self.main_sound_cnt.master_enable());
let was_disabled = !self.main_sound_cnt.master_enable();

mask &= 0xBF7F;
self.main_sound_cnt = ((u16::from(self.main_sound_cnt) & !mask) | (value & mask)).into();
Expand All @@ -269,13 +269,13 @@ impl Spu {
}
self.master_volume = volume;

if was_disabled && bool::from(self.main_sound_cnt.master_enable()) {
if was_disabled && self.main_sound_cnt.master_enable() {
for i in 0..CHANNEL_COUNT {
if bool::from(self.channels[i].cnt.start_status()) && (self.channels[i].sad != 0 || self.channels[i].cnt.get_format() == SoundChannelFormat::PsgNoise) {
if self.channels[i].cnt.start_status() && (self.channels[i].sad != 0 || self.channels[i].cnt.get_format() == SoundChannelFormat::PsgNoise) {
self.start_channel(i, emu);
}
}
} else if !bool::from(self.main_sound_cnt.master_enable()) {
} else if !self.main_sound_cnt.master_enable() {
for channel in &mut self.channels {
channel.active = false;
}
Expand Down Expand Up @@ -401,7 +401,7 @@ impl Spu {

if unlikely(!get_spu!(emu).audio_enabled) {
for i in 0..CHANNEL_COUNT {
get_channel_mut!(emu, i).cnt.set_start_status(u1::new(0));
get_channel_mut!(emu, i).cnt.set_start_status(false);
}
let spu = get_spu_mut!(emu);
spu.samples_buffer.push(0);
Expand Down Expand Up @@ -466,7 +466,7 @@ impl Spu {
channel.adpcm_toggle = false;
}
} else {
channel.cnt.set_start_status(u1::new(0));
channel.cnt.set_start_status(false);
channel.active = false;
break;
}
Expand All @@ -492,13 +492,13 @@ impl Spu {
if i == 1 {
channels_left[0] = data_left;
channels_right[0] = data_right;
if bool::from(get_spu!(emu).main_sound_cnt.output_ch1_to_mixer()) {
if get_spu!(emu).main_sound_cnt.output_ch1_to_mixer() {
continue;
}
} else if i == 3 {
channels_left[1] = data_left;
channels_right[1] = data_right;
if bool::from(get_spu!(emu).main_sound_cnt.output_ch3_to_mixer()) {
if get_spu!(emu).main_sound_cnt.output_ch3_to_mixer() {
continue;
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/core/thread_regs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ impl ThreadRegs {
}
}

#[inline]
pub fn set_cpsr_with_flags(&mut self, value: u32, flags: u8, emu: &mut Emu) {
if flags & 1 == 1 {
let mask = if u8::from(Cpsr::from(self.cpsr).mode()) == 0x10 { 0xE0 } else { 0xFF };
Expand All @@ -143,6 +144,7 @@ impl ThreadRegs {
}
}

#[inline]
pub fn set_spsr_with_flags(&mut self, value: u32, flags: u8) {
if DEBUG_LOG {
let mode = u8::from(Cpsr::from(self.cpsr).mode());
Expand All @@ -158,6 +160,7 @@ impl ThreadRegs {
}
}

#[inline]
pub fn restore_spsr(&mut self, emu: &mut Emu) {
if !self.is_user {
self.set_cpsr::<false>(self.spsr, emu);
Expand Down
13 changes: 7 additions & 6 deletions src/jit/assembler/block_asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::jit::assembler::block_inst::{BlockAluOp, BlockAluSetCond, BlockInst,
use crate::jit::assembler::block_inst_list::BlockInstList;
use crate::jit::assembler::block_reg_allocator::ALLOCATION_REGS;
use crate::jit::assembler::block_reg_set::BlockRegSet;
use crate::jit::assembler::{BlockAsmBuf, BlockInstKind, BlockLabel, BlockOperand, BlockOperandShift, BlockReg, BlockShift, ANY_REG_LIMIT};
use crate::jit::assembler::{block_inst_list, BlockAsmBuf, BlockInstKind, BlockLabel, BlockOperand, BlockOperandShift, BlockReg, BlockShift, ANY_REG_LIMIT};
use crate::jit::inst_info::InstInfo;
use crate::jit::reg::{Reg, RegReserve};
use crate::jit::{Cond, MemoryAmount, ShiftType};
Expand Down Expand Up @@ -43,7 +43,7 @@ macro_rules! alu2_op0 {
pub struct BlockAsm<'a> {
pub buf: &'a mut BlockAsmBuf,

pub insts_link: BlockInstList,
insts_link: BlockInstList,

any_reg_count: u16,
freed_any_regs: NoHashSet<u16>,
Expand Down Expand Up @@ -801,6 +801,7 @@ impl<'a> BlockAsm<'a> {
}

fn assemble_basic_blocks(&mut self, block_start_pc: u32, thumb: bool) -> (Vec<BasicBlock>, NoHashSet<usize>) {
unsafe { block_inst_list::reset_inst_list_entries() };
for i in 0..self.buf.insts.len() {
self.insts_link.insert_end(i);
}
Expand Down Expand Up @@ -941,7 +942,7 @@ impl<'a> BlockAsm<'a> {
}

basic_block.remove_dead_code(self);
// basic_block.consolidate_reg_io(self);
basic_block.consolidate_reg_io(self);
}

(basic_blocks, reachable_blocks)
Expand Down Expand Up @@ -972,7 +973,7 @@ impl<'a> BlockAsm<'a> {
}

self.buf.reg_allocator.dirty_regs.clear();
self.buf.reg_allocator.global_mapping.clear();
self.buf.reg_allocator.global_mapping.fill(Reg::None);
let mut input_regs = BlockRegSet::new();
for (i, basic_block) in basic_blocks.iter().enumerate() {
if !reachable_blocks.contains(&i) {
Expand All @@ -983,15 +984,15 @@ impl<'a> BlockAsm<'a> {
}
let gp_guest_regs = input_regs.get_guests().get_gp_regs();
for guest_reg in gp_guest_regs {
self.buf.reg_allocator.global_mapping.insert(guest_reg as u16, guest_reg);
self.buf.reg_allocator.global_mapping[guest_reg as usize] = guest_reg;
}

let mut non_input_guest_regs = input_regs;
non_input_guest_regs.remove_guests(gp_guest_regs);
let mut free_input_regs = (!input_regs.get_guests()).get_gp_regs();
for reg in non_input_guest_regs.iter_any() {
let free_input_reg = free_input_regs.pop().unwrap_or(Reg::None);
self.buf.reg_allocator.global_mapping.insert(reg, free_input_reg);
self.buf.reg_allocator.global_mapping[reg as usize] = free_input_reg;
}

if IS_DEBUG && unsafe { BLOCK_LOG } {
Expand Down
Loading

0 comments on commit 3df4437

Please sign in to comment.