ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/slot_rom.cpp
Revision: 1.5
Committed: 2001-06-27T19:03:35Z (23 years, 5 months ago) by cebix
Branch: MAIN
Changes since 1.4: +115 -63 lines
Log Message:
added infrastructure for resolution/depth switching (currently, all video
drivers only support one mode, the one selected by the user)

File Contents

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