* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-
-#include <freeldr.h>
-#include <ui.h>
-#include "tui.h"
-#include "keycodes.h"
-#include <rtl.h>
-#include <mm.h>
-#include <debug.h>
-#include <inifile.h>
-#include <version.h>
-#include <video.h>
-#include <machine.h>
+#include <freeldr.h>
PVOID TextVideoBuffer = NULL;
-BOOL TuiInitialize(VOID)
+/*
+ * printf() - prints formatted text to stdout
+ * originally from GRUB
+ */
+int TuiPrintf(const char *format, ... )
+{
+ va_list ap;
+ va_start(ap,format);
+ char c, *ptr, str[16];
+
+ while ((c = *(format++)))
+ {
+ if (c != '%')
+ {
+ MachConsPutChar(c);
+ }
+ else
+ {
+ switch (c = *(format++))
+ {
+ case 'd': case 'u': case 'x':
+ if (c == 'x')
+ _itoa(va_arg(ap, unsigned long), str, 16);
+ else
+ _itoa(va_arg(ap, unsigned long), str, 10);
+
+ ptr = str;
+
+ while (*ptr)
+ {
+ MachConsPutChar(*(ptr++));
+ }
+ break;
+
+ case 'c': MachConsPutChar((va_arg(ap,int))&0xff); break;
+
+ case 's':
+ ptr = va_arg(ap,char *);
+
+ while ((c = *(ptr++)))
+ {
+ MachConsPutChar(c);
+ }
+ break;
+ case '%':
+ MachConsPutChar(c);
+ break;
+ default:
+ printf("\nprintf() invalid format specifier - %%%c\n", c);
+ break;
+ }
+ }
+ }
+
+ va_end(ap);
+
+ return 0;
+}
+
+BOOLEAN TuiInitialize(VOID)
{
MachVideoClearScreen(ATTR(COLOR_WHITE, COLOR_BLACK));
MachVideoHideShowTextCursor(FALSE);
ULONG i, j;
// Clip the area to the screen
- // FIXME: This code seems to have problems... Uncomment and view ;-)
- /*if ((Left >= UiScreenWidth) || (Top >= UiScreenHeight))
+ if ((Left >= UiScreenWidth) || (Top >= UiScreenHeight))
{
return;
}
- if ((Left + Right) >= UiScreenWidth)
+ if (Right >= UiScreenWidth)
{
- Right = UiScreenWidth - Left;
+ Right = UiScreenWidth - 1;
}
- if ((Top + Bottom) >= UiScreenHeight)
+ if (Bottom >= UiScreenHeight)
{
- Bottom = UiScreenHeight - Top;
- }*/
+ Bottom = UiScreenHeight - 1;
+ }
// Loop through each line and fill it in
for (i=Top; i<=Bottom; i++)
* DrawBox()
* This function assumes coordinates are zero-based
*/
-VOID TuiDrawBox(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, UCHAR VertStyle, UCHAR HorzStyle, BOOL Fill, BOOL Shadow, UCHAR Attr)
+VOID TuiDrawBox(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, UCHAR VertStyle, UCHAR HorzStyle, BOOLEAN Fill, BOOLEAN Shadow, UCHAR Attr)
{
UCHAR ULCorner, URCorner, LLCorner, LRCorner;
* DrawText()
* This function assumes coordinates are zero-based
*/
-VOID TuiDrawText(ULONG X, ULONG Y, PCHAR Text, UCHAR Attr)
+VOID TuiDrawText(ULONG X, ULONG Y, PCSTR Text, UCHAR Attr)
{
PUCHAR ScreenMemory = (PUCHAR)TextVideoBuffer;
ULONG i, j;
}
}
-VOID TuiDrawCenteredText(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, PCHAR TextString, UCHAR Attr)
+VOID TuiDrawCenteredText(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, PCSTR TextString, UCHAR Attr)
{
ULONG TextLength;
ULONG BoxWidth;
}
}
-VOID TuiDrawStatusText(PCHAR StatusText)
+VOID TuiDrawStatusText(PCSTR StatusText)
{
ULONG i;
CHAR DateString[40];
CHAR TimeString[40];
CHAR TempString[20];
- BOOL PMHour = FALSE;
+ BOOLEAN PMHour = FALSE;
+
+ /* Don't draw the time if this has been disabled */
+ if (!UiDrawTime) return;
MachRTCGetCurrentDateTime(&Year, &Month, &Day, &Hour, &Minute, &Second);
+ if (Year < 1 || 9999 < Year || Month < 1 || 12 < Month || Day < 1 ||
+ 31 < Day || 23 < Hour || 59 < Minute || 59 < Second)
+ {
+ /* This happens on QEmu sometimes. We just skip updating */
+ return;
+ }
// Get the month name
strcpy(DateString, UiMonthNames[Month - 1]);
// Get the day
- itoa(Day, TempString, 10);
+ _itoa(Day, TempString, 10);
// Get the day postfix
if (1 == Day || 21 == Day || 31 == Day)
{
strcat(DateString, " ");
// Get the year and add it to the date
- itoa(Year, TempString, 10);
+ _itoa(Year, TempString, 10);
strcat(DateString, TempString);
// Draw the date
{
Hour = 12;
}
- itoa(Hour, TempString, 10);
+ _itoa(Hour, TempString, 10);
strcpy(TimeString, " ");
strcat(TimeString, TempString);
strcat(TimeString, ":");
- itoa(Minute, TempString, 10);
+ _itoa(Minute, TempString, 10);
if (Minute < 10)
{
strcat(TimeString, "0");
}
strcat(TimeString, TempString);
strcat(TimeString, ":");
- itoa(Second, TempString, 10);
+ _itoa(Second, TempString, 10);
if (Second < 10)
{
strcat(TimeString, "0");
}
}
-VOID TuiMessageBox(PCHAR MessageText)
+VOID TuiMessageBox(PCSTR MessageText)
{
PVOID ScreenBuffer;
// Save the screen contents
- ScreenBuffer = MmAllocateMemory(UiScreenWidth * UiScreenHeight * 2);
+ ScreenBuffer = MmHeapAlloc(UiScreenWidth * UiScreenHeight * 2);
TuiSaveScreen(ScreenBuffer);
// Display the message box
// Restore the screen contents
TuiRestoreScreen(ScreenBuffer);
- MmFreeMemory(ScreenBuffer);
+ MmHeapFree(ScreenBuffer);
}
-VOID TuiMessageBoxCritical(PCHAR MessageText)
+VOID TuiMessageBoxCritical(PCSTR MessageText)
{
int width = 8;
- int height = 1;
+ unsigned int height = 1;
int curline = 0;
- int i , j, k;
+ int k;
+ size_t i , j;
int x1, x2, y1, y2;
char temp[260];
char key;
// Draw the box
TuiDrawBox(Left, Top, Right, Bottom, VERT, HORZ, TRUE, TRUE, ATTR(UiMenuFgColor, UiMenuBgColor));
- // Draw the "Loading..." text
- //TuiDrawText(70/2, Top+1, "Loading...", ATTR(UiTextColor, UiMenuBgColor));
+ //
+ // Draw the "Loading..." text
+ //
TuiDrawCenteredText(Left + 2, Top + 2, Right - 2, Top + 2, ProgressText, ATTR(UiTextColor, UiMenuBgColor));
// Draw the percent complete
TuiDrawText(Left+2+i, Top+2, "\xDB", ATTR(UiTextColor, UiMenuBgColor));
}
- // Draw the rest
+ // Draw the shadow
for (; i<ProgressBarWidth; i++)
{
TuiDrawText(Left+2+i, Top+2, "\xB2", ATTR(UiTextColor, UiMenuBgColor));
}
TuiUpdateDateTime();
-
VideoCopyOffScreenBufferToVRAM();
}
-UCHAR TuiTextToColor(PCHAR ColorText)
+UCHAR TuiTextToColor(PCSTR ColorText)
{
- if (stricmp(ColorText, "Black") == 0)
+ if (_stricmp(ColorText, "Black") == 0)
return COLOR_BLACK;
- else if (stricmp(ColorText, "Blue") == 0)
+ else if (_stricmp(ColorText, "Blue") == 0)
return COLOR_BLUE;
- else if (stricmp(ColorText, "Green") == 0)
+ else if (_stricmp(ColorText, "Green") == 0)
return COLOR_GREEN;
- else if (stricmp(ColorText, "Cyan") == 0)
+ else if (_stricmp(ColorText, "Cyan") == 0)
return COLOR_CYAN;
- else if (stricmp(ColorText, "Red") == 0)
+ else if (_stricmp(ColorText, "Red") == 0)
return COLOR_RED;
- else if (stricmp(ColorText, "Magenta") == 0)
+ else if (_stricmp(ColorText, "Magenta") == 0)
return COLOR_MAGENTA;
- else if (stricmp(ColorText, "Brown") == 0)
+ else if (_stricmp(ColorText, "Brown") == 0)
return COLOR_BROWN;
- else if (stricmp(ColorText, "Gray") == 0)
+ else if (_stricmp(ColorText, "Gray") == 0)
return COLOR_GRAY;
- else if (stricmp(ColorText, "DarkGray") == 0)
+ else if (_stricmp(ColorText, "DarkGray") == 0)
return COLOR_DARKGRAY;
- else if (stricmp(ColorText, "LightBlue") == 0)
+ else if (_stricmp(ColorText, "LightBlue") == 0)
return COLOR_LIGHTBLUE;
- else if (stricmp(ColorText, "LightGreen") == 0)
+ else if (_stricmp(ColorText, "LightGreen") == 0)
return COLOR_LIGHTGREEN;
- else if (stricmp(ColorText, "LightCyan") == 0)
+ else if (_stricmp(ColorText, "LightCyan") == 0)
return COLOR_LIGHTCYAN;
- else if (stricmp(ColorText, "LightRed") == 0)
+ else if (_stricmp(ColorText, "LightRed") == 0)
return COLOR_LIGHTRED;
- else if (stricmp(ColorText, "LightMagenta") == 0)
+ else if (_stricmp(ColorText, "LightMagenta") == 0)
return COLOR_LIGHTMAGENTA;
- else if (stricmp(ColorText, "Yellow") == 0)
+ else if (_stricmp(ColorText, "Yellow") == 0)
return COLOR_YELLOW;
- else if (stricmp(ColorText, "White") == 0)
+ else if (_stricmp(ColorText, "White") == 0)
return COLOR_WHITE;
return COLOR_BLACK;
}
-UCHAR TuiTextToFillStyle(PCHAR FillStyleText)
+UCHAR TuiTextToFillStyle(PCSTR FillStyleText)
{
- if (stricmp(FillStyleText, "Light") == 0)
+ if (_stricmp(FillStyleText, "Light") == 0)
{
return LIGHT_FILL;
}
- else if (stricmp(FillStyleText, "Medium") == 0)
+ else if (_stricmp(FillStyleText, "Medium") == 0)
{
return MEDIUM_FILL;
}
- else if (stricmp(FillStyleText, "Dark") == 0)
+ else if (_stricmp(FillStyleText, "Dark") == 0)
{
return DARK_FILL;
}
if (UiUseSpecialEffects && ! MachVideoIsPaletteFixed())
{
- TuiFadePalette = (PPALETTE_ENTRY)MmAllocateMemory(sizeof(PALETTE_ENTRY) * 64);
+ TuiFadePalette = (PPALETTE_ENTRY)MmHeapAlloc(sizeof(PALETTE_ENTRY) * 64);
if (TuiFadePalette != NULL)
{
if (UiUseSpecialEffects && ! MachVideoIsPaletteFixed() && TuiFadePalette != NULL)
{
VideoFadeIn(TuiFadePalette, 64);
- MmFreeMemory(TuiFadePalette);
+ MmHeapFree(TuiFadePalette);
}
}
if (UiUseSpecialEffects && ! MachVideoIsPaletteFixed())
{
- TuiFadePalette = (PPALETTE_ENTRY)MmAllocateMemory(sizeof(PALETTE_ENTRY) * 64);
+ TuiFadePalette = (PPALETTE_ENTRY)MmHeapAlloc(sizeof(PALETTE_ENTRY) * 64);
if (TuiFadePalette != NULL)
{
if (UiUseSpecialEffects && ! MachVideoIsPaletteFixed() && TuiFadePalette != NULL)
{
VideoRestorePaletteState(TuiFadePalette, 64);
- MmFreeMemory(TuiFadePalette);
+ MmHeapFree(TuiFadePalette);
}
}
-BOOL TuiEditBox(PCHAR MessageText, PCHAR EditTextBuffer, ULONG Length)
+BOOLEAN TuiEditBox(PCSTR MessageText, PCHAR EditTextBuffer, ULONG Length)
{
int width = 8;
- int height = 1;
+ unsigned int height = 1;
int curline = 0;
- int i , j, k;
+ int k;
+ size_t i , j;
int x1, x2, y1, y2;
char temp[260];
char key;
int EditBoxLine;
- int EditBoxStartX, EditBoxEndX;
+ ULONG EditBoxStartX, EditBoxEndX;
int EditBoxCursorX;
- int EditBoxTextCount;
+ unsigned int EditBoxTextCount;
int EditBoxTextDisplayIndex;
- BOOL ReturnCode;
+ BOOLEAN ReturnCode;
PVOID ScreenBuffer;
// Save the screen contents
- ScreenBuffer = MmAllocateMemory(UiScreenWidth * UiScreenHeight * 2);
+ ScreenBuffer = MmHeapAlloc(UiScreenWidth * UiScreenHeight * 2);
TuiSaveScreen(ScreenBuffer);
// Find the height
}
else
{
- beep();
+ MachBeep();
}
}
else // Add this key to the buffer
}
else
{
- beep();
+ MachBeep();
}
}
}
// Restore the screen contents
TuiRestoreScreen(ScreenBuffer);
- MmFreeMemory(ScreenBuffer);
+ MmHeapFree(ScreenBuffer);
return ReturnCode;
}
+
+const UIVTBL TuiVtbl =
+{
+ TuiInitialize,
+ TuiUnInitialize,
+ TuiDrawBackdrop,
+ TuiFillArea,
+ TuiDrawShadow,
+ TuiDrawBox,
+ TuiDrawText,
+ TuiDrawCenteredText,
+ TuiDrawStatusText,
+ TuiUpdateDateTime,
+ TuiMessageBox,
+ TuiMessageBoxCritical,
+ TuiDrawProgressBarCenter,
+ TuiDrawProgressBar,
+ TuiEditBox,
+ TuiTextToColor,
+ TuiTextToFillStyle,
+ TuiFadeInBackdrop,
+ TuiFadeOut,
+ TuiDisplayMenu,
+ TuiDrawMenu,
+};