OSDN Git Service

a7696419ff8ab75128028ebb11e42f644b79734a
[csp-qt/common_source_project-fm7.git] / source / src / vm / pc6001 / floppy.h
1 //
2 // PC-6001/6601 disk I/O
3 // This file is based on a disk I/O program in C++
4 // by Mr. Yumitaro and translated into C for Cocoa iP6
5 // by Koichi NISHIDA 2006
6 //
7
8 /*
9         NEC PC-6601 Emulator 'yaPC-6601'
10         NEC PC-6601SR Emulator 'yaPC-6801'
11
12         Author : tanam
13         Date   : 2013.07.15-
14
15         [ internal floppy drive ]
16 */
17
18 #ifndef _FLOPPY_H_
19 #define _FLOPPY_H_
20
21 #include "../vm.h"
22 #include "../../emu.h"
23 #include "../device.h"
24
25 #if defined(USE_SOUND_FILES)
26 #define FLOPPY_SND_TBL_MAX 256
27 #ifndef SIG_SOUNDER_MUTE
28 #define SIG_SOUNDER_MUTE        (65536 + 0)
29 #endif
30 #ifndef SIG_SOUNDER_RELOAD
31 #define SIG_SOUNDER_RELOAD      (65536 + 32)
32 #endif
33 #ifndef SIG_SOUNDER_ADD
34 #define SIG_SOUNDER_ADD         (65536 + 64)
35 #endif
36
37 #define FLOPPY_SND_TYPE_SEEK 0
38 #define FLOPPY_SND_TYPE_HEAD 1
39 #endif
40 class DISK;
41 class FLOPPY : public DEVICE
42 {
43 private:
44         DEVICE *d_ext;
45         unsigned char io_B1H;
46         
47         DISK* disk[2];
48         int cur_trk[2];
49         int cur_sct[2];
50         int cur_pos[2];
51         bool access[2];
52         
53         int Seek88(int drvno, int trackno, int sectno);
54         unsigned char Getc88(int drvno);
55         int Putc88(int drvno, unsigned char dat);
56         
57         // data buffer (256BytesX4)
58         unsigned char Data[4][256];
59         int Index[4];
60         
61         typedef struct {
62                 unsigned char Data[10];
63                 int Index;
64         } CmdBuffer;
65         
66         CmdBuffer CmdIn;                                        // command buffer
67         CmdBuffer CmdOut;                               // status buffer
68         unsigned char SeekST0;                  // ST0 when SEEK
69         unsigned char LastCylinder;             // last read cylinder
70         int SeekEnd;                                            // complete seek flag
71         unsigned char SendSectors;              // amount(100H unit)
72         int DIO;                                                        // data direction TRUE: Buffer->CPU FALSE: CPU->Buffer
73         unsigned char Status;                   // FDC status register
74 #if defined(USE_SOUND_FILES)
75         int seek_track_num[2];
76         int seek_event_id[2];
77 #endif
78         void Push(int part, unsigned char data);
79         unsigned char Pop(int part);
80         void Clear(int i);
81         
82         int DiskInit66(void);
83         void PushStatus(int data);
84         unsigned char PopStatus();
85         void OutFDC(unsigned char data);
86         unsigned char InFDC();
87         void Read();
88         void Write(void);
89         void Seek(void);
90         void SenseInterruptStatus(void);
91         void Exec();
92         
93         void OutB1H_66(unsigned char data);
94         void OutB2H_66(unsigned char data);
95         void OutB3H_66(unsigned char data);
96         void OutD0H_66(unsigned char data);
97         void OutD1H_66(unsigned char data);
98         void OutD2H_66(unsigned char data);
99         void OutD3H_66(unsigned char data);
100         void OutD6H_66(unsigned char data);
101         void OutD8H_66(unsigned char data);
102         void OutDAH_66(unsigned char data);
103         void OutDDH_66(unsigned char data);
104         void OutDEH_66(unsigned char data);
105         
106         unsigned char InB2H_66();
107         unsigned char InD0H_66();
108         unsigned char InD1H_66();
109         unsigned char InD2H_66();
110         unsigned char InD3H_66();
111         unsigned char InD4H_66();
112         unsigned char InDCH_66();
113         unsigned char InDDH_66();
114         
115 #if defined(USE_SOUND_FILES)
116 protected:
117         _TCHAR snd_seek_name[512];
118         _TCHAR snd_head_name[512];
119         int snd_seek_mix_tbl[FLOPPY_SND_TBL_MAX];
120         int snd_head_mix_tbl[FLOPPY_SND_TBL_MAX];
121         int16_t *snd_seek_data; // Read only
122         int16_t *snd_head_data; // Read only
123         int snd_seek_samples_size;
124         int snd_head_samples_size;
125         bool snd_mute;
126         int snd_level_l, snd_level_r;
127         virtual void mix_main(int32_t *dst, int count, int16_t *src, int *table, int samples);
128         void add_sound(int type);
129 #endif
130 public:
131         FLOPPY(VM* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu)
132         {
133 #if defined(USE_SOUND_FILES)
134                 seek_track_num[0] = seek_track_num[1] = 0;
135                 cur_trk[0] = cur_trk[1] = 0;
136                 seek_event_id[0] = seek_event_id[1] = -1;
137                 for(int i = 0; i < FLOPPY_SND_TBL_MAX; i++) {
138                         snd_seek_mix_tbl[i] = -1;
139                         snd_head_mix_tbl[i] = -1;
140                 }
141                 snd_seek_data = snd_head_data = NULL;
142                 snd_seek_samples_size = snd_head_samples_size = 0;
143                 snd_mute = false;
144                 snd_level_l = snd_level_r = decibel_to_volume(0);
145                 memset(snd_seek_name, 0x00, sizeof(snd_seek_name));
146                 memset(snd_head_name, 0x00, sizeof(snd_head_name));
147 #endif
148                 set_device_name(_T("Floppy Drive"));
149         }
150         ~FLOPPY() {}
151         
152         // common functions
153         void initialize();
154         void release();
155         void reset();
156         void event_callback(int event_id, int err);
157         void write_io8(uint32_t addr, uint32_t data);
158         uint32_t read_io8(uint32_t addr);
159         uint32_t read_signal(int ch);
160         void save_state(FILEIO* state_fio);
161         bool load_state(FILEIO* state_fio);
162         
163         // unique functions
164         void set_context_ext(DEVICE* device)
165         {
166                 d_ext = device;
167         }
168         DISK* get_disk_handler(int drv)
169         {
170                 return disk[drv];
171         }
172 #if defined(USE_SOUND_FILES)
173         // Around SOUND. 20161004 K.O
174         bool load_sound_data(int type, const _TCHAR *pathname);
175         void release_sound_data(int type);
176         bool reload_sound_data(int type);
177         
178         void mix(int32_t *buffer, int cnt);
179         void set_volume(int ch, int decibel_l, int decibel_r);
180 #endif
181         void open_disk(int drv, const _TCHAR* file_path, int bank);
182         void close_disk(int drv);
183         bool is_disk_inserted(int drv);
184         void is_disk_protected(int drv, bool value);
185         bool is_disk_protected(int drv);
186 };
187
188 #endif
189