From 4d3f346edcd8b7edff2415d7c90903c54d4ee34f Mon Sep 17 00:00:00 2001
From: Arisotura <thetotalworm@gmail.com>
Date: Sat, 15 Jun 2019 18:30:12 +0200
Subject: get it to do more interesting things

---
 src/ARM.cpp     |  4 +++-
 src/DSi.cpp     |  1 +
 src/DSi_I2C.cpp | 19 ++++++++++++-------
 3 files changed, 16 insertions(+), 8 deletions(-)

(limited to 'src')

diff --git a/src/ARM.cpp b/src/ARM.cpp
index 870c455..ee72fbe 100644
--- a/src/ARM.cpp
+++ b/src/ARM.cpp
@@ -175,7 +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]);
+    //if (addr==0x037CA0D0) printf("VLORP %08X\n", R[15]);
 
     u32 oldregion = R[15] >> 24;
     u32 newregion = addr >> 24;
@@ -243,6 +243,8 @@ void ARMv4::JumpTo(u32 addr, bool restorecpsr)
         else                addr &= ~0x1;
     }
 
+    //if (addr==0x037D5A18) printf("SHITTY FUNC. %08X\n", R[15]);
+
     u32 oldregion = R[15] >> 23;
     u32 newregion = addr >> 23;
 
diff --git a/src/DSi.cpp b/src/DSi.cpp
index 3ec5ab1..0472f1d 100644
--- a/src/DSi.cpp
+++ b/src/DSi.cpp
@@ -817,6 +817,7 @@ u16 ARM9IORead16(u32 addr)
 {
     switch (addr)
     {
+    case 0x04004004: return 0; // TODO
     }
 
     return NDS::ARM9IORead16(addr);
diff --git a/src/DSi_I2C.cpp b/src/DSi_I2C.cpp
index 03fe85e..4a4f1e7 100644
--- a/src/DSi_I2C.cpp
+++ b/src/DSi_I2C.cpp
@@ -133,7 +133,6 @@ void WriteCnt(u8 val)
 {
     printf("I2C: write CNT %02X\n", val);
 
-    val &= 0xF7;
     // TODO: check ACK flag
     // TODO: transfer delay
     // TODO: IRQ
@@ -141,41 +140,47 @@ void WriteCnt(u8 val)
 
     if (val & (1<<7))
     {
-        bool islast = Cnt & (1<<0);
+        bool islast = val & (1<<0);
 
         if (val & (1<<5))
         {
             // read
-            printf("I2C read, device=%02X, cnt=%02X, last=%d\n", Device, Cnt, islast);
+            val &= 0xF7;
 
             switch (Device)
             {
             case 0x4A: Data = DSi_BPTWL::Read(islast); break;
             default: Data = 0; break;
             }
+
+            printf("I2C read, device=%02X, cnt=%02X, data=%02X, last=%d\n", Device, val, Data, islast);
         }
         else
         {
             // write
-            printf("I2C write, device=%02X, cnt=%02X, last=%d\n", Device, Cnt, islast);
+            val &= 0xE7;
 
             if (val & (1<<1))
             {
-                Device = Data;
-                printf("I2C: start, device=%02X\n", Device);
+                Device = Data & 0xFE;
+                printf("I2C: %s start, device=%02X\n", (Data&0x01)?"read":"write", Device);
 
                 switch (Device)
                 {
-                case 0x4A: DSi_BPTWL::Start(); return;
+                case 0x4A: DSi_BPTWL::Start(); break;
                 }
             }
             else
             {
+                printf("I2C write, device=%02X, cnt=%02X, data=%02X, last=%d\n", Device, val, Data, islast);
+
                 switch (Device)
                 {
                 case 0x4A: DSi_BPTWL::Write(Data, islast); break;
                 }
             }
+
+            val |= (1<<4);
         }
 
         val &= 0x7F;
-- 
cgit v1.2.3