00001 // See the end of this file for license information. 00002 00003 #ifndef TORSION_FLOPPY_H 00004 #define TORSION_FLOPPY_H 00005 00006 #include "dma.h" 00007 #include "irq.h" 00008 #include "blockdev.h" 00009 00011 00015 class Floppy { 00016 protected: 00017 static const unsigned int BLOCK_SIZE = 512; 00018 DMA_buffer buffer; 00019 volatile unsigned int timeout_counter; 00020 bool motor_on; 00021 int motor_counter; 00022 bool disk_change; 00023 unsigned char status[7]; 00024 unsigned char status_size; 00025 unsigned char sr0; 00026 unsigned char current_track; 00027 00028 public: 00029 volatile bool operation_done; 00030 00032 void 00033 init(); 00034 00036 void 00037 update_timers(); 00038 00040 void 00041 deinit(); 00042 00044 void 00045 reset(); 00046 00048 void 00049 send_byte(unsigned short int byte); 00050 00052 short int 00053 get_byte(); 00054 00057 bool 00058 wait_for_op(bool sense_interrupt_status); 00059 00061 bool 00062 seek(unsigned char track); 00063 00065 void 00066 recalibrate(); 00067 00069 void 00070 turn_motor_on(); 00071 00073 void 00074 turn_motor_off(); 00075 00077 bool 00078 read_block(unsigned int block, void* data); 00079 00081 bool 00082 write_block(unsigned int block, void* data); 00083 00086 bool 00087 read_write(unsigned int block, void* data, bool read); 00088 00090 void 00091 implement(Block_device& disk); 00092 }; 00093 00094 inline void 00095 floppy_init(void* floppy) { 00096 ((Floppy*)floppy)->init(); 00097 } 00098 00099 inline void 00100 floppy_deinit(void* floppy) { 00101 ((Floppy*)floppy)->init(); 00102 } 00103 00104 inline bool 00105 floppy_read_block(void* floppy, unsigned int block, void* data) { 00106 return ((Floppy*)floppy)->read_block(block, data); 00107 } 00108 00109 inline bool 00110 floppy_write_block(void* floppy, unsigned int block, void* data) { 00111 return ((Floppy*)floppy)->write_block(block, data); 00112 } 00113 00114 extern Floppy floppy; 00115 00117 inline void 00118 floppy_interrupt_handler(volatile Handler_registers& registers); 00119 00121 inline void 00122 floppy_timer_handler(volatile Handler_registers& registers); 00123 00125 const unsigned int DG144_HEADS = 2; 00126 const unsigned int DG144_TRACKS = 80; 00127 const unsigned int DG144_SPT = 18; 00128 const unsigned int DG144_GAP3FMT = 0x54; 00129 const unsigned int DG144_GAP3RW = 0x1b; 00130 00131 const unsigned int DG168_HEADS = 2; 00132 const unsigned int DG168_TRACKS = 80; 00133 const unsigned int DG168_SPT = 21; 00134 const unsigned int DG168_GAP3FMT = 0x0c; 00135 const unsigned int DG168_GAP3RW = 0x1c; 00136 00138 const unsigned int FDC_DOR = 0x3f2; 00139 const unsigned int FDC_MSR = 0x3f4; 00140 const unsigned int FDC_DRS = 0x3f4; 00141 const unsigned int FDC_DATA = 0x3f5; 00142 const unsigned int FDC_DIR = 0x3f7; 00143 const unsigned int FDC_CCR = 0x3f7; 00144 00146 const unsigned int CMD_SPECIFY = 0x03; 00147 const unsigned int CMD_WRITE = 0xc5; 00148 const unsigned int CMD_READ = 0xe6; 00149 const unsigned int CMD_RECAL = 0x07; 00150 const unsigned int CMD_SENSEI = 0x08; 00151 const unsigned int CMD_FORMAT = 0x4d; 00152 const unsigned int CMD_SEEK = 0x0f; 00153 const unsigned int CMD_VERSION = 0x10; 00154 00155 #endif 00156 00157 /* Torsion Operating System, Copyright (C) 2000-2002 Dan Helfman 00158 * 00159 * This program is free software; you can redistribute it and/or modify it 00160 * under the terms of the GNU General Public License as published by the 00161 * Free Software Foundation; either version 2 of the License, or (at your 00162 * option) any later version. 00163 * 00164 * This program is distributed in the hope that it will be useful, but 00165 * WITHOUT ANY WARRANTY; without even the implied warranty of 00166 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00167 * General Public License for more details (in the COPYING file). 00168 * 00169 * You should have received a copy of the GNU General Public License along 00170 * with this program; if not, write to the Free Software Foundation, Inc., 00171 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00172 */
Torsion Operating System, Copyright (C) 2000-2002 Dan Helfman