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.11 by cebix, 2001-06-28T21:19:59Z

# Line 50 | Line 50 | struct {
50          uint8 palette[256 * 3];         // Color palette, 256 entries, RGB
51          bool luminance_mapping;         // Luminance mapping on/off
52          bool interrupts_enabled;        // VBL interrupts on/off
53 +        uint32 gamma_table;                     // Mac address of gamma table
54          uint16 current_mode;            // Currently selected depth/resolution
55          uint32 current_id;
56          uint16 preferred_mode;          // Preferred depth/resolution
57          uint32 preferred_id;
58 +        uint32 sp;                                      // Mac address of Slot Manager parameter block
59   } VidLocal;
60  
61  
# Line 63 | Line 65 | struct {
65  
66   static bool has_resolution(uint32 id)
67   {
68 <        vector<video_mode>::const_iterator i = VideoModes.begin(), end = VideoModes.end();
68 >        std::vector<video_mode>::const_iterator i = VideoModes.begin(), end = VideoModes.end();
69          while (i != end) {
70                  if (i->resolution_id == id)
71                          return true;
# Line 74 | Line 76 | static bool has_resolution(uint32 id)
76  
77  
78   /*
79 + *  Find specified mode (depth/resolution) (or VideoModes.end() if not found)
80 + */
81 +
82 + static std::vector<video_mode>::const_iterator find_mode(uint16 mode, uint32 id)
83 + {
84 +        std::vector<video_mode>::const_iterator i = VideoModes.begin(), end = VideoModes.end();
85 +        while (i != end) {
86 +                if (i->resolution_id == id && DepthToAppleMode(i->depth) == mode)
87 +                        return i;
88 +                ++i;
89 +        }
90 +        return i;
91 + }
92 +
93 +
94 + /*
95   *  Find maximum supported depth for given resolution ID
96   */
97  
# Line 109 | Line 127 | static void get_size_of_resolution(uint3
127  
128  
129   /*
130 + *  Set palette to 50% gray
131 + */
132 +
133 + static void set_gray_palette(void)
134 + {
135 +        if (!IsDirectMode(VidLocal.current_mode)) {
136 +                for (int i=0; i<256; i++) {
137 +                        VidLocal.palette[i * 3 + 0] = 127;
138 +                        VidLocal.palette[i * 3 + 1] = 127;
139 +                        VidLocal.palette[i * 3 + 2] = 127;
140 +                }
141 +                video_set_palette(VidLocal.palette);
142 +        }
143 + }
144 +
145 +
146 + /*
147   *  Driver Open() routine
148   */
149  
# Line 129 | Line 164 | int16 VideoDriverOpen(uint32 pb, uint32
164          VidLocal.preferred_mode = VidLocal.current_mode;
165          VidLocal.preferred_id = VidLocal.current_id;
166  
167 +        // Allocate Slot Manager parameter block in Mac RAM
168 +        M68kRegisters r;
169 +        r.d[0] = SIZEOF_SPBlock;
170 +        Execute68kTrap(0xa71e, &r);     // NewPtrSysClear()
171 +        if (r.a[0] == 0)
172 +                return memFullErr;
173 +        VidLocal.sp = r.a[0];
174 +        D(bug("SPBlock at %08x\n", VidLocal.sp));
175 +
176 +        // Find and set default gamma table
177 +        VidLocal.gamma_table = 0; //!!
178 +
179          // Init color palette (solid gray)
180 <        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 <        }
180 >        set_gray_palette();
181          return noErr;
182   }
183  
# Line 156 | Line 196 | int16 VideoDriverControl(uint32 pb, uint
196                  case cscSetMode: {              // Set color depth
197                          uint16 mode = ReadMacInt16(param + csMode);
198                          D(bug(" SetMode %04x\n", mode));
199 <                        //!! switch mode
199 >
200 >                        // Set old base address in case the switch fails
201                          WriteMacInt32(param + csBaseAddr, VidLocal.desc->mac_frame_base);
202 <                        //!! VidLocal.current_mode = mode;
203 <                        if (mode != VidLocal.current_mode)
202 >
203 >                        if (ReadMacInt16(param + csPage))
204                                  return paramErr;
205 <                        else
206 <                                return noErr;
205 >
206 >                        if (mode != VidLocal.current_mode) {
207 >                                std::vector<video_mode>::const_iterator i = find_mode(mode, VidLocal.current_id);
208 >                                if (i == VideoModes.end())
209 >                                        return paramErr;
210 >                                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);
215 >                        }
216 >                        D(bug("  base %08x\n", VidLocal.desc->mac_frame_base));
217 >                        return noErr;
218                  }
219  
220                  case cscSetEntries: {   // Set palette
221 <                        D(bug(" SetEntries table %08lx, count %d, start %d\n", ReadMacInt32(param + csTable), ReadMacInt16(param + csCount), ReadMacInt16(param + csStart)));
222 <                        if (IsDirectMode(VidLocal.desc->mode))
221 >                        D(bug(" SetEntries table %08x, count %d, start %d\n", ReadMacInt32(param + csTable), ReadMacInt16(param + csCount), ReadMacInt16(param + csStart)));
222 >                        if (IsDirectMode(VidLocal.current_mode))
223                                  return controlErr;
224  
225                          uint32 s_pal = ReadMacInt32(param + csTable);   // Source palette
226                          uint8 *d_pal;                                                                   // Destination palette
227 +                        uint16 start = ReadMacInt16(param + csStart);
228                          uint16 count = ReadMacInt16(param + csCount);
229 <                        if (!s_pal || count > 255)
229 >                        if (s_pal == 0 || count > 255)
230                                  return paramErr;
231  
232 <                        if (ReadMacInt16(param + csStart) == 0xffff) {  // Indexed
232 >                        if (start == 0xffff) {  // Indexed
233                                  for (uint32 i=0; i<=count; i++) {
234 <                                        d_pal = VidLocal.palette + ReadMacInt16(s_pal) * 3;
234 >                                        d_pal = VidLocal.palette + (ReadMacInt16(s_pal) & 0xff) * 3;
235                                          uint8 red = (uint16)ReadMacInt16(s_pal + 2) >> 8;
236                                          uint8 green = (uint16)ReadMacInt16(s_pal + 4) >> 8;
237                                          uint8 blue = (uint16)ReadMacInt16(s_pal + 6) >> 8;
238                                          if (VidLocal.luminance_mapping)
239                                                  red = green = blue = (red * 0x4ccc + green * 0x970a + blue * 0x1c29) >> 16;
240 +                                        //!! gamma correction
241                                          *d_pal++ = red;
242                                          *d_pal++ = green;
243                                          *d_pal++ = blue;
244                                          s_pal += 8;
245                                  }
246 <                        } else {                                                                                // Sequential
247 <                                d_pal = VidLocal.palette + ReadMacInt16(param + csStart) * 3;
246 >                        } else {                                // Sequential
247 >                                if (start + count > 255)
248 >                                        return paramErr;
249 >                                d_pal = VidLocal.palette + start * 3;
250                                  for (uint32 i=0; i<=count; i++) {
251                                          uint8 red = (uint16)ReadMacInt16(s_pal + 2) >> 8;
252                                          uint8 green = (uint16)ReadMacInt16(s_pal + 4) >> 8;
253                                          uint8 blue = (uint16)ReadMacInt16(s_pal + 6) >> 8;
254                                          if (VidLocal.luminance_mapping)
255                                                  red = green = blue = (red * 0x4ccc + green * 0x970a + blue * 0x1c29) >> 16;
256 +                                        //!! gamma correction
257                                          *d_pal++ = red;
258                                          *d_pal++ = green;
259                                          *d_pal++ = blue;
# Line 210 | Line 267 | int16 VideoDriverControl(uint32 pb, uint
267                  case cscSetGamma:               // Set gamma table
268                          D(bug(" SetGamma\n"));
269                          //!!
270 <                        return noErr;
270 >                        return controlErr;
271  
272                  case cscGrayPage: {             // Fill page with dithered gray pattern
273                          D(bug(" GrayPage %d\n", ReadMacInt16(param + csPage)));
# Line 227 | Line 284 | int16 VideoDriverControl(uint32 pb, uint
284                          };
285                          uint32 p = VidLocal.desc->mac_frame_base;
286                          uint32 pat = pattern[VidLocal.desc->mode.depth];
287 +                        bool invert = (VidLocal.desc->mode.depth == VDEPTH_32BIT);
288                          for (uint32 y=0; y<VidLocal.desc->mode.y; y++) {
289                                  for (uint32 x=0; x<VidLocal.desc->mode.bytes_per_row; x+=4) {
290                                          WriteMacInt32(p + x, pat);
291 <                                        if (VidLocal.desc->mode.depth == VDEPTH_32BIT)
291 >                                        if (invert)
292                                                  pat = ~pat;
293                                  }
294                                  p += VidLocal.desc->mode.bytes_per_row;
295                                  pat = ~pat;
296                          }
297 +                        //!! if direct mode, load gamma table to CLUT
298                          return noErr;
299                  }
300  
# Line 249 | Line 308 | int16 VideoDriverControl(uint32 pb, uint
308                          VidLocal.interrupts_enabled = (ReadMacInt8(param + csMode) == 0);
309                          return noErr;
310  
252                // case cscDirectSetEntries:
253
311                  case cscSetDefaultMode: { // Set default color depth
312                          uint16 mode = ReadMacInt16(param + csMode);
313                          D(bug(" SetDefaultMode %04x\n", mode));
# Line 262 | Line 319 | int16 VideoDriverControl(uint32 pb, uint
319                          uint16 mode = ReadMacInt16(param + csMode);
320                          uint32 id = ReadMacInt32(param + csData);
321                          D(bug(" SwitchMode %04x, %08x\n", mode, id));
322 <                        //!! switch mode
322 >
323 >                        // Set old base address in case the switch fails
324                          WriteMacInt32(param + csBaseAddr, VidLocal.desc->mac_frame_base);
325 <                        //!! VidLocal.current_mode = mode;
326 <                        //!! VidLocal.current_id = id;
269 <                        if (mode != VidLocal.current_mode || id != VidLocal.current_id)
325 >
326 >                        if (ReadMacInt16(param + csPage))
327                                  return paramErr;
328 <                        else
329 <                                return noErr;
328 >
329 >                        if (mode != VidLocal.current_mode || id != VidLocal.current_id) {
330 >                                std::vector<video_mode>::const_iterator i = find_mode(mode, id);
331 >                                if (i == VideoModes.end())
332 >                                        return paramErr;
333 >                                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);
385 >                        }
386 >                        D(bug("  base %08x\n", VidLocal.desc->mac_frame_base));
387 >                        return noErr;
388                  }
389  
390                  case cscSavePreferredConfiguration: {
# Line 306 | Line 421 | int16 VideoDriverStatus(uint32 pb, uint3
421                          WriteMacInt32(param + csBaseAddr, VidLocal.desc->mac_frame_base);
422                          return noErr;
423  
424 <                // case cscGetEntries:
424 >                case cscGetEntries: {           // Read palette
425 >                        D(bug(" GetEntries table %08x, count %d, start %d\n", ReadMacInt32(param + csTable), ReadMacInt16(param + csCount), ReadMacInt16(param + csStart)));
426 >
427 >                        uint8 *s_pal;                                                                   // Source palette
428 >                        uint32 d_pal = ReadMacInt32(param + csTable);   // Destination palette
429 >                        uint16 start = ReadMacInt16(param + csStart);
430 >                        uint16 count = ReadMacInt16(param + csCount);
431 >                        if (d_pal == 0 || count > 255)
432 >                                return paramErr;
433  
434 <                case cscGetPageCnt:                     // Get number of pages
435 <                        D(bug(" GetPageCnt -> 1\n"));
434 >                        if (start == 0xffff) {  // Indexed
435 >                                for (uint32 i=0; i<=count; i++) {
436 >                                        s_pal = VidLocal.palette + (ReadMacInt16(d_pal) & 0xff) * 3;
437 >                                        uint8 red = *s_pal++;
438 >                                        uint8 green = *s_pal++;
439 >                                        uint8 blue = *s_pal++;
440 >                                        WriteMacInt16(d_pal + 2, red * 0x0101);
441 >                                        WriteMacInt16(d_pal + 4, green * 0x0101);
442 >                                        WriteMacInt16(d_pal + 6, blue * 0x0101);
443 >                                        d_pal += 8;
444 >                                }
445 >                        } else {                                // Sequential
446 >                                if (start + count > 255)
447 >                                        return paramErr;
448 >                                s_pal = VidLocal.palette + start * 3;
449 >                                for (uint32 i=0; i<=count; i++) {
450 >                                        uint8 red = *s_pal++;
451 >                                        uint8 green = *s_pal++;
452 >                                        uint8 blue = *s_pal++;
453 >                                        WriteMacInt16(d_pal + 2, red * 0x0101);
454 >                                        WriteMacInt16(d_pal + 4, green * 0x0101);
455 >                                        WriteMacInt16(d_pal + 6, blue * 0x0101);
456 >                                        d_pal += 8;
457 >                                }
458 >                        }
459 >                        return noErr;
460 >                }
461 >
462 >                case cscGetPages:                       // Get number of pages
463 >                        D(bug(" GetPages -> 1\n"));
464                          WriteMacInt16(param + csPage, 1);
465                          return noErr;
466  
467 <                case cscGetPageBase:            // Get page base address
468 <                        D(bug(" GetPageBase -> %08x\n", VidLocal.desc->mac_frame_base));
467 >                case cscGetBaseAddress:         // Get page base address
468 >                        D(bug(" GetBaseAddress -> %08x\n", VidLocal.desc->mac_frame_base));
469                          WriteMacInt32(param + csBaseAddr, VidLocal.desc->mac_frame_base);
470 <                        return noErr;
470 >                        if (ReadMacInt16(param + csPage))
471 >                                return paramErr;
472 >                        else
473 >                                return noErr;
474  
475                  case cscGetGray:                        // Get luminance mapping flag
476                          D(bug(" GetGray -> %d\n", VidLocal.luminance_mapping));
477 <                        WriteMacInt8(param, VidLocal.luminance_mapping ? 1 : 0);
477 >                        WriteMacInt16(param, VidLocal.luminance_mapping ? 0x0100 : 0);
478                          return noErr;
479  
480                  case cscGetInterrupt:           // Get interrupt disable flag
481                          D(bug(" GetInterrupt -> %d\n", VidLocal.interrupts_enabled));
482 <                        WriteMacInt8(param, VidLocal.interrupts_enabled ? 0 : 1);
482 >                        WriteMacInt16(param, VidLocal.interrupts_enabled ? 0 : 0x0100);
483                          return noErr;
484  
485 <                // case cscGetGamma:
485 >                case cscGetGamma:
486 >                        D(bug(" GetGamma -> \n"));
487 >                        //!!
488 >                        return statusErr;
489  
490                  case cscGetDefaultMode:         // Get default color depth
491                          D(bug(" GetDefaultMode -> %04x\n", VidLocal.preferred_mode));
492                          WriteMacInt16(param + csMode, VidLocal.preferred_mode);
493                          return noErr;
494  
495 <                case cscGetCurMode:                     // Get current video mode (depth and resolution)
496 <                        D(bug(" GetCurMode -> %04x/%08x\n", VidLocal.current_mode, VidLocal.current_id));
495 >                case cscGetCurrentMode:         // Get current video mode (depth and resolution)
496 >                        D(bug(" GetCurMode -> %04x/%08x, base %08x\n", VidLocal.current_mode, VidLocal.current_id, VidLocal.desc->mac_frame_base));
497                          WriteMacInt16(param + csMode, VidLocal.current_mode);
498                          WriteMacInt32(param + csData, VidLocal.current_id);
499                          WriteMacInt16(param + csPage, 0);
# Line 345 | Line 502 | int16 VideoDriverStatus(uint32 pb, uint3
502  
503                  case cscGetConnection:          // Get monitor information
504                          D(bug(" GetConnection\n"));
505 <                        WriteMacInt16(param + csDisplayType, 6);                // 21" Multiscan
506 <                        WriteMacInt8(param + csConnectTaggedType, 6);
507 <                        WriteMacInt8(param + csConnectTaggedData, 0x23);
508 <                        WriteMacInt32(param + csConnectFlags, 0x03);    // All modes valid and safe
505 >                        WriteMacInt16(param + csDisplayType, 8);                // Modeless connection
506 >                        WriteMacInt8(param + csConnectTaggedType, 0);
507 >                        WriteMacInt8(param + csConnectTaggedData, 0);
508 >                        WriteMacInt32(param + csConnectFlags, 0x43);    // All modes valid and safe, non-standard tagging
509                          WriteMacInt32(param + csDisplayComponent, 0);
510                          return noErr;
511  
512 +                case cscGetModeTiming: {        // Get video timing for specified resolution
513 +                        uint32 id = ReadMacInt32(param + csTimingMode);
514 +                        D(bug(" GetModeTiming %08x\n", id));
515 +                        if (!has_resolution(id))
516 +                                return paramErr;
517 +
518 +                        WriteMacInt32(param + csTimingFormat, FOURCC('d', 'e', 'c', 'l'));
519 +                        WriteMacInt32(param + csTimingData, 0); // unknown
520 +                        uint32 flags = 0xb; // mode valid, safe and shown in Monitors panel
521 +                        if (id == VidLocal.preferred_id)
522 +                                flags |= 4; // default mode
523 +                        WriteMacInt32(param + csTimingFlags, flags);
524 +                        return noErr;
525 +                }
526 +
527                  case cscGetModeBaseAddress:     // Get frame buffer base address
528 <                        D(bug(" GetModeBaseAddress -> %08x\n", VidLocal.desc->mac_frame_base));
529 <                        WriteMacInt32(param + csBaseAddr, VidLocal.desc->mac_frame_base);       // Base address of video RAM for the current DisplayModeID and relative bit depth
528 >                        D(bug(" GetModeBaseAddress -> base %08x\n", VidLocal.desc->mac_frame_base));
529 >                        WriteMacInt32(param + csBaseAddr, VidLocal.desc->mac_frame_base);
530                          return noErr;
531  
532                  case cscGetPreferredConfiguration: // Get default video mode (depth and resolution)
# Line 401 | Line 573 | int16 VideoDriverStatus(uint32 pb, uint3
573                          WriteMacInt32(param + csVerticalLines, y);
574                          WriteMacInt32(param + csRefreshRate, 75 << 16);
575                          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);
576                          return noErr;
577                  }
578  
# Line 426 | Line 594 | int16 VideoDriverStatus(uint32 pb, uint3
594                                          WriteMacInt16(vp + vpVersion, 0);
595                                          WriteMacInt16(vp + vpPackType, 0);
596                                          WriteMacInt32(vp + vpPackSize, 0);
597 <                                        WriteMacInt32(vp + vpHRes, 0x00480000);
597 >                                        WriteMacInt32(vp + vpHRes, 0x00480000); // 72 dpi
598                                          WriteMacInt32(vp + vpVRes, 0x00480000);
599                                          uint32 pix_type, pix_size, cmp_count, cmp_size, dev_type;
600                                          switch (i->depth) {
# Line 474 | Line 642 | int16 VideoDriverStatus(uint32 pb, uint3
642                          return paramErr; // specified resolution/depth not supported
643                  }
644  
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
645                  default:
646                          printf("WARNING: Unknown VideoDriverStatus(%d)\n", code);
647                          return statusErr;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines