1 /////////////////////////////////////////////////////////////////////////
2 // $Id: floppy.h,v 1.31 2007/09/28 19:51:59 sshwarts Exp $
3 /////////////////////////////////////////////////////////////////////////
5 // Copyright (C) 2002 MandrakeSoft S.A.
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
34 # define BX_FD_SMF static
35 # define BX_FD_THIS theFloppyController->
38 # define BX_FD_THIS this->
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 */
48 unsigned write_protected
;
49 unsigned char raw_floppy_win95
;
51 unsigned char raw_floppy_win95_drv
;
55 class bx_floppy_ctrl_c
: public bx_floppy_stub_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);
70 Bit8u command
[10]; /* largest command size ??? */
73 bx_bool command_complete
;
74 Bit8u pending_command
;
80 Bit8u format_fillbyte
;
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
;
112 // drive field allows up to 4 drives, even though probably only 2 will
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
);
138 Bit32u
read(Bit32u address
, unsigned io_len
);
139 void write(Bit32u address
, Bit32u value
, unsigned io_len
);
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 *);
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
);
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
{
176 } DIOC_REGISTERS
, *PDIOC_REGISTERS
;
178 #pragma pack(push, 1)
179 typedef struct _BLOCK_DEV_PARAMS
{
186 WORD bytes_per_sector
;
187 BYTE sect_per_cluster
;
188 WORD reserved_sectors
;
194 WORD sects_per_track
;
198 } BLOCK_DEV_PARAMS
, *PBLOCK_DEV_PARAMS
;