aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorArisotura <thetotalworm@gmail.com>2019-06-15 16:58:02 +0200
committerArisotura <thetotalworm@gmail.com>2019-06-15 16:58:02 +0200
commit58e3ff61ac31a6ac20e12d03c518a6c16715e83c (patch)
tree0737693fe217043735378bc38110b45449f2ce5b /src
parent7aa5131ec719f6dc4577a660ce94d793aa4a8617 (diff)
add I2C shito
Diffstat (limited to 'src')
-rw-r--r--src/ARM.cpp1
-rw-r--r--src/DSi.cpp8
-rw-r--r--src/DSi.h2
-rw-r--r--src/DSi_I2C.cpp185
-rw-r--r--src/DSi_I2C.h41
-rw-r--r--src/SPI.cpp2
-rw-r--r--src/SPI.h1
7 files changed, 237 insertions, 3 deletions
diff --git a/src/ARM.cpp b/src/ARM.cpp
index f50af25..870c455 100644
--- a/src/ARM.cpp
+++ b/src/ARM.cpp
@@ -175,6 +175,7 @@ void ARMv5::JumpTo(u32 addr, bool restorecpsr)
// aging cart debug crap
//if (addr == 0x0201764C) printf("capture test %d: R1=%08X\n", R[6], R[1]);
//if (addr == 0x020175D8) printf("capture test %d: res=%08X\n", R[6], R[0]);
+ if (addr==0x037CA0D0) printf("VLORP %08X\n", R[15]);
u32 oldregion = R[15] >> 24;
u32 newregion = addr >> 24;
diff --git a/src/DSi.cpp b/src/DSi.cpp
index 22741aa..057d229 100644
--- a/src/DSi.cpp
+++ b/src/DSi.cpp
@@ -25,6 +25,8 @@
#include "sha1/sha1.h"
#include "Platform.h"
+#include "DSi_I2C.h"
+
namespace NDS
{
@@ -59,6 +61,8 @@ void Reset()
{
NDS::ARM9->JumpTo(BootAddr[0]);
NDS::ARM7->JumpTo(BootAddr[1]);
+
+ DSi_I2C::Reset();
}
bool LoadBIOS()
@@ -855,6 +859,8 @@ u8 ARM7IORead8(u32 addr)
{
switch (addr)
{
+ case 0x04004500: return DSi_I2C::ReadData();
+ case 0x04004501: return DSi_I2C::Cnt;
}
return NDS::ARM7IORead8(addr);
@@ -882,6 +888,8 @@ void ARM7IOWrite8(u32 addr, u8 val)
{
switch (addr)
{
+ case 0x04004500: DSi_I2C::WriteData(val); return;
+ case 0x04004501: DSi_I2C::WriteCnt(val); return;
}
return NDS::ARM7IOWrite8(addr, val);
diff --git a/src/DSi.h b/src/DSi.h
index b1b4abf..02f84da 100644
--- a/src/DSi.h
+++ b/src/DSi.h
@@ -19,7 +19,7 @@
#ifndef DSI_H
#define DSI_H
-#include "types.h"
+#include "NDS.h"
namespace DSi
{
diff --git a/src/DSi_I2C.cpp b/src/DSi_I2C.cpp
new file mode 100644
index 0000000..1836c31
--- /dev/null
+++ b/src/DSi_I2C.cpp
@@ -0,0 +1,185 @@
+/*
+ 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_I2C.h"
+
+
+namespace DSi_BPTWL
+{
+
+u8 Registers[0x100];
+u32 CurPos;
+
+bool Init()
+{
+ return true;
+}
+
+void DeInit()
+{
+}
+
+void Reset()
+{
+ CurPos = 0;
+ memset(Registers, 0x5A, 0x100);
+
+ Registers[0x00] = 0x33; // TODO: support others??
+ Registers[0x01] = 0x00;
+ Registers[0x02] = 0x50;
+ Registers[0x10] = 0x00; // power btn
+ Registers[0x11] = 0x00; // reset
+ Registers[0x12] = 0x00; // power btn tap
+ Registers[0x20] = 0x83; // battery
+ Registers[0x21] = 0x07;
+ Registers[0x30] = 0x13;
+ Registers[0x31] = 0x00; // camera power
+ Registers[0x40] = 0x1F; // volume
+ Registers[0x41] = 0x04; // backlight
+ Registers[0x60] = 0x00;
+ Registers[0x61] = 0x01;
+ Registers[0x62] = 0x50;
+ Registers[0x63] = 0x00;
+ Registers[0x70] = 0x00; // boot flag
+ Registers[0x71] = 0x00;
+ Registers[0x72] = 0x00;
+ Registers[0x73] = 0x00;
+ Registers[0x74] = 0x00;
+ Registers[0x75] = 0x00;
+ Registers[0x76] = 0x00;
+ Registers[0x77] = 0x00;
+ Registers[0x80] = 0x10;
+ Registers[0x81] = 0x64;
+}
+
+void Start()
+{
+ CurPos = 0;
+}
+
+u8 Read(bool last)
+{
+ return Registers[CurPos++];
+}
+
+void Write(u8 val, bool last)
+{
+ if (CurPos == 0x11 || CurPos == 0x12 ||
+ CurPos == 0x21 ||
+ CurPos == 0x30 || CurPos == 0x31 ||
+ CurPos == 0x40 || CurPos == 0x31 ||
+ CurPos == 0x60 || CurPos == 0x63 ||
+ (CurPos >= 0x70 && CurPos <= 0x77) ||
+ CurPos == 0x80 || CurPos == 0x81)
+ {
+ Registers[CurPos] = val;
+ }
+
+ CurPos++;
+}
+
+}
+
+
+namespace DSi_I2C
+{
+
+u8 Cnt;
+u32 Device;
+
+bool Init()
+{
+ if (!DSi_BPTWL::Init()) return false;
+
+ return true;
+}
+
+void DeInit()
+{
+ DSi_BPTWL::DeInit();
+}
+
+void Reset()
+{
+ Device = -1;
+
+ DSi_BPTWL::Reset();
+}
+
+void WriteCnt(u8 val)
+{
+ val &= 0xF7;
+ // TODO: check ACK flag
+ // TODO: transfer delay
+
+ if (val & (1<<7))
+ {
+ if (val & (1<<2))
+ {
+ Device = -1;
+ printf("I2C: start\n");
+ }
+ }
+
+ Cnt = val;
+}
+
+u8 ReadData()
+{
+ switch (Device)
+ {
+ case 0x4A: return DSi_BPTWL::Read(Cnt & (1<<0));
+
+ default:
+ printf("I2C: read from unknown device %02X\n", Device);
+ break;
+ }
+
+ return 0;
+}
+
+void WriteData(u8 val)
+{
+ if (Device == -1)
+ {
+ Device = val;
+ switch (Device)
+ {
+ case 0x4A: DSi_BPTWL::Start(); return;
+
+ default:
+ printf("I2C: start on unknown device %02X\n", Device);
+ break;
+ }
+ return;
+ }
+
+ switch (Device)
+ {
+ case 0x4A: DSi_BPTWL::Write(val, Cnt & (1<<0)); return;
+
+ default:
+ printf("I2C: write to unknown device %02X\n", Device);
+ break;
+ }
+}
+
+}
diff --git a/src/DSi_I2C.h b/src/DSi_I2C.h
new file mode 100644
index 0000000..d058be1
--- /dev/null
+++ b/src/DSi_I2C.h
@@ -0,0 +1,41 @@
+/*
+ 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_I2C_H
+#define DSI_I2C_H
+
+namespace DSi_I2C
+{
+
+extern u8 Cnt;
+
+bool Init();
+void DeInit();
+void Reset();
+//void DoSavestate(Savestate* file);
+
+void WriteCnt(u8 val);
+
+u8 ReadData();
+void WriteData(u8 val);
+
+//void TransferDone(u32 param);
+
+}
+
+#endif // DSI_I2C_H
diff --git a/src/SPI.cpp b/src/SPI.cpp
index 759bbd9..8bee66f 100644
--- a/src/SPI.cpp
+++ b/src/SPI.cpp
@@ -581,7 +581,7 @@ namespace SPI
u16 Cnt;
-u32 CurDevice;
+u32 CurDevice; // remove me
bool Init()
diff --git a/src/SPI.h b/src/SPI.h
index 9b987ca..21ad9a6 100644
--- a/src/SPI.h
+++ b/src/SPI.h
@@ -50,7 +50,6 @@ void DeInit();
void Reset();
void DoSavestate(Savestate* file);
-u16 ReadCnt();
void WriteCnt(u16 val);
u8 ReadData();