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

Comparing BasiliskII/src/video.cpp (file contents):
Revision 1.12 by gbeauche, 2001-06-28T21:36:46Z vs.
Revision 1.22 by cebix, 2001-07-09T11:21:59Z

# Line 23 | Line 23
23   *  SEE ALSO
24   *    Inside Macintosh: Devices, chapter 1 "Device Manager"
25   *    Designing Cards and Drivers for the Macintosh Family, Second Edition
26 + *    Designing PCI Cards and Drivers for Power Macintosh Computers
27 + *    Display Device Driver Guide
28   */
29  
30   #include <stdio.h>
# Line 31 | Line 33
33   #include "cpu_emulation.h"
34   #include "main.h"
35   #include "macos_util.h"
36 + #include "slot_rom.h"
37   #include "video.h"
38   #include "video_defs.h"
39  
# Line 39 | Line 42
42  
43  
44   // List of supported video modes
45 < std::vector<video_mode> VideoModes;
45 > vector<video_mode> VideoModes;
46  
47   // Description of the main monitor
48   monitor_desc VideoMonitor;
49  
50 + // Depth code -> Apple mode mapping
51 + uint16 apple_mode_for_depth[6];
52 +
53   // Local variables (per monitor)
54   struct {
55          monitor_desc *desc;                     // Pointer to description of monitor handled by this instance of the driver
56          uint8 palette[256 * 3];         // Color palette, 256 entries, RGB
57          bool luminance_mapping;         // Luminance mapping on/off
58          bool interrupts_enabled;        // VBL interrupts on/off
59 +        bool dm_present;                        // We received a GetVideoParameters call, so the Display Manager seems to be present
60          uint32 gamma_table;                     // Mac address of gamma table
61 +        int alloc_gamma_table_size;     // Allocated size of gamma table
62          uint16 current_mode;            // Currently selected depth/resolution
63          uint32 current_id;
64          uint16 preferred_mode;          // Preferred depth/resolution
65          uint32 preferred_id;
66 <        uint32 sp;                                      // Mac address of Slot Manager parameter block
66 >        uint32 slot_param;                      // Mac address of Slot Manager parameter block
67   } VidLocal;
68  
69  
70   /*
71 + *  Initialize apple_mode_for_depth[] array from VideoModes list
72 + */
73 +
74 + void video_init_depth_list(void)
75 + {
76 +        uint16 mode = 0x80;
77 +        for (int depth = VDEPTH_1BIT; depth <= VDEPTH_32BIT; depth++) {
78 +                if (video_has_depth(video_depth(depth)))
79 +                        apple_mode_for_depth[depth] = mode++;
80 +                else
81 +                        apple_mode_for_depth[depth] = 0;
82 +        }
83 + }
84 +
85 +
86 + /*
87 + *  Check whether a mode with the specified depth exists
88 + */
89 +
90 + bool video_has_depth(video_depth depth)
91 + {
92 +        vector<video_mode>::const_iterator i = VideoModes.begin(), end = VideoModes.end();
93 +        while (i != end) {
94 +                if (i->depth == depth)
95 +                        return true;
96 +                ++i;
97 +        }
98 +        return false;
99 + }
100 +
101 +
102 + /*
103   *  Check whether specified resolution ID is one of the supported resolutions
104   */
105  
106   static bool has_resolution(uint32 id)
107   {
108 <        std::vector<video_mode>::const_iterator i = VideoModes.begin(), end = VideoModes.end();
109 <        while (i != end) {
108 >        vector<video_mode>::const_iterator i, end = VideoModes.end();
109 >        for (i = VideoModes.begin(); i != end; ++i) {
110                  if (i->resolution_id == id)
111                          return true;
72                ++i;
112          }
113          return false;
114   }
# Line 79 | Line 118 | static bool has_resolution(uint32 id)
118   *  Find specified mode (depth/resolution) (or VideoModes.end() if not found)
119   */
120  
121 < static std::vector<video_mode>::const_iterator find_mode(uint16 mode, uint32 id)
121 > static vector<video_mode>::const_iterator find_mode(uint16 mode, uint32 id)
122   {
123 <        std::vector<video_mode>::const_iterator i = VideoModes.begin(), end = VideoModes.end();
124 <        while (i != end) {
123 >        vector<video_mode>::const_iterator i, end = VideoModes.end();
124 >        for (i = VideoModes.begin(); i != end; ++i) {
125                  if (i->resolution_id == id && DepthToAppleMode(i->depth) == mode)
126                          return i;
88                ++i;
127          }
128          return i;
129   }
# Line 98 | Line 136 | static std::vector<video_mode>::const_it
136   static video_depth max_depth_of_resolution(uint32 id)
137   {
138          video_depth m = VDEPTH_1BIT;
139 <        std::vector<video_mode>::const_iterator i = VideoModes.begin(), end = VideoModes.end();
140 <        while (i != end) {
139 >        vector<video_mode>::const_iterator i, end = VideoModes.end();
140 >        for (i = VideoModes.begin(); i != end; ++i) {
141                  if (i->depth > m)
142                          m = i->depth;
105                ++i;
143          }
144          return m;
145   }
# Line 114 | Line 151 | static video_depth max_depth_of_resoluti
151  
152   static void get_size_of_resolution(uint32 id, uint32 &x, uint32 &y)
153   {
154 <        std::vector<video_mode>::const_iterator i = VideoModes.begin(), end = VideoModes.end();
155 <        while (i != end) {
154 >        vector<video_mode>::const_iterator i, end = VideoModes.end();
155 >        for (i = VideoModes.begin(); i != end; ++i) {
156                  if (i->resolution_id == id) {
157                          x = i->x;
158                          y = i->y;
159                          return;
160                  }
161 <                ++i;
161 >        }
162 >        x = y = 0;
163 > }
164 >
165 >
166 > /*
167 > *  Get bytes-per-row value for specified resolution/depth
168 > */
169 >
170 > uint32 video_bytes_per_row(video_depth depth, uint32 id)
171 > {
172 >        vector<video_mode>::const_iterator i, end = VideoModes.end();
173 >        for (i = VideoModes.begin(); i != end; ++i) {
174 >                if (i->depth == depth && i->resolution_id == id)
175 >                        return i->bytes_per_row;
176 >        }
177 >        uint32 x, y;
178 >        get_size_of_resolution(id, x, y);
179 >        return TrivialBytesPerRow(x, depth);
180 > }
181 >
182 >
183 > /*
184 > *  Find palette size for given color depth
185 > */
186 >
187 > static int palette_size(video_depth depth)
188 > {
189 >        switch (depth) {
190 >                case VDEPTH_1BIT: return 2;
191 >                case VDEPTH_2BIT: return 4;
192 >                case VDEPTH_4BIT: return 16;
193 >                case VDEPTH_8BIT: return 256;
194 >                case VDEPTH_16BIT: return 32;
195 >                case VDEPTH_32BIT: return 256;
196 >                default: return 0;
197          }
198   }
199  
# Line 132 | Line 204 | static void get_size_of_resolution(uint3
204  
205   static void set_gray_palette(void)
206   {
207 <        if (!IsDirectMode(VidLocal.current_mode)) {
208 <                for (int i=0; i<256; i++) {
209 <                        VidLocal.palette[i * 3 + 0] = 127;
210 <                        VidLocal.palette[i * 3 + 1] = 127;
211 <                        VidLocal.palette[i * 3 + 2] = 127;
207 >        for (int i=0; i<256; i++) {
208 >                VidLocal.palette[i * 3 + 0] = 127;
209 >                VidLocal.palette[i * 3 + 1] = 127;
210 >                VidLocal.palette[i * 3 + 2] = 127;
211 >        }
212 >        video_set_palette(VidLocal.palette, 256);
213 > }
214 >
215 >
216 > /*
217 > *  Load gamma-corrected black-to-white ramp to palette for direct-color mode
218 > */
219 >
220 > static void load_ramp_palette(void)
221 > {
222 >        // Find tables for gamma correction
223 >        uint8 *red_gamma, *green_gamma, *blue_gamma;
224 >        bool have_gamma = false;
225 >        int data_width = 0;
226 >        if (VidLocal.gamma_table) {
227 >                uint32 table = VidLocal.gamma_table;
228 >                red_gamma = Mac2HostAddr(table + gFormulaData + ReadMacInt16(table + gFormulaSize));
229 >                int chan_cnt = ReadMacInt16(table + gChanCnt);
230 >                if (chan_cnt == 1)
231 >                        green_gamma = blue_gamma = red_gamma;
232 >                else {
233 >                        int ofs = ReadMacInt16(table + gDataCnt);
234 >                        green_gamma = red_gamma + ofs;
235 >                        blue_gamma = green_gamma + ofs;
236                  }
237 <                video_set_palette(VidLocal.palette);
237 >                data_width = ReadMacInt16(table + gDataWidth);
238 >                have_gamma = true;
239 >        }
240 >
241 >        int num = (VidLocal.desc->mode.depth == VDEPTH_16BIT ? 32 : 256);
242 >        uint8 *p = VidLocal.palette;
243 >        for (int i=0; i<num; i++) {
244 >                uint8 red = (i * 256 / num), green = red, blue = red;
245 >                if (have_gamma) {
246 >                        red = red_gamma[red >> (8 - data_width)];
247 >                        green = green_gamma[green >> (8 - data_width)];
248 >                        blue = blue_gamma[blue >> (8 - data_width)];
249 >                }
250 >                *p++ = red;
251 >                *p++ = green;
252 >                *p++ = blue;
253 >        }
254 >
255 >        video_set_palette(VidLocal.palette, num);
256 > }
257 >
258 >
259 > /*
260 > *  Allocate gamma table of specified size
261 > */
262 >
263 > static bool allocate_gamma_table(int size)
264 > {
265 >        M68kRegisters r;
266 >
267 >        if (size > VidLocal.alloc_gamma_table_size) {
268 >                if (VidLocal.gamma_table) {
269 >                        r.a[0] = VidLocal.gamma_table;
270 >                        Execute68kTrap(0xa01f, &r);     // DisposePtr()
271 >                        VidLocal.gamma_table = 0;
272 >                        VidLocal.alloc_gamma_table_size = 0;
273 >                }
274 >                r.d[0] = size;
275 >                Execute68kTrap(0xa71e, &r);     // NewPtrSysClear()
276 >                if (r.a[0] == 0)
277 >                        return false;
278 >                VidLocal.gamma_table = r.a[0];
279 >                VidLocal.alloc_gamma_table_size = size;
280 >        }
281 >        return true;
282 > }
283 >
284 >
285 > /*
286 > *  Set gamma table (0 = build linear ramp)
287 > */
288 >
289 > static bool set_gamma_table(uint32 user_table)
290 > {
291 >        if (user_table == 0) { // Build linear ramp, 256 entries
292 >
293 >                // Allocate new table, if necessary
294 >                if (!allocate_gamma_table(SIZEOF_GammaTbl + 256))
295 >                        return memFullErr;
296 >                uint32 table = VidLocal.gamma_table;
297 >
298 >                // Initialize header
299 >                WriteMacInt16(table + gVersion, 0);
300 >                WriteMacInt16(table + gType, 0);
301 >                WriteMacInt16(table + gFormulaSize, 0);
302 >                WriteMacInt16(table + gChanCnt, 1);
303 >                WriteMacInt16(table + gDataCnt, 256);
304 >                WriteMacInt16(table + gDataWidth, 8);
305 >
306 >                // Build ramp
307 >                uint32 p = table + gFormulaData;
308 >                for (int i=0; i<256; i++)
309 >                        WriteMacInt8(p + i, i);
310 >
311 >        } else { // User-supplied gamma table
312 >
313 >                // Validate header
314 >                if (ReadMacInt16(user_table + gVersion))
315 >                        return paramErr;
316 >                if (ReadMacInt16(user_table + gType))
317 >                        return paramErr;
318 >                int chan_cnt = ReadMacInt16(user_table + gChanCnt);
319 >                if (chan_cnt != 1 && chan_cnt != 3)
320 >                        return paramErr;
321 >                int data_width = ReadMacInt16(user_table + gDataWidth);
322 >                if (data_width > 8)
323 >                        return paramErr;
324 >                int data_cnt = ReadMacInt16(user_table + gDataCnt);
325 >                if (data_cnt != (1 << data_width))
326 >                        return paramErr;
327 >
328 >                // Allocate new table, if necessary
329 >                int size = SIZEOF_GammaTbl + ReadMacInt16(user_table + gFormulaSize) + chan_cnt * data_cnt;
330 >                if (!allocate_gamma_table(size))
331 >                        return memFullErr;
332 >                uint32 table = VidLocal.gamma_table;
333 >
334 >                // Copy table
335 >                Mac2Mac_memcpy(table, user_table, size);
336 >        }
337 >
338 >        if (IsDirectMode(VidLocal.desc->mode))
339 >                load_ramp_palette();
340 >
341 >        return true;
342 > }
343 >
344 >
345 > /*
346 > *  Switch video mode
347 > */
348 >
349 > static void switch_mode(const video_mode &mode, uint32 param, uint32 dce)
350 > {
351 >        // Switch mode
352 >        set_gray_palette();
353 >        video_switch_to_mode(mode);
354 >
355 >        // Update VidLocal
356 >        VidLocal.current_mode = DepthToAppleMode(mode.depth);
357 >        VidLocal.current_id = mode.resolution_id;
358 >
359 >        uint32 frame_base = VidLocal.desc->mac_frame_base;
360 >
361 >        M68kRegisters r;
362 >        uint32 sp = VidLocal.slot_param;
363 >        r.a[0] = sp;
364 >
365 >        // Find functional sResource for this display
366 >        WriteMacInt8(sp + spSlot, ReadMacInt8(dce + dCtlSlot));
367 >        WriteMacInt8(sp + spID, ReadMacInt8(dce + dCtlSlotId));
368 >        WriteMacInt8(sp + spExtDev, 0);
369 >        r.d[0] = 0x0016;
370 >        Execute68kTrap(0xa06e, &r);     // SRsrcInfo()
371 >        uint32 rsrc = ReadMacInt32(sp + spPointer);
372 >
373 >        // Patch minorBase (otherwise rebooting won't work)
374 >        WriteMacInt8(sp + spID, 0x0a); // minorBase
375 >        r.d[0] = 0x0006;
376 >        Execute68kTrap(0xa06e, &r); // SFindStruct()
377 >        uint32 minor_base = ReadMacInt32(sp + spPointer) - ROMBaseMac;
378 >        ROMBaseHost[minor_base + 0] = frame_base >> 24;
379 >        ROMBaseHost[minor_base + 1] = frame_base >> 16;
380 >        ROMBaseHost[minor_base + 2] = frame_base >> 8;
381 >        ROMBaseHost[minor_base + 3] = frame_base;
382 >
383 >        // Patch video mode parameter table
384 >        WriteMacInt32(sp + spPointer, rsrc);
385 >        WriteMacInt8(sp + spID, DepthToAppleMode(mode.depth));
386 >        r.d[0] = 0x0006;
387 >        Execute68kTrap(0xa06e, &r); // SFindStruct()
388 >        WriteMacInt8(sp + spID, 0x01);
389 >        r.d[0] = 0x0006;
390 >        Execute68kTrap(0xa06e, &r); // SFindStruct()
391 >        uint32 p = ReadMacInt32(sp + spPointer) - ROMBaseMac;
392 >        ROMBaseHost[p +  8] = mode.bytes_per_row >> 8;
393 >        ROMBaseHost[p +  9] = mode.bytes_per_row;
394 >        ROMBaseHost[p + 14] = mode.y >> 8;
395 >        ROMBaseHost[p + 15] = mode.y;
396 >        ROMBaseHost[p + 16] = mode.x >> 8;
397 >        ROMBaseHost[p + 17] = mode.x;
398 >
399 >        // Recalculate slot ROM checksum
400 >        ChecksumSlotROM();
401 >
402 >        // Update sResource
403 >        WriteMacInt8(sp + spID, ReadMacInt8(dce + dCtlSlotId));
404 >        r.d[0] = 0x002b;
405 >        Execute68kTrap(0xa06e, &r); // SUpdateSRT()
406 >
407 >        // Update frame buffer base in DCE and param block
408 >        WriteMacInt32(dce + dCtlDevBase, frame_base);
409 >        WriteMacInt32(param + csBaseAddr, frame_base);
410 >
411 >        // Patch frame buffer base address for MacOS versions <7.6
412 >        if (!VidLocal.dm_present) { // Only do this when no Display Manager seems to be present; otherwise, the screen will not get redrawn
413 >                WriteMacInt32(0x824, frame_base);                       // ScrnBase
414 >                WriteMacInt32(0x898, frame_base);                       // CrsrBase
415 >                uint32 gdev = ReadMacInt32(0x8a4);                      // MainDevice
416 >                gdev = ReadMacInt32(gdev);
417 >                uint32 pmap = ReadMacInt32(gdev + 0x16);        // gdPMap
418 >                pmap = ReadMacInt32(pmap);
419 >                WriteMacInt32(pmap, frame_base);                        // baseAddr
420          }
421   }
422  
# Line 163 | Line 441 | int16 VideoDriverOpen(uint32 pb, uint32
441          VidLocal.current_id = VidLocal.desc->mode.resolution_id;
442          VidLocal.preferred_mode = VidLocal.current_mode;
443          VidLocal.preferred_id = VidLocal.current_id;
444 +        VidLocal.dm_present = false;
445  
446          // Allocate Slot Manager parameter block in Mac RAM
447          M68kRegisters r;
# Line 170 | Line 449 | int16 VideoDriverOpen(uint32 pb, uint32
449          Execute68kTrap(0xa71e, &r);     // NewPtrSysClear()
450          if (r.a[0] == 0)
451                  return memFullErr;
452 <        VidLocal.sp = r.a[0];
453 <        D(bug("SPBlock at %08x\n", VidLocal.sp));
452 >        VidLocal.slot_param = r.a[0];
453 >        D(bug("SPBlock at %08x\n", VidLocal.slot_param));
454  
455          // Find and set default gamma table
456 <        VidLocal.gamma_table = 0; //!!
456 >        VidLocal.gamma_table = 0;
457 >        VidLocal.alloc_gamma_table_size = 0;
458 >        set_gamma_table(0);
459  
460          // Init color palette (solid gray)
461          set_gray_palette();
# Line 204 | Line 485 | int16 VideoDriverControl(uint32 pb, uint
485                                  return paramErr;
486  
487                          if (mode != VidLocal.current_mode) {
488 <                                std::vector<video_mode>::const_iterator i = find_mode(mode, VidLocal.current_id);
488 >                                vector<video_mode>::const_iterator i = find_mode(mode, VidLocal.current_id);
489                                  if (i == VideoModes.end())
490                                          return paramErr;
491 <                                set_gray_palette();
211 <                                video_switch_to_mode(*i);
212 <                                VidLocal.current_mode = mode;
213 <                                WriteMacInt32(param + csBaseAddr, VidLocal.desc->mac_frame_base);
214 <                                WriteMacInt32(dce + dCtlDevBase, VidLocal.desc->mac_frame_base);
491 >                                switch_mode(*i, param, dce);
492                          }
493                          D(bug("  base %08x\n", VidLocal.desc->mac_frame_base));
494                          return noErr;
495                  }
496  
497 <                case cscSetEntries: {   // Set palette
498 <                        D(bug(" SetEntries table %08x, count %d, start %d\n", ReadMacInt32(param + csTable), ReadMacInt16(param + csCount), ReadMacInt16(param + csStart)));
499 <                        if (IsDirectMode(VidLocal.current_mode))
497 >                case cscSetEntries:             // Set palette
498 >                case cscDirectSetEntries: {
499 >                        D(bug(" (Direct)SetEntries table %08x, count %d, start %d\n", ReadMacInt32(param + csTable), ReadMacInt16(param + csCount), ReadMacInt16(param + csStart)));
500 >                        bool is_direct = IsDirectMode(VidLocal.desc->mode);
501 >                        if (code == cscSetEntries && is_direct)
502 >                                return controlErr;
503 >                        if (code == cscDirectSetEntries && !is_direct)
504                                  return controlErr;
505  
506                          uint32 s_pal = ReadMacInt32(param + csTable);   // Source palette
# Line 229 | Line 510 | int16 VideoDriverControl(uint32 pb, uint
510                          if (s_pal == 0 || count > 255)
511                                  return paramErr;
512  
513 +                        // Find tables for gamma correction
514 +                        uint8 *red_gamma, *green_gamma, *blue_gamma;
515 +                        bool have_gamma = false;
516 +                        int data_width = 0;
517 +                        if (VidLocal.gamma_table) {
518 +                                uint32 table = VidLocal.gamma_table;
519 +                                red_gamma = Mac2HostAddr(table + gFormulaData + ReadMacInt16(table + gFormulaSize));
520 +                                int chan_cnt = ReadMacInt16(table + gChanCnt);
521 +                                if (chan_cnt == 1)
522 +                                        green_gamma = blue_gamma = red_gamma;
523 +                                else {
524 +                                        int ofs = ReadMacInt16(table + gDataCnt);
525 +                                        green_gamma = red_gamma + ofs;
526 +                                        blue_gamma = green_gamma + ofs;
527 +                                }
528 +                                data_width = ReadMacInt16(table + gDataWidth);
529 +                                have_gamma = true;
530 +                        }
531 +
532 +                        // Convert palette
533                          if (start == 0xffff) {  // Indexed
534                                  for (uint32 i=0; i<=count; i++) {
535                                          d_pal = VidLocal.palette + (ReadMacInt16(s_pal) & 0xff) * 3;
536                                          uint8 red = (uint16)ReadMacInt16(s_pal + 2) >> 8;
537                                          uint8 green = (uint16)ReadMacInt16(s_pal + 4) >> 8;
538                                          uint8 blue = (uint16)ReadMacInt16(s_pal + 6) >> 8;
539 <                                        if (VidLocal.luminance_mapping)
539 >                                        if (VidLocal.luminance_mapping && !is_direct)
540                                                  red = green = blue = (red * 0x4ccc + green * 0x970a + blue * 0x1c29) >> 16;
541 <                                        //!! gamma correction
541 >                                        if (have_gamma) {
542 >                                                red = red_gamma[red >> (8 - data_width)];
543 >                                                green = green_gamma[green >> (8 - data_width)];
544 >                                                blue = blue_gamma[blue >> (8 - data_width)];
545 >                                        }
546                                          *d_pal++ = red;
547                                          *d_pal++ = green;
548                                          *d_pal++ = blue;
# Line 251 | Line 556 | int16 VideoDriverControl(uint32 pb, uint
556                                          uint8 red = (uint16)ReadMacInt16(s_pal + 2) >> 8;
557                                          uint8 green = (uint16)ReadMacInt16(s_pal + 4) >> 8;
558                                          uint8 blue = (uint16)ReadMacInt16(s_pal + 6) >> 8;
559 <                                        if (VidLocal.luminance_mapping)
559 >                                        if (VidLocal.luminance_mapping && !is_direct)
560                                                  red = green = blue = (red * 0x4ccc + green * 0x970a + blue * 0x1c29) >> 16;
561 <                                        //!! gamma correction
561 >                                        if (have_gamma) {
562 >                                                red = red_gamma[red >> (8 - data_width)];
563 >                                                green = green_gamma[green >> (8 - data_width)];
564 >                                                blue = blue_gamma[blue >> (8 - data_width)];
565 >                                        }
566                                          *d_pal++ = red;
567                                          *d_pal++ = green;
568                                          *d_pal++ = blue;
569                                          s_pal += 8;
570                                  }
571                          }
572 <                        video_set_palette(VidLocal.palette);
572 >                        video_set_palette(VidLocal.palette, palette_size(VidLocal.desc->mode.depth));
573                          return noErr;
574                  }
575  
576 <                case cscSetGamma:               // Set gamma table
577 <                        D(bug(" SetGamma\n"));
578 <                        //!!
579 <                        return controlErr;
576 >                case cscSetGamma: {             // Set gamma table
577 >                        uint32 user_table = ReadMacInt32(param + csGTable);
578 >                        D(bug(" SetGamma %08x\n", user_table));
579 >                        return set_gamma_table(user_table) ? noErr : memFullErr;
580 >                }
581  
582                  case cscGrayPage: {             // Fill page with dithered gray pattern
583                          D(bug(" GrayPage %d\n", ReadMacInt16(param + csPage)));
# Line 282 | Line 592 | int16 VideoDriverControl(uint32 pb, uint
592                                  0xffff0000,             // 16 bpp
593                                  0xffffffff              // 32 bpp
594                          };
595 <                        uint32 p = VidLocal.desc->mac_frame_base;
595 >                        uint32 frame_base = VidLocal.desc->mac_frame_base;
596                          uint32 pat = pattern[VidLocal.desc->mode.depth];
597                          bool invert = (VidLocal.desc->mode.depth == VDEPTH_32BIT);
598                          for (uint32 y=0; y<VidLocal.desc->mode.y; y++) {
599                                  for (uint32 x=0; x<VidLocal.desc->mode.bytes_per_row; x+=4) {
600 <                                        WriteMacInt32(p + x, pat);
600 >                                        WriteMacInt32(frame_base + x, pat);
601                                          if (invert)
602                                                  pat = ~pat;
603                                  }
604 <                                p += VidLocal.desc->mode.bytes_per_row;
604 >                                frame_base += VidLocal.desc->mode.bytes_per_row;
605                                  pat = ~pat;
606                          }
607 <                        //!! if direct mode, load gamma table to CLUT
607 >
608 >                        if (IsDirectMode(VidLocal.desc->mode))
609 >                                load_ramp_palette();
610 >
611                          return noErr;
612                  }
613  
# Line 309 | Line 622 | int16 VideoDriverControl(uint32 pb, uint
622                          return noErr;
623  
624                  case cscSetDefaultMode: { // Set default color depth
625 <                        uint16 mode = ReadMacInt16(param + csMode);
626 <                        D(bug(" SetDefaultMode %04x\n", mode));
625 >                        uint16 mode = ReadMacInt8(param + csMode);
626 >                        D(bug(" SetDefaultMode %02x\n", mode));
627                          VidLocal.preferred_mode = mode;
628                          return noErr;
629                  }
# Line 327 | Line 640 | int16 VideoDriverControl(uint32 pb, uint
640                                  return paramErr;
641  
642                          if (mode != VidLocal.current_mode || id != VidLocal.current_id) {
643 <                                std::vector<video_mode>::const_iterator i = find_mode(mode, id);
643 >                                vector<video_mode>::const_iterator i = find_mode(mode, id);
644                                  if (i == VideoModes.end())
645                                          return paramErr;
646 <                                set_gray_palette();
334 <                                video_switch_to_mode(*i);
335 <                                VidLocal.current_mode = mode;
336 <                                VidLocal.current_id = id;
337 <                                uint32 frame_base = VidLocal.desc->mac_frame_base;
338 <                                WriteMacInt32(param + csBaseAddr, frame_base);
339 <
340 <                                M68kRegisters r;
341 <                                uint32 sp = VidLocal.sp;
342 <                                r.a[0] = sp;
343 <
344 <                                // Find functional sResource for this display
345 <                                WriteMacInt8(sp + spSlot, ReadMacInt8(dce + dCtlSlot));
346 <                                WriteMacInt8(sp + spID, ReadMacInt8(dce + dCtlSlotId));
347 <                                WriteMacInt8(sp + spExtDev, 0);
348 <                                r.d[0] = 0x0016;
349 <                                Execute68kTrap(0xa06e, &r);     // SRsrcInfo()
350 <                                uint32 rsrc = ReadMacInt32(sp + spPointer);
351 <
352 <                                // Patch minorBase
353 <                                WriteMacInt8(sp + spID, 0x0a); // minorBase
354 <                                r.d[0] = 0x0006;
355 <                                Execute68kTrap(0xa06e, &r); // SFindStruct()
356 <                                uint32 minor_base = ReadMacInt32(sp + spPointer) - ROMBaseMac;
357 <                                ROMBaseHost[minor_base + 0] = frame_base >> 24;
358 <                                ROMBaseHost[minor_base + 1] = frame_base >> 16;
359 <                                ROMBaseHost[minor_base + 2] = frame_base >> 8;
360 <                                ROMBaseHost[minor_base + 3] = frame_base;
361 <
362 <                                // Patch video mode parameter table
363 <                                WriteMacInt32(sp + spPointer, rsrc);
364 <                                WriteMacInt8(sp + spID, mode);
365 <                                r.d[0] = 0x0006;
366 <                                Execute68kTrap(0xa06e, &r); // SFindStruct()
367 <                                WriteMacInt8(sp + spID, 0x01);
368 <                                r.d[0] = 0x0006;
369 <                                Execute68kTrap(0xa06e, &r); // SFindStruct()
370 <                                uint32 p = ReadMacInt32(sp + spPointer) - ROMBaseMac;
371 <                                ROMBaseHost[p +  8] = i->bytes_per_row >> 8;
372 <                                ROMBaseHost[p +  9] = i->bytes_per_row;
373 <                                ROMBaseHost[p + 14] = i->y >> 8;
374 <                                ROMBaseHost[p + 15] = i->y;
375 <                                ROMBaseHost[p + 16] = i->x >> 8;
376 <                                ROMBaseHost[p + 17] = i->x;
377 <
378 <                                // Update sResource
379 <                                WriteMacInt8(sp + spID, ReadMacInt8(dce + dCtlSlotId));
380 <                                r.d[0] = 0x002b;
381 <                                Execute68kTrap(0xa06e, &r); // SUpdateSRT()
382 <
383 <                                // Update frame buffer base in DCE
384 <                                WriteMacInt32(dce + dCtlDevBase, frame_base);
646 >                                switch_mode(*i, param, dce);
647                          }
648                          D(bug("  base %08x\n", VidLocal.desc->mac_frame_base));
649                          return noErr;
# Line 474 | Line 736 | int16 VideoDriverStatus(uint32 pb, uint3
736  
737                  case cscGetGray:                        // Get luminance mapping flag
738                          D(bug(" GetGray -> %d\n", VidLocal.luminance_mapping));
739 <                        WriteMacInt16(param, VidLocal.luminance_mapping ? 0x0100 : 0);
739 >                        WriteMacInt8(param, VidLocal.luminance_mapping ? 1 : 0);
740                          return noErr;
741  
742                  case cscGetInterrupt:           // Get interrupt disable flag
743                          D(bug(" GetInterrupt -> %d\n", VidLocal.interrupts_enabled));
744 <                        WriteMacInt16(param, VidLocal.interrupts_enabled ? 0 : 0x0100);
744 >                        WriteMacInt8(param, VidLocal.interrupts_enabled ? 0 : 1);
745                          return noErr;
746  
747                  case cscGetGamma:
748 <                        D(bug(" GetGamma -> \n"));
749 <                        //!!
750 <                        return statusErr;
748 >                        D(bug(" GetGamma -> %08x\n", VidLocal.gamma_table));
749 >                        WriteMacInt32(param + csGTable, VidLocal.gamma_table);
750 >                        return noErr;
751  
752                  case cscGetDefaultMode:         // Get default color depth
753 <                        D(bug(" GetDefaultMode -> %04x\n", VidLocal.preferred_mode));
754 <                        WriteMacInt16(param + csMode, VidLocal.preferred_mode);
753 >                        D(bug(" GetDefaultMode -> %02x\n", VidLocal.preferred_mode));
754 >                        WriteMacInt8(param + csMode, VidLocal.preferred_mode);
755                          return noErr;
756  
757                  case cscGetCurrentMode:         // Get current video mode (depth and resolution)
# Line 573 | Line 835 | int16 VideoDriverStatus(uint32 pb, uint3
835                          WriteMacInt32(param + csVerticalLines, y);
836                          WriteMacInt32(param + csRefreshRate, 75 << 16);
837                          WriteMacInt16(param + csMaxDepthMode, DepthToAppleMode(max_depth_of_resolution(id)));
838 +                        WriteMacInt32(param + csResolutionFlags, 0);
839                          return noErr;
840                  }
841  
# Line 580 | Line 843 | int16 VideoDriverStatus(uint32 pb, uint3
843                          uint32 id = ReadMacInt32(param + csDisplayModeID);
844                          uint16 mode = ReadMacInt16(param + csDepthMode);
845                          D(bug(" GetVideoParameters %04x/%08x\n", mode, id));
846 +                        VidLocal.dm_present = true;     // Display Manager seems to be present
847  
848 <                        std::vector<video_mode>::const_iterator i = VideoModes.begin(), end = VideoModes.end();
849 <                        while (i != end) {
848 >                        vector<video_mode>::const_iterator i, end = VideoModes.end();
849 >                        for (i = VideoModes.begin(); i != end; ++i) {
850                                  if (DepthToAppleMode(i->depth) == mode && i->resolution_id == id) {
851                                          uint32 vp = ReadMacInt32(param + csVPBlockPtr);
852                                          WriteMacInt32(vp + vpBaseOffset, 0);
# Line 637 | Line 901 | int16 VideoDriverStatus(uint32 pb, uint3
901                                          WriteMacInt32(param + csDeviceType, dev_type);
902                                          return noErr;
903                                  }
640                                ++i;
904                          }
905                          return paramErr; // specified resolution/depth not supported
906                  }
907  
908 +                case cscGetMultiConnect: {
909 +                        uint32 conn = ReadMacInt32(param + csDisplayCountOrNumber);
910 +                        D(bug(" GetMultiConnect %08x\n", conn));
911 +                        if (conn == 0xffffffff) {       // Get number of connections
912 +                                WriteMacInt32(param + csDisplayCountOrNumber, 1); // Single-headed
913 +                                return noErr;
914 +                        } else if (conn == 1) {         // Get information about first connection
915 +                                WriteMacInt16(param + csConnectInfo + csDisplayType, 8);                // Modeless connection
916 +                                WriteMacInt8(param + csConnectInfo + csConnectTaggedType, 0);
917 +                                WriteMacInt8(param + csConnectInfo + csConnectTaggedData, 0);
918 +                                WriteMacInt32(param + csConnectInfo + csConnectFlags, 0x43);    // All modes valid and safe, non-standard tagging
919 +                                WriteMacInt32(param + csConnectInfo + csDisplayComponent, 0);
920 +                                return noErr;
921 +                        } else
922 +                                return paramErr;
923 +                }
924 +
925                  default:
926                          printf("WARNING: Unknown VideoDriverStatus(%d)\n", code);
927                          return statusErr;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines