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.19 by cebix, 2001-07-01T21:09:26Z vs.
Revision 1.22 by cebix, 2001-07-09T11:21:59Z

# Line 23 | Line 23
23   *  SEE ALSO
24   *    Inside Macintosh: Devices, chapter 1 "Device Manager"
25   *    Designing Cards and Drivers for the Macintosh Family, Second Edition
26 + *    Designing PCI Cards and Drivers for Power Macintosh Computers
27 + *    Display Device Driver Guide
28   */
29  
30   #include <stdio.h>
# Line 45 | Line 47 | vector<video_mode> VideoModes;
47   // Description of the main monitor
48   monitor_desc VideoMonitor;
49  
50 + // Depth code -> Apple mode mapping
51 + uint16 apple_mode_for_depth[6];
52 +
53   // Local variables (per monitor)
54   struct {
55          monitor_desc *desc;                     // Pointer to description of monitor handled by this instance of the driver
56          uint8 palette[256 * 3];         // Color palette, 256 entries, RGB
57          bool luminance_mapping;         // Luminance mapping on/off
58          bool interrupts_enabled;        // VBL interrupts on/off
59 +        bool dm_present;                        // We received a GetVideoParameters call, so the Display Manager seems to be present
60          uint32 gamma_table;                     // Mac address of gamma table
61          int alloc_gamma_table_size;     // Allocated size of gamma table
62          uint16 current_mode;            // Currently selected depth/resolution
# Line 62 | Line 68 | struct {
68  
69  
70   /*
71 + *  Initialize apple_mode_for_depth[] array from VideoModes list
72 + */
73 +
74 + void video_init_depth_list(void)
75 + {
76 +        uint16 mode = 0x80;
77 +        for (int depth = VDEPTH_1BIT; depth <= VDEPTH_32BIT; depth++) {
78 +                if (video_has_depth(video_depth(depth)))
79 +                        apple_mode_for_depth[depth] = mode++;
80 +                else
81 +                        apple_mode_for_depth[depth] = 0;
82 +        }
83 + }
84 +
85 +
86 + /*
87 + *  Check whether a mode with the specified depth exists
88 + */
89 +
90 + bool video_has_depth(video_depth depth)
91 + {
92 +        vector<video_mode>::const_iterator i = VideoModes.begin(), end = VideoModes.end();
93 +        while (i != end) {
94 +                if (i->depth == depth)
95 +                        return true;
96 +                ++i;
97 +        }
98 +        return false;
99 + }
100 +
101 +
102 + /*
103   *  Check whether specified resolution ID is one of the supported resolutions
104   */
105  
# Line 121 | Line 159 | static void get_size_of_resolution(uint3
159                          return;
160                  }
161          }
162 +        x = y = 0;
163 + }
164 +
165 +
166 + /*
167 + *  Get bytes-per-row value for specified resolution/depth
168 + */
169 +
170 + uint32 video_bytes_per_row(video_depth depth, uint32 id)
171 + {
172 +        vector<video_mode>::const_iterator i, end = VideoModes.end();
173 +        for (i = VideoModes.begin(); i != end; ++i) {
174 +                if (i->depth == depth && i->resolution_id == id)
175 +                        return i->bytes_per_row;
176 +        }
177 +        uint32 x, y;
178 +        get_size_of_resolution(id, x, y);
179 +        return TrivialBytesPerRow(x, depth);
180   }
181  
182  
# Line 279 | Line 335 | static bool set_gamma_table(uint32 user_
335                  Mac2Mac_memcpy(table, user_table, size);
336          }
337  
338 <        if (IsDirectMode(VidLocal.current_mode))
338 >        if (IsDirectMode(VidLocal.desc->mode))
339                  load_ramp_palette();
340  
341          return true;
# Line 351 | Line 407 | static void switch_mode(const video_mode
407          // Update frame buffer base in DCE and param block
408          WriteMacInt32(dce + dCtlDevBase, frame_base);
409          WriteMacInt32(param + csBaseAddr, frame_base);
410 +
411 +        // Patch frame buffer base address for MacOS versions <7.6
412 +        if (!VidLocal.dm_present) { // Only do this when no Display Manager seems to be present; otherwise, the screen will not get redrawn
413 +                WriteMacInt32(0x824, frame_base);                       // ScrnBase
414 +                WriteMacInt32(0x898, frame_base);                       // CrsrBase
415 +                uint32 gdev = ReadMacInt32(0x8a4);                      // MainDevice
416 +                gdev = ReadMacInt32(gdev);
417 +                uint32 pmap = ReadMacInt32(gdev + 0x16);        // gdPMap
418 +                pmap = ReadMacInt32(pmap);
419 +                WriteMacInt32(pmap, frame_base);                        // baseAddr
420 +        }
421   }
422  
423  
# Line 374 | Line 441 | int16 VideoDriverOpen(uint32 pb, uint32
441          VidLocal.current_id = VidLocal.desc->mode.resolution_id;
442          VidLocal.preferred_mode = VidLocal.current_mode;
443          VidLocal.preferred_id = VidLocal.current_id;
444 +        VidLocal.dm_present = false;
445  
446          // Allocate Slot Manager parameter block in Mac RAM
447          M68kRegisters r;
# Line 429 | Line 497 | int16 VideoDriverControl(uint32 pb, uint
497                  case cscSetEntries:             // Set palette
498                  case cscDirectSetEntries: {
499                          D(bug(" (Direct)SetEntries table %08x, count %d, start %d\n", ReadMacInt32(param + csTable), ReadMacInt16(param + csCount), ReadMacInt16(param + csStart)));
500 <                        bool is_direct = IsDirectMode(VidLocal.current_mode);
500 >                        bool is_direct = IsDirectMode(VidLocal.desc->mode);
501                          if (code == cscSetEntries && is_direct)
502                                  return controlErr;
503                          if (code == cscDirectSetEntries && !is_direct)
# Line 524 | Line 592 | int16 VideoDriverControl(uint32 pb, uint
592                                  0xffff0000,             // 16 bpp
593                                  0xffffffff              // 32 bpp
594                          };
595 <                        uint32 p = VidLocal.desc->mac_frame_base;
595 >                        uint32 frame_base = VidLocal.desc->mac_frame_base;
596                          uint32 pat = pattern[VidLocal.desc->mode.depth];
597                          bool invert = (VidLocal.desc->mode.depth == VDEPTH_32BIT);
598                          for (uint32 y=0; y<VidLocal.desc->mode.y; y++) {
599                                  for (uint32 x=0; x<VidLocal.desc->mode.bytes_per_row; x+=4) {
600 <                                        WriteMacInt32(p + x, pat);
600 >                                        WriteMacInt32(frame_base + x, pat);
601                                          if (invert)
602                                                  pat = ~pat;
603                                  }
604 <                                p += VidLocal.desc->mode.bytes_per_row;
604 >                                frame_base += VidLocal.desc->mode.bytes_per_row;
605                                  pat = ~pat;
606                          }
607  
608 <                        if (IsDirectMode(VidLocal.current_mode))
608 >                        if (IsDirectMode(VidLocal.desc->mode))
609                                  load_ramp_palette();
610  
611                          return noErr;
# Line 554 | Line 622 | int16 VideoDriverControl(uint32 pb, uint
622                          return noErr;
623  
624                  case cscSetDefaultMode: { // Set default color depth
625 <                        uint16 mode = ReadMacInt16(param + csMode);
626 <                        D(bug(" SetDefaultMode %04x\n", mode));
625 >                        uint16 mode = ReadMacInt8(param + csMode);
626 >                        D(bug(" SetDefaultMode %02x\n", mode));
627                          VidLocal.preferred_mode = mode;
628                          return noErr;
629                  }
# Line 668 | Line 736 | int16 VideoDriverStatus(uint32 pb, uint3
736  
737                  case cscGetGray:                        // Get luminance mapping flag
738                          D(bug(" GetGray -> %d\n", VidLocal.luminance_mapping));
739 <                        WriteMacInt16(param, VidLocal.luminance_mapping ? 0x0100 : 0);
739 >                        WriteMacInt8(param, VidLocal.luminance_mapping ? 1 : 0);
740                          return noErr;
741  
742                  case cscGetInterrupt:           // Get interrupt disable flag
743                          D(bug(" GetInterrupt -> %d\n", VidLocal.interrupts_enabled));
744 <                        WriteMacInt16(param, VidLocal.interrupts_enabled ? 0 : 0x0100);
744 >                        WriteMacInt8(param, VidLocal.interrupts_enabled ? 0 : 1);
745                          return noErr;
746  
747                  case cscGetGamma:
# Line 682 | Line 750 | int16 VideoDriverStatus(uint32 pb, uint3
750                          return noErr;
751  
752                  case cscGetDefaultMode:         // Get default color depth
753 <                        D(bug(" GetDefaultMode -> %04x\n", VidLocal.preferred_mode));
754 <                        WriteMacInt16(param + csMode, VidLocal.preferred_mode);
753 >                        D(bug(" GetDefaultMode -> %02x\n", VidLocal.preferred_mode));
754 >                        WriteMacInt8(param + csMode, VidLocal.preferred_mode);
755                          return noErr;
756  
757                  case cscGetCurrentMode:         // Get current video mode (depth and resolution)
# Line 767 | Line 835 | int16 VideoDriverStatus(uint32 pb, uint3
835                          WriteMacInt32(param + csVerticalLines, y);
836                          WriteMacInt32(param + csRefreshRate, 75 << 16);
837                          WriteMacInt16(param + csMaxDepthMode, DepthToAppleMode(max_depth_of_resolution(id)));
838 +                        WriteMacInt32(param + csResolutionFlags, 0);
839                          return noErr;
840                  }
841  
# Line 774 | Line 843 | int16 VideoDriverStatus(uint32 pb, uint3
843                          uint32 id = ReadMacInt32(param + csDisplayModeID);
844                          uint16 mode = ReadMacInt16(param + csDepthMode);
845                          D(bug(" GetVideoParameters %04x/%08x\n", mode, id));
846 +                        VidLocal.dm_present = true;     // Display Manager seems to be present
847  
848                          vector<video_mode>::const_iterator i, end = VideoModes.end();
849                          for (i = VideoModes.begin(); i != end; ++i) {
# Line 835 | Line 905 | int16 VideoDriverStatus(uint32 pb, uint3
905                          return paramErr; // specified resolution/depth not supported
906                  }
907  
908 +                case cscGetMultiConnect: {
909 +                        uint32 conn = ReadMacInt32(param + csDisplayCountOrNumber);
910 +                        D(bug(" GetMultiConnect %08x\n", conn));
911 +                        if (conn == 0xffffffff) {       // Get number of connections
912 +                                WriteMacInt32(param + csDisplayCountOrNumber, 1); // Single-headed
913 +                                return noErr;
914 +                        } else if (conn == 1) {         // Get information about first connection
915 +                                WriteMacInt16(param + csConnectInfo + csDisplayType, 8);                // Modeless connection
916 +                                WriteMacInt8(param + csConnectInfo + csConnectTaggedType, 0);
917 +                                WriteMacInt8(param + csConnectInfo + csConnectTaggedData, 0);
918 +                                WriteMacInt32(param + csConnectInfo + csConnectFlags, 0x43);    // All modes valid and safe, non-standard tagging
919 +                                WriteMacInt32(param + csConnectInfo + csDisplayComponent, 0);
920 +                                return noErr;
921 +                        } else
922 +                                return paramErr;
923 +                }
924 +
925                  default:
926                          printf("WARNING: Unknown VideoDriverStatus(%d)\n", code);
927                          return statusErr;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines