1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
|
// license: BSD-3-Clause
// copyright-holders: Angelo Salese
/**************************************************************************************************
CR-560-B CD-ROM drive
Panasonic pre-IDE MKE interface, akin to CR-511-B (which this is based off) and Creative
Soundblaster.
NOTES:
- all commands but cmd_reset and cmd_read_subq acknowledge command byte issued
in first output return byte;
- 3do disks are not ISO9660 compatible. First sector at LBA 0 / MSF 00:02:00 is described at:
https://github.com/trapexit/portfolio_os/blob/bee7b0c8e4287083c73cb5497b658880c9e7af8e/utils/discdata.h#L52
TODO:
- Enough to load a few sectors and nothing else;
- Find common points with other MKE drives, generate a streamlined interface;
**************************************************************************************************/
#include "emu.h"
#include "cr560b.h"
#define LOG_CMD (1 << 1)
#define LOG_TOC (1 << 2)
#define LOG_PARAM (1 << 3)
#define LOG_DATA (1 << 4)
#define LOG_SUBQ (1 << 5)
#define LOG_SUBQ2 (1 << 6) // log subq data to popmessage
#define VERBOSE (LOG_GENERAL | LOG_TOC | LOG_CMD | LOG_PARAM)
//#define VERBOSE (LOG_TOC)
//#define LOG_OUTPUT_FUNC osd_printf_info
#define LOGPARAM LOGMASKED(LOG_PARAM, "-> Param: %02x %02x %02x %02x %02x %02x\n", \
m_input_fifo[1], m_input_fifo[2], m_input_fifo[3], \
m_input_fifo[4], m_input_fifo[5], m_input_fifo[6])
#include "logmacro.h"
//**************************************************************************
// TYPE DEFINITIONS
//**************************************************************************
DEFINE_DEVICE_TYPE(CR560B, cr560b_device, "cr560b", "CR-560-B CD-ROM drive")
cr560b_device::cr560b_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
cdrom_image_device(mconfig, CR560B, tag, owner, clock),
device_mixer_interface(mconfig, *this),
m_cdda(*this, "cdda"),
m_stch_cb(*this),
m_sten_cb(*this),
m_drq_cb(*this),
m_dten_cb(*this),
m_scor_cb(*this),
m_input_fifo_pos(0),
m_output_fifo_pos(0),
m_output_fifo_length(0),
m_status(0),
m_enabled(false),
m_cmd(false),
m_status_ready(false),
m_data_ready(false)
{
set_interface("cdrom");
}
//**************************************************************************
// MACHINE DEFINITIONS
//**************************************************************************
void cr560b_device::device_add_mconfig(machine_config &config)
{
CDDA(config, m_cdda);
m_cdda->add_route(0, DEVICE_SELF, 1.0, 0);
m_cdda->add_route(1, DEVICE_SELF, 1.0, 1);
m_cdda->set_cdrom_tag(*this);
m_cdda->audio_end_cb().set(FUNC(cr560b_device::audio_end_cb));
}
//**************************************************************************
// MACHINE EMULATION
//**************************************************************************
void cr560b_device::device_start()
{
cdrom_image_device::device_start();
m_frame_timer = timer_alloc(FUNC(cr560b_device::frame_cb), this);
m_stch_timer = timer_alloc(FUNC(cr560b_device::stch), this);
m_sten_timer = timer_alloc(FUNC(cr560b_device::sten), this);
std::fill(std::begin(m_input_fifo), std::end(m_input_fifo), 0x00);
std::fill(std::begin(m_output_fifo), std::end(m_output_fifo), 0x00);
std::fill(std::begin(m_transfer_buffer), std::end(m_transfer_buffer), 0xff);
// register for save states
save_item(NAME(m_input_fifo));
save_item(NAME(m_input_fifo_pos));
save_item(NAME(m_output_fifo));
save_item(NAME(m_output_fifo_pos));
save_item(NAME(m_output_fifo_length));
save_item(NAME(m_status));
save_item(NAME(m_sector_size));
save_item(NAME(m_transfer_lba));
save_item(NAME(m_transfer_sectors));
save_item(NAME(m_transfer_length));
save_item(NAME(m_transfer_buffer));
save_item(NAME(m_transfer_buffer_pos));
save_item(NAME(m_enabled));
save_item(NAME(m_cmd));
save_item(NAME(m_status_ready));
save_item(NAME(m_data_ready));
}
void cr560b_device::device_reset()
{
cdrom_image_device::device_reset();
m_input_fifo_pos = 0;
m_output_fifo_pos = 0;
m_output_fifo_length = 0;
m_sector_size = 2048;
m_status_ready = false;
m_data_ready = false;
m_cdrom_speed = 1;
m_status = 0; //STATUS_READY;
if (exists())
m_status |= STATUS_MEDIA;
m_sten_cb(1);
m_stch_cb(0);
}
std::pair<std::error_condition, std::string> cr560b_device::call_load()
{
auto ret = cdrom_image_device::call_load();
if (!ret.first)
{
status_change(m_status | STATUS_MEDIA | STATUS_DOOR_CLOSED);
}
return ret;
}
void cr560b_device::call_unload()
{
status_change(0);
cdrom_image_device::call_unload();
}
uint32_t cr560b_device::lba_to_msf(int32_t lba)
{
uint32_t msf = 0;
lba += 2 * 75; // lba 0 is equivalent to msf 00:02:00
msf |= ((lba / (60 * 75)) & 0xff) << 16;
msf |= (((lba / 75) % 60) & 0xff) << 8;
msf |= ((lba % 75) & 0xff) << 0;
return msf;
}
int32_t cr560b_device::msf_to_lba(uint32_t msf)
{
int32_t lba = 0;
lba += ((msf >> 16) & 0xff) * 60 * 75;
lba += ((msf >> 8) & 0xff) * 75;
lba += ((msf >> 0) & 0xff);
lba -= 2 * 75; // msf 00:02:00 is equivalent to lba 0
if (lba < 0)
throw emu_fatalerror("Requested lba in lead-in %08x %08x\n", msf, lba);
return lba;
}
int cr560b_device::size_to_track_type()
{
switch (m_sector_size)
{
case 2048: return cdrom_file::CD_TRACK_MODE1;
// TODO: really from flags
// Also: Clio and Madam sets 2448 in DMA params, off by 96 (subcode ...)
case 2352: return cdrom_file::CD_TRACK_AUDIO;
}
// TODO: 3do definitely supports other formats
throw emu_fatalerror("Unknown sector mode: %d\n", m_sector_size);
}
TIMER_CALLBACK_MEMBER(cr560b_device::frame_cb)
{
if (m_transfer_sectors > 0)
{
// old data hasn't been read completely yet
if (m_data_ready)
return;
LOGMASKED(LOG_DATA, "Reading sector: %d\n", m_transfer_lba);
read_data(m_transfer_lba, m_transfer_buffer, size_to_track_type());
// prepare for next sector
m_transfer_lba++;
m_transfer_sectors--;
m_transfer_buffer_pos = 0;
// signal that we have data
m_data_ready = true;
m_drq_cb(1);
}
else if (m_status & STATUS_PLAYING)
{
// TODO: subcode handling
m_scor_cb(0);
m_scor_cb(1);
}
}
TIMER_CALLBACK_MEMBER(cr560b_device::stch)
{
m_stch_cb(1);
m_stch_cb(0);
}
void cr560b_device::status_change(uint8_t status)
{
if (m_status != status)
{
m_status = status;
if (m_status & STATUS_MOTOR)
{
m_frame_timer->adjust(attotime::from_hz(75 * m_cdrom_speed), 0, attotime::from_hz(75 * m_cdrom_speed));
}
else
m_frame_timer->adjust(attotime::never);
m_stch_timer->adjust(attotime::from_usec(64 * 3)); // TODO
}
}
TIMER_CALLBACK_MEMBER(cr560b_device::sten)
{
m_status_ready = true;
m_sten_cb(0);
}
void cr560b_device::status_enable(uint8_t output_length)
{
m_input_fifo_pos = 0;
m_output_fifo_pos = 0;
m_output_fifo_length = output_length;
// do we have status data to send?
if (m_output_fifo_length > 0)
{
if (m_input_fifo[0] != 0x87 || (VERBOSE & LOG_SUBQ))
LOGMASKED(LOG_CMD, "-> Output: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n", m_output_fifo[0], m_output_fifo[1], m_output_fifo[2], m_output_fifo[3], m_output_fifo[4], m_output_fifo[5], m_output_fifo[6], m_output_fifo[7], m_output_fifo[8], m_output_fifo[9], m_output_fifo[10], m_output_fifo[11]);
m_sten_timer->adjust(attotime::from_usec(64 * 4)); // TODO
}
}
void cr560b_device::audio_end_cb(int state)
{
if (!state)
return;
LOGMASKED(LOG_CMD, "Playing audio finished\n", state);
status_change(m_status & ~STATUS_PLAYING);
}
uint8_t cr560b_device::read()
{
uint8_t data = 0xff;
if (!m_enabled)
{
LOG("Read while not enabled!\n");
return data;
}
if (m_cmd)
{
// command mode
if (m_status_ready)
{
data = m_output_fifo[m_output_fifo_pos];
// clear old data once read
m_output_fifo[m_output_fifo_pos++] = 0x00;
LOGMASKED(LOG_DATA, "Data from drive: %02x (%d of %d)\n", data, m_output_fifo_pos, m_output_fifo_length);
// more data?
if (m_output_fifo_pos < m_output_fifo_length)
{
m_sten_cb(0);
}
else
{
m_status_ready = false;
m_sten_cb(1);
}
}
}
else
{
// data mode
if (m_data_ready)
{
data = m_transfer_buffer[m_transfer_buffer_pos];
m_transfer_length--;
LOGMASKED(LOG_DATA, "Data = %02x, pos %d, length %d\n", data, m_transfer_buffer_pos, m_transfer_length);
// finished transferring this sector?
if (++m_transfer_buffer_pos == m_sector_size)
{
m_data_ready = false;
m_drq_cb(0);
if (m_transfer_sectors == 0)
{
LOGMASKED(LOG_DATA, "Read done\n");
status_change(m_status | STATUS_SUCCESS);
}
}
}
}
return data;
}
void cr560b_device::write(uint8_t data)
{
// verify that we're enabled and are in command mode
if (!m_enabled || !m_cmd)
{
LOG("Invalid write: %02x (enabled: %d, cmd: %d)\n", data, m_enabled, m_cmd);
return;
}
m_input_fifo[m_input_fifo_pos++] = data;
// all commands except for abort takes 7 input bytes
if (m_input_fifo_pos == 1 && m_input_fifo[0] == 0x08)
{
LOG("Abort command %08x (tbd)\n", m_input_fifo[0]);
//cmd_abort();
status_enable(0);
return;
}
if (m_input_fifo_pos != 7)
return;
switch (m_input_fifo[0])
{
case 0x01: cmd_seek(); break;
case 0x02: cmd_motor_on(); break;
case 0x03: cmd_motor_off(); break;
//case 0x04: cmd_diag(); break;
case 0x05: cmd_read_status(); break;
// TODO: drawer_open is issued by fz10e just after purging the disc avatars
//case 0x06: cmd_drawer_open(); break;
//case 0x07: cmd_drawer_close(); break;
case 0x09: cmd_set_mode(); break;
//case 0x0a: cmd_reset(); break;
// TODO: flush requested by Audio CD player
//case 0x0b: cmd_flush(); break;
// these two are unconfirmed
//case 0x0c: cmd_lock(); break;
//case 0x0d: cmd_pause_resume(); break;
case 0x0e: cmd_play_msf(); break;
case 0x0f: cmd_play_track(); break;
case 0x10: cmd_read(); break;
//case 0x11: cmd_read_subq(); break;
case 0x80: cmd_data_path_check(); break;
//case 0x81: cmd_read_status(); break;
case 0x82: cmd_read_error(); break;
case 0x83: cmd_version(); break;
//case 0x84: cmd_mode_sense(); break;
case 0x85: cmd_read_capacity(); break;
//case 0x86: cmd_read_header(); break;
//case 0x87: cmd_read_subq(); break;
//case 0x88: cmd_read_upc(); break;
//case 0x89: cmd_read_isrc(); break;
//case 0x8a: cmd_read_disc_code(); break;
case 0x8b: cmd_read_disc_info(); break;
case 0x8c: cmd_read_toc(); break;
case 0x8d: cmd_read_session_info(); break;
//case 0x8e: cmd_read_device_driver(); break;
default:
LOG("Unknown command: %02x\n", m_input_fifo[0]);
status_enable(0);
break;
}
}
void cr560b_device::cmd_w(int state)
{
m_cmd = !bool(state); // active low
}
void cr560b_device::enable_w(int state)
{
m_enabled = !bool(state); // active low
}
/******************
*
* Commands
*
*****************/
// TODO: unverified in this implementation
void cr560b_device::cmd_seek()
{
LOGMASKED(LOG_CMD, "Command: Seek\n");
LOGPARAM;
const u8 seek_mode = m_input_fifo[1];
const u32 param = (m_input_fifo[2] << 16) | (m_input_fifo[3] << 8) | (m_input_fifo[4]);
switch(seek_mode)
{
case 0x00:
LOGMASKED(LOG_CMD, "-> To LBA %06x\n", param);
break;
case 0x02:
LOGMASKED(LOG_CMD, "-> To MSF %06x\n", param);
break;
default:
LOGMASKED(LOG_CMD, "-> Unknown mode %02x!\n", seek_mode);
break;
}
// TODO: Does this enable STATUS_SUCCESS?
u8 status = m_status;
status |= STATUS_MOTOR;
m_output_fifo[0] = 0x01;
m_output_fifo[1] = status;
status_change(status);
status_enable(2);
}
// TODO: unverified in this implementation
// labeled as "No Operation" in 3do Technical Manual
void cr560b_device::cmd_read_status()
{
LOGMASKED(LOG_CMD, "Command: Read Status\n");
u8 status = m_status;
status &= ~STATUS_SUCCESS;
m_output_fifo[0] = 0x05;
m_output_fifo[1] = status;
status_change(status);
status_enable(2);
}
// TODO: unverified in this implementation
// Spinup
void cr560b_device::cmd_motor_on()
{
LOGMASKED(LOG_CMD, "Command: Motor On\n");
LOGPARAM;
// TODO: Does this enable STATUS_SUCCESS?
u8 status = m_status;
status |= STATUS_SUCCESS;
m_output_fifo[0] = 0x02;
m_output_fifo[1] = status;
status_change(status);
status_enable(2);
}
// TODO: unverifed in this implementation
// Spindown
void cr560b_device::cmd_motor_off()
{
LOGMASKED(LOG_CMD, "Command: Motor Off\n");
LOGPARAM;
// TODO: Does this enable STATUS_SUCCESS?
u8 status = m_status;
status &= ~STATUS_MOTOR;
m_output_fifo[0] = 0x03;
m_output_fifo[1] = status;
status_change(status);
status_enable(2);
}
void cr560b_device::cmd_set_mode()
{
LOGMASKED(LOG_CMD, "Command: Set Mode\n");
LOGPARAM;
u8 status = m_status;
switch(m_input_fifo[1])
{
case 0x00:
// density codes:
// 0x00: default density
// 0x01: data
// 0x81: mode2 XA
// 0x82: digital audio
m_sector_size = (m_input_fifo[3] << 8) | m_input_fifo[4];
LOGMASKED(LOG_CMD, "-> density code %02x sector size %d flags %02x\n", m_input_fifo[2], m_sector_size, m_input_fifo[5]);
break;
case 0x01:
LOGMASKED(LOG_CMD, "-> Error recovery type %02x retry count %02x\n", m_input_fifo[2], m_input_fifo[3]);
break;
case 0x02:
LOGMASKED(LOG_CMD, "-> Stop time %02x\n", m_input_fifo[2]);
break;
case 0x03:
m_cdrom_speed = BIT(m_input_fifo[2], 7) + 1;
LOGMASKED(LOG_CMD, "-> Set speed %dx vpitch %02x%02x\n", m_cdrom_speed, m_input_fifo[3], m_input_fifo[4]);
if (m_cdrom_speed == 2)
status |= STATUS_DOUBLE_SPEED;
else
status &= ~STATUS_DOUBLE_SPEED;
break;
case 0x04:
LOGMASKED(LOG_CMD, "-> Chunk size %02x\n", m_input_fifo[2]);
break;
//case 5: set volume (never seen it so far, not in Portfolio OS?)
default:
LOGMASKED(LOG_CMD, "-> <unknown %02x> !?\n", m_input_fifo[1]);
break;
}
status |= STATUS_SUCCESS;
m_output_fifo[0] = 0x09;
m_output_fifo[1] = status;
status_change(status);
status_enable(2);
}
// TODO: unverified in this implementation
// TODO: needs to check against 2x speed
void cr560b_device::cmd_play_msf()
{
LOGMASKED(LOG_CMD, "Command: Play MSF\n");
LOGPARAM;
uint8_t status = m_status;
uint32_t start = (m_input_fifo[1] << 16) | (m_input_fifo[2] << 8) | (m_input_fifo[3] << 0);
uint32_t end = (m_input_fifo[4] << 16) | (m_input_fifo[5] << 8) | (m_input_fifo[6] << 0);
int32_t start_lba = msf_to_lba(start);
int32_t end_lba = msf_to_lba(end);
// play to the end of the disc?
if (end == 0xffffff)
end_lba = get_track_start(0xaa) - 1;
if (start == 0 && end == 0)
{
LOGMASKED(LOG_CMD, "Stop audio\n");
if (m_cdda->audio_active())
status |= STATUS_SUCCESS;
m_cdda->stop_audio();
status &= ~STATUS_PLAYING;
status &= ~STATUS_MOTOR;
}
else if (start_lba < end_lba)
{
LOGMASKED(LOG_CMD, "Playing audio %02d:%02d.%02d to %02d:%02d.%02d (LBA %06x to %06x)\n",
m_input_fifo[1], m_input_fifo[2], m_input_fifo[3],
m_input_fifo[4], m_input_fifo[5], m_input_fifo[6], start_lba, end_lba);
m_cdda->start_audio(start_lba, end_lba - start_lba);
status |= STATUS_PLAYING;
status |= STATUS_MOTOR;
}
else
{
LOGMASKED(LOG_CMD, "Invalid range %d to %d!\n", start_lba, end_lba);
status |= STATUS_ERROR;
}
m_output_fifo[0] = 0x0e;
m_output_fifo[1] = status;
status_change(status);
status_enable(2);
}
// TODO: unverified in this implementation
// TODO: needs to check against 2x speed
void cr560b_device::cmd_play_track()
{
LOGMASKED(LOG_CMD, "Command: Play Track\n");
LOGPARAM;
uint8_t start_track = m_input_fifo[1];
uint8_t start_index = m_input_fifo[2]; // TODO
uint8_t end_track = m_input_fifo[3];
uint8_t end_index = m_input_fifo[4]; // TODO
uint32_t start_lba = get_track_start(start_track - 1);
uint32_t end_lba = get_track_start(end_track - 1) - 1;
LOGMASKED(LOG_CMD, "Playing audio track %d-%d to %d-%d (LBA %06x to %06x)\n", start_track, start_index, end_track, end_index, start_lba, end_lba);
m_cdda->start_audio(start_lba, end_lba - start_lba);
u8 status = m_status;
status |= STATUS_PLAYING;
status |= STATUS_MOTOR;
m_output_fifo[0] = 0x0f;
m_output_fifo[1] = status;
status_change(status);
status_enable(2);
}
// TODO: unverified in this implementation (sure needs data ready in Clio)
void cr560b_device::cmd_read()
{
LOGMASKED(LOG_CMD, "Command: Read\n");
LOGPARAM;
u8 read_mode = m_input_fifo[4];
if (read_mode & 0xfe)
throw emu_fatalerror("Unknown read mode %02x", read_mode);
// compared to CR-511 this is shuffled around to accomodate the transfer mode
u32 start_sector = (m_input_fifo[1] << 16) | (m_input_fifo[2] << 8) | (m_input_fifo[3] << 0);
if (read_mode == 0)
{
LOGMASKED(LOG_CMD, "MSF mode %06x ", start_sector);
start_sector = msf_to_lba(start_sector);
}
m_transfer_lba = start_sector;
m_transfer_sectors = (m_input_fifo[5] << 8) | (m_input_fifo[6] << 0);
m_transfer_length = m_transfer_sectors * m_sector_size;
LOGMASKED(LOG_CMD, "-> LBA %06x, sectors %d\n", m_transfer_lba, m_transfer_sectors);
m_cdda->stop_audio();
uint8_t status = m_status;
status &= ~STATUS_PLAYING;
status |= STATUS_MOTOR;
m_output_fifo[0] = 0x10;
m_output_fifo[1] = status;
status_change(status);
status_enable(2);
}
// checked in BIOS if a CD is inserted
void cr560b_device::cmd_data_path_check()
{
LOGMASKED(LOG_CMD, "Command: Data path check\n");
LOGPARAM;
m_output_fifo[0] = 0x80;
m_output_fifo[1] = 0xaa;
m_output_fifo[2] = 0x55;
m_output_fifo[3] = m_status;
status_enable(4);
}
// TODO: most unknowns, just checked by BIOS at startup
void cr560b_device::cmd_read_error()
{
LOGMASKED(LOG_CMD, "Command: Read error\n");
LOGPARAM;
uint8_t status = m_status;
//status |= STATUS_READY;
m_output_fifo[0] = 0x82;
m_output_fifo[1] = 0x00;
m_output_fifo[2] = 0x00;
m_output_fifo[3] = 0x00;
m_output_fifo[4] = 0x00;
m_output_fifo[5] = 0x00;
m_output_fifo[6] = 0x00;
m_output_fifo[7] = 0x00;
m_output_fifo[8] = 0x00;
// perhaps just the status byte?
m_output_fifo[9] = exists() ? 1 : 0;
status_change(status);
status_enable(10);
}
void cr560b_device::cmd_version()
{
LOGMASKED(LOG_CMD, "Command: Version\n");
LOGPARAM;
m_output_fifo[0] = 0x83;
m_output_fifo[1] = 0x00; // manufacturer ID
m_output_fifo[2] = 0x10; // ^
m_output_fifo[3] = 0x00; // manufacturer number
m_output_fifo[4] = 0x01; // ^
m_output_fifo[5] = 0x00;
m_output_fifo[6] = 0x00;
m_output_fifo[7] = 0x00; // revision number
m_output_fifo[8] = 0x00; // ^
m_output_fifo[9] = 0x00; // flag
m_output_fifo[10] = 0x00; // ^?
m_output_fifo[11] = m_status;
// status_change(status);
status_enable(12);
}
// same as cmd_read_session_info on regular single session disk
void cr560b_device::cmd_read_capacity()
{
LOGMASKED(LOG_CMD, "Command: Read Capacity\n");
LOGPARAM;
u8 status = m_status;
// TODO: unconfirmed here
//bool msf = bool(BIT(m_input_fifo[1], 1));
m_output_fifo[0] = 0x85;
if (exists())
{
uint32_t track_start = get_track_start(0xaa);
LOGMASKED(LOG_TOC, "Lead out start %06x\n", track_start);
//if (msf)
track_start = lba_to_msf(track_start);
LOGMASKED(LOG_TOC, "-> MSF %06x (%d)\n", track_start, track_start);
status |= STATUS_READY;
m_output_fifo[1] = 0;
m_output_fifo[2] = track_start >> 16;
m_output_fifo[3] = track_start >> 8;
m_output_fifo[4] = track_start >> 0;
m_output_fifo[5] = 0;
m_output_fifo[6] = 0;
m_output_fifo[7] = status;
status_enable(8);
}
else
{
status &= ~STATUS_READY;
status |= STATUS_ERROR;
m_output_fifo[1] = status;
}
status_change(status);
}
void cr560b_device::cmd_read_disc_info()
{
LOGMASKED(LOG_CMD, "Command: Read Disc Info\n");
LOGPARAM;
uint8_t status = m_status;
m_output_fifo[0] = 0x8b;
if (exists())
{
uint8_t last_track = get_last_track();
uint32_t last_lba = get_track_start(0xaa);
uint32_t last_msf = lba_to_msf(last_lba);
status |= STATUS_MOTOR | STATUS_SUCCESS;
status |= STATUS_READY;
LOGMASKED(LOG_TOC, "First track %d last track %d, lead out start %06x\n", 1, last_track, last_msf);
// TODO: determine disk type
// 0x00: DA or CD-Rom
// 0x10: CD-i
// 0x20: CD-Rom XA
m_output_fifo[1] = 0x00;
m_output_fifo[2] = 1; // first track
m_output_fifo[3] = last_track;
m_output_fifo[4] = last_msf >> 16;
m_output_fifo[5] = last_msf >> 8;
m_output_fifo[6] = last_msf >> 0;
m_output_fifo[7] = status;
status_change(status);
status_enable(8);
}
else
{
status &= ~STATUS_READY;
status |= STATUS_ERROR;
m_output_fifo[1] = status;
status_change(status);
status_enable(2);
}
}
// almost identical vs. CR-511B
void cr560b_device::cmd_read_toc()
{
LOGMASKED(LOG_CMD, "Command: Read TOC\n");
LOGPARAM;
// 01: bit 1 - msf or lba
// 02: track
// 03: unused?
// 04: unused?
// 05: unused?
// 06: unused?
// TODO: unconfirmed here
//bool msf = bool(BIT(m_input_fifo[1], 1));
uint8_t track = m_input_fifo[2];
uint8_t status = m_status;
status |= STATUS_MOTOR;
m_output_fifo[0] = 0x8c;
if (track > get_last_track() || !exists())
{
LOGMASKED(LOG_CMD, "Invalid track requested: %d\n", track);
status &= ~STATUS_READY;
status |= STATUS_ERROR;
m_output_fifo[1] = status;
status_enable(2);
}
else if (track == 0)
{
uint32_t track_start = get_track_start(0xaa);
LOGMASKED(LOG_TOC, "TOC: Track 0 requested, lead out start %06x\n", track_start);
//if (msf)
track_start = lba_to_msf(track_start);
LOGMASKED(LOG_TOC, "-> MSF %06x (%d)\n", track_start, track_start);
status |= STATUS_READY;
m_output_fifo[1] = 0;
m_output_fifo[2] = get_adr_control(0xaa);
m_output_fifo[3] = 1; // first track
m_output_fifo[4] = get_last_track();
m_output_fifo[5] = track_start >> 16;
m_output_fifo[6] = track_start >> 8;
m_output_fifo[7] = track_start >> 0;
m_output_fifo[8] = 0;
m_output_fifo[9] = status;
status_enable(10);
}
else
{
uint32_t track_start = get_track_start(track - 1);
LOGMASKED(LOG_TOC, "Track %d requested, start %06x\n", track, track_start);
status |= STATUS_READY;
//if (msf)
track_start = lba_to_msf(track_start);
const u8 adr = get_adr_control(track - 1);
LOGMASKED(LOG_TOC, "-> MSF %06x (%d) adr %02x\n", track_start, track_start, adr);
m_output_fifo[1] = 0;
m_output_fifo[2] = adr;
m_output_fifo[3] = track;
m_output_fifo[4] = 0;
m_output_fifo[5] = track_start >> 16;
m_output_fifo[6] = track_start >> 8;
m_output_fifo[7] = track_start >> 0;
m_output_fifo[8] = 0;
m_output_fifo[9] = status;
status_enable(10);
}
status_change(status);
}
// TODO: shouldn't matter for stock 3do games beyond reading lead-out but yes it's a thing
void cr560b_device::cmd_read_session_info()
{
LOGMASKED(LOG_CMD, "Command: Read Session Info\n");
LOGPARAM;
u8 status = m_status;
// TODO: unconfirmed here
//bool msf = bool(BIT(m_input_fifo[1], 1));
m_output_fifo[0] = 0x8d;
if (exists())
{
uint32_t track_start = get_track_start(0xaa);
LOGMASKED(LOG_TOC, "Session: Lead out start %06x\n", track_start);
//if (msf)
track_start = lba_to_msf(track_start);
LOGMASKED(LOG_TOC, "-> MSF %06x (%d)\n", track_start, track_start);
status |= STATUS_READY;
m_output_fifo[1] = 0;
m_output_fifo[2] = track_start >> 16;
m_output_fifo[3] = track_start >> 8;
m_output_fifo[4] = track_start >> 0;
m_output_fifo[5] = 0;
m_output_fifo[6] = 0;
m_output_fifo[7] = status;
status_enable(8);
}
else
{
status |= STATUS_ERROR;
m_output_fifo[1] = status;
}
status_change(status);
}
|