OSDN Git Service

[VM] Add vm_template.h . This class, VM_TEMPLATE:: must be mother of VM:: .See fm7...
[csp-qt/common_source_project-fm7.git] / source / src / vm / scsi_cdrom.h
1 /*
2         Skelton for retropc emulator
3
4         Author : Takeda.Toshiya
5         Date   : 2016.03.06-
6
7         [ SCSI CD-ROM drive ]
8 */
9
10 #ifndef _SCSI_CDROM_H_
11 #define _SCSI_CDROM_H_
12
13 #include "scsi_dev.h"
14
15 #define SIG_SCSI_CDROM_PLAYING  0
16 #define SIG_SCSI_CDROM_SAMPLE_L 1
17 #define SIG_SCSI_CDROM_SAMPLE_R 2
18
19 class FILEIO;
20 //class csp_state_utils;
21
22 class SCSI_CDROM : public SCSI_DEV
23 {
24 private:
25         outputs_t outputs_done;
26         
27         FILEIO* fio_img;
28         struct {
29                 uint32_t index0, index1, pregap;
30                 bool is_audio;
31         } toc_table[1024];
32         int track_num;
33         uint32_t max_logical_block;
34         bool access;
35         
36         uint32_t cdda_start_frame, cdda_end_frame, cdda_playing_frame;
37         uint8_t cdda_status;
38         bool cdda_repeat, cdda_interrupt;
39         uint8_t cdda_buffer[2352 * 75];
40         int cdda_buffer_ptr;
41         int cdda_sample_l, cdda_sample_r;
42         int event_cdda, mix_loop_num;
43         
44         void set_cdda_status(uint8_t status);
45         int get_track(uint32_t lba);
46         double get_seek_time(uint32_t lba);
47         
48         int volume_m;
49         int volume_l, volume_r;
50
51 //protected:
52 //      csp_state_utils *state_entry;
53         
54 public:
55         SCSI_CDROM(VM_TEMPLATE* parent_vm, EMU* parent_emu) : SCSI_DEV(parent_vm, parent_emu) 
56         {
57                 initialize_output_signals(&outputs_done);
58                 
59                 volume_m = 1024;
60                 volume_l = volume_r = 1024;
61                 
62                 my_sprintf_s(vendor_id, 9, "NECITSU");
63                 my_sprintf_s(product_id, 17, "SCSI-CDROM");
64                 device_type = 0x05; // CD-ROM drive
65                 is_removable = true;
66 //              seek_time = 400000; // 400msec (temporary)
67                 seek_time = 10.0;
68                 bytes_per_sec = 2048 * 75; // speed x1
69                 max_logical_block = 0;
70                 access = false;
71
72                 set_device_name(_T("SCSI CDROM"));
73         }
74         ~SCSI_CDROM() {}
75         
76         // common functions
77         void initialize();
78         void release();
79         void reset();
80         uint32_t read_signal(int id);
81         void event_callback(int event_id, int err);
82         void mix(int32_t* buffer, int cnt);
83         void set_volume(int ch, int decibel_l, int decibel_r);
84         void decl_state();
85         void save_state(FILEIO* state_fio);
86         bool load_state(FILEIO* state_fio);
87         
88         // virtual scsi functions
89         void reset_device();
90         bool is_device_ready();
91         uint32_t physical_block_size()
92         {
93                 return 2352;
94         }
95         uint32_t logical_block_size()
96         {
97                 return 2048;
98         }
99         uint32_t max_logical_block_addr()
100         {
101                 if(max_logical_block > 0) {
102                         return max_logical_block - 1;
103                 }
104                 return 0;
105         }
106         int get_command_length(int value);
107         void start_command();
108         void read_buffer(int length);
109         
110         // unique functions
111         void set_context_done(DEVICE* device, int id, uint32_t mask)
112         {
113                 register_output_signal(&outputs_done, device, id, mask);
114         }
115         void open(const _TCHAR* file_path);
116         void close();
117         bool mounted();
118         bool accessed();
119         void set_volume(int volume);
120 };
121
122 #endif
123