1 |
|
/* |
2 |
|
* IEC.h - IEC bus routines, 1541 emulation (DOS level) |
3 |
|
* |
4 |
< |
* Frodo (C) 1994-1997,2002 Christian Bauer |
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 |
39 |
|
// 1541 error codes |
40 |
|
enum { |
41 |
|
ERR_OK, // 00 OK |
42 |
< |
ERR_WRITEERROR, // 25 WRITE ERROR |
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_SYNTAX30, // 30 SYNTAX ERROR (unknown command) |
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_ILLEGALTS, // 67 ILLEGAL TRACK OR SECTOR |
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 |
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; |
157 |
|
uint8 Out(uint8 byte, bool eoi); |
158 |
|
uint8 OutATN(uint8 byte); |
159 |
|
uint8 OutSec(uint8 byte); |
160 |
< |
uint8 In(uint8 *byte); |
160 |
> |
uint8 In(uint8 &byte); |
161 |
|
void SetATN(void); |
162 |
|
void RelATN(void); |
163 |
|
void Turnaround(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); |
175 |
> |
uint8 data_in(uint8 &byte); |
176 |
|
|
177 |
|
C64Display *the_display; // Pointer to display object (for drive LEDs) |
178 |
|
|
179 |
< |
char name_buf[NAMEBUF_LENGTH]; // Buffer for file names and command strings |
180 |
< |
char *name_ptr; // Pointer for reception of file name |
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) |
200 |
|
Drive(IEC *iec); |
201 |
|
virtual ~Drive() {} |
202 |
|
|
203 |
< |
virtual uint8 Open(int channel, char *filename)=0; |
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; |
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 |
|
|
210 |
|
bool Ready; // Drive is ready for operation |
211 |
|
|
212 |
|
protected: |
213 |
< |
void set_error(int error); |
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 |
< |
char *error_ptr; // Pointer within error message |
218 |
< |
int error_len; // Remaining length of error message |
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 |
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 |