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

Comparing BasiliskII/src/Unix/sys_unix.cpp (file contents):
Revision 1.18 by cebix, 2002-04-28T14:06:17Z vs.
Revision 1.20 by gbeauche, 2003-10-12T21:55:44Z

# Line 1 | Line 1
1   /*
2   *  sys_unix.cpp - System dependent routines, Unix implementation
3   *
4 < *  Basilisk II (C) 1997-2002 Christian Bauer
4 > *  Basilisk II (C) 1997-2003 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
# Line 77 | Line 77 | struct file_handle {
77          int cdrom_cap;          // CD-ROM capability flags (only valid if is_cdrom is true)
78   #elif defined(__FreeBSD__)
79          struct ioc_capability cdrom_cap;
80 + #elif defined(__APPLE__) && defined(__MACH__)
81 +        char    *ioctl_name;    // For CDs on OS X - a device for special ioctls
82 +        int             ioctl_fd;
83   #endif
84   };
85  
# Line 141 | Line 144 | void SysAddFloppyPrefs(void)
144   #elif defined(__NetBSD__)
145          PrefsAddString("floppy", "/dev/fd0a");
146          PrefsAddString("floppy", "/dev/fd1a");
147 + #elif defined(__APPLE__) && defined(__MACH__)
148 +        // FIXME: We assume an Aqua build causes <AvailabilityMacros.h> to
149 +        // be included, thusly enabling this part of code that would cause
150 +        // Basilisk II to hang otherwise.
151 + #ifdef MAC_OS_X_VERSION_10_0
152 +        PrefsAddString("floppy", "/dev/fd/0");
153 +        PrefsAddString("floppy", "/dev/fd/1");
154 + #endif
155   #else
156          PrefsAddString("floppy", "/dev/fd0");
157          PrefsAddString("floppy", "/dev/fd1");
# Line 151 | Line 162 | void SysAddFloppyPrefs(void)
162   /*
163   *  This gets called when no "disk" prefs items are found
164   *  It scans for available HFS volumes and adds appropriate prefs items
165 + *      On OS X, we could do the same, but on an OS X machine I think it is
166 + *      very unlikely that any mounted volumes would contain a system which
167 + *      is old enough to boot a 68k Mac, so we just do nothing here for now.
168   */
169  
170   void SysAddDiskPrefs(void)
# Line 208 | Line 222 | void SysAddCDROMPrefs(void)
222                          closedir(cd_dir);
223                  }
224          }
225 + #elif defined(__APPLE__) && defined(__MACH__) && defined(MAC_OS_X_VERSION_10_0)
226 +        extern  void DarwinAddCDROMPrefs(void);
227 +
228 +        DarwinAddCDROMPrefs();
229   #elif defined(__FreeBSD__) || defined(__NetBSD__)
230          PrefsAddString("cdrom", "/dev/cd0c");
231   #endif
# Line 234 | Line 252 | void SysAddSerialPrefs(void)
252   #elif defined(__NetBSD__)
253          PrefsAddString("seriala", "/dev/tty00");
254          PrefsAddString("serialb", "/dev/tty01");
255 + #elif defined(__APPLE__) && defined(__MACH__)
256 +        // FIXME: We assume an Aqua build causes <AvailabilityMacros.h> to
257 +        // be included, thusly enabling this part of code that would cause
258 +        // Basilisk II to hang otherwise.
259 + #ifdef MAC_OS_X_VERSION_10_0
260 +        PrefsAddString("seriala", "/dev/ttys0");
261 +        PrefsAddString("serialb", "/dev/ttys1");
262 + #endif
263 + //      PrefsAddString("seriala", "/dev/cu.modem");
264 + //      PrefsAddString("serialb", "/dev/cu.IrDA-IrCOMMch-b");
265   #endif
266   }
267  
# Line 286 | Line 314 | void *Sys_open(const char *name, bool re
314          bool is_cdrom = strncmp(name, "/dev/cd", 7) == 0;
315   #endif
316  
317 + #if defined(__APPLE__) && defined(__MACH__)
318 +        //
319 +        // There is no set filename in /dev which is the cdrom,
320 +        // so we have to see if it is any of the devices that we found earlier
321 +        //
322 +        const char      *cdrom;
323 +        int                     tmp = 0;
324 +
325 +        while ( (cdrom = PrefsFindString("cdrom", tmp) ) != NULL )
326 +        {
327 +                if ( strcmp(name, cdrom) == 0 )
328 +                {
329 +                        is_cdrom = 1;
330 +                        read_only = 1;
331 +                        break;
332 +                }
333 +                ++tmp;
334 +        }
335 + #endif
336 +
337          D(bug("Sys_open(%s, %s)\n", name, read_only ? "read-only" : "read/write"));
338  
339          // Check if write access is allowed, set read-only flag if not
# Line 368 | Line 416 | void *Sys_open(const char *name, bool re
416                                          fh->is_floppy = ((st.st_rdev >> 16) == 2);
417   #endif
418                                  }
419 + #if defined(__APPLE__) && defined(__MACH__)
420 +
421 +                                // In OS X, the device name is OK for sending ioctls to,
422 +                                // but not for reading raw CDROM data from.
423 +                                // (it seems to have extra data padded in)
424 +                                //
425 +                                // So, we keep the already opened fiole handle,
426 +                                // and open a slightly different file for CDROM data
427 +                                //
428 +                                if ( is_cdrom )
429 +                                {
430 +                                        fh->ioctl_name  = fh->name;
431 +                                        fh->ioctl_fd    = fh->fd;
432 +
433 +                                        fh->name = (char *) malloc(strlen(name) + 2);
434 +                                        if ( fh->name )
435 +                                        {
436 +                                                *fh->name = '\0';
437 +                                                strcat(fh->name, name);
438 +                                                strcat(fh->name, "s1");
439 +                                                fh->fd = open(fh->name, (read_only ? O_RDONLY : O_RDWR));
440 +                                                if ( fh->fd < 0 ) {
441 +                                                        printf("WARNING: Cannot open %s (%s)\n",
442 +                                                                                        fh->name, strerror(errno));
443 +                                                        return NULL;
444 +                                                }
445 +                                        }
446 +                                }
447 + #endif
448                          }
449                  }
450                  if (fh->is_floppy && first_floppy == NULL)
# Line 505 | Line 582 | void SysEject(void *arg)
582                  close(fh->fd);  // Close and reopen so the driver will see the media change
583                  fh->fd = open(fh->name, O_RDONLY | O_NONBLOCK);
584          }
585 + #elif defined(__APPLE__) && defined(__MACH__)
586 +        if ( fh->is_cdrom ) {
587 +
588 +                // Stolen from IOKit/storage/IOMediaBSDClient.h
589 +                #define DKIOCEJECT _IO('d', 21)
590 +
591 +                close(fh->fd);
592 +                if ( ioctl(fh->ioctl_fd, DKIOCEJECT) < 0 )
593 +                {
594 +                        printf("ioctl(DKIOCEJECT) failed on file %s: %s\n",
595 +                                                                fh->ioctl_name, strerror(errno));
596 +
597 +                        // If we are running OSX, the device may be is busy
598 +                        // due to the Finder having the disk mounted and open,
599 +                        // so we have to use another method.
600 +
601 +                        // The only problem is that this takes about 5 seconds:
602 +
603 +                        char    *cmd = (char *) malloc(30+sizeof(fh->name));
604 +
605 +                        if ( ! cmd )
606 +                                return;
607 +                        close(fh->ioctl_fd);
608 +                        sprintf(cmd, "diskutil eject %s 2>&1 >/dev/null", fh->name);
609 +                        system(cmd);
610 +                }
611 +        }
612   #endif
613   }
614  
# Line 711 | Line 815 | bool SysCDReadTOC(void *arg, uint8 *toc)
815                  *toc++ = toc_size >> 8;
816                  *toc++ = toc_size & 0xff;
817                  return true;
818 + #elif defined(__APPLE__) && defined(__MACH__) && defined(MAC_OS_X_VERSION_10_2)
819 +                extern  bool    DarwinCDReadTOC(char *name, uint8 *toc);
820 +
821 +                return  DarwinCDReadTOC(fh->name, toc);
822   #elif defined(__FreeBSD__)
823                  uint8 *p = toc + 2;
824  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines