summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/chkpar.c126
-rw-r--r--src/cpy.c49
-rw-r--r--src/exi.c36
-rw-r--r--src/getsum.c40
-rw-r--r--src/hlp.c46
-rw-r--r--src/inidat.c36
-rw-r--r--src/main.c63
-rw-r--r--src/opn.c40
-rw-r--r--src/pat.c38
-rw-r--r--src/red.c42
10 files changed, 0 insertions, 516 deletions
diff --git a/src/chkpar.c b/src/chkpar.c
deleted file mode 100644
index 081173e..0000000
--- a/src/chkpar.c
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- 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 <stddef.h>
-#include <stdio.h>
-#include <string.h>
-
-noreturn static void
-agb_expparval (char const chrpar)
-{
- fprintf (stderr,"Expected value for character parameter '%c'\n", chrpar);
- agb_exi (agb_cnd_err, NULL);
-}
-
-static bool
-agb_chkchrpar (struct agb_dat* const restrict dat, char const* const restrict par)
-{
- char const chrpar = par[0x0];
- if (chrpar == '\x0') {return true;}
-
- char const* const restrict paramval = &par[0x1];
-
- switch (chrpar) {
- default:
- fprintf (stderr,"Invalid character parameter '%c'\n", chrpar);
- agb_exi (agb_cnd_err, NULL);
- case 'h':
- agb_hlp ();
- agb_exi (agb_cnd_oky, NULL);
- case 'i':
- {
- if (paramval[0x0] == '\x0') {agb_expparval (chrpar);}
- dat->pth = paramval;
- }
- return true;
- case 'p':
- dat->dopat = true;
- return false;
- case 's':
- dat->sil = true;
- return false;
- }
-}
-
-void
-agb_chkpar (struct agb_dat* const restrict dat, int const argc, char const* const* const argv) {
- if (argc < 0x2) {
- agb_hlp ();
- agb_exi (agb_cnd_oky, NULL);
- } else {
- size_t const numpar = argc; // Prettier.
-
- for (ptrdiff_t pos = 0x1u; pos < (ptrdiff_t)numpar; ++pos) {
- // Iterate over the parameters. One hyphen denotes character parameters (-h) whilst two denote long paramters (--help).
-
- char const* const par = argv[pos];
- if (par[0x0] == '-') {
- if (par[0x1] == '-') {
- char const* const lngparam = &par[0x2];
-
- // Check long parameters.
-
- if (lngparam[0x0] == '\x0') {
- fputs ("Missing long parameter after '--' sequence\n", stderr);
- agb_exi (agb_cnd_err, NULL);
- }
-
- if (!strcmp (lngparam,"help")) {
- agb_hlp ();
- agb_exi (agb_cnd_oky, NULL);
- }
-
- if (!strcmp (lngparam,"version")) {
- agb_cpy();
- agb_exi (agb_cnd_oky, NULL);
- }
-
- fprintf (stderr,"Invalid long parameter \"%s\"\n", lngparam);
- agb_exi (agb_cnd_err, NULL);
- }
-
- if (par[0x1] == '\x0') {
- fputs ("Missing character parameter after '-'\n", stderr);
- agb_exi (agb_cnd_err, NULL);
- }
-
- // Check character parameters.
-
- for (char const* chrpos = &par[0x1];; ++chrpos) {if (agb_chkchrpar (dat, chrpos)) {break;}}
-
- continue;
- }
- }
-
- // We did not find the 'i' parameter, so we don't know where the ROM is.
-
- if (dat->pth == NULL) {
- fputs ("ROM not set (missing character parameter 'i')\n", stderr);
- agb_exi (agb_cnd_err, NULL);
- }
- }
-}
diff --git a/src/cpy.c b/src/cpy.c
deleted file mode 100644
index a3f1a4b..0000000
--- a/src/cpy.c
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- 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)
-{
- printf (
- "agbsum #%" PRIX64 " - Copyright 2022-2023 Gabriel Jensen.\n"
- "\n"
- "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"
- "\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 A\n"
- "PARTICULAR PURPOSE. See the GNU General Public License for more details.\n"
- "\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",
- agb_rel
- );
-}
diff --git a/src/exi.c b/src/exi.c
deleted file mode 100644
index e960706..0000000
--- a/src/exi.c
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- 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 <stdio.h>
-#include <stdlib.h>
-
-noreturn void
-agb_exi (enum agb_cnd const cnd, FILE* restrict img)
-{
- if (img != NULL) { fclose (img); }
-
- exit (cnd == agb_cnd_oky ? EXIT_SUCCESS : EXIT_FAILURE);
-}
diff --git a/src/getsum.c b/src/getsum.c
deleted file mode 100644
index fd0e4a4..0000000
--- a/src/getsum.c
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- 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 <stdint.h>
-
-uint8_t
-agb_getsum (void const* const restrict imgptr)
-{
- uint8_t const* restrict img = imgptr;
- uint8_t sum = UINT8_C(0x0);
-
- for (char unsigned const* restrict pos = img; pos != img + agb_sumoff; ++pos) { sum += *pos; }
-
- sum = -(UINT8_C(0x19) + sum);
-
- return sum;
-}
diff --git a/src/hlp.c b/src/hlp.c
deleted file mode 100644
index 7e10e67..0000000
--- a/src/hlp.c
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- 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_hlp (void)
-{
- fputs (
- "agbsum - Patch AGB image header checksums.\n"
- "\n"
- "Usage: agbsum [options] <image>\n"
- "Options:\n"
- " --help -h Print the help screen\n"
- " -p Patch the image file\n"
- " -s Don't print results\n"
- " --version Print the version number\n"
- "\n",
- stdout
- );
- agb_cpy ();
-}
diff --git a/src/inidat.c b/src/inidat.c
deleted file mode 100644
index 05cd278..0000000
--- a/src/inidat.c
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- 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 <stddef.h>
-
-void
-agb_inidat (struct agb_dat* const restrict dat)
-{
- dat->dopat = false;
- dat->pth = NULL;
- dat->sil = false;
- dat->img = NULL;
-}
diff --git a/src/main.c b/src/main.c
deleted file mode 100644
index d130bd3..0000000
--- a/src/main.c
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- 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 <limits.h>
-#include <stdint.h>
-#include <stdio.h>
-
-#if CHAR_BIT != 0x8
-#error "agbsum only support 8-bit byte systems"
-#endif
-
-int main (int const argc, char const* const* const argv)
-{
- struct agb_dat dat;
- agb_inidat (&dat);
- agb_chkpar (&dat, argc, argv);
-
- dat.img = agb_opn (dat.pth);
-
- char unsigned buf[agb_sumoff + 0x1];
-
- agb_red (buf, dat.img);
-
- {
- char unsigned const sum = agb_getsum (buf);
- char unsigned const romsum = buf[agb_sumoff];
-
- if (romsum == sum || !dat.dopat) {
- // Don't patch the ROM if it's already okay or we're not allowed to.
- if (!dat.sil) {printf ("\"%s\": %hhX (%hhX in file)\n", dat.pth, sum, romsum);}
- agb_exi (agb_cnd_oky, dat.img);
- }
-
- agb_pat (dat.img, sum);
-
- if (!dat.sil) {printf ("\"%s\" @ %zX: %hhX => %hhX\n", dat.pth, agb_iptsrt + agb_sumoff, romsum, sum);} // If we aren't supposed to print anything then don't.
- }
-
- agb_exi (agb_cnd_oky, dat.img);
-}
diff --git a/src/opn.c b/src/opn.c
deleted file mode 100644
index 9990709..0000000
--- a/src/opn.c
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- 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 <stdio.h>
-
-FILE*
-agb_opn (char const* const restrict pth)
-{
- FILE* img = fopen (pth, "r+");
-
- if (img == NULL) {
- fputs ("Unable to open ROM\n", stderr);
- agb_exi (agb_cnd_err, NULL);
- }
-
- return img;
-}
diff --git a/src/pat.c b/src/pat.c
deleted file mode 100644
index 39b340f..0000000
--- a/src/pat.c
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- 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 <stdio.h>
-
-void
-agb_pat (FILE* const restrict img, char unsigned sum)
-{
- fseek (img, (long)(agb_iptsrt + agb_sumoff), SEEK_SET);
-
- if (fwrite (&sum, 0x1u, 0x1u, img) != 0x1u) {
- fputs ("Unable to patch ROM\n", stderr);
- agb_exi (agb_cnd_err, img);
- }
-}
diff --git a/src/red.c b/src/red.c
deleted file mode 100644
index 64d81da..0000000
--- a/src/red.c
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- 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 <stdio.h>
-
-void
-agb_red (void* const restrict buf, FILE* restrict img)
-{
- // We only need to read the part of the image
- // that is used for the checksum.
- fseek (img, agb_iptsrt, SEEK_SET);
-
- size_t const num = agb_sumoff + 0x1u;
-
- if (fread (buf, 0x1u, num, img) != num) {
- fputs ("Unable to read ROM\n", stderr);
- agb_exi (agb_cnd_err, img);
- }
-}