1
0
Fork 0
mirror of https://github.com/melonDS-emu/melonDS.git synced 2025-03-06 21:00:31 +01:00

moved SPI handling to new files

This commit is contained in:
barret 2025-01-21 21:42:05 -07:00
parent c6be1b61cd
commit c4f682d106
6 changed files with 127 additions and 13 deletions

2
buildscript.sh Executable file
View file

@ -0,0 +1,2 @@
cmake -B build
cmake --build build -j$(nproc --all)

View file

@ -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()

View file

@ -1 +1,53 @@
//test
/*
This file is copyright Barret Klics and maybe melonDS team I guess?
*/
#include "H8300.h"
#include <string.h>
#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;
}

View file

@ -1,2 +1,31 @@
//test
#ifndef H8300_H
#define H8300_H
#include <array>
#include <string>
#include <memory>
#include <variant>
#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

View file

@ -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<u8[]>&& 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<u8[]>&& 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
}
}
}

View file

@ -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<6F>mon Typing Adventure (SPI BT controller)
@ -470,3 +471,4 @@ std::unique_ptr<CartCommon> ParseROM(std::unique_ptr<u8[]>&& romdata, u32 romlen
}
#endif