ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/Frodo4/Src/IEC.h
Revision: 1.6
Committed: 2004-01-14T16:54:46Z (20 years, 3 months ago) by cebix
Content type: text/plain
Branch: MAIN
Changes since 1.5: +25 -3 lines
Log Message:
- backported T64 code from Frodo V5, handles .P00 files
- T64Drive renamed to ArchDrive
- PETSCII characters are uint8s, not chars

File Contents

# Content
1 /*
2 * IEC.h - IEC bus routines, 1541 emulation (DOS level)
3 *
4 * Frodo (C) 1994-1997,2002-2004 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 // Information about file in disk image/archive file
122 struct c64_dir_entry {
123 c64_dir_entry(const uint8 *n, int t, bool o, bool p, size_t s, off_t ofs = 0, uint8 sal = 0, uint8 sah = 0)
124 : type(t), is_open(o), is_protected(p), size(s), offset(ofs), sa_lo(sal), sa_hi(sah)
125 {
126 strncpy((char *)name, (const char *)n, 17);
127 name[16] = 0;
128 }
129
130 // Basic information
131 uint8 name[17]; // File name (C64 charset, null-terminated)
132 int type; // File type (see defines above)
133 bool is_open; // Flag: file open
134 bool is_protected; // Flag: file protected
135 size_t size; // File size (may be approximated)
136
137 // Special information
138 off_t offset; // Offset of file in archive file
139 uint8 sa_lo, sa_hi; // C64 start address
140 };
141
142
143 class Drive;
144 class C64Display;
145 class Prefs;
146
147 // Class for complete IEC bus system with drives 8..11
148 class IEC {
149 public:
150 IEC(C64Display *display);
151 ~IEC();
152
153 void Reset(void);
154 void NewPrefs(Prefs *prefs);
155 void UpdateLEDs(void);
156
157 uint8 Out(uint8 byte, bool eoi);
158 uint8 OutATN(uint8 byte);
159 uint8 OutSec(uint8 byte);
160 uint8 In(uint8 &byte);
161 void SetATN(void);
162 void RelATN(void);
163 void Turnaround(void);
164 void Release(void);
165
166 private:
167 uint8 listen(int device);
168 uint8 talk(int device);
169 uint8 unlisten(void);
170 uint8 untalk(void);
171 uint8 sec_listen(void);
172 uint8 sec_talk(void);
173 uint8 open_out(uint8 byte, bool eoi);
174 uint8 data_out(uint8 byte, bool eoi);
175 uint8 data_in(uint8 &byte);
176
177 C64Display *the_display; // Pointer to display object (for drive LEDs)
178
179 uint8 name_buf[NAMEBUF_LENGTH]; // Buffer for file names and command strings
180 uint8 *name_ptr; // Pointer for reception of file name
181 int name_len; // Received length of file name
182
183 Drive *drive[4]; // 4 drives (8..11)
184
185 Drive *listener; // Pointer to active listener
186 Drive *talker; // Pointer to active talker
187
188 bool listener_active; // Listener selected, listener_data is valid
189 bool talker_active; // Talker selected, talker_data is valid
190 bool listening; // Last ATN was listen (to decide between sec_listen/sec_talk)
191
192 uint8 received_cmd; // Received command code ($x0)
193 uint8 sec_addr; // Received secondary address ($0x)
194 };
195
196
197 // Abstract superclass for individual drives
198 class Drive {
199 public:
200 Drive(IEC *iec);
201 virtual ~Drive() {}
202
203 virtual uint8 Open(int channel, const uint8 *name, int name_len)=0;
204 virtual uint8 Close(int channel)=0;
205 virtual uint8 Read(int channel, uint8 &byte)=0;
206 virtual uint8 Write(int channel, uint8 byte, bool eoi)=0;
207 virtual void Reset(void)=0;
208
209 int LED; // Drive LED state
210 bool Ready; // Drive is ready for operation
211
212 protected:
213 void set_error(int error, int track = 0, int sector = 0);
214
215 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);
216
217 void execute_cmd(const uint8 *cmd, int cmd_len);
218 virtual void block_read_cmd(int channel, int track, int sector, bool user_cmd = false);
219 virtual void block_write_cmd(int channel, int track, int sector, bool user_cmd = false);
220 virtual void block_execute_cmd(int channel, int track, int sector);
221 virtual void block_allocate_cmd(int track, int sector);
222 virtual void block_free_cmd(int track, int sector);
223 virtual void buffer_pointer_cmd(int channel, int pos);
224 virtual void mem_read_cmd(uint16 adr, uint8 len);
225 virtual void mem_write_cmd(uint16 adr, uint8 len, uint8 *p);
226 virtual void mem_execute_cmd(uint16 adr);
227 virtual void copy_cmd(const uint8 *new_file, int new_file_len, const uint8 *old_files, int old_files_len);
228 virtual void rename_cmd(const uint8 *new_file, int new_file_len, const uint8 *old_file, int old_file_len);
229 virtual void scratch_cmd(const uint8 *files, int files_len);
230 virtual void position_cmd(const uint8 *cmd, int cmd_len);
231 virtual void initialize_cmd(void);
232 virtual void new_cmd(const uint8 *name, int name_len, const uint8 *comma);
233 virtual void validate_cmd(void);
234 void unsupp_cmd(void);
235
236 char error_buf[256]; // Buffer with current error message
237 char *error_ptr; // Pointer within error message
238 int error_len; // Remaining length of error message
239 int current_error; // Number of current error
240
241 uint8 cmd_buf[64]; // Buffer for incoming command strings
242 int cmd_len; // Length of received command
243
244 private:
245 IEC *the_iec; // Pointer to IEC object
246 };
247
248
249 // Convert ASCII character to PETSCII character
250 extern uint8 ascii2petscii(char c);
251
252 // Convert ASCII string to PETSCII string
253 extern void ascii2petscii(uint8 *dest, const char *src, int max);
254
255 // Convert PETSCII character to ASCII character
256 extern char petscii2ascii(uint8 c);
257
258 // Convert PETSCII string to ASCII string
259 extern void petscii2ascii(char *dest, const uint8 *src, int max);
260
261 #endif