From f0c572bc33cde9cb7a87f300752baeb3cc338d24 Mon Sep 17 00:00:00 2001 From: rhgndf <16336768+rhgndf@users.noreply.github.com> Date: Mon, 25 Sep 2023 12:18:49 +0800 Subject: [PATCH] Refactor printing the fuse map --- afterburner.ino | 97 +++++++++++++++++-------------------------------- 1 file changed, 33 insertions(+), 64 deletions(-) diff --git a/afterburner.ino b/afterburner.ino index 7f0436e..442af8e 100644 --- a/afterburner.ino +++ b/afterburner.ino @@ -1952,6 +1952,35 @@ static void printGalName() { } } +static unsigned printJedecBlock(unsigned short k, unsigned short bits, unsigned short rows) { + unsigned short i, j, n; + unsigned char unused; + + for (i = 0; i < bits; i++) + { + n = 0; + unused = 1; + line[n++] = 'L'; + n = addFormatedNumberDec4(k, n); + line[n++] = ' '; + for (j = 0; j < rows; j++, k++) + { + if (getFuseBit(k)) { + unused = 0; + line[n++] = '1'; + } else { + line[n++] = '0'; + } + } + line[n++] = '*'; + line[n++] = 0; + if (!unused) { + Serial.println(line); + } + } + return k; +} + // prints the contents of fuse-map array in the form of JEDEC text file static void printJedec() { @@ -1965,72 +1994,12 @@ static void printJedec() Serial.print(F("*QF")); Serial.print(galinfo[gal].fuses + apdFuse, DEC); Serial.println(F("*QV0*F0*G0*X0*")); + k = 0; if (gal == GAL6001 || gal == GAL6002) { - for (i = k = 0; i < 64; i++) - { - n = 0; - unused = 1; - line[n++] = 'L'; - n = addFormatedNumberDec4(k, n); - line[n++] = ' '; - for (j = 0; j < 114; j++, k++) - { - if (getFuseBit(k)) { - unused = 0; - line[n++] = '1'; - } else { - line[n++] = '0'; - } - } - line[n++] = '*'; - line[n++] = 0; - if (!unused) { - Serial.println(line); - } - } - for (i = 0; i < 11; i++) - { - unused = 1; - n = 0; - line[n++] = 'L'; - n = addFormatedNumberDec4(k, n); - line[n++] = ' '; - for (j = 0; j < 78; j++, k++) - { - if (getFuseBit(k)) { - unused = 0; - line[n++] = '1'; - } else { - line[n++] = '0'; - } - } - line[n++] = '*'; - line[n++] = 0; - if (!unused) { - Serial.println(line); - } - } + k = printJedecBlock(k, 64, 114); + k = printJedecBlock(k, 11, 78); } else { - for( i = k = 0; i < galinfo[gal].bits; i++) { - unused = 1; - n = 0; - line[n++] = 'L'; - n = addFormatedNumberDec4(k, n); - line[n++] = ' '; - for(j= 0; j < galinfo[gal].rows; j++, k++) { - if (getFuseBit(k)) { - unused = 0; - line[n++] = '1'; - } else { - line[n++] = '0'; - } - } - line[n++] = '*'; - line[n++] = 0; - if (!unused) { - Serial.println(line); - } - } + k = printJedecBlock(k, galinfo[gal].bits, galinfo[gal].rows); } if( k < galinfo[gal].uesfuse) {