コード例 #1
0
void write_lower_16KB_PRG_bank(uint8_t* bank_data) {
    uint16_t bank_address = 0;
    for(uint16_t NES_address = PRG_ROM_BANK1_ADDRESS; NES_address < PRG_ROM_BANK2_ADDRESS; NES_address++) {
        write_RAM(NES_address, bank_data[bank_address++]);
    }
}
コード例 #2
0
void write_upper_16KB_PRG_bank(uint8_t* bank_data) {
    uint16_t bank_address = 0;
    for(uint32_t NES_address = PRG_ROM_BANK2_ADDRESS; NES_address < PRG_ROM_BANK2_ADDRESS + PRG_BANK_SIZE; NES_address++) {
        write_RAM((uint16_t)NES_address, bank_data[bank_address++]);
    }
}
コード例 #3
0
ファイル: TCD2Usb.cpp プロジェクト: tba109/tgacs
// Reset the TCD2 USB device
int TCD2Usb::TCD2Usb_fx2lp_reset(const char * path, unsigned int vendor, unsigned int product)
{
  int retval = 0;
  TCD2Usb_reinitialization();
  
  // Reset is accomplished by writing a 1 to address 0xE600. 
  const size_t reset_addr = 0xe600;
  
  unsigned char val = 1;
  if( (retval = write_RAM(reset_addr,&val,1)) )
    {
      printf("TCD2Usb::TCD2Usb_fx2lp_reset: Error resetting FX2LP \n");
      return -TCD2USB_RESET_FX2LP_ERR;
    }
  

  if( (retval =  TCD2Usb_reinitialization()) )
    return retval;
  
  FILE *fp = fopen(path,"r");
  if(!fp)
    {  
      // printf("TCD2Usb::TCD2Usb_fx2lp_reset: Failed to open %s \n",path);
      return -TCD2USB_OPEN_IHX_FILE_ERR;
    }
  
  const size_t buflen=1024;  // Hopefully much too long for real life...
  char buf[buflen];
  unsigned char data[1024];
  unsigned char cksum = 0;
  unsigned int d = 0;
  unsigned int file_cksum = 0;

  char * s;
  unsigned int nbytes = 0, addr = 0, type = 0;
  while(1)
    {
      *buf='\0';
      nbytes = 0;
      addr = 0;
      type = 0;
      cksum = 0;
      d = 0;
      file_cksum = 0;

      // Read in and error check
      if(!fgets(buf,buflen,fp))
	{
	  if( feof(fp) )
	    break;
	  
	  // printf("Error reading %s \n",path);
	  fclose(fp);  
	  fp=NULL;
	  return -TCD2USB_READ_IHX_FILE_ERR;
	}
      
      // Check for format violations
      s = buf;
      if( *s != ':' )
	{
	  // printf("TCD2Usb::TCD2Usb_fx2lp_reset: Format violation 1 \n");
	  return -TCD2USB_IHX_FORMAT_VIOLATION1_ERR;
	}
      s++;

      if( sscanf(s,"%02x%04x%02x",&nbytes,&addr,&type) != 3 )
	{
	  printf("TCD2Usb::TCD2Usb_fx2lp_reset: Format violation 2. nbytes = %02x addr = %04x, type = %02x \n",nbytes,addr,type);
	  return -TCD2USB_IHX_FORMAT_VIOLATION2_ERR;
	}
      s+=8;
      
      if( type == 0 )
	{
	  //printf("TCD2Usb::TCD2Usb_fx2lp_reset: Writing nbytes=%d at addr=0x%04x\n",nbytes,addr);
	  if( (nbytes < 0) || (nbytes > 256) )
	    return -TCD2USB_IHX_NBYTES_ERR;
	  
	  // Calc 
	  cksum=nbytes+addr+(addr>>8)+type;
	  for(unsigned int i=0; i<nbytes; i++)
	    {
	      d = 0;
	      if( sscanf(s,"%02x",&d) != 1 )
		{  
		  // printf("TCD2Usb::TCD2Usb_fx2lp_reset: Format violation 3 \n");
		  return -TCD2USB_IHX_FORMAT_VIOLATION3_ERR;  
		}
	      s+=2;
	      data[i]=d;
	      cksum+=d;
	    }
	  
	  if( sscanf(s,"%02x",&file_cksum) != 1 )
	    {
	      // printf("TCD2Usb::TCD2Usb_fx2lp_reset: Format violation 4 \n");
	      return -TCD2USB_IHX_FORMAT_VIOLATION4_ERR;  
	    }
	  
	  if( (cksum+file_cksum) & 0xff )
	    {  
	      // printf("TCD2Usb::TCD2Usb_fx2lp_reset: Checksum mismatch \n");  
	      return -TCD2USB_CHECKSUM_ERR;  
	    }
	  
	  if( (retval = write_RAM(addr,data,nbytes)) )
	    return -TCD2USB_WRITE_RAM_ERR;  
	    
	}
      else if(type == 1) // EOF marker. Oh well, trust it. 
	break;
	
      else
	{
	  // printf("TCD2Usb::TCD2Usb_fx2lp_reset: Unknown entry type \n");
	  return -TCD2USB_UNKNOWN_TYPE_ERR;
	}
    }