OSDN Git Service

[VM][STATE] Apply new framework to some VMs.
[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                 is_hot_swappable = false;
67 //              seek_time = 400000; // 400msec (temporary)
68                 seek_time = 10.0;
69                 bytes_per_sec = 2048 * 75; // speed x1
70                 max_logical_block = 0;
71                 access = false;
72
73                 set_device_name(_T("SCSI CDROM"));
74         }
75         ~SCSI_CDROM() {}
76         
77         // common functions
78         void initialize();
79         void release();
80         void reset();
81         uint32_t read_signal(int id);
82         void event_callback(int event_id, int err);
83         void mix(int32_t* buffer, int cnt);
84         void set_volume(int ch, int decibel_l, int decibel_r);
85         bool process_state(FILEIO* state_fio, bool loading);
86         
87         // virtual scsi functions
88         void reset_device();
89         bool is_device_ready();
90         uint32_t physical_block_size()
91         {
92                 return 2352;
93         }
94         uint32_t logical_block_size()
95         {
96                 return 2048;
97         }
98         uint32_t max_logical_block_addr()
99         {
100                 if(max_logical_block > 0) {
101                         return max_logical_block - 1;
102                 }
103                 return 0;
104         }
105         int get_command_length(int value);
106         void start_command();
107         bool read_buffer(int length);
108         
109         // unique functions
110         void set_context_done(DEVICE* device, int id, uint32_t mask)
111         {
112                 register_output_signal(&outputs_done, device, id, mask);
113         }
114         void open(const _TCHAR* file_path);
115         void close();
116         bool mounted();
117         bool accessed();
118         void set_volume(int volume);
119 };
120
121 #endif
122