ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/macos_util.cpp
Revision: 1.7
Committed: 2001-02-02T20:52:57Z (23 years, 3 months ago) by cebix
Branch: MAIN
CVS Tags: snapshot-17022001, snapshot-29052001, release-0_9-1
Changes since 1.6: +1 -1 lines
Log Message:
- bumped version number to 0.9
- updated copyright dates

File Contents

# Content
1 /*
2 * macos_util.cpp - MacOS definitions/utility functions
3 *
4 * Basilisk II (C) 1997-2001 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 "adb.h"
24 #include "main.h"
25 #include "sony.h"
26 #include "disk.h"
27 #include "cdrom.h"
28 #include "macos_util.h"
29
30 #define DEBUG 0
31 #include "debug.h"
32
33
34 /*
35 * Enqueue QElem to list
36 */
37
38 void EnqueueMac(uint32 elem, uint32 list)
39 {
40 WriteMacInt32(elem + qLink, 0);
41 if (!ReadMacInt32(list + qTail)) {
42 WriteMacInt32(list + qHead, elem);
43 WriteMacInt32(list + qTail, elem);
44 } else {
45 WriteMacInt32(ReadMacInt32(list + qTail) + qLink, elem);
46 WriteMacInt32(list + qTail, elem);
47 }
48 }
49
50
51 /*
52 * Find first free drive number, starting at num
53 */
54
55 static bool is_drive_number_free(int num)
56 {
57 uint32 e = ReadMacInt32(0x308 + qHead);
58 while (e) {
59 uint32 d = e - dsQLink;
60 if ((int)ReadMacInt16(d + dsQDrive) == num)
61 return false;
62 e = ReadMacInt32(e + qLink);
63 }
64 return true;
65 }
66
67 int FindFreeDriveNumber(int num)
68 {
69 while (!is_drive_number_free(num))
70 num++;
71 return num;
72 }
73
74
75 /*
76 * Mount volume with given file handle (call this function when you are unable to
77 * do automatic media change detection and the user has to press a special key
78 * or something to mount a volume; this function will check if there's really a
79 * volume in the drive with SysIsDiskInserted(); volumes which are present on startup
80 * are automatically mounted)
81 */
82
83 void MountVolume(void *fh)
84 {
85 SonyMountVolume(fh) || DiskMountVolume(fh) || CDROMMountVolume(fh);
86 }
87
88
89 /*
90 * Calculate disk image file layout given file size and first 256 data bytes
91 */
92
93 void FileDiskLayout(loff_t size, uint8 *data, loff_t &start_byte, loff_t &real_size)
94 {
95 if (size == 419284 || size == 838484) {
96 // 400K/800K DiskCopy image, 84 byte header
97 start_byte = 84;
98 real_size = (size - 84) & ~0x1ff;
99 } else {
100 // 0..511 byte header
101 start_byte = size & 0x1ff;
102 real_size = size - start_byte;
103 }
104 }
105
106
107 uint32 DebugUtil(uint32 Selector)
108 {
109 switch (Selector)
110 {
111 case duDebuggerGetMax:
112 return 3;
113 case duDebuggerEnter:
114 return 0;
115 case duDebuggerExit:
116 return 0;
117 case duDebuggerPoll:
118 ADBInterrupt();
119 return 0;
120 default:
121 return (uint32) paramErr;
122 }
123 }
124