From 40542bbd778a63f86efccd71bd58c47a60aa3001 Mon Sep 17 00:00:00 2001 From: meepingsnesroms Date: Thu, 20 Sep 2018 13:13:46 -0700 Subject: [PATCH] Start adding SD command parsing --- missingFunctions.txt | 2 +- src/ads7846.c | 3 +-- src/emulator.c | 13 +++++++++++-- src/emulator.h | 6 ++++++ src/sdCard.c | 41 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 60 insertions(+), 5 deletions(-) diff --git a/missingFunctions.txt b/missingFunctions.txt index f8cafb6..8fd9705 100644 --- a/missingFunctions.txt +++ b/missingFunctions.txt @@ -5,7 +5,7 @@ Nothing can be installed(theres no memory card, hotsync emulation or direct inst When running OS commands through callFunction() it can crash Holding the buttons emulates pressing them like a turbo button(may be caused by the lack of sound emulation, a sound plays on app switch and may block the CPU while waiting for the button to release) State manager goes bezerk and crashes when saving on android, also can't close the window or it won't open again(also only on Android) -If there is no userdata-en-m515.ram on Android the emu won't create it +If there is no userdata-en-m515.ram on Android the emu won't create it(this is likely because theres no graceful exit being done on Android only goto home menu and kill process) Fixed: Only runs in debug mode because the touchscreen can only be pushed with a jump to OS function hack diff --git a/src/ads7846.c b/src/ads7846.c index 45efb3d..7ce6512 100644 --- a/src/ads7846.c +++ b/src/ads7846.c @@ -104,8 +104,7 @@ bool ads7846ExchangeBit(bool bitIn){ ads7846ControlByte <<= 1; ads7846ControlByte |= bitIn; } - - if(ads7846BitsToNextControl == 6){ + else if(ads7846BitsToNextControl == 6){ //control byte and busy cycle finished, get output value bool bitMode = ads7846ControlByte & 0x08; //bool differentialMode = !(ads7846ControlByte & 0x04); diff --git a/src/emulator.c b/src/emulator.c index 611f666..4c1be97 100644 --- a/src/emulator.c +++ b/src/emulator.c @@ -106,7 +106,7 @@ uint32_t emulatorInit(buffer_t palmRomDump, buffer_t palmBootDump, uint32_t spec //config palmClockMultiplier = (specialFeatures & FEATURE_FAST_CPU) ? 2.0 : 1.0;//overclock - palmClockMultiplier *= 0.80;//run at 80% speed, 20% is likely memory waitstates, at 100% it crashes on the spinning Palm welcome screen, 90% works though + palmClockMultiplier *= 0.80;//run at 80% speed, 20% is likely memory waitstates, at 100% it crashes on the spinning Palm welcome screen, 90% crashes at the digitizer test palmSpecialFeatures = specialFeatures; setRtc(0,0,0,0);//RTCTIME and DAYR are not cleared by reset, clear them manually in case the frontend doesnt set the RTC @@ -170,7 +170,8 @@ uint64_t emulatorGetStateSize(){ size += sizeof(uint16_t) * 9;//TX 8 * 16 SPI1 FIFO, 1 index is for FIFO full size += sizeof(uint8_t) * 4;//spi1(R/T)x(Read/Write)Position size += sizeof(uint8_t) * 7;//palmMisc - size += sizeof(uint8_t);//palmSdCard.response + size += sizeof(uint32_t);//palmSdCard.command + size += sizeof(uint8_t) * 2;//palmSdCard.response / palmSdCard.commandBitsRemaining size += sizeof(palmSdCard.dataPacket);//palmSdCard.dataPacket size += palmSdCard.flashChip.size;//palmSdCard.flashChip.data @@ -294,6 +295,10 @@ bool emulatorSaveState(buffer_t buffer){ offset += sizeof(uint8_t); //SD card + writeStateValueUint32(buffer.data + offset, palmSdCard.command); + offset += sizeof(uint32_t); + writeStateValueUint8(buffer.data + offset, palmSdCard.commandBitsRemaining); + offset += sizeof(uint8_t); writeStateValueUint8(buffer.data + offset, palmSdCard.response); offset += sizeof(uint8_t); memcpy(buffer.data + offset, palmSdCard.dataPacket, sizeof(palmSdCard.dataPacket)); @@ -423,6 +428,10 @@ bool emulatorLoadState(buffer_t buffer){ offset += sizeof(uint8_t); //SD card + palmSdCard.command = readStateValueUint32(buffer.data + offset); + offset += sizeof(uint32_t); + palmSdCard.commandBitsRemaining = readStateValueUint8(buffer.data + offset); + offset += sizeof(uint8_t); palmSdCard.response = readStateValueUint8(buffer.data + offset); offset += sizeof(uint8_t); memcpy(palmSdCard.dataPacket, buffer.data + offset, sizeof(palmSdCard.dataPacket)); diff --git a/src/emulator.h b/src/emulator.h index 62e2553..5627261 100644 --- a/src/emulator.h +++ b/src/emulator.h @@ -91,8 +91,14 @@ typedef struct{ }input_t; typedef struct{ + //CPU -> SD + uint64_t command; + uint8_t commandBitsRemaining; + + //SD -> CPU uint8_t response; uint8_t dataPacket[1 + 2048 + 2]; + buffer_t flashChip; }sd_card_t; diff --git a/src/sdCard.c b/src/sdCard.c index 5c2c822..9b2deea 100644 --- a/src/sdCard.c +++ b/src/sdCard.c @@ -4,7 +4,48 @@ #include "emulator.h" +//command format:01IIIIIIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACCCCCCC1//I = index, A = argument, C = CRC + +static inline void sdCardInvalidFormat(){ + palmSdCard.commandBitsRemaining = 63; +} + + bool sdCardExchangeBit(bool bit){ + //check validity of incoming bit + switch(palmSdCard.commandBitsRemaining){ + case 47: + if(bit) + sdCardInvalidFormat(); + return true; + + case 46: + case 0: + if(!bit) + sdCardInvalidFormat(); + return true; + } + + if(palmSdCard.commandBitsRemaining == 0){ + //process command + uint8_t command = palmSdCard.command >> 40 & 0x3F; + uint32_t argument = palmSdCard.command >> 8 & 0xFFFFFFFF; + uint8_t crc = palmSdCard.command >> 1 & 0x7F; + + switch(command){ + + default: + debugLog("SD command:cmd:0x%02X, arg:0x%08X, CRC:0x%02X\n", command, argument, crc); + break; + } + } + else{ + //more data still needed + palmSdCard.command <<= 1; + palmSdCard.command |= bit; + palmSdCard.commandBitsRemaining--; + } + //not done return true;//eek }