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> |
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 |
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 |
|
|
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 |
+ |
|
183 |
+ |
/* |
184 |
+ |
* Find palette size for given color depth |
185 |
+ |
*/ |
186 |
+ |
|
187 |
+ |
static int palette_size(video_depth depth) |
188 |
+ |
{ |
189 |
+ |
switch (depth) { |
190 |
+ |
case VDEPTH_1BIT: return 2; |
191 |
+ |
case VDEPTH_2BIT: return 4; |
192 |
+ |
case VDEPTH_4BIT: return 16; |
193 |
+ |
case VDEPTH_8BIT: return 256; |
194 |
+ |
case VDEPTH_16BIT: return 32; |
195 |
+ |
case VDEPTH_32BIT: return 256; |
196 |
+ |
default: return 0; |
197 |
+ |
} |
198 |
|
} |
199 |
|
|
200 |
|
|
209 |
|
VidLocal.palette[i * 3 + 1] = 127; |
210 |
|
VidLocal.palette[i * 3 + 2] = 127; |
211 |
|
} |
212 |
< |
video_set_palette(VidLocal.palette); |
212 |
> |
video_set_palette(VidLocal.palette, 256); |
213 |
|
} |
214 |
|
|
215 |
|
|
252 |
|
*p++ = blue; |
253 |
|
} |
254 |
|
|
255 |
< |
video_set_palette(VidLocal.palette); |
255 |
> |
video_set_palette(VidLocal.palette, num); |
256 |
|
} |
257 |
|
|
258 |
|
|
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; |
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 |
|
|
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; |
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) |
569 |
|
s_pal += 8; |
570 |
|
} |
571 |
|
} |
572 |
< |
video_set_palette(VidLocal.palette); |
572 |
> |
video_set_palette(VidLocal.palette, palette_size(VidLocal.desc->mode.depth)); |
573 |
|
return noErr; |
574 |
|
} |
575 |
|
|
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; |
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 |
|
} |
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: |
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) |
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 |
|
|
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) { |
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; |