--- Frodo4/Src/IEC.h 2003/07/01 17:51:17 1.2 +++ Frodo4/Src/IEC.h 2004/01/14 17:26:29 1.7 @@ -1,7 +1,7 @@ /* * IEC.h - IEC bus routines, 1541 emulation (DOS level) * - * Frodo (C) 1994-1997,2002-2003 Christian Bauer + * Frodo (C) 1994-1997,2002-2004 Christian Bauer * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,10 +22,13 @@ #define _IEC_H +/* + * Definitions + */ + // Maximum length of file names const int NAMEBUF_LENGTH = 256; - // C64 status codes enum { ST_OK = 0, // No error @@ -35,41 +38,66 @@ enum { ST_NOTPRESENT = 0x80 // Device not present }; - // 1541 error codes enum { ERR_OK, // 00 OK - ERR_WRITEERROR, // 25 WRITE ERROR + ERR_SCRATCHED, // 01 FILES SCRATCHED + ERR_UNIMPLEMENTED, // 03 UNIMPLEMENTED + ERR_READ20, // 20 READ ERROR (block header not found) + ERR_READ21, // 21 READ ERROR (no sync character) + ERR_READ22, // 22 READ ERROR (data block not present) + ERR_READ23, // 23 READ ERROR (checksum error in data block) + ERR_READ24, // 24 READ ERROR (byte decoding error) + ERR_WRITE25, // 25 WRITE ERROR (write-verify error) ERR_WRITEPROTECT, // 26 WRITE PROTECT ON - ERR_SYNTAX30, // 30 SYNTAX ERROR (unknown command) + ERR_READ27, // 27 READ ERROR (checksum error in header) + ERR_WRITE28, // 28 WRITE ERROR (long data block) + ERR_DISKID, // 29 DISK ID MISMATCH + ERR_SYNTAX30, // 30 SYNTAX ERROR (general syntax) + ERR_SYNTAX31, // 31 SYNTAX ERROR (invalid command) + ERR_SYNTAX32, // 32 SYNTAX ERROR (command too long) ERR_SYNTAX33, // 33 SYNTAX ERROR (wildcards on writing) + ERR_SYNTAX34, // 34 SYNTAX ERROR (missing file name) ERR_WRITEFILEOPEN, // 60 WRITE FILE OPEN ERR_FILENOTOPEN, // 61 FILE NOT OPEN ERR_FILENOTFOUND, // 62 FILE NOT FOUND - ERR_ILLEGALTS, // 67 ILLEGAL TRACK OR SECTOR + ERR_FILEEXISTS, // 63 FILE EXISTS + ERR_FILETYPE, // 64 FILE TYPE MISMATCH + ERR_NOBLOCK, // 65 NO BLOCK + ERR_ILLEGALTS, // 66 ILLEGAL TRACK OR SECTOR ERR_NOCHANNEL, // 70 NO CHANNEL + ERR_DIRERROR, // 71 DIR ERROR + ERR_DISKFULL, // 72 DISK FULL ERR_STARTUP, // 73 Power-up message ERR_NOTREADY // 74 DRIVE NOT READY }; +// Mountable file types +enum { + FILE_IMAGE, // Disk image, handled by ImageDrive + FILE_ARCH // Archive file, handled by ArchDrive +}; -// IEC command codes +// 1541 file types enum { - CMD_DATA = 0x60, // Data transfer - CMD_CLOSE = 0xe0, // Close channel - CMD_OPEN = 0xf0 // Open channel + FTYPE_DEL, // Deleted + FTYPE_SEQ, // Sequential + FTYPE_PRG, // Program + FTYPE_USR, // User + FTYPE_REL, // Relative + FTYPE_UNKNOWN }; +static const char ftype_char[9] = "DSPUL "; -// IEC ATN codes +// 1541 file access modes enum { - ATN_LISTEN = 0x20, - ATN_UNLISTEN = 0x30, - ATN_TALK = 0x40, - ATN_UNTALK = 0x50 + FMODE_READ, // Read + FMODE_WRITE, // Write + FMODE_APPEND, // Append + FMODE_M // Read open file }; - // Drive LED states enum { DRVLED_OFF, // Inactive, LED off @@ -77,6 +105,26 @@ enum { DRVLED_ERROR // Error, blink LED }; +// Information about file in disk image/archive file +struct c64_dir_entry { + 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) + : type(t), is_open(o), is_protected(p), size(s), offset(ofs), sa_lo(sal), sa_hi(sah) + { + strncpy((char *)name, (const char *)n, 17); + name[16] = 0; + } + + // Basic information + uint8 name[17]; // File name (C64 charset, null-terminated) + int type; // File type (see defines above) + bool is_open; // Flag: file open + bool is_protected; // Flag: file protected + size_t size; // File size (may be approximated) + + // Special information + off_t offset; // Offset of file in archive file + uint8 sa_lo, sa_hi; // C64 start address +}; class Drive; class C64Display; @@ -95,13 +143,15 @@ public: uint8 Out(uint8 byte, bool eoi); uint8 OutATN(uint8 byte); uint8 OutSec(uint8 byte); - uint8 In(uint8 *byte); + uint8 In(uint8 &byte); void SetATN(void); void RelATN(void); void Turnaround(void); void Release(void); private: + Drive *create_drive(const char *path); + uint8 listen(int device); uint8 talk(int device); uint8 unlisten(void); @@ -110,12 +160,12 @@ private: uint8 sec_talk(void); uint8 open_out(uint8 byte, bool eoi); uint8 data_out(uint8 byte, bool eoi); - uint8 data_in(uint8 *byte); + uint8 data_in(uint8 &byte); C64Display *the_display; // Pointer to display object (for drive LEDs) - char name_buf[NAMEBUF_LENGTH]; // Buffer for file names and command strings - char *name_ptr; // Pointer for reception of file name + uint8 name_buf[NAMEBUF_LENGTH]; // Buffer for file names and command strings + uint8 *name_ptr; // Pointer for reception of file name int name_len; // Received length of file name Drive *drive[4]; // 4 drives (8..11) @@ -131,16 +181,15 @@ private: uint8 sec_addr; // Received secondary address ($0x) }; - // Abstract superclass for individual drives class Drive { public: Drive(IEC *iec); virtual ~Drive() {} - virtual uint8 Open(int channel, char *filename)=0; + virtual uint8 Open(int channel, const uint8 *name, int name_len)=0; virtual uint8 Close(int channel)=0; - virtual uint8 Read(int channel, uint8 *byte)=0; + virtual uint8 Read(int channel, uint8 &byte)=0; virtual uint8 Write(int channel, uint8 byte, bool eoi)=0; virtual void Reset(void)=0; @@ -148,13 +197,62 @@ public: bool Ready; // Drive is ready for operation protected: - void set_error(int error); + void set_error(int error, int track = 0, int sector = 0); + + 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); - char *error_ptr; // Pointer within error message - int error_len; // Remaining length of error message + void execute_cmd(const uint8 *cmd, int cmd_len); + virtual void block_read_cmd(int channel, int track, int sector, bool user_cmd = false); + virtual void block_write_cmd(int channel, int track, int sector, bool user_cmd = false); + virtual void block_execute_cmd(int channel, int track, int sector); + virtual void block_allocate_cmd(int track, int sector); + virtual void block_free_cmd(int track, int sector); + virtual void buffer_pointer_cmd(int channel, int pos); + virtual void mem_read_cmd(uint16 adr, uint8 len); + virtual void mem_write_cmd(uint16 adr, uint8 len, uint8 *p); + virtual void mem_execute_cmd(uint16 adr); + virtual void copy_cmd(const uint8 *new_file, int new_file_len, const uint8 *old_files, int old_files_len); + virtual void rename_cmd(const uint8 *new_file, int new_file_len, const uint8 *old_file, int old_file_len); + virtual void scratch_cmd(const uint8 *files, int files_len); + virtual void position_cmd(const uint8 *cmd, int cmd_len); + virtual void initialize_cmd(void); + virtual void new_cmd(const uint8 *name, int name_len, const uint8 *comma); + virtual void validate_cmd(void); + void unsupp_cmd(void); + + char error_buf[256]; // Buffer with current error message + char *error_ptr; // Pointer within error message + int error_len; // Remaining length of error message + int current_error; // Number of current error + + uint8 cmd_buf[64]; // Buffer for incoming command strings + int cmd_len; // Length of received command private: - IEC *the_iec; // Pointer to IEC object + IEC *the_iec; // Pointer to IEC object }; + +/* + * Functions + */ + +// Convert ASCII character to PETSCII character +extern uint8 ascii2petscii(char c); + +// Convert ASCII string to PETSCII string +extern void ascii2petscii(uint8 *dest, const char *src, int max); + +// Convert PETSCII character to ASCII character +extern char petscii2ascii(uint8 c); + +// Convert PETSCII string to ASCII string +extern void petscii2ascii(char *dest, const uint8 *src, int max); + +// Check whether file is a mountable disk image or archive file, return type +extern bool IsMountableFile(const char *path, int &type); + +// Read directory of mountable disk image or archive file into c64_dir_entry vector +extern bool ReadDirectory(const char *path, int type, vector &vec); + #endif