Common Source Code Project for Qt (a.k.a for FM-7).
Revisão | 6d9d43c36247f5dd01ff4d32d595aa23ce8944b6 (tree) |
---|---|
Hora | 2020-02-15 16:12:39 |
Autor | K.Ohta <whatisthis.sowhat@gmai...> |
Commiter | K.Ohta |
[VM][SCSI_DEV][SCSI_CDROM] Fix freeze some PC-Engine's CD-ROM2 games and SCSI HDD for FM-Towns.
@@ -32,6 +32,7 @@ void SCSI_CDROM::initialize() | ||
32 | 32 | { |
33 | 33 | SCSI_DEV::initialize(); |
34 | 34 | fio_img = new FILEIO(); |
35 | + __CDROM_DEBUG_LOG = osd->check_feature(_T("_CDROM_DEBUG_LOG")); | |
35 | 36 | |
36 | 37 | if(44100 % emu->get_sound_rate() == 0) { |
37 | 38 | mix_loop_num = 44100 / emu->get_sound_rate(); |
@@ -45,7 +46,6 @@ void SCSI_CDROM::initialize() | ||
45 | 46 | is_cue = false; |
46 | 47 | current_track = 0; |
47 | 48 | read_sectors = 0; |
48 | - __CDROM_DEBUG_LOG = osd->check_feature(_T("_CDROM_DEBUG_LOG")); | |
49 | 49 | for(int i = 0; i < 99; i++) { |
50 | 50 | memset(track_data_path[i], 0x00, _MAX_PATH * sizeof(_TCHAR)); |
51 | 51 | } |
@@ -179,10 +179,11 @@ void SCSI_CDROM::event_callback(int event_id, int err) | ||
179 | 179 | } |
180 | 180 | } |
181 | 181 | if(cdda_playing_frame == cdda_end_frame) { |
182 | - // reached to end frame | |
183 | 182 | out_debug_log(_T("Reaches to the end of track.(FRAME %d). START_FRAME=%d END_FRAME=%d REPEAT=%s INTERRUPT=%s\n"), |
184 | - cdda_playing_frame, cdda_start_frame, cdda_end_frame, | |
185 | - (cdda_repeat) ? _T("YES") : _T("NO"), (cdda_interrupt) ? _T("YES") : _T("NO")); | |
183 | + cdda_playing_frame, cdda_start_frame, cdda_end_frame, | |
184 | + (cdda_repeat) ? _T("YES") : _T("NO"), | |
185 | + (cdda_interrupt) ? _T("YES") : _T("NO")); | |
186 | + // reached to end frame | |
186 | 187 | if(cdda_repeat) { |
187 | 188 | // reload buffer |
188 | 189 | // Restart. |
@@ -191,6 +192,11 @@ void SCSI_CDROM::event_callback(int event_id, int err) | ||
191 | 192 | if(fio_img->IsOpened()) { |
192 | 193 | fio_img->Fseek((cdda_start_frame - toc_table[trk].lba_offset) * 2352, FILEIO_SEEK_SET); |
193 | 194 | } |
195 | +// fio_img->Fclose(); | |
196 | + //current_track = 0; | |
197 | + //int trk = get_track(cdda_start_frame); | |
198 | +// int trk = current_track; | |
199 | +// fio_img->Fseek((cdda_start_frame - toc_table[trk].lba_offset) * 2352, FILEIO_SEEK_SET); | |
194 | 200 | } else { |
195 | 201 | fio_img->Fseek(cdda_start_frame * 2352, FILEIO_SEEK_SET); |
196 | 202 | } |
@@ -200,14 +206,18 @@ void SCSI_CDROM::event_callback(int event_id, int err) | ||
200 | 206 | read_sectors = 0; |
201 | 207 | memset(cdda_buffer, 0x00, sizeof(cdda_buffer)); |
202 | 208 | } |
209 | +// read_sectors = fio_img->Fread(cdda_buffer, 2352 * sizeof(uint8_t) , array_length(cdda_buffer) / 2352); | |
203 | 210 | cdda_buffer_ptr = 0; |
204 | 211 | cdda_playing_frame = cdda_start_frame; |
205 | 212 | access = true; |
206 | 213 | } else { |
207 | 214 | // Stop |
208 | 215 | if(event_cdda_delay_play >= 0) cancel_event(this, event_cdda_delay_play); |
209 | - register_event(this, EVENT_CDDA_DELAY_STOP, 1000.0, false, &event_cdda_delay_play); | |
210 | 216 | memset(cdda_buffer, 0x00, sizeof(cdda_buffer)); |
217 | + register_event(this, EVENT_CDDA_DELAY_STOP, 1000.0, false, &event_cdda_delay_play); | |
218 | + | |
219 | + //set_cdda_status(CDDA_OFF); | |
220 | + //register_event(this, EVENT_CDDA_DELAY_STOP, 1000.0, false, &event_cdda_delay_play); | |
211 | 221 | access = false; |
212 | 222 | } |
213 | 223 | } else if((cdda_buffer_ptr % 2352) == 0) { |
@@ -220,6 +230,7 @@ void SCSI_CDROM::event_callback(int event_id, int err) | ||
220 | 230 | read_sectors = 0; |
221 | 231 | memset(cdda_buffer, 0x00, sizeof(cdda_buffer)); |
222 | 232 | } |
233 | +// read_sectors = fio_img->Fread(cdda_buffer, 2352 * sizeof(uint8_t), array_length(cdda_buffer) / 2352); | |
223 | 234 | cdda_buffer_ptr = 0; |
224 | 235 | access = false; |
225 | 236 | } else { |
@@ -336,6 +347,7 @@ void SCSI_CDROM::get_track_by_track_num(int track) | ||
336 | 347 | fio_img->Fclose(); |
337 | 348 | } |
338 | 349 | out_debug_log(_T("LOAD TRK #%02d from %s\n"), track, track_data_path[track - 1]); |
350 | + | |
339 | 351 | if((track > 0) && (track < 100) && (track < track_num)) { |
340 | 352 | if((strlen(track_data_path[track - 1]) <= 0) || |
341 | 353 | !(fio_img->Fopen(track_data_path[track - 1], FILEIO_READ_BINARY))) { |
@@ -547,8 +559,8 @@ void SCSI_CDROM::start_command() | ||
547 | 559 | |
548 | 560 | if(cdda_end_frame <= toc_table[current_track].index0) { |
549 | 561 | cdda_end_frame = toc_table[current_track + 1].index0; // don't play pregap |
550 | - } else if(cdda_end_frame > toc_table[track_num].index0) { | |
551 | - cdda_end_frame = toc_table[track_num].index0; // end of disc | |
562 | + } else if(cdda_end_frame > toc_table[current_track + 1].index0) { | |
563 | + cdda_end_frame = toc_table[current_track + 1].index0; // don't play pregap | |
552 | 564 | } |
553 | 565 | #if 1 |
554 | 566 | if(is_cue) { |
@@ -559,15 +571,11 @@ void SCSI_CDROM::start_command() | ||
559 | 571 | #endif |
560 | 572 | if(cdda_end_frame <= toc_table[current_track].index0) { |
561 | 573 | cdda_end_frame = toc_table[current_track + 1].index0; // don't play pregap |
562 | - } else if(cdda_end_frame > toc_table[track_num].index0) { | |
563 | - cdda_end_frame = toc_table[track_num].index0; // end of disc | |
564 | - } | |
565 | - if(fio_img->IsOpened()) { | |
566 | - read_sectors = fio_img->Fread(cdda_buffer, 2352 * sizeof(uint8_t), array_length(cdda_buffer) / 2352); | |
567 | - } else { | |
568 | - read_sectors = 0; | |
569 | - memset(cdda_buffer, 0x00, sizeof(cdda_buffer)); | |
574 | + } else if(cdda_end_frame > toc_table[current_track + 1].index0) { | |
575 | + cdda_end_frame = toc_table[current_track + 1].index0; // don't play pregap | |
570 | 576 | } |
577 | + //memset(cdda_buffer, 0x00, array_length(cdda_buffer)); | |
578 | + read_sectors = fio_img->Fread(cdda_buffer, 2352 * sizeof(uint8_t), array_length(cdda_buffer) / 2352); | |
571 | 579 | if((command[1] & 3) != 0) { |
572 | 580 | cdda_repeat = ((command[1] & 3) == 1); |
573 | 581 | // read buffer |
@@ -635,13 +643,23 @@ void SCSI_CDROM::start_command() | ||
635 | 643 | // PCE tries to be clever here and set (start of track + track pregap size) to skip the pregap |
636 | 644 | // (I guess it wants the TOC to have the real start sector for data tracks and the start of the pregap for audio?) |
637 | 645 | |
638 | -// int track = get_track(cdda_start_frame); | |
639 | -// int track = current_track; | |
646 | +// int track = get_track(cdda_end_frame); | |
647 | + int track = current_track; | |
640 | 648 | // cdda_start_frame = toc_table[track].index0; |
641 | 649 | cdda_playing_frame = cdda_start_frame; |
642 | - //if(cdda_end_frame > toc_table[track + 1].index1 && (cdda_end_frame - toc_table[track].pregap) <= toc_table[track + 1].index1) { | |
643 | - // cdda_end_frame = toc_table[track + 1].index1; | |
644 | - //} | |
650 | +// if(is_cue) { | |
651 | +// fio_img->Fseek((cdda_start_frame - toc_table[current_track].lba_offset) * 2352, FILEIO_SEEK_SET); | |
652 | +// } else { | |
653 | +// fio_img->Fseek(cdda_start_frame * 2352, FILEIO_SEEK_SET); | |
654 | +// } | |
655 | + //read_sectors = fio_img->Fread(cdda_buffer, 2352 * sizeof(uint8_t), array_length(cdda_buffer) / 2352); | |
656 | +// if(cdda_end_frame < toc_table[track].lba_offset) { | |
657 | +// cdda_end_frame = toc_table[track + 1].index1; | |
658 | +// } | |
659 | + | |
660 | + if(cdda_end_frame > toc_table[track + 1].index1 && (cdda_end_frame - toc_table[track].pregap) <= toc_table[track + 1].index1) { | |
661 | + cdda_end_frame = toc_table[track + 1].index1; | |
662 | + } | |
645 | 663 | cdda_buffer_ptr = 0; |
646 | 664 | } |
647 | 665 | break; |
@@ -656,17 +674,12 @@ void SCSI_CDROM::start_command() | ||
656 | 674 | cdda_start_frame = toc_table[_track].index0; |
657 | 675 | cdda_end_frame = toc_table[_track].lba_size + toc_table[_track].lba_offset; |
658 | 676 | cdda_playing_frame = cdda_start_frame; |
659 | - if(fio_img->IsOpened()) { | |
660 | - if(is_cue) { | |
661 | - fio_img->Fseek((cdda_start_frame - toc_table[current_track].lba_offset) * 2352, FILEIO_SEEK_SET); | |
662 | - } else { | |
663 | - fio_img->Fseek(cdda_start_frame * 2352, FILEIO_SEEK_SET); | |
664 | - } | |
665 | - read_sectors = fio_img->Fread(cdda_buffer, 2352 * sizeof(uint8_t), array_length(cdda_buffer) / 2352); | |
677 | + if(is_cue) { | |
678 | + fio_img->Fseek((cdda_start_frame - toc_table[current_track].lba_offset) * 2352, FILEIO_SEEK_SET); | |
666 | 679 | } else { |
667 | - memset(cdda_buffer, 0x00, sizeof(cdda_buffer)); | |
668 | - read_sectors = 0; | |
680 | + fio_img->Fseek(cdda_start_frame * 2352, FILEIO_SEEK_SET); | |
669 | 681 | } |
682 | + read_sectors = fio_img->Fread(cdda_buffer, 2352 * sizeof(uint8_t), array_length(cdda_buffer) / 2352); | |
670 | 683 | cdda_buffer_ptr = 0; |
671 | 684 | } |
672 | 685 | } |
@@ -680,27 +693,26 @@ void SCSI_CDROM::start_command() | ||
680 | 693 | cdda_repeat = ((command[1] & 3) == 1); |
681 | 694 | cdda_interrupt = ((command[1] & 3) == 2); |
682 | 695 | |
683 | -// if(event_cdda_delay_play >= 0) cancel_event(this, event_cdda_delay_play); | |
684 | -// register_event(this, EVENT_CDDA_DELAY_PLAY, 10.0, false, &event_cdda_delay_play); | |
685 | - set_cdda_status(CDDA_PLAYING); | |
686 | - } else { | |
687 | - cdda_repeat = false; | |
688 | - cdda_interrupt = false; | |
689 | -// if(event_cdda_delay_play >= 0) cancel_event(this, event_cdda_delay_play); | |
690 | -// register_event(this, EVENT_CDDA_DELAY_STOP, 10.0, false, &event_cdda_delay_play); | |
691 | - set_cdda_status(CDDA_OFF); | |
692 | - } | |
696 | + if(event_cdda_delay_play >= 0) cancel_event(this, event_cdda_delay_play); | |
697 | + register_event(this, EVENT_CDDA_DELAY_PLAY, 10.0, false, &event_cdda_delay_play); | |
698 | + //set_cdda_status(CDDA_PLAYING); | |
699 | + } | |
693 | 700 | } |
694 | 701 | // change to status phase |
695 | 702 | set_dat(is_device_ready() ? SCSI_STATUS_GOOD : SCSI_STATUS_CHKCOND); |
696 | 703 | if(is_device_ready()) { |
697 | 704 | write_signals(&outputs_done, 0xffffffff); |
705 | + //if(event_delay_interrupt >= 0) cancel_event(this, event_delay_interrupt); | |
706 | + //register_event(this, EVENT_CDROM_DELAY_INTERRUPT_ON, 10.0, false, &event_delay_interrupt); | |
707 | + | |
698 | 708 | } |
699 | 709 | set_phase_delay(SCSI_PHASE_STATUS, 10.0); |
700 | 710 | return; |
701 | 711 | |
702 | 712 | case 0xda: |
703 | - out_debug_log(_T("Command: NEC Pause\n"), scsi_id); | |
713 | + #ifdef _SCSI_DEBUG_LOG | |
714 | + this->out_debug_log(_T("[SCSI_DEV:ID=%d] Command: NEC Pause\n"), scsi_id); | |
715 | + #endif | |
704 | 716 | if(is_device_ready()) { |
705 | 717 | if(cdda_status == CDDA_PLAYING) { |
706 | 718 | set_cdda_status(CDDA_PAUSED); |
@@ -713,7 +725,9 @@ void SCSI_CDROM::start_command() | ||
713 | 725 | return; |
714 | 726 | |
715 | 727 | case 0xdd: |
716 | - out_debug_log(_T("Command: NEC Read Sub Channel Q\n")); | |
728 | + #ifdef _SCSI_DEBUG_LOG | |
729 | + this->out_debug_log(_T("[SCSI_DEV:ID=%d] Command: NEC Read Sub Channel Q\n"), scsi_id); | |
730 | + #endif | |
717 | 731 | if(is_device_ready()) { |
718 | 732 | // create track info |
719 | 733 | uint32_t frame = (cdda_status == CDDA_OFF) ? cdda_start_frame : cdda_playing_frame; |
@@ -757,10 +771,14 @@ void SCSI_CDROM::start_command() | ||
757 | 771 | return; |
758 | 772 | |
759 | 773 | case 0xde: |
760 | - out_debug_log(_T("Command: NEC Get Dir Info\n")); | |
774 | + #ifdef _SCSI_DEBUG_LOG | |
775 | + this->out_debug_log(_T("[SCSI_DEV:ID=%d] Command: NEC Get Dir Info\n"), scsi_id); | |
776 | + #endif | |
761 | 777 | if(is_device_ready()) { |
762 | 778 | buffer->clear(); |
763 | - out_debug_log(_T("CMD=%02x ARG=%02x \n"), command[1], command[2]); | |
779 | + #ifdef _SCSI_DEBUG_LOG | |
780 | + this->out_debug_log(_T("[SCSI_DEV:ID=%d] CMD=%02x ARG=%02x \n"), scsi_id, command[1], command[2]); | |
781 | + #endif | |
764 | 782 | switch(command[1]) { |
765 | 783 | case 0x00: /* Get first and last track numbers */ |
766 | 784 | buffer->write(TO_BCD(1)); |
@@ -835,16 +853,22 @@ bool SCSI_CDROM::read_buffer(int length) | ||
835 | 853 | |
836 | 854 | if(is_cue) { |
837 | 855 | // ToDo: Need seek wait. |
838 | - out_debug_log(_T("Seek to LBA %d LENGTH=%d\n"), position / 2352, length); | |
856 | + #ifdef _CDROM_DEBUG_LOG | |
857 | + this->out_debug_log(_T("Seek to LBA %d LENGTH=%d\n"), position / 2352, length); | |
858 | + #endif | |
839 | 859 | if(fio_img->Fseek(((long)position - (long)(toc_table[current_track].lba_offset * 2352)), FILEIO_SEEK_SET) != 0) { |
840 | 860 | set_sense_code(SCSI_SENSE_ILLGLBLKADDR); //SCSI_SENSE_SEEKERR |
841 | - out_debug_log(_T("Error on reading (ILLGLBLKADDR) at line %d\n"), __LINE__); | |
861 | + #ifdef _SCSI_DEBUG_LOG | |
862 | + this->out_debug_log(_T("[SCSI_DEV:ID=%d] Error on reading (ILLGLBLKADDR) at line %d\n"), scsi_id, __LINE__); | |
863 | + #endif | |
842 | 864 | return false; |
843 | 865 | } |
844 | 866 | } else { |
845 | 867 | if(fio_img->Fseek((long)position, FILEIO_SEEK_SET) != 0) { |
846 | 868 | set_sense_code(SCSI_SENSE_ILLGLBLKADDR); //SCSI_SENSE_SEEKERR |
847 | - out_debug_log(_T("Error on reading (ILLGLBLKADDR) at line %d\n"), __LINE__); | |
869 | + #ifdef _SCSI_DEBUG_LOG | |
870 | + this->out_debug_log(_T("[SCSI_DEV:ID=%d] Error on reading (ILLGLBLKADDR) at line %d\n"), scsi_id, __LINE__); | |
871 | + #endif | |
848 | 872 | return false; |
849 | 873 | } |
850 | 874 | } |
@@ -854,7 +878,10 @@ bool SCSI_CDROM::read_buffer(int length) | ||
854 | 878 | int tmp_length = 2352 - offset; |
855 | 879 | |
856 | 880 | if(fio_img->Fread(tmp_buffer, tmp_length, 1) != 1) { |
857 | - out_debug_log(_T("Error on reading (ILLGLBLKADDR) at line %d\n"), __LINE__); | |
881 | + #ifdef _SCSI_DEBUG_LOG | |
882 | + this->out_debug_log(_T("[SCSI_DEV:ID=%d] Error on reading (ILLGLBLKADDR) at line %d\n"), scsi_id, __LINE__); | |
883 | + #endif | |
884 | + | |
858 | 885 | set_sense_code(SCSI_SENSE_ILLGLBLKADDR); //SCSI_SENSE_NORECORDFND |
859 | 886 | return false; |
860 | 887 | } |
@@ -881,10 +908,14 @@ bool SCSI_CDROM::write_buffer(int length) | ||
881 | 908 | int value = buffer->read(); |
882 | 909 | if(command[0] == SCSI_CMD_MODE_SEL6) { |
883 | 910 | if(i == 4) { |
884 | - out_debug_log(_T("NEC Read Mode = %02X\n"), value); | |
911 | + #ifdef _SCSI_DEBUG_LOG | |
912 | + this->out_debug_log(_T("[SCSI_DEV:ID=%d] NEC Read Mode = %02X\n"), scsi_id, value); | |
913 | + #endif | |
885 | 914 | read_mode = (value != 0); |
886 | 915 | } else if(i == 10) { |
887 | - out_debug_log(_T("NEC Retry Count = %02X\n"), value); | |
916 | + #ifdef _SCSI_DEBUG_LOG | |
917 | + this->out_debug_log(_T("[SCSI_DEV:ID=%d] NEC Retry Count = %02X\n"), scsi_id, value); | |
918 | + #endif | |
888 | 919 | } |
889 | 920 | } |
890 | 921 | position++; |
@@ -1031,7 +1062,10 @@ bool SCSI_CDROM::open_cue_file(const _TCHAR* file_path) | ||
1031 | 1062 | image_tmp_data_path.clear(); |
1032 | 1063 | image_tmp_data_path = std::string(parent_dir); |
1033 | 1064 | image_tmp_data_path.append(_arg2); |
1034 | - out_debug_log(_T("**FILE %s\n"), image_tmp_data_path.c_str()); | |
1065 | + | |
1066 | + #ifdef _CDROM_DEBUG_LOG | |
1067 | + this->out_debug_log(_T("**FILE %s\n"), image_tmp_data_path.c_str()); | |
1068 | + #endif | |
1035 | 1069 | goto _n_continue; // ToDo: Check ARG2 (BINARY etc..) 20181118 K.O |
1036 | 1070 | } else if(_arg1 == "TRACK") { |
1037 | 1071 | _arg2_ptr_s = _arg2.find_first_of((const char *)" \t"); |
@@ -1170,7 +1204,7 @@ bool SCSI_CDROM::open_cue_file(const _TCHAR* file_path) | ||
1170 | 1204 | |
1171 | 1205 | |
1172 | 1206 | //#ifdef _CDROM_DEBUG_LOG |
1173 | - out_debug_log(_T("TRACK#%02d TYPE=%s PREGAP=%d INDEX0=%d INDEX1=%d LBA_SIZE=%d LBA_OFFSET=%d PATH=%s\n"), | |
1207 | + this->out_debug_log(_T("TRACK#%02d TYPE=%s PREGAP=%d INDEX0=%d INDEX1=%d LBA_SIZE=%d LBA_OFFSET=%d PATH=%s\n"), | |
1174 | 1208 | i, (toc_table[i].is_audio) ? _T("AUDIO") : _T("MODE1/2352"), |
1175 | 1209 | toc_table[i].pregap, toc_table[i].index0, toc_table[i].index1, |
1176 | 1210 | toc_table[i].lba_size, toc_table[i].lba_offset, track_data_path[i - 1]); |
@@ -1269,19 +1303,19 @@ void SCSI_CDROM::open(const _TCHAR* file_path) | ||
1269 | 1303 | } |
1270 | 1304 | } |
1271 | 1305 | } |
1272 | - if(__SCSI_DEBUG_LOG) { | |
1306 | +#ifdef _SCSI_DEBUG_LOG | |
1273 | 1307 | if(mounted()) { |
1274 | 1308 | for(int i = 0; i < track_num + 1; i++) { |
1275 | 1309 | uint32_t idx0_msf = lba_to_msf(toc_table[i].index0); |
1276 | 1310 | uint32_t idx1_msf = lba_to_msf(toc_table[i].index1); |
1277 | 1311 | uint32_t pgap_msf = lba_to_msf(toc_table[i].pregap); |
1278 | - out_debug_log(_T("Track%02d: Index0=%02x:%02x:%02x Index1=%02x:%02x:%02x PreGap=%02x:%02x:%02x\n"), i + 1, | |
1312 | + this->out_debug_log(_T("Track%02d: Index0=%02x:%02x:%02x Index1=%02x:%02x:%02x PreGap=%02x:%02x:%02x\n"), i + 1, | |
1279 | 1313 | (idx0_msf >> 16) & 0xff, (idx0_msf >> 8) & 0xff, idx0_msf & 0xff, |
1280 | 1314 | (idx1_msf >> 16) & 0xff, (idx1_msf >> 8) & 0xff, idx1_msf & 0xff, |
1281 | 1315 | (pgap_msf >> 16) & 0xff, (pgap_msf >> 8) & 0xff, pgap_msf & 0xff); |
1282 | 1316 | } |
1283 | 1317 | } |
1284 | - } | |
1318 | +#endif | |
1285 | 1319 | } |
1286 | 1320 | |
1287 | 1321 | void SCSI_CDROM::close() |
@@ -100,6 +100,7 @@ public: | ||
100 | 100 | virtual void mix(int32_t* buffer, int cnt); |
101 | 101 | virtual void set_volume(int ch, int decibel_l, int decibel_r); |
102 | 102 | virtual bool process_state(FILEIO* state_fio, bool loading); |
103 | + virtual void out_debug_log(const _TCHAR *format, ...); | |
103 | 104 | |
104 | 105 | // virtual scsi functions |
105 | 106 | virtual void reset_device(); |
@@ -129,7 +130,6 @@ public: | ||
129 | 130 | { |
130 | 131 | register_output_signal(&outputs_done, device, id, mask); |
131 | 132 | } |
132 | - virtual void out_debug_log(const _TCHAR *format, ...); | |
133 | 133 | void open(const _TCHAR* file_path); |
134 | 134 | void close(); |
135 | 135 | bool mounted(); |
@@ -13,7 +13,6 @@ | ||
13 | 13 | #define EVENT_SEL 0 |
14 | 14 | #define EVENT_PHASE 1 |
15 | 15 | #define EVENT_REQ 2 |
16 | -#define EVENT_BSY 3 | |
17 | 16 | //#define _SCSI_DEBUG_LOG |
18 | 17 | |
19 | 18 | void SCSI_DEV::initialize() |
@@ -54,16 +53,8 @@ void SCSI_DEV::reset() | ||
54 | 53 | data_bus = 0; |
55 | 54 | sel_status = atn_status = ack_status = rst_status = false; |
56 | 55 | selected = atn_pending = false; |
57 | - next_bsy = 0; | |
58 | 56 | |
59 | - if(event_sel > -1) cancel_event(this, event_sel); | |
60 | - if(event_phase > -1) cancel_event(this, event_phase); | |
61 | - if(event_req > -1) cancel_event(this, event_req); | |
62 | - if(event_bsy > -1) cancel_event(this, event_bsy); | |
63 | - event_sel = event_phase = event_req = event_bsy = -1; | |
64 | - // Release BUS | |
65 | -// write_signals(&outputs_dat, 0); | |
66 | - write_signals(&outputs_bsy, 0); | |
57 | + event_sel = event_phase = event_req = -1; | |
67 | 58 | set_phase(SCSI_PHASE_BUS_FREE); |
68 | 59 | set_sense_code(SCSI_SENSE_NOSENSE); |
69 | 60 | } |
@@ -110,8 +101,6 @@ void SCSI_DEV::write_signal(int id, uint32_t data, uint32_t mask) | ||
110 | 101 | command_index = 0; |
111 | 102 | set_phase_delay(SCSI_PHASE_COMMAND, 10.0); |
112 | 103 | // set_phase(SCSI_PHASE_COMMAND); |
113 | -// set_bsy(1); | |
114 | -// set_req_delay(0, 1000.0); | |
115 | 104 | } |
116 | 105 | } |
117 | 106 | } |
@@ -172,7 +161,7 @@ void SCSI_DEV::write_signal(int id, uint32_t data, uint32_t mask) | ||
172 | 161 | */ |
173 | 162 | bool prev_status = ack_status; |
174 | 163 | ack_status = ((data & mask) != 0); |
175 | - //out_debug_log(_T("ACK=%s from %s"), (ack_status) ? _T("ON") : _T("OFF"), (prev_status) ? _T("ON") : _T("OFF")); | |
164 | + | |
176 | 165 | if(phase == SCSI_PHASE_BUS_FREE) { |
177 | 166 | // this device is not selected |
178 | 167 | } else if(!prev_status & ack_status) { |
@@ -198,7 +187,6 @@ void SCSI_DEV::write_signal(int id, uint32_t data, uint32_t mask) | ||
198 | 187 | break; |
199 | 188 | } |
200 | 189 | set_req_delay(0, 0.1); |
201 | -// set_req_delay(0, 0.25); // 4MHz | |
202 | 190 | } else if(prev_status && !ack_status) { |
203 | 191 | // H -> L |
204 | 192 | if(atn_pending) { |
@@ -317,8 +305,6 @@ void SCSI_DEV::write_signal(int id, uint32_t data, uint32_t mask) | ||
317 | 305 | memset(command, 0, sizeof(command)); |
318 | 306 | command_index = 0; |
319 | 307 | set_phase_delay(SCSI_PHASE_COMMAND, 10.0); |
320 | -// set_bsy(1); | |
321 | -// set_req_delay(0, 1000.0); | |
322 | 308 | } else { |
323 | 309 | // abort, change to bus free phase |
324 | 310 | set_phase_delay(SCSI_PHASE_BUS_FREE, 10.0); |
@@ -360,18 +346,13 @@ void SCSI_DEV::write_signal(int id, uint32_t data, uint32_t mask) | ||
360 | 346 | void SCSI_DEV::event_callback(int event_id, int err) |
361 | 347 | { |
362 | 348 | switch(event_id) { |
363 | - case EVENT_BSY: | |
364 | - event_bsy = -1; | |
365 | - set_bsy(next_bsy); | |
366 | - break; | |
367 | 349 | case EVENT_SEL: |
368 | 350 | event_sel = -1; |
369 | 351 | if((data_bus & 0x7f) == (1 << scsi_id)) { |
370 | 352 | if(is_device_existing()) { |
371 | 353 | // this device is selected! |
372 | 354 | out_debug_log(_T("This device is selected\n")); |
373 | - set_bsy(1); | |
374 | -// set_req(1); | |
355 | + set_bsy(true); | |
375 | 356 | selected = true; |
376 | 357 | } |
377 | 358 | } |
@@ -392,24 +373,22 @@ void SCSI_DEV::event_callback(int event_id, int err) | ||
392 | 373 | void SCSI_DEV::set_phase(int value) |
393 | 374 | { |
394 | 375 | out_debug_log(_T("Phase %s -> %s\n"), scsi_phase_name[phase], scsi_phase_name[value]); |
395 | - set_io (value & 1); | |
396 | - set_msg(value & 2); | |
397 | - set_cd (value & 4); | |
398 | - | |
399 | 376 | if(event_phase != -1) { |
400 | 377 | cancel_event(this, event_phase); |
401 | 378 | event_phase = -1; |
402 | 379 | } |
380 | + set_io (value & 1); | |
381 | + set_msg(value & 2); | |
382 | + set_cd (value & 4); | |
383 | + | |
403 | 384 | if(value == SCSI_PHASE_BUS_FREE) { |
404 | - set_bsy(0); | |
385 | + set_bsy(false); | |
405 | 386 | set_req(0); |
406 | 387 | selected = false; |
407 | 388 | } else { |
408 | 389 | first_req_clock = 0; |
409 | - set_bsy(1); | |
410 | - set_req(1); | |
411 | - //set_req_delay(0, 800.0); | |
412 | - //set_bsy_delay(0, 800.0); | |
390 | +// set_bsy(true); | |
391 | + set_req_delay(1, 10.0); | |
413 | 392 | } |
414 | 393 | phase = value; |
415 | 394 | } |
@@ -430,23 +409,12 @@ void SCSI_DEV::set_phase_delay(int value, double usec) | ||
430 | 409 | |
431 | 410 | void SCSI_DEV::set_dat(int value) |
432 | 411 | { |
412 | + if(__SCSI_DEBUG_LOG) { | |
433 | 413 | // emu->force_out_debug_log(_T("[SCSI_DEV:ID=%d] DATA = %02x\n"), scsi_id, value); |
414 | + } | |
434 | 415 | write_signals(&outputs_dat, value); |
435 | 416 | } |
436 | 417 | |
437 | -void SCSI_DEV::set_bsy_delay(int value, double usec) | |
438 | -{ | |
439 | - if(event_bsy > -1) { | |
440 | - cancel_event(this, event_bsy); | |
441 | - event_bsy = -1; | |
442 | - } | |
443 | - next_bsy = value; | |
444 | - if(usec <= 10.0) { | |
445 | - set_bsy(value); | |
446 | - } else { | |
447 | - register_event(this, EVENT_BSY, usec, false, &event_bsy); | |
448 | - } | |
449 | -} | |
450 | 418 | void SCSI_DEV::set_bsy(int value) |
451 | 419 | { |
452 | 420 | out_debug_log(_T("BUSY = %d\n"), value ? 1 : 0); |
@@ -473,7 +441,7 @@ void SCSI_DEV::set_msg(int value) | ||
473 | 441 | |
474 | 442 | void SCSI_DEV::set_req(int value) |
475 | 443 | { |
476 | -// out_debug_log(_T("REQ = %d\n"), value ? 1 : 0); | |
444 | + out_debug_log(_T("REQ = %d\n"), value ? 1 : 0); | |
477 | 445 | if(event_req != -1) { |
478 | 446 | cancel_event(this, event_req); |
479 | 447 | event_req = -1; |
@@ -520,7 +488,7 @@ void SCSI_DEV::start_command() | ||
520 | 488 | { |
521 | 489 | switch(command[0]) { |
522 | 490 | case SCSI_CMD_TST_U_RDY: |
523 | - out_debug_log(_T("Command: Test Unit Ready\n")); | |
491 | + out_debug_log(_T("Command: Test Unit Ready\n")); | |
524 | 492 | // change to status phase |
525 | 493 | if(!is_device_ready()) { |
526 | 494 | set_dat(SCSI_STATUS_CHKCOND); |
@@ -529,7 +497,6 @@ void SCSI_DEV::start_command() | ||
529 | 497 | set_dat(SCSI_STATUS_GOOD); |
530 | 498 | set_sense_code(SCSI_SENSE_NOSENSE); |
531 | 499 | } |
532 | -// remain = 0; | |
533 | 500 | set_phase_delay(SCSI_PHASE_STATUS, 10.0); |
534 | 501 | break; |
535 | 502 |
@@ -642,9 +609,9 @@ void SCSI_DEV::start_command() | ||
642 | 609 | break; |
643 | 610 | |
644 | 611 | case SCSI_CMD_READ6: |
645 | - out_debug_log(_T("Command: Read 6-byte\n")); | |
646 | 612 | // start position |
647 | 613 | position = (command[1] & 0x1f) * 0x10000 + command[2] * 0x100 + command[3]; |
614 | + out_debug_log(_T("Command: Read 6-byte LBA=%d BLOCKS=%d\n"), position, command[4]); | |
648 | 615 | position *= physical_block_size(); |
649 | 616 | // transfer length |
650 | 617 | remain = command[4] * logical_block_size(); |
@@ -670,9 +637,9 @@ void SCSI_DEV::start_command() | ||
670 | 637 | break; |
671 | 638 | |
672 | 639 | case SCSI_CMD_WRITE6: |
673 | - out_debug_log(_T("Command: Write 6-Byte\n")); | |
674 | 640 | // start position |
675 | 641 | position = (command[1] & 0x1f) * 0x10000 + command[2] * 0x100 + command[3]; |
642 | + out_debug_log(_T("Command: Write 6-byte LBA=%d BLOCKS=%d\n"), position, command[4]); | |
676 | 643 | position *= physical_block_size(); |
677 | 644 | // transfer length |
678 | 645 | remain = command[4] * logical_block_size(); |
@@ -690,9 +657,9 @@ void SCSI_DEV::start_command() | ||
690 | 657 | break; |
691 | 658 | |
692 | 659 | case SCSI_CMD_READ10: |
693 | - out_debug_log(_T("Command: Read 10-byte\n")); | |
694 | 660 | // start position |
695 | 661 | position = command[2] * 0x1000000 + command[3] * 0x10000 + command[4] * 0x100 + command[5]; |
662 | + out_debug_log(_T("Command: Read 10-byte LBA=%d BLOCKS=%d\n"), position, command[7] * 0x100 + command[8]); | |
696 | 663 | position *= physical_block_size(); |
697 | 664 | // transfer length |
698 | 665 | remain = command[7] * 0x100 + command[8]; |
@@ -719,13 +686,12 @@ void SCSI_DEV::start_command() | ||
719 | 686 | break; |
720 | 687 | |
721 | 688 | case SCSI_CMD_WRITE10: |
722 | - out_debug_log(_T("Command: Write 10-Byte\n")); | |
723 | 689 | goto WRITE10; |
724 | 690 | case SCSI_CMD_WRT_VERIFY: |
725 | - out_debug_log(_T("Command: Write and Verify\n")); | |
726 | 691 | WRITE10: |
727 | 692 | // start position |
728 | 693 | position = command[2] * 0x1000000 + command[3] * 0x10000 + command[4] * 0x100 + command[5]; |
694 | + out_debug_log(_T("Command: %s LBA=%d BLOCKS=%d\n"), (command[0] == SCSI_CMD_WRT_VERIFY) ? _T("Write and Verify") : _T("Write 10-byte"), position, command[7] * 0x100 + command[8]); | |
729 | 695 | position *= physical_block_size(); |
730 | 696 | // transfer length |
731 | 697 | remain = command[7] * 0x100 + command[8]; |
@@ -744,9 +710,9 @@ void SCSI_DEV::start_command() | ||
744 | 710 | break; |
745 | 711 | |
746 | 712 | case SCSI_CMD_READ12: |
747 | - out_debug_log(_T("Command: Read 12-byte\n")); | |
748 | 713 | // start position |
749 | 714 | position = command[2] * 0x1000000 + command[3] * 0x10000 + command[4] * 0x100 + command[5]; |
715 | + out_debug_log(_T("Command: Read 12-byte LBA=%d BLOCKS=%d\n"), position, command[6] * 0x1000000 + command[7] * 0x10000 + command[8] * 0x100 + command[9]); | |
750 | 716 | position *= physical_block_size(); |
751 | 717 | // transfer length |
752 | 718 | remain = command[6] * 0x1000000 + command[7] * 0x10000 + command[8] * 0x100 + command[9]; |
@@ -773,9 +739,9 @@ void SCSI_DEV::start_command() | ||
773 | 739 | break; |
774 | 740 | |
775 | 741 | case SCSI_CMD_WRITE12: |
776 | - out_debug_log(_T("Command: Write 12-Byte\n")); | |
777 | 742 | // start position |
778 | 743 | position = command[2] * 0x1000000 + command[3] * 0x10000 + command[4] * 0x100 + command[5]; |
744 | + out_debug_log(_T("Command: Write 12-byte LBA=%d BLOCKS=%d\n"), position, command[6] * 0x1000000 + command[7] * 0x10000 + command[8] * 0x100 + command[9]); | |
779 | 745 | position *= physical_block_size(); |
780 | 746 | // transfer length |
781 | 747 | remain = command[6] * 0x1000000 + command[7] * 0x10000 + command[8] * 0x100 + command[9]; |
@@ -820,7 +786,7 @@ bool SCSI_DEV::write_buffer(int length) | ||
820 | 786 | return true; |
821 | 787 | } |
822 | 788 | |
823 | -#define STATE_VERSION 3 | |
789 | +#define STATE_VERSION 2 | |
824 | 790 | |
825 | 791 | bool SCSI_DEV::process_state(FILEIO* state_fio, bool loading) |
826 | 792 | { |
@@ -853,7 +819,5 @@ bool SCSI_DEV::process_state(FILEIO* state_fio, bool loading) | ||
853 | 819 | state_fio->StateValue(position); |
854 | 820 | state_fio->StateValue(remain); |
855 | 821 | state_fio->StateValue(sense_code); |
856 | - state_fio->StateValue(event_bsy); | |
857 | - state_fio->StateValue(next_bsy); | |
858 | 822 | return true; |
859 | 823 | } |
@@ -150,35 +150,30 @@ protected: | ||
150 | 150 | |
151 | 151 | int phase, next_phase, next_req; |
152 | 152 | int event_sel, event_phase, event_req; |
153 | - int next_bsy; | |
154 | - int event_bsy; | |
155 | - | |
156 | 153 | uint32_t first_req_clock; |
157 | 154 | double next_req_usec; |
158 | 155 | |
159 | 156 | uint8_t sense_code; |
160 | - | |
157 | + | |
161 | 158 | bool _SCSI_HOST_WIDE; |
162 | 159 | bool _SCSI_DEV_IMMEDIATE_SELECT; |
163 | 160 | bool __SCSI_DEBUG_LOG; |
164 | 161 | bool _OUT_DEBUG_LOG; |
165 | - | |
166 | 162 | public: |
167 | 163 | SCSI_DEV(VM_TEMPLATE* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu) |
168 | 164 | { |
169 | - _SCSI_HOST_WIDE = false; | |
170 | - _SCSI_DEV_IMMEDIATE_SELECT = false; | |
171 | - __SCSI_DEBUG_LOG = false; | |
172 | - _OUT_DEBUG_LOG = false; | |
173 | 165 | initialize_output_signals(&outputs_dat); |
174 | 166 | initialize_output_signals(&outputs_bsy); |
175 | 167 | initialize_output_signals(&outputs_cd); |
176 | 168 | initialize_output_signals(&outputs_io); |
177 | 169 | initialize_output_signals(&outputs_msg); |
178 | 170 | initialize_output_signals(&outputs_req); |
171 | + _SCSI_HOST_WIDE = false; | |
172 | + _SCSI_DEV_IMMEDIATE_SELECT = false; | |
173 | + __SCSI_DEBUG_LOG = false; | |
174 | + _OUT_DEBUG_LOG = false; | |
179 | 175 | |
180 | 176 | set_device_name(_T("SCSI DEVICE")); |
181 | - | |
182 | 177 | } |
183 | 178 | ~SCSI_DEV() {} |
184 | 179 |
@@ -200,6 +195,7 @@ public: | ||
200 | 195 | //#else |
201 | 196 | register_output_signal(&outputs_dat, device, SIG_SCSI_DAT, 0xff); |
202 | 197 | //#endif |
198 | +// register_output_signal(&outputs_dat, device, SIG_SCSI_DAT, 1 << scsi_id); | |
203 | 199 | register_output_signal(&outputs_bsy, device, SIG_SCSI_BSY, 1 << scsi_id); |
204 | 200 | register_output_signal(&outputs_cd, device, SIG_SCSI_CD, 1 << scsi_id); |
205 | 201 | register_output_signal(&outputs_io, device, SIG_SCSI_IO, 1 << scsi_id); |
@@ -218,7 +214,6 @@ public: | ||
218 | 214 | void set_phase_delay(int value, double usec); |
219 | 215 | void set_dat(int value); |
220 | 216 | void set_bsy(int value); |
221 | - void set_bsy_delay(int value, double usec); | |
222 | 217 | void set_cd(int value); |
223 | 218 | void set_io(int value); |
224 | 219 | void set_msg(int value); |