--- SheepShaver/src/video.cpp 2003/09/29 20:30:19 1.2 +++ SheepShaver/src/video.cpp 2004/12/19 09:01:04 1.10 @@ -1,7 +1,7 @@ /* * video.cpp - Video/graphics emulation * - * SheepShaver (C) 1997-2002 Marc Hellwig and Christian Bauer + * SheepShaver (C) 1997-2004 Marc Hellwig and Christian Bauer * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -35,6 +35,7 @@ #include "macos_util.h" #include "user_strings.h" #include "version.h" +#include "thunks.h" #define DEBUG 0 #include "debug.h" @@ -73,15 +74,15 @@ static long save_conf_mode = APPLE_8_BIT // Function pointers of imported functions typedef int16 (*iocic_ptr)(void *, int16); static uint32 iocic_tvect = 0; -static inline int16 IOCommandIsComplete(void *arg1, int16 arg2) +static inline int16 IOCommandIsComplete(uintptr arg1, int16 arg2) { - return (int16)CallMacOS2(iocic_ptr, iocic_tvect, arg1, arg2); + return (int16)CallMacOS2(iocic_ptr, iocic_tvect, (void *)arg1, arg2); } typedef int16 (*vslnewis_ptr)(void *, uint32, uint32 *); static uint32 vslnewis_tvect = 0; -static inline int16 VSLNewInterruptService(void *arg1, uint32 arg2, uint32 *arg3) +static inline int16 VSLNewInterruptService(uintptr arg1, uint32 arg2, uintptr arg3) { - return (int16)CallMacOS3(vslnewis_ptr, vslnewis_tvect, arg1, arg2, arg3); + return (int16)CallMacOS3(vslnewis_ptr, vslnewis_tvect, (void *)arg1, arg2, (uint32 *)arg3); } typedef int16 (*vsldisposeis_ptr)(uint32); static uint32 vsldisposeis_tvect = 0; @@ -97,9 +98,9 @@ int16 VSLDoInterruptService(uint32 arg1) } typedef void (*nqdmisc_ptr)(uint32, void *); static uint32 nqdmisc_tvect = 0; -void NQDMisc(uint32 arg1, void *arg2) +void NQDMisc(uint32 arg1, uintptr arg2) { - CallMacOS2(nqdmisc_ptr, nqdmisc_tvect, arg1, arg2); + CallMacOS2(nqdmisc_ptr, nqdmisc_tvect, arg1, (void *)arg2); } @@ -167,9 +168,9 @@ static int16 VideoOpen(uint32 pb, VidLoc set_gamma(csSave, 0); // Install and activate interrupt service - uint32 theServiceID = 0; - VSLNewInterruptService(csSave->regEntryID, FOURCC('v','b','l',' '), &theServiceID); - csSave->vslServiceID = theServiceID; + SheepVar32 theServiceID = 0; + VSLNewInterruptService(Host2MacAddr((uint8 *)csSave->regEntryID), FOURCC('v','b','l',' '), theServiceID.addr()); + csSave->vslServiceID = theServiceID.value(); D(bug(" Interrupt ServiceID %08lx\n", csSave->vslServiceID)); csSave->interruptsEnabled = true; @@ -183,6 +184,7 @@ static int16 VideoOpen(uint32 pb, VidLoc static int16 set_gamma(VidLocals *csSave, uint32 gamma) { +#warning "FIXME: this code is not little endian aware" GammaTbl *clientGamma = (GammaTbl *)gamma; GammaTbl *gammaTable = csSave->gammaTable; @@ -286,10 +288,10 @@ static int16 VideoControl(uint32 pb, Vid case cscSetEntries: { // SetEntries D(bug("SetEntries\n")); if (VModes[cur_mode].viAppleMode > APPLE_8_BIT) return controlErr; - ColorSpec *s_pal = (ColorSpec *)Mac2HostAddr(ReadMacInt32(param + csTable)); - int16 start = ReadMacInt16(param + csStart); - int16 count = ReadMacInt16(param + csCount); - if (s_pal == NULL || count > 256) return controlErr; + uint32 s_pal = ReadMacInt32(param + csTable); + uint16 start = ReadMacInt16(param + csStart); + uint16 count = ReadMacInt16(param + csCount); + if (s_pal == 0 || count > 256) return controlErr; // Preparations for gamma correction bool do_gamma = false; @@ -312,12 +314,12 @@ static int16 VideoControl(uint32 pb, Vid // Set palette rgb_color *d_pal; - if (start == -1) { // Indexed + if (start == 0xffff) { // Indexed for (int i=0; i<=count; i++) { - d_pal = &(mac_pal[(*s_pal).value]); - uint8 red = (*s_pal).red >> 8; - uint8 green = (*s_pal).green >> 8; - uint8 blue = (*s_pal).blue >> 8; + d_pal = mac_pal + (ReadMacInt16(s_pal + csValue) & 0xff); + uint8 red = (uint16)ReadMacInt16(s_pal + csRed) >> 8; + uint8 green = (uint16)ReadMacInt16(s_pal + csGreen) >> 8; + uint8 blue = (uint16)ReadMacInt16(s_pal + csBlue) >> 8; if (csSave->luminanceMapping) red = green = blue = (red * 0x4ccc + green * 0x970a + blue * 0x1c29) >> 16; if (do_gamma) { @@ -328,14 +330,14 @@ static int16 VideoControl(uint32 pb, Vid (*d_pal).red = red; (*d_pal).green = green; (*d_pal).blue = blue; - s_pal++; + s_pal += 8; } - } else { // Sequential - d_pal = &(mac_pal[start]); + } else { // Sequential + d_pal = mac_pal + start; for (int i=0; i<=count; i++) { - uint8 red = (*s_pal).red >> 8; - uint8 green = (*s_pal).green >> 8; - uint8 blue = (*s_pal).blue >> 8; + uint8 red = (uint16)ReadMacInt16(s_pal + csRed) >> 8; + uint8 green = (uint16)ReadMacInt16(s_pal + csGreen) >> 8; + uint8 blue = (uint16)ReadMacInt16(s_pal + csBlue) >> 8; if (csSave->luminanceMapping) red = green = blue = (red * 0x4ccc + green * 0x970a + blue * 0x1c29) >> 16; if (do_gamma) { @@ -346,7 +348,8 @@ static int16 VideoControl(uint32 pb, Vid (*d_pal).red = red; (*d_pal).green = green; (*d_pal).blue = blue; - d_pal++; s_pal++; + d_pal++; + s_pal += 8; } } video_set_palette(); @@ -358,39 +361,29 @@ static int16 VideoControl(uint32 pb, Vid return set_gamma(csSave, ReadMacInt32(param)); case cscGrayPage: { // GrayPage - D(bug("GrayPage\n")); - uint32 *screen = (uint32 *)csSave->saveBaseAddr; - uint32 pattern; - uint32 row_bytes = VModes[cur_mode].viRowBytes; - switch (VModes[cur_mode].viAppleMode) { - case APPLE_8_BIT: - pattern=0xff00ff00; - for (int i=0;i>2);j++) - screen[j] = pattern; - pattern = ~pattern; - screen = (uint32 *)((uint32)screen + row_bytes); - } - break; - case APPLE_16_BIT: - pattern=0xffff0000; - for (int i=0;i>1);j++) - screen[j]=pattern; - pattern = ~pattern; - screen = (uint32 *)((uint32)screen + row_bytes); - } - break; - case APPLE_32_BIT: - pattern=0xffffffff; - for (int i=0;isaveBaseAddr; + uint32 pat = pattern[VModes[cur_mode].viAppleMode - APPLE_1_BIT]; + bool invert = (VModes[cur_mode].viAppleMode == APPLE_32_BIT); + for (uint32 y=0; y= 0) { // indexed get - s_pal = &(mac_pal[start]); + + if (start == 0xffff) { // Indexed for (uint16 i=0;i 255) + return paramErr; + s_pal = mac_pal + start; for (uint16 i=0;igammaTable; delete private_data; - iocic_tvect = (uint32)FindLibSymbol("\021DriverServicesLib", "\023IOCommandIsComplete"); + iocic_tvect = FindLibSymbol("\021DriverServicesLib", "\023IOCommandIsComplete"); D(bug("IOCommandIsComplete TVECT at %08lx\n", iocic_tvect)); if (iocic_tvect == 0) { printf("FATAL: VideoDoDriverIO(): Can't find IOCommandIsComplete()\n"); err = -1; break; } - vslnewis_tvect = (uint32)FindLibSymbol("\020VideoServicesLib", "\026VSLNewInterruptService"); + vslnewis_tvect = FindLibSymbol("\020VideoServicesLib", "\026VSLNewInterruptService"); D(bug("VSLNewInterruptService TVECT at %08lx\n", vslnewis_tvect)); if (vslnewis_tvect == 0) { printf("FATAL: VideoDoDriverIO(): Can't find VSLNewInterruptService()\n"); err = -1; break; } - vsldisposeis_tvect = (uint32)FindLibSymbol("\020VideoServicesLib", "\032VSLDisposeInterruptService"); + vsldisposeis_tvect = FindLibSymbol("\020VideoServicesLib", "\032VSLDisposeInterruptService"); D(bug("VSLDisposeInterruptService TVECT at %08lx\n", vsldisposeis_tvect)); if (vsldisposeis_tvect == 0) { printf("FATAL: VideoDoDriverIO(): Can't find VSLDisposeInterruptService()\n"); err = -1; break; } - vsldois_tvect = (uint32)FindLibSymbol("\020VideoServicesLib", "\025VSLDoInterruptService"); + vsldois_tvect = FindLibSymbol("\020VideoServicesLib", "\025VSLDoInterruptService"); D(bug("VSLDoInterruptService TVECT at %08lx\n", vsldois_tvect)); if (vsldois_tvect == 0) { printf("FATAL: VideoDoDriverIO(): Can't find VSLDoInterruptService()\n"); err = -1; break; } - nqdmisc_tvect = (uint32)FindLibSymbol("\014InterfaceLib", "\007NQDMisc"); + nqdmisc_tvect = FindLibSymbol("\014InterfaceLib", "\007NQDMisc"); D(bug("NQDMisc TVECT at %08lx\n", nqdmisc_tvect)); if (nqdmisc_tvect == 0) { printf("FATAL: VideoDoDriverIO(): Can't find NQDMisc()\n"); @@ -916,7 +927,7 @@ int16 VideoDoDriverIO(void *spaceID, voi private_data = new VidLocals; private_data->gammaTable = NULL; - memcpy(private_data->regEntryID, (uint8 *)commandContents + 2, 16); // DriverInitInfo.deviceEntry + Mac2Host_memcpy(&private_data->regEntryID, commandContents + 2, 16); // DriverInitInfo.deviceEntry private_data->interruptsEnabled = false; // Disable interrupts break; @@ -929,19 +940,19 @@ int16 VideoDoDriverIO(void *spaceID, voi break; case kOpenCommand: - err = VideoOpen((uint32)commandContents, private_data); + err = VideoOpen(commandContents, private_data); break; case kCloseCommand: - err = VideoClose((uint32)commandContents, private_data); + err = VideoClose(commandContents, private_data); break; case kControlCommand: - err = VideoControl((uint32)commandContents, private_data); + err = VideoControl(commandContents, private_data); break; case kStatusCommand: - err = VideoStatus((uint32)commandContents, private_data); + err = VideoStatus(commandContents, private_data); break; case kReadCommand: