1 |
/* |
2 |
* 1541job.h - Emulation of 1541 GCR disk reading/writing |
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 _1541JOB_H |
22 |
#define _1541JOB_H |
23 |
|
24 |
|
25 |
class MOS6502_1541; |
26 |
class Prefs; |
27 |
struct Job1541State; |
28 |
|
29 |
class Job1541 { |
30 |
public: |
31 |
Job1541(uint8 *ram1541); |
32 |
~Job1541(); |
33 |
|
34 |
void GetState(Job1541State *state); |
35 |
void SetState(Job1541State *state); |
36 |
void NewPrefs(Prefs *prefs); |
37 |
void MoveHeadOut(void); |
38 |
void MoveHeadIn(void); |
39 |
bool SyncFound(void); |
40 |
uint8 ReadGCRByte(void); |
41 |
uint8 WPState(void); |
42 |
void WriteSector(void); |
43 |
void FormatTrack(void); |
44 |
|
45 |
private: |
46 |
void open_d64_file(char *filepath); |
47 |
void close_d64_file(void); |
48 |
bool read_sector(int track, int sector, uint8 *buffer); |
49 |
bool write_sector(int track, int sector, uint8 *buffer); |
50 |
void format_disk(void); |
51 |
int secnum_from_ts(int track, int sector); |
52 |
int offset_from_ts(int track, int sector); |
53 |
void gcr_conv4(uint8 *from, uint8 *to); |
54 |
void sector2gcr(int track, int sector); |
55 |
void disk2gcr(void); |
56 |
|
57 |
uint8 *ram; // Pointer to 1541 RAM |
58 |
FILE *the_file; // File pointer for .d64 file |
59 |
int image_header; // Length of .d64/.x64 file header |
60 |
|
61 |
uint8 id1, id2; // ID of disk |
62 |
uint8 error_info[683]; // Sector error information (1 byte/sector) |
63 |
|
64 |
uint8 *gcr_data; // Pointer to GCR encoded disk data |
65 |
uint8 *gcr_ptr; // Pointer to GCR data under R/W head |
66 |
uint8 *gcr_track_start; // Pointer to start of GCR data of current track |
67 |
uint8 *gcr_track_end; // Pointer to end of GCR data of current track |
68 |
int current_halftrack; // Current halftrack number (2..70) |
69 |
|
70 |
bool write_protected; // Flag: Disk write-protected |
71 |
bool disk_changed; // Flag: Disk changed (WP sensor strobe control) |
72 |
}; |
73 |
|
74 |
// 1541 GCR state |
75 |
struct Job1541State { |
76 |
int current_halftrack; |
77 |
uint32 gcr_ptr; |
78 |
bool write_protected; |
79 |
bool disk_changed; |
80 |
}; |
81 |
|
82 |
|
83 |
/* |
84 |
* Check if R/W head is over SYNC |
85 |
*/ |
86 |
|
87 |
inline bool Job1541::SyncFound(void) |
88 |
{ |
89 |
if (*gcr_ptr == 0xff) |
90 |
return true; |
91 |
else { |
92 |
gcr_ptr++; // Rotate disk |
93 |
if (gcr_ptr == gcr_track_end) |
94 |
gcr_ptr = gcr_track_start; |
95 |
return false; |
96 |
} |
97 |
} |
98 |
|
99 |
|
100 |
/* |
101 |
* Read one GCR byte from disk |
102 |
*/ |
103 |
|
104 |
inline uint8 Job1541::ReadGCRByte(void) |
105 |
{ |
106 |
uint8 byte = *gcr_ptr++; // Rotate disk |
107 |
if (gcr_ptr == gcr_track_end) |
108 |
gcr_ptr = gcr_track_start; |
109 |
return byte; |
110 |
} |
111 |
|
112 |
|
113 |
/* |
114 |
* Return state of write protect sensor |
115 |
*/ |
116 |
|
117 |
inline uint8 Job1541::WPState(void) |
118 |
{ |
119 |
if (disk_changed) { // Disk change -> WP sensor strobe |
120 |
disk_changed = false; |
121 |
return write_protected ? 0x10 : 0; |
122 |
} else |
123 |
return write_protected ? 0 : 0x10; |
124 |
} |
125 |
|
126 |
#endif |