ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/slot_rom.cpp
Revision: 1.6
Committed: 2001-06-27T20:05:23Z (23 years, 4 months ago) by cebix
Branch: MAIN
Changes since 1.5: +25 -29 lines
Log Message:
depth/resolution switching infrastructure should be complete now; slot ROM
contains all supported depths, default mode is stored in XPRAM upon startup,
and added video_switch_to_mode() call (currently unimplemented in all drivers)

File Contents

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