1 |
|
/* |
2 |
|
* IEC.h - IEC bus routines, 1541 emulation (DOS level) |
3 |
|
* |
4 |
< |
* Frodo (C) 1994-1997,2002-2003 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 |
22 |
|
#define _IEC_H |
23 |
|
|
24 |
|
|
25 |
+ |
/* |
26 |
+ |
* Definitions |
27 |
+ |
*/ |
28 |
+ |
|
29 |
|
// Maximum length of file names |
30 |
|
const int NAMEBUF_LENGTH = 256; |
31 |
|
|
28 |
– |
|
32 |
|
// C64 status codes |
33 |
|
enum { |
34 |
|
ST_OK = 0, // No error |
38 |
|
ST_NOTPRESENT = 0x80 // Device not present |
39 |
|
}; |
40 |
|
|
38 |
– |
|
41 |
|
// 1541 error codes |
42 |
|
enum { |
43 |
|
ERR_OK, // 00 OK |
72 |
|
ERR_NOTREADY // 74 DRIVE NOT READY |
73 |
|
}; |
74 |
|
|
75 |
+ |
// Mountable file types |
76 |
+ |
enum { |
77 |
+ |
FILE_IMAGE, // Disk image, handled by ImageDrive |
78 |
+ |
FILE_ARCH // Archive file, handled by ArchDrive |
79 |
+ |
}; |
80 |
|
|
81 |
|
// 1541 file types |
82 |
|
enum { |
90 |
|
|
91 |
|
static const char ftype_char[9] = "DSPUL "; |
92 |
|
|
86 |
– |
|
93 |
|
// 1541 file access modes |
94 |
|
enum { |
95 |
|
FMODE_READ, // Read |
98 |
|
FMODE_M // Read open file |
99 |
|
}; |
100 |
|
|
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 |
– |
|
101 |
|
// Drive LED states |
102 |
|
enum { |
103 |
|
DRVLED_OFF, // Inactive, LED off |
105 |
|
DRVLED_ERROR // Error, blink LED |
106 |
|
}; |
107 |
|
|
108 |
+ |
// Information about file in disk image/archive file |
109 |
+ |
struct c64_dir_entry { |
110 |
+ |
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) |
111 |
+ |
: type(t), is_open(o), is_protected(p), size(s), offset(ofs), sa_lo(sal), sa_hi(sah) |
112 |
+ |
{ |
113 |
+ |
strncpy((char *)name, (const char *)n, 17); |
114 |
+ |
name[16] = 0; |
115 |
+ |
} |
116 |
+ |
|
117 |
+ |
// Basic information |
118 |
+ |
uint8 name[17]; // File name (C64 charset, null-terminated) |
119 |
+ |
int type; // File type (see defines above) |
120 |
+ |
bool is_open; // Flag: file open |
121 |
+ |
bool is_protected; // Flag: file protected |
122 |
+ |
size_t size; // File size (may be approximated) |
123 |
+ |
|
124 |
+ |
// Special information |
125 |
+ |
off_t offset; // Offset of file in archive file |
126 |
+ |
uint8 sa_lo, sa_hi; // C64 start address |
127 |
+ |
}; |
128 |
|
|
129 |
|
class Drive; |
130 |
|
class C64Display; |
143 |
|
uint8 Out(uint8 byte, bool eoi); |
144 |
|
uint8 OutATN(uint8 byte); |
145 |
|
uint8 OutSec(uint8 byte); |
146 |
< |
uint8 In(uint8 *byte); |
146 |
> |
uint8 In(uint8 &byte); |
147 |
|
void SetATN(void); |
148 |
|
void RelATN(void); |
149 |
|
void Turnaround(void); |
150 |
|
void Release(void); |
151 |
|
|
152 |
|
private: |
153 |
+ |
Drive *create_drive(const char *path); |
154 |
+ |
|
155 |
|
uint8 listen(int device); |
156 |
|
uint8 talk(int device); |
157 |
|
uint8 unlisten(void); |
160 |
|
uint8 sec_talk(void); |
161 |
|
uint8 open_out(uint8 byte, bool eoi); |
162 |
|
uint8 data_out(uint8 byte, bool eoi); |
163 |
< |
uint8 data_in(uint8 *byte); |
163 |
> |
uint8 data_in(uint8 &byte); |
164 |
|
|
165 |
|
C64Display *the_display; // Pointer to display object (for drive LEDs) |
166 |
|
|
181 |
|
uint8 sec_addr; // Received secondary address ($0x) |
182 |
|
}; |
183 |
|
|
174 |
– |
|
184 |
|
// Abstract superclass for individual drives |
185 |
|
class Drive { |
186 |
|
public: |
189 |
|
|
190 |
|
virtual uint8 Open(int channel, const uint8 *name, int name_len)=0; |
191 |
|
virtual uint8 Close(int channel)=0; |
192 |
< |
virtual uint8 Read(int channel, uint8 *byte)=0; |
192 |
> |
virtual uint8 Read(int channel, uint8 &byte)=0; |
193 |
|
virtual uint8 Write(int channel, uint8 byte, bool eoi)=0; |
194 |
|
virtual void Reset(void)=0; |
195 |
|
|
223 |
|
char error_buf[256]; // Buffer with current error message |
224 |
|
char *error_ptr; // Pointer within error message |
225 |
|
int error_len; // Remaining length of error message |
226 |
+ |
int current_error; // Number of current error |
227 |
|
|
228 |
|
uint8 cmd_buf[64]; // Buffer for incoming command strings |
229 |
|
int cmd_len; // Length of received command |
233 |
|
}; |
234 |
|
|
235 |
|
|
236 |
+ |
/* |
237 |
+ |
* Functions |
238 |
+ |
*/ |
239 |
+ |
|
240 |
|
// Convert ASCII character to PETSCII character |
241 |
< |
extern char ascii2petscii(char c); |
241 |
> |
extern uint8 ascii2petscii(char c); |
242 |
|
|
243 |
|
// Convert ASCII string to PETSCII string |
244 |
< |
extern void ascii2petscii(char *dest, const char *src, int max); |
244 |
> |
extern void ascii2petscii(uint8 *dest, const char *src, int max); |
245 |
|
|
246 |
|
// Convert PETSCII character to ASCII character |
247 |
|
extern char petscii2ascii(uint8 c); |
248 |
|
|
249 |
|
// Convert PETSCII string to ASCII string |
250 |
< |
extern void petscii2ascii(char *dest, const char *src, int max); |
250 |
> |
extern void petscii2ascii(char *dest, const uint8 *src, int max); |
251 |
> |
|
252 |
> |
// Check whether file is a mountable disk image or archive file, return type |
253 |
> |
extern bool IsMountableFile(const char *path, int &type); |
254 |
> |
|
255 |
> |
// Read directory of mountable disk image or archive file into c64_dir_entry vector |
256 |
> |
extern bool ReadDirectory(const char *path, int type, vector<c64_dir_entry> &vec); |
257 |
|
|
258 |
|
#endif |