ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/sony.cpp
(Generate patch)

Comparing BasiliskII/src/sony.cpp (file contents):
Revision 1.10 by cebix, 2001-02-10T20:03:55Z vs.
Revision 1.11 by cebix, 2001-07-01T14:38:02Z

# Line 29 | Line 29
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"
# Line 99 | Line 104 | const uint8 SonyDriveIcon[258] = {
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
# Line 118 | Line 118 | struct DriveInfo {
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;
# Line 130 | Line 131 | static bool acc_run_called = false;
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  
# Line 151 | Line 151 | static DriveInfo *get_drive_info(int num
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;
# Line 167 | Line 165 | void SonyInit(void)
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  
# Line 186 | Line 177 | void SonyInit(void)
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  
# Line 202 | Line 190 | void SonyExit(void)
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
# Line 224 | Line 213 | bool SonyMountVolume(void *fh)
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?
# Line 246 | Line 235 | static void mount_mountable_volumes(void
235                          Execute68kTrap(0xa02f, &r);             // PostEvent()
236                          info->to_be_mounted = false;
237                  }
249
250                info = info->next;
238          }
239   }
240  
# Line 287 | Line 274 | int16 SonyOpen(uint32 pb, uint32 dce)
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;
# Line 341 | Line 329 | int16 SonyPrime(uint32 pb, uint32 dce)
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);
# Line 411 | Line 399 | int16 SonyControl(uint32 pb, uint32 dce)
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
# Line 492 | Line 480 | int16 SonyStatus(uint32 pb, uint32 dce)
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;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines