ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/Frodo4/Src/1541d64.h
Revision: 1.8
Committed: 2005-06-27T19:55:48Z (17 years, 5 months ago) by cebix
Content type: text/plain
Branch: MAIN
CVS Tags: VERSION_4_2, HEAD
Changes since 1.7: +1 -1 lines
Log Message:
updated copyright dates

File Contents

# Content
1 /*
2 * 1541d64.h - 1541 emulation in disk image files (.d64/.x64/zipcode)
3 *
4 * Frodo (C) 1994-1997,2002-2005 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 _1541D64_H
22 #define _1541D64_H
23
24 #include "IEC.h"
25
26
27 /*
28 * Definitions
29 */
30
31 // Constants
32 const int NUM_SECTORS_35 = 683; // Number of sectors in a 35-track image
33 const int NUM_SECTORS_40 = 768; // Number of sectors in a 40-track image
34
35 // Disk image types
36 enum {
37 TYPE_D64, // D64 file
38 TYPE_ED64, // Converted zipcode file (D64 with header ID)
39 TYPE_X64 // x64 file
40 };
41
42 // Channel descriptor
43 struct channel_desc {
44 int mode; // Channel mode
45 bool writing; // Flag: writing to file (for file channels)
46 int buf_num; // Buffer number for direct access and file channels
47 uint8 *buf; // Pointer to start of buffer
48 uint8 *buf_ptr; // Pointer to current position in buffer
49 int buf_len; // Remaining bytes in buffer
50 int track, sector; // Track and sector the buffer will be written to (for writing to file channels)
51 int num_blocks; // Number of blocks in file (for writing to file channels)
52 int dir_track; // Track...
53 int dir_sector; // ...and sector of directory block containing file entry
54 int entry; // Number of entry in directory block
55 };
56
57 // Disk image file descriptor
58 struct image_file_desc {
59 int type; // See definitions above
60 int header_size; // Size of file header
61 int num_tracks; // Number of tracks
62 uint8 id1, id2; // Block header ID (as opposed to BAM ID)
63 uint8 error_info[NUM_SECTORS_40]; // Sector error information (1 byte/sector)
64 bool has_error_info; // Flag: error info present in file
65 };
66
67 // Disk image drive class
68 class ImageDrive : public Drive {
69 public:
70 ImageDrive(IEC *iec, const char *filepath);
71 virtual ~ImageDrive();
72
73 virtual uint8 Open(int channel, const uint8 *name, int name_len);
74 virtual uint8 Close(int channel);
75 virtual uint8 Read(int channel, uint8 &byte);
76 virtual uint8 Write(int channel, uint8 byte, bool eoi);
77 virtual void Reset(void);
78
79 private:
80 void close_image(void);
81 bool change_image(const char *path);
82
83 uint8 open_file(int channel, const uint8 *name, int name_len);
84 uint8 open_file_ts(int channel, int track, int sector);
85 uint8 create_file(int channel, const uint8 *name, int name_len, int type, bool overwrite = false);
86 uint8 open_directory(const uint8 *pattern, int pattern_len);
87 uint8 open_direct(int channel, const uint8 *filename);
88 void close_all_channels(void);
89
90 int alloc_buffer(int want);
91 void free_buffer(int buf);
92
93 bool find_file(const uint8 *pattern, int pattern_len, int &dir_track, int &dir_sector, int &entry, bool cont);
94 bool find_first_file(const uint8 *pattern, int pattern_len, int &dir_track, int &dir_sector, int &entry);
95 bool find_next_file(const uint8 *pattern, int pattern_len, int &dir_track, int &dir_sector, int &entry);
96 bool alloc_dir_entry(int &track, int &sector, int &entry);
97
98 bool is_block_free(int track, int sector);
99 int num_free_blocks(int track);
100 int alloc_block(int track, int sector);
101 int free_block(int track, int sector);
102 bool alloc_block_chain(int track, int sector);
103 bool free_block_chain(int track, int sector);
104 bool alloc_next_block(int &track, int &sector, int interleave);
105
106 bool read_sector(int track, int sector, uint8 *buffer);
107 bool write_sector(int track, int sector, uint8 *buffer);
108 void write_error_info(void);
109
110 virtual void block_read_cmd(int channel, int track, int sector, bool user_cmd = false);
111 virtual void block_write_cmd(int channel, int track, int sector, bool user_cmd = false);
112 virtual void block_allocate_cmd(int track, int sector);
113 virtual void block_free_cmd(int track, int sector);
114 virtual void buffer_pointer_cmd(int channel, int pos);
115 virtual void mem_read_cmd(uint16 adr, uint8 len);
116 virtual void mem_write_cmd(uint16 adr, uint8 len, uint8 *p);
117 virtual void copy_cmd(const uint8 *new_file, int new_file_len, const uint8 *old_files, int old_files_len);
118 virtual void rename_cmd(const uint8 *new_file, int new_file_len, const uint8 *old_file, int old_file_len);
119 virtual void scratch_cmd(const uint8 *files, int files_len);
120 virtual void initialize_cmd(void);
121 virtual void new_cmd(const uint8 *name, int name_len, const uint8 *comma);
122 virtual void validate_cmd(void);
123
124 FILE *the_file; // File pointer for image file
125 image_file_desc desc; // Image file descriptor
126 bool write_protected; // Flag: image file write-protected
127
128 uint8 ram[0x800]; // 2k 1541 RAM
129 uint8 dir[258]; // Buffer for directory blocks
130 uint8 *bam; // Pointer to BAM in 1541 RAM (buffer 4, upper 256 bytes)
131 bool bam_dirty; // Flag: BAM modified, needs to be written back
132
133 channel_desc ch[18]; // Descriptors for channels 0..17 (16 = internal read, 17 = internal write)
134 bool buf_free[4]; // Flags: buffer 0..3 free?
135 };
136
137
138 /*
139 * Functions
140 */
141
142 // Check whether file with given header (64 bytes) and size looks like one
143 // of the file types supported by this module
144 extern bool IsImageFile(const char *path, const uint8 *header, long size);
145
146 // Read directory of disk image file into (empty) c64_dir_entry vector
147 extern bool ReadImageDirectory(const char *path, vector<c64_dir_entry> &vec);
148
149 // Create new blank disk image file
150 extern bool CreateImageFile(const char *path);
151
152 #endif