1 |
/* |
2 |
* 1541d64.h - 1541 emulation in .d64 file |
3 |
* |
4 |
* Frodo (C) 1994-1997,2002-2003 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 |
// BAM structure |
28 |
typedef struct { |
29 |
uint8 dir_track; // Track... |
30 |
uint8 dir_sector; // ...and sector of first directory block |
31 |
int8 fmt_type; // Format type |
32 |
int8 pad0; |
33 |
uint8 bitmap[4*35]; // Sector allocation |
34 |
uint8 disk_name[18]; // Disk name |
35 |
uint8 id[2]; // Disk ID |
36 |
int8 pad1; |
37 |
uint8 fmt_char[2]; // Format characters |
38 |
int8 pad2[4]; |
39 |
int8 pad3[85]; |
40 |
} BAM; |
41 |
|
42 |
// Directory entry structure |
43 |
typedef struct { |
44 |
uint8 type; // File type |
45 |
uint8 track; // Track... |
46 |
uint8 sector; // ...and sector of first data block |
47 |
uint8 name[16]; // File name |
48 |
uint8 side_track; // Track... |
49 |
uint8 side_sector; // ...and sector of first side sector |
50 |
uint8 rec_len; // Record length |
51 |
int8 pad0[4]; |
52 |
uint8 ovr_track; // Track... |
53 |
uint8 ovr_sector; // ...and sector on overwrite |
54 |
uint8 num_blocks_l; // Number of blocks, LSB |
55 |
uint8 num_blocks_h; // Number of blocks, MSB |
56 |
int8 pad1[2]; |
57 |
} DirEntry; |
58 |
|
59 |
// Directory block structure |
60 |
typedef struct { |
61 |
uint8 padding[2]; // Keep DirEntry word-aligned |
62 |
uint8 next_track; |
63 |
uint8 next_sector; |
64 |
DirEntry entry[8]; |
65 |
} Directory; |
66 |
|
67 |
|
68 |
class D64Drive : public Drive { |
69 |
public: |
70 |
D64Drive(IEC *iec, char *filepath); |
71 |
virtual ~D64Drive(); |
72 |
virtual uint8 Open(int channel, char *filename); |
73 |
virtual uint8 Close(int channel); |
74 |
virtual uint8 Read(int channel, uint8 *byte); |
75 |
virtual uint8 Write(int channel, uint8 byte, bool eoi); |
76 |
virtual void Reset(void); |
77 |
|
78 |
private: |
79 |
void open_close_d64_file(char *d64name); |
80 |
uint8 open_file(int channel, char *filename); |
81 |
void convert_filename(char *srcname, char *destname, int *filemode, int *filetype); |
82 |
bool find_file(char *filename, int *track, int *sector); |
83 |
uint8 open_file_ts(int channel, int track, int sector); |
84 |
uint8 open_directory(char *pattern); |
85 |
uint8 open_direct(int channel, char *filename); |
86 |
void close_all_channels(); |
87 |
void execute_command(char *command); |
88 |
void block_read_cmd(char *command); |
89 |
void buffer_ptr_cmd(char *command); |
90 |
bool parse_bcmd(char *cmd, int *arg1, int *arg2, int *arg3, int *arg4); |
91 |
void chd64_cmd(char *d64name); |
92 |
int alloc_buffer(int want); |
93 |
void free_buffer(int buf); |
94 |
bool read_sector(int track, int sector, uint8 *buffer); |
95 |
int offset_from_ts(int track, int sector); |
96 |
uint8 conv_from_64(uint8 c, bool map_slash); |
97 |
|
98 |
char orig_d64_name[256]; // Original path of .d64 file |
99 |
|
100 |
FILE *the_file; // File pointer for .d64 file |
101 |
|
102 |
uint8 *ram; // 2KB 1541 RAM |
103 |
BAM *bam; // Pointer to BAM |
104 |
Directory dir; // Buffer for directory blocks |
105 |
|
106 |
int chan_mode[16]; // Channel mode |
107 |
int chan_buf_num[16]; // Buffer number of channel (for direct access channels) |
108 |
uint8 *chan_buf[16]; // Pointer to buffer |
109 |
uint8 *buf_ptr[16]; // Pointer in buffer |
110 |
int buf_len[16]; // Remaining bytes in buffer |
111 |
|
112 |
bool buf_free[4]; // Buffer 0..3 free? |
113 |
|
114 |
char cmd_buffer[44]; // Buffer for incoming command strings |
115 |
int cmd_len; // Length of received command |
116 |
|
117 |
int image_header; // Length of .d64 file header |
118 |
|
119 |
uint8 error_info[683]; // Sector error information (1 byte/sector) |
120 |
}; |
121 |
|
122 |
#endif |