コード例 #1
0
ファイル: isotest.c プロジェクト: zig/kos-dcplaya
/* Pulls the requested sector into a cache block and returns the cache
   block index. Note that the sector in question may already be in the
   cache, in which case it just returns the containing block. */
static int bread(uint32 sector) {
	int i, rv = -1;
	
	thd_mutex_lock(&cache_mutex);

	/* Look for a pre-existing cache block */
	for (i=NUM_CACHE_BLOCKS-1; i>=0; i--) {
		if (cache[i]->sector == sector) {
			bgrad(i);
			rv = NUM_CACHE_BLOCKS - 1;
			goto bread_exit;
		}
	}
	
	/* If not, look for an open cache slot; if we find one, use it */
	for (i=0; i<NUM_CACHE_BLOCKS; i++) {
		if (cache[i]->sector == -1) break;
	}
	
	/* If we didn't find one, kick an LRU block out of cache */
	if (i >= NUM_CACHE_BLOCKS) { i = 0; }
	
	/* Load the requested block */
	if (cdrom_read_sectors(cache[i]->data, sector + 150, 1) < 0) {
		rv = -1;
		goto bread_exit;
	}
	cache[i]->sector = sector;
	
	/* Move it to the most-recently-used position */
	bgrad(i);
	rv = NUM_CACHE_BLOCKS - 1;

	/* Return the new cache block index */
bread_exit:
	thd_mutex_unlock(&cache_mutex);
	return rv;
}
コード例 #2
0
ファイル: module.c プロジェクト: i-rom/DreamShell
void gd_ripper_ipbin_name(){
	CDROM_TOC toc ;
	int status = 0, disc_type = 0, cdcr = 0, x = 0;
	char pbuff[2048] , text[MAX_FN_LEN];
	uint32 lba;

	cdrom_set_sector_size(2048);
	if((cdcr = cdrom_get_status(&status, &disc_type)) != ERR_OK) {
		switch (cdcr){
			case ERR_NO_DISC :
				ds_printf("DS_ERROR: Disk not inserted\n");
				return;
			default:
				ds_printf("DS_ERROR: GD-rom error\n");
				return;
		}
	}
	if (disc_type == CD_CDROM_XA) {
		if(cdrom_read_toc(&toc, 0) != CMD_OK) { 
			ds_printf("DS_ERROR: Toc read error\n"); 
			return; 
		}
		if(!(lba = cdrom_locate_data_track(&toc))) {
			ds_printf("DS_ERROR: Error locate data track\n"); 
			return;
		}
		if (cdrom_read_sectors(pbuff,lba , 1)) {
			ds_printf("DS_ERROR: CD read error %d\n",lba); 
			return;
		}
	} else if (disc_type == CD_GDROM) {
		if (cdrom_read_sectors(pbuff,45150 , 1)) {
			ds_printf("DS_ERROR: GD read error\n"); 
			return;
		}
	}else {
		ds_printf("DS_ERROR: not game disc\n");
		return;
	}
	
	ipbin_meta_t *meta = (ipbin_meta_t*) pbuff;
	
	char *p;
	char *o;
	
	p = meta->title;
	o = text;

	// skip any spaces at the beginning
	while(*p == ' ' && meta->title + 29 > p) 
		p++;

	// copy rest to output buffer
	while(meta->title + 29 > p) { 
		*o = *p;
		p++; 
		o++; 
	}

	// make sure output buf is null terminated
	*o = '\0';
	o--;

	// remove trailing spaces
	while(*o == ' ' && o > text) {
		*o='\0';
		o--;
	}
	
	if (strlen(text) == 0) {
		GUI_TextEntrySetText(self.gname, "Game");	
	} else {
		for (x=0;text[x] !=0;x++) {
			if (text[x] == ' ') text[x] = '_' ;
		}
		GUI_TextEntrySetText(self.gname, text);
	}
	//ds_printf("Image name - %s\n",text);
}
コード例 #3
0
ファイル: module.c プロジェクト: i-rom/DreamShell
int gdfiles(char *dst_folder,char *dst_file,char *text){
	file_t gdfd;
	FILE *gdifd;
	
	CDROM_TOC gdtoc;
	CDROM_TOC cdtoc;
	int track ,lba ,gdtype ,cdtype;
	uint8 *buff = memalign(32, 32768);
	
	cdrom_set_sector_size (2048);
	if(cdrom_read_toc(&cdtoc, 0) != CMD_OK) { 
		ds_printf("DS_ERROR:CD Toc read error\n"); 
		free(buff); 
		return CMD_ERROR; 
	}
	
	if(cdrom_read_toc(&gdtoc, 1) != CMD_OK) { 
		ds_printf("DS_ERROR:GD Toc read error\n"); 
		free(buff); 
		return CMD_ERROR; 
	}
	
	if(cdrom_read_sectors(buff,45150,16)) { 
		ds_printf("DS_ERROR: IP.BIN read error\n"); 
		free(buff); 
		return CMD_ERROR; 
	}
	
	strcpy(dst_file,"\0"); 
	snprintf(dst_file,MAX_FN_LEN,"%s/IP.BIN",dst_folder); 
	
	if ((gdfd=fs_open(dst_file,O_WRONLY | O_TRUNC | O_CREAT)) == FILEHND_INVALID) { 
		ds_printf("DS_ERROR: Error open IP.BIN for write\n"); 
		free(buff); 
		return CMD_ERROR; 
	}
	
	if (fs_write(gdfd,buff,32768) == -1) {
		ds_printf("DS_ERROR: Error write IP.BIN\n"); 
		free(buff); 
		fs_close(gdfd); 
		return CMD_ERROR;
	}
	
	fs_close(gdfd); 
	free(buff);
	ds_printf("IP.BIN succes dumped\n");
	
	fs_chdir(dst_folder);
	strcpy(dst_file,"\0"); 
	snprintf(dst_file,MAX_FN_LEN,"%s.gdi",text);
	if ((gdifd=fopen(dst_file,"w")) == NULL){
		ds_printf("DS_ERROR: Error open %s.gdi for write\n",text); 
		return CMD_ERROR; 
	}
	
	int cdfirst = TOC_TRACK(cdtoc.first);
	int cdlast = TOC_TRACK(cdtoc.last);
	int gdfirst = TOC_TRACK(gdtoc.first);
	int gdlast = TOC_TRACK(gdtoc.last);
	fprintf(gdifd,"%d\n",gdlast);
	
	for (track=cdfirst; track <= cdlast; track++ ) {
		lba = TOC_LBA(cdtoc.entry[track-1]);
		lba -= 150;
		cdtype = TOC_CTRL(cdtoc.entry[track-1]);
		fprintf(gdifd, "%d %d %d %d track%02d.%s 0\n",track,lba,cdtype,(cdtype == 4 ? 2048 : 2352),track,(cdtype == 4 ? "iso" : "raw"));
	}
	
	for (track=gdfirst; track <= gdlast; track++ ) {
		lba = TOC_LBA(gdtoc.entry[track-1]);
		lba -= 150;
		gdtype = TOC_CTRL(gdtoc.entry[track-1]);
		fprintf(gdifd, "%d %d %d %d track%02d.%s 0\n",track,lba,gdtype,(gdtype == 4 ? 2048 : 2352),track,(gdtype == 4 ? "iso" : "raw"));
	}
	
	fclose(gdifd); 
	fs_chdir("/");
	ds_printf("%s.gdi succes writen\n",text);

return CMD_OK;	
}
コード例 #4
0
ファイル: module.c プロジェクト: i-rom/DreamShell
static int rip_sec(int tn,int first,int count,int type,char *dst_file, int disc_type){

double percent,percent_last=0.0;
maple_device_t *cont;
cont_state_t *state;
file_t hnd;
int secbyte = (type == 4 ? 2048 : 2352) , i , count_old=count, bad=0, cdstat, readi;
uint8 *buffer = (uint8 *)memalign(32, SEC_BUF_SIZE * secbyte);
	
	GUI_WidgetMarkChanged(self.app->body);
//	ds_printf("Track %d		First %d	Count %d	Type %d\n",tn,first,count,type);
/*	if (secbyte == 2048) cdrom_set_sector_size (secbyte);
	else _cdrom_reinit (1);
*/
	cdrom_set_sector_size (secbyte);
	
	if ((hnd = fs_open(dst_file,O_WRONLY | O_TRUNC | O_CREAT)) == FILEHND_INVALID) {
		ds_printf("Error open file %s\n" ,dst_file); 
		cdrom_spin_down(); free(buffer); 
		return CMD_ERROR;
		}
	
	LockVideo();
	
	while(count) {
	
		int nsects = count > SEC_BUF_SIZE ? SEC_BUF_SIZE : count;
		count -= nsects;
		
		
		while((cdstat=cdrom_read_sectors(buffer, first, nsects)) != ERR_OK ) {
			if (atoi(GUI_TextEntryGetText(self.num_read)) == 0) break;
			readi++ ;
			if (readi > 5) break ;
			thd_sleep(200);
		}
			readi = 0;
		if (cdstat != ERR_OK) {
			if (!GUI_WidgetGetState(self.bad)) {
				UnlockVideo();
				GUI_ProgressBarSetPosition(self.read_error, 1.0);
				for(;;) {
					cont = maple_enum_type(0, MAPLE_FUNC_CONTROLLER);
					
					if(!cont) continue;
					state = (cont_state_t *)maple_dev_status(cont);
					
					if(!state) continue;
					if(state->buttons & CONT_A) {
						GUI_ProgressBarSetPosition(self.read_error, 0.0);
						GUI_WidgetMarkChanged(self.app->body); 
						ds_printf("DS_ERROR: Can't read sector %ld\n", first); 
						free(buffer); 
						fs_close(hnd); 
						return CMD_ERROR;
					} else if(state->buttons & CONT_B) {
						GUI_ProgressBarSetPosition(self.read_error, 0.0);
						GUI_WidgetMarkChanged(self.app->body); 
						break;
					} else if(state->buttons & CONT_Y) {
						GUI_ProgressBarSetPosition(self.read_error, 0.0); 
						GUI_WidgetSetState(self.bad, 1);
						GUI_WidgetMarkChanged(self.app->body); 
						break;
					}
				}
			}
			// Ошибка, попробуем по одному
			uint8 *pbuffer = buffer;
			LockVideo();
			for(i = 0; i < nsects; i++) {
				
				while((cdstat=cdrom_read_sectors(pbuffer, first, 1)) != ERR_OK ) {
				readi++ ;
				if (readi > atoi(GUI_TextEntryGetText(self.num_read))) break ;
				if (readi == 1 || readi == 6 || readi == 11 || readi == 16 || readi == 21 || readi == 26 || readi == 31 || readi == 36 || readi == 41 || readi == 46) cdrom_reinit();
				thd_sleep(200);
				}
				readi = 0;
				
				if (cdstat != ERR_OK) {
					// Ошибка, заполним нулями и игнорируем
					UnlockVideo();
					cdrom_reinit();
					memset(pbuffer, 0, secbyte);
					bad++;
					ds_printf("DS_ERROR: Can't read sector %ld\n", first);
					LockVideo();
				}
			
				pbuffer += secbyte;
				first++;
			}
		
		} else {
			// Все ок, идем дальше
			first += nsects;
		}
	
		if(fs_write(hnd, buffer, nsects * secbyte) < 0) {
			// Ошибка записи, печально, прерываем процесс
			UnlockVideo();
			free(buffer);
			fs_close(hnd);
			return CMD_ERROR;
		}
		UnlockVideo();
		percent = 1-(float)(count) / count_old;
		if ((percent = ((int)(percent*100 + 0.5))/100.0) > percent_last) {
		percent_last = percent;
		GUI_ProgressBarSetPosition(self.pbar, percent);
		LockVideo();
		}
	}
UnlockVideo();
free(buffer);
fs_close(hnd);
ds_printf("%d Bad sectors on track\n", bad);
return CMD_OK;
}