From a4f436f8279477e683e4155bd280e19dff9d3f91 Mon Sep 17 00:00:00 2001 From: StapleButter Date: Fri, 7 Apr 2017 17:37:49 +0200 Subject: [PATCH] * stub more wifi crap * louder sound * misc fixes --- src/ARM.cpp | 3 ++ src/NDS.cpp | 4 +++ src/NDSCart.cpp | 4 +-- src/SPI.cpp | 4 +++ src/SPI.h | 4 +++ src/SPU.cpp | 19 ++++++++-- src/SPU.h | 2 ++ src/Wifi.cpp | 95 ++++++++++++++++++++++++++++++++++++++++++++++++- src/wx/main.cpp | 1 + 9 files changed, 130 insertions(+), 6 deletions(-) diff --git a/src/ARM.cpp b/src/ARM.cpp index a2e00664..47a37bd7 100644 --- a/src/ARM.cpp +++ b/src/ARM.cpp @@ -174,6 +174,9 @@ void ARM::JumpTo(u32 addr, bool restorecpsr) // aging cart debug crap //if (addr == 0x0201764C) printf("capture test %d: R1=%08X\n", R[6], R[1]); //if (addr == 0x020175D8) printf("capture test %d: res=%08X\n", R[6], R[0]); + //if (addr == 0x37FF234 && R[15]!=0x37FF23C) printf("poké infinite loop %08X, %08X\n", R[15], DataRead32(0x380FFC8)); + // 37FD4BC. if R0=0, inf. loop + // 38098AC -> R0 if (addr & 0x1) { diff --git a/src/NDS.cpp b/src/NDS.cpp index 623f025d..682ed509 100644 --- a/src/NDS.cpp +++ b/src/NDS.cpp @@ -220,6 +220,8 @@ void SetupDirectBoot() PowerControl9 = 0x820F; GPU::DisplaySwap(PowerControl9); + SPU::SetBias(0x200); + ARM7BIOSProt = 0x1204; SPI_Firmware::SetupDirectBoot(); @@ -1464,6 +1466,7 @@ u32 ARM9IORead32(u32 addr) case 0x04000244: return GPU::VRAMCNT[4] | (GPU::VRAMCNT[5] << 8) | (GPU::VRAMCNT[6] << 16) | (WRAMCnt << 24); case 0x04000248: return GPU::VRAMCNT[7] | (GPU::VRAMCNT[8] << 8); + case 0x04000280: return DivCnt; case 0x04000290: return DivNumerator[0]; case 0x04000294: return DivNumerator[1]; case 0x04000298: return DivDenominator[0]; @@ -1473,6 +1476,7 @@ u32 ARM9IORead32(u32 addr) case 0x040002A8: return DivRemainder[0]; case 0x040002AC: return DivRemainder[1]; + case 0x040002B0: return SqrtCnt; case 0x040002B4: return SqrtRes; case 0x040002B8: return SqrtVal[0]; case 0x040002BC: return SqrtVal[1]; diff --git a/src/NDSCart.cpp b/src/NDSCart.cpp index f291d7bc..68c6fe7c 100644 --- a/src/NDSCart.cpp +++ b/src/NDSCart.cpp @@ -495,8 +495,8 @@ void Write(u8 val, u32 hold) break; default: - if (DataPos==0) - printf("unknown save SPI command %02X\n", CurCmd); + //if (DataPos==0) + // printf("unknown save SPI command %02X %08X\n", CurCmd); break; } diff --git a/src/SPI.cpp b/src/SPI.cpp index 3e77027a..2c881978 100644 --- a/src/SPI.cpp +++ b/src/SPI.cpp @@ -164,6 +164,10 @@ void SetupDirectBoot() NDS::ARM9Write32(0x027FFC80+i, *(u32*)&Firmware[UserSettings+i]); } +u8 GetConsoleType() { return Firmware[0x1D]; } +u8 GetWifiVersion() { return Firmware[0x2F]; } +u8 GetRFVersion() { return Firmware[0x40]; } + u8 Read() { return Data; diff --git a/src/SPI.h b/src/SPI.h index 4304b1f8..d122da81 100644 --- a/src/SPI.h +++ b/src/SPI.h @@ -24,6 +24,10 @@ namespace SPI_Firmware void SetupDirectBoot(); +u8 GetConsoleType(); +u8 GetWifiVersion(); +u8 GetRFVersion(); + } namespace SPI_TSC diff --git a/src/SPU.cpp b/src/SPU.cpp index dd057d32..28582db9 100644 --- a/src/SPU.cpp +++ b/src/SPU.cpp @@ -52,7 +52,7 @@ const s16 PSGTable[8][8] = {-0x7FFF, -0x7FFF, -0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF}, {-0x7FFF, -0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF}, {-0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF}, - { 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF} + {-0x7FFF, -0x7FFF, -0x7FFF, -0x7FFF, -0x7FFF, -0x7FFF, -0x7FFF, -0x7FFF} }; const u32 OutputBufferSize = 2*1024; @@ -99,6 +99,12 @@ void Reset() } +void SetBias(u16 bias) +{ + Bias = bias; +} + + Channel::Channel(u32 num) { Num = num; @@ -358,8 +364,15 @@ void Mix(u32 samples) l = ((s64)l * MasterVolume) >> 7; r = ((s64)r * MasterVolume) >> 7; - OutputBuffer[OutputWriteOffset ] = l >> 12; - OutputBuffer[OutputWriteOffset + 1] = r >> 12; + l >>= 12; + if (l < -0x8000) l = -0x8000; + else if (l > 0x7FFF) l = 0x7FFF; + r >>= 12; + if (r < -0x8000) r = -0x8000; + else if (r > 0x7FFF) r = 0x7FFF; + + OutputBuffer[OutputWriteOffset ] = l << 3; + OutputBuffer[OutputWriteOffset + 1] = r << 3; OutputWriteOffset += 2; OutputWriteOffset &= ((2*OutputBufferSize)-1); } diff --git a/src/SPU.h b/src/SPU.h index 1fbe26d4..0687b412 100644 --- a/src/SPU.h +++ b/src/SPU.h @@ -26,6 +26,8 @@ bool Init(); void DeInit(); void Reset(); +void SetBias(u16 bias); + void Mix(u32 samples); void ReadOutput(s16* data, int samples); diff --git a/src/Wifi.cpp b/src/Wifi.cpp index 0f1c239e..385aa77d 100644 --- a/src/Wifi.cpp +++ b/src/Wifi.cpp @@ -19,20 +19,35 @@ #include #include #include "NDS.h" +#include "SPI.h" #include "Wifi.h" namespace Wifi { +u8 RAM[0x2000]; + +u16 Random; + u16 BBCnt; u8 BBWrite; u8 BBRegs[0x100]; u8 BBRegsRO[0x100]; +u8 RFVersion; +u16 RFCnt; +u16 RFData1; +u16 RFData2; +u32 RFRegs[0x40]; + void Reset() { + memset(RAM, 0, 0x2000); + + Random = 0x7FF; + BBCnt = 0; BBWrite = 0; memset(BBRegs, 0, 0x100); @@ -65,15 +80,66 @@ void Reset() BBREG_FIXED(i, 0x00); } #undef BBREG_FIXED + + RFVersion = SPI_Firmware::GetRFVersion(); + RFCnt = 0; + RFData1 = 0; + RFData2 = 0; + memset(RFRegs, 0, 4*0x40); } +void RFTransfer_Type2() +{ + u32 id = (RFData2 >> 2) & 0x1F; + + if (RFData2 & 0x0080) + { + u32 data = RFRegs[id]; + RFData1 = data & 0xFFFF; + RFData2 = (RFData2 & 0xFFFC) | ((data >> 16) & 0x3); + } + else + { + u32 data = RFData1 | ((RFData2 & 0x0003) << 16); + RFRegs[id] = data; + } +} + +void RFTransfer_Type3() +{ + u32 id = (RFData1 >> 8) & 0x3F; + + u32 cmd = RFData2 & 0xF; + if (cmd == 6) + { + RFData1 = (RFData1 & 0xFF00) | (RFRegs[id] & 0xFF); + } + else if (cmd == 5) + { + u32 data = RFData1 & 0xFF; + RFRegs[id] = data; + } +} + + +// TODO: wifi waitstates + u16 Read(u32 addr) { addr &= 0x7FFF; + if (addr >= 0x4000 && addr < 0x6000) + { + return *(u16*)&RAM[addr & 0x1FFF]; + } + switch (addr) { + case 0x044: // random generator. not accurate + Random = (Random & 0x1) ^ (((Random & 0x3FF) << 1) | (Random >> 10)); + return Random; + case 0x158: return BBCnt; @@ -86,7 +152,16 @@ u16 Read(u32 addr) return BBRegs[BBCnt & 0xFF]; case 0x15E: - return 0; // cheap + return 0; // TODO eventually (BB busy flag) + + case 0x17C: + return RFData2; + case 0x17E: + return RFData1; + case 0x180: + return 0; // TODO eventually (RF busy flag) + case 0x184: + return RFCnt; } printf("WIFI: unknown read %08X\n", addr); @@ -97,6 +172,12 @@ void Write(u32 addr, u16 val) { addr &= 0x7FFF; + if (addr >= 0x4000 && addr < 0x6000) + { + *(u16*)&RAM[addr & 0x1FFF] = val; + return; + } + switch (addr) { case 0x158: @@ -112,6 +193,18 @@ void Write(u32 addr, u16 val) case 0x15A: BBWrite = val; return; + + case 0x17C: + RFData2 = val; + if (RFVersion == 3) RFTransfer_Type3(); + else RFTransfer_Type2(); + return; + case 0x17E: + RFData1 = val; + return; + case 0x184: + RFCnt = val & 0x413F; + return; } printf("WIFI: unknown write %08X %04X\n", addr, val); diff --git a/src/wx/main.cpp b/src/wx/main.cpp index f3d8ef82..ff220904 100644 --- a/src/wx/main.cpp +++ b/src/wx/main.cpp @@ -554,6 +554,7 @@ void EmuThread::ProcessEvents() if (evt.key.keysym.scancode == Config::KeyMapping[i]) NDS::PressKey(i); if (evt.key.keysym.scancode == Config::KeyMapping[10]) NDS::PressKey(16); if (evt.key.keysym.scancode == Config::KeyMapping[11]) NDS::PressKey(17); + if (evt.key.keysym.scancode == SDL_SCANCODE_F12) NDS::debug(0); break; case SDL_KEYUP: