lay base for DSi-mode TSC

This commit is contained in:
Arisotura 2019-08-04 11:44:36 +02:00
parent f7f4ff0519
commit a6a9f74acc
7 changed files with 186 additions and 19 deletions

View File

@ -114,6 +114,8 @@
<Unit filename="src/DSi_NWifi.h" />
<Unit filename="src/DSi_SD.cpp" />
<Unit filename="src/DSi_SD.h" />
<Unit filename="src/DSi_SPI_TSC.cpp" />
<Unit filename="src/DSi_SPI_TSC.h" />
<Unit filename="src/FIFO.h" />
<Unit filename="src/GPU.cpp" />
<Unit filename="src/GPU.h" />

113
src/DSi_SPI_TSC.cpp Normal file
View File

@ -0,0 +1,113 @@
/*
Copyright 2016-2019 Arisotura
This file is part of melonDS.
melonDS is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option)
any later version.
melonDS is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with melonDS. If not, see http://www.gnu.org/licenses/.
*/
#include <stdio.h>
#include <string.h>
#include "DSi.h"
#include "DSi_SPI_TSC.h"
namespace DSi_SPI_TSC
{
u32 DataPos;
u8 Index;
u8 Mode;
u8 Data;
u16 TouchX, TouchY;
bool Init()
{
return true;
}
void DeInit()
{
}
void Reset()
{
DataPos = 0;
Mode = 0;
Index = 0;
Data = 0;
}
void DoSavestate(Savestate* file)
{
/*file->Section("SPTi");
file->Var32(&DataPos);
file->Var8(&ControlByte);
file->Var8(&Data);
file->Var16(&ConvResult);*/
// TODO!!
}
void SetTouchCoords(u16 x, u16 y)
{
TouchX = x;
TouchY = y;
if (y == 0xFFF) return;
TouchX <<= 4;
TouchY <<= 4;
}
void MicInputFrame(s16* data, int samples)
{
// TODO: forward to DS-mode TSC if needed
}
u8 Read()
{
return Data;
}
void Write(u8 val, u32 hold)
{
#define READWRITE(var) { if (Index & 0x01) Data = var; else var = val; }
printf("TSC: %02X %d\n", val, hold?1:0);
if (DataPos == 0)
{
Index = val;
}
else
{
if ((Index & 0xFE) == 0)
{
READWRITE(Mode);
}
else
{
printf("DSi_SPI_TSC: unknown IO, mode=%02X, index=%02X (%02X %s)\n", Mode, Index, Index>>1, (Index&1)?"read":"write");
}
Index += (1<<1); // increment index
}
if (hold) DataPos++;
else DataPos = 0;
}
}

40
src/DSi_SPI_TSC.h Normal file
View File

@ -0,0 +1,40 @@
/*
Copyright 2016-2019 Arisotura
This file is part of melonDS.
melonDS is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option)
any later version.
melonDS is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with melonDS. If not, see http://www.gnu.org/licenses/.
*/
#ifndef DSI_SPI_TSC
#define DSI_SPI_TSC
namespace DSi_SPI_TSC
{
extern u32 DataPos;
bool Init();
void DeInit();
void Reset();
void DoSavestate(Savestate* file);
void SetTouchCoords(u16 x, u16 y);
void MicInputFrame(s16* data, int samples);
u8 Read();
void Write(u8 val, u32 hold);
}
#endif // DSI_SPI_TSC

View File

@ -32,6 +32,7 @@
#include "Platform.h"
#include "DSi.h"
#include "DSi_SPI_TSC.h"
namespace NDS
@ -519,6 +520,7 @@ void Reset()
Wifi::Reset();
DSi::Reset();
KeyInput &= ~(1 << (16+6)); // TODO
}
void Stop()
@ -932,24 +934,30 @@ void CancelEvent(u32 id)
}
void PressKey(u32 key)
{
KeyInput &= ~(1 << key);
}
void ReleaseKey(u32 key)
{
KeyInput |= (1 << key);
}
void TouchScreen(u16 x, u16 y)
{
SPI_TSC::SetTouchCoords(x, y);
if (true) // TODO!!
{
DSi_SPI_TSC::SetTouchCoords(x, y);
}
else
{
SPI_TSC::SetTouchCoords(x, y);
KeyInput &= ~(1 << (16+6));
}
}
void ReleaseScreen()
{
SPI_TSC::SetTouchCoords(0x000, 0xFFF);
if (true) // TODO!!
{
DSi_SPI_TSC::SetTouchCoords(0x000, 0xFFF);
}
else
{
SPI_TSC::SetTouchCoords(0x000, 0xFFF);
KeyInput |= (1 << (16+6));
}
}

View File

@ -180,8 +180,6 @@ void RelocateSave(const char* path, bool write);
u32 RunFrame();
void PressKey(u32 key);
void ReleaseKey(u32 key);
void TouchScreen(u16 x, u16 y);
void ReleaseScreen();

View File

@ -22,6 +22,7 @@
#include "Config.h"
#include "NDS.h"
#include "SPI.h"
#include "DSi_SPI_TSC.h"
#include "Platform.h"
@ -590,6 +591,7 @@ bool Init()
if (!SPI_Firmware::Init()) return false;
if (!SPI_Powerman::Init()) return false;
if (!SPI_TSC::Init()) return false;
if (!DSi_SPI_TSC::Init()) return false;
return true;
}
@ -599,6 +601,7 @@ void DeInit()
SPI_Firmware::DeInit();
SPI_Powerman::DeInit();
SPI_TSC::DeInit();
DSi_SPI_TSC::DeInit();
}
void Reset()
@ -608,6 +611,7 @@ void Reset()
SPI_Firmware::Reset();
SPI_Powerman::Reset();
SPI_TSC::Reset();
DSi_SPI_TSC::Reset();
}
void DoSavestate(Savestate* file)
@ -620,6 +624,7 @@ void DoSavestate(Savestate* file)
SPI_Firmware::DoSavestate(file);
SPI_Powerman::DoSavestate(file);
SPI_TSC::DoSavestate(file);
DSi_SPI_TSC::DoSavestate(file);
}
@ -633,7 +638,8 @@ void WriteCnt(u16 val)
{
case 0x0000: SPI_Powerman::Hold = 0; break;
case 0x0100: SPI_Firmware::Hold = 0; break;
case 0x0200: SPI_TSC::DataPos = 0; break;
//case 0x0200: SPI_TSC::DataPos = 0; break;
case 0x0200: DSi_SPI_TSC::DataPos = 0; break;
}
}
@ -659,7 +665,8 @@ u8 ReadData()
{
case 0x0000: return SPI_Powerman::Read();
case 0x0100: return SPI_Firmware::Read();
case 0x0200: return SPI_TSC::Read();
//case 0x0200: return SPI_TSC::Read();
case 0x0200: return DSi_SPI_TSC::Read();
default: return 0;
}
}
@ -675,7 +682,8 @@ void WriteData(u8 val)
{
case 0x0000: SPI_Powerman::Write(val, Cnt&(1<<11)); break;
case 0x0100: SPI_Firmware::Write(val, Cnt&(1<<11)); break;
case 0x0200: SPI_TSC::Write(val, Cnt&(1<<11)); break;
//case 0x0200: SPI_TSC::Write(val, Cnt&(1<<11)); break;
case 0x0200: DSi_SPI_TSC::Write(val, Cnt&(1<<11)); break;
default: printf("SPI to unknown device %04X %02X\n", Cnt, val); break;
}

View File

@ -1088,7 +1088,6 @@ void OnAreaMouseEvent(uiAreaHandler* handler, uiArea* area, uiAreaMouseEvent* ev
if (Touching && (evt->Up == 1))
{
Touching = false;
NDS::ReleaseKey(16+6);
NDS::ReleaseScreen();
}
else if (!Touching && (evt->Down == 1) &&
@ -1096,7 +1095,6 @@ void OnAreaMouseEvent(uiAreaHandler* handler, uiArea* area, uiAreaMouseEvent* ev
(x < (BottomScreenRect.X+BottomScreenRect.Width)) && (y < (BottomScreenRect.Y+BottomScreenRect.Height)))
{
Touching = true;
NDS::PressKey(16+6);
}
if (Touching)