shithub: rgbds

Download patch

ref: 2afdc060d00040cdc0b5cf86d7ab3022dad0db66
parent: 7e4104cabe8d995e40e552da2078fea87ff4ada6
author: anthony <[email protected]>
date: Wed Dec 30 11:32:28 EST 2009

add -b option to change MBC type (lmod)

--- a/src/fix/main.c
+++ b/src/fix/main.c
@@ -21,6 +21,7 @@
 #define OPTF_TRUNCATE	0x10L
 #define OPTF_QUIET	0x20L
 #define OPTF_RAMSIZE	0x40L
+#define OPTF_MBCTYPE	0x80L
 
 unsigned long ulOptions;
 
@@ -142,6 +143,7 @@
 	FILE *f;
 	int pad_value = 0;
 	int ram_size = 0;
+	int mbc_type = 0;
 
 	ulOptions = 0;
 
@@ -172,6 +174,20 @@
 					FatalError("Invalid argument for option 'm'");
 				}
 				break;
+			case 'b':
+				ulOptions |= OPTF_MBCTYPE;
+				if (strlen(argv[argn] + 2) > 0 && strlen(argv[argn] + 2) <= 2) {
+					int result;
+					result = sscanf(argv[argn] + 2, "%x", &mbc_type);
+					if (!((result == EOF) || (result == 1))) {
+						FatalError("Invalid argument for option 'b'");
+					}
+				} else if (strlen(argv[argn] + 2) > 0) {
+					FatalError("MBC type must be between 0 and FF");
+				} else {
+					FatalError("Invalid argument for option 'b'");
+				}
+				break;
 			case 'p':
 				ulOptions |= OPTF_PAD;
 				if (strlen(argv[argn] + 2) > 0 && strlen(argv[argn] + 2) <= 2) {
@@ -335,6 +351,23 @@
 
 			if (!(ulOptions & OPTF_QUIET)) {
 				printf("\tRAM size set to %#02X\n", ram_size);
+			}
+		}
+		/*
+		 * -b (Set MBC type) option code
+		 */
+		if (ulOptions & OPTF_MBCTYPE) {
+			/* carttype byte can be anything? */
+			if (!(ulOptions & OPTF_QUIET)) {
+				printf("Setting MBC type\n");
+			}
+			fflush(f);
+			fseek(f, 0x147L, SEEK_SET);
+			fputc(mbc_type, f);
+			fflush(f);
+
+			if (!(ulOptions & OPTF_QUIET)) {
+				printf("\tMBC type set to %#02X\n", mbc_type);
 			}
 		}
 		/*