OSDN Git Service

[VM][STATE] Apply new framework to some VMs.
[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 class DISK;
26 class NOISE;
27
28 class FLOPPY : public DEVICE
29 {
30 private:
31         DEVICE *d_ext;
32         NOISE *d_noise_seek;
33 //      NOISE* d_noise_head_down;
34 //      NOISE* d_noise_head_up;
35         unsigned char io_B1H;
36         
37         DISK* disk[2];
38         
39         int cur_trk[2];
40         int cur_sct[2];
41         int cur_pos[2];
42         bool access[2];
43         
44         int Seek88(int drvno, int trackno, int sectno);
45         unsigned char Getc88(int drvno);
46         int Putc88(int drvno, unsigned char dat);
47         
48         // data buffer (256BytesX4)
49         unsigned char Data[4][256];
50         int Index[4];
51         
52         typedef struct {
53                 unsigned char Data[10];
54                 int Index;
55         } CmdBuffer;
56         
57         CmdBuffer CmdIn;                                        // command buffer
58         CmdBuffer CmdOut;                               // status buffer
59         unsigned char SeekST0;                  // ST0 when SEEK
60         unsigned char LastCylinder;             // last read cylinder
61         int SeekEnd;                                            // complete seek flag
62         unsigned char SendSectors;              // amount(100H unit)
63         int DIO;                                                        // data direction TRUE: Buffer->CPU FALSE: CPU->Buffer
64         unsigned char Status;                   // FDC status register
65         
66         void Push(int part, unsigned char data);
67         unsigned char Pop(int part);
68         void Clear(int i);
69         
70         int DiskInit66(void);
71         void PushStatus(int data);
72         unsigned char PopStatus();
73         void OutFDC(unsigned char data);
74         unsigned char InFDC();
75         void Read();
76         void Write(void);
77         void Seek(void);
78         void SenseInterruptStatus(void);
79         void Exec();
80         
81         void OutB1H_66(unsigned char data);
82         void OutB2H_66(unsigned char data);
83         void OutB3H_66(unsigned char data);
84         void OutD0H_66(unsigned char data);
85         void OutD1H_66(unsigned char data);
86         void OutD2H_66(unsigned char data);
87         void OutD3H_66(unsigned char data);
88         void OutD6H_66(unsigned char data);
89         void OutD8H_66(unsigned char data);
90         void OutDAH_66(unsigned char data);
91         void OutDDH_66(unsigned char data);
92         void OutDEH_66(unsigned char data);
93         
94         unsigned char InB2H_66();
95         unsigned char InD0H_66();
96         unsigned char InD1H_66();
97         unsigned char InD2H_66();
98         unsigned char InD3H_66();
99         unsigned char InD4H_66();
100         unsigned char InDCH_66();
101         unsigned char InDDH_66();
102         
103 public:
104         FLOPPY(VM_TEMPLATE* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu)
105         {
106                 d_noise_seek = NULL;
107 //              d_noise_head_down = NULL;
108 //              d_noise_head_up = NULL;
109                 set_device_name(_T("Floppy Drive"));
110         }
111         ~FLOPPY() {}
112         
113         // common functions
114         void initialize();
115         void release();
116         void reset();
117         void write_io8(uint32_t addr, uint32_t data);
118         uint32_t read_io8(uint32_t addr);
119         uint32_t read_signal(int ch);
120         void update_config();
121         bool process_state(FILEIO* state_fio, bool loading);
122         
123         // unique functions
124         void set_context_ext(DEVICE* device)
125         {
126                 d_ext = device;
127         }
128         void set_context_noise_seek(NOISE* device)
129         {
130                 d_noise_seek = device;
131         }
132         NOISE* get_context_noise_seek()
133         {
134                 return d_noise_seek;
135         }
136 //      void set_context_noise_head_down(NOISE* device)
137 //      {
138 //              d_noise_head_down = device;
139 //      }
140 //      NOISE* get_context_noise_head_down()
141 //      {
142 //              return d_noise_head_down;
143 //      }
144 //      void set_context_noise_head_up(NOISE* device)
145 //      {
146 //              d_noise_head_up = device;
147 //      }
148 //      NOISE* get_context_noise_head_up()
149 //      {
150 //              return d_noise_head_up;
151 //      }
152         DISK* get_disk_handler(int drv)
153         {
154                 return disk[drv];
155         }
156         void open_disk(int drv, const _TCHAR* file_path, int bank);
157         void close_disk(int drv);
158         bool is_disk_inserted(int drv);
159         void is_disk_protected(int drv, bool value);
160         bool is_disk_protected(int drv);
161 };
162
163 #endif
164