Skip to content

Instantly share code, notes, and snippets.

@BrentFarris
Last active November 19, 2021 16:52
Show Gist options
  • Save BrentFarris/28ab8529b2d2d74fcdaa56708f66e4d9 to your computer and use it in GitHub Desktop.
Save BrentFarris/28ab8529b2d2d74fcdaa56708f66e4d9 to your computer and use it in GitHub Desktop.
The code I used for my "Hacking Pokemon Red to say Hello! (Nintendo Game Boy)" YouTube video - https://youtu.be/Vm4UpRkBD5g
#include <stdio.h>
#include <stdint.h>
int main(int argc, char** argv) {
FILE* fp = fopen(argv[1], "rb");
if (fp == NULL) {
return -1;
}
fseek(fp, 0L, SEEK_END);
size_t len = ftell(fp);
rewind(fp);
uint8_t* buff = malloc(len);
fread(buff, len, 1, fp);
fclose(fp);
size_t sum = 0;
for (size_t i = 0; i < len; ++i) {
if (i != 0x14E && i != 0x14F) {
sum += buff[i];
} else {
printf("Skipping checksum\n");
}
}
printf("Sum: %zx\n", sum);
return 0;
}
@BrentFarris
Copy link
Author

Improve the code if you wish, I just wanted something working asap :P

@BrentFarris
Copy link
Author

I updated to print out in hex instead of decimal, one less conversion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment