From f1c34faac8ca589d6a432d19861d7bb78c4e069f Mon Sep 17 00:00:00 2001 From: ahezard Date: Tue, 31 Jan 2017 22:36:04 +0100 Subject: [PATCH 1/2] code simplification --- cardengine_arm9/source/cardEngine.c | 52 ++++++++--------------------- 1 file changed, 14 insertions(+), 38 deletions(-) diff --git a/cardengine_arm9/source/cardEngine.c b/cardengine_arm9/source/cardEngine.c index 29bea35ff..f06da7e9a 100644 --- a/cardengine_arm9/source/cardEngine.c +++ b/cardengine_arm9/source/cardEngine.c @@ -111,8 +111,8 @@ void cardRead (u32* cacheStruct) { if((src - currentSector) + len2 > READ_SIZE_ARM7){ len2 = currentSector - src + READ_SIZE_ARM7; } - - if(len2 >= 512 && len2 % 32 == 0 && ((u32)dst)%4 == 0 && src%4 == 0) { + + if(len2 >= 512 && len2 % 32 == 0 && ((u32)dst)%4 == 0 && src%4 == 0) { /*// send a log command for debug purpose // ------------------------------------- commandRead = 0x026ff800; @@ -134,54 +134,30 @@ void cardRead (u32* cacheStruct) { cardStruct[0] = src + len2; cardStruct[1] = dst + len2; cardStruct[2] = len - len2; - } else { - bool remainToRead = true; - u32 src2 = cardStruct[0]; - while (remainToRead && (src2-currentSector < READ_SIZE_ARM7) ) { - u32 page2 = (src2/512)*512; - - /*// send a log command for debug purpose - // ------------------------------------- - commandRead = 0x026ff800; - - sharedAddr[0] = page2; - sharedAddr[1] = len2; - sharedAddr[2] = 0x03740000+page2-sector; - sharedAddr[3] = commandRead; - - IPC_SendSync(0xEE24); - - while(sharedAddr[3] != (vu32)0); - // -------------------------------------*/ - - // read via the 512b ram cache - fastCopy32(BUFFER_ADDRESS+(page2-currentSector), cacheBuffer, 512); - *cachePage = page2; - remainToRead = (*readCachedRef)(cacheStruct); - src2 = cardStruct[0]; - } - } - if(len == len2) { - len =0; + } else { /*// send a log command for debug purpose // ------------------------------------- commandRead = 0x026ff800; - sharedAddr[0] = dst; - sharedAddr[1] = len; - sharedAddr[2] = src; + sharedAddr[0] = page2; + sharedAddr[1] = len2; + sharedAddr[2] = 0x03740000+page2-sector; sharedAddr[3] = commandRead; IPC_SendSync(0xEE24); while(sharedAddr[3] != (vu32)0); // -------------------------------------*/ - - } else { - // bigger than 32k unaligned command + + // read via the 512b ram cache + fastCopy32(BUFFER_ADDRESS+(page-currentSector), cacheBuffer, 512); + *cachePage = page; + (*readCachedRef)(cacheStruct); + } + len = cardStruct[2]; + if(len>0) { src = cardStruct[0]; dst = cardStruct[1]; - len = cardStruct[2]; page = (src/512)*512; sector = (src/READ_SIZE_ARM7)*READ_SIZE_ARM7; } From 24c7b7dbbaaa14ac046c122926eafe1e5fc3b903 Mon Sep 17 00:00:00 2001 From: ahezard Date: Tue, 31 Jan 2017 23:00:42 +0100 Subject: [PATCH 2/2] litlle optimization --- cardengine_arm9/source/cardEngine.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cardengine_arm9/source/cardEngine.c b/cardengine_arm9/source/cardEngine.c index f06da7e9a..33f7b52a4 100644 --- a/cardengine_arm9/source/cardEngine.c +++ b/cardengine_arm9/source/cardEngine.c @@ -111,6 +111,11 @@ void cardRead (u32* cacheStruct) { if((src - currentSector) + len2 > READ_SIZE_ARM7){ len2 = currentSector - src + READ_SIZE_ARM7; } + + if(len2 > 512) { + len2 -= src%4; + len2 -= len2 % 32; + } if(len2 >= 512 && len2 % 32 == 0 && ((u32)dst)%4 == 0 && src%4 == 0) { /*// send a log command for debug purpose