+ char string[4096];
+ va_list arg;
+
+ va_start(arg, text);
+ vsprintf(string, text, arg);
+ va_end(arg);
+
+ uint32 pitch = sdlemuGetOverlayWidthInPixels();
+ uint32 length = strlen(string), address = x + (y * pitch);
+
+ color &= 0x00FFFFFF; // Just in case alpha was passed in...
+
+ for(uint32 i=0; i<length; i++)
+ {
+ uint8 c = string[i];
+ c = (c < 32 ? 0 : c - 32);
+ uint32 fontAddr = (uint32)c * FONT_WIDTH * FONT_HEIGHT;
+
+ for(uint32 yy=0; yy<FONT_HEIGHT; yy++)
+ {
+ for(uint32 xx=0; xx<FONT_WIDTH; xx++)
+ {
+ uint8 fontTrans = font2[fontAddr++];
+ uint32 newTrans = (fontTrans * transparency / 255) << 24;
+ uint32 pixel = newTrans | color;
+
+ *(screen + address + xx + (yy * pitch)) = pixel;
+ }
+ }
+
+ address += FONT_WIDTH;
+ }
+}
+
+//
+// Draw "picture"
+// Uses zero as transparent color
+// Can also use an optional alpha channel
+// Alpha channel is now mandatory! ;-)
+//
+//void DrawTransparentBitmap(int16 * screen, uint32 x, uint32 y, uint16 * bitmap, uint8 * alpha/*=NULL*/)
+/*void DrawTransparentBitmap(uint32 * screen, uint32 x, uint32 y, uint32 * bitmap, uint8 * alpha)
+{
+ uint32 width = bitmap[0], height = bitmap[1];
+ bitmap += 2;
+
+// uint32 pitch = GetSDLScreenPitch() / 2; // Returns pitch in bytes but we need words...
+ uint32 pitch = sdlemuGetOverlayWidthInPixels();//GetSDLScreenWidthInPixels();
+ uint32 address = x + (y * pitch);
+
+ for(uint32 yy=0; yy<height; yy++)
+ {
+ for(uint32 xx=0; xx<width; xx++)
+ {
+ if (alpha == NULL)
+ {
+ if (*bitmap && x + xx < pitch) // NOTE: Still doesn't clip the Y val...
+ *(screen + address + xx + (yy * pitch)) = *bitmap;
+ }
+ else
+ {
+ uint8 trans = *alpha;
+ uint32 color = *bitmap;
+ uint32 existingColor = *(screen + address + xx + (yy * pitch));
+
+ uint8 eRed = existingColor & 0xFF,
+ eGreen = (existingColor >> 8) & 0xFF,
+ eBlue = (existingColor >> 16) & 0xFF,
+
+ nRed = color & 0xFF,
+ nGreen = (color >> 8) & 0xFF,
+ nBlue = (color >> 16) & 0xFF;
+
+ uint8 invTrans = 255 - trans;
+ uint32 bRed = (eRed * trans + nRed * invTrans) / 255;
+ uint32 bGreen = (eGreen * trans + nGreen * invTrans) / 255;
+ uint32 bBlue = (eBlue * trans + nBlue * invTrans) / 255;
+
+ uint32 blendedColor = 0xFF000000 | bRed | (bGreen << 8) | (bBlue << 16);
+
+ *(screen + address + xx + (yy * pitch)) = blendedColor;
+
+ alpha++;
+ }
+
+ bitmap++;
+ }
+ }
+}*/
+void DrawTransparentBitmapDeprecated(uint32 * screen, uint32 x, uint32 y, uint32 * bitmap)
+{
+ uint32 width = bitmap[0], height = bitmap[1];
+ bitmap += 2;
+
+ uint32 pitch = sdlemuGetOverlayWidthInPixels();//GetSDLScreenWidthInPixels();
+ uint32 address = x + (y * pitch);
+
+ for(uint32 yy=0; yy<height; yy++)
+ {
+ for(uint32 xx=0; xx<width; xx++)
+ {
+ uint32 color = *bitmap;
+ uint32 blendedColor = color;
+ uint32 existingColor = *(screen + address + xx + (yy * pitch));
+
+ if (existingColor >> 24 != 0x00) // Pixel needs blending
+ {
+ uint8 trans = color >> 24;
+ uint8 invTrans = trans ^ 0xFF;//255 - trans;
+
+ uint8 eRed = existingColor & 0xFF,
+ eGreen = (existingColor >> 8) & 0xFF,
+ eBlue = (existingColor >> 16) & 0xFF,
+
+ nRed = color & 0xFF,
+ nGreen = (color >> 8) & 0xFF,
+ nBlue = (color >> 16) & 0xFF;
+
+ uint32 bRed = (eRed * invTrans + nRed * trans) / 255;
+ uint32 bGreen = (eGreen * invTrans + nGreen * trans) / 255;
+ uint32 bBlue = (eBlue * invTrans + nBlue * trans) / 255;
+
+ blendedColor = 0xFF000000 | bRed | (bGreen << 8) | (bBlue << 16);
+ }
+
+ *(screen + address + xx + (yy * pitch)) = blendedColor;
+ bitmap++;
+ }
+ }
+}
+
+void DrawTransparentBitmap(uint32 * screen, uint32 x, uint32 y, const void * bitmap)
+{
+ uint32 pitch = sdlemuGetOverlayWidthInPixels();
+ uint32 address = x + (y * pitch);
+ uint32 count = 0;
+
+ for(uint32 yy=0; yy<((Bitmap *)bitmap)->height; yy++)
+ {
+ for(uint32 xx=0; xx<((Bitmap *)bitmap)->width; xx++)
+ {
+ uint32 color = ((uint32 *)((Bitmap *)bitmap)->pixelData)[count];
+ uint32 blendedColor = color;
+ uint32 existingColor = *(screen + address + xx + (yy * pitch));
+
+ if (existingColor >> 24 != 0x00) // Pixel needs blending
+ {
+ uint8 trans = color >> 24;
+ uint8 invTrans = trans ^ 0xFF;
+
+ uint8 eRed = existingColor & 0xFF,
+ eGreen = (existingColor >> 8) & 0xFF,
+ eBlue = (existingColor >> 16) & 0xFF,
+
+ nRed = color & 0xFF,
+ nGreen = (color >> 8) & 0xFF,
+ nBlue = (color >> 16) & 0xFF;
+
+ uint32 bRed = (eRed * invTrans + nRed * trans) / 255;
+ uint32 bGreen = (eGreen * invTrans + nGreen * trans) / 255;
+ uint32 bBlue = (eBlue * invTrans + nBlue * trans) / 255;
+
+// Instead of $FF, should use the alpha from the destination pixel as the final alpha value...
+ blendedColor = 0xFF000000 | bRed | (bGreen << 8) | (bBlue << 16);
+ }
+
+ *(screen + address + xx + (yy * pitch)) = blendedColor;
+ count++;
+ }
+ }
+}
+
+//
+// Draw a bitmap without using blending
+//
+void DrawBitmap(uint32 * screen, uint32 x, uint32 y, const void * bitmap)
+{
+ uint32 pitch = sdlemuGetOverlayWidthInPixels();
+ uint32 address = x + (y * pitch);
+ uint32 count = 0;
+
+ for(uint32 yy=0; yy<((Bitmap *)bitmap)->height; yy++)
+ {
+ for(uint32 xx=0; xx<((Bitmap *)bitmap)->width; xx++)
+ {
+ *(screen + address + xx + (yy * pitch)) = ((uint32 *)((Bitmap *)bitmap)->pixelData)[count];
+ count++;
+ }
+ }
+}
+
+//
+// Fill a portion of the screen with the passed in color
+//
+void FillScreenRectangle(uint32 * screen, uint32 x, uint32 y, uint32 w, uint32 h, uint32 color)
+//void ClearScreenRectangle(uint32 * screen, uint32 x, uint32 y, uint32 w, uint32 h)
+{
+ uint32 pitch = sdlemuGetOverlayWidthInPixels();
+ uint32 address = x + (y * pitch);
+
+ for(uint32 yy=0; yy<h; yy++)
+ for(uint32 xx=0; xx<w; xx++)
+ *(screen + address + xx + (yy * pitch)) = color;
+}
+
+
+//
+// GUI stuff--it's not crunchy, it's GUI! ;-)
+//
+
+void InitGUI(void)
+{
+ SDL_ShowCursor(SDL_DISABLE);
+ SDL_GetMouseState(&mouseX, &mouseY);
+}
+
+void GUIDone(void)
+{
+}
+
+//
+// GUI main loop
+//
+//bool GUIMain(void)
+bool GUIMain(char * filename)
+{
+WriteLog("GUI: Inside GUIMain...\n");
+
+ uint32 pointerBGSave[6 * 8 + 2];
+ pointerBGSave[0] = 6;
+ pointerBGSave[1] = 8;
+
+// Need to set things up so that it loads and runs a file if given on the command line. !!! FIX !!! [DONE]
+// extern uint32 * backbuffer;
+// bool done = false;