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.12 by cebix, 2001-07-15T14:19:06Z

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines