void ripROM (uint8_t startBank, int isLowROM, int16_t numberOfPages, uint8_t *ROMdump){ totalChecksum = 0; //static uint8_t ROMdump[5000000] = ""; uint32_t pageChecksum = 0; uint8_t currentByte = 0; uint8_t bank = 0; uint32_t position = 0; uint32_t j = 0; uint32_t startOffset; uint32_t offset; if (isLowROM == 1) startOffset = startBank * 0x8000; else startOffset = startBank * 0x10000; offset = startOffset; // Set current Offset to starting offset gotoOffset(startOffset,isLowROM); // Change current bank & address to offset printf ("----Start Cart Read------\n"); position = 0; //Start at current bank, and increment the number of banks needed for (j = startBank; j < (numberOfPages + startBank); j++ ){ printf("Current Bank: DEC: %d; HEX: %x\n", currentBank, currentBank ); //If bank increments, exit the following inner loop, else keep scanning while (j == currentBank){ currentByte = readData(); *(ROMdump + position) = currentByte; pageChecksum += currentByte; offset += 1; //Increment offset gotoOffset(offset,isLowROM); //goto new offset //printf("%d -- %d: %d\n", currentByte, *(ROMdump + position), position ); position++; } if (isLowROM == 0 | (isLowROM == 1 && currentBank % 2 == 0) ){ printf(" - Page Checksum: %u\n", pageChecksum ); totalChecksum += pageChecksum; pageChecksum = 0; printf("\nCurrent Checksum: %d | Hex: %x\n", totalChecksum, totalChecksum); printf("Header Checksum: %x\n", ROMchecksum); } } //return ROMdump; }
void FormatWidget::setData(QHexEdit *hexedit) { this->_hexedit = hexedit; this->_formatmodel = new FormatModel(this->_hexedit->data(), nullptr, ui->tvFormat); ui->tvFormat->setModel(this->_formatmodel); connect(ui->tvFormat, SIGNAL(setBackColor(FormatElement*)), this, SLOT(onSetBackColor(FormatElement*))); connect(ui->tvFormat, SIGNAL(removeBackColor(FormatElement*)), this, SLOT(onRemoveBackColor(FormatElement*))); connect(ui->tvFormat, SIGNAL(formatObjectSelected(FormatElement*)), this, SLOT(onFormatObjectSelected(FormatElement*))); connect(ui->tvFormat, SIGNAL(exportAction(FormatElement*)), this, SLOT(exportData(FormatElement*))); connect(ui->tvFormat, SIGNAL(importAction(FormatElement*)), this, SLOT(importData(FormatElement*))); connect(ui->tvFormat, SIGNAL(gotoOffset(qint64)), this->_hexedit, SLOT(setCursorPos(qint64))); }
void CX4setROMsize(int16_t ROMsize){ gotoOffset(0x007F52,0); uint8_t ROMsizeRegister = readData(); printf("$007F52 offset reads %u", ROMsizeRegister ); changeDataDir(0);//writeByte (0, _SNESBankAndData, IODIRB, 0x00);//SNESBankAndData._writeRegister(IODIRB,0x00) # Set MCP bank B to outputs (SNES Data 0-7) setIOControl(_WR + _CS + _POWER); /* # GPA0: /RD # GPA1: /RESET # GPA2: /WR # GPA3: /CS # GPA4: CART MOSFET # GPA7: /IRQ */ if (ROMsize > 8){ if (ROMsizeRegister == 1){ printf("ROM is larger than 8 megs, writing 0x00 to CX4 register"); writeByte (0, _SNESBankAndData, GPIOB, 0x00);//SNESBankAndData._writeRegister(GPIOB,0x00) } else printf("CX4 register is at correct value, will not change"); } else{ if (ROMsizeRegister == 1) printf("CX4 register is at correct value, will not change"); else{ printf("ROM is 8 megs, writing 0x01 to CX4 register"); writeByte (0, _SNESBankAndData, GPIOB, 0x01);//SNESBankAndData._writeRegister(GPIOB,0x01) } } setIOControl(_RD + _CS + _POWER); changeDataDir(1); printf("$007F52 offset now reads %u",readData() ); }
int main(void){ printf("START\n"); int readCart = 1; uint8_t ROMmakeup; uint8_t ROMspeed; uint8_t bankSize; uint8_t ROMtype; uint8_t ROMsize; uint8_t SRAMsize; uint8_t country; uint8_t license; uint8_t version; uint32_t VBLvector; uint32_t resetVector; uint32_t inverseChecksum; int i = 0; int x = 0; // ------------- Set Registers ----------------------------------------------------- wiringPiSetup () ; mcp23s17Setup (BASE, 0, _IOControls) ; mcp23s17Setup (BASE+100, 0,_SNESAddressPins) ; mcp23s17Setup (BASE+200, 0, _SNESBankAndData) ; initInterface_SPI(); //---------------------------------------------------------------------------------------------------- /* # GPA0: /RD # GPA1: /RESET # GPA2: /WR # GPA3: /CS # GPA4: CART MOSFET # GPA7: /IRQ */ setIOControl(_RD + _CS + _POWER); //time.sleep(.25) //----------------------------------------------------- char cartname[21] = ""; uint32_t headerAddr =32704; int isLowROM = 1; int isValid = 0; if (compareROMchecksums(32704,1) == 1){ printf("Checksums matched\n"); ROMmakeup = readOffset(headerAddr + 21,isLowROM); ROMspeed = getUpNibble(ROMmakeup); bankSize = getLowNibble(ROMmakeup); if (bankSize == 0){ printf("ROM Makeup match for LoROM. Assuming this is the case!\n"); isLowROM = 1; isValid = 1; } else if (bankSize == 1){ printf("ROM Makeup match for HiROM. Assuming this is the case!\n"); headerAddr = 65472; isLowROM = 0; isValid = 1; } else printf("Bank Configuration Read Error\n"); } else printf("Checksums did not match. Either no cart, or cart read error\n"); //#--- Debug. Manually set bank size ---------- //#isLowROM = 1 //#------------------------------------------- uint32_t currentAddr = headerAddr; gotoOffset(headerAddr, isLowROM); for (i = headerAddr; i <(headerAddr + 20); i++ ) cartname[x++] = readOffset(i,isLowROM); //cartname = cartname.rstrip() ROMmakeup = readAddr(headerAddr + 21,isLowROM); ROMspeed = getUpNibble(ROMmakeup); bankSize = getLowNibble(ROMmakeup); ROMtype = readAddr(headerAddr + 22,isLowROM); ROMsize = getROMsize(headerAddr + 23, isLowROM); SRAMsize = readAddr(headerAddr + 24,isLowROM); country = readAddr(headerAddr + 25,isLowROM); license = readAddr(headerAddr + 26,isLowROM); version = readAddr(headerAddr + 27,isLowROM); currentAddr = headerAddr + 28; inverseChecksum = readAddr(currentAddr,isLowROM); inverseChecksum += readAddr(currentAddr+1,isLowROM) * 256; currentAddr = headerAddr + 30; ROMchecksum = readAddr(currentAddr,isLowROM); ROMchecksum += readAddr(currentAddr+1,isLowROM) * 256; currentAddr = headerAddr + 32; VBLvector = readAddr(currentAddr,isLowROM); VBLvector += readAddr(currentAddr+1,isLowROM) * 256; currentAddr = headerAddr + 34; resetVector = readAddr(currentAddr,isLowROM); resetVector += readAddr(currentAddr+1,isLowROM) * 256; int16_t numberOfPages = getNumberOfPages(ROMsize,isLowROM); printf("Game Title: %s\n", cartname); printf("ROM Makeup: %d\n", ROMmakeup); printf(" - ROM Speed: %d\n", ROMspeed); printf(" - Bank Size: %d\n", bankSize); printf("ROM Type: %d\n", ROMtype); if (ROMtype == 243){ printf("\nCapcom CX4 ROM Type detected!"); CX4setROMsize(ROMsize); printf("\n"); } printf("ROM Size: %d MBits\n", ROMsize); int convertedSRAMsize = 0; printf("SRAM Size: Value: %d",SRAMsize); if (convertedSRAMsize == 0) if (SRAMsize <= 12 && SRAMsize > 0) convertedSRAMsize = 1<<(SRAMsize +3); printf(" | %d KBits\n", convertedSRAMsize); printf("Country: %d\n", country); printf( "License: %d\n", license); printf( "Version: 1.%d\n",version); printf( "Inverse Checksum: %x\n", inverseChecksum); printf( "ROM Checksum: %x\n", + ROMchecksum); printf( " - Checksums xOr'ed: %x\n", (inverseChecksum | ROMchecksum) ); printf( "\n"); printf( "VBL Vector: %d\n", VBLvector); printf( "Reset Vector: %d\n", resetVector); printf( "\n"); printf( "Number of pages: %d\n", numberOfPages ); printf( "\n"); uint8_t *dump; char fileName[30]; //dump = returnNULLheader() int y = 0; uint32_t sizeOfCartInBytes = 0; uint32_t pageChecksum = 0; //uint32_t totalChecksum = 0; uint32_t currentByte = 0; uint32_t numberOfRemainPages = 0; uint32_t firstNumberOfPages = 0; time_t timeStart = 0; time_t timeEnd = 0; /* if directory != "" : if directory[len(directory)-1] != "/": directory += "/" g = open("/tmp/insertedCart",'w')*/ if (isValid == 1){ //g.write(cartname) if (readCart == 1){ //if os.path.exists(directory + cartname + '.smc'){ // printf("Cart has already been ripped, not ripping again!"); // readCart = 0; } else if (readCart == 0) printf("Will not rip cart due to OPTs"); if (readCart == 1){ numberOfRemainPages = 0; firstNumberOfPages = numberOfPages; timeStart = time(NULL); //f = open(directory + cartname + '.smc','w') FILE *romfile; stpcpy(fileName, cartname); strcat(fileName, ".smc"); romfile = fopen( fileName, "wb"); if (isLowROM == 1){ sizeOfCartInBytes = numberOfPages * 32768; dump = calloc(sizeOfCartInBytes, sizeof(uint8_t) ); printf("Reading %d Low ROM pages.\n", numberOfPages); //ROM Ripper ripROM(0x00, isLowROM, firstNumberOfPages, dump); } else{ sizeOfCartInBytes = numberOfPages * 65536; dump = calloc(sizeOfCartInBytes, sizeof(uint8_t) ); if (numberOfPages > 64){ numberOfRemainPages = ( numberOfPages - 64 ); //# number of pages over 64 printf("Reading first 64 of %d Hi ROM pages.\n", numberOfPages); firstNumberOfPages = 64; } else printf("Reading %d Hi ROM pages.\n", numberOfPages); /*dump =*/ ripROM(0xC0, isLowROM, firstNumberOfPages, dump); if (numberOfRemainPages > 0){ printf("Reading last %d of High ROM pages.\n", numberOfRemainPages); /*dump +=*/ ripROM(0x40, isLowROM, numberOfRemainPages, dump); } } printf("\n"); printf("Entire Checksum: %x\n", totalChecksum); printf("\n"); printf("Header Checksum: %x\n", ROMchecksum ); totalChecksum = ( totalChecksum & 0xFFFF ); printf("16-bit Generated Checksum: %x\n", totalChecksum); if (totalChecksum == ROMchecksum) printf("-------------------------- CHECKSUMS MATCH!\n"); else printf("----------WARNING: CHECKSUMS DO NOT MATCH: %x != %x\n", totalChecksum, ROMchecksum); timeEnd = time(NULL); //print "" printf("Address Writes - LowByte: %d HighByte: %d | Bank Writes: %d | Data Reads: %d\n", LowByteWrites, HighByteWrites, BankWrites, DataReads); printf("\nIt took %d seconds to read cart\n", timeEnd - timeStart); printf("Size of Cart in Bytes: %d\n", sizeOfCartInBytes); fwrite(dump, sizeof(uint8_t), sizeOfCartInBytes, romfile); fclose(romfile); free(dump); } /*if (readSRAM == 1){ f = open(directory + cartname + '.srm','w') timeStart = time.time() dump = ripSRAM(convertedSRAMsize,ROMsize,isLowROM) timeEnd = time.time() print "" print "It took " + str(timeEnd - timeStart) + "seconds to read SRAM Data" f.write(dump) f.close }*/ } else{ //g.write("NULL") //g.close } //#--- Clean Up & End Script ------------------------------------------------------ shutdownInterface_SPI(); }
uint8_t readOffset(uint32_t offset,int isLowROM){ //printf("Seventh\n"); gotoOffset(offset,isLowROM); return readData(); }