-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpc-uefi.h
96 lines (84 loc) · 2.93 KB
/
pc-uefi.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <uefi.h>
struct pdraw
{
int pixel_size;
int x_max;
int y_max;
efi_gop_t *gop;
};
void print_gop_info()
{
efi_status_t status;
efi_guid_t gopGuid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
efi_gop_t *gop = NULL;
status = BS->LocateProtocol(&gopGuid, NULL, (void**)&gop);
if(!EFI_ERROR(status) && gop) {
printf("Framebuffer address: %x, size: %d, width: %d, height: %d, pixelsperline %d\n",
gop->Mode->FrameBufferBase,
gop->Mode->FrameBufferSize,
gop->Mode->Information->HorizontalResolution,
gop->Mode->Information->VerticalResolution,
gop->Mode->Information->PixelsPerScanLine);
}
}
struct pdraw setup_graphics(int pixel_size)
{
struct pdraw p;
efi_status_t status;
efi_guid_t gopGuid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
efi_gop_t *gop = NULL;
/* set video mode */
status = BS->LocateProtocol(&gopGuid, NULL, (void**)&gop);
printf("test\n");
/* construct pdraw struct */
p.pixel_size = pixel_size;
int screen_width = gop->Mode->Information->HorizontalResolution;
int screen_height = gop->Mode->Information->VerticalResolution;
p.x_max = screen_width / pixel_size;
if (screen_width % pixel_size != 0) {
printf("pdraw: WARNING: Pixel size does not divide screen's horizontal \
resolution: right margin will be visible\n");
}
p.y_max = screen_height / pixel_size;
if (screen_height % pixel_size != 0) {
printf("pdraw: WARNING: Pixel size does not divide screen's vertical \
resolution: bottom margin will be visible\n");
}
p.gop = gop;
// printf("pixel size: %d. x_max: %d. y_max %d\n", p.pixel_size, p.x_max, p.y_max);
// printf("%x %d", p.gop->Mode->FrameBufferBase, p.gop->Mode->Information->PixelsPerScanLine);
// sleep(10);
// printf("Pixel format: %x\n", gop->Mode->Information->PixelFormat);
// sleep(5);
if(!EFI_ERROR(status) && gop) {
status = gop->SetMode(gop, 0);
ST->ConOut->Reset(ST->ConOut, 0);
ST->StdErr->Reset(ST->StdErr, 0);
if(EFI_ERROR(status)) {
printf("unable to set video mode\n");
sleep(5);
exit(1);
}
} else {
printf("unable to get graphics output protocol\n");
sleep(5);
exit(1);
}
return p;
}
void pixel_on(struct pdraw p, int y, int x, uint32_t color)
{
// if (x >= 0 && x < p.x_max && y >= 0 && y < p.y_max) {
int pix_per_scanl = p.gop->Mode->Information->PixelsPerScanLine;
uint32_t *ppix_base = (uint32_t*)(p.gop->Mode->FrameBufferBase + 4 * pix_per_scanl * p.pixel_size * y + 4 * p.pixel_size * x);
for (int y_i=0; y_i<p.pixel_size; ++y_i) {
for (int x_i=0; x_i<p.pixel_size; ++x_i) {
*((uint32_t*)(ppix_base + pix_per_scanl * y_i + x_i)) = color;
}
}
// }
}
void pixel_off(struct pdraw p, int y, int x)
{
pixel_on(p, y, x, 0x00000000);
}