From 98c17d3120b66c6c9507474cb5c3db1ca7b36ed3 Mon Sep 17 00:00:00 2001 From: Dmitry Borisov Date: Sun, 10 May 2020 22:35:51 +0600 Subject: [PATCH] [FREELDR] Add vertical screen scrolling for Xbox with console mode (#2745) Also turn off debug messages to screen before setting up the CPU (To print a character to the screen on some ports the MMIO access should be executed, so it throws an exception). CORE-16216 --- .../freeldr/freeldr/arch/i386/pc98/machpc98.c | 1 + .../freeldr/freeldr/arch/i386/xbox/machxbox.c | 11 ++++++---- .../freeldr/freeldr/arch/i386/xbox/xboxcons.c | 18 +++++++++++++---- .../freeldr/arch/i386/xbox/xboxvideo.c | 20 ++++++++++++++++++- .../freeldr/include/arch/i386/machxbox.h | 1 + boot/freeldr/freeldr/include/debug.h | 1 + boot/freeldr/freeldr/lib/debug.c | 6 ++++++ 7 files changed, 49 insertions(+), 9 deletions(-) diff --git a/boot/freeldr/freeldr/arch/i386/pc98/machpc98.c b/boot/freeldr/freeldr/arch/i386/pc98/machpc98.c index ca94ea54976..38ddf378378 100644 --- a/boot/freeldr/freeldr/arch/i386/pc98/machpc98.c +++ b/boot/freeldr/freeldr/arch/i386/pc98/machpc98.c @@ -37,6 +37,7 @@ Pc98PrepareForReactOS(VOID) Pc98DiskPrepareForReactOS(); Pc98VideoPrepareForReactOS(); DiskStopFloppyMotor(); + DebugDisableScreenPort(); } ULONG diff --git a/boot/freeldr/freeldr/arch/i386/xbox/machxbox.c b/boot/freeldr/freeldr/arch/i386/xbox/machxbox.c index b1ed4c94be0..3735f18982b 100644 --- a/boot/freeldr/freeldr/arch/i386/xbox/machxbox.c +++ b/boot/freeldr/freeldr/arch/i386/xbox/machxbox.c @@ -277,10 +277,6 @@ MachInit(const char *CmdLine) /* Set LEDs to red before anything is initialized */ XboxSetLED("rrrr"); - /* Initialize our stuff */ - XboxMemInit(); - XboxVideoInit(); - /* Setup vtbl */ MachVtbl.ConsPutChar = XboxConsPutChar; MachVtbl.ConsKbHit = XboxConsKbHit; @@ -311,6 +307,10 @@ MachInit(const char *CmdLine) MachVtbl.HwDetect = XboxHwDetect; MachVtbl.HwIdle = XboxHwIdle; + /* Initialize our stuff */ + XboxMemInit(); + XboxVideoInit(); + /* Set LEDs to orange after init */ XboxSetLED("oooo"); @@ -324,6 +324,9 @@ XboxPrepareForReactOS(VOID) XboxVideoPrepareForReactOS(); XboxDiskInit(FALSE); DiskStopFloppyMotor(); + + /* Turn off debug messages to screen */ + DebugDisableScreenPort(); } /* EOF */ diff --git a/boot/freeldr/freeldr/arch/i386/xbox/xboxcons.c b/boot/freeldr/freeldr/arch/i386/xbox/xboxcons.c index 8baba25b5cc..ed5d55c5b09 100644 --- a/boot/freeldr/freeldr/arch/i386/xbox/xboxcons.c +++ b/boot/freeldr/freeldr/arch/i386/xbox/xboxcons.c @@ -25,7 +25,17 @@ static unsigned CurrentAttr = 0x0f; VOID XboxConsPutChar(int c) { - ULONG Width, Unused; + ULONG Width, Height, Unused; + BOOLEAN NeedScroll; + + XboxVideoGetDisplaySize(&Width, &Height, &Unused); + + NeedScroll = (CurrentCursorY >= Height); + if (NeedScroll) + { + XboxVideoScrollUp(); + --CurrentCursorY; + } if (c == '\r') { @@ -34,7 +44,9 @@ XboxConsPutChar(int c) else if (c == '\n') { CurrentCursorX = 0; - CurrentCursorY++; + + if (!NeedScroll) + ++CurrentCursorY; } else if (c == '\t') { @@ -46,13 +58,11 @@ XboxConsPutChar(int c) CurrentCursorX++; } - XboxVideoGetDisplaySize(&Width, &Unused, &Unused); if (CurrentCursorX >= Width) { CurrentCursorX = 0; CurrentCursorY++; } - // FIXME: Implement vertical screen scrolling if we are at the end of the screen. } BOOLEAN diff --git a/boot/freeldr/freeldr/arch/i386/xbox/xboxvideo.c b/boot/freeldr/freeldr/arch/i386/xbox/xboxvideo.c index 261f4550664..0d6e3b2c70b 100644 --- a/boot/freeldr/freeldr/arch/i386/xbox/xboxvideo.c +++ b/boot/freeldr/freeldr/arch/i386/xbox/xboxvideo.c @@ -20,8 +20,8 @@ */ #include -#include +#include DBG_DEFAULT_CHANNEL(UI); PVOID FrameBuffer; @@ -101,6 +101,24 @@ XboxVideoClearScreenColor(ULONG Color, BOOLEAN FullScreen) } } +VOID +XboxVideoScrollUp(VOID) +{ + ULONG BgColor, Dummy; + ULONG PixelCount = ScreenWidth * CHAR_HEIGHT * + (((ScreenHeight - 2 * TOP_BOTTOM_LINES) / CHAR_HEIGHT) - 1); + PULONG Src = (PULONG)((PUCHAR)FrameBuffer + (CHAR_HEIGHT + TOP_BOTTOM_LINES) * Delta); + PULONG Dst = (PULONG)((PUCHAR)FrameBuffer + TOP_BOTTOM_LINES * Delta); + + XboxVideoAttrToColors(ATTR(COLOR_WHITE, COLOR_BLACK), &Dummy, &BgColor); + + while (PixelCount--) + *Dst++ = *Src++; + + for (PixelCount = 0; PixelCount < ScreenWidth * CHAR_HEIGHT; PixelCount++) + *Dst++ = BgColor; +} + VOID XboxVideoClearScreen(UCHAR Attr) { diff --git a/boot/freeldr/freeldr/include/arch/i386/machxbox.h b/boot/freeldr/freeldr/include/arch/i386/machxbox.h index 3f41e848666..d4342de4a0f 100644 --- a/boot/freeldr/freeldr/include/arch/i386/machxbox.h +++ b/boot/freeldr/freeldr/include/arch/i386/machxbox.h @@ -69,6 +69,7 @@ VOID XboxVideoSetPaletteColor(UCHAR Color, UCHAR Red, UCHAR Green, UCHAR Blue); VOID XboxVideoGetPaletteColor(UCHAR Color, UCHAR* Red, UCHAR* Green, UCHAR* Blue); VOID XboxVideoSync(VOID); VOID XboxVideoPrepareForReactOS(VOID); +VOID XboxVideoScrollUp(VOID); VOID XboxPrepareForReactOS(VOID); VOID XboxMemInit(VOID); diff --git a/boot/freeldr/freeldr/include/debug.h b/boot/freeldr/freeldr/include/debug.h index 1862220fb82..3ab9392b28e 100644 --- a/boot/freeldr/freeldr/include/debug.h +++ b/boot/freeldr/freeldr/include/debug.h @@ -44,6 +44,7 @@ ULONG DbgPrint(const char *Format, ...); VOID DbgPrint2(ULONG Mask, ULONG Level, const char *File, ULONG Line, char *Format, ...); VOID DebugDumpBuffer(ULONG Mask, PVOID Buffer, ULONG Length); + VOID DebugDisableScreenPort(); VOID DbgParseDebugChannels(PCHAR Value); #define ERR_LEVEL 0x1 diff --git a/boot/freeldr/freeldr/lib/debug.c b/boot/freeldr/freeldr/lib/debug.c index abc2545f7ea..e68df9af9cf 100644 --- a/boot/freeldr/freeldr/lib/debug.c +++ b/boot/freeldr/freeldr/lib/debug.c @@ -327,6 +327,12 @@ DebugDumpBuffer(ULONG Mask, PVOID Buffer, ULONG Length) } } +VOID +DebugDisableScreenPort(VOID) +{ + DebugPort &= ~SCREEN; +} + static BOOLEAN DbgAddDebugChannel(CHAR* channel, CHAR* level, CHAR op) {