From 141e2a7ab0bf5c70e478ddb18c5343569b8324fc Mon Sep 17 00:00:00 2001 From: StapleButter Date: Tue, 19 Dec 2017 00:20:36 +0100 Subject: [PATCH] clear chipselect when turning SPI off. fixes libnds bugs. --- src/SPI.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/SPI.cpp b/src/SPI.cpp index 534f6ca2..2c62a6a3 100644 --- a/src/SPI.cpp +++ b/src/SPI.cpp @@ -528,6 +528,18 @@ void Reset() void WriteCnt(u16 val) { + // turning it off should clear chipselect + // TODO: confirm on hardware. libnds expects this, though. + if ((Cnt & (1<<15)) && !(val & (1<<15))) + { + switch (Cnt & 0x0300) + { + case 0x0000: SPI_Powerman::Hold = 0; break; + case 0x0100: SPI_Firmware::Hold = 0; break; + case 0x0200: SPI_TSC::DataPos = 0; break; + } + } + Cnt = (Cnt & 0x0080) | (val & 0xCF03); if (val & 0x0400) printf("!! CRAPOED 16BIT SPI MODE\n"); if (Cnt & (1<<7)) printf("!! CHANGING SPICNT DURING TRANSFER: %04X\n", val);