The code I used for my "Hacking Pokemon Red to say Hello! (Nintendo Game Boy)" YouTube video - https://youtu.be/Vm4UpRkBD5g
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
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
Improve the code if you wish, I just wanted something working asap :P