1 |
|
/* |
2 |
|
* video.cpp - Video/graphics emulation |
3 |
|
* |
4 |
< |
* SheepShaver (C) 1997-2002 Marc Hellwig and Christian Bauer |
4 |
> |
* SheepShaver (C) 1997-2004 Marc Hellwig and Christian Bauer |
5 |
|
* |
6 |
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
* it under the terms of the GNU General Public License as published by |
35 |
|
#include "macos_util.h" |
36 |
|
#include "user_strings.h" |
37 |
|
#include "version.h" |
38 |
+ |
#include "thunks.h" |
39 |
|
|
40 |
|
#define DEBUG 0 |
41 |
|
#include "debug.h" |
74 |
|
// Function pointers of imported functions |
75 |
|
typedef int16 (*iocic_ptr)(void *, int16); |
76 |
|
static uint32 iocic_tvect = 0; |
77 |
< |
static inline int16 IOCommandIsComplete(void *arg1, int16 arg2) |
77 |
> |
static inline int16 IOCommandIsComplete(uintptr arg1, int16 arg2) |
78 |
|
{ |
79 |
< |
return (int16)CallMacOS2(iocic_ptr, iocic_tvect, arg1, arg2); |
79 |
> |
return (int16)CallMacOS2(iocic_ptr, iocic_tvect, (void *)arg1, arg2); |
80 |
|
} |
81 |
|
typedef int16 (*vslnewis_ptr)(void *, uint32, uint32 *); |
82 |
|
static uint32 vslnewis_tvect = 0; |
83 |
< |
static inline int16 VSLNewInterruptService(void *arg1, uint32 arg2, uint32 *arg3) |
83 |
> |
static inline int16 VSLNewInterruptService(uintptr arg1, uint32 arg2, uintptr arg3) |
84 |
|
{ |
85 |
< |
return (int16)CallMacOS3(vslnewis_ptr, vslnewis_tvect, arg1, arg2, arg3); |
85 |
> |
return (int16)CallMacOS3(vslnewis_ptr, vslnewis_tvect, (void *)arg1, arg2, (uint32 *)arg3); |
86 |
|
} |
87 |
|
typedef int16 (*vsldisposeis_ptr)(uint32); |
88 |
|
static uint32 vsldisposeis_tvect = 0; |
98 |
|
} |
99 |
|
typedef void (*nqdmisc_ptr)(uint32, void *); |
100 |
|
static uint32 nqdmisc_tvect = 0; |
101 |
< |
void NQDMisc(uint32 arg1, void *arg2) |
101 |
> |
void NQDMisc(uint32 arg1, uintptr arg2) |
102 |
|
{ |
103 |
< |
CallMacOS2(nqdmisc_ptr, nqdmisc_tvect, arg1, arg2); |
103 |
> |
CallMacOS2(nqdmisc_ptr, nqdmisc_tvect, arg1, (void *)arg2); |
104 |
|
} |
105 |
|
|
106 |
|
|
168 |
|
set_gamma(csSave, 0); |
169 |
|
|
170 |
|
// Install and activate interrupt service |
171 |
< |
uint32 theServiceID = 0; |
172 |
< |
VSLNewInterruptService(csSave->regEntryID, FOURCC('v','b','l',' '), &theServiceID); |
173 |
< |
csSave->vslServiceID = theServiceID; |
171 |
> |
SheepVar32 theServiceID = 0; |
172 |
> |
VSLNewInterruptService(Host2MacAddr((uint8 *)csSave->regEntryID), FOURCC('v','b','l',' '), theServiceID.addr()); |
173 |
> |
csSave->vslServiceID = theServiceID.value(); |
174 |
|
D(bug(" Interrupt ServiceID %08lx\n", csSave->vslServiceID)); |
175 |
|
csSave->interruptsEnabled = true; |
176 |
|
|
184 |
|
|
185 |
|
static int16 set_gamma(VidLocals *csSave, uint32 gamma) |
186 |
|
{ |
187 |
+ |
#warning "FIXME: this code is not little endian aware" |
188 |
|
GammaTbl *clientGamma = (GammaTbl *)gamma; |
189 |
|
GammaTbl *gammaTable = csSave->gammaTable; |
190 |
|
|
288 |
|
case cscSetEntries: { // SetEntries |
289 |
|
D(bug("SetEntries\n")); |
290 |
|
if (VModes[cur_mode].viAppleMode > APPLE_8_BIT) return controlErr; |
291 |
< |
ColorSpec *s_pal = (ColorSpec *)Mac2HostAddr(ReadMacInt32(param + csTable)); |
292 |
< |
int16 start = ReadMacInt16(param + csStart); |
293 |
< |
int16 count = ReadMacInt16(param + csCount); |
294 |
< |
if (s_pal == NULL || count > 256) return controlErr; |
291 |
> |
uint32 s_pal = ReadMacInt32(param + csTable); |
292 |
> |
uint16 start = ReadMacInt16(param + csStart); |
293 |
> |
uint16 count = ReadMacInt16(param + csCount); |
294 |
> |
if (s_pal == 0 || count > 256) return controlErr; |
295 |
|
|
296 |
|
// Preparations for gamma correction |
297 |
|
bool do_gamma = false; |
314 |
|
|
315 |
|
// Set palette |
316 |
|
rgb_color *d_pal; |
317 |
< |
if (start == -1) { // Indexed |
317 |
> |
if (start == 0xffff) { // Indexed |
318 |
|
for (int i=0; i<=count; i++) { |
319 |
< |
d_pal = &(mac_pal[(*s_pal).value]); |
320 |
< |
uint8 red = (*s_pal).red >> 8; |
321 |
< |
uint8 green = (*s_pal).green >> 8; |
322 |
< |
uint8 blue = (*s_pal).blue >> 8; |
319 |
> |
d_pal = mac_pal + (ReadMacInt16(s_pal + csValue) & 0xff); |
320 |
> |
uint8 red = (uint16)ReadMacInt16(s_pal + csRed) >> 8; |
321 |
> |
uint8 green = (uint16)ReadMacInt16(s_pal + csGreen) >> 8; |
322 |
> |
uint8 blue = (uint16)ReadMacInt16(s_pal + csBlue) >> 8; |
323 |
|
if (csSave->luminanceMapping) |
324 |
|
red = green = blue = (red * 0x4ccc + green * 0x970a + blue * 0x1c29) >> 16; |
325 |
|
if (do_gamma) { |
330 |
|
(*d_pal).red = red; |
331 |
|
(*d_pal).green = green; |
332 |
|
(*d_pal).blue = blue; |
333 |
< |
s_pal++; |
333 |
> |
s_pal += 8; |
334 |
|
} |
335 |
< |
} else { // Sequential |
336 |
< |
d_pal = &(mac_pal[start]); |
335 |
> |
} else { // Sequential |
336 |
> |
d_pal = mac_pal + start; |
337 |
|
for (int i=0; i<=count; i++) { |
338 |
< |
uint8 red = (*s_pal).red >> 8; |
339 |
< |
uint8 green = (*s_pal).green >> 8; |
340 |
< |
uint8 blue = (*s_pal).blue >> 8; |
338 |
> |
uint8 red = (uint16)ReadMacInt16(s_pal + csRed) >> 8; |
339 |
> |
uint8 green = (uint16)ReadMacInt16(s_pal + csGreen) >> 8; |
340 |
> |
uint8 blue = (uint16)ReadMacInt16(s_pal + csBlue) >> 8; |
341 |
|
if (csSave->luminanceMapping) |
342 |
|
red = green = blue = (red * 0x4ccc + green * 0x970a + blue * 0x1c29) >> 16; |
343 |
|
if (do_gamma) { |
348 |
|
(*d_pal).red = red; |
349 |
|
(*d_pal).green = green; |
350 |
|
(*d_pal).blue = blue; |
351 |
< |
d_pal++; s_pal++; |
351 |
> |
d_pal++; |
352 |
> |
s_pal += 8; |
353 |
|
} |
354 |
|
} |
355 |
|
video_set_palette(); |
361 |
|
return set_gamma(csSave, ReadMacInt32(param)); |
362 |
|
|
363 |
|
case cscGrayPage: { // GrayPage |
364 |
< |
D(bug("GrayPage\n")); |
365 |
< |
uint32 *screen = (uint32 *)csSave->saveBaseAddr; |
366 |
< |
uint32 pattern; |
367 |
< |
uint32 row_bytes = VModes[cur_mode].viRowBytes; |
368 |
< |
switch (VModes[cur_mode].viAppleMode) { |
369 |
< |
case APPLE_8_BIT: |
370 |
< |
pattern=0xff00ff00; |
371 |
< |
for (int i=0;i<VModes[cur_mode].viYsize;i++) { |
372 |
< |
for (int j=0;j<(VModes[cur_mode].viXsize>>2);j++) |
373 |
< |
screen[j] = pattern; |
374 |
< |
pattern = ~pattern; |
375 |
< |
screen = (uint32 *)((uint32)screen + row_bytes); |
376 |
< |
} |
377 |
< |
break; |
378 |
< |
case APPLE_16_BIT: |
379 |
< |
pattern=0xffff0000; |
380 |
< |
for (int i=0;i<VModes[cur_mode].viYsize;i++) { |
381 |
< |
for (int j=0;j<(VModes[cur_mode].viXsize>>1);j++) |
382 |
< |
screen[j]=pattern; |
383 |
< |
pattern = ~pattern; |
384 |
< |
screen = (uint32 *)((uint32)screen + row_bytes); |
385 |
< |
} |
386 |
< |
break; |
384 |
< |
case APPLE_32_BIT: |
385 |
< |
pattern=0xffffffff; |
386 |
< |
for (int i=0;i<VModes[cur_mode].viYsize;i++) { |
387 |
< |
for (int j=0;j<VModes[cur_mode].viXsize;j++) { |
388 |
< |
screen[j]=pattern; |
389 |
< |
pattern = ~pattern; |
390 |
< |
} |
391 |
< |
screen = (uint32 *)((uint32)screen + row_bytes); |
392 |
< |
} |
393 |
< |
break; |
364 |
> |
D(bug("GrayPage %d\n", ReadMacInt16(param + csPage))); |
365 |
> |
if (ReadMacInt16(param + csPage)) |
366 |
> |
return paramErr; |
367 |
> |
|
368 |
> |
uint32 pattern[6] = { |
369 |
> |
0xaaaaaaaa, // 1 bpp |
370 |
> |
0xcccccccc, // 2 bpp |
371 |
> |
0xf0f0f0f0, // 4 bpp |
372 |
> |
0xff00ff00, // 8 bpp |
373 |
> |
0xffff0000, // 16 bpp |
374 |
> |
0xffffffff // 32 bpp |
375 |
> |
}; |
376 |
> |
uint32 p = csSave->saveBaseAddr; |
377 |
> |
uint32 pat = pattern[VModes[cur_mode].viAppleMode - APPLE_1_BIT]; |
378 |
> |
bool invert = (VModes[cur_mode].viAppleMode == APPLE_32_BIT); |
379 |
> |
for (uint32 y=0; y<VModes[cur_mode].viYsize; y++) { |
380 |
> |
for (uint32 x=0; x<VModes[cur_mode].viRowBytes; x+=4) { |
381 |
> |
WriteMacInt32(p + x, pat); |
382 |
> |
if (invert) |
383 |
> |
pat = ~pat; |
384 |
> |
} |
385 |
> |
p += VModes[cur_mode].viRowBytes; |
386 |
> |
pat = ~pat; |
387 |
|
} |
388 |
|
return noErr; |
389 |
|
} |
449 |
|
MacCursor[3] = ReadMacInt8(0x887); |
450 |
|
|
451 |
|
// Set new cursor image |
452 |
< |
if (display_type == DIS_SCREEN) |
452 |
> |
if (!video_can_change_cursor()) |
453 |
|
return controlErr; |
454 |
|
if (changed) |
455 |
|
video_set_cursor(); |
539 |
|
|
540 |
|
case cscGetEntries: { // GetEntries |
541 |
|
D(bug("GetEntries\n")); |
542 |
< |
ColorSpec *d_pal = (ColorSpec *)Mac2HostAddr(ReadMacInt32(param + csTable)); |
543 |
< |
int16 start = ReadMacInt16(param + csStart); |
544 |
< |
int16 count = ReadMacInt16(param + csCount); |
542 |
> |
uint32 d_pal = ReadMacInt32(param + csTable); |
543 |
> |
uint16 start = ReadMacInt16(param + csStart); |
544 |
> |
uint16 count = ReadMacInt16(param + csCount); |
545 |
|
rgb_color *s_pal; |
546 |
|
if ((VModes[cur_mode].viAppleMode == APPLE_32_BIT)|| |
547 |
|
(VModes[cur_mode].viAppleMode == APPLE_16_BIT)) { |
548 |
|
D(bug("ERROR: GetEntries in direct mode \n")); |
549 |
|
return statusErr; |
550 |
|
} |
551 |
< |
if (start >= 0) { // indexed get |
552 |
< |
s_pal = &(mac_pal[start]); |
551 |
> |
|
552 |
> |
if (start == 0xffff) { // Indexed |
553 |
|
for (uint16 i=0;i<count;i++) { |
554 |
< |
(*d_pal).red=(uint16)((*s_pal).red)*0x101; |
555 |
< |
(*d_pal).green=(uint16)((*s_pal).green)*0x101; |
556 |
< |
(*d_pal).blue=(uint16)((*s_pal).blue)*0x101; |
557 |
< |
d_pal++; s_pal++; |
554 |
> |
s_pal = mac_pal + (ReadMacInt16(d_pal + csValue) & 0xff); |
555 |
> |
uint8 red = (*s_pal).red; |
556 |
> |
uint8 green = (*s_pal).green; |
557 |
> |
uint8 blue = (*s_pal).blue; |
558 |
> |
WriteMacInt16(d_pal + csRed, red * 0x0101); |
559 |
> |
WriteMacInt16(d_pal + csGreen, green * 0x0101); |
560 |
> |
WriteMacInt16(d_pal + csBlue, blue * 0x0101); |
561 |
> |
d_pal += 8; |
562 |
|
} |
563 |
< |
} else { // selected set |
563 |
> |
} else { // Sequential |
564 |
> |
if (start + count > 255) |
565 |
> |
return paramErr; |
566 |
> |
s_pal = mac_pal + start; |
567 |
|
for (uint16 i=0;i<count;i++) { |
568 |
< |
s_pal = &(mac_pal[(*d_pal).value]); |
569 |
< |
(*d_pal).red=(uint16)((*s_pal).red)*0x101; |
570 |
< |
(*d_pal).green=(uint16)((*s_pal).green)*0x101; |
571 |
< |
(*d_pal).blue=(uint16)((*s_pal).blue)*0x101; |
572 |
< |
d_pal++; |
568 |
> |
uint8 red = (*s_pal).red; |
569 |
> |
uint8 green = (*s_pal).green; |
570 |
> |
uint8 blue = (*s_pal).blue; |
571 |
> |
s_pal++; |
572 |
> |
WriteMacInt16(d_pal + csRed, red * 0x0101); |
573 |
> |
WriteMacInt16(d_pal + csGreen, green * 0x0101); |
574 |
> |
WriteMacInt16(d_pal + csBlue, blue * 0x0101); |
575 |
> |
d_pal += 8; |
576 |
|
} |
577 |
|
}; |
578 |
|
return noErr; |
691 |
|
WriteMacInt32(param + csVerticalLines, 768); |
692 |
|
WriteMacInt32(param + csRefreshRate, 75<<16); |
693 |
|
break; |
694 |
+ |
case APPLE_1152x768: |
695 |
+ |
WriteMacInt32(param + csHorizontalPixels, 1152); |
696 |
+ |
WriteMacInt32(param + csVerticalLines, 768); |
697 |
+ |
WriteMacInt32(param + csRefreshRate, 75<<16); |
698 |
+ |
break; |
699 |
|
case APPLE_1152x900: |
700 |
|
WriteMacInt32(param + csHorizontalPixels, 1152); |
701 |
|
WriteMacInt32(param + csVerticalLines, 900); |
814 |
|
case APPLE_1024x768: |
815 |
|
timing = timingVESA_1024x768_75hz; |
816 |
|
break; |
817 |
+ |
case APPLE_1152x768: |
818 |
+ |
timing = timingApple_1152x870_75hz; // FIXME |
819 |
+ |
break; |
820 |
|
case APPLE_1152x900: |
821 |
|
timing = timingApple_1152x870_75hz; |
822 |
|
break; |
877 |
|
* Native (PCI) driver entry |
878 |
|
*/ |
879 |
|
|
880 |
< |
int16 VideoDoDriverIO(void *spaceID, void *commandID, void *commandContents, uint32 commandCode, uint32 commandKind) |
880 |
> |
int16 VideoDoDriverIO(uint32 spaceID, uint32 commandID, uint32 commandContents, uint32 commandCode, uint32 commandKind) |
881 |
|
{ |
882 |
< |
// D(bug("VideoDoDriverIO space %p, command %p, contents %p, code %d, kind %d\n", spaceID, commandID, commandContents, commandCode, commandKind)); |
882 |
> |
// D(bug("VideoDoDriverIO space %08x, command %08x, contents %08x, code %d, kind %d\n", spaceID, commandID, commandContents, commandCode, commandKind)); |
883 |
|
int16 err = noErr; |
884 |
|
|
885 |
|
switch (commandCode) { |
889 |
|
delete private_data->gammaTable; |
890 |
|
delete private_data; |
891 |
|
|
892 |
< |
iocic_tvect = (uint32)FindLibSymbol("\021DriverServicesLib", "\023IOCommandIsComplete"); |
892 |
> |
iocic_tvect = FindLibSymbol("\021DriverServicesLib", "\023IOCommandIsComplete"); |
893 |
|
D(bug("IOCommandIsComplete TVECT at %08lx\n", iocic_tvect)); |
894 |
|
if (iocic_tvect == 0) { |
895 |
|
printf("FATAL: VideoDoDriverIO(): Can't find IOCommandIsComplete()\n"); |
896 |
|
err = -1; |
897 |
|
break; |
898 |
|
} |
899 |
< |
vslnewis_tvect = (uint32)FindLibSymbol("\020VideoServicesLib", "\026VSLNewInterruptService"); |
899 |
> |
vslnewis_tvect = FindLibSymbol("\020VideoServicesLib", "\026VSLNewInterruptService"); |
900 |
|
D(bug("VSLNewInterruptService TVECT at %08lx\n", vslnewis_tvect)); |
901 |
|
if (vslnewis_tvect == 0) { |
902 |
|
printf("FATAL: VideoDoDriverIO(): Can't find VSLNewInterruptService()\n"); |
903 |
|
err = -1; |
904 |
|
break; |
905 |
|
} |
906 |
< |
vsldisposeis_tvect = (uint32)FindLibSymbol("\020VideoServicesLib", "\032VSLDisposeInterruptService"); |
906 |
> |
vsldisposeis_tvect = FindLibSymbol("\020VideoServicesLib", "\032VSLDisposeInterruptService"); |
907 |
|
D(bug("VSLDisposeInterruptService TVECT at %08lx\n", vsldisposeis_tvect)); |
908 |
|
if (vsldisposeis_tvect == 0) { |
909 |
|
printf("FATAL: VideoDoDriverIO(): Can't find VSLDisposeInterruptService()\n"); |
910 |
|
err = -1; |
911 |
|
break; |
912 |
|
} |
913 |
< |
vsldois_tvect = (uint32)FindLibSymbol("\020VideoServicesLib", "\025VSLDoInterruptService"); |
913 |
> |
vsldois_tvect = FindLibSymbol("\020VideoServicesLib", "\025VSLDoInterruptService"); |
914 |
|
D(bug("VSLDoInterruptService TVECT at %08lx\n", vsldois_tvect)); |
915 |
|
if (vsldois_tvect == 0) { |
916 |
|
printf("FATAL: VideoDoDriverIO(): Can't find VSLDoInterruptService()\n"); |
917 |
|
err = -1; |
918 |
|
break; |
919 |
|
} |
920 |
< |
nqdmisc_tvect = (uint32)FindLibSymbol("\014InterfaceLib", "\007NQDMisc"); |
920 |
> |
nqdmisc_tvect = FindLibSymbol("\014InterfaceLib", "\007NQDMisc"); |
921 |
|
D(bug("NQDMisc TVECT at %08lx\n", nqdmisc_tvect)); |
922 |
|
if (nqdmisc_tvect == 0) { |
923 |
|
printf("FATAL: VideoDoDriverIO(): Can't find NQDMisc()\n"); |
927 |
|
|
928 |
|
private_data = new VidLocals; |
929 |
|
private_data->gammaTable = NULL; |
930 |
< |
memcpy(private_data->regEntryID, (uint8 *)commandContents + 2, 16); // DriverInitInfo.deviceEntry |
930 |
> |
Mac2Host_memcpy(&private_data->regEntryID, commandContents + 2, 16); // DriverInitInfo.deviceEntry |
931 |
|
private_data->interruptsEnabled = false; // Disable interrupts |
932 |
|
break; |
933 |
|
|
940 |
|
break; |
941 |
|
|
942 |
|
case kOpenCommand: |
943 |
< |
err = VideoOpen((uint32)commandContents, private_data); |
943 |
> |
err = VideoOpen(commandContents, private_data); |
944 |
|
break; |
945 |
|
|
946 |
|
case kCloseCommand: |
947 |
< |
err = VideoClose((uint32)commandContents, private_data); |
947 |
> |
err = VideoClose(commandContents, private_data); |
948 |
|
break; |
949 |
|
|
950 |
|
case kControlCommand: |
951 |
< |
err = VideoControl((uint32)commandContents, private_data); |
951 |
> |
err = VideoControl(commandContents, private_data); |
952 |
|
break; |
953 |
|
|
954 |
|
case kStatusCommand: |
955 |
< |
err = VideoStatus((uint32)commandContents, private_data); |
955 |
> |
err = VideoStatus(commandContents, private_data); |
956 |
|
break; |
957 |
|
|
958 |
|
case kReadCommand: |