ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/video.cpp
Revision: 1.13
Committed: 2001-06-29T12:51:20Z (23 years, 4 months ago) by cebix
Branch: MAIN
Changes since 1.12: +5 -1 lines
Log Message:
slot ROM checksum is recalculated after patching during resolution switch

File Contents

# User Rev Content
1 cebix 1.1 /*
2     * video.cpp - Video/graphics emulation
3     *
4 cebix 1.7 * Basilisk II (C) 1997-2001 Christian Bauer
5 cebix 1.1 * Portions (C) 1997-1999 Marc Hellwig
6     *
7     * This program is free software; you can redistribute it and/or modify
8     * it under the terms of the GNU General Public License as published by
9     * the Free Software Foundation; either version 2 of the License, or
10     * (at your option) any later version.
11     *
12     * This program is distributed in the hope that it will be useful,
13     * but WITHOUT ANY WARRANTY; without even the implied warranty of
14     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     * GNU General Public License for more details.
16     *
17     * You should have received a copy of the GNU General Public License
18     * along with this program; if not, write to the Free Software
19     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20     */
21    
22     /*
23     * SEE ALSO
24     * Inside Macintosh: Devices, chapter 1 "Device Manager"
25     * Designing Cards and Drivers for the Macintosh Family, Second Edition
26     */
27    
28     #include <stdio.h>
29    
30     #include "sysdeps.h"
31     #include "cpu_emulation.h"
32     #include "main.h"
33     #include "macos_util.h"
34 cebix 1.13 #include "slot_rom.h"
35 cebix 1.1 #include "video.h"
36     #include "video_defs.h"
37    
38 cebix 1.11 #define DEBUG 0
39 cebix 1.1 #include "debug.h"
40    
41    
42 cebix 1.9 // List of supported video modes
43 gbeauche 1.12 std::vector<video_mode> VideoModes;
44 cebix 1.9
45 cebix 1.1 // Description of the main monitor
46 cebix 1.9 monitor_desc VideoMonitor;
47 cebix 1.1
48     // Local variables (per monitor)
49     struct {
50 cebix 1.9 monitor_desc *desc; // Pointer to description of monitor handled by this instance of the driver
51 cebix 1.1 uint8 palette[256 * 3]; // Color palette, 256 entries, RGB
52     bool luminance_mapping; // Luminance mapping on/off
53     bool interrupts_enabled; // VBL interrupts on/off
54 cebix 1.11 uint32 gamma_table; // Mac address of gamma table
55 cebix 1.9 uint16 current_mode; // Currently selected depth/resolution
56     uint32 current_id;
57     uint16 preferred_mode; // Preferred depth/resolution
58     uint32 preferred_id;
59 cebix 1.11 uint32 sp; // Mac address of Slot Manager parameter block
60 cebix 1.1 } VidLocal;
61    
62    
63     /*
64 cebix 1.9 * Check whether specified resolution ID is one of the supported resolutions
65     */
66    
67     static bool has_resolution(uint32 id)
68     {
69 cebix 1.10 std::vector<video_mode>::const_iterator i = VideoModes.begin(), end = VideoModes.end();
70 cebix 1.9 while (i != end) {
71     if (i->resolution_id == id)
72     return true;
73     ++i;
74     }
75     return false;
76     }
77    
78    
79     /*
80 cebix 1.10 * Find specified mode (depth/resolution) (or VideoModes.end() if not found)
81     */
82    
83     static std::vector<video_mode>::const_iterator find_mode(uint16 mode, uint32 id)
84     {
85     std::vector<video_mode>::const_iterator i = VideoModes.begin(), end = VideoModes.end();
86     while (i != end) {
87     if (i->resolution_id == id && DepthToAppleMode(i->depth) == mode)
88     return i;
89     ++i;
90     }
91     return i;
92     }
93    
94    
95     /*
96 cebix 1.9 * Find maximum supported depth for given resolution ID
97     */
98    
99     static video_depth max_depth_of_resolution(uint32 id)
100     {
101     video_depth m = VDEPTH_1BIT;
102 gbeauche 1.12 std::vector<video_mode>::const_iterator i = VideoModes.begin(), end = VideoModes.end();
103 cebix 1.9 while (i != end) {
104     if (i->depth > m)
105     m = i->depth;
106     ++i;
107     }
108     return m;
109     }
110    
111    
112     /*
113     * Get X/Y size of specified resolution
114     */
115    
116     static void get_size_of_resolution(uint32 id, uint32 &x, uint32 &y)
117     {
118 gbeauche 1.12 std::vector<video_mode>::const_iterator i = VideoModes.begin(), end = VideoModes.end();
119 cebix 1.9 while (i != end) {
120     if (i->resolution_id == id) {
121     x = i->x;
122     y = i->y;
123     return;
124     }
125     ++i;
126     }
127     }
128    
129    
130     /*
131 cebix 1.11 * Set palette to 50% gray
132     */
133    
134     static void set_gray_palette(void)
135     {
136     if (!IsDirectMode(VidLocal.current_mode)) {
137     for (int i=0; i<256; i++) {
138     VidLocal.palette[i * 3 + 0] = 127;
139     VidLocal.palette[i * 3 + 1] = 127;
140     VidLocal.palette[i * 3 + 2] = 127;
141     }
142     video_set_palette(VidLocal.palette);
143     }
144     }
145    
146    
147     /*
148 cebix 1.1 * Driver Open() routine
149     */
150    
151 cebix 1.2 int16 VideoDriverOpen(uint32 pb, uint32 dce)
152 cebix 1.1 {
153 cebix 1.2 D(bug("VideoDriverOpen\n"));
154 cebix 1.1
155 cebix 1.9 // This shouldn't happen unless the platform-specific video code is broken
156     if (VideoModes.empty())
157     fprintf(stderr, "No valid video modes found (broken video driver?)\n");
158    
159 cebix 1.1 // Init local variables
160     VidLocal.desc = &VideoMonitor;
161     VidLocal.luminance_mapping = false;
162     VidLocal.interrupts_enabled = false;
163 cebix 1.9 VidLocal.current_mode = DepthToAppleMode(VidLocal.desc->mode.depth);
164     VidLocal.current_id = VidLocal.desc->mode.resolution_id;
165     VidLocal.preferred_mode = VidLocal.current_mode;
166     VidLocal.preferred_id = VidLocal.current_id;
167 cebix 1.1
168 cebix 1.11 // Allocate Slot Manager parameter block in Mac RAM
169     M68kRegisters r;
170     r.d[0] = SIZEOF_SPBlock;
171     Execute68kTrap(0xa71e, &r); // NewPtrSysClear()
172     if (r.a[0] == 0)
173     return memFullErr;
174     VidLocal.sp = r.a[0];
175     D(bug("SPBlock at %08x\n", VidLocal.sp));
176    
177     // Find and set default gamma table
178     VidLocal.gamma_table = 0; //!!
179    
180 cebix 1.1 // Init color palette (solid gray)
181 cebix 1.11 set_gray_palette();
182 cebix 1.1 return noErr;
183     }
184    
185    
186     /*
187     * Driver Control() routine
188     */
189    
190 cebix 1.2 int16 VideoDriverControl(uint32 pb, uint32 dce)
191 cebix 1.1 {
192     uint16 code = ReadMacInt16(pb + csCode);
193     uint32 param = ReadMacInt32(pb + csParam);
194 cebix 1.2 D(bug("VideoDriverControl %d\n", code));
195 cebix 1.1 switch (code) {
196    
197 cebix 1.9 case cscSetMode: { // Set color depth
198     uint16 mode = ReadMacInt16(param + csMode);
199     D(bug(" SetMode %04x\n", mode));
200 cebix 1.10
201 cebix 1.11 // Set old base address in case the switch fails
202     WriteMacInt32(param + csBaseAddr, VidLocal.desc->mac_frame_base);
203    
204     if (ReadMacInt16(param + csPage))
205     return paramErr;
206    
207 cebix 1.10 if (mode != VidLocal.current_mode) {
208     std::vector<video_mode>::const_iterator i = find_mode(mode, VidLocal.current_id);
209 cebix 1.11 if (i == VideoModes.end())
210 cebix 1.10 return paramErr;
211 cebix 1.11 set_gray_palette();
212 cebix 1.10 video_switch_to_mode(*i);
213     VidLocal.current_mode = mode;
214 cebix 1.11 WriteMacInt32(param + csBaseAddr, VidLocal.desc->mac_frame_base);
215     WriteMacInt32(dce + dCtlDevBase, VidLocal.desc->mac_frame_base);
216 cebix 1.10 }
217 cebix 1.11 D(bug(" base %08x\n", VidLocal.desc->mac_frame_base));
218 cebix 1.10 return noErr;
219 cebix 1.9 }
220 cebix 1.1
221     case cscSetEntries: { // Set palette
222 cebix 1.11 D(bug(" SetEntries table %08x, count %d, start %d\n", ReadMacInt32(param + csTable), ReadMacInt16(param + csCount), ReadMacInt16(param + csStart)));
223     if (IsDirectMode(VidLocal.current_mode))
224 cebix 1.1 return controlErr;
225    
226     uint32 s_pal = ReadMacInt32(param + csTable); // Source palette
227     uint8 *d_pal; // Destination palette
228 cebix 1.11 uint16 start = ReadMacInt16(param + csStart);
229 cebix 1.1 uint16 count = ReadMacInt16(param + csCount);
230 cebix 1.11 if (s_pal == 0 || count > 255)
231 cebix 1.1 return paramErr;
232    
233 cebix 1.11 if (start == 0xffff) { // Indexed
234 cebix 1.1 for (uint32 i=0; i<=count; i++) {
235 cebix 1.11 d_pal = VidLocal.palette + (ReadMacInt16(s_pal) & 0xff) * 3;
236 cebix 1.1 uint8 red = (uint16)ReadMacInt16(s_pal + 2) >> 8;
237     uint8 green = (uint16)ReadMacInt16(s_pal + 4) >> 8;
238     uint8 blue = (uint16)ReadMacInt16(s_pal + 6) >> 8;
239     if (VidLocal.luminance_mapping)
240     red = green = blue = (red * 0x4ccc + green * 0x970a + blue * 0x1c29) >> 16;
241 cebix 1.11 //!! gamma correction
242 cebix 1.1 *d_pal++ = red;
243     *d_pal++ = green;
244     *d_pal++ = blue;
245     s_pal += 8;
246     }
247 cebix 1.11 } else { // Sequential
248     if (start + count > 255)
249     return paramErr;
250     d_pal = VidLocal.palette + start * 3;
251 cebix 1.1 for (uint32 i=0; i<=count; i++) {
252     uint8 red = (uint16)ReadMacInt16(s_pal + 2) >> 8;
253     uint8 green = (uint16)ReadMacInt16(s_pal + 4) >> 8;
254     uint8 blue = (uint16)ReadMacInt16(s_pal + 6) >> 8;
255     if (VidLocal.luminance_mapping)
256     red = green = blue = (red * 0x4ccc + green * 0x970a + blue * 0x1c29) >> 16;
257 cebix 1.11 //!! gamma correction
258 cebix 1.1 *d_pal++ = red;
259     *d_pal++ = green;
260     *d_pal++ = blue;
261     s_pal += 8;
262     }
263     }
264     video_set_palette(VidLocal.palette);
265     return noErr;
266     }
267    
268     case cscSetGamma: // Set gamma table
269     D(bug(" SetGamma\n"));
270 cebix 1.9 //!!
271 cebix 1.11 return controlErr;
272 cebix 1.1
273     case cscGrayPage: { // Fill page with dithered gray pattern
274     D(bug(" GrayPage %d\n", ReadMacInt16(param + csPage)));
275     if (ReadMacInt16(param + csPage))
276     return paramErr;
277    
278     uint32 pattern[6] = {
279     0xaaaaaaaa, // 1 bpp
280     0xcccccccc, // 2 bpp
281     0xf0f0f0f0, // 4 bpp
282     0xff00ff00, // 8 bpp
283     0xffff0000, // 16 bpp
284     0xffffffff // 32 bpp
285     };
286     uint32 p = VidLocal.desc->mac_frame_base;
287 cebix 1.9 uint32 pat = pattern[VidLocal.desc->mode.depth];
288 cebix 1.11 bool invert = (VidLocal.desc->mode.depth == VDEPTH_32BIT);
289 cebix 1.9 for (uint32 y=0; y<VidLocal.desc->mode.y; y++) {
290     for (uint32 x=0; x<VidLocal.desc->mode.bytes_per_row; x+=4) {
291 cebix 1.8 WriteMacInt32(p + x, pat);
292 cebix 1.11 if (invert)
293 cebix 1.1 pat = ~pat;
294     }
295 cebix 1.9 p += VidLocal.desc->mode.bytes_per_row;
296 cebix 1.1 pat = ~pat;
297     }
298 cebix 1.11 //!! if direct mode, load gamma table to CLUT
299 cebix 1.1 return noErr;
300     }
301    
302     case cscSetGray: // Enable/disable luminance mapping
303     D(bug(" SetGray %02x\n", ReadMacInt8(param + csMode)));
304     VidLocal.luminance_mapping = ReadMacInt8(param + csMode);
305     return noErr;
306    
307     case cscSetInterrupt: // Enable/disable VBL
308     D(bug(" SetInterrupt %02x\n", ReadMacInt8(param + csMode)));
309     VidLocal.interrupts_enabled = (ReadMacInt8(param + csMode) == 0);
310     return noErr;
311    
312 cebix 1.9 case cscSetDefaultMode: { // Set default color depth
313     uint16 mode = ReadMacInt16(param + csMode);
314     D(bug(" SetDefaultMode %04x\n", mode));
315     VidLocal.preferred_mode = mode;
316     return noErr;
317     }
318    
319     case cscSwitchMode: { // Switch video mode (depth and resolution)
320     uint16 mode = ReadMacInt16(param + csMode);
321     uint32 id = ReadMacInt32(param + csData);
322     D(bug(" SwitchMode %04x, %08x\n", mode, id));
323 cebix 1.10
324 cebix 1.11 // Set old base address in case the switch fails
325     WriteMacInt32(param + csBaseAddr, VidLocal.desc->mac_frame_base);
326    
327     if (ReadMacInt16(param + csPage))
328     return paramErr;
329    
330 cebix 1.10 if (mode != VidLocal.current_mode || id != VidLocal.current_id) {
331     std::vector<video_mode>::const_iterator i = find_mode(mode, id);
332 cebix 1.11 if (i == VideoModes.end())
333 cebix 1.10 return paramErr;
334 cebix 1.11 set_gray_palette();
335 cebix 1.10 video_switch_to_mode(*i);
336     VidLocal.current_mode = mode;
337     VidLocal.current_id = id;
338 cebix 1.11 uint32 frame_base = VidLocal.desc->mac_frame_base;
339     WriteMacInt32(param + csBaseAddr, frame_base);
340    
341     M68kRegisters r;
342     uint32 sp = VidLocal.sp;
343     r.a[0] = sp;
344    
345     // Find functional sResource for this display
346     WriteMacInt8(sp + spSlot, ReadMacInt8(dce + dCtlSlot));
347     WriteMacInt8(sp + spID, ReadMacInt8(dce + dCtlSlotId));
348     WriteMacInt8(sp + spExtDev, 0);
349     r.d[0] = 0x0016;
350     Execute68kTrap(0xa06e, &r); // SRsrcInfo()
351     uint32 rsrc = ReadMacInt32(sp + spPointer);
352    
353 cebix 1.13 // Patch minorBase (otherwise rebooting won't work)
354 cebix 1.11 WriteMacInt8(sp + spID, 0x0a); // minorBase
355     r.d[0] = 0x0006;
356     Execute68kTrap(0xa06e, &r); // SFindStruct()
357     uint32 minor_base = ReadMacInt32(sp + spPointer) - ROMBaseMac;
358     ROMBaseHost[minor_base + 0] = frame_base >> 24;
359     ROMBaseHost[minor_base + 1] = frame_base >> 16;
360     ROMBaseHost[minor_base + 2] = frame_base >> 8;
361     ROMBaseHost[minor_base + 3] = frame_base;
362    
363     // Patch video mode parameter table
364     WriteMacInt32(sp + spPointer, rsrc);
365     WriteMacInt8(sp + spID, mode);
366     r.d[0] = 0x0006;
367     Execute68kTrap(0xa06e, &r); // SFindStruct()
368     WriteMacInt8(sp + spID, 0x01);
369     r.d[0] = 0x0006;
370     Execute68kTrap(0xa06e, &r); // SFindStruct()
371     uint32 p = ReadMacInt32(sp + spPointer) - ROMBaseMac;
372     ROMBaseHost[p + 8] = i->bytes_per_row >> 8;
373     ROMBaseHost[p + 9] = i->bytes_per_row;
374     ROMBaseHost[p + 14] = i->y >> 8;
375     ROMBaseHost[p + 15] = i->y;
376     ROMBaseHost[p + 16] = i->x >> 8;
377     ROMBaseHost[p + 17] = i->x;
378 cebix 1.13
379     // Recalculate slot ROM checksum
380     ChecksumSlotROM();
381 cebix 1.11
382     // Update sResource
383     WriteMacInt8(sp + spID, ReadMacInt8(dce + dCtlSlotId));
384     r.d[0] = 0x002b;
385     Execute68kTrap(0xa06e, &r); // SUpdateSRT()
386    
387     // Update frame buffer base in DCE
388     WriteMacInt32(dce + dCtlDevBase, frame_base);
389 cebix 1.10 }
390 cebix 1.11 D(bug(" base %08x\n", VidLocal.desc->mac_frame_base));
391 cebix 1.10 return noErr;
392 cebix 1.9 }
393    
394     case cscSavePreferredConfiguration: {
395     uint16 mode = ReadMacInt16(param + csMode);
396     uint32 id = ReadMacInt32(param + csData);
397     D(bug(" SavePreferredConfiguration %04x, %08x\n", mode, id));
398     VidLocal.preferred_mode = mode;
399     VidLocal.preferred_id = id;
400     return noErr;
401     }
402    
403 cebix 1.1 default:
404 cebix 1.2 printf("WARNING: Unknown VideoDriverControl(%d)\n", code);
405 cebix 1.1 return controlErr;
406     }
407     }
408    
409    
410     /*
411     * Driver Status() routine
412     */
413    
414 cebix 1.2 int16 VideoDriverStatus(uint32 pb, uint32 dce)
415 cebix 1.1 {
416     uint16 code = ReadMacInt16(pb + csCode);
417     uint32 param = ReadMacInt32(pb + csParam);
418 cebix 1.2 D(bug("VideoDriverStatus %d\n", code));
419 cebix 1.1 switch (code) {
420    
421 cebix 1.9 case cscGetMode: // Get current color depth
422     D(bug(" GetMode -> %04x, base %08x\n", VidLocal.current_mode, VidLocal.desc->mac_frame_base));
423     WriteMacInt16(param + csMode, VidLocal.current_mode);
424     WriteMacInt16(param + csPage, 0);
425     WriteMacInt32(param + csBaseAddr, VidLocal.desc->mac_frame_base);
426     return noErr;
427    
428 cebix 1.11 case cscGetEntries: { // Read palette
429     D(bug(" GetEntries table %08x, count %d, start %d\n", ReadMacInt32(param + csTable), ReadMacInt16(param + csCount), ReadMacInt16(param + csStart)));
430 cebix 1.9
431 cebix 1.11 uint8 *s_pal; // Source palette
432     uint32 d_pal = ReadMacInt32(param + csTable); // Destination palette
433     uint16 start = ReadMacInt16(param + csStart);
434     uint16 count = ReadMacInt16(param + csCount);
435     if (d_pal == 0 || count > 255)
436     return paramErr;
437    
438     if (start == 0xffff) { // Indexed
439     for (uint32 i=0; i<=count; i++) {
440     s_pal = VidLocal.palette + (ReadMacInt16(d_pal) & 0xff) * 3;
441     uint8 red = *s_pal++;
442     uint8 green = *s_pal++;
443     uint8 blue = *s_pal++;
444     WriteMacInt16(d_pal + 2, red * 0x0101);
445     WriteMacInt16(d_pal + 4, green * 0x0101);
446     WriteMacInt16(d_pal + 6, blue * 0x0101);
447     d_pal += 8;
448     }
449     } else { // Sequential
450     if (start + count > 255)
451     return paramErr;
452     s_pal = VidLocal.palette + start * 3;
453     for (uint32 i=0; i<=count; i++) {
454     uint8 red = *s_pal++;
455     uint8 green = *s_pal++;
456     uint8 blue = *s_pal++;
457     WriteMacInt16(d_pal + 2, red * 0x0101);
458     WriteMacInt16(d_pal + 4, green * 0x0101);
459     WriteMacInt16(d_pal + 6, blue * 0x0101);
460     d_pal += 8;
461     }
462     }
463     return noErr;
464     }
465    
466     case cscGetPages: // Get number of pages
467     D(bug(" GetPages -> 1\n"));
468 cebix 1.1 WriteMacInt16(param + csPage, 1);
469     return noErr;
470    
471 cebix 1.11 case cscGetBaseAddress: // Get page base address
472     D(bug(" GetBaseAddress -> %08x\n", VidLocal.desc->mac_frame_base));
473 cebix 1.1 WriteMacInt32(param + csBaseAddr, VidLocal.desc->mac_frame_base);
474 cebix 1.11 if (ReadMacInt16(param + csPage))
475     return paramErr;
476     else
477     return noErr;
478 cebix 1.1
479     case cscGetGray: // Get luminance mapping flag
480 cebix 1.9 D(bug(" GetGray -> %d\n", VidLocal.luminance_mapping));
481 cebix 1.11 WriteMacInt16(param, VidLocal.luminance_mapping ? 0x0100 : 0);
482 cebix 1.1 return noErr;
483    
484     case cscGetInterrupt: // Get interrupt disable flag
485 cebix 1.9 D(bug(" GetInterrupt -> %d\n", VidLocal.interrupts_enabled));
486 cebix 1.11 WriteMacInt16(param, VidLocal.interrupts_enabled ? 0 : 0x0100);
487 cebix 1.1 return noErr;
488    
489 cebix 1.11 case cscGetGamma:
490     D(bug(" GetGamma -> \n"));
491     //!!
492     return statusErr;
493 cebix 1.9
494     case cscGetDefaultMode: // Get default color depth
495     D(bug(" GetDefaultMode -> %04x\n", VidLocal.preferred_mode));
496     WriteMacInt16(param + csMode, VidLocal.preferred_mode);
497 cebix 1.1 return noErr;
498    
499 cebix 1.11 case cscGetCurrentMode: // Get current video mode (depth and resolution)
500     D(bug(" GetCurMode -> %04x/%08x, base %08x\n", VidLocal.current_mode, VidLocal.current_id, VidLocal.desc->mac_frame_base));
501 cebix 1.9 WriteMacInt16(param + csMode, VidLocal.current_mode);
502     WriteMacInt32(param + csData, VidLocal.current_id);
503 cebix 1.1 WriteMacInt16(param + csPage, 0);
504     WriteMacInt32(param + csBaseAddr, VidLocal.desc->mac_frame_base);
505     return noErr;
506    
507     case cscGetConnection: // Get monitor information
508     D(bug(" GetConnection\n"));
509 cebix 1.11 WriteMacInt16(param + csDisplayType, 8); // Modeless connection
510     WriteMacInt8(param + csConnectTaggedType, 0);
511     WriteMacInt8(param + csConnectTaggedData, 0);
512     WriteMacInt32(param + csConnectFlags, 0x43); // All modes valid and safe, non-standard tagging
513 cebix 1.1 WriteMacInt32(param + csDisplayComponent, 0);
514     return noErr;
515    
516 cebix 1.11 case cscGetModeTiming: { // Get video timing for specified resolution
517     uint32 id = ReadMacInt32(param + csTimingMode);
518     D(bug(" GetModeTiming %08x\n", id));
519     if (!has_resolution(id))
520     return paramErr;
521    
522     WriteMacInt32(param + csTimingFormat, FOURCC('d', 'e', 'c', 'l'));
523     WriteMacInt32(param + csTimingData, 0); // unknown
524     uint32 flags = 0xb; // mode valid, safe and shown in Monitors panel
525     if (id == VidLocal.preferred_id)
526     flags |= 4; // default mode
527     WriteMacInt32(param + csTimingFlags, flags);
528     return noErr;
529     }
530    
531 cebix 1.9 case cscGetModeBaseAddress: // Get frame buffer base address
532 cebix 1.11 D(bug(" GetModeBaseAddress -> base %08x\n", VidLocal.desc->mac_frame_base));
533     WriteMacInt32(param + csBaseAddr, VidLocal.desc->mac_frame_base);
534 cebix 1.1 return noErr;
535    
536 cebix 1.9 case cscGetPreferredConfiguration: // Get default video mode (depth and resolution)
537     D(bug(" GetPreferredConfiguration -> %04x/%08x\n", VidLocal.preferred_mode, VidLocal.preferred_id));
538     WriteMacInt16(param + csMode, VidLocal.preferred_mode);
539     WriteMacInt32(param + csData, VidLocal.preferred_id);
540     return noErr;
541    
542     case cscGetNextResolution: { // Called iteratively to obtain a list of all supported resolutions
543     uint32 id = ReadMacInt32(param + csPreviousDisplayModeID);
544     D(bug(" GetNextResolution %08x\n", id));
545    
546     switch (id) {
547     case 0:
548     // Return current resolution
549     id = VidLocal.current_id;
550     break;
551    
552     case 0xfffffffe:
553     // Return first supported resolution
554     id = 0x80;
555     while (!has_resolution(id))
556     id++;
557     break;
558    
559     default:
560     // Get next resolution
561     if (!has_resolution(id))
562     return paramErr;
563     id++;
564     while (!has_resolution(id) && id < 0x100)
565     id++;
566     if (id == 0x100) { // No more resolutions
567     WriteMacInt32(param + csRIDisplayModeID, 0xfffffffd);
568     return noErr;
569     }
570     break;
571     }
572    
573     WriteMacInt32(param + csRIDisplayModeID, id);
574     uint32 x, y;
575     get_size_of_resolution(id, x, y);
576     WriteMacInt32(param + csHorizontalPixels, x);
577     WriteMacInt32(param + csVerticalLines, y);
578     WriteMacInt32(param + csRefreshRate, 75 << 16);
579     WriteMacInt16(param + csMaxDepthMode, DepthToAppleMode(max_depth_of_resolution(id)));
580 jlachmann 1.5 return noErr;
581 cebix 1.9 }
582 jlachmann 1.5
583 cebix 1.9 case cscGetVideoParameters: { // Get information about specified resolution/depth
584     uint32 id = ReadMacInt32(param + csDisplayModeID);
585     uint16 mode = ReadMacInt16(param + csDepthMode);
586     D(bug(" GetVideoParameters %04x/%08x\n", mode, id));
587    
588 gbeauche 1.12 std::vector<video_mode>::const_iterator i = VideoModes.begin(), end = VideoModes.end();
589 cebix 1.9 while (i != end) {
590     if (DepthToAppleMode(i->depth) == mode && i->resolution_id == id) {
591     uint32 vp = ReadMacInt32(param + csVPBlockPtr);
592     WriteMacInt32(vp + vpBaseOffset, 0);
593     WriteMacInt16(vp + vpRowBytes, i->bytes_per_row);
594     WriteMacInt16(vp + vpBounds, 0);
595     WriteMacInt16(vp + vpBounds + 2, 0);
596     WriteMacInt16(vp + vpBounds + 4, i->y);
597     WriteMacInt16(vp + vpBounds + 6, i->x);
598     WriteMacInt16(vp + vpVersion, 0);
599     WriteMacInt16(vp + vpPackType, 0);
600     WriteMacInt32(vp + vpPackSize, 0);
601 cebix 1.11 WriteMacInt32(vp + vpHRes, 0x00480000); // 72 dpi
602 cebix 1.9 WriteMacInt32(vp + vpVRes, 0x00480000);
603     uint32 pix_type, pix_size, cmp_count, cmp_size, dev_type;
604     switch (i->depth) {
605     case VDEPTH_1BIT:
606     pix_type = 0; pix_size = 1;
607     cmp_count = 1; cmp_size = 1;
608     dev_type = 0; // CLUT
609     break;
610     case VDEPTH_2BIT:
611     pix_type = 0; pix_size = 2;
612     cmp_count = 1; cmp_size = 2;
613     dev_type = 0; // CLUT
614     break;
615     case VDEPTH_4BIT:
616     pix_type = 0; pix_size = 4;
617     cmp_count = 1; cmp_size = 4;
618     dev_type = 0; // CLUT
619     break;
620     case VDEPTH_8BIT:
621     pix_type = 0; pix_size = 8;
622     cmp_count = 1; cmp_size = 8;
623     dev_type = 0; // CLUT
624     break;
625     case VDEPTH_16BIT:
626     pix_type = 0x10; pix_size = 16;
627     cmp_count = 3; cmp_size = 5;
628     dev_type = 2; // direct
629     break;
630     case VDEPTH_32BIT:
631     pix_type = 0x10; pix_size = 32;
632     cmp_count = 3; cmp_size = 8;
633     dev_type = 2; // direct
634     break;
635     }
636     WriteMacInt16(vp + vpPixelType, pix_type);
637     WriteMacInt16(vp + vpPixelSize, pix_size);
638     WriteMacInt16(vp + vpCmpCount, cmp_count);
639     WriteMacInt16(vp + vpCmpSize, cmp_size);
640     WriteMacInt32(param + csPageCount, 1);
641     WriteMacInt32(param + csDeviceType, dev_type);
642     return noErr;
643     }
644     ++i;
645     }
646     return paramErr; // specified resolution/depth not supported
647     }
648 cebix 1.1
649     default:
650 cebix 1.2 printf("WARNING: Unknown VideoDriverStatus(%d)\n", code);
651 cebix 1.1 return statusErr;
652     }
653     }