TSC support, touchscreen input. not perfect but for now this will do.
This commit is contained in:
parent
548b8d99a6
commit
1f5faf8291
4
CP15.cpp
4
CP15.cpp
|
@ -114,14 +114,14 @@ void Write(u32 id, u32 val)
|
|||
//printf("inval data cache %08X\n", val);
|
||||
return;
|
||||
case 0x762:
|
||||
printf("inval data cache SI\n");
|
||||
//printf("inval data cache SI\n");
|
||||
return;
|
||||
|
||||
case 0x7A1:
|
||||
//printf("flush data cache %08X\n", val);
|
||||
return;
|
||||
case 0x7A2:
|
||||
printf("flush data cache SI\n");
|
||||
//printf("flush data cache SI\n");
|
||||
return;
|
||||
|
||||
|
||||
|
|
4
DMA.cpp
4
DMA.cpp
|
@ -87,8 +87,8 @@ void DMA::WriteCnt(u32 val)
|
|||
|
||||
if ((StartMode & 0x7) == 0)
|
||||
Start();
|
||||
else
|
||||
printf("SPECIAL ARM%d DMA%d START MODE %02X\n", CPU?7:9, Num, StartMode);
|
||||
//else
|
||||
// printf("SPECIAL ARM%d DMA%d START MODE %02X\n", CPU?7:9, Num, StartMode);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
18
NDS.cpp
18
NDS.cpp
|
@ -141,6 +141,7 @@ void LoadROM()
|
|||
|
||||
//f = fopen("rom/armwrestler.nds", "rb");
|
||||
//f = fopen("rom/zorp.nds", "rb");
|
||||
//f = fopen("rom/hello_world.nds", "rb");
|
||||
f = fopen("rom/nsmb.nds", "rb");
|
||||
|
||||
u32 bootparams[8];
|
||||
|
@ -421,6 +422,17 @@ void ReleaseKey(u32 key)
|
|||
KeyInput |= (1 << key);
|
||||
}
|
||||
|
||||
void TouchScreen(u16 x, u16 y)
|
||||
{
|
||||
SPI_TSC::SetTouchCoords(x, y);
|
||||
printf("touching %d,%d\n", x, y);
|
||||
}
|
||||
|
||||
void ReleaseScreen()
|
||||
{
|
||||
SPI_TSC::SetTouchCoords(0x000, 0xFFF);
|
||||
}
|
||||
|
||||
|
||||
void Halt()
|
||||
{
|
||||
|
@ -1257,6 +1269,8 @@ u16 ARM9IORead16(u32 addr)
|
|||
case 0x04000004: return GPU::DispStat[0];
|
||||
case 0x04000006: return GPU::VCount;
|
||||
|
||||
case 0x04000060: return 0;
|
||||
|
||||
case 0x040000B8: return DMAs[0]->Cnt & 0xFFFF;
|
||||
case 0x040000BA: return DMAs[0]->Cnt >> 16;
|
||||
case 0x040000C4: return DMAs[1]->Cnt & 0xFFFF;
|
||||
|
@ -1482,6 +1496,8 @@ void ARM9IOWrite16(u32 addr, u16 val)
|
|||
{
|
||||
case 0x04000004: GPU::SetDispStat(0, val); return;
|
||||
|
||||
case 0x04000060: return;
|
||||
|
||||
case 0x040000B8: DMAs[0]->WriteCnt((DMAs[0]->Cnt & 0xFFFF0000) | val); return;
|
||||
case 0x040000BA: DMAs[0]->WriteCnt((DMAs[0]->Cnt & 0x0000FFFF) | (val << 16)); return;
|
||||
case 0x040000C4: DMAs[1]->WriteCnt((DMAs[1]->Cnt & 0xFFFF0000) | val); return;
|
||||
|
@ -1592,6 +1608,8 @@ void ARM9IOWrite32(u32 addr, u32 val)
|
|||
{
|
||||
switch (addr)
|
||||
{
|
||||
case 0x04000060: return;
|
||||
|
||||
case 0x040000B0: DMAs[0]->SrcAddr = val; return;
|
||||
case 0x040000B4: DMAs[0]->DstAddr = val; return;
|
||||
case 0x040000B8: DMAs[0]->WriteCnt(val); return;
|
||||
|
|
2
NDS.h
2
NDS.h
|
@ -119,6 +119,8 @@ void RunFrame();
|
|||
|
||||
void PressKey(u32 key);
|
||||
void ReleaseKey(u32 key);
|
||||
void TouchScreen(u16 x, u16 y);
|
||||
void ReleaseScreen();
|
||||
|
||||
/*SchedEvent* ScheduleEvent(s32 Delay, void (*Func)(u32), u32 Param);
|
||||
void CancelEvent(SchedEvent* event);
|
||||
|
|
104
SPI.cpp
104
SPI.cpp
|
@ -88,11 +88,27 @@ void Reset()
|
|||
|
||||
fclose(f);
|
||||
|
||||
// temp: disable autoboot
|
||||
/*Firmware[0x3FE64] &= 0xBF;
|
||||
*(u16*)&Firmware[0x3FE72] = CRC16(&Firmware[0x3FE00], 0x70, 0xFFFF);
|
||||
Firmware[0x3FF64] &= 0xBF;
|
||||
*(u16*)&Firmware[0x3FF72] = CRC16(&Firmware[0x3FF00], 0x70, 0xFFFF);*/
|
||||
u32 userdata = 0x3FE00;
|
||||
if (*(u16*)&Firmware[0x3FF70] == ((*(u16*)&Firmware[0x3FE70] + 1) & 0x7F))
|
||||
{
|
||||
if (VerifyCRC16(0xFFFF, 0x3FF00, 0x70, 0x3FF72))
|
||||
userdata = 0x3FF00;
|
||||
}
|
||||
|
||||
// fix touchscreen coords
|
||||
*(u16*)&Firmware[userdata+0x58] = 0;
|
||||
*(u16*)&Firmware[userdata+0x5A] = 0;
|
||||
Firmware[userdata+0x5C] = 1;
|
||||
Firmware[userdata+0x5D] = 1;
|
||||
*(u16*)&Firmware[userdata+0x5E] = 254;
|
||||
*(u16*)&Firmware[userdata+0x60] = 190;
|
||||
Firmware[userdata+0x62] = 255;
|
||||
Firmware[userdata+0x63] = 191;
|
||||
|
||||
// disable autoboot
|
||||
//Firmware[userdata+0x64] &= 0xBF;
|
||||
|
||||
*(u16*)&Firmware[userdata+0x72] = CRC16(&Firmware[userdata], 0x70, 0xFFFF);
|
||||
|
||||
// verify shit
|
||||
printf("FW: WIFI CRC16 = %s\n", VerifyCRC16(0x0000, 0x2C, *(u16*)&Firmware[0x2C], 0x2A)?"GOOD":"BAD");
|
||||
|
@ -267,6 +283,80 @@ void Write(u8 val, u32 hold)
|
|||
}
|
||||
|
||||
|
||||
namespace SPI_TSC
|
||||
{
|
||||
|
||||
u32 DataPos;
|
||||
u8 ControlByte;
|
||||
u8 Data;
|
||||
|
||||
u16 ConvResult;
|
||||
|
||||
u16 TouchX, TouchY;
|
||||
|
||||
|
||||
void Init()
|
||||
{
|
||||
}
|
||||
|
||||
void Reset()
|
||||
{
|
||||
ControlByte = 0;
|
||||
Data = 0;
|
||||
|
||||
ConvResult = 0;
|
||||
}
|
||||
|
||||
void SetTouchCoords(u16 x, u16 y)
|
||||
{
|
||||
// scr.x = (adc.x-adc.x1) * (scr.x2-scr.x1) / (adc.x2-adc.x1) + (scr.x1-1)
|
||||
// scr.y = (adc.y-adc.y1) * (scr.y2-scr.y1) / (adc.y2-adc.y1) + (scr.y1-1)
|
||||
// adc.x = ((scr.x * ((adc.x2-adc.x1) + (scr.x1-1))) / (scr.x2-scr.x1)) + adc.x1
|
||||
// adc.y = ((scr.y * ((adc.y2-adc.y1) + (scr.y1-1))) / (scr.y2-scr.y1)) + adc.y1
|
||||
TouchX = x;
|
||||
TouchY = y;
|
||||
|
||||
if (y == 0xFFF) return;
|
||||
|
||||
// TODO: eventually convert?
|
||||
}
|
||||
|
||||
u8 Read()
|
||||
{
|
||||
return Data;
|
||||
}
|
||||
|
||||
void Write(u8 val, u32 hold)
|
||||
{
|
||||
if (DataPos == 1)
|
||||
Data = (ConvResult >> 5) & 0xFF;
|
||||
else if (DataPos == 2)
|
||||
Data = (ConvResult << 3) & 0xFF;
|
||||
else
|
||||
Data = 0;
|
||||
|
||||
if (val & 0x80)
|
||||
{
|
||||
ControlByte = val;
|
||||
DataPos = 1;
|
||||
|
||||
switch (ControlByte & 0x70)
|
||||
{
|
||||
case 0x10: ConvResult = TouchY; break;
|
||||
case 0x50: ConvResult = TouchX; break;
|
||||
default: ConvResult = 0xFFF; break;
|
||||
}
|
||||
|
||||
if (ControlByte & 0x08)
|
||||
ConvResult &= 0x0FF0; // checkme
|
||||
}
|
||||
else
|
||||
DataPos++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
namespace SPI
|
||||
{
|
||||
|
||||
|
@ -279,6 +369,7 @@ void Init()
|
|||
{
|
||||
SPI_Firmware::Init();
|
||||
SPI_Powerman::Init();
|
||||
SPI_TSC::Init();
|
||||
}
|
||||
|
||||
void Reset()
|
||||
|
@ -287,6 +378,7 @@ void Reset()
|
|||
|
||||
SPI_Firmware::Reset();
|
||||
SPI_Powerman::Reset();
|
||||
SPI_TSC::Init();
|
||||
}
|
||||
|
||||
|
||||
|
@ -304,6 +396,7 @@ u8 ReadData()
|
|||
{
|
||||
case 0x0000: return SPI_Powerman::Read();
|
||||
case 0x0100: return SPI_Firmware::Read();
|
||||
case 0x0200: return SPI_TSC::Read();
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
|
@ -318,6 +411,7 @@ 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;
|
||||
default: printf("SPI to unknown device %04X %02X\n", Cnt, val); break;
|
||||
}
|
||||
|
||||
|
|
7
SPI.h
7
SPI.h
|
@ -19,6 +19,13 @@
|
|||
#ifndef SPI_H
|
||||
#define SPI_H
|
||||
|
||||
namespace SPI_TSC
|
||||
{
|
||||
|
||||
void SetTouchCoords(u16 x, u16 y);
|
||||
|
||||
}
|
||||
|
||||
namespace SPI
|
||||
{
|
||||
|
||||
|
|
43
main.cpp
43
main.cpp
|
@ -30,6 +30,8 @@ HWND melon;
|
|||
BITMAPV4HEADER bmp;
|
||||
bool quit;
|
||||
|
||||
bool touching;
|
||||
|
||||
|
||||
LRESULT CALLBACK derpo(HWND window, UINT msg, WPARAM wparam, LPARAM lparam)
|
||||
{
|
||||
|
@ -59,7 +61,6 @@ LRESULT CALLBACK derpo(HWND window, UINT msg, WPARAM wparam, LPARAM lparam)
|
|||
case VK_DOWN: NDS::PressKey(7); break;
|
||||
case VK_LEFT: NDS::PressKey(5); break;
|
||||
case VK_RIGHT: NDS::PressKey(4); break;
|
||||
case 'P': NDS::PressKey(16+6); break;
|
||||
case 'A': NDS::PressKey(0); break;
|
||||
case 'B': NDS::PressKey(1); break;
|
||||
case 'D': NDS::debug(0); break;
|
||||
|
@ -75,12 +76,49 @@ LRESULT CALLBACK derpo(HWND window, UINT msg, WPARAM wparam, LPARAM lparam)
|
|||
case VK_DOWN: NDS::ReleaseKey(7); break;
|
||||
case VK_LEFT: NDS::ReleaseKey(5); break;
|
||||
case VK_RIGHT: NDS::ReleaseKey(4); break;
|
||||
case 'P': NDS::ReleaseKey(16+6); break;
|
||||
case 'A': NDS::ReleaseKey(0); break;
|
||||
case 'B': NDS::ReleaseKey(1); break;
|
||||
}
|
||||
return 0;
|
||||
|
||||
case WM_LBUTTONDOWN:
|
||||
if (!touching)
|
||||
{
|
||||
s16 x = (s16)(lparam & 0xFFFF);
|
||||
s16 y = (s16)(lparam >> 16);
|
||||
|
||||
y -= 192;
|
||||
if (x >= 0 && x < 256 && y >= 0 && y < 192)
|
||||
{
|
||||
NDS::TouchScreen(x, y);
|
||||
NDS::PressKey(16+6);
|
||||
touching = true;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
||||
case WM_LBUTTONUP:
|
||||
case WM_NCLBUTTONUP:
|
||||
if (touching)
|
||||
{
|
||||
NDS::ReleaseScreen();
|
||||
NDS::ReleaseKey(16+6);
|
||||
touching = false;
|
||||
}
|
||||
return 0;
|
||||
|
||||
case WM_MOUSEMOVE:
|
||||
if (touching)
|
||||
{
|
||||
s16 x = (s16)(lparam & 0xFFFF);
|
||||
s16 y = (s16)(lparam >> 16);
|
||||
|
||||
y -= 192;
|
||||
if (x >= 0 && x < 256 && y >= 0 && y < 192)
|
||||
NDS::TouchScreen(x, y);
|
||||
}
|
||||
return 0;
|
||||
|
||||
/*case WM_PAINT:
|
||||
{
|
||||
|
||||
|
@ -98,6 +136,7 @@ int main()
|
|||
printf("it's a DS emulator!!!\n");
|
||||
printf("http://melonds.kuribo64.net/\n");
|
||||
quit = false;
|
||||
touching = false;
|
||||
|
||||
instance = GetModuleHandle(NULL);
|
||||
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
# depslib dependency file v1.0
|
||||
1485884302 source:c:\documents\sources\melonds\main.cpp
|
||||
1485901373 source:c:\documents\sources\melonds\main.cpp
|
||||
<stdio.h>
|
||||
<windows.h>
|
||||
"NDS.h"
|
||||
"GPU.h"
|
||||
|
||||
1485808644 c:\documents\sources\melonds\nds.h
|
||||
1485901230 c:\documents\sources\melonds\nds.h
|
||||
"types.h"
|
||||
|
||||
1481161027 c:\documents\sources\melonds\types.h
|
||||
|
||||
1485895731 source:c:\documents\sources\melonds\nds.cpp
|
||||
1485901668 source:c:\documents\sources\melonds\nds.cpp
|
||||
<stdio.h>
|
||||
<string.h>
|
||||
"NDS.h"
|
||||
|
@ -71,16 +71,16 @@
|
|||
|
||||
1485799621 c:\documents\sources\melonds\cp15.h
|
||||
|
||||
1485883361 source:c:\documents\sources\melonds\cp15.cpp
|
||||
1485901523 source:c:\documents\sources\melonds\cp15.cpp
|
||||
<stdio.h>
|
||||
<string.h>
|
||||
"NDS.h"
|
||||
"ARM.h"
|
||||
"CP15.h"
|
||||
|
||||
1485878592 c:\documents\sources\melonds\spi.h
|
||||
1485900740 c:\documents\sources\melonds\spi.h
|
||||
|
||||
1485878652 source:c:\documents\sources\melonds\spi.cpp
|
||||
1485901732 source:c:\documents\sources\melonds\spi.cpp
|
||||
<stdio.h>
|
||||
<string.h>
|
||||
"NDS.h"
|
||||
|
@ -108,7 +108,7 @@
|
|||
1484612398 c:\documents\sources\melonds\fifo.h
|
||||
"types.h"
|
||||
|
||||
1485133888 source:c:\documents\sources\melonds\dma.cpp
|
||||
1485901572 source:c:\documents\sources\melonds\dma.cpp
|
||||
<stdio.h>
|
||||
"NDS.h"
|
||||
"DMA.h"
|
||||
|
|
Loading…
Reference in New Issue