Skip to content

Commit 4fb7bd5

Browse files
[FREELDR:APPLETV] Use vidfb for the frame buffer
1 parent e011af0 commit 4fb7bd5

File tree

8 files changed

+136
-227
lines changed

8 files changed

+136
-227
lines changed

boot/freeldr/freeldr/appletv.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ list(APPEND APPLETVLDR_ARC_SOURCE
3737

3838
# extra stuff we need
3939
list(APPEND APPLETVLDR_ARC_SOURCE
40+
arch/vidfb.c
4041
arch/vgafont.c
4142
arch/drivers/hwide.c
4243
arch/i386/hwdisk.c

boot/freeldr/freeldr/arch/i386/appletv/appletvcons.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
* PROJECT: FreeLoader
33
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
44
* PURPOSE: Console routines for the original Apple TV
5-
* COPYRIGHT: Copyright 2023 Sylas Hollander ([email protected])
5+
* COPYRIGHT: Authors of xboxcons.c
6+
Copyright 2023 Sylas Hollander ([email protected])
67
*/
78

89
/* INCLUDES ******************************************************************/
910

1011
#include <freeldr.h>
12+
#include "../../vidfb.h"
1113

1214
/* GLOBALS *******************************************************************/
1315

@@ -28,7 +30,7 @@ AppleTVConsPutChar(int c)
2830
NeedScroll = (CurrentCursorY >= Height);
2931
if (NeedScroll)
3032
{
31-
AppleTVVideoScrollUp();
33+
VidFbScrollUp(CurrentAttr);
3234
--CurrentCursorY;
3335
}
3436

boot/freeldr/freeldr/arch/i386/appletv/appletvhw.c

Lines changed: 2 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@
88
/* INCLUDES ******************************************************************/
99

1010
#include <freeldr.h>
11+
#include "../../vidfb.h"
1112

1213
/* UEFI support */
1314
#include <Uefi.h>
1415
#include <Acpi.h>
15-
#include <GraphicsOutput.h>
16-
#include <drivers/bootvid/framebuf.h>
1716

1817
#include <debug.h>
1918
DBG_DEFAULT_CHANNEL(WARNING);
@@ -409,108 +408,6 @@ DetectAcpiBios(PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG *BusNumber)
409408
}
410409
}
411410

412-
static VOID
413-
DetectDisplayController(PCONFIGURATION_COMPONENT_DATA BusKey)
414-
{
415-
PCONFIGURATION_COMPONENT_DATA ControllerKey;
416-
PCM_PARTIAL_RESOURCE_LIST PartialResourceList;
417-
PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
418-
PCM_FRAMEBUF_DEVICE_DATA FramebufferData;
419-
ULONG Size;
420-
421-
PMACH_VIDEO Video = &BootArgs->Video;
422-
423-
TRACE("\nStructure sizes:\n"
424-
" sizeof(CM_PARTIAL_RESOURCE_LIST) = %lu\n"
425-
" sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) = %lu\n"
426-
" sizeof(CM_FRAMEBUF_DEVICE_DATA) = %lu\n\n",
427-
sizeof(CM_PARTIAL_RESOURCE_LIST),
428-
sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR),
429-
sizeof(CM_FRAMEBUF_DEVICE_DATA));
430-
431-
Size = sizeof(CM_PARTIAL_RESOURCE_LIST) +
432-
sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) +
433-
sizeof(CM_FRAMEBUF_DEVICE_DATA);
434-
PartialResourceList = FrLdrHeapAlloc(Size, TAG_HW_RESOURCE_LIST);
435-
if (PartialResourceList == NULL)
436-
{
437-
ERR("Failed to allocate resource descriptor\n");
438-
return;
439-
}
440-
441-
// Initialize resource descriptor
442-
RtlZeroMemory(PartialResourceList, Size);
443-
PartialResourceList->Version = ARC_VERSION;
444-
PartialResourceList->Revision = ARC_REVISION;
445-
PartialResourceList->Count = 2;
446-
447-
// Set Memory
448-
PartialDescriptor = &PartialResourceList->PartialDescriptors[0];
449-
PartialDescriptor->Type = CmResourceTypeMemory;
450-
PartialDescriptor->ShareDisposition = CmResourceShareDeviceExclusive;
451-
PartialDescriptor->Flags = CM_RESOURCE_MEMORY_READ_WRITE;
452-
PartialDescriptor->u.Memory.Start.QuadPart = Video->BaseAddress;
453-
PartialDescriptor->u.Memory.Length = (Video->Pitch * Video->Height);
454-
455-
// Set framebuffer-specific data
456-
PartialDescriptor = &PartialResourceList->PartialDescriptors[1];
457-
PartialDescriptor->Type = CmResourceTypeDeviceSpecific;
458-
PartialDescriptor->ShareDisposition = CmResourceShareUndetermined;
459-
PartialDescriptor->Flags = 0;
460-
PartialDescriptor->u.DeviceSpecificData.DataSize =
461-
sizeof(CM_FRAMEBUF_DEVICE_DATA);
462-
463-
// Get pointer to framebuffer-specific data
464-
FramebufferData = (PVOID)(PartialDescriptor + 1);
465-
RtlZeroMemory(FramebufferData, sizeof(*FramebufferData));
466-
FramebufferData->Version = 2;
467-
FramebufferData->Revision = 0;
468-
469-
FramebufferData->VideoClock = 0; // FIXME: Use EDID
470-
471-
// Horizontal and Vertical resolution in pixels
472-
FramebufferData->ScreenWidth = Video->Width;
473-
FramebufferData->ScreenHeight = Video->Height;
474-
475-
// Number of pixel elements per video memory line
476-
FramebufferData->PixelsPerScanLine = (Video->Pitch / 4);
477-
478-
//
479-
// TODO: Investigate display rotation!
480-
//
481-
// See OpenCorePkg OcConsoleLib/ConsoleGop.c
482-
// if ((mGop.Rotation == 90) || (mGop.Rotation == 270))
483-
if (FramebufferData->ScreenWidth < FramebufferData->ScreenHeight)
484-
{
485-
#define SWAP(x, y) { (x) ^= (y); (y) ^= (x); (x) ^= (y); }
486-
SWAP(FramebufferData->ScreenWidth, FramebufferData->ScreenHeight);
487-
FramebufferData->PixelsPerScanLine = FramebufferData->ScreenWidth;
488-
#undef SWAP
489-
}
490-
491-
// Physical format of the pixel
492-
// ASSERT(sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL) == 4);
493-
// On Apple systems this can just be hardcoded to PixelBlueGreenRedReserved8BitPerColor.
494-
FramebufferData->BitsPerPixel = (8 * sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
495-
*(EFI_PIXEL_BITMASK*)&FramebufferData->PixelInformation = EfiPixelMasks[PixelBlueGreenRedReserved8BitPerColor];
496-
497-
FldrCreateComponentKey(BusKey,
498-
ControllerClass,
499-
DisplayController,
500-
Output | ConsoleOut,
501-
0,
502-
0xFFFFFFFF,
503-
"Apple TV Framebuffer",
504-
PartialResourceList,
505-
Size,
506-
&ControllerKey);
507-
508-
// NOTE: Don't add a MonitorPeripheral for now...
509-
// We should use EDID data for it.
510-
511-
}
512-
513-
514411
static
515412
VOID
516413
DetectInternal(PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG *BusNumber)
@@ -550,7 +447,7 @@ DetectInternal(PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG *BusNumber)
550447
(*BusNumber)++;
551448

552449
// Detect devices that do not belong to "standard" buses
553-
DetectDisplayController(BusKey);
450+
DetectDisplayController(BusKey, "Apple TV Framebuffer");
554451

555452
//FIXME: Detect more devices
556453
}

boot/freeldr/freeldr/arch/i386/appletv/appletvvideo.c

Lines changed: 14 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
/* INCLUDES *******************************************************************/
99
#include <freeldr.h>
10+
#include "../../vidfb.h"
1011

1112
/* UEFI support */
1213
#include <Uefi.h>
@@ -24,156 +25,51 @@ UCHAR MachDefaultTextColor = COLOR_GRAY;
2425

2526
/* FUNCTIONS ******************************************************************/
2627

27-
28-
static ULONG
29-
AppleTVVideoAttrToSingleColor(UCHAR Attr)
30-
{
31-
UCHAR Intensity;
32-
Intensity = (0 == (Attr & 0x08) ? 127 : 255);
33-
34-
return 0xff000000 |
35-
(0 == (Attr & 0x04) ? 0 : (Intensity << 16)) |
36-
(0 == (Attr & 0x02) ? 0 : (Intensity << 8)) |
37-
(0 == (Attr & 0x01) ? 0 : Intensity);
38-
}
39-
40-
static VOID
41-
AppleTVVideoAttrToColors(UCHAR Attr, ULONG *FgColor, ULONG *BgColor)
42-
{
43-
*FgColor = AppleTVVideoAttrToSingleColor(Attr & 0xf);
44-
*BgColor = AppleTVVideoAttrToSingleColor((Attr >> 4) & 0xf);
45-
}
46-
47-
48-
static VOID
49-
AppleTVVideoClearScreenColor(ULONG Color, BOOLEAN FullScreen)
50-
{
51-
ULONG Delta;
52-
ULONG Line, Col;
53-
PULONG p;
54-
55-
PMACH_VIDEO Video = &BootArgs->Video;
56-
57-
Delta = (Video->Pitch + 3) & ~ 0x3;
58-
for (Line = 0; Line < Video->Height - (FullScreen ? 0 : 2 * TOP_BOTTOM_LINES); Line++)
59-
{
60-
p = (PULONG) ((char *) Video->BaseAddress + (Line + (FullScreen ? 0 : TOP_BOTTOM_LINES)) * Delta);
61-
for (Col = 0; Col < Video->Width; Col++)
62-
{
63-
*p++ = Color;
64-
}
65-
}
66-
}
67-
6828
VOID
6929
AppleTVVideoClearScreen(UCHAR Attr)
7030
{
71-
ULONG FgColor, BgColor;
72-
73-
AppleTVVideoAttrToColors(Attr, &FgColor, &BgColor);
74-
AppleTVVideoClearScreenColor(BgColor, FALSE);
75-
}
76-
77-
VOID
78-
AppleTVVideoOutputChar(UCHAR Char, unsigned X, unsigned Y, ULONG FgColor, ULONG BgColor)
79-
{
80-
PUCHAR FontPtr;
81-
PULONG Pixel;
82-
UCHAR Mask;
83-
unsigned Line;
84-
unsigned Col;
85-
ULONG Delta;
86-
87-
PMACH_VIDEO Video = &BootArgs->Video;
88-
89-
Delta = (Video->Pitch + 3) & ~ 0x3;
90-
FontPtr = BitmapFont8x16 + Char * 16;
91-
Pixel = (PULONG) ((char *) Video->BaseAddress +
92-
(Y * CHAR_HEIGHT + TOP_BOTTOM_LINES) * Delta + X * CHAR_WIDTH * 4);
93-
94-
for (Line = 0; Line < CHAR_HEIGHT; Line++)
95-
{
96-
Mask = 0x80;
97-
for (Col = 0; Col < CHAR_WIDTH; Col++)
98-
{
99-
Pixel[Col] = (0 != (FontPtr[Line] & Mask) ? FgColor : BgColor);
100-
Mask = Mask >> 1;
101-
}
102-
Pixel = (PULONG) ((char *) Pixel + Delta);
103-
}
31+
VidFbClearScreen(Attr);
10432
}
10533

10634
VOID
10735
AppleTVVideoPutChar(int Ch, UCHAR Attr, unsigned X, unsigned Y)
10836
{
109-
ULONG FgColor = 0;
110-
ULONG BgColor = 0;
111-
if (Ch != 0)
112-
{
113-
AppleTVVideoAttrToColors(Attr, &FgColor, &BgColor);
114-
AppleTVVideoOutputChar(Ch, X, Y, FgColor, BgColor);
115-
}
37+
VidFbPutChar(Ch, Attr, X, Y);
11638
}
11739

11840
VOID
11941
AppleTVVideoGetDisplaySize(PULONG Width, PULONG Height, PULONG Depth)
12042
{
121-
PMACH_VIDEO Video = &BootArgs->Video;
122-
123-
*Width = Video->Width / CHAR_WIDTH;
124-
*Height = (Video->Height - 2 * TOP_BOTTOM_LINES) / CHAR_HEIGHT;
125-
*Depth = 0;
43+
VidFbGetDisplaySize(Width, Height, Depth);
12644
}
12745

12846
ULONG
12947
AppleTVVideoGetBufferSize(VOID)
13048
{
131-
PMACH_VIDEO Video = &BootArgs->Video;
132-
133-
return ((Video->Height - 2 * TOP_BOTTOM_LINES) / CHAR_HEIGHT * (Video->Width / CHAR_WIDTH) * 2);
49+
return VidFbGetBufferSize();
13450
}
13551

13652
VOID
13753
AppleTVVideoCopyOffScreenBufferToVRAM(PVOID Buffer)
13854
{
139-
PMACH_VIDEO Video = &BootArgs->Video;
140-
PUCHAR OffScreenBuffer = (PUCHAR)Buffer;
141-
142-
ULONG Col, Line;
143-
for (Line = 0; Line < (Video->Height - 2 * TOP_BOTTOM_LINES) / CHAR_HEIGHT; Line++)
144-
{
145-
for (Col = 0; Col < Video->Width / CHAR_WIDTH; Col++)
146-
{
147-
AppleTVVideoPutChar(OffScreenBuffer[0], OffScreenBuffer[1], Col, Line);
148-
OffScreenBuffer += 2;
149-
}
150-
}
55+
VidFbCopyOffScreenBufferToVRAM(Buffer);
15156
}
15257

15358
VOID
154-
AppleTVVideoScrollUp(VOID)
59+
AppleTVInitializeVideo(VOID)
15560
{
15661
PMACH_VIDEO Video = &BootArgs->Video;
15762

158-
ULONG BgColor, Dummy;
159-
ULONG Delta;
160-
Delta = (Video->Pitch + 3) & ~ 0x3;
161-
ULONG PixelCount = Video->Width * CHAR_HEIGHT *
162-
(((Video->Height - 2 * TOP_BOTTOM_LINES) / CHAR_HEIGHT) - 1);
163-
PULONG Src = (PULONG)((PUCHAR)Video->BaseAddress + (CHAR_HEIGHT + TOP_BOTTOM_LINES) * Delta);
164-
PULONG Dst = (PULONG)((PUCHAR)Video->BaseAddress + TOP_BOTTOM_LINES * Delta);
165-
166-
AppleTVVideoAttrToColors(ATTR(COLOR_WHITE, COLOR_BLACK), &Dummy, &BgColor);
167-
168-
while (PixelCount--)
169-
*Dst++ = *Src++;
170-
171-
for (PixelCount = 0; PixelCount < Video->Width * CHAR_HEIGHT; PixelCount++)
172-
*Dst++ = BgColor;
63+
VidFbInitializeVideo(Video->BaseAddress,
64+
(Video->Pitch * Video->Height),
65+
Video->Width,
66+
Video->Height,
67+
(Video->Pitch / 4),
68+
Video->Depth);
17369
}
17470

17571
VIDEODISPLAYMODE
176-
AppleTVVideoSetDisplayMode(char *DisplayMode, BOOLEAN Init)
72+
AppleTVVideoSetDisplayMode(PCSTR DisplayMode, BOOLEAN Init)
17773
{
17874
// We only have one display mode
17975
return VideoTextMode;

boot/freeldr/freeldr/arch/i386/appletv/machappletv.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ AppleTVPrepareForReactOS(VOID)
2424
VOID
2525
MachInit(const char *CmdLine)
2626
{
27+
2728
if (BootArgs->Version != 1
2829
&& BootArgs->Revision != 4)
2930
{
@@ -66,6 +67,8 @@ MachInit(const char *CmdLine)
6667
MachVtbl.HwDetect = AppleTVHwDetect;
6768
MachVtbl.HwIdle = AppleTVHwIdle;
6869

70+
AppleTVInitializeVideo();
71+
6972
/*
7073
* If we are booting in text mode, enable screen debugging
7174
* Text mode can be enabled by holding Windows/Command-V or Command-S at startup

0 commit comments

Comments
 (0)