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 |
< |
* Check whether specified resolution ID is one of the supported resolutions |
69 |
> |
* Initialize apple_mode_for_depth[] array from VideoModes list |
70 |
|
*/ |
71 |
|
|
72 |
< |
static bool has_resolution(uint32 id) |
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->resolution_id == id) |
92 |
> |
if (i->depth == depth) |
93 |
|
return true; |
94 |
|
++i; |
95 |
|
} |
98 |
|
|
99 |
|
|
100 |
|
/* |
101 |
+ |
* Check whether specified resolution ID is one of the supported resolutions |
102 |
+ |
*/ |
103 |
+ |
|
104 |
+ |
static bool has_resolution(uint32 id) |
105 |
+ |
{ |
106 |
+ |
vector<video_mode>::const_iterator i, end = VideoModes.end(); |
107 |
+ |
for (i = VideoModes.begin(); i != end; ++i) { |
108 |
+ |
if (i->resolution_id == id) |
109 |
+ |
return true; |
110 |
+ |
} |
111 |
+ |
return false; |
112 |
+ |
} |
113 |
+ |
|
114 |
+ |
|
115 |
+ |
/* |
116 |
|
* Find specified mode (depth/resolution) (or VideoModes.end() if not found) |
117 |
|
*/ |
118 |
|
|
119 |
|
static vector<video_mode>::const_iterator find_mode(uint16 mode, uint32 id) |
120 |
|
{ |
121 |
< |
vector<video_mode>::const_iterator i = VideoModes.begin(), end = VideoModes.end(); |
122 |
< |
while (i != end) { |
121 |
> |
vector<video_mode>::const_iterator i, end = VideoModes.end(); |
122 |
> |
for (i = VideoModes.begin(); i != end; ++i) { |
123 |
|
if (i->resolution_id == id && DepthToAppleMode(i->depth) == mode) |
124 |
|
return i; |
90 |
– |
++i; |
125 |
|
} |
126 |
|
return i; |
127 |
|
} |
134 |
|
static video_depth max_depth_of_resolution(uint32 id) |
135 |
|
{ |
136 |
|
video_depth m = VDEPTH_1BIT; |
137 |
< |
vector<video_mode>::const_iterator i = VideoModes.begin(), end = VideoModes.end(); |
138 |
< |
while (i != end) { |
137 |
> |
vector<video_mode>::const_iterator i, end = VideoModes.end(); |
138 |
> |
for (i = VideoModes.begin(); i != end; ++i) { |
139 |
|
if (i->depth > m) |
140 |
|
m = i->depth; |
107 |
– |
++i; |
141 |
|
} |
142 |
|
return m; |
143 |
|
} |
149 |
|
|
150 |
|
static void get_size_of_resolution(uint32 id, uint32 &x, uint32 &y) |
151 |
|
{ |
152 |
< |
vector<video_mode>::const_iterator i = VideoModes.begin(), end = VideoModes.end(); |
153 |
< |
while (i != end) { |
152 |
> |
vector<video_mode>::const_iterator i, end = VideoModes.end(); |
153 |
> |
for (i = VideoModes.begin(); i != end; ++i) { |
154 |
|
if (i->resolution_id == id) { |
155 |
|
x = i->x; |
156 |
|
y = i->y; |
157 |
|
return; |
158 |
|
} |
159 |
< |
++i; |
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 |
|
|
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; |
341 |
|
|
342 |
|
|
343 |
|
/* |
344 |
+ |
* Switch video mode |
345 |
+ |
*/ |
346 |
+ |
|
347 |
+ |
static void switch_mode(const video_mode &mode, uint32 param, uint32 dce) |
348 |
+ |
{ |
349 |
+ |
// Switch mode |
350 |
+ |
set_gray_palette(); |
351 |
+ |
video_switch_to_mode(mode); |
352 |
+ |
|
353 |
+ |
// Update VidLocal |
354 |
+ |
VidLocal.current_mode = DepthToAppleMode(mode.depth); |
355 |
+ |
VidLocal.current_id = mode.resolution_id; |
356 |
+ |
|
357 |
+ |
uint32 frame_base = VidLocal.desc->mac_frame_base; |
358 |
+ |
|
359 |
+ |
M68kRegisters r; |
360 |
+ |
uint32 sp = VidLocal.slot_param; |
361 |
+ |
r.a[0] = sp; |
362 |
+ |
|
363 |
+ |
// Find functional sResource for this display |
364 |
+ |
WriteMacInt8(sp + spSlot, ReadMacInt8(dce + dCtlSlot)); |
365 |
+ |
WriteMacInt8(sp + spID, ReadMacInt8(dce + dCtlSlotId)); |
366 |
+ |
WriteMacInt8(sp + spExtDev, 0); |
367 |
+ |
r.d[0] = 0x0016; |
368 |
+ |
Execute68kTrap(0xa06e, &r); // SRsrcInfo() |
369 |
+ |
uint32 rsrc = ReadMacInt32(sp + spPointer); |
370 |
+ |
|
371 |
+ |
// Patch minorBase (otherwise rebooting won't work) |
372 |
+ |
WriteMacInt8(sp + spID, 0x0a); // minorBase |
373 |
+ |
r.d[0] = 0x0006; |
374 |
+ |
Execute68kTrap(0xa06e, &r); // SFindStruct() |
375 |
+ |
uint32 minor_base = ReadMacInt32(sp + spPointer) - ROMBaseMac; |
376 |
+ |
ROMBaseHost[minor_base + 0] = frame_base >> 24; |
377 |
+ |
ROMBaseHost[minor_base + 1] = frame_base >> 16; |
378 |
+ |
ROMBaseHost[minor_base + 2] = frame_base >> 8; |
379 |
+ |
ROMBaseHost[minor_base + 3] = frame_base; |
380 |
+ |
|
381 |
+ |
// Patch video mode parameter table |
382 |
+ |
WriteMacInt32(sp + spPointer, rsrc); |
383 |
+ |
WriteMacInt8(sp + spID, DepthToAppleMode(mode.depth)); |
384 |
+ |
r.d[0] = 0x0006; |
385 |
+ |
Execute68kTrap(0xa06e, &r); // SFindStruct() |
386 |
+ |
WriteMacInt8(sp + spID, 0x01); |
387 |
+ |
r.d[0] = 0x0006; |
388 |
+ |
Execute68kTrap(0xa06e, &r); // SFindStruct() |
389 |
+ |
uint32 p = ReadMacInt32(sp + spPointer) - ROMBaseMac; |
390 |
+ |
ROMBaseHost[p + 8] = mode.bytes_per_row >> 8; |
391 |
+ |
ROMBaseHost[p + 9] = mode.bytes_per_row; |
392 |
+ |
ROMBaseHost[p + 14] = mode.y >> 8; |
393 |
+ |
ROMBaseHost[p + 15] = mode.y; |
394 |
+ |
ROMBaseHost[p + 16] = mode.x >> 8; |
395 |
+ |
ROMBaseHost[p + 17] = mode.x; |
396 |
+ |
|
397 |
+ |
// Recalculate slot ROM checksum |
398 |
+ |
ChecksumSlotROM(); |
399 |
+ |
|
400 |
+ |
// Update sResource |
401 |
+ |
WriteMacInt8(sp + spID, ReadMacInt8(dce + dCtlSlotId)); |
402 |
+ |
r.d[0] = 0x002b; |
403 |
+ |
Execute68kTrap(0xa06e, &r); // SUpdateSRT() |
404 |
+ |
|
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 |
+ |
uint32 gdev = ReadMacInt32(0x8a4); // MainDevice |
413 |
+ |
gdev = ReadMacInt32(gdev); |
414 |
+ |
uint32 pmap = ReadMacInt32(gdev + 0x16); // gdPMap |
415 |
+ |
pmap = ReadMacInt32(pmap); |
416 |
+ |
WriteMacInt32(pmap, frame_base); // baseAddr |
417 |
+ |
} |
418 |
+ |
} |
419 |
+ |
|
420 |
+ |
|
421 |
+ |
/* |
422 |
|
* Driver Open() routine |
423 |
|
*/ |
424 |
|
|
438 |
|
VidLocal.current_id = VidLocal.desc->mode.resolution_id; |
439 |
|
VidLocal.preferred_mode = VidLocal.current_mode; |
440 |
|
VidLocal.preferred_id = VidLocal.current_id; |
441 |
+ |
VidLocal.dm_present = false; |
442 |
|
|
443 |
|
// Allocate Slot Manager parameter block in Mac RAM |
444 |
|
M68kRegisters r; |
485 |
|
vector<video_mode>::const_iterator i = find_mode(mode, VidLocal.current_id); |
486 |
|
if (i == VideoModes.end()) |
487 |
|
return paramErr; |
488 |
< |
set_gray_palette(); |
342 |
< |
video_switch_to_mode(*i); |
343 |
< |
VidLocal.current_mode = mode; |
344 |
< |
WriteMacInt32(param + csBaseAddr, VidLocal.desc->mac_frame_base); |
345 |
< |
WriteMacInt32(dce + dCtlDevBase, VidLocal.desc->mac_frame_base); |
488 |
> |
switch_mode(*i, param, dce); |
489 |
|
} |
490 |
|
D(bug(" base %08x\n", VidLocal.desc->mac_frame_base)); |
491 |
|
return noErr; |
494 |
|
case cscSetEntries: // Set palette |
495 |
|
case cscDirectSetEntries: { |
496 |
|
D(bug(" (Direct)SetEntries table %08x, count %d, start %d\n", ReadMacInt32(param + csTable), ReadMacInt16(param + csCount), ReadMacInt16(param + csStart))); |
497 |
< |
bool is_direct = IsDirectMode(VidLocal.current_mode); |
497 |
> |
bool is_direct = IsDirectMode(VidLocal.desc->mode); |
498 |
|
if (code == cscSetEntries && is_direct) |
499 |
|
return controlErr; |
500 |
|
if (code == cscDirectSetEntries && !is_direct) |
566 |
|
s_pal += 8; |
567 |
|
} |
568 |
|
} |
569 |
< |
video_set_palette(VidLocal.palette); |
569 |
> |
video_set_palette(VidLocal.palette, palette_size(VidLocal.desc->mode.depth)); |
570 |
|
return noErr; |
571 |
|
} |
572 |
|
|
589 |
|
0xffff0000, // 16 bpp |
590 |
|
0xffffffff // 32 bpp |
591 |
|
}; |
592 |
< |
uint32 p = VidLocal.desc->mac_frame_base; |
592 |
> |
uint32 frame_base = VidLocal.desc->mac_frame_base; |
593 |
|
uint32 pat = pattern[VidLocal.desc->mode.depth]; |
594 |
|
bool invert = (VidLocal.desc->mode.depth == VDEPTH_32BIT); |
595 |
|
for (uint32 y=0; y<VidLocal.desc->mode.y; y++) { |
596 |
|
for (uint32 x=0; x<VidLocal.desc->mode.bytes_per_row; x+=4) { |
597 |
< |
WriteMacInt32(p + x, pat); |
597 |
> |
WriteMacInt32(frame_base + x, pat); |
598 |
|
if (invert) |
599 |
|
pat = ~pat; |
600 |
|
} |
601 |
< |
p += VidLocal.desc->mode.bytes_per_row; |
601 |
> |
frame_base += VidLocal.desc->mode.bytes_per_row; |
602 |
|
pat = ~pat; |
603 |
|
} |
604 |
|
|
605 |
< |
if (IsDirectMode(VidLocal.current_mode)) |
605 |
> |
if (IsDirectMode(VidLocal.desc->mode)) |
606 |
|
load_ramp_palette(); |
607 |
|
|
608 |
|
return noErr; |
640 |
|
vector<video_mode>::const_iterator i = find_mode(mode, id); |
641 |
|
if (i == VideoModes.end()) |
642 |
|
return paramErr; |
643 |
< |
set_gray_palette(); |
501 |
< |
video_switch_to_mode(*i); |
502 |
< |
VidLocal.current_mode = mode; |
503 |
< |
VidLocal.current_id = id; |
504 |
< |
uint32 frame_base = VidLocal.desc->mac_frame_base; |
505 |
< |
WriteMacInt32(param + csBaseAddr, frame_base); |
506 |
< |
|
507 |
< |
M68kRegisters r; |
508 |
< |
uint32 sp = VidLocal.slot_param; |
509 |
< |
r.a[0] = sp; |
510 |
< |
|
511 |
< |
// Find functional sResource for this display |
512 |
< |
WriteMacInt8(sp + spSlot, ReadMacInt8(dce + dCtlSlot)); |
513 |
< |
WriteMacInt8(sp + spID, ReadMacInt8(dce + dCtlSlotId)); |
514 |
< |
WriteMacInt8(sp + spExtDev, 0); |
515 |
< |
r.d[0] = 0x0016; |
516 |
< |
Execute68kTrap(0xa06e, &r); // SRsrcInfo() |
517 |
< |
uint32 rsrc = ReadMacInt32(sp + spPointer); |
518 |
< |
|
519 |
< |
// Patch minorBase (otherwise rebooting won't work) |
520 |
< |
WriteMacInt8(sp + spID, 0x0a); // minorBase |
521 |
< |
r.d[0] = 0x0006; |
522 |
< |
Execute68kTrap(0xa06e, &r); // SFindStruct() |
523 |
< |
uint32 minor_base = ReadMacInt32(sp + spPointer) - ROMBaseMac; |
524 |
< |
ROMBaseHost[minor_base + 0] = frame_base >> 24; |
525 |
< |
ROMBaseHost[minor_base + 1] = frame_base >> 16; |
526 |
< |
ROMBaseHost[minor_base + 2] = frame_base >> 8; |
527 |
< |
ROMBaseHost[minor_base + 3] = frame_base; |
528 |
< |
|
529 |
< |
// Patch video mode parameter table |
530 |
< |
WriteMacInt32(sp + spPointer, rsrc); |
531 |
< |
WriteMacInt8(sp + spID, mode); |
532 |
< |
r.d[0] = 0x0006; |
533 |
< |
Execute68kTrap(0xa06e, &r); // SFindStruct() |
534 |
< |
WriteMacInt8(sp + spID, 0x01); |
535 |
< |
r.d[0] = 0x0006; |
536 |
< |
Execute68kTrap(0xa06e, &r); // SFindStruct() |
537 |
< |
uint32 p = ReadMacInt32(sp + spPointer) - ROMBaseMac; |
538 |
< |
ROMBaseHost[p + 8] = i->bytes_per_row >> 8; |
539 |
< |
ROMBaseHost[p + 9] = i->bytes_per_row; |
540 |
< |
ROMBaseHost[p + 14] = i->y >> 8; |
541 |
< |
ROMBaseHost[p + 15] = i->y; |
542 |
< |
ROMBaseHost[p + 16] = i->x >> 8; |
543 |
< |
ROMBaseHost[p + 17] = i->x; |
544 |
< |
|
545 |
< |
// Recalculate slot ROM checksum |
546 |
< |
ChecksumSlotROM(); |
547 |
< |
|
548 |
< |
// Update sResource |
549 |
< |
WriteMacInt8(sp + spID, ReadMacInt8(dce + dCtlSlotId)); |
550 |
< |
r.d[0] = 0x002b; |
551 |
< |
Execute68kTrap(0xa06e, &r); // SUpdateSRT() |
552 |
< |
|
553 |
< |
// Update frame buffer base in DCE |
554 |
< |
WriteMacInt32(dce + dCtlDevBase, frame_base); |
643 |
> |
switch_mode(*i, param, dce); |
644 |
|
} |
645 |
|
D(bug(" base %08x\n", VidLocal.desc->mac_frame_base)); |
646 |
|
return noErr; |
839 |
|
uint32 id = ReadMacInt32(param + csDisplayModeID); |
840 |
|
uint16 mode = ReadMacInt16(param + csDepthMode); |
841 |
|
D(bug(" GetVideoParameters %04x/%08x\n", mode, id)); |
842 |
+ |
VidLocal.dm_present = true; // Display Manager seems to be present |
843 |
|
|
844 |
< |
vector<video_mode>::const_iterator i = VideoModes.begin(), end = VideoModes.end(); |
845 |
< |
while (i != end) { |
844 |
> |
vector<video_mode>::const_iterator i, end = VideoModes.end(); |
845 |
> |
for (i = VideoModes.begin(); i != end; ++i) { |
846 |
|
if (DepthToAppleMode(i->depth) == mode && i->resolution_id == id) { |
847 |
|
uint32 vp = ReadMacInt32(param + csVPBlockPtr); |
848 |
|
WriteMacInt32(vp + vpBaseOffset, 0); |
897 |
|
WriteMacInt32(param + csDeviceType, dev_type); |
898 |
|
return noErr; |
899 |
|
} |
810 |
– |
++i; |
900 |
|
} |
901 |
|
return paramErr; // specified resolution/depth not supported |
902 |
|
} |