diff --git a/buildscript.sh b/buildscript.sh new file mode 100755 index 00000000..f491128a --- /dev/null +++ b/buildscript.sh @@ -0,0 +1,2 @@ +cmake -B build +cmake --build build -j$(nproc --all) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fef78706..78b56da2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -64,8 +64,10 @@ add_library(core STATIC sha1/sha1.c tiny-AES-c/aes.c - xxhash/xxhash.c) + xxhash/xxhash.c + H8300.cpp + H8300.h) if (ENABLE_GDBSTUB) message(NOTICE "Enabling GDB stub") target_sources(core PRIVATE @@ -100,7 +102,7 @@ if (ENABLE_JIT) ARMJIT_Global.cpp dolphin/CommonFuncs.cpp) - + if (WIN32) # Required for memory mapping-related functions introduced in Windows 8 target_compile_definitions(core PRIVATE -D_WIN32_WINNT=_WIN32_WINNT_WIN8) @@ -211,4 +213,3 @@ endif() # BEFORE PUBLIC -fsanitize=undefined PUBLIC -fsanitize=address # ) #endif() - diff --git a/src/H8300.cpp b/src/H8300.cpp index 0ae040b6..aa241863 100644 --- a/src/H8300.cpp +++ b/src/H8300.cpp @@ -1 +1,53 @@ -//test +/* + This file is copyright Barret Klics and maybe melonDS team I guess? + */ + + +#include "H8300.h" +#include +#include "types.h" +H8300::H8300(){ + printf("H8/300 has been created"); +} + +H8300::~H8300(){ + + printf("H8/300 has been killed"); + +} + +void H8300::speak(){ + printf("H8 CHIP IS SPEAKING"); +} + + +//A botched implementation +u8 H8300::handleSPI(u8& IRCmd, u8& val, u32&pos, bool& last){ + + printf("IRCmd: %d val:%d pos: %ld last: %d\n", IRCmd, val, pos, last); + switch (IRCmd) + { + case 0x00: // pass-through + printf("CRITICAL ERROR IN H8300 emu, should not have recieved 0x00 command!"); + return 0xFF; + + + case 0x01: + u8 rtnval; + if (pos == 1){ + rtnval = 0x01; + } + if (pos == 2){ + rtnval = 0x56; + } + printf(" returning: 0x%02x val: %d pos: %ld last: %d\n", rtnval, val, pos, last); + return rtnval; + + + case 0x08: // ID + return 0xAA; + } + + printf("Unhandled: %d val:%d pos: %ld last: %d\n", IRCmd, val, pos, last); + return 0x00; +} diff --git a/src/H8300.h b/src/H8300.h index 118291ec..c5f0a070 100644 --- a/src/H8300.h +++ b/src/H8300.h @@ -1,2 +1,31 @@ //test +#ifndef H8300_H +#define H8300_H + + + +#include +#include +#include +#include + +#include "types.h" + + +using namespace melonDS; +class H8300 { +public: + H8300(); + ~H8300(); + + void speak(); + u8 handleSPI(u8& IRCmd, u8& val, u32&pos, bool& last); + + +private: + int exampleInt; +}; + +#endif + diff --git a/src/NDSCart.cpp b/src/NDSCart.cpp index 1fa0fbfe..d87a06a8 100644 --- a/src/NDSCart.cpp +++ b/src/NDSCart.cpp @@ -26,6 +26,7 @@ #include "melonDLDI.h" #include "FATStorage.h" #include "Utils.h" +#include "H8300.h" namespace melonDS { @@ -907,7 +908,7 @@ int CartRetailNAND::ROMCommandStart(NDS& nds, NDSCart::NDSCartSlot& cartslot, co switch (cmd[0]) { - case 0x81: // write data + case 0x81: // write data where H8300 is fully defined in the source file (e.g., .cpp or .h): if ((SRAMStatus & (1<<4)) && SRAMWindow >= SRAMBase && SRAMWindow < (SRAMBase+SRAMLength)) { u32 addr = (cmd[1]<<24) | (cmd[2]<<16) | (cmd[3]<<8) | cmd[4]; @@ -1090,7 +1091,6 @@ CartRetailIR::CartRetailIR(const u8* rom, u32 len, u32 chipid, u32 irversion, bo CartRetailIR(CopyToUnique(rom, len), len, chipid, irversion, badDSiDump, romparams, std::move(sram), sramlen, userdata) { } - CartRetailIR::CartRetailIR( std::unique_ptr&& rom, u32 len, @@ -1103,7 +1103,8 @@ CartRetailIR::CartRetailIR( void* userdata ) : CartRetail(std::move(rom), len, chipid, badDSiDump, romparams, std::move(sram), sramlen, userdata, CartType::RetailIR), - IRVersion(irversion) + IRVersion(irversion), + IRChip() { } @@ -1122,29 +1123,56 @@ void CartRetailIR::DoSavestate(Savestate* file) file->Var8(&IRCmd); } - +//BARRET BEGIN CHANGES u8 CartRetailIR::SPIWrite(u8 val, u32 pos, bool last) { + //Kind of like an init sequence, we only really care about commands after this first one if (pos == 0) { +// printf("IRCmd: %d val:%d pos: %ld last: %d\n", val, val, pos, last); IRCmd = val; return 0; } // TODO: emulate actual IR comm + if (IRCmd == 0){ + return CartRetail::SPIWrite(val, pos-1, last); + } + + else{ + return IRChip.handleSPI(IRCmd, val, pos, last); + + } + + + /* switch (IRCmd) { case 0x00: // pass-through return CartRetail::SPIWrite(val, pos-1, last); + + case 0xaa: + u8 rtnval; + if (pos == 1){ + rtnval = 0x01; + } + if (pos == 2){ + rtnval = 0x56; + } + printf(" returning: 0x%02x val: %d pos: %ld last: %d\n", rtnval, val, pos, last); + return rtnval; + + case 0x08: // ID return 0xAA; } - - return 0; + return IRChip.handleSPI(val, pos,last); + //printf(" Unhandled Case: val: 0x%02x\n", val); + //return 0;*/ } - +//BARRET END CHANGES CartRetailBT::CartRetailBT(const u8* rom, u32 len, u32 chipid, ROMListEntry romparams, std::unique_ptr&& sram, u32 sramlen, void* userdata) : CartRetailBT(CopyToUnique(rom, len), len, chipid, romparams, std::move(sram), sramlen, userdata) { @@ -2045,4 +2073,4 @@ void NDSCartSlot::WriteSPIData(u8 val) noexcept } -} \ No newline at end of file +} diff --git a/src/NDSCart.h b/src/NDSCart.h index 3704f659..4cc1d292 100644 --- a/src/NDSCart.h +++ b/src/NDSCart.h @@ -29,7 +29,7 @@ #include "NDS_Header.h" #include "FATStorage.h" #include "ROMList.h" - +#include "H8300.h" namespace melonDS { class NDS; @@ -233,6 +233,7 @@ public: private: u32 IRVersion = 0; u8 IRCmd = 0; + H8300 IRChip; }; // CartRetailBT - Pok�mon Typing Adventure (SPI BT controller) @@ -470,3 +471,4 @@ std::unique_ptr ParseROM(std::unique_ptr&& romdata, u32 romlen } #endif +