29 |
|
*/ |
30 |
|
|
31 |
|
#include <string.h> |
32 |
+ |
#include <vector> |
33 |
+ |
|
34 |
+ |
#ifndef NO_STD_NAMESPACE |
35 |
+ |
using std::vector; |
36 |
+ |
#endif |
37 |
|
|
38 |
|
#include "sysdeps.h" |
39 |
|
#include "cpu_emulation.h" |
104 |
|
|
105 |
|
|
106 |
|
// Struct for each drive |
107 |
< |
struct DriveInfo { |
108 |
< |
DriveInfo() |
109 |
< |
{ |
110 |
< |
next = NULL; |
111 |
< |
num = 0; |
107 |
< |
fh = NULL; |
108 |
< |
read_only = false; |
109 |
< |
status = 0; |
110 |
< |
} |
107 |
> |
struct sony_drive_info { |
108 |
> |
sony_drive_info() : num(0), fh(NULL), read_only(false), status(0) {} |
109 |
> |
sony_drive_info(void *fh_, bool ro) : num(0), fh(fh_), read_only(ro), status(0) {} |
110 |
> |
|
111 |
> |
void close_fh(void) { Sys_close(fh); } |
112 |
|
|
112 |
– |
DriveInfo *next; // Pointer to next DriveInfo (must be first in struct!) |
113 |
|
int num; // Drive number |
114 |
|
void *fh; // Floppy driver file handle |
115 |
|
bool to_be_mounted; // Flag: drive must be mounted in accRun |
118 |
|
uint32 status; // Mac address of drive status record |
119 |
|
}; |
120 |
|
|
121 |
< |
// Linked list of DriveInfos |
122 |
< |
static DriveInfo *first_drive_info; |
121 |
> |
// List of drives handled by this driver |
122 |
> |
typedef vector<sony_drive_info> drive_vec; |
123 |
> |
static drive_vec drives; |
124 |
|
|
125 |
|
// Icon addresses (Mac address space, set by PatchROM()) |
126 |
|
uint32 SonyDiskIconAddr; |
131 |
|
|
132 |
|
|
133 |
|
/* |
134 |
< |
* Get pointer to drive info, NULL = invalid drive number |
134 |
> |
* Get reference to drive info or drives.end() if not found |
135 |
|
*/ |
136 |
|
|
137 |
< |
static DriveInfo *get_drive_info(int num) |
137 |
> |
static drive_vec::iterator get_drive_info(int num) |
138 |
|
{ |
139 |
< |
DriveInfo *info = first_drive_info; |
140 |
< |
while (info != NULL) { |
139 |
> |
drive_vec::iterator info, end = drives.end(); |
140 |
> |
for (info = drives.begin(); info != end; ++info) { |
141 |
|
if (info->num == num) |
142 |
|
return info; |
142 |
– |
info = info->next; |
143 |
|
} |
144 |
< |
return NULL; |
144 |
> |
return info; |
145 |
|
} |
146 |
|
|
147 |
|
|
151 |
|
|
152 |
|
void SonyInit(void) |
153 |
|
{ |
154 |
– |
first_drive_info = NULL; |
155 |
– |
|
154 |
|
// No drives specified in prefs? Then add defaults |
155 |
|
if (PrefsFindString("floppy", 0) == NULL) |
156 |
|
SysAddFloppyPrefs(); |
157 |
|
|
158 |
|
// Add drives specified in preferences |
159 |
< |
int32 index = 0; |
159 |
> |
int index = 0; |
160 |
|
const char *str; |
161 |
|
while ((str = PrefsFindString("floppy", index++)) != NULL) { |
162 |
|
bool read_only = false; |
165 |
|
str++; |
166 |
|
} |
167 |
|
void *fh = Sys_open(str, read_only); |
168 |
< |
if (fh) { |
169 |
< |
DriveInfo *info = new DriveInfo; |
172 |
< |
info->fh = fh; |
173 |
< |
info->read_only = SysIsReadOnly(fh); |
174 |
< |
DriveInfo *p = (DriveInfo *)&first_drive_info; |
175 |
< |
while (p->next != NULL) |
176 |
< |
p = p->next; |
177 |
< |
p->next = info; |
178 |
< |
} |
168 |
> |
if (fh) |
169 |
> |
drives.push_back(sony_drive_info(fh, SysIsReadOnly(fh))); |
170 |
|
} |
171 |
|
} |
172 |
|
|
177 |
|
|
178 |
|
void SonyExit(void) |
179 |
|
{ |
180 |
< |
DriveInfo *info = first_drive_info, *next; |
181 |
< |
while (info != NULL) { |
182 |
< |
Sys_close(info->fh); |
183 |
< |
next = info->next; |
193 |
< |
delete info; |
194 |
< |
info = next; |
195 |
< |
} |
180 |
> |
drive_vec::iterator info, end = drives.end(); |
181 |
> |
for (info = drives.begin(); info != end; ++info) |
182 |
> |
info->close_fh(); |
183 |
> |
drives.clear(); |
184 |
|
} |
185 |
|
|
186 |
|
|
190 |
|
|
191 |
|
bool SonyMountVolume(void *fh) |
192 |
|
{ |
193 |
< |
DriveInfo *info; |
194 |
< |
for (info = first_drive_info; info != NULL && info->fh != fh; info = info->next) ; |
195 |
< |
if (info) { |
193 |
> |
drive_vec::iterator info = drives.begin(), end = drives.end(); |
194 |
> |
while (info != end && info->fh != fh) |
195 |
> |
++info; |
196 |
> |
if (info != end) { |
197 |
|
if (SysIsDiskInserted(info->fh)) { |
198 |
|
info->read_only = SysIsReadOnly(info->fh); |
199 |
|
WriteMacInt8(info->status + dsDiskInPlace, 1); // Inserted removable disk |
213 |
|
|
214 |
|
static void mount_mountable_volumes(void) |
215 |
|
{ |
216 |
< |
DriveInfo *info = first_drive_info; |
217 |
< |
while (info != NULL) { |
216 |
> |
drive_vec::iterator info, end = drives.end(); |
217 |
> |
for (info = drives.begin(); info != end; ++info) { |
218 |
|
|
219 |
|
#if DISK_INSERT_CHECK |
220 |
|
// Disk in drive? |
235 |
|
Execute68kTrap(0xa02f, &r); // PostEvent() |
236 |
|
info->to_be_mounted = false; |
237 |
|
} |
249 |
– |
|
250 |
– |
info = info->next; |
238 |
|
} |
239 |
|
} |
240 |
|
|
274 |
|
set_dsk_err(0); |
275 |
|
|
276 |
|
// Install drives |
277 |
< |
for (DriveInfo *info = first_drive_info; info; info = info->next) { |
277 |
> |
drive_vec::iterator info, end = drives.end(); |
278 |
> |
for (info = drives.begin(); info != end; ++info) { |
279 |
|
|
280 |
|
info->num = FindFreeDriveNumber(1); |
281 |
|
info->to_be_mounted = false; |
329 |
|
WriteMacInt32(pb + ioActCount, 0); |
330 |
|
|
331 |
|
// Drive valid and disk inserted? |
332 |
< |
DriveInfo *info; |
333 |
< |
if ((info = get_drive_info(ReadMacInt16(pb + ioVRefNum))) == NULL) |
332 |
> |
drive_vec::iterator info = get_drive_info(ReadMacInt16(pb + ioVRefNum)); |
333 |
> |
if (info == drives.end()) |
334 |
|
return set_dsk_err(nsDrvErr); |
335 |
|
if (!ReadMacInt8(info->status + dsDiskInPlace)) |
336 |
|
return set_dsk_err(offLinErr); |
399 |
|
} |
400 |
|
|
401 |
|
// Drive valid? |
402 |
< |
DriveInfo *info; |
403 |
< |
if ((info = get_drive_info(ReadMacInt16(pb + ioVRefNum))) == NULL) |
402 |
> |
drive_vec::iterator info = get_drive_info(ReadMacInt16(pb + ioVRefNum)); |
403 |
> |
if (info == drives.end()) |
404 |
|
return set_dsk_err(nsDrvErr); |
405 |
|
|
406 |
|
// Drive-specific codes |
480 |
|
D(bug("SonyStatus %d\n", code)); |
481 |
|
|
482 |
|
// Drive valid? |
483 |
< |
DriveInfo *info; |
484 |
< |
if ((info = get_drive_info(ReadMacInt16(pb + ioVRefNum))) == NULL) |
483 |
> |
drive_vec::iterator info = get_drive_info(ReadMacInt16(pb + ioVRefNum)); |
484 |
> |
if (info == drives.end()) |
485 |
|
return set_dsk_err(nsDrvErr); |
486 |
|
|
487 |
|
int16 err = noErr; |