Various pointer changes
This commit is contained in:
@@ -48,6 +48,10 @@ int Interpreter::Step() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if((u64)regs.pc == 0xFFFFFFFF8002070C) {
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
regs.oldPC = regs.pc;
|
||||
regs.pc = regs.nextPC;
|
||||
regs.nextPC += 4;
|
||||
|
||||
@@ -337,6 +337,11 @@ template<> void Mem::Write<u8>(Registers& regs, u32 paddr, u32 val) {
|
||||
const auto pointer = writePages[page];
|
||||
SI& si = mmio.si;
|
||||
|
||||
if(paddr == 0x0023e650) {
|
||||
//DumpRDRAM();
|
||||
//fmt::print("PC is 0x{:016X}: Writing 0x{:02X} -> 0x{:08X}\n", (u64)regs.oldPC, (u8)val, paddr);
|
||||
}
|
||||
|
||||
if(pointer) {
|
||||
((u8*)pointer)[BYTE_ADDRESS(offset)] = val;
|
||||
} else {
|
||||
@@ -382,6 +387,11 @@ template<> void Mem::Write<u16>(Registers& regs, u32 paddr, u32 val) {
|
||||
const auto pointer = writePages[page];
|
||||
SI& si = mmio.si;
|
||||
|
||||
if(paddr == 0x0023e650) {
|
||||
//DumpRDRAM();
|
||||
//fmt::print("PC is 0x{:016X}: Writing 0x{:04X} -> 0x{:08X}\n", (u64) regs.oldPC, (u16) val, paddr);
|
||||
}
|
||||
|
||||
if(pointer) {
|
||||
Util::WriteAccess<u16>((u8*)pointer, HALF_ADDRESS(offset), val);
|
||||
} else {
|
||||
@@ -427,6 +437,11 @@ template<> void Mem::Write<u32>(Registers& regs, u32 paddr, u32 val) {
|
||||
const auto pointer = writePages[page];
|
||||
SI& si = mmio.si;
|
||||
|
||||
if(paddr == 0x0023e650) {
|
||||
//DumpRDRAM();
|
||||
//fmt::print("PC is 0x{:016X}: Writing 0x{:08X} -> 0x{:08X}\n", (u64) regs.oldPC, val, paddr);
|
||||
}
|
||||
|
||||
if(pointer) {
|
||||
Util::WriteAccess<u32>((u8*)pointer, offset, val);
|
||||
} else {
|
||||
@@ -466,6 +481,11 @@ void Mem::Write(Registers& regs, u32 paddr, u64 val) {
|
||||
const auto pointer = writePages[page];
|
||||
SI& si = mmio.si;
|
||||
|
||||
if(paddr == 0x0023e650) {
|
||||
//DumpRDRAM();
|
||||
//fmt::print("PC is 0x{:016X}: Writing 0x{:016X} -> 0x{:08X}\n", (u64) regs.oldPC, val, paddr);
|
||||
}
|
||||
|
||||
if(pointer) {
|
||||
Util::WriteAccess<u64>((u8*)pointer, offset, val);
|
||||
} else {
|
||||
|
||||
@@ -465,15 +465,19 @@ void Interpreter::sb(u32 instr) {
|
||||
void Interpreter::sc(u32 instr) {
|
||||
u64 address = regs.gpr[RS(instr)] + (s16)instr;
|
||||
|
||||
if (check_address_error(0b11, address)) {
|
||||
regs.cop0.FireException(ExceptionCode::AddressErrorStore, 0, regs.oldPC);
|
||||
return;
|
||||
}
|
||||
|
||||
if(regs.cop0.llbit) {
|
||||
regs.cop0.llbit = false;
|
||||
|
||||
if (check_address_error(0b11, address)) {
|
||||
regs.gpr[RT(instr)] = 0;
|
||||
regs.cop0.HandleTLBException(address);
|
||||
regs.cop0.FireException(ExceptionCode::AddressErrorStore, 0, regs.oldPC);
|
||||
return;
|
||||
}
|
||||
|
||||
u32 paddr = 0;
|
||||
if(!regs.cop0.MapVAddr(Cop0::STORE, address, paddr)) {
|
||||
regs.gpr[RT(instr)] = 0;
|
||||
regs.cop0.HandleTLBException(address);
|
||||
regs.cop0.FireException(regs.cop0.GetTLBExceptionCode(regs.cop0.tlbError, Cop0::STORE), 0, regs.oldPC);
|
||||
} else {
|
||||
@@ -496,16 +500,20 @@ void Interpreter::scd(u32 instr) {
|
||||
}
|
||||
|
||||
s64 address = regs.gpr[RS(instr)] + (s16)instr;
|
||||
if (check_address_error(0b111, address)) {
|
||||
regs.cop0.HandleTLBException(address);
|
||||
regs.cop0.FireException(ExceptionCode::AddressErrorStore, 0, regs.oldPC);
|
||||
return;
|
||||
}
|
||||
|
||||
if(regs.cop0.llbit) {
|
||||
regs.cop0.llbit = false;
|
||||
|
||||
if (check_address_error(0b111, address)) {
|
||||
regs.gpr[RT(instr)] = 0;
|
||||
regs.cop0.HandleTLBException(address);
|
||||
regs.cop0.FireException(ExceptionCode::AddressErrorStore, 0, regs.oldPC);
|
||||
return;
|
||||
}
|
||||
|
||||
u32 paddr = 0;
|
||||
if(!regs.cop0.MapVAddr(Cop0::STORE, address, paddr)) {
|
||||
regs.gpr[RT(instr)] = 0;
|
||||
regs.cop0.HandleTLBException(address);
|
||||
regs.cop0.FireException(regs.cop0.GetTLBExceptionCode(regs.cop0.tlbError, Cop0::STORE), 0, regs.oldPC);
|
||||
} else {
|
||||
|
||||
@@ -11,19 +11,13 @@ namespace n64 {
|
||||
void audioCallback(void* user, Uint8* stream, int length) {
|
||||
auto audioDevice = (AudioDevice*)user;
|
||||
int gotten = 0, available = 0;
|
||||
|
||||
if (audioDevice) {
|
||||
audioDevice->LockMutex();
|
||||
}
|
||||
|
||||
if (audioDevice) {
|
||||
available = SDL_AudioStreamAvailable(audioDevice->GetStream().get());
|
||||
}
|
||||
|
||||
if (available > 0 && audioDevice) {
|
||||
gotten = SDL_AudioStreamGet(audioDevice->GetStream().get(), stream, length);
|
||||
}
|
||||
|
||||
if (audioDevice) {
|
||||
available = SDL_AudioStreamAvailable(audioDevice->GetStream());
|
||||
if (available > 0) {
|
||||
gotten = SDL_AudioStreamGet(audioDevice->GetStream(), stream, length);
|
||||
}
|
||||
audioDevice->UnlockMutex();
|
||||
}
|
||||
|
||||
@@ -37,11 +31,18 @@ void audioCallback(void* user, Uint8* stream, int length) {
|
||||
}
|
||||
}
|
||||
|
||||
AudioDevice::AudioDevice() : audioStream(SDL_NewAudioStream, SDL_FreeAudioStream, "audioStream", SYSTEM_SAMPLE_FORMAT, 2, AUDIO_SAMPLE_RATE, SYSTEM_SAMPLE_FORMAT, 2, AUDIO_SAMPLE_RATE),
|
||||
audioStreamMutex(SDL_CreateMutex, SDL_DestroyMutex, "audioStreamMutex") {
|
||||
AudioDevice::~AudioDevice() {
|
||||
LockMutex();
|
||||
SDL_FreeAudioStream(GetStream());
|
||||
UnlockMutex();
|
||||
SDL_DestroyMutex(audioStreamMutex);
|
||||
}
|
||||
|
||||
AudioDevice::AudioDevice() : audioStream(SDL_NewAudioStream(SYSTEM_SAMPLE_FORMAT, 2, AUDIO_SAMPLE_RATE, SYSTEM_SAMPLE_FORMAT, 2, AUDIO_SAMPLE_RATE)),
|
||||
audioStreamMutex(SDL_CreateMutex()) {
|
||||
SDL_InitSubSystem(SDL_INIT_AUDIO);
|
||||
|
||||
if(!audioStreamMutex.get()) {
|
||||
if(!audioStreamMutex) {
|
||||
Util::panic("Unable to initialize audio mutex: {}", SDL_GetError());
|
||||
}
|
||||
|
||||
@@ -66,15 +67,16 @@ void AudioDevice::PushSample(float left, float volumeL, float right, float volum
|
||||
float adjustedR = right * volumeR;
|
||||
float samples[2]{ adjustedL, adjustedR };
|
||||
|
||||
auto availableBytes = (float)SDL_AudioStreamAvailable(audioStream.get());
|
||||
auto availableBytes = (float)SDL_AudioStreamAvailable(audioStream);
|
||||
if(availableBytes <= BYTES_PER_HALF_SECOND) {
|
||||
SDL_AudioStreamPut(audioStream.get(), samples, 2 * sizeof(float));
|
||||
SDL_AudioStreamPut(audioStream, samples, 2 * sizeof(float));
|
||||
}
|
||||
}
|
||||
|
||||
void AudioDevice::AdjustSampleRate(int sampleRate) {
|
||||
LockMutex();
|
||||
audioStream.Construct(SDL_NewAudioStream, SYSTEM_SAMPLE_FORMAT, 2, sampleRate, SYSTEM_SAMPLE_FORMAT, 2, AUDIO_SAMPLE_RATE);
|
||||
SDL_FreeAudioStream(audioStream);
|
||||
audioStream = SDL_NewAudioStream(SYSTEM_SAMPLE_FORMAT, 2, sampleRate, SYSTEM_SAMPLE_FORMAT, 2, AUDIO_SAMPLE_RATE);
|
||||
UnlockMutex();
|
||||
}
|
||||
}
|
||||
@@ -5,24 +5,23 @@
|
||||
namespace n64 {
|
||||
struct AudioDevice {
|
||||
AudioDevice();
|
||||
~AudioDevice();
|
||||
|
||||
void PushSample(float, float, float, float);
|
||||
void AdjustSampleRate(int);
|
||||
void LockMutex() {
|
||||
if(audioStreamMutex.get())
|
||||
SDL_LockMutex(audioStreamMutex.get());
|
||||
if(audioStreamMutex)
|
||||
SDL_LockMutex(audioStreamMutex);
|
||||
}
|
||||
void UnlockMutex() {
|
||||
if (audioStreamMutex.get())
|
||||
SDL_UnlockMutex(audioStreamMutex.get());
|
||||
if (audioStreamMutex)
|
||||
SDL_UnlockMutex(audioStreamMutex);
|
||||
}
|
||||
|
||||
Util::AutoRelease<SDL_AudioStream, const SDL_AudioFormat, const Uint8, const int, const SDL_AudioFormat,
|
||||
const Uint8, const int>& GetStream() { return audioStream; }
|
||||
SDL_AudioStream* GetStream() { return audioStream; }
|
||||
private:
|
||||
Util::AutoRelease<SDL_AudioStream, const SDL_AudioFormat, const Uint8, const int, const SDL_AudioFormat,
|
||||
const Uint8, const int> audioStream;
|
||||
Util::AutoRelease<SDL_mutex> audioStreamMutex;
|
||||
SDL_AudioStream* audioStream;
|
||||
SDL_mutex* audioStreamMutex;
|
||||
SDL_AudioSpec audioSpec{};
|
||||
SDL_AudioSpec request{};
|
||||
SDL_AudioDeviceID handle{};
|
||||
|
||||
Reference in New Issue
Block a user