Main Page | Class Hierarchy | Compound List | File List | Compound Members | File Members | Related Pages

IEC.h

Go to the documentation of this file.
00001 /*
00002  *  IEC.h - IEC bus routines, 1541 emulation (DOS level)
00003  *
00004  *  Frodo (C) 1994-1997 Christian Bauer
00005  */
00006 
00007 #ifndef _IEC_H
00008 #define _IEC_H
00009 
00010 
00011 // Maximum length of file names
00012 const int NAMEBUF_LENGTH = 256;
00013 
00014 
00015 // C64 status codes
00016 enum {
00017         ST_OK = 0,                              // No error
00018         ST_READ_TIMEOUT = 0x02, // Timeout on reading
00019         ST_TIMEOUT = 0x03,              // Timeout
00020         ST_EOF = 0x40,                  // End of file
00021         ST_NOTPRESENT = 0x80    // Device not present
00022 };
00023 
00024 
00025 // 1541 error codes
00026 enum {
00027         ERR_OK,                         // 00 OK
00028         ERR_WRITEERROR,         // 25 WRITE ERROR
00029         ERR_WRITEPROTECT,       // 26 WRITE PROTECT ON
00030         ERR_SYNTAX30,           // 30 SYNTAX ERROR (unknown command)
00031         ERR_SYNTAX33,           // 33 SYNTAX ERROR (wildcards on writing)
00032         ERR_WRITEFILEOPEN,      // 60 WRITE FILE OPEN
00033         ERR_FILENOTOPEN,        // 61 FILE NOT OPEN
00034         ERR_FILENOTFOUND,       // 62 FILE NOT FOUND
00035         ERR_ILLEGALTS,          // 67 ILLEGAL TRACK OR SECTOR
00036         ERR_NOCHANNEL,          // 70 NO CHANNEL
00037         ERR_STARTUP,            // 73 Power-up message
00038         ERR_NOTREADY            // 74 DRIVE NOT READY
00039 };
00040 
00041 
00042 // IEC command codes
00043 enum {
00044         CMD_DATA = 0x60,        // Data transfer
00045         CMD_CLOSE = 0xe0,       // Close channel
00046         CMD_OPEN = 0xf0         // Open channel
00047 };
00048 
00049 
00050 // IEC ATN codes
00051 enum {
00052         ATN_LISTEN = 0x20,
00053         ATN_UNLISTEN = 0x30,
00054         ATN_TALK = 0x40,
00055         ATN_UNTALK = 0x50
00056 };
00057 
00058 
00059 // Drive LED states
00060 enum {
00061         DRVLED_OFF,             // Inactive, LED off
00062         DRVLED_ON,              // Active, LED on
00063         DRVLED_ERROR    // Error, blink LED
00064 };
00065 
00066 
00067 class Drive;
00068 class C64Display;
00069 class Prefs;
00070 
00071 // Class for complete IEC bus system with drives 8..11
00072 class IEC {
00073 public:
00074         IEC(C64Display *display);
00075         ~IEC();
00076 
00077         void Reset(void);
00078         void NewPrefs(Prefs *prefs);
00079         void UpdateLEDs(void);
00080 
00081         uint8 Out(uint8 byte, bool eoi);
00082         uint8 OutATN(uint8 byte);
00083         uint8 OutSec(uint8 byte);
00084         uint8 In(uint8 *byte);
00085         void SetATN(void);
00086         void RelATN(void);
00087         void Turnaround(void);
00088         void Release(void);
00089 
00090 private:
00091         uint8 listen(int device);
00092         uint8 talk(int device);
00093         uint8 unlisten(void);
00094         uint8 untalk(void);
00095         uint8 sec_listen(void);
00096         uint8 sec_talk(void);
00097         uint8 open_out(uint8 byte, bool eoi);
00098         uint8 data_out(uint8 byte, bool eoi);
00099         uint8 data_in(uint8 *byte);
00100 
00101         C64Display *the_display;        // Pointer to display object (for drive LEDs)
00102 
00103         char name_buf[NAMEBUF_LENGTH];  // Buffer for file names and command strings
00104         char *name_ptr;                 // Pointer for reception of file name
00105         int name_len;                   // Received length of file name
00106 
00107         Drive *drive[4];                // 4 drives (8..11)
00108 
00109         Drive *listener;                // Pointer to active listener
00110         Drive *talker;                  // Pointer to active talker
00111 
00112         bool listener_active;   // Listener selected, listener_data is valid
00113         bool talker_active;             // Talker selected, talker_data is valid
00114         bool listening;                 // Last ATN was listen (to decide between sec_listen/sec_talk)
00115 
00116         uint8 received_cmd;             // Received command code ($x0)
00117         uint8 sec_addr;                 // Received secondary address ($0x)
00118         Prefs& ThePrefs;
00119 };
00120 
00121 
00122 // Abstract superclass for individual drives
00123 class Drive {
00124 public:
00125         Drive(IEC *iec);
00126         virtual ~Drive() {}
00127 
00128         virtual uint8 Open(int channel, char *filename)=0;
00129         virtual uint8 Close(int channel)=0;
00130         virtual uint8 Read(int channel, uint8 *byte)=0;
00131         virtual uint8 Write(int channel, uint8 byte, bool eoi)=0;
00132         virtual void Reset(void)=0;
00133 
00134         int LED;                        // Drive LED state
00135         bool Ready;                     // Drive is ready for operation
00136 
00137 protected:
00138         void set_error(int error);
00139 
00140         char *error_ptr;        // Pointer within error message 
00141         int error_len;          // Remaining length of error message
00142 
00143 private:
00144         IEC *the_iec;           // Pointer to IEC object
00145 };
00146 
00147 #endif

Generated on Tue Feb 8 04:07:56 2005 for E32frodo by doxygen 1.3.3