Exemplo n.º 1
0
void UPD765A::cmd_write_id()
{
	switch(phase) {
	case PHASE_IDLE:
		shift_to_cmd(5);
		break;
	case PHASE_CMD:
		set_hdu(buffer[0]);
		id[3] = buffer[1];
		eot = buffer[2];
		gpl = buffer[3];
		dtl = buffer[4]; // temporary
		if(!eot) {
			REGISTER_PHASE_EVENT(PHASE_TIMER, 1000000);
			break;
		}
		fdc[hdu & DRIVE_MASK].next_trans_position = get_cur_position(hdu & DRIVE_MASK);
		shift_to_write(4 * eot);
		break;
	case PHASE_TC:
	case PHASE_WRITE:
		REGISTER_PHASE_EVENT(PHASE_TIMER, 4000000);
		break;
	case PHASE_TIMER:
#ifdef SDL
		if (force_ready && !disk[hdu & DRIVE_MASK]->inserted) {
			REGISTER_PHASE_EVENT(PHASE_TIMER, 1000000);
			break;
		}
#endif // SDL
		result =  write_id();
		shift_to_result7();
		break;
	}
}
Exemplo n.º 2
0
double UPD765A::get_usec_to_exec_phase()
{
	int drv = hdu & DRIVE_MASK;
	int trk = fdc[drv].track;
	int side = (hdu >> 2) & 1;
	
	// XXX: this is a standard image and skew may be incorrect
	if(disk[drv]->is_standard_image) {
		return 100;
	}
	
	// search target sector
	int position = get_cur_position(drv);
	int trans_position = -1, sync_position;
	
	if(disk[drv]->get_track(trk, side) && disk[drv]->sector_num.sd != 0) {
		if((command & 0x1f) == 0x02) {
			// read diagnotics
			trans_position = disk[drv]->data_position[0];
			sync_position = disk[drv]->sync_position[0];
		} else {
			for(int i = 0; i < disk[drv]->sector_num.sd; i++) {
				if(!disk[drv]->get_sector(trk, side, i)) {
					continue;
				}
				if(disk[drv]->id[0] != id[0] || disk[drv]->id[1] != id[1] || disk[drv]->id[2] != id[2] /*|| disk[drv]->id[3] != id[3]*/) {
					continue;
				}
				// sector number is matched
				trans_position = disk[drv]->data_position[i];
				sync_position = disk[drv]->sync_position[i];
				break;
			}
		}
	}
	if(trans_position == -1) {
		// sector not found
		return 100;
	}
	
	// get current position
	int bytes = trans_position - position;
	if(sync_position < position) {
		bytes += disk[drv]->get_track_size();
	}
	return disk[drv]->get_usec_per_bytes(bytes);
}
Exemplo n.º 3
0
void UPD765A::event_callback(int event_id, int err)
{
#ifdef SDL
	request_single_exec();
#endif // SDL
	if(event_id == EVENT_PHASE) {
		phase_id = -1;
		phase = event_phase;
		process_cmd(command & 0x1f);
	} else if(event_id == EVENT_DRQ) {
		drq_id = -1;
		status |= S_RQM;
		
		int drv = hdu & DRIVE_MASK;
		fdc[drv].cur_position = (fdc[drv].cur_position + 1) % disk[drv]->get_track_size();
		fdc[drv].prev_clock = prev_drq_clock = current_clock();
		set_drq(true);
	} else if(event_id == EVENT_LOST) {
#ifdef _FDC_DEBUG_LOG
		emu->out_debug_log("FDC: DATA LOST\n");
#endif
		lost_id = -1;
		result = ST1_OR;
		set_drq(false);
		shift_to_result7();
	} else if(event_id == EVENT_RESULT7) {
		result7_id = -1;
		shift_to_result7_event();
	} else if(event_id == EVENT_INDEX) {
		int drv = hdu & DRIVE_MASK;
		bool now_index = (disk[drv]->inserted && get_cur_position(drv) == 0);
		if(prev_index != now_index) {
			write_signals(&outputs_index, now_index ? 0xffffffff : 0);
			prev_index = now_index;
		}
	} else if(event_id >= EVENT_SEEK && event_id < EVENT_SEEK + 4) {
		int drv = event_id - EVENT_SEEK;
		seek_id[drv] = -1;
		seek_event(drv);
	}
}
Exemplo n.º 4
0
uint32 UPD765A::read_id()
{
	int drv = hdu & DRIVE_MASK;
	int trk = fdc[drv].track;
	int side = (hdu >> 2) & 1;
	
	// get sector counts in the current track
	if(!disk[drv]->get_track(trk, side)) {
		return ST0_AT | ST1_MA;
	}
	int secnum = disk[drv]->sector_num.sd;
	if(!secnum) {
		return ST0_AT | ST1_MA;
	}
	
	// first found sector
	int position = get_cur_position(drv), first_sector = 0;
	if(position > disk[drv]->sync_position[secnum - 1]) {
		position -= disk[drv]->get_track_size();
	}
	for(int i = 0; i < secnum; i++) {
		if(position < disk[drv]->sync_position[i]) {
			first_sector = i;
			break;
		}
	}
	for(int i = 0; i < secnum; i++) {
		int index = (first_sector + i) % secnum;
		if(disk[drv]->get_sector(trk, side, index)) {
			id[0] = disk[drv]->id[0];
			id[1] = disk[drv]->id[1];
			id[2] = disk[drv]->id[2];
			id[3] = disk[drv]->id[3];
			fdc[drv].next_trans_position = disk[drv]->id_position[index] + 6;
			return 0;
		}
	}
	return ST0_AT | ST1_ND;
}
Exemplo n.º 5
0
void UPD765A::cmd_read_id()
{
	switch(phase) {
	case PHASE_IDLE:
		shift_to_cmd(1);
		break;
	case PHASE_CMD:
		set_hdu(buffer[0]);
//		break;
	case PHASE_EXEC:
#ifdef SDL
		if (force_ready && !disk[hdu & DRIVE_MASK]->inserted) {
			REGISTER_PHASE_EVENT(PHASE_EXEC, 1000000);
			break;
		}
#endif // SDL
		if(check_cond(false) & ST1_MA) {
//			REGISTER_PHASE_EVENT(PHASE_EXEC, 1000000);
//			break;
		}
		if((result = read_id()) == 0) {
			int drv = hdu & DRIVE_MASK;
			int bytes = fdc[drv].next_trans_position - get_cur_position(drv);
			if(bytes < 0) {
				bytes += disk[drv]->get_track_size();
			}
			REGISTER_PHASE_EVENT_NEW(PHASE_TIMER, disk[drv]->get_usec_per_bytes(bytes));
		} else {
			REGISTER_PHASE_EVENT(PHASE_TIMER, 5000);
		}
		break;
	case PHASE_TIMER:
		shift_to_result7();
		break;
	}
}
Exemplo n.º 6
0
int main() {
	char chout='\n';
	int action=1;
	time_t last_time_action, current_time, last_time;
	
	if ( init_mpc () == 0) {
		printf("Error init mpc\n");
		exit (-1);
	}

	output_t * output_st = init_output_st ();

	while (init_display(output_st)) {
		printf("Error display\n");
		sleep (1);
	}

	set_cirilic ();
	clear_scr();
	
	int encoder_fd = 0;
	if (cfileexists(ENCODER_COM_PORT)) {
		encoder_fd = init_comport(ENCODER_COM_PORT, ENCODER_COM_SPEED);
	} else {
		encoder_fd = init_comport(DEFAULT_ENCODER_COM_PORT, ENCODER_COM_SPEED);
	}

	init_term();
	last_time = time(NULL); 

	int count_click = 0;
	struct timeval t_start, t_end;
	int show_time = 0;
	while (1) {
		get_all (output_st);
		int ret_read = read_com(encoder_fd, 1 , 100, &chout);
		if ((chout=='R') || (chout=='L') ||(chout=='a') || (chout=='d')) {
				action=0;
				last_time_action = time(NULL);
				set_play_list_position(tuning_movement(chout)); 
				get_cur_position (); 
				show_current_cursor_pos ();
		}
		if ((chout=='P') ||(chout=='s') ) {
			gettimeofday(&t_end, NULL);
			if(!count_click) {
				t_start = t_end;
				count_click++;
			} else {
				if (usec_used (&t_start, &t_end) <= 500000) {
					double_click_button();
					if (show_time) {
						show_time--;
					} else {
						show_time++;
					}
				} 
				count_click = 0;
			}
		}

		if (count_click) {
			gettimeofday(&t_end, NULL);
			if (usec_used (&t_start, &t_end) > 500000) 	{
				print_button_pressed();
				music_pause();
				count_click = 0;
			}
		}

		chout = '\0';
		current_time = time(NULL); 
		if (action==0) {
			if ((current_time-last_time_action)>3) {
				action++;
			}
		}
		if ((action) && ((current_time-last_time)>0)) {
			if (!show_time) {
				show_current_track(output_st);
			} else {
				show_current_time_and_date();
			}
			last_time = current_time; 
		}
	}
}