Character encoding fixups

This commit is contained in:
elasota
2020-10-14 18:18:57 -04:00
parent 7858aff6cd
commit b682004f29
5 changed files with 118 additions and 116 deletions

View File

@@ -144,9 +144,9 @@ void DrawHighScores (DrawSurface *surface)
PortabilityLayer::RenderedFont *appFont14 = GetApplicationFont(14, PortabilityLayer::FontFamilyFlag_Bold, true); PortabilityLayer::RenderedFont *appFont14 = GetApplicationFont(14, PortabilityLayer::FontFamilyFlag_Bold, true);
PasStringCopy(PSTR("<EFBFBD> "), tempStr); PasStringCopy(PSTR("\xa5 "), tempStr);
PasStringConcat(tempStr, thisHouseName); PasStringConcat(tempStr, thisHouseName);
PasStringConcat(tempStr, PSTR(" <EFBFBD>")); PasStringConcat(tempStr, PSTR(" \xa5"));
const Point scoreShadowPoint = Point::Create(scoreLeft + ((kScoreWide - appFont14->MeasurePStr(tempStr)) / 2) - 1, dropIt - 66); const Point scoreShadowPoint = Point::Create(scoreLeft + ((kScoreWide - appFont14->MeasurePStr(tempStr)) / 2) - 1, dropIt - 66);
surface->DrawString(scoreShadowPoint, tempStr, blackColor, appFont14); surface->DrawString(scoreShadowPoint, tempStr, blackColor, appFont14);

View File

@@ -785,7 +785,7 @@ void ShiftWholeHouse (short howFar)
short i, h, numRooms; short i, h, numRooms;
char wasState; char wasState;
OpenMessageWindow(PSTR("Shifting Whole House<EFBFBD>")); OpenMessageWindow(PSTR("Shifting Whole House\xc9"));
SpinCursor(3); SpinCursor(3);
CopyThisRoomToRoom(); CopyThisRoomToRoom();

View File

@@ -175,7 +175,7 @@ void RefreshRoomTitle (short mode)
break; break;
case kSavingTitleMode: case kSavingTitleMode:
surface->DrawString(strShadowPoint, PSTR("Saving Game<EFBFBD>"), blackColor, appFont); surface->DrawString(strShadowPoint, PSTR("Saving Game\xc9"), blackColor, appFont);
break; break;
default: default:
@@ -190,7 +190,7 @@ void RefreshRoomTitle (short mode)
break; break;
case kSavingTitleMode: case kSavingTitleMode:
surface->DrawString(strPoint, PSTR("Saving Game<EFBFBD>"), whiteColor, appFont); surface->DrawString(strPoint, PSTR("Saving Game\xc9"), whiteColor, appFont);
break; break;
default: default:

View File

@@ -14,13 +14,13 @@
//============================================================== Functions //============================================================== Functions
//-------------------------------------------------------------- PasStringCopy //-------------------------------------------------------------- PasStringCopy
// Given a source string and storage for a second, this function<EFBFBD> // Given a source string and storage for a second, this function?
// copies from one to the other. It assumes Pascal style strings. // copies from one to the other. It assumes Pascal style strings.
void PasStringCopy (StringPtr p1, StringPtr p2) void PasStringCopy (StringPtr p1, StringPtr p2)
{ {
register short stringLength; short stringLength;
stringLength = *p2++ = *p1++; stringLength = *p2++ = *p1++;
while (--stringLength >= 0) while (--stringLength >= 0)
*p2++ = *p1++; *p2++ = *p1++;
@@ -28,9 +28,9 @@ void PasStringCopy (StringPtr p1, StringPtr p2)
//-------------------------------------------------------------- WhichStringFirst //-------------------------------------------------------------- WhichStringFirst
// This is a sorting function that handles two Pascal strings. It<EFBFBD> // This is a sorting function that handles two Pascal strings. It?
// will return a 1 to indicate the 1st string is "greater", a 1 to<EFBFBD> // will return a 1 to indicate the 1st string is "greater", a 1 to?
// indicate the 2nd was greater and a 0 to indicate that the strings<EFBFBD> // indicate the 2nd was greater and a 0 to indicate that the strings?
// are equal. // are equal.
short WhichStringFirst (StringPtr p1, StringPtr p2) short WhichStringFirst (StringPtr p1, StringPtr p2)
@@ -38,11 +38,11 @@ short WhichStringFirst (StringPtr p1, StringPtr p2)
short smallestLength, seek, greater; short smallestLength, seek, greater;
char char1, char2; char char1, char2;
Boolean foundIt; Boolean foundIt;
smallestLength = p1[0]; smallestLength = p1[0];
if (p2[0] < smallestLength) if (p2[0] < smallestLength)
smallestLength = p2[0]; smallestLength = p2[0];
greater = 0; // neither are greater, they are equal greater = 0; // neither are greater, they are equal
seek = 1; // start at character #1 seek = 1; // start at character #1
foundIt = false; foundIt = false;
@@ -54,7 +54,7 @@ short WhichStringFirst (StringPtr p1, StringPtr p2)
char2 = p2[seek]; // make upper case (if applicable) char2 = p2[seek]; // make upper case (if applicable)
if ((char2 > 0x60) && (char2 < 0x7B)) if ((char2 > 0x60) && (char2 < 0x7B))
char2 -= 0x20; char2 -= 0x20;
if (char1 > char2) // first string is greater if (char1 > char2) // first string is greater
{ {
greater = 1; greater = 1;
@@ -79,69 +79,69 @@ short WhichStringFirst (StringPtr p1, StringPtr p2)
} }
} }
while (!foundIt); while (!foundIt);
return (greater); return (greater);
} }
//-------------------------------------------------------------- PasStringCopyNum //-------------------------------------------------------------- PasStringCopyNum
// This function copies a specified number of characters from one<EFBFBD> // This function copies a specified number of characters from one?
// Pascal string to another. // Pascal string to another.
void PasStringCopyNum (StringPtr p1, StringPtr p2, short charsToCopy) void PasStringCopyNum (StringPtr p1, StringPtr p2, short charsToCopy)
{ {
short i; short i;
if (charsToCopy > *p1) // if trying to copy more chars than there are if (charsToCopy > *p1) // if trying to copy more chars than there are
charsToCopy = *p1; // reduce the number of chars to copy to this size charsToCopy = *p1; // reduce the number of chars to copy to this size
*p2 = static_cast<unsigned char>(charsToCopy); *p2 = static_cast<unsigned char>(charsToCopy);
*p2++; p2++;
*p1++; p1++;
for (i = 0; i < charsToCopy; i++) for (i = 0; i < charsToCopy; i++)
*p2++ = *p1++; *p2++ = *p1++;
} }
//-------------------------------------------------------------- PasStringConcat //-------------------------------------------------------------- PasStringConcat
// This function concatenates the second Pascal string to the end of<EFBFBD> // This function concatenates the second Pascal string to the end of?
// the first Pascal string. // the first Pascal string.
void PasStringConcat (StringPtr p1, const PLPasStr &p2) void PasStringConcat (StringPtr p1, const PLPasStr &p2)
{ {
short wasLength, addedLength; short wasLength, addedLength;
wasLength = *p1; wasLength = *p1;
if (wasLength > 255) if (wasLength > 255)
wasLength = 255; wasLength = 255;
addedLength = p2.Length(); addedLength = p2.Length();
if ((wasLength + addedLength) > 255) if ((wasLength + addedLength) > 255)
addedLength = 255 - wasLength; addedLength = 255 - wasLength;
*p1 = wasLength + addedLength; *p1 = wasLength + addedLength;
p1 += (1 + wasLength); p1 += (1 + wasLength);
memcpy(p1, p2.Chars(), addedLength); memcpy(p1, p2.Chars(), addedLength);
} }
//-------------------------------------------------------------- GetLineOfText //-------------------------------------------------------------- GetLineOfText
// This function walks through a source string and looks for an<EFBFBD> // This function walks through a source string and looks for an?
// entire line of text. A "line" of text is assumed to be bounded<EFBFBD> // entire line of text. A "line" of text is assumed to be bounded?
// by carriage returns. The index variable indicates which line<EFBFBD> // by carriage returns. The index variable indicates which line?
// is sought. // is sought.
void GetLineOfText (StringPtr srcStr, short index, StringPtr textLine) void GetLineOfText (StringPtr srcStr, short index, StringPtr textLine)
{ {
short i, srcLength, count, start, stop; short i, srcLength, count, start, stop;
Boolean foundIt; Boolean foundIt;
PasStringCopy(PSTR(""), textLine); PasStringCopy(PSTR(""), textLine);
srcLength = srcStr[0]; srcLength = srcStr[0];
if (index == 0) // walk through to "index" if (index == 0) // walk through to "index"
start = 1; start = 1;
else else
@@ -165,11 +165,11 @@ void GetLineOfText (StringPtr srcStr, short index, StringPtr textLine)
} }
while ((i < srcLength) && (!foundIt)); while ((i < srcLength) && (!foundIt));
} }
if (start != 0) if (start != 0)
{ {
i = start; i = start;
foundIt = false; foundIt = false;
do do
{ {
@@ -181,7 +181,7 @@ void GetLineOfText (StringPtr srcStr, short index, StringPtr textLine)
i++; i++;
} }
while ((i < srcLength) && (!foundIt)); while ((i < srcLength) && (!foundIt));
if (!foundIt) if (!foundIt)
{ {
if (start > srcLength) if (start > srcLength)
@@ -192,9 +192,9 @@ void GetLineOfText (StringPtr srcStr, short index, StringPtr textLine)
else else
stop = i; stop = i;
} }
count = 0; count = 0;
for (i = start; i <= stop; i++) for (i = start; i <= stop; i++)
{ {
count++; count++;
@@ -206,18 +206,18 @@ void GetLineOfText (StringPtr srcStr, short index, StringPtr textLine)
//-------------------------------------------------------------- WrapText //-------------------------------------------------------------- WrapText
// Given a string and the maximum number of characters to put on<EFBFBD> // Given a string and the maximum number of characters to put on?
// one line, this function goes through and inserts carriage returns<EFBFBD> // one line, this function goes through and inserts carriage returns?
// in order to ensure that no line of text exceeds maxChars. // in order to ensure that no line of text exceeds maxChars.
void WrapText (StringPtr theText, short maxChars) void WrapText (StringPtr theText, short maxChars)
{ {
short lastChar, count, chars, spaceIs; short lastChar, count, chars, spaceIs;
Boolean foundEdge, foundSpace; Boolean foundEdge, foundSpace;
lastChar = theText[0]; lastChar = theText[0];
count = 0; count = 0;
do do
{ {
chars = 0; chars = 0;
@@ -236,7 +236,7 @@ void WrapText (StringPtr theText, short maxChars)
} }
} }
while ((count < lastChar) && (chars < maxChars) && (!foundEdge)); while ((count < lastChar) && (chars < maxChars) && (!foundEdge));
if ((!foundEdge) && (count < lastChar) && (foundSpace)) if ((!foundEdge) && (count < lastChar) && (foundSpace))
{ {
theText[spaceIs] = '\r'; theText[spaceIs] = '\r';
@@ -253,16 +253,16 @@ void WrapText (StringPtr theText, short maxChars)
void GetFirstWordOfString (StringPtr stringIn, StringPtr stringOut) void GetFirstWordOfString (StringPtr stringIn, StringPtr stringOut)
{ {
short isLong, spaceAt, i; short isLong, spaceAt, i;
isLong = stringIn[0]; isLong = stringIn[0];
spaceAt = isLong; spaceAt = isLong;
for (i = 1; i < isLong; i++) for (i = 1; i < isLong; i++)
{ {
if ((stringIn[i] == ' ') && (spaceAt == isLong)) if ((stringIn[i] == ' ') && (spaceAt == isLong))
spaceAt = i - 1; spaceAt = i - 1;
} }
if (spaceAt <= 0) if (spaceAt <= 0)
PasStringCopy(PSTR(""), stringOut); PasStringCopy(PSTR(""), stringOut);
else else
@@ -271,24 +271,24 @@ void GetFirstWordOfString (StringPtr stringIn, StringPtr stringOut)
//-------------------------------------------------------------- CollapseStringToWidth //-------------------------------------------------------------- CollapseStringToWidth
// Given a string and a maximum width (in pixels), this function<EFBFBD> // Given a string and a maximum width (in pixels), this function?
// calculates how wide the text would be drawn with the current<EFBFBD> // calculates how wide the text would be drawn with the current?
// font. If the text would exceed our width limit, characters<EFBFBD> // font. If the text would exceed our width limit, characters?
// are dropped off the end of the string and "<EFBFBD>" appended. // are dropped off the end of the string and "?" appended.
void CollapseStringToWidth (PortabilityLayer::RenderedFont *font, StringPtr theStr, short wide) void CollapseStringToWidth (PortabilityLayer::RenderedFont *font, StringPtr theStr, short wide)
{ {
short dotsWide; short dotsWide;
Boolean tooWide; Boolean tooWide;
dotsWide = font->MeasurePStr(PSTR("<EFBFBD>")); dotsWide = font->MeasurePStr(PSTR("\xc9"));
tooWide = font->MeasurePStr(theStr) > wide; tooWide = font->MeasurePStr(theStr) > wide;
while (tooWide && theStr[0] > 0) while (tooWide && theStr[0] > 0)
{ {
theStr[0]--; theStr[0]--;
tooWide = ((font->MeasurePStr(theStr) + dotsWide) > wide); tooWide = ((font->MeasurePStr(theStr) + dotsWide) > wide);
if (!tooWide) if (!tooWide)
PasStringConcat(theStr, PSTR("<EFBFBD>")); PasStringConcat(theStr, PSTR("\xc9"));
} }
} }
@@ -297,7 +297,7 @@ void CollapseStringToWidth (PortabilityLayer::RenderedFont *font, StringPtr theS
StringPtr GetLocalizedString (short index, StringPtr theString) StringPtr GetLocalizedString (short index, StringPtr theString)
{ {
#define kLocalizedStringsID 150 #define kLocalizedStringsID 150
GetIndString(theString, kLocalizedStringsID, index); GetIndString(theString, kLocalizedStringsID, index);
return (theString); return (theString);
} }

View File

@@ -34,11 +34,11 @@ extern Boolean switchedOut;
//-------------------------------------------------------------- ToolBoxInit //-------------------------------------------------------------- ToolBoxInit
// The standard ToolBox intialization that must happen when any Mac<61> // The standard ToolBox intialization that must happen when any Mac<61>
// program first launches. // program first launches.
void ToolBoxInit (void) void ToolBoxInit (void)
{ {
InitCursor(); InitCursor();
switchedOut = false; switchedOut = false;
} }
@@ -48,13 +48,13 @@ void ToolBoxInit (void)
short RandomInt (short range) short RandomInt (short range)
{ {
register long rawResult; long rawResult;
rawResult = Random(); rawResult = Random();
if (rawResult < 0L) if (rawResult < 0L)
rawResult *= -1L; rawResult *= -1L;
rawResult = (rawResult * (long)range) / 32768L; rawResult = (rawResult * (long)range) / 32768L;
return ((short)rawResult); return ((short)rawResult);
} }
@@ -64,30 +64,30 @@ short RandomInt (short range)
long RandomLong (long range) long RandomLong (long range)
{ {
register long highWord, lowWord; long highWord, lowWord;
register long rawResultHi, rawResultLo; long rawResultHi, rawResultLo;
highWord = (range & 0xFFFF0000) >> 16; highWord = (range & 0xFFFF0000) >> 16;
lowWord = range & 0x0000FFFF; lowWord = range & 0x0000FFFF;
rawResultHi = Random(); rawResultHi = Random();
if (rawResultHi < 0L) if (rawResultHi < 0L)
rawResultHi *= -1L; rawResultHi *= -1L;
rawResultHi = (rawResultHi * highWord) / 32768L; rawResultHi = (rawResultHi * highWord) / 32768L;
rawResultLo = Random(); rawResultLo = Random();
if (rawResultLo < 0L) if (rawResultLo < 0L)
rawResultLo *= -1L; rawResultLo *= -1L;
rawResultLo = (rawResultLo * lowWord) / 32768L; rawResultLo = (rawResultLo * lowWord) / 32768L;
rawResultHi = (rawResultHi << 16) + rawResultLo; rawResultHi = (rawResultHi << 16) + rawResultLo;
return (rawResultHi); return (rawResultHi);
} }
//-------------------------------------------------------------- RedAlert //-------------------------------------------------------------- RedAlert
// Called when we must quit app. Brings up a dialog informing user<65> // Called when we must quit app. Brings up a dialog informing user<65>
// of the problem and the exits to shell. // of the problem and the exits to shell.
void RedAlert (short errorNumber) void RedAlert (short errorNumber)
@@ -97,9 +97,9 @@ void RedAlert (short errorNumber)
#define rErrMssgID 171 // string ID for death error message #define rErrMssgID 171 // string ID for death error message
short dummyInt; short dummyInt;
Str255 errTitle, errMessage, errNumberString; Str255 errTitle, errMessage, errNumberString;
InitCursor(); InitCursor();
if (errorNumber > 1) // <= 0 is unaccounted for if (errorNumber > 1) // <= 0 is unaccounted for
{ {
GetIndString(errTitle, rErrTitleID, errorNumber); GetIndString(errTitle, rErrTitleID, errorNumber);
@@ -113,7 +113,7 @@ void RedAlert (short errorNumber)
NumToString((long)errorNumber, errNumberString); NumToString((long)errorNumber, errNumberString);
DialogTextSubstitutions substitutions(errTitle, errMessage, errNumberString, PSTR("")); DialogTextSubstitutions substitutions(errTitle, errMessage, errNumberString, PSTR(""));
// CenterAlert(rDeathAlertID); // CenterAlert(rDeathAlertID);
dummyInt = PortabilityLayer::DialogManager::GetInstance()->DisplayAlert(rDeathAlertID, &substitutions); dummyInt = PortabilityLayer::DialogManager::GetInstance()->DisplayAlert(rDeathAlertID, &substitutions);
//ExitToShell(); //ExitToShell();
@@ -127,14 +127,14 @@ void RedAlert (short errorNumber)
void CreateOffScreenBitMap (Rect *theRect, GrafPtr *offScreen) void CreateOffScreenBitMap (Rect *theRect, GrafPtr *offScreen)
{ {
GrafPtr theBWPort; GrafPtr theBWPort;
BitMap theBitMap; BitMap theBitMap;
long theRowBytes; long theRowBytes;
theBWPort = (GrafPtr)(NewPtr(sizeof(GrafPort))); theBWPort = (GrafPtr)(NewPtr(sizeof(GrafPort)));
OpenPort(theBWPort); OpenPort(theBWPort);
theRowBytes = (long)((theRect->right - theRect->left + 15L) / 16L) * 2L; theRowBytes = (long)((theRect->right - theRect->left + 15L) / 16L) * 2L;
theBitMap.rowBytes = (short)theRowBytes; theBitMap.rowBytes = (short)theRowBytes;
theBitMap.baseAddr = NewPtr((long)theBitMap.rowBytes * theBitMap.baseAddr = NewPtr((long)theBitMap.rowBytes *
(theRect->bottom - theRect->top)); (theRect->bottom - theRect->top));
if (theBitMap.baseAddr == nil) if (theBitMap.baseAddr == nil)
RedAlert(kErrNoMemory); RedAlert(kErrNoMemory);
@@ -161,7 +161,7 @@ void CreateOffScreenPixMap (Rect *theRect, CGrafPtr *offScreen)
PLError_t theErr; PLError_t theErr;
short thisDepth; short thisDepth;
char wasState; char wasState;
oldDevice = GetGDevice(); oldDevice = GetGDevice();
SetGDevice(thisGDevice); SetGDevice(thisGDevice);
newCGrafPtr = nil; newCGrafPtr = nil;
@@ -170,7 +170,7 @@ void CreateOffScreenPixMap (Rect *theRect, CGrafPtr *offScreen)
{ {
OpenCPort(newCGrafPtr); OpenCPort(newCGrafPtr);
thisDepth = (**(*newCGrafPtr).portPixMap).pixelSize; thisDepth = (**(*newCGrafPtr).portPixMap).pixelSize;
offRowBytes = ((((long)thisDepth * offRowBytes = ((((long)thisDepth *
(long)(theRect->right - theRect->left)) + 15L) >> 4L) << 1L; (long)(theRect->right - theRect->left)) + 15L) >> 4L) << 1L;
sizeOfOff = (long)(theRect->bottom - theRect->top + 1) * offRowBytes; sizeOfOff = (long)(theRect->bottom - theRect->top + 1) * offRowBytes;
// sizeOfOff = (long)(theRect->bottom - theRect->top) * offRowBytes; // sizeOfOff = (long)(theRect->bottom - theRect->top) * offRowBytes;
@@ -196,7 +196,7 @@ void CreateOffScreenPixMap (Rect *theRect, CGrafPtr *offScreen)
} }
else else
{ {
CloseCPort(newCGrafPtr); CloseCPort(newCGrafPtr);
DisposePtr((Ptr)newCGrafPtr); DisposePtr((Ptr)newCGrafPtr);
newCGrafPtr = nil; newCGrafPtr = nil;
RedAlert(kErrNoMemory); RedAlert(kErrNoMemory);
@@ -204,18 +204,18 @@ void CreateOffScreenPixMap (Rect *theRect, CGrafPtr *offScreen)
} }
else else
RedAlert(kErrNoMemory); RedAlert(kErrNoMemory);
*offScreen = newCGrafPtr; *offScreen = newCGrafPtr;
SetGDevice(oldDevice); SetGDevice(oldDevice);
} }
*/ */
//-------------------------------------------------------------------- CreateOffScreenGWorld //-------------------------------------------------------------------- CreateOffScreenGWorld
// Creates an offscreen GWorld<6C>using the depth passed in. // Creates an offscreen GWorld<6C>using the depth passed in.
PLError_t CreateOffScreenGWorld (DrawSurface **theGWorld, Rect *bounds) PLError_t CreateOffScreenGWorld (DrawSurface **theGWorld, Rect *bounds)
{ {
GpPixelFormat_t pixelFormat = PortabilityLayer::DisplayDeviceManager::GetInstance()->GetPixelFormat(); GpPixelFormat_t pixelFormat = PortabilityLayer::DisplayDeviceManager::GetInstance()->GetPixelFormat();
return NewGWorld(theGWorld, pixelFormat, bounds, nil); return NewGWorld(theGWorld, pixelFormat, bounds, nil);
} }
@@ -231,7 +231,7 @@ PLError_t CreateOffScreenGWorldCustomDepth(DrawSurface **theGWorld, Rect *bounds
void KillOffScreenPixMap (CGrafPtr offScreen) void KillOffScreenPixMap (CGrafPtr offScreen)
{ {
Ptr theseBits; Ptr theseBits;
if (offScreen != nil) if (offScreen != nil)
{ {
theseBits = (**(*offScreen).portPixMap).baseAddr; theseBits = (**(*offScreen).portPixMap).baseAddr;
@@ -257,23 +257,23 @@ void KillOffScreenBitMap (GrafPtr offScreen)
} }
*/ */
//-------------------------------------------------------------- LoadGraphic //-------------------------------------------------------------- LoadGraphic
// Function loads the specified 'PICT' from disk and draws it to<74> // Function loads the specified 'PICT' from disk and draws it to<74>
// the current port (no scaling, clipping, etc, are done). Always<79> // the current port (no scaling, clipping, etc, are done). Always<79>
// draws in the upper left corner of current port. // draws in the upper left corner of current port.
void LoadGraphic (DrawSurface *surface, short resID) void LoadGraphic (DrawSurface *surface, short resID)
{ {
Rect bounds; Rect bounds;
THandle<BitmapImage> thePicture; THandle<BitmapImage> thePicture;
thePicture = PortabilityLayer::ResourceManager::GetInstance()->GetAppResource('PICT', resID).StaticCast<BitmapImage>(); thePicture = PortabilityLayer::ResourceManager::GetInstance()->GetAppResource('PICT', resID).StaticCast<BitmapImage>();
if (thePicture == nil) if (thePicture == nil)
RedAlert(kErrFailedGraphicLoad); RedAlert(kErrFailedGraphicLoad);
bounds = (*thePicture)->GetRect(); bounds = (*thePicture)->GetRect();
OffsetRect(&bounds, -bounds.left, -bounds.top); OffsetRect(&bounds, -bounds.left, -bounds.top);
surface->DrawPicture(thePicture, bounds); surface->DrawPicture(thePicture, bounds);
thePicture.Dispose(); thePicture.Dispose();
} }
@@ -296,14 +296,14 @@ void LoadGraphicCustom(DrawSurface *surface, short resID)
} }
//-------------------------------------------------------------- LoadScaledGraphic //-------------------------------------------------------------- LoadScaledGraphic
// Loads the specified 'PICT' and draws it mapped to the rectangle<6C> // Loads the specified 'PICT' and draws it mapped to the rectangle<6C>
// specified. If this rect isn't the same size of the 'PICT', scaling<6E> // specified. If this rect isn't the same size of the 'PICT', scaling<6E>
// will occur. // will occur.
void LoadScaledGraphic (DrawSurface *surface, short resID, Rect *theRect) void LoadScaledGraphic (DrawSurface *surface, short resID, Rect *theRect)
{ {
THandle<BitmapImage> thePicture; THandle<BitmapImage> thePicture;
thePicture = PortabilityLayer::ResourceManager::GetInstance()->GetAppResource('PICT', resID).StaticCast<BitmapImage>(); thePicture = PortabilityLayer::ResourceManager::GetInstance()->GetAppResource('PICT', resID).StaticCast<BitmapImage>();
if (thePicture == nil) if (thePicture == nil)
RedAlert(kErrFailedGraphicLoad); RedAlert(kErrFailedGraphicLoad);
@@ -312,8 +312,8 @@ void LoadScaledGraphic (DrawSurface *surface, short resID, Rect *theRect)
} }
//-------------------------------------------------------------- LoadScaledGraphic //-------------------------------------------------------------- LoadScaledGraphic
// Loads the specified 'PICT' and draws it mapped to the rectangle<6C> // Loads the specified 'PICT' and draws it mapped to the rectangle<6C>
// specified. If this rect isn't the same size of the 'PICT', scaling<6E> // specified. If this rect isn't the same size of the 'PICT', scaling<6E>
// will occur. // will occur.
void LoadScaledGraphicCustom(DrawSurface *surface, short resID, Rect *theRect) void LoadScaledGraphicCustom(DrawSurface *surface, short resID, Rect *theRect)
@@ -378,7 +378,7 @@ void DrawCIcon (DrawSurface *surface, short theID, short h, short v)
if (PortabilityLayer::IconLoader::GetInstance()->LoadColorIcon(theID, colorImage, bwImage, maskImage)) if (PortabilityLayer::IconLoader::GetInstance()->LoadColorIcon(theID, colorImage, bwImage, maskImage))
{ {
Rect theRect; Rect theRect;
SetRect(&theRect, 0, 0, 32, 32); SetRect(&theRect, 0, 0, 32, 32);
OffsetRect(&theRect, h, v); OffsetRect(&theRect, h, v);
@@ -393,27 +393,27 @@ void DrawCIcon (DrawSurface *surface, short theID, short h, short v)
//-------------------------------------------------------------- LongSquareRoot //-------------------------------------------------------------- LongSquareRoot
// This is a quick and dirty square root function that returns pretty<74> // This is a quick and dirty square root function that returns pretty<74>
// accurate long integer results. It uses no transcendental functions or<6F> // accurate long integer results. It uses no transcendental functions or<6F>
// floating point. // floating point.
long LongSquareRoot (long theNumber) long LongSquareRoot (long theNumber)
{ {
long currentAnswer; long currentAnswer;
long nextTrial; long nextTrial;
if (theNumber <= 1L) if (theNumber <= 1L)
return (theNumber); return (theNumber);
nextTrial = theNumber / 2; nextTrial = theNumber / 2;
do do
{ {
currentAnswer = nextTrial; currentAnswer = nextTrial;
nextTrial = (nextTrial + theNumber / nextTrial) / 2; nextTrial = (nextTrial + theNumber / nextTrial) / 2;
} }
while (nextTrial < currentAnswer); while (nextTrial < currentAnswer);
return(currentAnswer); return(currentAnswer);
} }
@@ -427,13 +427,13 @@ Boolean WaitForInputEvent (short seconds)
TimeTaggedVOSEvent theEvent; TimeTaggedVOSEvent theEvent;
long timeToBail; long timeToBail;
Boolean waiting, didResume; Boolean waiting, didResume;
timeToBail = TickCount() + 60L * (long)seconds; timeToBail = TickCount() + 60L * (long)seconds;
FlushEvents(); FlushEvents();
waiting = true; waiting = true;
didResume = false; didResume = false;
while (waiting) while (waiting)
{ {
const KeyDownStates *theKeys = PortabilityLayer::InputManager::GetInstance()->GetKeys(); const KeyDownStates *theKeys = PortabilityLayer::InputManager::GetInstance()->GetKeys();
@@ -462,9 +462,9 @@ Boolean WaitForInputEvent (short seconds)
void WaitCommandQReleased (void) void WaitCommandQReleased (void)
{ {
Boolean waiting; Boolean waiting;
waiting = true; waiting = true;
while (waiting) while (waiting)
{ {
const KeyDownStates *theKeys = PortabilityLayer::InputManager::GetInstance()->GetKeys(); const KeyDownStates *theKeys = PortabilityLayer::InputManager::GetInstance()->GetKeys();
@@ -483,20 +483,20 @@ void WaitCommandQReleased (void)
char KeyMapOffsetFromRawKey (char rawKeyCode) char KeyMapOffsetFromRawKey (char rawKeyCode)
{ {
char hiByte, loByte, theOffset; char hiByte, loByte, theOffset;
hiByte = rawKeyCode & 0xF0; hiByte = rawKeyCode & 0xF0;
loByte = rawKeyCode & 0x0F; loByte = rawKeyCode & 0x0F;
if (loByte <= 0x07) if (loByte <= 0x07)
theOffset = hiByte + (0x07 - loByte); theOffset = hiByte + (0x07 - loByte);
else else
theOffset = hiByte + (0x17 - loByte); theOffset = hiByte + (0x17 - loByte);
return (theOffset); return (theOffset);
} }
//-------------------------------------------------------------- GetKeyName //-------------------------------------------------------------- GetKeyName
// Given a keyDown event (it's message field), this function returns<6E> // Given a keyDown event (it's message field), this function returns<6E>
// a string with that key's name (so we get "Shift" and "Esc", etc.). // a string with that key's name (so we get "Shift" and "Esc", etc.).
static const char *gs_specialKeyNames[GpKeySpecials::kCount] = static const char *gs_specialKeyNames[GpKeySpecials::kCount] =
@@ -591,6 +591,8 @@ void GetKeyName (intptr_t message, StringPtr theName)
// This should never happen // This should never happen
assert(false); assert(false);
break; break;
default:
break;
} }
const size_t name1Length = (name1 == nullptr) ? 0 : strlen(name1); const size_t name1Length = (name1 == nullptr) ? 0 : strlen(name1);
@@ -612,7 +614,7 @@ void GetKeyName (intptr_t message, StringPtr theName)
Boolean OptionKeyDown (void) Boolean OptionKeyDown (void)
{ {
const KeyDownStates *theKeys = PortabilityLayer::InputManager::GetInstance()->GetKeys(); const KeyDownStates *theKeys = PortabilityLayer::InputManager::GetInstance()->GetKeys();
if (theKeys->IsSet(PL_KEY_EITHER_SPECIAL(kAlt))) if (theKeys->IsSet(PL_KEY_EITHER_SPECIAL(kAlt)))
return (true); return (true);
else else
@@ -625,13 +627,13 @@ Boolean OptionKeyDown (void)
long ExtractCTSeed (CGrafPtr porter) long ExtractCTSeed (CGrafPtr porter)
{ {
long theSeed; long theSeed;
theSeed = (**((**(porter->portPixMap)).pmTable)).ctSeed; theSeed = (**((**(porter->portPixMap)).pmTable)).ctSeed;
return(theSeed); return(theSeed);
} }
*/ */
//-------------------------------------------------------------- ForceCTSeed //-------------------------------------------------------------- ForceCTSeed
// Forces the "color table seed" from a specified graf port to a<> // Forces the "color table seed" from a specified graf port to a<>
// specified value. // specified value.
/* /*
void ForceCTSeed (CGrafPtr porter, long newSeed) void ForceCTSeed (CGrafPtr porter, long newSeed)
@@ -640,25 +642,25 @@ void ForceCTSeed (CGrafPtr porter, long newSeed)
} }
*/ */
//-------------------------------------------------------------- DelayTicks //-------------------------------------------------------------- DelayTicks
// Lil' function that just sits and waits a specified number of<6F> // Lil' function that just sits and waits a specified number of<6F>
// Ticks (1/60 of a second). // Ticks (1/60 of a second).
void DelayTicks (long howLong) void DelayTicks (long howLong)
{ {
UInt32 whoCares; UInt32 whoCares;
Delay(howLong, &whoCares); Delay(howLong, &whoCares);
} }
//-------------------------------------------------------------- UnivGetSoundVolume //-------------------------------------------------------------- UnivGetSoundVolume
// Returns the speaker volume (as set by the user) in the range of<6F> // Returns the speaker volume (as set by the user) in the range of<6F>
// zero to seven (handles Sound Manager 3 case as well). // zero to seven (handles Sound Manager 3 case as well).
void UnivGetSoundVolume (short *volume, Boolean hasSM3) void UnivGetSoundVolume (short *volume, Boolean hasSM3)
{ {
long longVol; long longVol;
PLError_t theErr; PLError_t theErr;
// if (hasSM3) // if (hasSM3)
// { // {
longVol = PortabilityLayer::SoundSystem::GetInstance()->GetVolume(); longVol = PortabilityLayer::SoundSystem::GetInstance()->GetVolume();
@@ -666,7 +668,7 @@ void UnivGetSoundVolume (short *volume, Boolean hasSM3)
// } // }
// else // else
// GetSoundVol(volume); // GetSoundVol(volume);
if (*volume > 7) if (*volume > 7)
*volume = 7; *volume = 7;
else if (*volume < 0) else if (*volume < 0)
@@ -674,18 +676,18 @@ void UnivGetSoundVolume (short *volume, Boolean hasSM3)
} }
//-------------------------------------------------------------- UnivSetSoundVolume //-------------------------------------------------------------- UnivSetSoundVolume
// Sets the speaker volume to a specified value (in the range of<6F> // Sets the speaker volume to a specified value (in the range of<6F>
// zero to seven (handles Sound Manager 3 case as well). // zero to seven (handles Sound Manager 3 case as well).
void UnivSetSoundVolume (short volume, Boolean hasSM3) void UnivSetSoundVolume (short volume, Boolean hasSM3)
{ {
long longVol; long longVol;
if (volume > 7) if (volume > 7)
volume = 7; volume = 7;
else if (volume < 0) else if (volume < 0)
volume = 0; volume = 0;
// if (hasSM3) // if (hasSM3)
// { // {
longVol = (long)volume * 0x0025; longVol = (long)volume * 0x0025;