diff --git a/src/gb/gb.c b/src/gb/gb.c
index 8d2670208..6042eec0b 100644
--- a/src/gb/gb.c
+++ b/src/gb/gb.c
@@ -114,7 +114,7 @@ void GBUnloadROM(struct GB* gb) {
 		if (gb->yankedRomSize) {
 			gb->yankedRomSize = 0;
 		}
-		mappedMemoryFree(gb->memory.rom, 0x400000);
+		mappedMemoryFree(gb->memory.rom, GB_SIZE_CART_MAX);
 	}
 	gb->memory.rom = 0;
 
@@ -140,10 +140,10 @@ void GBApplyPatch(struct GB* gb, struct Patch* patch) {
 	if (!patchedSize) {
 		return;
 	}
-	if (patchedSize > 0x400000) {
-		patchedSize = 0x400000;
+	if (patchedSize > GB_SIZE_CART_MAX) {
+		patchedSize = GB_SIZE_CART_MAX;
 	}
-	gb->memory.rom = anonymousMemoryMap(0x400000);
+	gb->memory.rom = anonymousMemoryMap(GB_SIZE_CART_MAX);
 	if (!patch->applyPatch(patch, gb->pristineRom, gb->pristineRomSize, gb->memory.rom, patchedSize)) {
 		mappedMemoryFree(gb->memory.rom, patchedSize);
 		gb->memory.rom = gb->pristineRom;
diff --git a/src/gb/memory.c b/src/gb/memory.c
index cddd8fa63..81a69853f 100644
--- a/src/gb/memory.c
+++ b/src/gb/memory.c
@@ -514,9 +514,10 @@ void _GBMBC3(struct GBMemory* memory, uint16_t address, uint8_t value) {
 }
 
 void _GBMBC5(struct GBMemory* memory, uint16_t address, uint8_t value) {
-	int bank = value;
-	switch (address >> 13) {
+	int bank;
+	switch (address >> 12) {
 	case 0x0:
+	case 0x1:
 		switch (value) {
 		case 0:
 			memory->sramAccess = false;
@@ -531,10 +532,16 @@ void _GBMBC5(struct GBMemory* memory, uint16_t address, uint8_t value) {
 			break;
 		}
 		break;
-	case 0x1:
+	case 0x2:
+		bank = (memory->currentBank & 0x100) | value;
 		_switchBank(memory, bank);
 		break;
-	case 0x2:
+	case 0x3:
+		bank = (memory->currentBank & 0xFF) | ((value & 1) << 8);
+		_switchBank(memory, bank);
+		break;
+	case 0x4:
+	case 0x5:
 		if (memory->mbcType == GB_MBC5_RUMBLE) {
 			memory->rumble->setRumble(memory->rumble, (value >> 3) & 1);
 			value &= ~8;
diff --git a/src/gb/memory.h b/src/gb/memory.h
index aaaa8e321..f3b25a162 100644
--- a/src/gb/memory.h
+++ b/src/gb/memory.h
@@ -44,6 +44,7 @@ enum {
 
 enum {
 	GB_SIZE_CART_BANK0 = 0x4000,
+	GB_SIZE_CART_MAX = 0x800000,
 	GB_SIZE_VRAM = 0x4000,
 	GB_SIZE_VRAM_BANK0 = 0x2000,
 	GB_SIZE_EXTERNAL_RAM = 0x2000,