1 |
/* |
2 |
* IEC.h - IEC bus routines, 1541 emulation (DOS level) |
3 |
* |
4 |
* Frodo (C) 1994-1997,2002 Christian Bauer |
5 |
* |
6 |
* This program is free software; you can redistribute it and/or modify |
7 |
* it under the terms of the GNU General Public License as published by |
8 |
* the Free Software Foundation; either version 2 of the License, or |
9 |
* (at your option) any later version. |
10 |
* |
11 |
* This program is distributed in the hope that it will be useful, |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
* GNU General Public License for more details. |
15 |
* |
16 |
* You should have received a copy of the GNU General Public License |
17 |
* along with this program; if not, write to the Free Software |
18 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 |
*/ |
20 |
|
21 |
#ifndef _IEC_H |
22 |
#define _IEC_H |
23 |
|
24 |
|
25 |
// Maximum length of file names |
26 |
const int NAMEBUF_LENGTH = 256; |
27 |
|
28 |
|
29 |
// C64 status codes |
30 |
enum { |
31 |
ST_OK = 0, // No error |
32 |
ST_READ_TIMEOUT = 0x02, // Timeout on reading |
33 |
ST_TIMEOUT = 0x03, // Timeout |
34 |
ST_EOF = 0x40, // End of file |
35 |
ST_NOTPRESENT = 0x80 // Device not present |
36 |
}; |
37 |
|
38 |
|
39 |
// 1541 error codes |
40 |
enum { |
41 |
ERR_OK, // 00 OK |
42 |
ERR_WRITEERROR, // 25 WRITE ERROR |
43 |
ERR_WRITEPROTECT, // 26 WRITE PROTECT ON |
44 |
ERR_SYNTAX30, // 30 SYNTAX ERROR (unknown command) |
45 |
ERR_SYNTAX33, // 33 SYNTAX ERROR (wildcards on writing) |
46 |
ERR_WRITEFILEOPEN, // 60 WRITE FILE OPEN |
47 |
ERR_FILENOTOPEN, // 61 FILE NOT OPEN |
48 |
ERR_FILENOTFOUND, // 62 FILE NOT FOUND |
49 |
ERR_ILLEGALTS, // 67 ILLEGAL TRACK OR SECTOR |
50 |
ERR_NOCHANNEL, // 70 NO CHANNEL |
51 |
ERR_STARTUP, // 73 Power-up message |
52 |
ERR_NOTREADY // 74 DRIVE NOT READY |
53 |
}; |
54 |
|
55 |
|
56 |
// IEC command codes |
57 |
enum { |
58 |
CMD_DATA = 0x60, // Data transfer |
59 |
CMD_CLOSE = 0xe0, // Close channel |
60 |
CMD_OPEN = 0xf0 // Open channel |
61 |
}; |
62 |
|
63 |
|
64 |
// IEC ATN codes |
65 |
enum { |
66 |
ATN_LISTEN = 0x20, |
67 |
ATN_UNLISTEN = 0x30, |
68 |
ATN_TALK = 0x40, |
69 |
ATN_UNTALK = 0x50 |
70 |
}; |
71 |
|
72 |
|
73 |
// Drive LED states |
74 |
enum { |
75 |
DRVLED_OFF, // Inactive, LED off |
76 |
DRVLED_ON, // Active, LED on |
77 |
DRVLED_ERROR // Error, blink LED |
78 |
}; |
79 |
|
80 |
|
81 |
class Drive; |
82 |
class C64Display; |
83 |
class Prefs; |
84 |
|
85 |
// Class for complete IEC bus system with drives 8..11 |
86 |
class IEC { |
87 |
public: |
88 |
IEC(C64Display *display); |
89 |
~IEC(); |
90 |
|
91 |
void Reset(void); |
92 |
void NewPrefs(Prefs *prefs); |
93 |
void UpdateLEDs(void); |
94 |
|
95 |
uint8 Out(uint8 byte, bool eoi); |
96 |
uint8 OutATN(uint8 byte); |
97 |
uint8 OutSec(uint8 byte); |
98 |
uint8 In(uint8 *byte); |
99 |
void SetATN(void); |
100 |
void RelATN(void); |
101 |
void Turnaround(void); |
102 |
void Release(void); |
103 |
|
104 |
private: |
105 |
uint8 listen(int device); |
106 |
uint8 talk(int device); |
107 |
uint8 unlisten(void); |
108 |
uint8 untalk(void); |
109 |
uint8 sec_listen(void); |
110 |
uint8 sec_talk(void); |
111 |
uint8 open_out(uint8 byte, bool eoi); |
112 |
uint8 data_out(uint8 byte, bool eoi); |
113 |
uint8 data_in(uint8 *byte); |
114 |
|
115 |
C64Display *the_display; // Pointer to display object (for drive LEDs) |
116 |
|
117 |
char name_buf[NAMEBUF_LENGTH]; // Buffer for file names and command strings |
118 |
char *name_ptr; // Pointer for reception of file name |
119 |
int name_len; // Received length of file name |
120 |
|
121 |
Drive *drive[4]; // 4 drives (8..11) |
122 |
|
123 |
Drive *listener; // Pointer to active listener |
124 |
Drive *talker; // Pointer to active talker |
125 |
|
126 |
bool listener_active; // Listener selected, listener_data is valid |
127 |
bool talker_active; // Talker selected, talker_data is valid |
128 |
bool listening; // Last ATN was listen (to decide between sec_listen/sec_talk) |
129 |
|
130 |
uint8 received_cmd; // Received command code ($x0) |
131 |
uint8 sec_addr; // Received secondary address ($0x) |
132 |
}; |
133 |
|
134 |
|
135 |
// Abstract superclass for individual drives |
136 |
class Drive { |
137 |
public: |
138 |
Drive(IEC *iec); |
139 |
virtual ~Drive() {} |
140 |
|
141 |
virtual uint8 Open(int channel, char *filename)=0; |
142 |
virtual uint8 Close(int channel)=0; |
143 |
virtual uint8 Read(int channel, uint8 *byte)=0; |
144 |
virtual uint8 Write(int channel, uint8 byte, bool eoi)=0; |
145 |
virtual void Reset(void)=0; |
146 |
|
147 |
int LED; // Drive LED state |
148 |
bool Ready; // Drive is ready for operation |
149 |
|
150 |
protected: |
151 |
void set_error(int error); |
152 |
|
153 |
char *error_ptr; // Pointer within error message |
154 |
int error_len; // Remaining length of error message |
155 |
|
156 |
private: |
157 |
IEC *the_iec; // Pointer to IEC object |
158 |
}; |
159 |
|
160 |
#endif |