summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/chkpar.c16
-rw-r--r--src/cpy.c30
-rw-r--r--src/getsum.c10
-rw-r--r--src/hlp.c4
-rw-r--r--src/inidat.c3
-rw-r--r--src/main.c22
-rw-r--r--src/pat.c7
-rw-r--r--src/red.c5
8 files changed, 72 insertions, 25 deletions
diff --git a/src/chkpar.c b/src/chkpar.c
index 9ad487d..02256d3 100644
--- a/src/chkpar.c
+++ b/src/chkpar.c
@@ -9,6 +9,7 @@
#include <agbsum.h>
+#include <inttypes.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
@@ -58,7 +59,7 @@ agb_chkpar (agb_dat * const restrict dat, int const argc, char const* const* con
} else {
size_t const numpar = argc;
- for (size_t pos = 0x1u;pos < numpar;++pos) {
+ for (size_t pos = 0x1u; pos < numpar; ++pos) {
char const* const par = argv[pos];
if (par[0x0u] == '-') {
@@ -74,6 +75,17 @@ agb_chkpar (agb_dat * const restrict dat, int const argc, char const* const* con
agb_hlp ();
agb_exi (agb_cnd_oky, NULL);
}
+
+ if (!strcmp (lngparam,"version")) {
+ printf(
+ "agbsum #%" PRIX64 "\n"
+ "Copyright 2022-2023 Gabriel Jensen.\n"
+ "\n",
+ agb_rel
+ );
+ agb_cpy();
+ agb_exi (agb_cnd_oky, NULL);
+ }
fprintf (stderr,"Invalid long parameter \"%s\"\n", lngparam);
agb_exi (agb_cnd_err, NULL);
@@ -84,7 +96,7 @@ agb_chkpar (agb_dat * const restrict dat, int const argc, char const* const* con
agb_exi (agb_cnd_err, NULL);
}
- for (char const* chrpos = &par[0x1u];;++chrpos) {if (agb_chkchrpar (dat, chrpos)) {break;}}
+ for (char const* chrpos = &par[0x1u];; ++chrpos) {if (agb_chkchrpar (dat, chrpos)) {break;}}
continue;
}
diff --git a/src/cpy.c b/src/cpy.c
new file mode 100644
index 0000000..700827b
--- /dev/null
+++ b/src/cpy.c
@@ -0,0 +1,30 @@
+/*
+ Copyright 2022-2023 Gabriel Jensen.
+
+ This file is part of agbsum.
+ agbsum is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+ agbsum is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
+ You should have received a copy of the GNU Affero General Public License along with agbsum. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+#include <agbsum.h>
+
+#include <inttypes.h>
+#include <stdio.h>
+
+void
+agb_cpy (void)
+{
+ fputs (
+ "This program is free software: you can redistribute it and/or modify it under\n"
+ " the terms of the GNU General Public License as published by the Free Software\n"
+ " Foundation, either version 3 of the License, or (at your option) any later\n"
+ " version.\n"
+ "This program is distributed in the hope that it will be useful, but WITHOUT ANY\n"
+ " WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR\n"
+ " A PARTICULAR PURPOSE. See the GNU General Public License for more details.\n"
+ "You should have received a copy of the GNU General Public License along with\n"
+ " this program. If not, see <https://www.gnu.org/licenses/>.\n",
+ stdout
+ );
+}
diff --git a/src/getsum.c b/src/getsum.c
index b92fdef..29bc093 100644
--- a/src/getsum.c
+++ b/src/getsum.c
@@ -14,12 +14,12 @@
uint8_t
agb_getsum (void const* const restrict romptr)
{
- uint8_t const* restrict rom = romptr;
- uint8_t chksum = 0x0u;
+ uint8_t const* restrict rom = romptr;
+ uint8_t sum = 0x0u;
- for (unsigned char const* restrict pos = rom;pos != rom+agb_chksumoff;++pos) {chksum += *pos;}
+ for (char unsigned const* restrict pos = rom; pos != rom + agb_sumoff; ++pos) {sum += *pos;}
- chksum = 0x0u-(0x19u+chksum);
+ sum = 0x0u-(0x19u + sum);
- return chksum;
+ return sum;
}
diff --git a/src/hlp.c b/src/hlp.c
index 63a5c08..c674016 100644
--- a/src/hlp.c
+++ b/src/hlp.c
@@ -15,7 +15,7 @@
void
agb_hlp (void)
{
- fprintf (stderr,
+ printf (
"agbsum - Calculate GBA ROM header checksums.\n"
"Release #%" PRIX64 ". Copyright 2022-2023 Gabriel Jensen.\n"
"\n"
@@ -24,7 +24,9 @@ agb_hlp (void)
" --help -h Print the help screen\n"
" -p Patch the ROM\n"
" -s Don't print the results\n"
+ " --version Don't print the results\n"
"\n",
agb_rel
);
+ agb_cpy();
}
diff --git a/src/inidat.c b/src/inidat.c
index 0657c70..b215faf 100644
--- a/src/inidat.c
+++ b/src/inidat.c
@@ -11,7 +11,8 @@
#include <stddef.h>
-void agb_inidat (agb_dat * const restrict dat)
+void
+agb_inidat (agb_dat * const restrict dat)
{
dat->dopat = false;
dat->pth = NULL;
diff --git a/src/main.c b/src/main.c
index 44d8a96..6ee4734 100644
--- a/src/main.c
+++ b/src/main.c
@@ -20,28 +20,28 @@
int main (int const argc, char const* const* const argv)
{
agb_dat dat;
-
agb_inidat (&dat);
-
agb_chkpar (&dat, argc, argv);
dat.rom = agb_opn (dat.pth);
- unsigned char buf[agb_chksumoff+0x1u];
+ char unsigned buf[agb_sumoff + 0x1u];
agb_red (buf, dat.rom);
- unsigned char const chksum = agb_getsum (buf);
- unsigned char const romchksum = buf[agb_chksumoff];
+ {
+ char unsigned const sum = agb_getsum (buf);
+ char unsigned const romsum = buf[agb_sumoff];
- if (romchksum == chksum || !dat.dopat) {
- if (!dat.sil) {printf ("\"%s\": %hhX (%hhX in file)\n", dat.pth, chksum, romchksum);}
- agb_exi (agb_cnd_oky, dat.rom);
- }
+ if (romsum == sum || !dat.dopat) {
+ if (!dat.sil) {printf ("\"%s\": %hhX (%hhX in file)\n", dat.pth, sum, romsum);}
+ agb_exi (agb_cnd_oky, dat.rom);
+ }
- agb_pat (dat.rom, chksum);
+ agb_pat (dat.rom, sum);
- if (!dat.sil) {printf ("\"%s\" @ %zX: %hhX => %hhX\n", dat.pth, agb_romsrt+agb_chksumoff, romchksum, chksum);}
+ if (!dat.sil) {printf ("\"%s\" @ %zX: %hhX => %hhX\n", dat.pth, agb_romsrt + agb_sumoff, romsum, sum);}
+ }
agb_exi (agb_cnd_oky, dat.rom);
}
diff --git a/src/pat.c b/src/pat.c
index 9313665..0a9e1fe 100644
--- a/src/pat.c
+++ b/src/pat.c
@@ -11,11 +11,12 @@
#include <stdio.h>
-void agb_pat (FILE * const restrict rom, unsigned char chksum)
+void
+agb_pat (FILE * const restrict rom, char unsigned sum)
{
- fseek (rom,(long)(agb_romsrt+agb_chksumoff), SEEK_SET);
+ fseek (rom,(long)(agb_romsrt + agb_sumoff), SEEK_SET);
- if (fwrite (&chksum,0x1u,0x1u, rom) != 0x1u) {
+ if (fwrite (&sum,0x1u,0x1u, rom) != 0x1u) {
fputs ("Unable to patch ROM\n", stderr);
agb_exi (agb_cnd_err, rom);
}
diff --git a/src/red.c b/src/red.c
index da9b5af..c152543 100644
--- a/src/red.c
+++ b/src/red.c
@@ -11,10 +11,11 @@
#include <stdio.h>
-void agb_red (void * const restrict buf, FILE * restrict rom)
+void
+agb_red (void * const restrict buf, FILE * restrict rom)
{
fseek (rom, agb_romsrt, SEEK_SET); // We only need to read the part of the ROM that is used for the checksum.
- size_t const num = agb_chksumoff+0x1u;
+ size_t const num = agb_sumoff + 0x1u;
if (fread (buf,0x1u, num, rom) != num) {
fputs ("Unable to read ROM\n", stderr);