From: Spacy <sp...@us...> - 2006-06-06 14:57:16
|
Update of /cvsroot/vba/VisualBoyAdvance/src/gb In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv1412/src/gb Modified Files: GB.cpp GB.h gbCheats.cpp gbCheats.h gbMemory.cpp gbMemory.h Log Message: Pokemonhacker: Improved/corrected the GG and GS cheats handling. Added support for the GS hardware rom bank switching. Corrected a crash in loading GB savestates while in GBC mode. Index: gbMemory.cpp =================================================================== RCS file: /cvsroot/vba/VisualBoyAdvance/src/gb/gbMemory.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** gbMemory.cpp 13 May 2006 16:32:15 -0000 1.6 --- gbMemory.cpp 6 Jun 2006 14:25:43 -0000 1.7 *************** *** 1532,1536 **** } ! mapperMMM01 gbDataMMM01 ={ 0, // RAM enable --- 1532,1536 ---- } ! // MMM01 Used in Momotarou collection (however the rom is corrupted) mapperMMM01 gbDataMMM01 ={ 0, // RAM enable *************** *** 1543,1547 **** }; ! // MBC1 ROM write registers void mapperMMM01ROM(u16 address, u8 value) { --- 1543,1547 ---- }; ! // MMM01 ROM write registers void mapperMMM01ROM(u16 address, u8 value) { *************** *** 1614,1618 **** } ! // MBC1 RAM write void mapperMMM01RAM(u16 address, u8 value) { --- 1614,1618 ---- } ! // MMM01 RAM write void mapperMMM01RAM(u16 address, u8 value) { *************** *** 1653,1654 **** --- 1653,1717 ---- } } + + // GameGenie ROM write registers + void mapperGGROM(u16 address, u8 value) + { + int tmpAddress = 0; + + switch(address & 0x6000) { + case 0x0000: // RAM enable register + break; + case 0x2000: // GameGenie has only a half bank + break; + case 0x4000: // GameGenie has no RAM + if ((address >=0x4001) && (address <= 0x4020)) // GG Hardware Registers + gbMemoryMap[address >> 12][address & 0x0fff] = value; + break; + case 0x6000: // GameGenie has only a half bank + break; + } + } + + + // GS3 Used to emulate the GS V3.0 rom bank switching + mapperGS3 gbDataGS3 = { 1 }; // ROM bank + + void mapperGS3ROM(u16 address, u8 value) + { + int tmpAddress = 0; + + switch(address & 0x6000) { + case 0x0000: // GS has no ram + break; + case 0x2000: // GS has no 'classic' ROM bank select + break; + case 0x4000: // GS has no ram + break; + case 0x6000: // 0x6000 area is RW, and used for GS hardware registers + + if (address == 0x7FE1) // This is the (half) ROM bank select register + { + if(value == gbDataGS3.mapperROMBank) + break; + tmpAddress = value << 13; + + tmpAddress &= gbRomSizeMask; + gbDataGS3.mapperROMBank = value; + gbMemoryMap[0x04] = &gbRom[tmpAddress]; + gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; + } + else + gbMemoryMap[address>>12][address & 0x0fff] = value; + break; + } + } + + void memoryUpdateMapGS3() + { + int tmpAddress = gbDataGS3.mapperROMBank << 13; + + tmpAddress &= gbRomSizeMask; + // GS can only change a half ROM bank + gbMemoryMap[0x04] = &gbRom[tmpAddress]; + gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; + } \ No newline at end of file Index: gbCheats.h =================================================================== RCS file: /cvsroot/vba/VisualBoyAdvance/src/gb/gbCheats.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** gbCheats.h 13 May 2004 15:06:46 -0000 1.3 --- gbCheats.h 6 Jun 2006 14:25:43 -0000 1.4 *************** *** 51,54 **** --- 51,55 ---- extern void gbCheatDisable(int); extern u8 gbCheatRead(u16); + extern void gbCheatWrite(bool); extern int gbCheatNumber; Index: GB.h =================================================================== RCS file: /cvsroot/vba/VisualBoyAdvance/src/gb/GB.h,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** GB.h 27 May 2006 14:47:33 -0000 1.8 --- GB.h 6 Jun 2006 14:25:43 -0000 1.9 *************** *** 39,42 **** --- 39,43 ---- extern bool gbLoadRom(const char *); extern void gbEmulate(int); + extern void gbWriteMemory(register u16, register u8); extern void gbDrawLine(); extern bool gbIsGameboyRom(const char *); Index: gbMemory.h =================================================================== RCS file: /cvsroot/vba/VisualBoyAdvance/src/gb/gbMemory.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** gbMemory.h 30 Apr 2006 14:44:16 -0000 1.3 --- gbMemory.h 6 Jun 2006 14:25:43 -0000 1.4 *************** *** 147,150 **** --- 147,154 ---- }; + struct mapperGS3 { + int mapperROMBank; + }; + extern mapperMBC1 gbDataMBC1; extern mapperMBC2 gbDataMBC2; *************** *** 155,158 **** --- 159,163 ---- extern mapperTAMA5 gbDataTAMA5; extern mapperMMM01 gbDataMMM01; + extern mapperGS3 gbDataGS3; void mapperMBC1ROM(u16,u8); *************** *** 180,183 **** --- 185,190 ---- void mapperMMM01ROM(u16,u8); void mapperMMM01RAM(u16,u8); + void mapperGGROM(u16,u8); + void mapperGS3ROM(u16,u8); //extern void (*mapper)(u16,u8); //extern void (*mapperRAM)(u16,u8); *************** *** 193,196 **** --- 200,204 ---- extern void memoryUpdateMapTAMA5(); extern void memoryUpdateMapMMM01(); + extern void memoryUpdateMapGS3(); Index: GB.cpp =================================================================== RCS file: /cvsroot/vba/VisualBoyAdvance/src/gb/GB.cpp,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** GB.cpp 27 May 2006 14:47:33 -0000 1.26 --- GB.cpp 6 Jun 2006 14:25:43 -0000 1.27 *************** *** 134,137 **** --- 134,138 ---- int gbIntBreak = 0; int gbInterruptLaunched = 0; + u8 gbCheatingDevice = 0; // 1 = GS, 2 = GG // breakpoint bool breakpoint = false; *************** *** 726,733 **** #endif - if(mapper) (*mapper)(address, value); return; } --- 727,734 ---- #endif if(mapper) (*mapper)(address, value); return; + } *************** *** 738,744 **** // This part is used to emulate a small difference between hardwares // (check 8-in-1's arrow on GBA/GBC to verify it) ! ((register_LY == 0) && ((gbHardware & 0xa) && (gbScreenOn==false) && ! (register_LCDC & 0x80)) && ! (gbLcdLYIncrementTicksDelayed ==(GBLY_INCREMENT_CLOCK_TICKS-GBLCD_MODE_2_CLOCK_TICKS)))) gbMemoryMap[address>>12][address&0x0fff] = value; return; --- 739,745 ---- // This part is used to emulate a small difference between hardwares // (check 8-in-1's arrow on GBA/GBC to verify it) ! ((register_LY == 0) && ((gbHardware & 0xa) && (gbScreenOn==false) && ! (register_LCDC & 0x80)) && ! (gbLcdLYIncrementTicksDelayed ==(GBLY_INCREMENT_CLOCK_TICKS-GBLCD_MODE_2_CLOCK_TICKS)))) gbMemoryMap[address>>12][address&0x0fff] = value; return; *************** *** 772,785 **** // OAM not accessible during mode 2 & 3. ! if((address < 0xfea0) && ! (((gbHardware & 0xa) && ((gbLcdMode | gbLcdModeDelayed) &2)) || ! ((gbHardware & 5) && (((gbLcdModeDelayed == 2) && ! (gbLcdTicksDelayed<=GBLCD_MODE_2_CLOCK_TICKS)) || ! (gbLcdModeDelayed == 3))))) { ! return; } ! if(address < 0xff00){ gbMemory[address] = value; return; --- 773,793 ---- // OAM not accessible during mode 2 & 3. ! if(address < 0xfea0) ! { ! if (((gbHardware & 0xa) && ((gbLcdMode | gbLcdModeDelayed) &2)) || ! ((gbHardware & 5) && (((gbLcdModeDelayed == 2) && ! (gbLcdTicksDelayed<=GBLCD_MODE_2_CLOCK_TICKS)) || ! (gbLcdModeDelayed == 3)))) ! return; ! else ! { ! gbMemory[address] = value; ! return; ! } } ! ! if((address > 0xfea0) && (address < 0xff00)){ // GBC allows reading/writing to that area gbMemory[address] = value; return; *************** *** 1712,1715 **** --- 1720,1736 ---- break; } + + if ((address >= 0xfea0) && (address < 0xff00)) + { + if (gbHardware & 1) + return ((((address + ((address >> 4) - 0xfea)) >> 2) & 1) ? 0x00 : 0xff ); + else if (gbHardware & 2) + return gbMemoryMap[address>>12][address & 0x0fff]; + else if (gbHardware & 4) + return ((((address + ((address >> 4) - 0xfea)) >> 2) & 1) ? 0xff : 0x00 ); + else if (gbHardware & 8) + return ((address & 0xf0) |((address & 0xf0)>>4)); + } + return gbMemoryMap[address>>12][address & 0x0fff]; } *************** *** 1958,1961 **** --- 1979,1994 ---- return 0xff; + if ((address >= 0xfea0) && (address < 0xff00)) + { + if (gbHardware & 1) + return ((((address + ((address >> 4) - 0xfea)) >> 2) & 1) ? 0x00 : 0xff ); + else if (gbHardware & 2) + return gbMemoryMap[address>>12][address & 0x0fff]; + else if (gbHardware & 4) + return ((((address + ((address >> 4) - 0xfea)) >> 2) & 1) ? 0xff : 0x00 ); + else if (gbHardware & 8) + return ((address & 0xf0) |((address & 0xf0)>>4)); + } + return gbMemoryMap[address>>12][address & 0x0fff]; } *************** *** 1963,1966 **** --- 1996,2000 ---- void gbVblank_interrupt() { + gbCheatWrite(false); // Emulates GS codes. gbMemory[0xff0f] = register_IF &= 0xfe; gbWriteMemory(--SP.W, PC.B.B1); *************** *** 2172,2176 **** if (gbMemory != NULL) { ! memset(gbMemory,0, 65536); for (int temp = 0xC000; temp < 0xE000; temp++) if ((temp & 0x8) ^((temp & 0x800)>>8)) --- 2206,2210 ---- if (gbMemory != NULL) { ! memset(gbMemory,0xff, 65536); for (int temp = 0xC000; temp < 0xE000; temp++) if ((temp & 0x8) ^((temp & 0x800)>>8)) *************** *** 2618,2621 **** --- 2652,2656 ---- inBios = false; } + gbMemoryMap[0x01] = &gbRom[0x1000]; gbMemoryMap[0x02] = &gbRom[0x2000]; *************** *** 2642,2646 **** gbMemoryMap[0x0d] = &gbMemory[0xd000]; gbMemoryMap[0x0e] = &gbMemory[0xe000]; ! gbMemoryMap[0x0f] = &gbMemory[0xf000]; } --- 2677,2681 ---- gbMemoryMap[0x0d] = &gbMemory[0xd000]; gbMemoryMap[0x0e] = &gbMemory[0xe000]; ! gbMemoryMap[0x0f] = &gbMemory[0xf000]; } *************** *** 2660,2663 **** --- 2695,2700 ---- gbSystemMessage = false; + gbCheatWrite(true); // Emulates GS codes. + } *************** *** 3597,3603 **** } - int oldgbCgbMode = gbCgbMode; - int oldgbSgbMode = gbSgbMode; - gbReset(); --- 3634,3637 ---- *************** *** 3608,3634 **** // Correct crash when loading color gameboy save in regular gameboy type. ! if (oldgbCgbMode != gbCgbMode) { ! if (!gbCgbMode) ! { ! if(gbVram != NULL) { ! free(gbVram); ! gbVram = NULL; ! } ! if(gbWram != NULL) { ! free(gbWram); ! gbWram = NULL; ! } } ! else ! { ! if(gbVram == NULL) ! gbVram = (u8 *)malloc(0x4000); ! if(gbWram == NULL) ! gbWram = (u8 *)malloc(0x8000); ! memset(gbVram,0,0x4000); ! memset(gbPalette,0, 2*128); } } if(version >= GBSAVE_GAME_VERSION_7) { --- 3642,3667 ---- // Correct crash when loading color gameboy save in regular gameboy type. ! if (!gbCgbMode) { ! if(gbVram != NULL) { ! free(gbVram); ! gbVram = NULL; } ! if(gbWram != NULL) { ! free(gbWram); ! gbWram = NULL; } } + else + { + if(gbVram == NULL) + gbVram = (u8 *)malloc(0x4000); + if(gbWram == NULL) + gbWram = (u8 *)malloc(0x8000); + memset(gbVram,0,0x4000); + memset(gbPalette,0, 2*128); + } + + if(version >= GBSAVE_GAME_VERSION_7) { *************** *** 3775,3778 **** --- 3808,3815 ---- memoryUpdateMapMBC7(); break; + case 0x56: + // GS3 + memoryUpdateMapGS3(); + break; case 0xfd: // TAMA5 *************** *** 4028,4031 **** --- 4065,4070 ---- if(gbRomSize < gbRomSizes[gbRom[0x148]]) { gbRom = (u8 *)realloc(gbRom, gbRomSizes[gbRom[0x148]]); + for (int i = gbRomSize; i<gbRomSizes[gbRom[0x148]]; i++) + gbRom[i] = 0x00; // Not sure if it's 0x00, 0xff or random data... } // (it's in the case a cart is 'lying' on its size. *************** *** 4060,4063 **** --- 4099,4115 ---- gbRom[0x149] = ramsize; + if ((gbRom[2] == 0x6D) && (gbRom[5] == 0x47) && (gbRom[6] == 0x65) && (gbRom[7] == 0x6E) && + (gbRom[8] == 0x69) && (gbRom[9] == 0x65) && (gbRom[0xA] == 0x28) && (gbRom[0xB] == 0x54)) + { + gbCheatingDevice = 1; // GameGenie + for (int i = 0; i < 0x20; i++) // Cleans GG hardware registers + gbRom[0x4000+i] = 0; + } + else if (((gbRom[0x104] == 0x44) && (gbRom[0x156] == 0xEA) && (gbRom[0x158] == 0x7F) && + (gbRom[0x159] == 0xEA) && (gbRom[0x15B] == 0x7F)) || ((gbRom[0x165] == 0x3E) && + (gbRom[0x166] == 0xD9) && (gbRom[0x16D] == 0xE1) && (gbRom[0x16E] == 0x7F))) + gbCheatingDevice = 2; // GameShark + else gbCheatingDevice = 0; + if(ramsize > 5) { systemMessage(MSG_UNSUPPORTED_RAM_SIZE, *************** *** 4090,4093 **** --- 4142,4149 ---- gbRomType = 0x1b; } + else if (gbCheatingDevice == 1) + gbRomType = 0x55; + else if (gbCheatingDevice == 2) + gbRomType = 0x56; gbRom[0x147] = gbRomType; *************** *** 4101,4105 **** case 0x03: case 0x08: ! case 0x09: // MBC 1 mapper = mapperMBC1ROM; --- 4157,4161 ---- case 0x03: case 0x08: ! case 0x09: // MBC 1 mapper = mapperMBC1ROM; *************** *** 4155,4158 **** --- 4211,4222 ---- mapperReadRAM = mapperMBC7ReadRAM; break; + // GG (GameGenie) + case 0x55: + mapper = mapperGGROM; + break; + case 0x56: + // GS (GameShark) + mapper = mapperGS3ROM; + break; case 0xfd: // TAMA5 Index: gbCheats.cpp =================================================================== RCS file: /cvsroot/vba/VisualBoyAdvance/src/gb/gbCheats.cpp,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** gbCheats.cpp 27 May 2006 14:47:33 -0000 1.10 --- gbCheats.cpp 6 Jun 2006 14:25:43 -0000 1.11 *************** *** 28,34 **** --- 28,36 ---- #include "gbCheats.h" #include "gbGlobals.h" + #include "GB.h" gbCheat gbCheatList[100]; int gbCheatNumber = 0; + int gbNextCheat = 0; bool gbCheatMap[0x10000]; *************** *** 181,188 **** GBCHEAT_HEX_VALUE(code[5]); - if(address < 0xa000 || - address > 0xdfff) - return false; - return true; } --- 183,186 ---- *************** *** 221,227 **** gbCheatList[i].enabled = true; ! ! gbCheatMap[gbCheatList[i].address] = true; ! gbCheatNumber++; } --- 219,233 ---- gbCheatList[i].enabled = true; ! ! int gsCode = gbCheatList[i].code; ! ! if ((gsCode !=1) && ((gsCode & 0xF0) !=0x80) && ((gsCode & 0xF0) !=0x90) && ! ((gsCode & 0xF0) !=0xA0) && ((gsCode) !=0xF0) && ((gsCode) !=0xF1)) ! systemMessage(MSG_WRONG_GAMESHARK_CODE, ! N_("Wrong GameShark code type : %s"), code); ! else if (((gsCode & 0xF0) ==0xA0) || ((gsCode) ==0xF0) || ((gsCode) ==0xF1)) ! systemMessage(MSG_UNSUPPORTED_GAMESHARK_CODE, ! N_("Unsupported GameShark code type : %s"), code); ! gbCheatNumber++; } *************** *** 319,323 **** strcpy(gbCheatList[i].cheatDesc, desc); ! gbCheatList[i].code = 1; gbCheatList[i].value = (GBCHEAT_HEX_VALUE(code[0]) << 4) + GBCHEAT_HEX_VALUE(code[1]); --- 325,329 ---- strcpy(gbCheatList[i].cheatDesc, desc); ! gbCheatList[i].code = 0x101; gbCheatList[i].value = (GBCHEAT_HEX_VALUE(code[0]) << 4) + GBCHEAT_HEX_VALUE(code[1]); *************** *** 344,347 **** --- 350,354 ---- } + gbCheatList[i].enabled = true; *************** *** 428,431 **** --- 435,439 ---- } + // Used to emulated GG codes u8 gbCheatRead(u16 address) { *************** *** 440,461 **** return gbCheatList[i].value; break; ! case 0x00: ! case 0x01: ! case 0x80: ! return gbCheatList[i].value; ! case 0x90: ! case 0x91: ! case 0x92: ! case 0x93: ! case 0x94: ! case 0x95: ! case 0x96: ! case 0x97: ! if(address >= 0xd000 && address < 0xe000) { ! if(((gbMemoryMap[0x0d] - gbWram)/0x1000) == ! (gbCheatList[i].code - 0x90)) ! return gbCheatList[i].value; ! } else return gbCheatList[i].value; } } --- 448,454 ---- return gbCheatList[i].value; break; ! case 0x101: // GameGenie 6 digits code support return gbCheatList[i].value; + break; } } *************** *** 463,464 **** --- 456,518 ---- return gbMemoryMap[address>>12][address&0xFFF]; } + + + // Used to emulate GS codes. + void gbCheatWrite(bool reboot) + { + if(cheatsEnabled) + { + u16 address = 0; + + if (gbNextCheat >= gbCheatNumber) + gbNextCheat = 0; + + for(int i = gbNextCheat; i < gbCheatNumber; i++) { + if(gbCheatList[i].enabled) { + address = gbCheatList[i].address; + if ((!reboot) && (address >= 0x8000) && !((address>=0xA000) && (address<0xC000))) + { // These codes are executed one per one, at each Vblank + switch(gbCheatList[i].code) { + case 0x01: + gbWriteMemory(address, gbCheatList[i].value); + gbNextCheat = i+1; + return; + case 0x90: + case 0x91: + case 0x92: + case 0x93: + case 0x94: + case 0x95: + case 0x96: + case 0x97: + case 0x98: + case 0x99: + case 0x9A: + case 0x9B: + case 0x9C: + case 0x9D: + case 0x9E: + case 0x9F: + int oldbank = gbMemory[0xff70]; + gbWriteMemory(0xff70, gbCheatList[i].code & 0xf); + gbWriteMemory(address, gbCheatList[i].value); + gbWriteMemory(0xff70, oldbank); + gbNextCheat = i+1; + return; + } + } + else // These codes are only executed when the game is booted + { + switch(gbCheatList[i].code & 0xF0) { + case 0x80: + gbWriteMemory(0x0000, 0x0A); + gbWriteMemory(0x4000, gbCheatList[i].value & 0xF); + gbWriteMemory(address, gbCheatList[i].value); + gbNextCheat = i+1; + return; + } + } + } + } + } + } \ No newline at end of file |