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.9 by cebix, 2001-06-27T19:03:35Z vs.
Revision 1.19 by cebix, 2001-07-01T21:09:26Z

# 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  
# 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 slot_param;                      // Mac address of Slot Manager parameter block
61   } VidLocal;
62  
63  
# Line 63 | Line 67 | struct {
67  
68   static bool has_resolution(uint32 id)
69   {
70 <        vector<video_mode>::const_iterator i = VideoModes.begin(), end = VideoModes.end();
71 <        while (i != end) {
70 >        vector<video_mode>::const_iterator i, end = VideoModes.end();
71 >        for (i = VideoModes.begin(); i != end; ++i) {
72                  if (i->resolution_id == id)
73                          return true;
70                ++i;
74          }
75          return false;
76   }
77  
78  
79   /*
80 + *  Find specified mode (depth/resolution) (or VideoModes.end() if not found)
81 + */
82 +
83 + static vector<video_mode>::const_iterator find_mode(uint16 mode, uint32 id)
84 + {
85 +        vector<video_mode>::const_iterator i, end = VideoModes.end();
86 +        for (i = VideoModes.begin(); i != end; ++i) {
87 +                if (i->resolution_id == id && DepthToAppleMode(i->depth) == mode)
88 +                        return i;
89 +        }
90 +        return i;
91 + }
92 +
93 +
94 + /*
95   *  Find maximum supported depth for given resolution ID
96   */
97  
98   static video_depth max_depth_of_resolution(uint32 id)
99   {
100          video_depth m = VDEPTH_1BIT;
101 <        vector<video_mode>::const_iterator i = VideoModes.begin(), end = VideoModes.end();
102 <        while (i != end) {
101 >        vector<video_mode>::const_iterator i, end = VideoModes.end();
102 >        for (i = VideoModes.begin(); i != end; ++i) {
103                  if (i->depth > m)
104                          m = i->depth;
87                ++i;
105          }
106          return m;
107   }
# Line 96 | Line 113 | static video_depth max_depth_of_resoluti
113  
114   static void get_size_of_resolution(uint32 id, uint32 &x, uint32 &y)
115   {
116 <        vector<video_mode>::const_iterator i = VideoModes.begin(), end = VideoModes.end();
117 <        while (i != end) {
116 >        vector<video_mode>::const_iterator i, end = VideoModes.end();
117 >        for (i = VideoModes.begin(); i != end; ++i) {
118                  if (i->resolution_id == id) {
119                          x = i->x;
120                          y = i->y;
121                          return;
122                  }
106                ++i;
123          }
124   }
125  
126  
127   /*
128 + *  Find palette size for given color depth
129 + */
130 +
131 + static int palette_size(video_depth depth)
132 + {
133 +        switch (depth) {
134 +                case VDEPTH_1BIT: return 2;
135 +                case VDEPTH_2BIT: return 4;
136 +                case VDEPTH_4BIT: return 16;
137 +                case VDEPTH_8BIT: return 256;
138 +                case VDEPTH_16BIT: return 32;
139 +                case VDEPTH_32BIT: return 256;
140 +                default: return 0;
141 +        }
142 + }
143 +
144 +
145 + /*
146 + *  Set palette to 50% gray
147 + */
148 +
149 + static void set_gray_palette(void)
150 + {
151 +        for (int i=0; i<256; i++) {
152 +                VidLocal.palette[i * 3 + 0] = 127;
153 +                VidLocal.palette[i * 3 + 1] = 127;
154 +                VidLocal.palette[i * 3 + 2] = 127;
155 +        }
156 +        video_set_palette(VidLocal.palette, 256);
157 + }
158 +
159 +
160 + /*
161 + *  Load gamma-corrected black-to-white ramp to palette for direct-color mode
162 + */
163 +
164 + static void load_ramp_palette(void)
165 + {
166 +        // Find tables for gamma correction
167 +        uint8 *red_gamma, *green_gamma, *blue_gamma;
168 +        bool have_gamma = false;
169 +        int data_width = 0;
170 +        if (VidLocal.gamma_table) {
171 +                uint32 table = VidLocal.gamma_table;
172 +                red_gamma = Mac2HostAddr(table + gFormulaData + ReadMacInt16(table + gFormulaSize));
173 +                int chan_cnt = ReadMacInt16(table + gChanCnt);
174 +                if (chan_cnt == 1)
175 +                        green_gamma = blue_gamma = red_gamma;
176 +                else {
177 +                        int ofs = ReadMacInt16(table + gDataCnt);
178 +                        green_gamma = red_gamma + ofs;
179 +                        blue_gamma = green_gamma + ofs;
180 +                }
181 +                data_width = ReadMacInt16(table + gDataWidth);
182 +                have_gamma = true;
183 +        }
184 +
185 +        int num = (VidLocal.desc->mode.depth == VDEPTH_16BIT ? 32 : 256);
186 +        uint8 *p = VidLocal.palette;
187 +        for (int i=0; i<num; i++) {
188 +                uint8 red = (i * 256 / num), green = red, blue = red;
189 +                if (have_gamma) {
190 +                        red = red_gamma[red >> (8 - data_width)];
191 +                        green = green_gamma[green >> (8 - data_width)];
192 +                        blue = blue_gamma[blue >> (8 - data_width)];
193 +                }
194 +                *p++ = red;
195 +                *p++ = green;
196 +                *p++ = blue;
197 +        }
198 +
199 +        video_set_palette(VidLocal.palette, num);
200 + }
201 +
202 +
203 + /*
204 + *  Allocate gamma table of specified size
205 + */
206 +
207 + static bool allocate_gamma_table(int size)
208 + {
209 +        M68kRegisters r;
210 +
211 +        if (size > VidLocal.alloc_gamma_table_size) {
212 +                if (VidLocal.gamma_table) {
213 +                        r.a[0] = VidLocal.gamma_table;
214 +                        Execute68kTrap(0xa01f, &r);     // DisposePtr()
215 +                        VidLocal.gamma_table = 0;
216 +                        VidLocal.alloc_gamma_table_size = 0;
217 +                }
218 +                r.d[0] = size;
219 +                Execute68kTrap(0xa71e, &r);     // NewPtrSysClear()
220 +                if (r.a[0] == 0)
221 +                        return false;
222 +                VidLocal.gamma_table = r.a[0];
223 +                VidLocal.alloc_gamma_table_size = size;
224 +        }
225 +        return true;
226 + }
227 +
228 +
229 + /*
230 + *  Set gamma table (0 = build linear ramp)
231 + */
232 +
233 + static bool set_gamma_table(uint32 user_table)
234 + {
235 +        if (user_table == 0) { // Build linear ramp, 256 entries
236 +
237 +                // Allocate new table, if necessary
238 +                if (!allocate_gamma_table(SIZEOF_GammaTbl + 256))
239 +                        return memFullErr;
240 +                uint32 table = VidLocal.gamma_table;
241 +
242 +                // Initialize header
243 +                WriteMacInt16(table + gVersion, 0);
244 +                WriteMacInt16(table + gType, 0);
245 +                WriteMacInt16(table + gFormulaSize, 0);
246 +                WriteMacInt16(table + gChanCnt, 1);
247 +                WriteMacInt16(table + gDataCnt, 256);
248 +                WriteMacInt16(table + gDataWidth, 8);
249 +
250 +                // Build ramp
251 +                uint32 p = table + gFormulaData;
252 +                for (int i=0; i<256; i++)
253 +                        WriteMacInt8(p + i, i);
254 +
255 +        } else { // User-supplied gamma table
256 +
257 +                // Validate header
258 +                if (ReadMacInt16(user_table + gVersion))
259 +                        return paramErr;
260 +                if (ReadMacInt16(user_table + gType))
261 +                        return paramErr;
262 +                int chan_cnt = ReadMacInt16(user_table + gChanCnt);
263 +                if (chan_cnt != 1 && chan_cnt != 3)
264 +                        return paramErr;
265 +                int data_width = ReadMacInt16(user_table + gDataWidth);
266 +                if (data_width > 8)
267 +                        return paramErr;
268 +                int data_cnt = ReadMacInt16(user_table + gDataCnt);
269 +                if (data_cnt != (1 << data_width))
270 +                        return paramErr;
271 +
272 +                // Allocate new table, if necessary
273 +                int size = SIZEOF_GammaTbl + ReadMacInt16(user_table + gFormulaSize) + chan_cnt * data_cnt;
274 +                if (!allocate_gamma_table(size))
275 +                        return memFullErr;
276 +                uint32 table = VidLocal.gamma_table;
277 +
278 +                // Copy table
279 +                Mac2Mac_memcpy(table, user_table, size);
280 +        }
281 +
282 +        if (IsDirectMode(VidLocal.current_mode))
283 +                load_ramp_palette();
284 +
285 +        return true;
286 + }
287 +
288 +
289 + /*
290 + *  Switch video mode
291 + */
292 +
293 + static void switch_mode(const video_mode &mode, uint32 param, uint32 dce)
294 + {
295 +        // Switch mode
296 +        set_gray_palette();
297 +        video_switch_to_mode(mode);
298 +
299 +        // Update VidLocal
300 +        VidLocal.current_mode = DepthToAppleMode(mode.depth);
301 +        VidLocal.current_id = mode.resolution_id;
302 +
303 +        uint32 frame_base = VidLocal.desc->mac_frame_base;
304 +
305 +        M68kRegisters r;
306 +        uint32 sp = VidLocal.slot_param;
307 +        r.a[0] = sp;
308 +
309 +        // Find functional sResource for this display
310 +        WriteMacInt8(sp + spSlot, ReadMacInt8(dce + dCtlSlot));
311 +        WriteMacInt8(sp + spID, ReadMacInt8(dce + dCtlSlotId));
312 +        WriteMacInt8(sp + spExtDev, 0);
313 +        r.d[0] = 0x0016;
314 +        Execute68kTrap(0xa06e, &r);     // SRsrcInfo()
315 +        uint32 rsrc = ReadMacInt32(sp + spPointer);
316 +
317 +        // Patch minorBase (otherwise rebooting won't work)
318 +        WriteMacInt8(sp + spID, 0x0a); // minorBase
319 +        r.d[0] = 0x0006;
320 +        Execute68kTrap(0xa06e, &r); // SFindStruct()
321 +        uint32 minor_base = ReadMacInt32(sp + spPointer) - ROMBaseMac;
322 +        ROMBaseHost[minor_base + 0] = frame_base >> 24;
323 +        ROMBaseHost[minor_base + 1] = frame_base >> 16;
324 +        ROMBaseHost[minor_base + 2] = frame_base >> 8;
325 +        ROMBaseHost[minor_base + 3] = frame_base;
326 +
327 +        // Patch video mode parameter table
328 +        WriteMacInt32(sp + spPointer, rsrc);
329 +        WriteMacInt8(sp + spID, DepthToAppleMode(mode.depth));
330 +        r.d[0] = 0x0006;
331 +        Execute68kTrap(0xa06e, &r); // SFindStruct()
332 +        WriteMacInt8(sp + spID, 0x01);
333 +        r.d[0] = 0x0006;
334 +        Execute68kTrap(0xa06e, &r); // SFindStruct()
335 +        uint32 p = ReadMacInt32(sp + spPointer) - ROMBaseMac;
336 +        ROMBaseHost[p +  8] = mode.bytes_per_row >> 8;
337 +        ROMBaseHost[p +  9] = mode.bytes_per_row;
338 +        ROMBaseHost[p + 14] = mode.y >> 8;
339 +        ROMBaseHost[p + 15] = mode.y;
340 +        ROMBaseHost[p + 16] = mode.x >> 8;
341 +        ROMBaseHost[p + 17] = mode.x;
342 +
343 +        // Recalculate slot ROM checksum
344 +        ChecksumSlotROM();
345 +
346 +        // Update sResource
347 +        WriteMacInt8(sp + spID, ReadMacInt8(dce + dCtlSlotId));
348 +        r.d[0] = 0x002b;
349 +        Execute68kTrap(0xa06e, &r); // SUpdateSRT()
350 +
351 +        // Update frame buffer base in DCE and param block
352 +        WriteMacInt32(dce + dCtlDevBase, frame_base);
353 +        WriteMacInt32(param + csBaseAddr, frame_base);
354 + }
355 +
356 +
357 + /*
358   *  Driver Open() routine
359   */
360  
# Line 129 | Line 375 | int16 VideoDriverOpen(uint32 pb, uint32
375          VidLocal.preferred_mode = VidLocal.current_mode;
376          VidLocal.preferred_id = VidLocal.current_id;
377  
378 +        // Allocate Slot Manager parameter block in Mac RAM
379 +        M68kRegisters r;
380 +        r.d[0] = SIZEOF_SPBlock;
381 +        Execute68kTrap(0xa71e, &r);     // NewPtrSysClear()
382 +        if (r.a[0] == 0)
383 +                return memFullErr;
384 +        VidLocal.slot_param = r.a[0];
385 +        D(bug("SPBlock at %08x\n", VidLocal.slot_param));
386 +
387 +        // Find and set default gamma table
388 +        VidLocal.gamma_table = 0;
389 +        VidLocal.alloc_gamma_table_size = 0;
390 +        set_gamma_table(0);
391 +
392          // Init color palette (solid gray)
393 <        if (!IsDirectMode(VidLocal.desc->mode)) {
134 <                for (int i=0; i<256; i++) {
135 <                        VidLocal.palette[i * 3 + 0] = 127;
136 <                        VidLocal.palette[i * 3 + 1] = 127;
137 <                        VidLocal.palette[i * 3 + 2] = 127;
138 <                }
139 <                video_set_palette(VidLocal.palette);
140 <        }
393 >        set_gray_palette();
394          return noErr;
395   }
396  
# Line 156 | Line 409 | int16 VideoDriverControl(uint32 pb, uint
409                  case cscSetMode: {              // Set color depth
410                          uint16 mode = ReadMacInt16(param + csMode);
411                          D(bug(" SetMode %04x\n", mode));
412 <                        //!! switch mode
412 >
413 >                        // Set old base address in case the switch fails
414                          WriteMacInt32(param + csBaseAddr, VidLocal.desc->mac_frame_base);
415 <                        //!! VidLocal.current_mode = mode;
416 <                        if (mode != VidLocal.current_mode)
415 >
416 >                        if (ReadMacInt16(param + csPage))
417                                  return paramErr;
418 <                        else
419 <                                return noErr;
418 >
419 >                        if (mode != VidLocal.current_mode) {
420 >                                vector<video_mode>::const_iterator i = find_mode(mode, VidLocal.current_id);
421 >                                if (i == VideoModes.end())
422 >                                        return paramErr;
423 >                                switch_mode(*i, param, dce);
424 >                        }
425 >                        D(bug("  base %08x\n", VidLocal.desc->mac_frame_base));
426 >                        return noErr;
427                  }
428  
429 <                case cscSetEntries: {   // Set palette
430 <                        D(bug(" SetEntries table %08lx, count %d, start %d\n", ReadMacInt32(param + csTable), ReadMacInt16(param + csCount), ReadMacInt16(param + csStart)));
431 <                        if (IsDirectMode(VidLocal.desc->mode))
429 >                case cscSetEntries:             // Set palette
430 >                case cscDirectSetEntries: {
431 >                        D(bug(" (Direct)SetEntries table %08x, count %d, start %d\n", ReadMacInt32(param + csTable), ReadMacInt16(param + csCount), ReadMacInt16(param + csStart)));
432 >                        bool is_direct = IsDirectMode(VidLocal.current_mode);
433 >                        if (code == cscSetEntries && is_direct)
434 >                                return controlErr;
435 >                        if (code == cscDirectSetEntries && !is_direct)
436                                  return controlErr;
437  
438                          uint32 s_pal = ReadMacInt32(param + csTable);   // Source palette
439                          uint8 *d_pal;                                                                   // Destination palette
440 +                        uint16 start = ReadMacInt16(param + csStart);
441                          uint16 count = ReadMacInt16(param + csCount);
442 <                        if (!s_pal || count > 255)
442 >                        if (s_pal == 0 || count > 255)
443                                  return paramErr;
444  
445 <                        if (ReadMacInt16(param + csStart) == 0xffff) {  // Indexed
445 >                        // Find tables for gamma correction
446 >                        uint8 *red_gamma, *green_gamma, *blue_gamma;
447 >                        bool have_gamma = false;
448 >                        int data_width = 0;
449 >                        if (VidLocal.gamma_table) {
450 >                                uint32 table = VidLocal.gamma_table;
451 >                                red_gamma = Mac2HostAddr(table + gFormulaData + ReadMacInt16(table + gFormulaSize));
452 >                                int chan_cnt = ReadMacInt16(table + gChanCnt);
453 >                                if (chan_cnt == 1)
454 >                                        green_gamma = blue_gamma = red_gamma;
455 >                                else {
456 >                                        int ofs = ReadMacInt16(table + gDataCnt);
457 >                                        green_gamma = red_gamma + ofs;
458 >                                        blue_gamma = green_gamma + ofs;
459 >                                }
460 >                                data_width = ReadMacInt16(table + gDataWidth);
461 >                                have_gamma = true;
462 >                        }
463 >
464 >                        // Convert palette
465 >                        if (start == 0xffff) {  // Indexed
466                                  for (uint32 i=0; i<=count; i++) {
467 <                                        d_pal = VidLocal.palette + ReadMacInt16(s_pal) * 3;
467 >                                        d_pal = VidLocal.palette + (ReadMacInt16(s_pal) & 0xff) * 3;
468                                          uint8 red = (uint16)ReadMacInt16(s_pal + 2) >> 8;
469                                          uint8 green = (uint16)ReadMacInt16(s_pal + 4) >> 8;
470                                          uint8 blue = (uint16)ReadMacInt16(s_pal + 6) >> 8;
471 <                                        if (VidLocal.luminance_mapping)
471 >                                        if (VidLocal.luminance_mapping && !is_direct)
472                                                  red = green = blue = (red * 0x4ccc + green * 0x970a + blue * 0x1c29) >> 16;
473 +                                        if (have_gamma) {
474 +                                                red = red_gamma[red >> (8 - data_width)];
475 +                                                green = green_gamma[green >> (8 - data_width)];
476 +                                                blue = blue_gamma[blue >> (8 - data_width)];
477 +                                        }
478                                          *d_pal++ = red;
479                                          *d_pal++ = green;
480                                          *d_pal++ = blue;
481                                          s_pal += 8;
482                                  }
483 <                        } else {                                                                                // Sequential
484 <                                d_pal = VidLocal.palette + ReadMacInt16(param + csStart) * 3;
483 >                        } else {                                // Sequential
484 >                                if (start + count > 255)
485 >                                        return paramErr;
486 >                                d_pal = VidLocal.palette + start * 3;
487                                  for (uint32 i=0; i<=count; i++) {
488                                          uint8 red = (uint16)ReadMacInt16(s_pal + 2) >> 8;
489                                          uint8 green = (uint16)ReadMacInt16(s_pal + 4) >> 8;
490                                          uint8 blue = (uint16)ReadMacInt16(s_pal + 6) >> 8;
491 <                                        if (VidLocal.luminance_mapping)
491 >                                        if (VidLocal.luminance_mapping && !is_direct)
492                                                  red = green = blue = (red * 0x4ccc + green * 0x970a + blue * 0x1c29) >> 16;
493 +                                        if (have_gamma) {
494 +                                                red = red_gamma[red >> (8 - data_width)];
495 +                                                green = green_gamma[green >> (8 - data_width)];
496 +                                                blue = blue_gamma[blue >> (8 - data_width)];
497 +                                        }
498                                          *d_pal++ = red;
499                                          *d_pal++ = green;
500                                          *d_pal++ = blue;
501                                          s_pal += 8;
502                                  }
503                          }
504 <                        video_set_palette(VidLocal.palette);
504 >                        video_set_palette(VidLocal.palette, palette_size(VidLocal.desc->mode.depth));
505                          return noErr;
506                  }
507  
508 <                case cscSetGamma:               // Set gamma table
509 <                        D(bug(" SetGamma\n"));
510 <                        //!!
511 <                        return noErr;
508 >                case cscSetGamma: {             // Set gamma table
509 >                        uint32 user_table = ReadMacInt32(param + csGTable);
510 >                        D(bug(" SetGamma %08x\n", user_table));
511 >                        return set_gamma_table(user_table) ? noErr : memFullErr;
512 >                }
513  
514                  case cscGrayPage: {             // Fill page with dithered gray pattern
515                          D(bug(" GrayPage %d\n", ReadMacInt16(param + csPage)));
# Line 227 | Line 526 | int16 VideoDriverControl(uint32 pb, uint
526                          };
527                          uint32 p = VidLocal.desc->mac_frame_base;
528                          uint32 pat = pattern[VidLocal.desc->mode.depth];
529 +                        bool invert = (VidLocal.desc->mode.depth == VDEPTH_32BIT);
530                          for (uint32 y=0; y<VidLocal.desc->mode.y; y++) {
531                                  for (uint32 x=0; x<VidLocal.desc->mode.bytes_per_row; x+=4) {
532                                          WriteMacInt32(p + x, pat);
533 <                                        if (VidLocal.desc->mode.depth == VDEPTH_32BIT)
533 >                                        if (invert)
534                                                  pat = ~pat;
535                                  }
536                                  p += VidLocal.desc->mode.bytes_per_row;
537                                  pat = ~pat;
538                          }
539 +
540 +                        if (IsDirectMode(VidLocal.current_mode))
541 +                                load_ramp_palette();
542 +
543                          return noErr;
544                  }
545  
# Line 249 | Line 553 | int16 VideoDriverControl(uint32 pb, uint
553                          VidLocal.interrupts_enabled = (ReadMacInt8(param + csMode) == 0);
554                          return noErr;
555  
252                // case cscDirectSetEntries:
253
556                  case cscSetDefaultMode: { // Set default color depth
557                          uint16 mode = ReadMacInt16(param + csMode);
558                          D(bug(" SetDefaultMode %04x\n", mode));
# Line 262 | Line 564 | int16 VideoDriverControl(uint32 pb, uint
564                          uint16 mode = ReadMacInt16(param + csMode);
565                          uint32 id = ReadMacInt32(param + csData);
566                          D(bug(" SwitchMode %04x, %08x\n", mode, id));
567 <                        //!! switch mode
567 >
568 >                        // Set old base address in case the switch fails
569                          WriteMacInt32(param + csBaseAddr, VidLocal.desc->mac_frame_base);
570 <                        //!! VidLocal.current_mode = mode;
571 <                        //!! VidLocal.current_id = id;
269 <                        if (mode != VidLocal.current_mode || id != VidLocal.current_id)
570 >
571 >                        if (ReadMacInt16(param + csPage))
572                                  return paramErr;
573 <                        else
574 <                                return noErr;
573 >
574 >                        if (mode != VidLocal.current_mode || id != VidLocal.current_id) {
575 >                                vector<video_mode>::const_iterator i = find_mode(mode, id);
576 >                                if (i == VideoModes.end())
577 >                                        return paramErr;
578 >                                switch_mode(*i, param, dce);
579 >                        }
580 >                        D(bug("  base %08x\n", VidLocal.desc->mac_frame_base));
581 >                        return noErr;
582                  }
583  
584                  case cscSavePreferredConfiguration: {
# Line 306 | Line 615 | int16 VideoDriverStatus(uint32 pb, uint3
615                          WriteMacInt32(param + csBaseAddr, VidLocal.desc->mac_frame_base);
616                          return noErr;
617  
618 <                // case cscGetEntries:
618 >                case cscGetEntries: {           // Read palette
619 >                        D(bug(" GetEntries table %08x, count %d, start %d\n", ReadMacInt32(param + csTable), ReadMacInt16(param + csCount), ReadMacInt16(param + csStart)));
620 >
621 >                        uint8 *s_pal;                                                                   // Source palette
622 >                        uint32 d_pal = ReadMacInt32(param + csTable);   // Destination palette
623 >                        uint16 start = ReadMacInt16(param + csStart);
624 >                        uint16 count = ReadMacInt16(param + csCount);
625 >                        if (d_pal == 0 || count > 255)
626 >                                return paramErr;
627 >
628 >                        if (start == 0xffff) {  // Indexed
629 >                                for (uint32 i=0; i<=count; i++) {
630 >                                        s_pal = VidLocal.palette + (ReadMacInt16(d_pal) & 0xff) * 3;
631 >                                        uint8 red = *s_pal++;
632 >                                        uint8 green = *s_pal++;
633 >                                        uint8 blue = *s_pal++;
634 >                                        WriteMacInt16(d_pal + 2, red * 0x0101);
635 >                                        WriteMacInt16(d_pal + 4, green * 0x0101);
636 >                                        WriteMacInt16(d_pal + 6, blue * 0x0101);
637 >                                        d_pal += 8;
638 >                                }
639 >                        } else {                                // Sequential
640 >                                if (start + count > 255)
641 >                                        return paramErr;
642 >                                s_pal = VidLocal.palette + start * 3;
643 >                                for (uint32 i=0; i<=count; i++) {
644 >                                        uint8 red = *s_pal++;
645 >                                        uint8 green = *s_pal++;
646 >                                        uint8 blue = *s_pal++;
647 >                                        WriteMacInt16(d_pal + 2, red * 0x0101);
648 >                                        WriteMacInt16(d_pal + 4, green * 0x0101);
649 >                                        WriteMacInt16(d_pal + 6, blue * 0x0101);
650 >                                        d_pal += 8;
651 >                                }
652 >                        }
653 >                        return noErr;
654 >                }
655  
656 <                case cscGetPageCnt:                     // Get number of pages
657 <                        D(bug(" GetPageCnt -> 1\n"));
656 >                case cscGetPages:                       // Get number of pages
657 >                        D(bug(" GetPages -> 1\n"));
658                          WriteMacInt16(param + csPage, 1);
659                          return noErr;
660  
661 <                case cscGetPageBase:            // Get page base address
662 <                        D(bug(" GetPageBase -> %08x\n", VidLocal.desc->mac_frame_base));
661 >                case cscGetBaseAddress:         // Get page base address
662 >                        D(bug(" GetBaseAddress -> %08x\n", VidLocal.desc->mac_frame_base));
663                          WriteMacInt32(param + csBaseAddr, VidLocal.desc->mac_frame_base);
664 <                        return noErr;
664 >                        if (ReadMacInt16(param + csPage))
665 >                                return paramErr;
666 >                        else
667 >                                return noErr;
668  
669                  case cscGetGray:                        // Get luminance mapping flag
670                          D(bug(" GetGray -> %d\n", VidLocal.luminance_mapping));
671 <                        WriteMacInt8(param, VidLocal.luminance_mapping ? 1 : 0);
671 >                        WriteMacInt16(param, VidLocal.luminance_mapping ? 0x0100 : 0);
672                          return noErr;
673  
674                  case cscGetInterrupt:           // Get interrupt disable flag
675                          D(bug(" GetInterrupt -> %d\n", VidLocal.interrupts_enabled));
676 <                        WriteMacInt8(param, VidLocal.interrupts_enabled ? 0 : 1);
676 >                        WriteMacInt16(param, VidLocal.interrupts_enabled ? 0 : 0x0100);
677                          return noErr;
678  
679 <                // case cscGetGamma:
679 >                case cscGetGamma:
680 >                        D(bug(" GetGamma -> %08x\n", VidLocal.gamma_table));
681 >                        WriteMacInt32(param + csGTable, VidLocal.gamma_table);
682 >                        return noErr;
683  
684                  case cscGetDefaultMode:         // Get default color depth
685                          D(bug(" GetDefaultMode -> %04x\n", VidLocal.preferred_mode));
686                          WriteMacInt16(param + csMode, VidLocal.preferred_mode);
687                          return noErr;
688  
689 <                case cscGetCurMode:                     // Get current video mode (depth and resolution)
690 <                        D(bug(" GetCurMode -> %04x/%08x\n", VidLocal.current_mode, VidLocal.current_id));
689 >                case cscGetCurrentMode:         // Get current video mode (depth and resolution)
690 >                        D(bug(" GetCurMode -> %04x/%08x, base %08x\n", VidLocal.current_mode, VidLocal.current_id, VidLocal.desc->mac_frame_base));
691                          WriteMacInt16(param + csMode, VidLocal.current_mode);
692                          WriteMacInt32(param + csData, VidLocal.current_id);
693                          WriteMacInt16(param + csPage, 0);
# Line 345 | Line 696 | int16 VideoDriverStatus(uint32 pb, uint3
696  
697                  case cscGetConnection:          // Get monitor information
698                          D(bug(" GetConnection\n"));
699 <                        WriteMacInt16(param + csDisplayType, 6);                // 21" Multiscan
700 <                        WriteMacInt8(param + csConnectTaggedType, 6);
701 <                        WriteMacInt8(param + csConnectTaggedData, 0x23);
702 <                        WriteMacInt32(param + csConnectFlags, 0x03);    // All modes valid and safe
699 >                        WriteMacInt16(param + csDisplayType, 8);                // Modeless connection
700 >                        WriteMacInt8(param + csConnectTaggedType, 0);
701 >                        WriteMacInt8(param + csConnectTaggedData, 0);
702 >                        WriteMacInt32(param + csConnectFlags, 0x43);    // All modes valid and safe, non-standard tagging
703                          WriteMacInt32(param + csDisplayComponent, 0);
704                          return noErr;
705  
706 +                case cscGetModeTiming: {        // Get video timing for specified resolution
707 +                        uint32 id = ReadMacInt32(param + csTimingMode);
708 +                        D(bug(" GetModeTiming %08x\n", id));
709 +                        if (!has_resolution(id))
710 +                                return paramErr;
711 +
712 +                        WriteMacInt32(param + csTimingFormat, FOURCC('d', 'e', 'c', 'l'));
713 +                        WriteMacInt32(param + csTimingData, 0); // unknown
714 +                        uint32 flags = 0xb; // mode valid, safe and shown in Monitors panel
715 +                        if (id == VidLocal.preferred_id)
716 +                                flags |= 4; // default mode
717 +                        WriteMacInt32(param + csTimingFlags, flags);
718 +                        return noErr;
719 +                }
720 +
721                  case cscGetModeBaseAddress:     // Get frame buffer base address
722 <                        D(bug(" GetModeBaseAddress -> %08x\n", VidLocal.desc->mac_frame_base));
723 <                        WriteMacInt32(param + csBaseAddr, VidLocal.desc->mac_frame_base);       // Base address of video RAM for the current DisplayModeID and relative bit depth
722 >                        D(bug(" GetModeBaseAddress -> base %08x\n", VidLocal.desc->mac_frame_base));
723 >                        WriteMacInt32(param + csBaseAddr, VidLocal.desc->mac_frame_base);
724                          return noErr;
725  
726                  case cscGetPreferredConfiguration: // Get default video mode (depth and resolution)
# Line 401 | Line 767 | int16 VideoDriverStatus(uint32 pb, uint3
767                          WriteMacInt32(param + csVerticalLines, y);
768                          WriteMacInt32(param + csRefreshRate, 75 << 16);
769                          WriteMacInt16(param + csMaxDepthMode, DepthToAppleMode(max_depth_of_resolution(id)));
404                        uint32 flags = 0xb; // mode valid, safe and shown in Monitors panel
405                        if (id == VidLocal.preferred_id)
406                                flags |= 4; // default mode
407                        WriteMacInt32(param + csResolutionFlags, flags);
770                          return noErr;
771                  }
772  
# Line 413 | Line 775 | int16 VideoDriverStatus(uint32 pb, uint3
775                          uint16 mode = ReadMacInt16(param + csDepthMode);
776                          D(bug(" GetVideoParameters %04x/%08x\n", mode, id));
777  
778 <                        vector<video_mode>::const_iterator i = VideoModes.begin(), end = VideoModes.end();
779 <                        while (i != end) {
778 >                        vector<video_mode>::const_iterator i, end = VideoModes.end();
779 >                        for (i = VideoModes.begin(); i != end; ++i) {
780                                  if (DepthToAppleMode(i->depth) == mode && i->resolution_id == id) {
781                                          uint32 vp = ReadMacInt32(param + csVPBlockPtr);
782                                          WriteMacInt32(vp + vpBaseOffset, 0);
# Line 426 | Line 788 | int16 VideoDriverStatus(uint32 pb, uint3
788                                          WriteMacInt16(vp + vpVersion, 0);
789                                          WriteMacInt16(vp + vpPackType, 0);
790                                          WriteMacInt32(vp + vpPackSize, 0);
791 <                                        WriteMacInt32(vp + vpHRes, 0x00480000);
791 >                                        WriteMacInt32(vp + vpHRes, 0x00480000); // 72 dpi
792                                          WriteMacInt32(vp + vpVRes, 0x00480000);
793                                          uint32 pix_type, pix_size, cmp_count, cmp_size, dev_type;
794                                          switch (i->depth) {
# Line 469 | Line 831 | int16 VideoDriverStatus(uint32 pb, uint3
831                                          WriteMacInt32(param + csDeviceType, dev_type);
832                                          return noErr;
833                                  }
472                                ++i;
834                          }
835                          return paramErr; // specified resolution/depth not supported
836                  }
837  
477                case cscGetModeTiming: {        // Get video timing for specified resolution
478                        uint32 id = ReadMacInt32(param + csTimingMode);
479                        D(bug(" GetModeTiming %08x\n", id));
480                        if (!has_resolution(id))
481                                return paramErr;
482
483                        WriteMacInt32(param + csTimingFormat, FOURCC('d', 'e', 'c', 'l'));
484                        WriteMacInt32(param + csTimingData, 0); // unknown
485                        uint32 flags = 0xb; // mode valid, safe and shown in Monitors panel
486                        if (id == VidLocal.preferred_id)
487                                flags |= 4; // default mode
488                        WriteMacInt32(param + csTimingFlags, flags);
489                        return noErr;
490                }
491
838                  default:
839                          printf("WARNING: Unknown VideoDriverStatus(%d)\n", code);
840                          return statusErr;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines