1 |
/* |
2 |
* slot_rom.cpp - Slot declaration ROM |
3 |
* |
4 |
* Basilisk II (C) 1996-1997 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 |
/* |
22 |
* SEE ALSO |
23 |
* Inside Macintosh: Devices, chapter 2 "Slot Manager" |
24 |
* Designing Cards and Drivers for the Macintosh Family, Second Edition |
25 |
*/ |
26 |
|
27 |
#include <stdio.h> |
28 |
#include <string.h> |
29 |
|
30 |
#include "sysdeps.h" |
31 |
#include "cpu_emulation.h" |
32 |
#include "main.h" |
33 |
#include "video.h" |
34 |
#include "emul_op.h" |
35 |
#include "version.h" |
36 |
#include "slot_rom.h" |
37 |
|
38 |
|
39 |
// Temporary buffer for slot ROM |
40 |
static uint8 srom[4096]; |
41 |
|
42 |
// Index in srom |
43 |
static uint32 p; |
44 |
|
45 |
|
46 |
/* |
47 |
* Construct slot declaration ROM and copy it into the Mac ROM (must be called after VideoInit()) |
48 |
*/ |
49 |
|
50 |
static void Offs(uint8 type, uint32 ptr) |
51 |
{ |
52 |
uint32 offs = ptr - p; |
53 |
srom[p++] = type; |
54 |
srom[p++] = offs >> 16; |
55 |
srom[p++] = offs >> 8; |
56 |
srom[p++] = offs; |
57 |
} |
58 |
|
59 |
static void Rsrc(uint8 type, uint32 data) |
60 |
{ |
61 |
srom[p++] = type; |
62 |
srom[p++] = data >> 16; |
63 |
srom[p++] = data >> 8; |
64 |
srom[p++] = data; |
65 |
} |
66 |
|
67 |
static void EndOfList(void) |
68 |
{ |
69 |
srom[p++] = 0xff; |
70 |
srom[p++] = 0; |
71 |
srom[p++] = 0; |
72 |
srom[p++] = 0; |
73 |
} |
74 |
|
75 |
static void Long(uint32 data) |
76 |
{ |
77 |
srom[p++] = data >> 24; |
78 |
srom[p++] = data >> 16; |
79 |
srom[p++] = data >> 8; |
80 |
srom[p++] = data; |
81 |
} |
82 |
|
83 |
static void Word(uint16 data) |
84 |
{ |
85 |
srom[p++] = data >> 8; |
86 |
srom[p++] = data; |
87 |
} |
88 |
|
89 |
static void String(char *str) |
90 |
{ |
91 |
while ((srom[p++] = *str++) != 0) ; |
92 |
if (p & 1) |
93 |
srom[p++] = 0; |
94 |
} |
95 |
|
96 |
static void PString(char *str) |
97 |
{ |
98 |
srom[p++] = strlen(str); |
99 |
while ((srom[p++] = *str++) != 0) ; |
100 |
p--; |
101 |
if (p & 1) |
102 |
srom[p++] = 0; |
103 |
} |
104 |
|
105 |
bool InstallSlotROM(void) |
106 |
{ |
107 |
uint32 boardType, boardName, vendorID, revLevel, partNum, date; |
108 |
uint32 vendorInfo, sRsrcBoard; |
109 |
|
110 |
uint32 videoType, videoName, minorBase, minorLength, videoDrvr, vidDrvrDir; |
111 |
uint32 defaultGamma, gammaDir, vidModeParms, vidMode, sRsrcVideo; |
112 |
|
113 |
uint32 cpuType, cpuName, cpuMajor, cpuMinor, sRsrcCPU; |
114 |
|
115 |
uint32 etherType, etherName, etherDrvr, etherDrvrDir, sRsrcEther; |
116 |
|
117 |
uint32 sRsrcDir; |
118 |
|
119 |
char str[256]; |
120 |
p = 0; |
121 |
|
122 |
// Board sResource |
123 |
boardType = p; // Literals |
124 |
Word(1); Word(0); Word(0); Word(0); // Board sResource |
125 |
boardName = p; |
126 |
String("Basilisk II Slot ROM"); |
127 |
vendorID = p; |
128 |
String("Christian Bauer"); |
129 |
revLevel = p; |
130 |
sprintf(str, "V%d.%d", VERSION_MAJOR, VERSION_MINOR); |
131 |
String(str); |
132 |
partNum = p; |
133 |
String("BasiliskII"); |
134 |
date = p; |
135 |
String(__DATE__); |
136 |
|
137 |
vendorInfo = p; // Vendor Info |
138 |
Offs(0x01, vendorID); // Vendor ID |
139 |
Offs(0x03, revLevel); // Revision level |
140 |
Offs(0x04, partNum); // Part number |
141 |
Offs(0x05, date); // ROM build date |
142 |
EndOfList(); |
143 |
|
144 |
sRsrcBoard = p; |
145 |
Offs(0x01, boardType); // Board descriptor |
146 |
Offs(0x02, boardName); // Board name |
147 |
Rsrc(0x20, 0x4232); // Board ID ('B2') |
148 |
Offs(0x24, vendorInfo); // Vendor Info |
149 |
EndOfList(); |
150 |
|
151 |
// Video sResource |
152 |
videoType = p; // Literals |
153 |
Word(3); Word(1); Word(1); Word(0x4232); // Display Video Apple 'B2' |
154 |
videoName = p; |
155 |
String("Display_Video_Apple_Basilisk"); |
156 |
minorBase = p; |
157 |
Long(VideoMonitor.mac_frame_base); // Frame buffer base |
158 |
minorLength = p; |
159 |
Long(VideoMonitor.bytes_per_row * VideoMonitor.y); // Frame buffer size |
160 |
|
161 |
videoDrvr = p; // Video driver |
162 |
Long(0x72); // Length |
163 |
Word(0x4c00); Word(0); Word(0); Word(0); |
164 |
Word(0x32); // Open offset |
165 |
Word(0x36); // Prime offset |
166 |
Word(0x3a); // Control offset |
167 |
Word(0x46); // Status offset |
168 |
Word(0x6c); // Close offset |
169 |
PString(".Display_Video_Apple_Basilisk"); |
170 |
Word(1); // Driver version |
171 |
Word(M68K_EMUL_OP_VIDEO_OPEN); // Open() |
172 |
Word(0x4e75); |
173 |
Word(0x70ff); // Prime() |
174 |
Word(0x600e); |
175 |
Word(M68K_EMUL_OP_VIDEO_CONTROL); // Control() |
176 |
Word(0x0c68); Word(0x0001); Word(0x001a); |
177 |
Word(0x6604); |
178 |
Word(0x4e75); |
179 |
Word(M68K_EMUL_OP_VIDEO_STATUS); // Status() |
180 |
Word(0x3228); Word(0x0006); // IOReturn |
181 |
Word(0x0801); Word(0x0009); |
182 |
Word(0x670c); |
183 |
Word(0x4a40); |
184 |
Word(0x6f02); |
185 |
Word(0x4240); |
186 |
Word(0x3140); Word(0x0010); |
187 |
Word(0x4e75); |
188 |
Word(0x4a40); |
189 |
Word(0x6f04); |
190 |
Word(0x4240); |
191 |
Word(0x4e75); |
192 |
Word(0x2f38); Word(0x08fc); |
193 |
Word(0x4e75); |
194 |
Word(0x70e8); // Close() |
195 |
Word(0x4e75); |
196 |
|
197 |
vidDrvrDir = p; // Driver directory |
198 |
Offs(0x02, videoDrvr); // sMacOS68020 |
199 |
EndOfList(); |
200 |
|
201 |
defaultGamma = p; // Gamma table |
202 |
Long(38 + 0x100); // Length |
203 |
Word(0x2000); // Resource ID |
204 |
String("Mac HiRes Std Gamma"); |
205 |
Word(0); // Version |
206 |
Word(0); // Type |
207 |
Word(0); // FormulaSize |
208 |
Word(1); // ChanCnt |
209 |
Word(0x0100); // DataCnt |
210 |
Word(8); // ChanWidth |
211 |
Long(0x0005090B); Long(0x0E101315); Long(0x17191B1D); Long(0x1E202224); |
212 |
Long(0x2527282A); Long(0x2C2D2F30); Long(0x31333436); Long(0x37383A3B); |
213 |
Long(0x3C3E3F40); Long(0x42434445); Long(0x4748494A); Long(0x4B4D4E4F); |
214 |
Long(0x50515254); Long(0x55565758); Long(0x595A5B5C); Long(0x5E5F6061); |
215 |
Long(0x62636465); Long(0x66676869); Long(0x6A6B6C6D); Long(0x6E6F7071); |
216 |
Long(0x72737475); Long(0x76777879); Long(0x7A7B7C7D); Long(0x7E7F8081); |
217 |
Long(0x81828384); Long(0x85868788); Long(0x898A8B8C); Long(0x8C8D8E8F); |
218 |
Long(0x90919293); Long(0x94959596); Long(0x9798999A); Long(0x9B9B9C9D); |
219 |
Long(0x9E9FA0A1); Long(0xA1A2A3A4); Long(0xA5A6A6A7); Long(0xA8A9AAAB); |
220 |
Long(0xABACADAE); Long(0xAFB0B0B1); Long(0xB2B3B4B4); Long(0xB5B6B7B8); |
221 |
Long(0xB8B9BABB); Long(0xBCBCBDBE); Long(0xBFC0C0C1); Long(0xC2C3C3C4); |
222 |
Long(0xC5C6C7C7); Long(0xC8C9CACA); Long(0xCBCCCDCD); Long(0xCECFD0D0); |
223 |
Long(0xD1D2D3D3); Long(0xD4D5D6D6); Long(0xD7D8D9D9); Long(0xDADBDCDC); |
224 |
Long(0xDDDEDFDF); Long(0xE0E1E1E2); Long(0xE3E4E4E5); Long(0xE6E7E7E8); |
225 |
Long(0xE9E9EAEB); Long(0xECECEDEE); Long(0xEEEFF0F1); Long(0xF1F2F3F3); |
226 |
Long(0xF4F5F5F6); Long(0xF7F8F8F9); Long(0xFAFAFBFC); Long(0xFCFDFEFF); |
227 |
|
228 |
gammaDir = p; // Gamma directory |
229 |
Offs(0x80, defaultGamma); |
230 |
EndOfList(); |
231 |
|
232 |
vidModeParms = p; // Video mode parameters |
233 |
Long(50); // Length |
234 |
Long(0); // Base offset |
235 |
Word(VideoMonitor.bytes_per_row); // Row bytes |
236 |
Word(0); // Bounds |
237 |
Word(0); |
238 |
Word(VideoMonitor.y); |
239 |
Word(VideoMonitor.x); |
240 |
Word(0); // Version |
241 |
Word(0); // Pack type |
242 |
Long(0); // Pack size |
243 |
Long(0x00480000); // HRes |
244 |
Long(0x00480000); // VRes |
245 |
switch (VideoMonitor.mode) { |
246 |
case VMODE_1BIT: |
247 |
Word(0); // Pixel type (indirect) |
248 |
Word(1); // Pixel size |
249 |
Word(1); // CmpCount |
250 |
Word(1); // CmpSize |
251 |
break; |
252 |
case VMODE_2BIT: |
253 |
Word(0); // Pixel type (indirect) |
254 |
Word(2); // Pixel size |
255 |
Word(1); // CmpCount |
256 |
Word(2); // CmpSize |
257 |
break; |
258 |
case VMODE_4BIT: |
259 |
Word(0); // Pixel type (indirect) |
260 |
Word(4); // Pixel size |
261 |
Word(1); // CmpCount |
262 |
Word(4); // CmpSize |
263 |
break; |
264 |
case VMODE_8BIT: |
265 |
Word(0); // Pixel type (indirect) |
266 |
Word(8); // Pixel size |
267 |
Word(1); // CmpCount |
268 |
Word(8); // CmpSize |
269 |
break; |
270 |
case VMODE_16BIT: |
271 |
Word(16); // Pixel type (direct) |
272 |
Word(16); // Pixel size |
273 |
Word(3); // CmpCount |
274 |
Word(5); // CmpSize |
275 |
break; |
276 |
case VMODE_32BIT: |
277 |
Word(16); // Pixel type (direct) |
278 |
Word(32); // Pixel size |
279 |
Word(3); // CmpCount |
280 |
Word(8); // CmpSize |
281 |
break; |
282 |
} |
283 |
Long(0); // Plane size |
284 |
Long(0); // Reserved |
285 |
|
286 |
vidMode = p; // Video mode description |
287 |
Offs(0x01, vidModeParms); // Video parameters |
288 |
Rsrc(0x03, 1); // Page count |
289 |
Rsrc(0x04, IsDirectMode(VideoMonitor.mode) ? 2 :0); // Device type |
290 |
EndOfList(); |
291 |
|
292 |
sRsrcVideo = p; |
293 |
Offs(0x01, videoType); // Video type descriptor |
294 |
Offs(0x02, videoName); // Driver name |
295 |
Offs(0x04, vidDrvrDir); // Driver directory |
296 |
Rsrc(0x08, 0x4232); // Hardware device ID ('B2') |
297 |
Offs(0x0a, minorBase); // Frame buffer base |
298 |
Offs(0x0b, minorLength); // Frame buffer length |
299 |
Offs(0x40, gammaDir); // Gamma directory |
300 |
Rsrc(0x7d, 6); // Video attributes: Default to color, built-in |
301 |
Offs(0x80, vidMode); // Video mode parameters |
302 |
EndOfList(); |
303 |
|
304 |
// CPU sResource |
305 |
cpuType = p; // Literals |
306 |
Word(10); Word(3); Word(0); Word(24); // CPU 68020 |
307 |
cpuName = p; |
308 |
String("CPU_68020"); |
309 |
cpuMajor = p; |
310 |
Long(0); Long(0x7fffffff); |
311 |
cpuMinor = p; |
312 |
Long(0xf0800000); Long(0xf0ffffff); |
313 |
|
314 |
sRsrcCPU = p; |
315 |
Offs(0x01, cpuType); // Type descriptor |
316 |
Offs(0x02, cpuName); // CPU name |
317 |
Offs(0x81, cpuMajor); // Major RAM space |
318 |
Offs(0x82, cpuMinor); // Minor RAM space |
319 |
EndOfList(); |
320 |
|
321 |
// Ethernet sResource |
322 |
etherType = p; // Literals |
323 |
Word(4); Word(1); Word(1); Word(0x4232); // Network Ethernet Apple 'B2' |
324 |
etherName = p; |
325 |
String("Network_Ethernet_Apple_BasiliskII"); |
326 |
|
327 |
etherDrvr = p; // Video driver |
328 |
Long(0x88); // Length |
329 |
Word(0x4400); Word(0); Word(0); Word(0); |
330 |
Word(0x4a); // Open offset |
331 |
Word(0x4e); // Prime offset |
332 |
Word(0x52); // Control offset |
333 |
Word(0x4e); // Status offset |
334 |
Word(0x82); // Close offset |
335 |
PString(".ENET"); |
336 |
Word(0x0111); Word(0x8000); // Driver version |
337 |
Word(0); |
338 |
PString("1.1.1 "); |
339 |
PString("Basilisk II Ethernet Network Driver"); |
340 |
Word(M68K_EMUL_OP_ETHER_OPEN); // Open() |
341 |
Word(0x4e75); |
342 |
Word(0x70ef); // Prime()/Status() |
343 |
Word(0x600c); |
344 |
Word(M68K_EMUL_OP_ETHER_CONTROL); // Control() |
345 |
Word(0x0c68); Word(0x0001); Word(0x001a); |
346 |
Word(0x6602); |
347 |
Word(0x4e75); |
348 |
Word(0x3228); Word(0x0006); // IOReturn |
349 |
Word(0x0801); Word(0x0009); |
350 |
Word(0x670c); |
351 |
Word(0x4a40); |
352 |
Word(0x6f02); |
353 |
Word(0x4240); |
354 |
Word(0x3140); Word(0x0010); |
355 |
Word(0x4e75); |
356 |
Word(0x4a40); |
357 |
Word(0x6f04); |
358 |
Word(0x4240); |
359 |
Word(0x4e75); |
360 |
Word(0x2f38); Word(0x08fc); |
361 |
Word(0x4e75); |
362 |
Word(0x70e8); // Close() |
363 |
Word(0x4e75); |
364 |
|
365 |
etherDrvrDir = p; // Driver directory |
366 |
Offs(0x02, etherDrvr); // sMacOS68020 |
367 |
EndOfList(); |
368 |
|
369 |
sRsrcEther = p; |
370 |
Offs(0x01, etherType); // Type descriptor |
371 |
Offs(0x02, etherName); // Driver name |
372 |
Offs(0x04, etherDrvrDir); // Driver directory |
373 |
Rsrc(0x07, 2); // Flags: OpenAtStart |
374 |
Rsrc(0x08, 0x4232); // Hardware device ID ('B2') |
375 |
EndOfList(); |
376 |
|
377 |
// sResource directory |
378 |
sRsrcDir = p; |
379 |
Offs(0x01, sRsrcBoard); |
380 |
Offs(0x80, sRsrcVideo); |
381 |
Offs(0xf0, sRsrcCPU); |
382 |
Offs(0xf1, sRsrcEther); |
383 |
EndOfList(); |
384 |
|
385 |
// Format/header block |
386 |
Offs(0, sRsrcDir); // sResource directory |
387 |
Long(p + 16); // Length of declaration data |
388 |
Long(0); // CRC (calculated below) |
389 |
Word(0x0101); // Rev. level, format |
390 |
Long(0x5a932bc7); // Test pattern |
391 |
Word(0x000f); // Byte lanes |
392 |
|
393 |
// Calculate CRC |
394 |
uint32 crc = 0; |
395 |
for (uint32 i=0; i<p; i++) { |
396 |
crc = (crc << 1) | (crc >> 31); |
397 |
crc += srom[i]; |
398 |
} |
399 |
srom[p - 12] = crc >> 24; |
400 |
srom[p - 11] = crc >> 16; |
401 |
srom[p - 10] = crc >> 8; |
402 |
srom[p - 9] = crc; |
403 |
|
404 |
// Copy slot ROM to Mac ROM |
405 |
memcpy(ROMBaseHost + ROMSize - p, srom, p); |
406 |
return true; |
407 |
} |