From 586d30fafa5156e468a4ce0d87845127743370e6 Mon Sep 17 00:00:00 2001 From: Pk11 Date: Mon, 21 Feb 2022 23:57:02 -0600 Subject: [PATCH] Improve DSiWare save generation --- arm9/source/game/nds.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/arm9/source/game/nds.c b/arm9/source/game/nds.c index 964842c..75f181e 100644 --- a/arm9/source/game/nds.c +++ b/arm9/source/game/nds.c @@ -55,21 +55,25 @@ u32 BuildTwlSaveHeader(void* sav, u32 size) { u16 n_sct = 1; u16 sct_track = 1; u16 sct_heads = 1; - while (true) { - if (sct_heads < sct_track) { - u16 n_sct_next = sct_track * (sct_heads+1) * (sct_heads+1); - if (n_sct_next < n_sct_max) { - sct_heads++; + u16 n_sct_next = 0; + while (n_sct_next <= n_sct_max) { + n_sct_next = sct_track * (sct_heads + 1) * (sct_heads + 1); + if (n_sct_next <= n_sct_max) { + sct_heads++; + n_sct = n_sct_next; + + sct_track++; + n_sct_next = sct_track * sct_heads * sct_heads; + if (n_sct_next <= n_sct_max) { n_sct = n_sct_next; - } else break; - } else { - u16 n_sct_next = (sct_track+1) * sct_heads * sct_heads; - if (n_sct_next < n_sct_max) { - sct_track++; - n_sct = n_sct_next; - } else break; + } } } + n_sct_next = (sct_track + 1) * sct_heads * sct_heads; + if (n_sct_next <= n_sct_max) { + sct_track++; + n_sct = n_sct_next; + } // sectors per cluster (should be identical to Nintendo) u8 clr_size = (n_sct > 8 * 1024) ? 8 : (n_sct > 1024) ? 4 : 1;