engine/dc/gdrom.c
/////////////////////////////////////////////////////////////////////////////
//
// Initialize gdrom system
// returns the starting LBA of the main data track
//
Initialize gdrom system
returns the starting LBA of the main data track
Initialize gdrom system returns the starting LBA of the main data track
int gdrom_init(void) {
  int param[4];
  int i, j;
  int first, last, track;
  int probable_lba = -1;
  int probable2_lba = -1;
  int definite_lba = -1;
  *((volatile int*)0xA05F74E4) = 0x001FFFFF;
  for(i = 0; i<(0x200000/4); i++) {
	j += ((volatile int*)0xA0000000)[i];
  }
  bios_gdGdcInitSystem();
tryinit:
  i = bios_gdGdcReqCmd(CMD_INIT, NULL);
  for(;;) {
	bios_gdGdcExecServer();
	param[0] = 0; param[1] = 0; param[2] = 0; param[3] = 0;
	j = bios_gdGdcGetCmdStat(i, param);
	if(j != 1) break;
  }
  if(j != 2) goto tryinit;
  param[0] = 0;     
  param[1] = 8192;  
  param[2] = 0;     
  param[3] = 2048;  
  if(bios_gdGdcChangeDataType(param) < 0) goto tryinit;
  param[0] = 0; 
  param[1] = (int)(&gdrom_toc); 
  i = bios_gdGdcReqCmd(CMD_GETTOC2, param);
  for(;;) {
	bios_gdGdcExecServer();
	param[0] = 0; param[1] = 0; param[2] = 0; param[3] = 0;
	j = bios_gdGdcGetCmdStat(i, param);
	if(j != 1) break;
  }
  if(j != 2) goto tryinit;
  first = GDROM_TOC_TRACK(gdrom_toc.first);
  last  = GDROM_TOC_TRACK(gdrom_toc.last);
  if(first < 1 || last > 99 || first > last) {
	goto tryinit;
  }
  for(track = last; track >= first; track--) {
	if(GDROM_TOC_CTRL(gdrom_toc.entry[track-1]) & 4) {
	  int lba = GDROM_TOC_LBA(gdrom_toc.entry[track-1]);
	  if(probable_lba < 0) probable_lba = lba;
	  if(quickblockread(lba+16, 1) != 2) continue;
	  if(memcmp(GDROM_READBUFFER_P2+1, "CD001", 5)) continue;
	  definite_lba = lba;
	  break;
	}
  }
  if(definite_lba >= 0) return definite_lba;
  if(probable2_lba >= 0) return probable2_lba;
  if(probable_lba >= 0) return probable_lba;
  return -1;
}
int gdrom_init ( void ) { int param [ 4 ] ; int i , j ; int first , last , track ; int probable_lba = -1 ; int probable2_lba = -1 ; int definite_lba = -1 ; * ( ( volatile int * ) 0xA05F74E4 ) = 0x001FFFFF ; for ( i = 0 ; i < ( 0x200000 / 4 ) ; i ++ ) { j += ( ( volatile int * ) 0xA0000000 ) [ i ] ; } bios_gdGdcInitSystem ( ) ; tryinit : i = bios_gdGdcReqCmd ( CMD_INIT , NULL ) ; for ( ; ; ) { bios_gdGdcExecServer ( ) ; param [ 0 ] = 0 ; param [ 1 ] = 0 ; param [ 2 ] = 0 ; param [ 3 ] = 0 ; j = bios_gdGdcGetCmdStat ( i , param ) ; if ( j != 1 ) break ; } if ( j != 2 ) goto tryinit ; param [ 0 ] = 0 ; param [ 1 ] = 8192 ; param [ 2 ] = 0 ; param [ 3 ] = 2048 ; if ( bios_gdGdcChangeDataType ( param ) < 0 ) goto tryinit ; param [ 0 ] = 0 ; param [ 1 ] = ( int ) ( & gdrom_toc ) ; i = bios_gdGdcReqCmd ( CMD_GETTOC2 , param ) ; for ( ; ; ) { bios_gdGdcExecServer ( ) ; param [ 0 ] = 0 ; param [ 1 ] = 0 ; param [ 2 ] = 0 ; param [ 3 ] = 0 ; j = bios_gdGdcGetCmdStat ( i , param ) ; if ( j != 1 ) break ; } if ( j != 2 ) goto tryinit ; first = GDROM_TOC_TRACK ( gdrom_toc . first ) ; last = GDROM_TOC_TRACK ( gdrom_toc . last ) ; if ( first < 1 || last > 99 || first > last ) { goto tryinit ; } for ( track = last ; track >= first ; track -- ) { if ( GDROM_TOC_CTRL ( gdrom_toc . entry [ track - 1 ] ) & 4 ) { int lba = GDROM_TOC_LBA ( gdrom_toc . entry [ track - 1 ] ) ; if ( probable_lba < 0 ) probable_lba = lba ; if ( quickblockread ( lba + 16 , 1 ) != 2 ) continue ; if ( memcmp ( GDROM_READBUFFER_P2 + 1 , " " , 5 ) ) continue ; definite_lba = lba ; break ; } } if ( definite_lba >= 0 ) return definite_lba ; if ( probable2_lba >= 0 ) return probable2_lba ; if ( probable_lba >= 0 ) return probable_lba ; return -1 ; }
Initialize gdrom system
returns the starting LBA of the main data track
Initialize gdrom system returns the starting LBA of the main data track
// Reactivate GD-ROM drive // Reset GD system functions // Try to initialize the disc // Set the read mode // 0 = set, 1 = get // ? // autodetect read mode // sector size // Try to read the TOC // session // toc // corrupt toc data, maybe //      // try to read the boot sector //      if(quickblockread(lba, 1) != 2) continue; //      // look for "SEGA" in the boot sector //      if(memcmp(GDROM_READBUFFER_P2, "SEGA", 4)) continue; //      if(probable2_lba < 0) probable2_lba = lba; // try to read the first sector after the boot sector // look for "CD001" // success! // now return either a definite or a probable lba // and if we don't have any of those, we're really screwed, oh well // we could try running through tryinit again, but that would probably be // fruitless