get this started: refactor SPI in OOP

This commit is contained in:
Arisotura
2023-11-03 20:17:00 +01:00
parent 70c6750561
commit 440b356674
17 changed files with 855 additions and 846 deletions

View File

@ -19,38 +19,25 @@
#include <stdio.h>
#include <string.h>
#include "DSi.h"
#include "SPI.h"
#include "DSi_SPI_TSC.h"
#include "Platform.h"
using Platform::Log;
using Platform::LogLevel;
namespace DSi_SPI_TSC
{
u32 DataPos;
u8 Index;
u8 Bank;
u8 Data;
u8 Bank3Regs[0x80];
u8 TSCMode;
u16 TouchX, TouchY;
bool Init()
{
return true;
}
void DeInit()
DSi_TSC::DSi_TSC(SPIHost* host) : TSC(host)
{
}
void Reset()
DSi_TSC::~DSi_TSC()
{
}
void DSi_TSC::Reset()
{
TSC::Reset();
DataPos = 0;
Bank = 0;
@ -72,8 +59,10 @@ void Reset()
TSCMode = 0x01; // DSi mode
}
void DoSavestate(Savestate* file)
void DSi_TSC::DoSavestate(Savestate* file)
{
TSC::DoSavestate(file);
file->Section("SPTi");
file->Var32(&DataPos);
@ -85,19 +74,14 @@ void DoSavestate(Savestate* file)
file->Var8(&TSCMode);
}
void SetMode(u8 mode)
void DSi_TSC::SetMode(u8 mode)
{
TSCMode = mode;
}
void SetTouchCoords(u16 x, u16 y)
void DSi_TSC::SetTouchCoords(u16 x, u16 y)
{
if (TSCMode == 0x00)
{
if (y == 0xFFF) NDS::KeyInput |= (1 << (16+6));
else NDS::KeyInput &= ~(1 << (16+6));
return SPI_TSC::SetTouchCoords(x, y);
}
if (TSCMode == 0x00) return TSC::SetTouchCoords(x, y);
TouchX = x;
TouchY = y;
@ -135,24 +119,17 @@ void SetTouchCoords(u16 x, u16 y)
}
}
void MicInputFrame(s16* data, int samples)
void DSi_TSC::MicInputFrame(s16* data, int samples)
{
if (TSCMode == 0x00) return SPI_TSC::MicInputFrame(data, samples);
if (TSCMode == 0x00) return TSC::MicInputFrame(data, samples);
// otherwise we don't handle mic input
// TODO: handle it where it needs to be
}
u8 Read()
void DSi_TSC::Write(u8 val)
{
if (TSCMode == 0x00) return SPI_TSC::Read();
return Data;
}
void Write(u8 val, u32 hold)
{
if (TSCMode == 0x00) return SPI_TSC::Write(val, hold);
if (TSCMode == 0x00) return TSC::Write(val);
#define READWRITE(var) { if (Index & 0x01) Data = var; else var = val; }
@ -233,8 +210,12 @@ void Write(u8 val, u32 hold)
Index += (1<<1); // increment index
}
if (hold) DataPos++;
else DataPos = 0;
DataPos++;
}
void DSi_TSC::Release()
{
if (TSCMode == 0x00) return TSC::Release();
DataPos = 0;
}