@@ -6,45 +6,46 @@ int DECOMP_MEMCARD_ChecksumLoad(unsigned char* saveBytes, int len)
66 int crc ;
77 int byteIndexEnd ;
88 int byteIndexStart ;
9- int memcardStatusFlags ;
10-
11- // load checkpoints (both zero on first call),
12- // also group all $gp variables together, save asm
13- crc = sdata -> crc16_checkpoint_status ;
14- byteIndexStart = sdata -> crc16_checkpoint_byteIndex ;
15- memcardStatusFlags = sdata -> memcardStatusFlags ;
9+ int boolFinishThisFrame = 1 ;
1610
17- // end of memcard "before" checksum ,
18- // checksum goes in last 2 bytes
11+ // Leave 2 bytes at the end ,
12+ // the checksum is stored there
1913 len -= 2 ;
2014 byteIndexEnd = len ;
15+
16+ // Option 1: Set ZERO for a one-frame load
17+ // Option 2: Set ZERO for first-frame of multi-frame load
18+ // Option 3: Set existing checkpoint from previous frame
19+ crc = sdata -> crc16_checkpoint_status ;
20+ byteIndexStart = sdata -> crc16_checkpoint_byteIndex ;
2121
22- // if not running full checksum in one frame
23- if ((memcardStatusFlags & 8 ) == 0 )
22+ // if this is not a one- frame load
23+ if ((sdata -> memcardStatusFlags & 8 ) == 0 )
2424 {
25- // if more than 512 bytes remain, cap it
26- if (byteIndexEnd > (byteIndexStart + 0x200 ))
25+ // if more than 512 bytes remain
26+ if (byteIndexEnd > (byteIndexStart + 0x200 ))
27+ {
28+ // cap to 512 bytes, and then continue next frame
2729 byteIndexEnd = (byteIndexStart + 0x200 );
30+ boolFinishThisFrame = 0 ;
31+ }
2832 }
2933
30- // checksum 10% of the profile
34+ // run checksum
3135 for (i = byteIndexStart ; i < byteIndexEnd ; i ++ )
3236 {
3337 crc = MEMCARD_CRC16 (crc , saveBytes [i ]);
3438 }
35-
36- // at this point, 'i' equals byteIndexEnd,
37- // but can't use 'i' cause that's too much asm
38-
39- // save checkpoints
40- sdata -> crc16_checkpoint_status = crc ;
41- sdata -> crc16_checkpoint_byteIndex = byteIndexEnd ;
42-
43- // if end is not reached
44- if (byteIndexEnd != len )
39+
40+ // save checkpoints for next frame
41+ if (boolFinishThisFrame == 0 )
42+ {
43+ sdata -> crc16_checkpoint_status = crc ;
44+ sdata -> crc16_checkpoint_byteIndex = byteIndexEnd ;
4545 return MC_RETURN_PENDING ;
46+ }
4647
47- // finalize checksum twice (dont loop)
48+ // finishing check
4849 crc = MEMCARD_CRC16 (crc , saveBytes [byteIndexEnd ]);
4950 crc = MEMCARD_CRC16 (crc , saveBytes [byteIndexEnd + 1 ]);
5051
0 commit comments