From 39715ca6bf65d2e2dd889cdef4b39d584464d9e7 Mon Sep 17 00:00:00 2001 From: Peter Fors Date: Sun, 6 Apr 2025 12:27:12 +0200 Subject: added more mappers (buggy) --- dump_mappers.c | 112 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 dump_mappers.c (limited to 'dump_mappers.c') diff --git a/dump_mappers.c b/dump_mappers.c new file mode 100644 index 0000000..42034de --- /dev/null +++ b/dump_mappers.c @@ -0,0 +1,112 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#define INES_HEADER_SIZE 16 + +static void process_nes_file(const char *path) { + FILE *f = fopen(path, "rb"); + if(!f) return; + + uint8_t header[INES_HEADER_SIZE]; + if(fread(header, 1, INES_HEADER_SIZE, f) != INES_HEADER_SIZE) { + fclose(f); + return; + } + fclose(f); + + if(memcmp(header, "NES\x1A", 4) != 0) return; + + uint8_t mapper_low = (header[6] >> 4); + uint8_t mapper_high = (header[7] & 0xF0); + uint8_t mapper_ext = header[8] & 0x0F; + uint8_t submapper = header[8] >> 4; + + uint32_t mapper = (submapper << 12) | (mapper_ext << 8) | mapper_high | mapper_low; + printf("0x%04x %s\n", mapper, path); +} + +static void process_zip_file(const char *path) { + unzFile zip = unzOpen(path); + if(!zip) return; + + if(unzGoToFirstFile(zip) != UNZ_OK) { + unzClose(zip); + return; + } + + char filename[256]; + unz_file_info info; + if(unzGetCurrentFileInfo(zip, &info, filename, sizeof(filename), 0, 0, 0, 0) != UNZ_OK) { + unzClose(zip); + return; + } + + if(strstr(filename, ".nes") == 0) { + unzClose(zip); + return; + } + + if(unzOpenCurrentFile(zip) != UNZ_OK) { + unzClose(zip); + return; + } + + uint8_t header[INES_HEADER_SIZE]; + if(unzReadCurrentFile(zip, header, INES_HEADER_SIZE) != INES_HEADER_SIZE) { + unzCloseCurrentFile(zip); + unzClose(zip); + return; + } + unzCloseCurrentFile(zip); + unzClose(zip); + + if(memcmp(header, "NES\x1A", 4) != 0) return; + + uint8_t mapper_low = (header[6] >> 4); + uint8_t mapper_high = (header[7] & 0xF0); + uint8_t mapper_ext = header[8] & 0x0F; + uint8_t submapper = header[8] >> 4; + + uint32_t mapper = (submapper << 12) | (mapper_ext << 8) | mapper_high | mapper_low; + printf("0x%04x %s\n", mapper, path); +} + +static void scan_directory(const char *path) { + DIR *dir = opendir(path); + if(!dir) return; + + struct dirent *entry; + while((entry = readdir(dir))) { + if(entry->d_name[0] == '.') continue; + + char fullpath[1024]; + snprintf(fullpath, sizeof(fullpath), "%s/%s", path, entry->d_name); + + struct stat st; + if(stat(fullpath, &st) < 0) continue; + + if(S_ISDIR(st.st_mode)) { + scan_directory(fullpath); + } else if(strstr(fullpath, ".nes")) { + process_nes_file(fullpath); + } else if(strstr(fullpath, ".zip")) { + process_zip_file(fullpath); + } + } + closedir(dir); +} + +int main(int argc, char **argv) { + if(argc < 2) { + fprintf(stderr, "usage: %s \n", argv[0]); + return 1; + } + scan_directory(argv[1]); + return 0; +} -- cgit v1.2.3