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

Comparing BasiliskII/src/disk.cpp (file contents):
Revision 1.9 by cebix, 2001-02-02T20:52:57Z vs.
Revision 1.10 by cebix, 2001-07-01T14:38:02Z

# Line 27 | Line 27
27   */
28  
29   #include <string.h>
30 + #include <vector>
31 +
32 + #ifndef NO_STD_NAMESPACE
33 + using std::vector;
34 + #endif
35  
36   #include "sysdeps.h"
37   #include "cpu_emulation.h"
# Line 65 | Line 70 | const uint8 DiskIcon[258] = {
70  
71  
72   // Struct for each drive
73 < struct DriveInfo {
74 <        DriveInfo()
75 <        {
76 <                next = NULL;
77 <                num = 0;
73 <                fh = NULL;
74 <                read_only = false;
75 <                status = 0;
76 <        }
73 > struct disk_drive_info {
74 >        disk_drive_info() : num(0), fh(NULL), read_only(false), status(0) {}
75 >        disk_drive_info(void *fh_, bool ro) : num(0), fh(fh_), read_only(ro), status(0) {}
76 >
77 >        void close_fh(void) { Sys_close(fh); }
78  
78        DriveInfo *next;        // Pointer to next DriveInfo (must be first in struct!)
79          int num;                        // Drive number
80          void *fh;                       // File handle
81          uint32 num_blocks;      // Size in 512-byte blocks
# Line 84 | Line 84 | struct DriveInfo {
84          uint32 status;          // Mac address of drive status record
85   };
86  
87 < // Linked list of DriveInfos
88 < static DriveInfo *first_drive_info;
87 > // List of drives handled by this driver
88 > typedef vector<disk_drive_info> drive_vec;
89 > static drive_vec drives;
90  
91   // Icon address (Mac address space, set by PatchROM())
92   uint32 DiskIconAddr;
# Line 95 | Line 96 | static bool acc_run_called = false;
96  
97  
98   /*
99 < *  Get pointer to drive info, NULL = invalid drive number
99 > *  Get pointer to drive info or drives.end() if not found
100   */
101  
102 < static DriveInfo *get_drive_info(int num)
102 > static drive_vec::iterator get_drive_info(int num)
103   {
104 <        DriveInfo *info = first_drive_info;
105 <        while (info != NULL) {
104 >        drive_vec::iterator info, end = drives.end();
105 >        for (info = drives.begin(); info != end; ++info) {
106                  if (info->num == num)
107                          return info;
107                info = info->next;
108          }
109 <        return NULL;
109 >        return info;
110   }
111  
112  
# Line 116 | Line 116 | static DriveInfo *get_drive_info(int num
116  
117   void DiskInit(void)
118   {
119        first_drive_info = NULL;
120
119          // No drives specified in prefs? Then add defaults
120          if (PrefsFindString("disk", 0) == NULL)
121                  SysAddDiskPrefs();
122  
123          // Add drives specified in preferences
124 <        int32 index = 0;
124 >        int index = 0;
125          const char *str;
126          while ((str = PrefsFindString("disk", index++)) != NULL) {
127                  bool read_only = false;
# Line 132 | Line 130 | void DiskInit(void)
130                          str++;
131                  }
132                  void *fh = Sys_open(str, read_only);
133 <                if (fh) {
134 <                        D(bug(" adding drive '%s'\n", str));
137 <                        DriveInfo *info = new DriveInfo;
138 <                        info->fh = fh;
139 <                        info->read_only = SysIsReadOnly(fh);
140 <                        DriveInfo *p = (DriveInfo *)&first_drive_info;
141 <                        while (p->next != NULL)
142 <                                p = p->next;
143 <                        p->next = info;
144 <                }
133 >                if (fh)
134 >                        drives.push_back(disk_drive_info(fh, SysIsReadOnly(fh)));
135          }
136   }
137  
# Line 152 | Line 142 | void DiskInit(void)
142  
143   void DiskExit(void)
144   {
145 <        DriveInfo *info = first_drive_info, *next;
146 <        while (info != NULL) {
147 <                Sys_close(info->fh);
148 <                next = info->next;
159 <                delete info;
160 <                info = next;
161 <        }
145 >        drive_vec::iterator info, end = drives.end();
146 >        for (info = drives.begin(); info != end; ++info)
147 >                info->close_fh();
148 >        drives.clear();
149   }
150  
151  
# Line 168 | Line 155 | void DiskExit(void)
155  
156   bool DiskMountVolume(void *fh)
157   {
158 <        DriveInfo *info;
159 <        for (info = first_drive_info; info != NULL && info->fh != fh; info = info->next) ;
160 <        if (info) {
158 >        drive_vec::iterator info = drives.begin(), end = drives.end();
159 >        while (info != end && info->fh != fh)
160 >                ++info;
161 >        if (info != end) {
162                  if (SysIsDiskInserted(info->fh)) {
163                          info->read_only = SysIsReadOnly(info->fh);
164                          WriteMacInt8(info->status + dsDiskInPlace, 1);  // Inserted removable disk
# Line 193 | Line 181 | bool DiskMountVolume(void *fh)
181  
182   static void mount_mountable_volumes(void)
183   {
184 <        DriveInfo *info = first_drive_info;
185 <        while (info != NULL) {
184 >        drive_vec::iterator info, end = drives.end();
185 >        for (info = drives.begin(); info != end; ++info) {
186  
187                  // Disk in drive?
188                  if (!ReadMacInt8(info->status + dsDiskInPlace)) {
# Line 213 | Line 201 | static void mount_mountable_volumes(void
201                          Execute68kTrap(0xa02f, &r);             // PostEvent()
202                          info->to_be_mounted = false;
203                  }
216
217                info = info->next;
204          }
205   }
206  
# Line 232 | Line 218 | int16 DiskOpen(uint32 pb, uint32 dce)
218          acc_run_called = false;
219  
220          // Install drives
221 <        for (DriveInfo *info = first_drive_info; info; info = info->next) {
221 >        drive_vec::iterator info, end = drives.end();
222 >        for (info = drives.begin(); info != end; ++info) {
223  
224                  info->num = FindFreeDriveNumber(1);
225                  info->to_be_mounted = false;
# Line 289 | Line 276 | int16 DiskPrime(uint32 pb, uint32 dce)
276          WriteMacInt32(pb + ioActCount, 0);
277  
278          // Drive valid and disk inserted?
279 <        DriveInfo *info;
280 <        if ((info = get_drive_info(ReadMacInt16(pb + ioVRefNum))) == NULL)
279 >        drive_vec::iterator info = get_drive_info(ReadMacInt16(pb + ioVRefNum));
280 >        if (info == drives.end())
281                  return nsDrvErr;
282          if (!ReadMacInt8(info->status + dsDiskInPlace))
283                  return offLinErr;
# Line 352 | Line 339 | int16 DiskControl(uint32 pb, uint32 dce)
339          }
340  
341          // Drive valid?
342 <        DriveInfo *info;
343 <        if ((info = get_drive_info(ReadMacInt16(pb + ioVRefNum))) == NULL)
342 >        drive_vec::iterator info = get_drive_info(ReadMacInt16(pb + ioVRefNum));
343 >        if (info == drives.end())
344                  return nsDrvErr;
345  
346          // Drive-specific codes
# Line 417 | Line 404 | int16 DiskControl(uint32 pb, uint32 dce)
404  
405   int16 DiskStatus(uint32 pb, uint32 dce)
406   {
407 <        DriveInfo *info = get_drive_info(ReadMacInt16(pb + ioVRefNum));
407 >        drive_vec::iterator info = get_drive_info(ReadMacInt16(pb + ioVRefNum));
408          uint16 code = ReadMacInt16(pb + csCode);
409          D(bug("DiskStatus %d\n", code));
410  
411 <        // General codes
411 >        // General codes (we can get these even if the drive was invalid)
412          switch (code) {
413                  case 43: {      // Driver gestalt
414                          uint32 sel = ReadMacInt32(pb + csParam);
# Line 431 | Line 418 | int16 DiskStatus(uint32 pb, uint32 dce)
418                                          WriteMacInt32(pb + csParam + 4, 0x01008000);
419                                          break;
420                                  case FOURCC('d','e','v','t'):   // Device type
421 <                                        if (info != NULL) {
421 >                                        if (info != drives.end()) {
422                                                  if (ReadMacInt8(info->status + dsDiskInPlace) == 8)
423                                                          WriteMacInt32(pb + csParam + 4, FOURCC('d','i','s','k'));
424                                                  else
# Line 446 | Line 433 | int16 DiskStatus(uint32 pb, uint32 dce)
433                                          WriteMacInt32(pb + csParam + 4, 0x01000000);
434                                          break;
435                                  case FOURCC('b','o','o','t'):   // Boot ID
436 <                                        if (info != NULL)
436 >                                        if (info != drives.end())
437                                                  WriteMacInt16(pb + csParam + 4, info->num);
438                                          else
439                                                  WriteMacInt16(pb + csParam + 4, 0);
# Line 475 | Line 462 | int16 DiskStatus(uint32 pb, uint32 dce)
462          }
463  
464          // Drive valid?
465 <        if (info == NULL)
465 >        if (info == drives.end())
466                  return nsDrvErr;
467  
468          // Drive-specific codes

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines