1 |
/* |
2 |
* macos_util.cpp - MacOS definitions/utility functions |
3 |
* |
4 |
* Basilisk II (C) 1997-2000 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 |
8 |
* the Free Software Foundation; either version 2 of the License, or |
9 |
* (at your option) any later version. |
10 |
* |
11 |
* This program is distributed in the hope that it will be useful, |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
* GNU General Public License for more details. |
15 |
* |
16 |
* You should have received a copy of the GNU General Public License |
17 |
* along with this program; if not, write to the Free Software |
18 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 |
*/ |
20 |
|
21 |
#include "sysdeps.h" |
22 |
#include "cpu_emulation.h" |
23 |
#include "main.h" |
24 |
#include "sony.h" |
25 |
#include "disk.h" |
26 |
#include "cdrom.h" |
27 |
#include "macos_util.h" |
28 |
|
29 |
#define DEBUG 0 |
30 |
#include "debug.h" |
31 |
|
32 |
|
33 |
/* |
34 |
* Enqueue QElem to list |
35 |
*/ |
36 |
|
37 |
void EnqueueMac(uint32 elem, uint32 list) |
38 |
{ |
39 |
WriteMacInt32(elem + qLink, 0); |
40 |
if (!ReadMacInt32(list + qTail)) { |
41 |
WriteMacInt32(list + qHead, elem); |
42 |
WriteMacInt32(list + qTail, elem); |
43 |
} else { |
44 |
WriteMacInt32(ReadMacInt32(list + qTail) + qLink, elem); |
45 |
WriteMacInt32(list + qTail, elem); |
46 |
} |
47 |
} |
48 |
|
49 |
|
50 |
/* |
51 |
* Find first free drive number, starting at num |
52 |
*/ |
53 |
|
54 |
static bool is_drive_number_free(int num) |
55 |
{ |
56 |
uint32 e = ReadMacInt32(0x308 + qHead); |
57 |
while (e) { |
58 |
uint32 d = e - dsQLink; |
59 |
if ((int)ReadMacInt16(d + dsQDrive) == num) |
60 |
return false; |
61 |
e = ReadMacInt32(e + qLink); |
62 |
} |
63 |
return true; |
64 |
} |
65 |
|
66 |
int FindFreeDriveNumber(int num) |
67 |
{ |
68 |
while (!is_drive_number_free(num)) |
69 |
num++; |
70 |
return num; |
71 |
} |
72 |
|
73 |
|
74 |
/* |
75 |
* Mount volume with given file handle (call this function when you are unable to |
76 |
* do automatic media change detection and the user has to press a special key |
77 |
* or something to mount a volume; this function will check if there's really a |
78 |
* volume in the drive with SysIsDiskInserted(); volumes which are present on startup |
79 |
* are automatically mounted) |
80 |
*/ |
81 |
|
82 |
void MountVolume(void *fh) |
83 |
{ |
84 |
SonyMountVolume(fh) || DiskMountVolume(fh) || CDROMMountVolume(fh); |
85 |
} |
86 |
|
87 |
|
88 |
/* |
89 |
* Test if basic MacOS initializations (of the ROM) are done |
90 |
*/ |
91 |
|
92 |
bool HasMacStarted(void) |
93 |
{ |
94 |
return ReadMacInt32(0xcfc) == 'WLSC'; // Mac warm start flag |
95 |
} |
96 |
|
97 |
|
98 |
/* |
99 |
* Calculate disk image file layout given file size and first 256 data bytes |
100 |
*/ |
101 |
|
102 |
void FileDiskLayout(loff_t size, uint8 *data, loff_t &start_byte, loff_t &real_size) |
103 |
{ |
104 |
if (size == 419284 || size == 838484) { |
105 |
// 400K/800K DiskCopy image, 84 byte header |
106 |
start_byte = 84; |
107 |
real_size = (size - 84) & ~0x1ff; |
108 |
} else { |
109 |
// 0..511 byte header |
110 |
start_byte = size & 0x1ff; |
111 |
real_size = size - start_byte; |
112 |
} |
113 |
} |