Пример #1
0
bool Storage::seek( const lba_t lba ) {
	if ( lba >= getNumberOfPages() )
		return false;

	this->offset = lba * STORAGE_PAGE_SIZE;
	return true;
}
void NSRPopplerDocument::renderPage(int page)
{
	double dpix, dpiy;

	if (_doc == NULL || page > getNumberOfPages() || page < 1)
		return;

	_page = _catalog->getPage(page);

	if (isTextOnly()) {
		PDFRectangle	*rect;
		GooString	*text;
		TextOutputDev	*dev;

		dev = new TextOutputDev (0, gFalse, gFalse, gFalse);

		_doc->displayPageSlice(dev, _page->getNum(), 72, 72, 0, gFalse, gTrue, gFalse, -1, -1, -1, -1);

		rect = _page->getCropBox();
		text = dev->getText(rect->x1, rect->y1, rect->x2, rect->y2);
		_text = processText(QString::fromUtf8(text->getCString()));

		delete text;
		delete dev;
		_readyForLoad = true;

		return;
	}

	if (isZoomToWidth()) {
		double wZoom = ((double) getScreenWidth() / (double) _page->getCropWidth() * 100.0);
		setZoomSilent((int) wZoom);
	}

	if (getZoom() > getMaxZoom())
		setZoomSilent (getMaxZoom());
	else if (getZoom() < getMinZoom())
		setZoomSilent (getMinZoom());

	if (_readyForLoad)
		_dev->startPage(0, NULL);

	dpix = _dpix * getZoom() / 100.0;
	dpiy = _dpiy * getZoom() / 100.0;

	_page->display(_dev, dpix, dpiy, getRotation(), gFalse, gFalse, gTrue, _catalog);

	_readyForLoad = true;
}
Пример #3
0
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();


}