45 |
|
// Description of the main monitor |
46 |
|
monitor_desc VideoMonitor; |
47 |
|
|
48 |
+ |
// Depth code -> Apple mode mapping |
49 |
+ |
uint16 apple_mode_for_depth[6]; |
50 |
+ |
|
51 |
|
// Local variables (per monitor) |
52 |
|
struct { |
53 |
|
monitor_desc *desc; // Pointer to description of monitor handled by this instance of the driver |
54 |
|
uint8 palette[256 * 3]; // Color palette, 256 entries, RGB |
55 |
|
bool luminance_mapping; // Luminance mapping on/off |
56 |
|
bool interrupts_enabled; // VBL interrupts on/off |
57 |
+ |
bool dm_present; // We received a GetVideoParameters call, so the Display Manager seems to be present |
58 |
|
uint32 gamma_table; // Mac address of gamma table |
59 |
|
int alloc_gamma_table_size; // Allocated size of gamma table |
60 |
|
uint16 current_mode; // Currently selected depth/resolution |
66 |
|
|
67 |
|
|
68 |
|
/* |
69 |
+ |
* Initialize apple_mode_for_depth[] array from VideoModes list |
70 |
+ |
*/ |
71 |
+ |
|
72 |
+ |
void video_init_depth_list(void) |
73 |
+ |
{ |
74 |
+ |
uint16 mode = 0x80; |
75 |
+ |
for (int depth = VDEPTH_1BIT; depth <= VDEPTH_32BIT; depth++) { |
76 |
+ |
if (video_has_depth(video_depth(depth))) |
77 |
+ |
apple_mode_for_depth[depth] = mode++; |
78 |
+ |
else |
79 |
+ |
apple_mode_for_depth[depth] = 0; |
80 |
+ |
} |
81 |
+ |
} |
82 |
+ |
|
83 |
+ |
|
84 |
+ |
/* |
85 |
+ |
* Check whether a mode with the specified depth exists |
86 |
+ |
*/ |
87 |
+ |
|
88 |
+ |
bool video_has_depth(video_depth depth) |
89 |
+ |
{ |
90 |
+ |
vector<video_mode>::const_iterator i = VideoModes.begin(), end = VideoModes.end(); |
91 |
+ |
while (i != end) { |
92 |
+ |
if (i->depth == depth) |
93 |
+ |
return true; |
94 |
+ |
++i; |
95 |
+ |
} |
96 |
+ |
return false; |
97 |
+ |
} |
98 |
+ |
|
99 |
+ |
|
100 |
+ |
/* |
101 |
|
* Check whether specified resolution ID is one of the supported resolutions |
102 |
|
*/ |
103 |
|
|
157 |
|
return; |
158 |
|
} |
159 |
|
} |
160 |
+ |
x = y = 0; |
161 |
+ |
} |
162 |
+ |
|
163 |
+ |
|
164 |
+ |
/* |
165 |
+ |
* Get bytes-per-row value for specified resolution/depth |
166 |
+ |
*/ |
167 |
+ |
|
168 |
+ |
uint32 video_bytes_per_row(video_depth depth, uint32 id) |
169 |
+ |
{ |
170 |
+ |
vector<video_mode>::const_iterator i, end = VideoModes.end(); |
171 |
+ |
for (i = VideoModes.begin(); i != end; ++i) { |
172 |
+ |
if (i->depth == depth && i->resolution_id == id) |
173 |
+ |
return i->bytes_per_row; |
174 |
+ |
} |
175 |
+ |
uint32 x, y; |
176 |
+ |
get_size_of_resolution(id, x, y); |
177 |
+ |
return TrivialBytesPerRow(x, depth); |
178 |
+ |
} |
179 |
+ |
|
180 |
+ |
|
181 |
+ |
/* |
182 |
+ |
* Find palette size for given color depth |
183 |
+ |
*/ |
184 |
+ |
|
185 |
+ |
static int palette_size(video_depth depth) |
186 |
+ |
{ |
187 |
+ |
switch (depth) { |
188 |
+ |
case VDEPTH_1BIT: return 2; |
189 |
+ |
case VDEPTH_2BIT: return 4; |
190 |
+ |
case VDEPTH_4BIT: return 16; |
191 |
+ |
case VDEPTH_8BIT: return 256; |
192 |
+ |
case VDEPTH_16BIT: return 32; |
193 |
+ |
case VDEPTH_32BIT: return 256; |
194 |
+ |
default: return 0; |
195 |
+ |
} |
196 |
|
} |
197 |
|
|
198 |
|
|
207 |
|
VidLocal.palette[i * 3 + 1] = 127; |
208 |
|
VidLocal.palette[i * 3 + 2] = 127; |
209 |
|
} |
210 |
< |
video_set_palette(VidLocal.palette); |
210 |
> |
video_set_palette(VidLocal.palette, 256); |
211 |
|
} |
212 |
|
|
213 |
|
|
250 |
|
*p++ = blue; |
251 |
|
} |
252 |
|
|
253 |
< |
video_set_palette(VidLocal.palette); |
253 |
> |
video_set_palette(VidLocal.palette, num); |
254 |
|
} |
255 |
|
|
256 |
|
|
333 |
|
Mac2Mac_memcpy(table, user_table, size); |
334 |
|
} |
335 |
|
|
336 |
< |
if (IsDirectMode(VidLocal.current_mode)) |
336 |
> |
if (IsDirectMode(VidLocal.desc->mode)) |
337 |
|
load_ramp_palette(); |
338 |
|
|
339 |
|
return true; |
405 |
|
// Update frame buffer base in DCE and param block |
406 |
|
WriteMacInt32(dce + dCtlDevBase, frame_base); |
407 |
|
WriteMacInt32(param + csBaseAddr, frame_base); |
408 |
+ |
|
409 |
+ |
// Patch frame buffer base address for MacOS versions <7.6 |
410 |
+ |
if (!VidLocal.dm_present) { // Only do this when no Display Manager seems to be present; otherwise, the screen will not get redrawn |
411 |
+ |
WriteMacInt32(0x824, frame_base); // ScrnBase |
412 |
+ |
WriteMacInt32(0x898, frame_base); // CrsrBase |
413 |
+ |
uint32 gdev = ReadMacInt32(0x8a4); // MainDevice |
414 |
+ |
gdev = ReadMacInt32(gdev); |
415 |
+ |
uint32 pmap = ReadMacInt32(gdev + 0x16); // gdPMap |
416 |
+ |
pmap = ReadMacInt32(pmap); |
417 |
+ |
WriteMacInt32(pmap, frame_base); // baseAddr |
418 |
+ |
} |
419 |
|
} |
420 |
|
|
421 |
|
|
439 |
|
VidLocal.current_id = VidLocal.desc->mode.resolution_id; |
440 |
|
VidLocal.preferred_mode = VidLocal.current_mode; |
441 |
|
VidLocal.preferred_id = VidLocal.current_id; |
442 |
+ |
VidLocal.dm_present = false; |
443 |
|
|
444 |
|
// Allocate Slot Manager parameter block in Mac RAM |
445 |
|
M68kRegisters r; |
495 |
|
case cscSetEntries: // Set palette |
496 |
|
case cscDirectSetEntries: { |
497 |
|
D(bug(" (Direct)SetEntries table %08x, count %d, start %d\n", ReadMacInt32(param + csTable), ReadMacInt16(param + csCount), ReadMacInt16(param + csStart))); |
498 |
< |
bool is_direct = IsDirectMode(VidLocal.current_mode); |
498 |
> |
bool is_direct = IsDirectMode(VidLocal.desc->mode); |
499 |
|
if (code == cscSetEntries && is_direct) |
500 |
|
return controlErr; |
501 |
|
if (code == cscDirectSetEntries && !is_direct) |
567 |
|
s_pal += 8; |
568 |
|
} |
569 |
|
} |
570 |
< |
video_set_palette(VidLocal.palette); |
570 |
> |
video_set_palette(VidLocal.palette, palette_size(VidLocal.desc->mode.depth)); |
571 |
|
return noErr; |
572 |
|
} |
573 |
|
|
590 |
|
0xffff0000, // 16 bpp |
591 |
|
0xffffffff // 32 bpp |
592 |
|
}; |
593 |
< |
uint32 p = VidLocal.desc->mac_frame_base; |
593 |
> |
uint32 frame_base = VidLocal.desc->mac_frame_base; |
594 |
|
uint32 pat = pattern[VidLocal.desc->mode.depth]; |
595 |
|
bool invert = (VidLocal.desc->mode.depth == VDEPTH_32BIT); |
596 |
|
for (uint32 y=0; y<VidLocal.desc->mode.y; y++) { |
597 |
|
for (uint32 x=0; x<VidLocal.desc->mode.bytes_per_row; x+=4) { |
598 |
< |
WriteMacInt32(p + x, pat); |
598 |
> |
WriteMacInt32(frame_base + x, pat); |
599 |
|
if (invert) |
600 |
|
pat = ~pat; |
601 |
|
} |
602 |
< |
p += VidLocal.desc->mode.bytes_per_row; |
602 |
> |
frame_base += VidLocal.desc->mode.bytes_per_row; |
603 |
|
pat = ~pat; |
604 |
|
} |
605 |
|
|
606 |
< |
if (IsDirectMode(VidLocal.current_mode)) |
606 |
> |
if (IsDirectMode(VidLocal.desc->mode)) |
607 |
|
load_ramp_palette(); |
608 |
|
|
609 |
|
return noErr; |
620 |
|
return noErr; |
621 |
|
|
622 |
|
case cscSetDefaultMode: { // Set default color depth |
623 |
< |
uint16 mode = ReadMacInt16(param + csMode); |
624 |
< |
D(bug(" SetDefaultMode %04x\n", mode)); |
623 |
> |
uint16 mode = ReadMacInt8(param + csMode); |
624 |
> |
D(bug(" SetDefaultMode %02x\n", mode)); |
625 |
|
VidLocal.preferred_mode = mode; |
626 |
|
return noErr; |
627 |
|
} |
734 |
|
|
735 |
|
case cscGetGray: // Get luminance mapping flag |
736 |
|
D(bug(" GetGray -> %d\n", VidLocal.luminance_mapping)); |
737 |
< |
WriteMacInt16(param, VidLocal.luminance_mapping ? 0x0100 : 0); |
737 |
> |
WriteMacInt8(param, VidLocal.luminance_mapping ? 1 : 0); |
738 |
|
return noErr; |
739 |
|
|
740 |
|
case cscGetInterrupt: // Get interrupt disable flag |
741 |
|
D(bug(" GetInterrupt -> %d\n", VidLocal.interrupts_enabled)); |
742 |
< |
WriteMacInt16(param, VidLocal.interrupts_enabled ? 0 : 0x0100); |
742 |
> |
WriteMacInt8(param, VidLocal.interrupts_enabled ? 0 : 1); |
743 |
|
return noErr; |
744 |
|
|
745 |
|
case cscGetGamma: |
748 |
|
return noErr; |
749 |
|
|
750 |
|
case cscGetDefaultMode: // Get default color depth |
751 |
< |
D(bug(" GetDefaultMode -> %04x\n", VidLocal.preferred_mode)); |
752 |
< |
WriteMacInt16(param + csMode, VidLocal.preferred_mode); |
751 |
> |
D(bug(" GetDefaultMode -> %02x\n", VidLocal.preferred_mode)); |
752 |
> |
WriteMacInt8(param + csMode, VidLocal.preferred_mode); |
753 |
|
return noErr; |
754 |
|
|
755 |
|
case cscGetCurrentMode: // Get current video mode (depth and resolution) |
833 |
|
WriteMacInt32(param + csVerticalLines, y); |
834 |
|
WriteMacInt32(param + csRefreshRate, 75 << 16); |
835 |
|
WriteMacInt16(param + csMaxDepthMode, DepthToAppleMode(max_depth_of_resolution(id))); |
836 |
+ |
WriteMacInt32(param + csResolutionFlags, 0); |
837 |
|
return noErr; |
838 |
|
} |
839 |
|
|
841 |
|
uint32 id = ReadMacInt32(param + csDisplayModeID); |
842 |
|
uint16 mode = ReadMacInt16(param + csDepthMode); |
843 |
|
D(bug(" GetVideoParameters %04x/%08x\n", mode, id)); |
844 |
+ |
VidLocal.dm_present = true; // Display Manager seems to be present |
845 |
|
|
846 |
|
vector<video_mode>::const_iterator i, end = VideoModes.end(); |
847 |
|
for (i = VideoModes.begin(); i != end; ++i) { |
903 |
|
return paramErr; // specified resolution/depth not supported |
904 |
|
} |
905 |
|
|
906 |
+ |
case cscGetMultiConnect: { |
907 |
+ |
uint32 conn = ReadMacInt32(param + csDisplayCountOrNumber); |
908 |
+ |
D(bug(" GetMultiConnect %08x\n", conn)); |
909 |
+ |
if (conn == 0xffffffff) { // Get number of connections |
910 |
+ |
WriteMacInt32(param + csDisplayCountOrNumber, 1); // Single-headed |
911 |
+ |
return noErr; |
912 |
+ |
} else if (conn == 1) { // Get information about first connection |
913 |
+ |
WriteMacInt16(param + csConnectInfo + csDisplayType, 8); // Modeless connection |
914 |
+ |
WriteMacInt8(param + csConnectInfo + csConnectTaggedType, 0); |
915 |
+ |
WriteMacInt8(param + csConnectInfo + csConnectTaggedData, 0); |
916 |
+ |
WriteMacInt32(param + csConnectInfo + csConnectFlags, 0x43); // All modes valid and safe, non-standard tagging |
917 |
+ |
WriteMacInt32(param + csConnectInfo + csDisplayComponent, 0); |
918 |
+ |
return noErr; |
919 |
+ |
} else |
920 |
+ |
return paramErr; |
921 |
+ |
} |
922 |
+ |
|
923 |
|
default: |
924 |
|
printf("WARNING: Unknown VideoDriverStatus(%d)\n", code); |
925 |
|
return statusErr; |