ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/slot_rom.cpp
(Generate patch)

Comparing BasiliskII/src/slot_rom.cpp (file contents):
Revision 1.1.1.1 by cebix, 1999-10-03T14:16:25Z vs.
Revision 1.18 by cebix, 2010-02-21T12:00:01Z

# Line 1 | Line 1
1   /*
2   *  slot_rom.cpp - Slot declaration ROM
3   *
4 < *  Basilisk II (C) 1996-1997 Christian Bauer
4 > *  Basilisk II (C) 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
# Line 42 | Line 42 | static uint8 srom[4096];
42   // Index in srom
43   static uint32 p;
44  
45 + // Length of slot ROM
46 + static int slot_rom_size = 0;
47 +
48  
49   /*
50   *  Construct slot declaration ROM and copy it into the Mac ROM (must be called after VideoInit())
# Line 86 | Line 89 | static void Word(uint16 data)
89          srom[p++] = data;
90   }
91  
92 < static void String(char *str)
92 > static void String(const 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)
99 > static void PString(const char *str)
100   {
101          srom[p++] = strlen(str);
102          while ((srom[p++] = *str++) != 0) ;
# Line 102 | Line 105 | static void PString(char *str)
105                  srom[p++] = 0;
106   }
107  
108 + static uint32 VModeParms(const monitor_desc &m, video_depth depth)
109 + {
110 +        const video_mode &mode = m.get_current_mode();
111 +
112 +        uint32 ret = p;
113 +        Long(50);                                       // Length
114 +        Long(0);                                        // Base offset
115 +        Word(m.get_bytes_per_row(depth, mode.resolution_id));
116 +        Word(0);                                        // Bounds
117 +        Word(0);
118 +        Word(mode.y);
119 +        Word(mode.x);
120 +        Word(0);                                        // Version
121 +        Word(0);                                        // Pack type
122 +        Long(0);                                        // Pack size
123 +        Long(0x00480000);                       // HRes
124 +        Long(0x00480000);                       // VRes
125 +        switch (depth) {
126 +                case VDEPTH_1BIT:
127 +                        Word(0);                        // Pixel type (indirect)
128 +                        Word(1);                        // Pixel size
129 +                        Word(1);                        // CmpCount
130 +                        Word(1);                        // CmpSize
131 +                        break;
132 +                case VDEPTH_2BIT:
133 +                        Word(0);                        // Pixel type (indirect)
134 +                        Word(2);                        // Pixel size
135 +                        Word(1);                        // CmpCount
136 +                        Word(2);                        // CmpSize
137 +                        break;
138 +                case VDEPTH_4BIT:
139 +                        Word(0);                        // Pixel type (indirect)
140 +                        Word(4);                        // Pixel size
141 +                        Word(1);                        // CmpCount
142 +                        Word(4);                        // CmpSize
143 +                        break;
144 +                case VDEPTH_8BIT:
145 +                        Word(0);                        // Pixel type (indirect)
146 +                        Word(8);                        // Pixel size
147 +                        Word(1);                        // CmpCount
148 +                        Word(8);                        // CmpSize
149 +                        break;
150 +                case VDEPTH_16BIT:
151 +                        Word(16);                       // Pixel type (direct)
152 +                        Word(16);                       // Pixel size
153 +                        Word(3);                        // CmpCount
154 +                        Word(5);                        // CmpSize
155 +                        break;
156 +                case VDEPTH_32BIT:
157 +                        Word(16);                       // Pixel type (direct)
158 +                        Word(32);                       // Pixel size
159 +                        Word(3);                        // CmpCount
160 +                        Word(8);                        // CmpSize
161 +                        break;
162 +        }
163 +        Long(0);                                        // Plane size
164 +        Long(0);                                        // Reserved
165 +        return ret;
166 + }
167 +
168 + static uint32 VModeDesc(uint32 params, bool direct)
169 + {
170 +        uint32 ret = p;
171 +        Offs(0x01, params);                     // Video parameters
172 +        Rsrc(0x03, 1);                          // Page count
173 +        Rsrc(0x04, direct ? 2 : 0);     // Device type
174 +        EndOfList();
175 +        return ret;
176 + }
177 +
178 + static uint32 VMonitor(const monitor_desc &m, uint32 videoType, uint32 videoName, uint32 vidDrvrDir, uint32 gammaDir)
179 + {
180 +        uint32 minorBase, minorLength;
181 +        uint32 vidModeParms1, vidModeParms2, vidModeParms4, vidModeParms8, vidModeParms16, vidModeParms32;
182 +        uint32 vidMode1, vidMode2, vidMode4, vidMode8, vidMode16, vidMode32;
183 +        uint32 ret;
184 +
185 +        minorBase = p;
186 +        Long(m.get_mac_frame_base());   // Frame buffer base
187 +        minorLength = p;
188 +        Long(0);                                        // Frame buffer size (unspecified)
189 +
190 +        vidModeParms1 = VModeParms(m, VDEPTH_1BIT);
191 +        vidModeParms2 = VModeParms(m, VDEPTH_2BIT);
192 +        vidModeParms4 = VModeParms(m, VDEPTH_4BIT);
193 +        vidModeParms8 = VModeParms(m, VDEPTH_8BIT);
194 +        vidModeParms16 = VModeParms(m, VDEPTH_16BIT);
195 +        vidModeParms32 = VModeParms(m, VDEPTH_32BIT);
196 +
197 +        vidMode1 = VModeDesc(vidModeParms1, false);
198 +        vidMode2 = VModeDesc(vidModeParms2, false);
199 +        vidMode4 = VModeDesc(vidModeParms4, false);
200 +        vidMode8 = VModeDesc(vidModeParms8, false);
201 +        vidMode16 = VModeDesc(vidModeParms16, true);
202 +        vidMode32 = VModeDesc(vidModeParms32, true);
203 +
204 +        ret = p;
205 +        Offs(0x01, videoType);                          // Video type descriptor
206 +        Offs(0x02, videoName);                          // Driver name
207 +        Offs(0x04, vidDrvrDir);                         // Driver directory
208 +        Rsrc(0x08, 0x4232);                                     // Hardware device ID ('B2')
209 +        Offs(0x0a, minorBase);                          // Frame buffer base
210 +        Offs(0x0b, minorLength);                        // Frame buffer length
211 +        Offs(0x40, gammaDir);                           // Gamma directory
212 +        Rsrc(0x7d, 6);                                          // Video attributes: Default to color, built-in
213 +        if (m.has_depth(VDEPTH_1BIT))
214 +                Offs(m.depth_to_apple_mode(VDEPTH_1BIT), vidMode1);     // Video mode parameters for 1 bit
215 +        if (m.has_depth(VDEPTH_2BIT))
216 +                Offs(m.depth_to_apple_mode(VDEPTH_2BIT), vidMode2);     // Video mode parameters for 2 bit
217 +        if (m.has_depth(VDEPTH_4BIT))
218 +                Offs(m.depth_to_apple_mode(VDEPTH_4BIT), vidMode4);     // Video mode parameters for 4 bit
219 +        if (m.has_depth(VDEPTH_8BIT))
220 +                Offs(m.depth_to_apple_mode(VDEPTH_8BIT), vidMode8);     // Video mode parameters for 8 bit
221 +        if (m.has_depth(VDEPTH_16BIT))
222 +                Offs(m.depth_to_apple_mode(VDEPTH_16BIT), vidMode16);   // Video mode parameters for 16 bit
223 +        if (m.has_depth(VDEPTH_32BIT))
224 +                Offs(m.depth_to_apple_mode(VDEPTH_32BIT), vidMode32);   // Video mode parameters for 32 bit
225 +        EndOfList();
226 +        return ret;
227 + }
228 +
229   bool InstallSlotROM(void)
230   {
231          uint32 boardType, boardName, vendorID, revLevel, partNum, date;
232          uint32 vendorInfo, sRsrcBoard;
233  
234 <        uint32 videoType, videoName, minorBase, minorLength, videoDrvr, vidDrvrDir;
235 <        uint32 defaultGamma, gammaDir, vidModeParms, vidMode, sRsrcVideo;
234 >        uint32 videoType, videoName, videoDrvr, vidDrvrDir;
235 >        uint32 defaultGamma, gammaDir;
236  
237          uint32 cpuType, cpuName, cpuMajor, cpuMinor, sRsrcCPU;
238  
# Line 116 | Line 240 | bool InstallSlotROM(void)
240  
241          uint32 sRsrcDir;
242  
243 +        vector<monitor_desc *>::const_iterator m, mend = VideoMonitors.end();
244 +        vector<uint32> sRsrcVideo;
245 +
246          char str[256];
247 +        int i;
248          p = 0;
249  
250          // Board sResource
# Line 148 | Line 276 | bool InstallSlotROM(void)
276          Offs(0x24, vendorInfo);                         // Vendor Info
277          EndOfList();
278  
279 <        // Video sResource
280 <        videoType = p;                                          // Literals
153 <        Word(3); Word(1); Word(1); Word(0x4232);                        // Display Video Apple 'B2'
279 >        videoType = p;
280 >        Word(3); Word(1); Word(1); Word(0x4232);        // Display Video Apple 'B2'
281          videoName = p;
282          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
283  
284          videoDrvr = p;                                          // Video driver
285          Long(0x72);                                                     // Length
# Line 229 | Line 352 | bool InstallSlotROM(void)
352          Offs(0x80, defaultGamma);
353          EndOfList();
354  
355 <        vidModeParms = p;                                       // Video mode parameters
356 <        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();
355 >        for (m = VideoMonitors.begin(); m != mend; ++m)
356 >                sRsrcVideo.push_back(VMonitor(**m, videoType, videoName, vidDrvrDir, gammaDir));
357  
358          // CPU sResource
359          cpuType = p;                                            // Literals
# Line 377 | Line 431 | bool InstallSlotROM(void)
431          // sResource directory
432          sRsrcDir = p;
433          Offs(0x01, sRsrcBoard);
434 <        Offs(0x80, sRsrcVideo);
434 >        for (m = VideoMonitors.begin(), i = 0; m != mend; ++m, ++i)
435 >                Offs((*m)->get_slot_id(), sRsrcVideo[i]);
436          Offs(0xf0, sRsrcCPU);
437          Offs(0xf1, sRsrcEther);
438          EndOfList();
# Line 385 | Line 440 | bool InstallSlotROM(void)
440          // Format/header block
441          Offs(0, sRsrcDir);                                      // sResource directory
442          Long(p + 16);                                           // Length of declaration data
443 <        Long(0);                                                        // CRC (calculated below)
443 >        Long(0);                                                        // CRC (calculated later)
444          Word(0x0101);                                           // Rev. level, format
445          Long(0x5a932bc7);                                       // Test pattern
446          Word(0x000f);                                           // Byte lanes
447  
448 +        // Copy slot ROM to Mac ROM
449 +        slot_rom_size = p;
450 +        memcpy(ROMBaseHost + ROMSize - slot_rom_size, srom, slot_rom_size);
451 +
452 +        // Calculate checksum
453 +        ChecksumSlotROM();
454 +        return true;
455 + }
456 +
457 + /*
458 + *  Calculate slot ROM checksum (in-place)
459 + */
460 +
461 + void ChecksumSlotROM(void)
462 + {
463          // Calculate CRC
464 +        uint8 *p = ROMBaseHost + ROMSize - slot_rom_size;
465 +        p[slot_rom_size - 12] = 0;
466 +        p[slot_rom_size - 11] = 0;
467 +        p[slot_rom_size - 10] = 0;
468 +        p[slot_rom_size - 9] = 0;
469          uint32 crc = 0;
470 <        for (int i=0; i<p; i++) {
470 >        for (int i=0; i<slot_rom_size; i++) {
471                  crc = (crc << 1) | (crc >> 31);
472 <                crc += srom[i];
472 >                crc += p[i];
473          }
474 <        srom[p - 12] = crc >> 24;
475 <        srom[p - 11] = crc >> 16;
476 <        srom[p - 10] = crc >> 8;
477 <        srom[p - 9] = crc;
403 <
404 <        // Copy slot ROM to Mac ROM
405 <        memcpy(ROMBaseHost + ROMSize - p, srom, p);
406 <        return true;
474 >        p[slot_rom_size - 12] = crc >> 24;
475 >        p[slot_rom_size - 11] = crc >> 16;
476 >        p[slot_rom_size - 10] = crc >> 8;
477 >        p[slot_rom_size - 9] = crc;
478   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines