Skip to content

Instantly share code, notes, and snippets.

@BrentFarris
Last active Nov 19, 2021
Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@BrentFarris BrentFarris commented Nov 19, 2021

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

@BrentFarris

This comment has been minimized.

Copy link
Owner Author

@BrentFarris BrentFarris commented Nov 19, 2021

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