ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/Frodo4/Src/IEC.h
Revision: 1.3
Committed: 2004-01-11T00:09:51Z (20 years, 2 months ago) by cebix
Content type: text/plain
Branch: MAIN
Changes since 1.2: +88 -10 lines
Log Message:
some cleanups and refactoring

File Contents

# Content
1 /*
2 * IEC.h - IEC bus routines, 1541 emulation (DOS level)
3 *
4 * Frodo (C) 1994-1997,2002-2003 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_SCRATCHED, // 01 FILES SCRATCHED
43 ERR_UNIMPLEMENTED, // 03 UNIMPLEMENTED
44 ERR_READ20, // 20 READ ERROR (block header not found)
45 ERR_READ21, // 21 READ ERROR (no sync character)
46 ERR_READ22, // 22 READ ERROR (data block not present)
47 ERR_READ23, // 23 READ ERROR (checksum error in data block)
48 ERR_READ24, // 24 READ ERROR (byte decoding error)
49 ERR_WRITE25, // 25 WRITE ERROR (write-verify error)
50 ERR_WRITEPROTECT, // 26 WRITE PROTECT ON
51 ERR_READ27, // 27 READ ERROR (checksum error in header)
52 ERR_WRITE28, // 28 WRITE ERROR (long data block)
53 ERR_DISKID, // 29 DISK ID MISMATCH
54 ERR_SYNTAX30, // 30 SYNTAX ERROR (general syntax)
55 ERR_SYNTAX31, // 31 SYNTAX ERROR (invalid command)
56 ERR_SYNTAX32, // 32 SYNTAX ERROR (command too long)
57 ERR_SYNTAX33, // 33 SYNTAX ERROR (wildcards on writing)
58 ERR_SYNTAX34, // 34 SYNTAX ERROR (missing file name)
59 ERR_WRITEFILEOPEN, // 60 WRITE FILE OPEN
60 ERR_FILENOTOPEN, // 61 FILE NOT OPEN
61 ERR_FILENOTFOUND, // 62 FILE NOT FOUND
62 ERR_FILEEXISTS, // 63 FILE EXISTS
63 ERR_FILETYPE, // 64 FILE TYPE MISMATCH
64 ERR_NOBLOCK, // 65 NO BLOCK
65 ERR_ILLEGALTS, // 66 ILLEGAL TRACK OR SECTOR
66 ERR_NOCHANNEL, // 70 NO CHANNEL
67 ERR_DIRERROR, // 71 DIR ERROR
68 ERR_DISKFULL, // 72 DISK FULL
69 ERR_STARTUP, // 73 Power-up message
70 ERR_NOTREADY // 74 DRIVE NOT READY
71 };
72
73
74 // 1541 file types
75 enum {
76 FTYPE_DEL, // Deleted
77 FTYPE_SEQ, // Sequential
78 FTYPE_PRG, // Program
79 FTYPE_USR, // User
80 FTYPE_REL, // Relative
81 FTYPE_UNKNOWN
82 };
83
84 static const char ftype_char[9] = "DSPUL ";
85
86
87 // 1541 file access modes
88 enum {
89 FMODE_READ, // Read
90 FMODE_WRITE, // Write
91 FMODE_APPEND, // Append
92 FMODE_M // Read open file
93 };
94
95
96 // IEC command codes
97 enum {
98 CMD_DATA = 0x60, // Data transfer
99 CMD_CLOSE = 0xe0, // Close channel
100 CMD_OPEN = 0xf0 // Open channel
101 };
102
103
104 // IEC ATN codes
105 enum {
106 ATN_LISTEN = 0x20,
107 ATN_UNLISTEN = 0x30,
108 ATN_TALK = 0x40,
109 ATN_UNTALK = 0x50
110 };
111
112
113 // Drive LED states
114 enum {
115 DRVLED_OFF, // Inactive, LED off
116 DRVLED_ON, // Active, LED on
117 DRVLED_ERROR // Error, blink LED
118 };
119
120
121 class Drive;
122 class C64Display;
123 class Prefs;
124
125 // Class for complete IEC bus system with drives 8..11
126 class IEC {
127 public:
128 IEC(C64Display *display);
129 ~IEC();
130
131 void Reset(void);
132 void NewPrefs(Prefs *prefs);
133 void UpdateLEDs(void);
134
135 uint8 Out(uint8 byte, bool eoi);
136 uint8 OutATN(uint8 byte);
137 uint8 OutSec(uint8 byte);
138 uint8 In(uint8 *byte);
139 void SetATN(void);
140 void RelATN(void);
141 void Turnaround(void);
142 void Release(void);
143
144 private:
145 uint8 listen(int device);
146 uint8 talk(int device);
147 uint8 unlisten(void);
148 uint8 untalk(void);
149 uint8 sec_listen(void);
150 uint8 sec_talk(void);
151 uint8 open_out(uint8 byte, bool eoi);
152 uint8 data_out(uint8 byte, bool eoi);
153 uint8 data_in(uint8 *byte);
154
155 C64Display *the_display; // Pointer to display object (for drive LEDs)
156
157 uint8 name_buf[NAMEBUF_LENGTH]; // Buffer for file names and command strings
158 uint8 *name_ptr; // Pointer for reception of file name
159 int name_len; // Received length of file name
160
161 Drive *drive[4]; // 4 drives (8..11)
162
163 Drive *listener; // Pointer to active listener
164 Drive *talker; // Pointer to active talker
165
166 bool listener_active; // Listener selected, listener_data is valid
167 bool talker_active; // Talker selected, talker_data is valid
168 bool listening; // Last ATN was listen (to decide between sec_listen/sec_talk)
169
170 uint8 received_cmd; // Received command code ($x0)
171 uint8 sec_addr; // Received secondary address ($0x)
172 };
173
174
175 // Abstract superclass for individual drives
176 class Drive {
177 public:
178 Drive(IEC *iec);
179 virtual ~Drive() {}
180
181 virtual uint8 Open(int channel, const uint8 *name, int name_len)=0;
182 virtual uint8 Close(int channel)=0;
183 virtual uint8 Read(int channel, uint8 *byte)=0;
184 virtual uint8 Write(int channel, uint8 byte, bool eoi)=0;
185 virtual void Reset(void)=0;
186
187 int LED; // Drive LED state
188 bool Ready; // Drive is ready for operation
189
190 protected:
191 void set_error(int error, int track = 0, int sector = 0);
192
193 void parse_file_name(const uint8 *src, int src_len, uint8 *dest, int &dest_len, int &mode, int &type, int &rec_len, bool convert_charset = false);
194
195 void execute_cmd(const uint8 *cmd, int cmd_len);
196 virtual void block_read_cmd(int channel, int track, int sector, bool user_cmd = false);
197 virtual void block_write_cmd(int channel, int track, int sector, bool user_cmd = false);
198 virtual void block_execute_cmd(int channel, int track, int sector);
199 virtual void block_allocate_cmd(int track, int sector);
200 virtual void block_free_cmd(int track, int sector);
201 virtual void buffer_pointer_cmd(int channel, int pos);
202 virtual void mem_read_cmd(uint16 adr, uint8 len);
203 virtual void mem_write_cmd(uint16 adr, uint8 len, uint8 *p);
204 virtual void mem_execute_cmd(uint16 adr);
205 virtual void copy_cmd(const uint8 *new_file, int new_file_len, const uint8 *old_files, int old_files_len);
206 virtual void rename_cmd(const uint8 *new_file, int new_file_len, const uint8 *old_file, int old_file_len);
207 virtual void scratch_cmd(const uint8 *files, int files_len);
208 virtual void position_cmd(const uint8 *cmd, int cmd_len);
209 virtual void initialize_cmd(void);
210 virtual void new_cmd(const uint8 *name, int name_len, const uint8 *comma);
211 virtual void validate_cmd(void);
212 void unsupp_cmd(void);
213
214 char error_buf[256]; // Buffer with current error message
215 char *error_ptr; // Pointer within error message
216 int error_len; // Remaining length of error message
217
218 uint8 cmd_buf[64]; // Buffer for incoming command strings
219 int cmd_len; // Length of received command
220
221 private:
222 IEC *the_iec; // Pointer to IEC object
223 };
224
225
226 // Convert ASCII character to PETSCII character
227 extern char ascii2petscii(char c);
228
229 // Convert ASCII string to PETSCII string
230 extern void ascii2petscii(char *dest, const char *src, int max);
231
232 // Convert PETSCII character to ASCII character
233 extern char petscii2ascii(uint8 c);
234
235 // Convert PETSCII string to ASCII string
236 extern void petscii2ascii(char *dest, const char *src, int max);
237
238 #endif