ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/slot_rom.cpp
Revision: 1.13
Committed: 2002-01-15T14:58:32Z (22 years, 10 months ago) by cebix
Branch: MAIN
CVS Tags: snapshot-15012002
Changes since 1.12: +1 -1 lines
Log Message:
- documentation updates
- 2001 -> 2002
- version 0.9 -> 1.0

File Contents

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