Disk.h

Go to the documentation of this file.
00001 /* ES40 emulator.
00002  * Copyright (C) 2007-2008 by the ES40 Emulator Project
00003  *
00004  * WWW    : http://sourceforge.net/projects/es40
00005  * E-mail : camiel@camicom.com
00006  * 
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  * 
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  * 
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00020  * 
00021  * Although this is not required, the author would appreciate being notified of, 
00022  * and receiving any modifications you may make to the source code that might serve
00023  * the general public.
00024  */
00025 
00079 #if !defined(__DISK_H__)
00080 #define __DISK_H__
00081 
00082 #include "DiskController.h"
00083 #include "SCSIDevice.h"
00084 #include "SCSIBus.h"
00085 
00086 #define DATO_BUFSZ  256 * 1024
00087 #define DATI_BUFSZ  256 * 1024
00088 
00092 class CDisk : public CSystemComponent, public CSCSIDevice
00093 {
00094   public:
00095     CDisk(CConfigurator*  cfg, CSystem*  sys, CDiskController*  c, int idebus,
00096           int idedev);
00097     virtual         ~CDisk(void);
00098     virtual int     SaveState(FILE* f);
00099     virtual int     RestoreState(FILE* f);
00100 
00101     virtual void    scsi_select_me(int bus);
00102     virtual size_t  scsi_expected_xfer_me(int bus);
00103     virtual void*   scsi_xfer_ptr_me(int bus, size_t bytes);
00104     virtual void    scsi_xfer_done_me(int bus);
00105 
00106     void            set_atapi_mode()  { atapi_mode = true; };
00107 
00108     int             do_scsi_command();
00109     int             do_scsi_message();
00110     void            do_scsi_error(int errcode);
00111 
00112     virtual bool    seek_byte(off_t_large byte) = 0;
00113     virtual size_t  read_bytes(void* dest, size_t bytes) = 0;
00114     virtual size_t  write_bytes(void* src, size_t bytes) = 0;
00115 
00116     bool seek_block(off_t_large lba)
00117     {
00118       return seek_byte(lba * state.block_size);
00119     };
00120     size_t read_blocks(void* dest, size_t blocks)
00121     {
00122       return read_bytes(dest, blocks * state.block_size) / state.block_size;
00123     };
00124     size_t write_blocks(void* src, size_t blocks)
00125     {
00126       return write_bytes(src, blocks * state.block_size) / state.block_size;
00127     };
00128 
00129     size_t  get_block_size()  { return state.block_size; };
00130     void set_block_size(size_t bs)
00131     {
00132       state.block_size = bs;
00133       determine_layout();           /*calc_cylinders();*/
00134     };
00135 
00136     void        determine_layout();
00137 
00138     off_t_large get_lba_size()  { return byte_size / state.block_size; };
00139     off_t_large get_byte_size() { return byte_size; };
00140     off_t_large get_chs_size()  { return cylinders * heads * sectors; };
00141     off_t_large get_cylinders() { return cylinders; };
00142     long        get_heads()     { return heads; };
00143     long        get_sectors()   { return sectors; };
00144 
00145     char*       get_serial()    { return serial_number; };
00146     char*       get_model()     { return model_number; };
00147     char*       get_rev()       { return revision_number; };
00148 
00149     bool        ro()            { return read_only; };
00150     bool        rw()            { return !read_only; };
00151     bool        cdrom()         { return is_cdrom; };
00152 
00153     void        calc_cylinders();
00154   protected:
00155     CConfigurator*    myCfg;
00156     CDiskController*  myCtrl;
00157     int               myBus;
00158     int               myDev;
00159 
00160     char*             serial_number;
00161     char*             model_number;
00162     char*             revision_number;
00163 
00164     bool              read_only;
00165     bool              is_cdrom;
00166 
00167     off_t_large       byte_size;
00168     off_t_large       cylinders;
00169     long              heads;
00170     long              sectors;
00171 
00172     bool              atapi_mode;
00173 
00175     struct SDisk_state
00176     {
00177       size_t      block_size;       
00178       off_t_large byte_pos;         
00180 
00181       struct SDisk_scsi
00182       {
00183 
00184         // State for Message In Phase (disk -> controller)
00185         struct SDisk_msgi
00186         {
00187           u8            data[256];  
00188           unsigned int  available;  
00189           unsigned int  read;       
00190         } msgi;
00191 
00193         struct SDisk_msgo
00194         {
00195           u8            data[256];  
00196           unsigned int  written;    
00197         } msgo;
00198 
00199         bool  lun_selected;         
00201 
00202         struct SDisk_cmd
00203         {
00204           u8            data[256];  
00205           unsigned int  written;    
00206         } cmd;
00207 
00209         struct SDisk_dati
00210         {
00211           u8            data[DATI_BUFSZ]; 
00212           unsigned int  available;        
00213           unsigned int  read; 
00214         } dati;
00215 
00217         struct SDisk_dato
00218         {
00219           u8            data[DATO_BUFSZ]; 
00220           unsigned int  expected;         
00221           unsigned int  written;          
00222         } dato;
00223 
00225         struct SDisk_stat
00226         {
00227           u8            data[256];        
00228           unsigned int  available;        
00229           unsigned int  read; 
00230         } stat;
00231 
00233         struct SDisk_sense
00234         {
00235           u8            data[256];
00236           unsigned int  available;
00237         } sense;
00238 
00239         bool  locked;         
00241         //bool disconnect_priv;       /**< Initiator has allowed us to disconnect/reconnect. **/
00242         //bool will_disconnect;       /**< We intend to disconnect. **/
00243         //bool disconnected;          /**< We have disconnected. **/
00244         //bool reselected;            /**< We have reselected the initiator. **/
00245         //int disconnect_phase;       /**< After we reconnect, we should go to this SCSI phase. **/
00246       } scsi;
00247     } state;
00248 };
00249 #endif 

SourceForge.net Logo
Project space on SourceForge.net