- NMAKE (MSVC toolkit 2003) doesn't like structure type and member having the
[bochs-mirror.git] / iodev / floppy.h
blob3528c819c8a1b5c926fab61cb7459b2bde7aa6cf
1 /////////////////////////////////////////////////////////////////////////
2 // $Id: floppy.h,v 1.31 2007/09/28 19:51:59 sshwarts Exp $
3 /////////////////////////////////////////////////////////////////////////
4 //
5 // Copyright (C) 2002 MandrakeSoft S.A.
6 //
7 // MandrakeSoft S.A.
8 // 43, rue d'Aboukir
9 // 75002 Paris - France
10 // http://www.linux-mandrake.com/
11 // http://www.mandrakesoft.com/
13 // This library is free software; you can redistribute it and/or
14 // modify it under the terms of the GNU Lesser General Public
15 // License as published by the Free Software Foundation; either
16 // version 2 of the License, or (at your option) any later version.
18 // This library is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 // Lesser General Public License for more details.
23 // You should have received a copy of the GNU Lesser General Public
24 // License along with this library; if not, write to the Free Software
25 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #ifndef BX_IODEV_FLOPPY_H
28 #define BX_IODEV_FLOPPY_H
30 #define FROM_FLOPPY 10
31 #define TO_FLOPPY 11
33 #if BX_USE_FD_SMF
34 # define BX_FD_SMF static
35 # define BX_FD_THIS theFloppyController->
36 #else
37 # define BX_FD_SMF
38 # define BX_FD_THIS this->
39 #endif
41 typedef struct {
42 int fd; /* file descriptor of floppy image file */
43 unsigned sectors_per_track; /* number of sectors/track */
44 unsigned sectors; /* number of formatted sectors on diskette */
45 unsigned tracks; /* number of tracks */
46 unsigned heads; /* number of heads */
47 unsigned type;
48 unsigned write_protected;
49 unsigned char raw_floppy_win95;
50 #ifdef WIN32
51 unsigned char raw_floppy_win95_drv;
52 #endif
53 } floppy_t;
55 class bx_floppy_ctrl_c : public bx_floppy_stub_c {
56 public:
57 bx_floppy_ctrl_c();
58 virtual ~bx_floppy_ctrl_c();
59 virtual void init(void);
60 virtual void reset(unsigned type);
61 virtual unsigned set_media_status(unsigned drive, unsigned status);
62 virtual unsigned get_media_status(unsigned drive);
63 virtual void register_state(void);
65 private:
67 struct {
68 Bit8u data_rate;
70 Bit8u command[10]; /* largest command size ??? */
71 Bit8u command_index;
72 Bit8u command_size;
73 bx_bool command_complete;
74 Bit8u pending_command;
76 bx_bool multi_track;
77 bx_bool pending_irq;
78 Bit8u reset_sensei;
79 Bit8u format_count;
80 Bit8u format_fillbyte;
82 Bit8u result[10];
83 Bit8u result_index;
84 Bit8u result_size;
86 Bit8u DOR; // Digital Ouput Register
87 Bit8u TDR; // Tape Drive Register
88 Bit8u cylinder[4]; // really only using 2 drives
89 Bit8u head[4]; // really only using 2 drives
90 Bit8u sector[4]; // really only using 2 drives
91 Bit8u eot[4]; // really only using 2 drives
92 bx_bool TC; // Terminal Count status from DMA controller
94 /* MAIN STATUS REGISTER
95 * b7: MRQ: main request 1=data register ready 0=data register not ready
96 * b6: DIO: data input/output:
97 * 1=controller->CPU (ready for data read)
98 * 0=CPU->controller (ready for data write)
99 * b5: NDMA: non-DMA mode: 1=controller not in DMA modes
100 * 0=controller in DMA mode
101 * b4: BUSY: instruction(device busy) 1=active 0=not active
102 * b3-0: ACTD, ACTC, ACTB, ACTA:
103 * drive D,C,B,A in positioning mode 1=active 0=not active
105 Bit8u main_status_reg;
107 Bit8u status_reg0;
108 Bit8u status_reg1;
109 Bit8u status_reg2;
110 Bit8u status_reg3;
112 // drive field allows up to 4 drives, even though probably only 2 will
113 // ever be used.
114 floppy_t media[4];
115 unsigned num_supported_floppies;
116 Bit8u floppy_buffer[512+2]; // 2 extra for good measure
117 unsigned floppy_buffer_index;
118 int floppy_timer_index;
119 bx_bool media_present[4];
120 Bit8u device_type[4];
121 Bit8u DIR[4]; // Digital Input Register:
122 // b7: 0=diskette is present and has not been changed
123 // 1=diskette missing or changed
124 bx_bool lock; // FDC lock status
125 Bit8u SRT; // step rate time
126 Bit8u HUT; // head unload time
127 Bit8u HLT; // head load time
128 Bit8u config; // configure byte #1
129 Bit8u pretrk; // precompensation track
130 Bit8u perp_mode; // perpendicular mode
132 int statusbar_id[2]; // IDs of the status LEDs
133 } s; // state information
135 static Bit32u read_handler(void *this_ptr, Bit32u address, unsigned io_len);
136 static void write_handler(void *this_ptr, Bit32u address, Bit32u value, unsigned io_len);
137 #if !BX_USE_FD_SMF
138 Bit32u read(Bit32u address, unsigned io_len);
139 void write(Bit32u address, Bit32u value, unsigned io_len);
140 #endif
141 BX_FD_SMF void dma_write(Bit8u *data_byte);
142 BX_FD_SMF void dma_read(Bit8u *data_byte);
143 BX_FD_SMF void floppy_command(void);
144 BX_FD_SMF void floppy_xfer(Bit8u drive, Bit32u offset, Bit8u *buffer, Bit32u bytes, Bit8u direction);
145 BX_FD_SMF void raise_interrupt(void);
146 BX_FD_SMF void lower_interrupt(void);
147 BX_FD_SMF void enter_idle_phase(void);
148 BX_FD_SMF void enter_result_phase(void);
149 BX_FD_SMF Bit32u calculate_step_delay(Bit8u drive, Bit8u new_cylinder);
150 BX_FD_SMF void reset_changeline(void);
151 BX_FD_SMF bx_bool get_tc(void);
152 static void timer_handler(void *);
154 public:
155 BX_FD_SMF void timer(void);
156 BX_FD_SMF void increment_sector(void);
157 BX_FD_SMF bx_bool evaluate_media(Bit8u devtype, Bit8u type, char *path, floppy_t *floppy);
161 #ifdef WIN32
163 // used for direct floppy access in Win95
164 #define VWIN32_DIOC_DOS_IOCTL 1
165 #define VWIN32_DIOC_DOS_INT25 2
166 #define VWIN32_DIOC_DOS_INT26 3
168 typedef struct _DIOC_REGISTERS {
169 DWORD reg_EBX;
170 DWORD reg_EDX;
171 DWORD reg_ECX;
172 DWORD reg_EAX;
173 DWORD reg_EDI;
174 DWORD reg_ESI;
175 DWORD reg_Flags;
176 } DIOC_REGISTERS, *PDIOC_REGISTERS;
178 #pragma pack(push, 1)
179 typedef struct _BLOCK_DEV_PARAMS {
180 BYTE features;
181 BYTE dev_type;
182 WORD attribs;
183 WORD cylinders;
184 BYTE media_type;
185 // BPB
186 WORD bytes_per_sector;
187 BYTE sect_per_cluster;
188 WORD reserved_sectors;
189 BYTE fats;
190 WORD root_entries;
191 WORD tot_sectors;
192 BYTE media_id;
193 WORD sects_per_fat;
194 WORD sects_per_track;
195 WORD num_heads;
196 WORD hidden_sectors;
197 BYTE remainder[5];
198 } BLOCK_DEV_PARAMS, *PBLOCK_DEV_PARAMS;
199 #pragma pack(pop)
201 #endif /* WIN32 */
203 #endif