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.10 by cebix, 2001-06-27T20:05:23Z vs.
Revision 1.14 by cebix, 2001-06-30T17:21:51Z

# Line 31 | Line 31
31   #include "cpu_emulation.h"
32   #include "main.h"
33   #include "macos_util.h"
34 + #include "slot_rom.h"
35   #include "video.h"
36   #include "video_defs.h"
37  
38 < #define DEBUG 1
38 > #define DEBUG 0
39   #include "debug.h"
40  
41  
42   // List of supported video modes
43 < vector<video_mode> VideoModes;
43 > std::vector<video_mode> VideoModes;
44  
45   // Description of the main monitor
46   monitor_desc VideoMonitor;
# Line 50 | Line 51 | struct {
51          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 +        uint32 gamma_table;                     // Mac address of gamma table
55 +        int alloc_gamma_table_size;     // Allocated size of gamma table
56          uint16 current_mode;            // Currently selected depth/resolution
57          uint32 current_id;
58          uint16 preferred_mode;          // Preferred depth/resolution
59          uint32 preferred_id;
60 +        uint32 sp;                                      // Mac address of Slot Manager parameter block
61   } VidLocal;
62  
63  
# Line 96 | Line 100 | static std::vector<video_mode>::const_it
100   static video_depth max_depth_of_resolution(uint32 id)
101   {
102          video_depth m = VDEPTH_1BIT;
103 <        vector<video_mode>::const_iterator i = VideoModes.begin(), end = VideoModes.end();
103 >        std::vector<video_mode>::const_iterator i = VideoModes.begin(), end = VideoModes.end();
104          while (i != end) {
105                  if (i->depth > m)
106                          m = i->depth;
# Line 112 | Line 116 | static video_depth max_depth_of_resoluti
116  
117   static void get_size_of_resolution(uint32 id, uint32 &x, uint32 &y)
118   {
119 <        vector<video_mode>::const_iterator i = VideoModes.begin(), end = VideoModes.end();
119 >        std::vector<video_mode>::const_iterator i = VideoModes.begin(), end = VideoModes.end();
120          while (i != end) {
121                  if (i->resolution_id == id) {
122                          x = i->x;
# Line 125 | Line 129 | static void get_size_of_resolution(uint3
129  
130  
131   /*
132 + *  Set palette to 50% gray
133 + */
134 +
135 + static void set_gray_palette(void)
136 + {
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 + *  Load gamma-corrected black-to-white ramp to palette for direct-color mode
148 + */
149 +
150 + static void load_ramp_palette(void)
151 + {
152 +        // Find tables for gamma correction
153 +        uint8 *red_gamma, *green_gamma, *blue_gamma;
154 +        bool have_gamma = false;
155 +        int data_width = 0;
156 +        if (VidLocal.gamma_table) {
157 +                uint32 table = VidLocal.gamma_table;
158 +                red_gamma = Mac2HostAddr(table + gFormulaData + ReadMacInt16(table + gFormulaSize));
159 +                int chan_cnt = ReadMacInt16(table + gChanCnt);
160 +                if (chan_cnt == 1)
161 +                        green_gamma = blue_gamma = red_gamma;
162 +                else {
163 +                        int ofs = ReadMacInt16(table + gDataCnt);
164 +                        green_gamma = red_gamma + ofs;
165 +                        blue_gamma = green_gamma + ofs;
166 +                }
167 +                data_width = ReadMacInt16(table + gDataWidth);
168 +                have_gamma = true;
169 +        }
170 +
171 +        int num = (VidLocal.desc->mode.depth == VDEPTH_16BIT ? 32 : 256);
172 +        int inc = 256 / num, value = 0;
173 +        uint8 *p = VidLocal.palette;
174 +        for (int i=0; i<num; i++) {
175 +                uint8 red = value, green = value, blue = value;
176 +                if (have_gamma) {
177 +                        red = red_gamma[red >> (8 - data_width)];
178 +                        green = green_gamma[green >> (8 - data_width)];
179 +                        blue = blue_gamma[blue >> (8 - data_width)];
180 +                }
181 +                *p++ = red;
182 +                *p++ = green;
183 +                *p++ = blue;
184 +                value += inc;
185 +        }
186 +
187 +        video_set_palette(VidLocal.palette);
188 + }
189 +
190 +
191 + /*
192 + *  Allocate gamma table of specified size
193 + */
194 +
195 + static bool allocate_gamma_table(int size)
196 + {
197 +        M68kRegisters r;
198 +
199 +        if (size > VidLocal.alloc_gamma_table_size) {
200 +                if (VidLocal.gamma_table) {
201 +                        r.a[0] = VidLocal.gamma_table;
202 +                        Execute68kTrap(0xa01f, &r);     // DisposePtr()
203 +                        VidLocal.gamma_table = 0;
204 +                        VidLocal.alloc_gamma_table_size = 0;
205 +                }
206 +                r.d[0] = size;
207 +                Execute68kTrap(0xa71e, &r);     // NewPtrSysClear()
208 +                if (r.a[0] == 0)
209 +                        return false;
210 +                VidLocal.gamma_table = r.a[0];
211 +                VidLocal.alloc_gamma_table_size = size;
212 +        }
213 +        return true;
214 + }
215 +
216 +
217 + /*
218 + *  Set gamma table (0 = build linear ramp)
219 + */
220 +
221 + static bool set_gamma_table(uint32 user_table)
222 + {
223 +        if (user_table == 0) { // Build linear ramp, 256 entries
224 +
225 +                // Allocate new table, if necessary
226 +                if (!allocate_gamma_table(SIZEOF_GammaTbl + 256))
227 +                        return memFullErr;
228 +                uint32 table = VidLocal.gamma_table;
229 +
230 +                // Initialize header
231 +                WriteMacInt16(table + gVersion, 0);
232 +                WriteMacInt16(table + gType, 0);
233 +                WriteMacInt16(table + gFormulaSize, 0);
234 +                WriteMacInt16(table + gChanCnt, 1);
235 +                WriteMacInt16(table + gDataCnt, 256);
236 +                WriteMacInt16(table + gDataWidth, 8);
237 +
238 +                // Build ramp
239 +                uint32 p = table + gFormulaData;
240 +                for (int i=0; i<256; i++)
241 +                        WriteMacInt8(p + i, i);
242 +
243 +        } else { // User-supplied gamma table
244 +
245 +                // Validate header
246 +                if (ReadMacInt16(user_table + gVersion))
247 +                        return paramErr;
248 +                if (ReadMacInt16(user_table + gType))
249 +                        return paramErr;
250 +                int chan_cnt = ReadMacInt16(user_table + gChanCnt);
251 +                if (chan_cnt != 1 && chan_cnt != 3)
252 +                        return paramErr;
253 +                int data_width = ReadMacInt16(user_table + gDataWidth);
254 +                if (data_width > 8)
255 +                        return paramErr;
256 +                int data_cnt = ReadMacInt16(user_table + gDataCnt);
257 +                if (data_cnt != (1 << data_width))
258 +                        return paramErr;
259 +
260 +                // Allocate new table, if necessary
261 +                int size = SIZEOF_GammaTbl + ReadMacInt16(user_table + gFormulaSize) + chan_cnt * data_cnt;
262 +                if (!allocate_gamma_table(size))
263 +                        return memFullErr;
264 +                uint32 table = VidLocal.gamma_table;
265 +
266 +                // Copy table
267 +                Mac2Mac_memcpy(table, user_table, size);
268 +        }
269 +
270 +        if (IsDirectMode(VidLocal.current_mode))
271 +                load_ramp_palette();
272 +
273 +        return true;
274 + }
275 +
276 +
277 + /*
278   *  Driver Open() routine
279   */
280  
# Line 145 | Line 295 | int16 VideoDriverOpen(uint32 pb, uint32
295          VidLocal.preferred_mode = VidLocal.current_mode;
296          VidLocal.preferred_id = VidLocal.current_id;
297  
298 +        // Allocate Slot Manager parameter block in Mac RAM
299 +        M68kRegisters r;
300 +        r.d[0] = SIZEOF_SPBlock;
301 +        Execute68kTrap(0xa71e, &r);     // NewPtrSysClear()
302 +        if (r.a[0] == 0)
303 +                return memFullErr;
304 +        VidLocal.sp = r.a[0];
305 +        D(bug("SPBlock at %08x\n", VidLocal.sp));
306 +
307 +        // Find and set default gamma table
308 +        VidLocal.gamma_table = 0;
309 +        VidLocal.alloc_gamma_table_size = 0;
310 +        set_gamma_table(0);
311 +
312          // Init color palette (solid gray)
313 <        if (!IsDirectMode(VidLocal.desc->mode)) {
150 <                for (int i=0; i<256; i++) {
151 <                        VidLocal.palette[i * 3 + 0] = 127;
152 <                        VidLocal.palette[i * 3 + 1] = 127;
153 <                        VidLocal.palette[i * 3 + 2] = 127;
154 <                }
155 <                video_set_palette(VidLocal.palette);
156 <        }
313 >        set_gray_palette();
314          return noErr;
315   }
316  
# Line 173 | Line 330 | int16 VideoDriverControl(uint32 pb, uint
330                          uint16 mode = ReadMacInt16(param + csMode);
331                          D(bug(" SetMode %04x\n", mode));
332  
333 +                        // Set old base address in case the switch fails
334 +                        WriteMacInt32(param + csBaseAddr, VidLocal.desc->mac_frame_base);
335 +
336 +                        if (ReadMacInt16(param + csPage))
337 +                                return paramErr;
338 +
339                          if (mode != VidLocal.current_mode) {
340                                  std::vector<video_mode>::const_iterator i = find_mode(mode, VidLocal.current_id);
341 <                                if (i == VideoModes.end()) {
179 <                                        WriteMacInt32(param + csBaseAddr, VidLocal.desc->mac_frame_base);
341 >                                if (i == VideoModes.end())
342                                          return paramErr;
343 <                                }
343 >                                set_gray_palette();
344                                  video_switch_to_mode(*i);
345                                  VidLocal.current_mode = mode;
346 +                                WriteMacInt32(param + csBaseAddr, VidLocal.desc->mac_frame_base);
347 +                                WriteMacInt32(dce + dCtlDevBase, VidLocal.desc->mac_frame_base);
348                          }
349 <                        WriteMacInt32(param + csBaseAddr, VidLocal.desc->mac_frame_base);
349 >                        D(bug("  base %08x\n", VidLocal.desc->mac_frame_base));
350                          return noErr;
351                  }
352  
353 <                case cscSetEntries: {   // Set palette
354 <                        D(bug(" SetEntries table %08lx, count %d, start %d\n", ReadMacInt32(param + csTable), ReadMacInt16(param + csCount), ReadMacInt16(param + csStart)));
355 <                        if (IsDirectMode(VidLocal.desc->mode))
353 >                case cscSetEntries:             // Set palette
354 >                case cscDirectSetEntries: {
355 >                        D(bug(" (Direct)SetEntries table %08x, count %d, start %d\n", ReadMacInt32(param + csTable), ReadMacInt16(param + csCount), ReadMacInt16(param + csStart)));
356 >                        bool is_direct = IsDirectMode(VidLocal.current_mode);
357 >                        if (code == cscSetEntries && is_direct)
358 >                                return controlErr;
359 >                        if (code == cscDirectSetEntries && !is_direct)
360                                  return controlErr;
361  
362                          uint32 s_pal = ReadMacInt32(param + csTable);   // Source palette
363                          uint8 *d_pal;                                                                   // Destination palette
364 +                        uint16 start = ReadMacInt16(param + csStart);
365                          uint16 count = ReadMacInt16(param + csCount);
366 <                        if (!s_pal || count > 255)
366 >                        if (s_pal == 0 || count > 255)
367                                  return paramErr;
368  
369 <                        if (ReadMacInt16(param + csStart) == 0xffff) {  // Indexed
369 >                        // Find tables for gamma correction
370 >                        uint8 *red_gamma, *green_gamma, *blue_gamma;
371 >                        bool have_gamma = false;
372 >                        int data_width = 0;
373 >                        if (VidLocal.gamma_table) {
374 >                                uint32 table = VidLocal.gamma_table;
375 >                                red_gamma = Mac2HostAddr(table + gFormulaData + ReadMacInt16(table + gFormulaSize));
376 >                                int chan_cnt = ReadMacInt16(table + gChanCnt);
377 >                                if (chan_cnt == 1)
378 >                                        green_gamma = blue_gamma = red_gamma;
379 >                                else {
380 >                                        int ofs = ReadMacInt16(table + gDataCnt);
381 >                                        green_gamma = red_gamma + ofs;
382 >                                        blue_gamma = green_gamma + ofs;
383 >                                }
384 >                                data_width = ReadMacInt16(table + gDataWidth);
385 >                                have_gamma = true;
386 >                        }
387 >
388 >                        // Convert palette
389 >                        if (start == 0xffff) {  // Indexed
390                                  for (uint32 i=0; i<=count; i++) {
391 <                                        d_pal = VidLocal.palette + ReadMacInt16(s_pal) * 3;
391 >                                        d_pal = VidLocal.palette + (ReadMacInt16(s_pal) & 0xff) * 3;
392                                          uint8 red = (uint16)ReadMacInt16(s_pal + 2) >> 8;
393                                          uint8 green = (uint16)ReadMacInt16(s_pal + 4) >> 8;
394                                          uint8 blue = (uint16)ReadMacInt16(s_pal + 6) >> 8;
395 <                                        if (VidLocal.luminance_mapping)
395 >                                        if (VidLocal.luminance_mapping && !is_direct)
396                                                  red = green = blue = (red * 0x4ccc + green * 0x970a + blue * 0x1c29) >> 16;
397 +                                        if (have_gamma) {
398 +                                                red = red_gamma[red >> (8 - data_width)];
399 +                                                green = green_gamma[green >> (8 - data_width)];
400 +                                                blue = blue_gamma[blue >> (8 - data_width)];
401 +                                        }
402                                          *d_pal++ = red;
403                                          *d_pal++ = green;
404                                          *d_pal++ = blue;
405                                          s_pal += 8;
406                                  }
407 <                        } else {                                                                                // Sequential
408 <                                d_pal = VidLocal.palette + ReadMacInt16(param + csStart) * 3;
407 >                        } else {                                // Sequential
408 >                                if (start + count > 255)
409 >                                        return paramErr;
410 >                                d_pal = VidLocal.palette + start * 3;
411                                  for (uint32 i=0; i<=count; i++) {
412                                          uint8 red = (uint16)ReadMacInt16(s_pal + 2) >> 8;
413                                          uint8 green = (uint16)ReadMacInt16(s_pal + 4) >> 8;
414                                          uint8 blue = (uint16)ReadMacInt16(s_pal + 6) >> 8;
415 <                                        if (VidLocal.luminance_mapping)
415 >                                        if (VidLocal.luminance_mapping && !is_direct)
416                                                  red = green = blue = (red * 0x4ccc + green * 0x970a + blue * 0x1c29) >> 16;
417 +                                        if (have_gamma) {
418 +                                                red = red_gamma[red >> (8 - data_width)];
419 +                                                green = green_gamma[green >> (8 - data_width)];
420 +                                                blue = blue_gamma[blue >> (8 - data_width)];
421 +                                        }
422                                          *d_pal++ = red;
423                                          *d_pal++ = green;
424                                          *d_pal++ = blue;
# Line 228 | Line 429 | int16 VideoDriverControl(uint32 pb, uint
429                          return noErr;
430                  }
431  
432 <                case cscSetGamma:               // Set gamma table
433 <                        D(bug(" SetGamma\n"));
434 <                        //!!
435 <                        return noErr;
432 >                case cscSetGamma: {             // Set gamma table
433 >                        uint32 user_table = ReadMacInt32(param + csGTable);
434 >                        D(bug(" SetGamma %08x\n", user_table));
435 >                        return set_gamma_table(user_table) ? noErr : memFullErr;
436 >                }
437  
438                  case cscGrayPage: {             // Fill page with dithered gray pattern
439                          D(bug(" GrayPage %d\n", ReadMacInt16(param + csPage)));
# Line 248 | Line 450 | int16 VideoDriverControl(uint32 pb, uint
450                          };
451                          uint32 p = VidLocal.desc->mac_frame_base;
452                          uint32 pat = pattern[VidLocal.desc->mode.depth];
453 +                        bool invert = (VidLocal.desc->mode.depth == VDEPTH_32BIT);
454                          for (uint32 y=0; y<VidLocal.desc->mode.y; y++) {
455                                  for (uint32 x=0; x<VidLocal.desc->mode.bytes_per_row; x+=4) {
456                                          WriteMacInt32(p + x, pat);
457 <                                        if (VidLocal.desc->mode.depth == VDEPTH_32BIT)
457 >                                        if (invert)
458                                                  pat = ~pat;
459                                  }
460                                  p += VidLocal.desc->mode.bytes_per_row;
461                                  pat = ~pat;
462                          }
463 +
464 +                        if (IsDirectMode(VidLocal.current_mode))
465 +                                load_ramp_palette();
466 +
467                          return noErr;
468                  }
469  
# Line 270 | Line 477 | int16 VideoDriverControl(uint32 pb, uint
477                          VidLocal.interrupts_enabled = (ReadMacInt8(param + csMode) == 0);
478                          return noErr;
479  
273                // case cscDirectSetEntries:
274
480                  case cscSetDefaultMode: { // Set default color depth
481                          uint16 mode = ReadMacInt16(param + csMode);
482                          D(bug(" SetDefaultMode %04x\n", mode));
# Line 284 | Line 489 | int16 VideoDriverControl(uint32 pb, uint
489                          uint32 id = ReadMacInt32(param + csData);
490                          D(bug(" SwitchMode %04x, %08x\n", mode, id));
491  
492 +                        // Set old base address in case the switch fails
493 +                        WriteMacInt32(param + csBaseAddr, VidLocal.desc->mac_frame_base);
494 +
495 +                        if (ReadMacInt16(param + csPage))
496 +                                return paramErr;
497 +
498                          if (mode != VidLocal.current_mode || id != VidLocal.current_id) {
499                                  std::vector<video_mode>::const_iterator i = find_mode(mode, id);
500 <                                if (i == VideoModes.end()) {
290 <                                        WriteMacInt32(param + csBaseAddr, VidLocal.desc->mac_frame_base);
500 >                                if (i == VideoModes.end())
501                                          return paramErr;
502 <                                }
502 >                                set_gray_palette();
503                                  video_switch_to_mode(*i);
504                                  VidLocal.current_mode = mode;
505                                  VidLocal.current_id = id;
506 +                                uint32 frame_base = VidLocal.desc->mac_frame_base;
507 +                                WriteMacInt32(param + csBaseAddr, frame_base);
508 +
509 +                                M68kRegisters r;
510 +                                uint32 sp = VidLocal.sp;
511 +                                r.a[0] = sp;
512 +
513 +                                // Find functional sResource for this display
514 +                                WriteMacInt8(sp + spSlot, ReadMacInt8(dce + dCtlSlot));
515 +                                WriteMacInt8(sp + spID, ReadMacInt8(dce + dCtlSlotId));
516 +                                WriteMacInt8(sp + spExtDev, 0);
517 +                                r.d[0] = 0x0016;
518 +                                Execute68kTrap(0xa06e, &r);     // SRsrcInfo()
519 +                                uint32 rsrc = ReadMacInt32(sp + spPointer);
520 +
521 +                                // Patch minorBase (otherwise rebooting won't work)
522 +                                WriteMacInt8(sp + spID, 0x0a); // minorBase
523 +                                r.d[0] = 0x0006;
524 +                                Execute68kTrap(0xa06e, &r); // SFindStruct()
525 +                                uint32 minor_base = ReadMacInt32(sp + spPointer) - ROMBaseMac;
526 +                                ROMBaseHost[minor_base + 0] = frame_base >> 24;
527 +                                ROMBaseHost[minor_base + 1] = frame_base >> 16;
528 +                                ROMBaseHost[minor_base + 2] = frame_base >> 8;
529 +                                ROMBaseHost[minor_base + 3] = frame_base;
530 +
531 +                                // Patch video mode parameter table
532 +                                WriteMacInt32(sp + spPointer, rsrc);
533 +                                WriteMacInt8(sp + spID, mode);
534 +                                r.d[0] = 0x0006;
535 +                                Execute68kTrap(0xa06e, &r); // SFindStruct()
536 +                                WriteMacInt8(sp + spID, 0x01);
537 +                                r.d[0] = 0x0006;
538 +                                Execute68kTrap(0xa06e, &r); // SFindStruct()
539 +                                uint32 p = ReadMacInt32(sp + spPointer) - ROMBaseMac;
540 +                                ROMBaseHost[p +  8] = i->bytes_per_row >> 8;
541 +                                ROMBaseHost[p +  9] = i->bytes_per_row;
542 +                                ROMBaseHost[p + 14] = i->y >> 8;
543 +                                ROMBaseHost[p + 15] = i->y;
544 +                                ROMBaseHost[p + 16] = i->x >> 8;
545 +                                ROMBaseHost[p + 17] = i->x;
546 +
547 +                                // Recalculate slot ROM checksum
548 +                                ChecksumSlotROM();
549 +
550 +                                // Update sResource
551 +                                WriteMacInt8(sp + spID, ReadMacInt8(dce + dCtlSlotId));
552 +                                r.d[0] = 0x002b;
553 +                                Execute68kTrap(0xa06e, &r); // SUpdateSRT()
554 +
555 +                                // Update frame buffer base in DCE
556 +                                WriteMacInt32(dce + dCtlDevBase, frame_base);
557                          }
558 <                        WriteMacInt32(param + csBaseAddr, VidLocal.desc->mac_frame_base);
558 >                        D(bug("  base %08x\n", VidLocal.desc->mac_frame_base));
559                          return noErr;
560                  }
561  
# Line 332 | Line 593 | int16 VideoDriverStatus(uint32 pb, uint3
593                          WriteMacInt32(param + csBaseAddr, VidLocal.desc->mac_frame_base);
594                          return noErr;
595  
596 <                // case cscGetEntries:
596 >                case cscGetEntries: {           // Read palette
597 >                        D(bug(" GetEntries table %08x, count %d, start %d\n", ReadMacInt32(param + csTable), ReadMacInt16(param + csCount), ReadMacInt16(param + csStart)));
598  
599 <                case cscGetPageCnt:                     // Get number of pages
600 <                        D(bug(" GetPageCnt -> 1\n"));
599 >                        uint8 *s_pal;                                                                   // Source palette
600 >                        uint32 d_pal = ReadMacInt32(param + csTable);   // Destination palette
601 >                        uint16 start = ReadMacInt16(param + csStart);
602 >                        uint16 count = ReadMacInt16(param + csCount);
603 >                        if (d_pal == 0 || count > 255)
604 >                                return paramErr;
605 >
606 >                        if (start == 0xffff) {  // Indexed
607 >                                for (uint32 i=0; i<=count; i++) {
608 >                                        s_pal = VidLocal.palette + (ReadMacInt16(d_pal) & 0xff) * 3;
609 >                                        uint8 red = *s_pal++;
610 >                                        uint8 green = *s_pal++;
611 >                                        uint8 blue = *s_pal++;
612 >                                        WriteMacInt16(d_pal + 2, red * 0x0101);
613 >                                        WriteMacInt16(d_pal + 4, green * 0x0101);
614 >                                        WriteMacInt16(d_pal + 6, blue * 0x0101);
615 >                                        d_pal += 8;
616 >                                }
617 >                        } else {                                // Sequential
618 >                                if (start + count > 255)
619 >                                        return paramErr;
620 >                                s_pal = VidLocal.palette + start * 3;
621 >                                for (uint32 i=0; i<=count; i++) {
622 >                                        uint8 red = *s_pal++;
623 >                                        uint8 green = *s_pal++;
624 >                                        uint8 blue = *s_pal++;
625 >                                        WriteMacInt16(d_pal + 2, red * 0x0101);
626 >                                        WriteMacInt16(d_pal + 4, green * 0x0101);
627 >                                        WriteMacInt16(d_pal + 6, blue * 0x0101);
628 >                                        d_pal += 8;
629 >                                }
630 >                        }
631 >                        return noErr;
632 >                }
633 >
634 >                case cscGetPages:                       // Get number of pages
635 >                        D(bug(" GetPages -> 1\n"));
636                          WriteMacInt16(param + csPage, 1);
637                          return noErr;
638  
639 <                case cscGetPageBase:            // Get page base address
640 <                        D(bug(" GetPageBase -> %08x\n", VidLocal.desc->mac_frame_base));
639 >                case cscGetBaseAddress:         // Get page base address
640 >                        D(bug(" GetBaseAddress -> %08x\n", VidLocal.desc->mac_frame_base));
641                          WriteMacInt32(param + csBaseAddr, VidLocal.desc->mac_frame_base);
642 <                        return noErr;
642 >                        if (ReadMacInt16(param + csPage))
643 >                                return paramErr;
644 >                        else
645 >                                return noErr;
646  
647                  case cscGetGray:                        // Get luminance mapping flag
648                          D(bug(" GetGray -> %d\n", VidLocal.luminance_mapping));
649 <                        WriteMacInt8(param, VidLocal.luminance_mapping ? 1 : 0);
649 >                        WriteMacInt16(param, VidLocal.luminance_mapping ? 0x0100 : 0);
650                          return noErr;
651  
652                  case cscGetInterrupt:           // Get interrupt disable flag
653                          D(bug(" GetInterrupt -> %d\n", VidLocal.interrupts_enabled));
654 <                        WriteMacInt8(param, VidLocal.interrupts_enabled ? 0 : 1);
654 >                        WriteMacInt16(param, VidLocal.interrupts_enabled ? 0 : 0x0100);
655                          return noErr;
656  
657 <                // case cscGetGamma:
657 >                case cscGetGamma:
658 >                        D(bug(" GetGamma -> %08x\n", VidLocal.gamma_table));
659 >                        WriteMacInt32(param + csGTable, VidLocal.gamma_table);
660 >                        return noErr;
661  
662                  case cscGetDefaultMode:         // Get default color depth
663                          D(bug(" GetDefaultMode -> %04x\n", VidLocal.preferred_mode));
664                          WriteMacInt16(param + csMode, VidLocal.preferred_mode);
665                          return noErr;
666  
667 <                case cscGetCurMode:                     // Get current video mode (depth and resolution)
668 <                        D(bug(" GetCurMode -> %04x/%08x\n", VidLocal.current_mode, VidLocal.current_id));
667 >                case cscGetCurrentMode:         // Get current video mode (depth and resolution)
668 >                        D(bug(" GetCurMode -> %04x/%08x, base %08x\n", VidLocal.current_mode, VidLocal.current_id, VidLocal.desc->mac_frame_base));
669                          WriteMacInt16(param + csMode, VidLocal.current_mode);
670                          WriteMacInt32(param + csData, VidLocal.current_id);
671                          WriteMacInt16(param + csPage, 0);
# Line 371 | Line 674 | int16 VideoDriverStatus(uint32 pb, uint3
674  
675                  case cscGetConnection:          // Get monitor information
676                          D(bug(" GetConnection\n"));
677 <                        WriteMacInt16(param + csDisplayType, 6);                // 21" Multiscan
678 <                        WriteMacInt8(param + csConnectTaggedType, 6);
679 <                        WriteMacInt8(param + csConnectTaggedData, 0x23);
680 <                        WriteMacInt32(param + csConnectFlags, 0x03);    // All modes valid and safe
677 >                        WriteMacInt16(param + csDisplayType, 8);                // Modeless connection
678 >                        WriteMacInt8(param + csConnectTaggedType, 0);
679 >                        WriteMacInt8(param + csConnectTaggedData, 0);
680 >                        WriteMacInt32(param + csConnectFlags, 0x43);    // All modes valid and safe, non-standard tagging
681                          WriteMacInt32(param + csDisplayComponent, 0);
682                          return noErr;
683  
684 +                case cscGetModeTiming: {        // Get video timing for specified resolution
685 +                        uint32 id = ReadMacInt32(param + csTimingMode);
686 +                        D(bug(" GetModeTiming %08x\n", id));
687 +                        if (!has_resolution(id))
688 +                                return paramErr;
689 +
690 +                        WriteMacInt32(param + csTimingFormat, FOURCC('d', 'e', 'c', 'l'));
691 +                        WriteMacInt32(param + csTimingData, 0); // unknown
692 +                        uint32 flags = 0xb; // mode valid, safe and shown in Monitors panel
693 +                        if (id == VidLocal.preferred_id)
694 +                                flags |= 4; // default mode
695 +                        WriteMacInt32(param + csTimingFlags, flags);
696 +                        return noErr;
697 +                }
698 +
699                  case cscGetModeBaseAddress:     // Get frame buffer base address
700 <                        D(bug(" GetModeBaseAddress -> %08x\n", VidLocal.desc->mac_frame_base));
701 <                        WriteMacInt32(param + csBaseAddr, VidLocal.desc->mac_frame_base);       // Base address of video RAM for the current DisplayModeID and relative bit depth
700 >                        D(bug(" GetModeBaseAddress -> base %08x\n", VidLocal.desc->mac_frame_base));
701 >                        WriteMacInt32(param + csBaseAddr, VidLocal.desc->mac_frame_base);
702                          return noErr;
703  
704                  case cscGetPreferredConfiguration: // Get default video mode (depth and resolution)
# Line 427 | Line 745 | int16 VideoDriverStatus(uint32 pb, uint3
745                          WriteMacInt32(param + csVerticalLines, y);
746                          WriteMacInt32(param + csRefreshRate, 75 << 16);
747                          WriteMacInt16(param + csMaxDepthMode, DepthToAppleMode(max_depth_of_resolution(id)));
430                        uint32 flags = 0xb; // mode valid, safe and shown in Monitors panel
431                        if (id == VidLocal.preferred_id)
432                                flags |= 4; // default mode
433                        WriteMacInt32(param + csResolutionFlags, flags);
748                          return noErr;
749                  }
750  
# Line 439 | Line 753 | int16 VideoDriverStatus(uint32 pb, uint3
753                          uint16 mode = ReadMacInt16(param + csDepthMode);
754                          D(bug(" GetVideoParameters %04x/%08x\n", mode, id));
755  
756 <                        vector<video_mode>::const_iterator i = VideoModes.begin(), end = VideoModes.end();
756 >                        std::vector<video_mode>::const_iterator i = VideoModes.begin(), end = VideoModes.end();
757                          while (i != end) {
758                                  if (DepthToAppleMode(i->depth) == mode && i->resolution_id == id) {
759                                          uint32 vp = ReadMacInt32(param + csVPBlockPtr);
# Line 452 | Line 766 | int16 VideoDriverStatus(uint32 pb, uint3
766                                          WriteMacInt16(vp + vpVersion, 0);
767                                          WriteMacInt16(vp + vpPackType, 0);
768                                          WriteMacInt32(vp + vpPackSize, 0);
769 <                                        WriteMacInt32(vp + vpHRes, 0x00480000);
769 >                                        WriteMacInt32(vp + vpHRes, 0x00480000); // 72 dpi
770                                          WriteMacInt32(vp + vpVRes, 0x00480000);
771                                          uint32 pix_type, pix_size, cmp_count, cmp_size, dev_type;
772                                          switch (i->depth) {
# Line 500 | Line 814 | int16 VideoDriverStatus(uint32 pb, uint3
814                          return paramErr; // specified resolution/depth not supported
815                  }
816  
503                case cscGetModeTiming: {        // Get video timing for specified resolution
504                        uint32 id = ReadMacInt32(param + csTimingMode);
505                        D(bug(" GetModeTiming %08x\n", id));
506                        if (!has_resolution(id))
507                                return paramErr;
508
509                        WriteMacInt32(param + csTimingFormat, FOURCC('d', 'e', 'c', 'l'));
510                        WriteMacInt32(param + csTimingData, 0); // unknown
511                        uint32 flags = 0xb; // mode valid, safe and shown in Monitors panel
512                        if (id == VidLocal.preferred_id)
513                                flags |= 4; // default mode
514                        WriteMacInt32(param + csTimingFlags, flags);
515                        return noErr;
516                }
517
817                  default:
818                          printf("WARNING: Unknown VideoDriverStatus(%d)\n", code);
819                          return statusErr;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines