mirror of
https://gitlab.com/bztsrc/posix-uefi.git
synced 2024-12-29 05:55:31 +01:00
More examples
This commit is contained in:
parent
6a432a12fe
commit
dce7280340
12 changed files with 1863 additions and 0 deletions
4
examples/0A_bmpfont/Makefile
Normal file
4
examples/0A_bmpfont/Makefile
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
TARGET = bmpfont.efi
|
||||||
|
|
||||||
|
#USE_GCC=1
|
||||||
|
include uefi/Makefile
|
120
examples/0A_bmpfont/bmpfont.c
Normal file
120
examples/0A_bmpfont/bmpfont.c
Normal file
|
@ -0,0 +1,120 @@
|
||||||
|
#include <uefi.h>
|
||||||
|
|
||||||
|
/* Scalable Screen Font (https://gitlab.com/bztsrc/scalable-font2) */
|
||||||
|
typedef struct {
|
||||||
|
unsigned char magic[4];
|
||||||
|
unsigned int size;
|
||||||
|
unsigned char type;
|
||||||
|
unsigned char features;
|
||||||
|
unsigned char width;
|
||||||
|
unsigned char height;
|
||||||
|
unsigned char baseline;
|
||||||
|
unsigned char underline;
|
||||||
|
unsigned short fragments_offs;
|
||||||
|
unsigned int characters_offs;
|
||||||
|
unsigned int ligature_offs;
|
||||||
|
unsigned int kerning_offs;
|
||||||
|
unsigned int cmap_offs;
|
||||||
|
} __attribute__((packed)) ssfn_font_t;
|
||||||
|
|
||||||
|
/* framebuffer properties */
|
||||||
|
unsigned int width, height, pitch;
|
||||||
|
unsigned char *lfb;
|
||||||
|
/* font to be used */
|
||||||
|
ssfn_font_t *font;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display string using a bitmap font without the SSFN library
|
||||||
|
*/
|
||||||
|
void printString(int x, int y, char *s)
|
||||||
|
{
|
||||||
|
unsigned char *ptr, *chr, *frg;
|
||||||
|
unsigned int c;
|
||||||
|
uintptr_t o, p;
|
||||||
|
int i, j, k, l, m, n;
|
||||||
|
while(*s) {
|
||||||
|
c = 0; s += mbtowc((wchar_t*)&c, (const char*)s, 4);
|
||||||
|
if(c == '\r') { x = 0; continue; } else
|
||||||
|
if(c == '\n') { x = 0; y += font->height; continue; }
|
||||||
|
for(ptr = (unsigned char*)font + font->characters_offs, chr = 0, i = 0; i < 0x110000; i++) {
|
||||||
|
if(ptr[0] == 0xFF) { i += 65535; ptr++; }
|
||||||
|
else if((ptr[0] & 0xC0) == 0xC0) { j = (((ptr[0] & 0x3F) << 8) | ptr[1]); i += j; ptr += 2; }
|
||||||
|
else if((ptr[0] & 0xC0) == 0x80) { j = (ptr[0] & 0x3F); i += j; ptr++; }
|
||||||
|
else { if((unsigned int)i == c) { chr = ptr; break; } ptr += 6 + ptr[1] * (ptr[0] & 0x40 ? 6 : 5); }
|
||||||
|
}
|
||||||
|
if(!chr) continue;
|
||||||
|
ptr = chr + 6; o = (uintptr_t)lfb + y * pitch + x * 4;
|
||||||
|
for(i = n = 0; i < chr[1]; i++, ptr += chr[0] & 0x40 ? 6 : 5) {
|
||||||
|
if(ptr[0] == 255 && ptr[1] == 255) continue;
|
||||||
|
frg = (unsigned char*)font + (chr[0] & 0x40 ? ((ptr[5] << 24) | (ptr[4] << 16) | (ptr[3] << 8) | ptr[2]) :
|
||||||
|
((ptr[4] << 16) | (ptr[3] << 8) | ptr[2]));
|
||||||
|
if((frg[0] & 0xE0) != 0x80) continue;
|
||||||
|
o += (int)(ptr[1] - n) * pitch; n = ptr[1];
|
||||||
|
k = ((frg[0] & 0x1F) + 1) << 3; j = frg[1] + 1; frg += 2;
|
||||||
|
for(m = 1; j; j--, n++, o += pitch)
|
||||||
|
for(p = o, l = 0; l < k; l++, p += 4, m <<= 1) {
|
||||||
|
if(m > 0x80) { frg++; m = 1; }
|
||||||
|
if(*frg & m) *((unsigned int*)p) = 0xFFFFFF;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
x += chr[4]+1; y += chr[5];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display bitmap fonts
|
||||||
|
*/
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
efi_status_t status;
|
||||||
|
efi_guid_t gopGuid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
|
||||||
|
efi_gop_t *gop = NULL;
|
||||||
|
efi_gop_mode_info_t *info = NULL;
|
||||||
|
uintn_t isiz = sizeof(efi_gop_mode_info_t), currentMode, i;
|
||||||
|
FILE *f;
|
||||||
|
long int size;
|
||||||
|
|
||||||
|
/* load font */
|
||||||
|
if((f = fopen("\\0A_bmpfont\\font.sfn", "r"))) {
|
||||||
|
fseek(f, 0, SEEK_END);
|
||||||
|
size = ftell(f);
|
||||||
|
fseek(f, 0, SEEK_SET);
|
||||||
|
font = (ssfn_font_t*)malloc(size + 1);
|
||||||
|
if(!font) {
|
||||||
|
fprintf(stderr, "unable to allocate memory\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
fread(font, size, 1, f);
|
||||||
|
fclose(f);
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "Unable to load font\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* set video mode */
|
||||||
|
status = BS->LocateProtocol(&gopGuid, NULL, (void**)&gop);
|
||||||
|
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)) {
|
||||||
|
fprintf(stderr, "unable to set video mode\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/* set up destination buffer */
|
||||||
|
lfb = (unsigned char*)gop->Mode->FrameBufferBase;
|
||||||
|
width = gop->Mode->Information->HorizontalResolution;
|
||||||
|
height = gop->Mode->Information->VerticalResolution;
|
||||||
|
pitch = sizeof(unsigned int) * gop->Mode->Information->PixelsPerScanLine;
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "unable to get graphics output protocol\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* display multilingual text */
|
||||||
|
printString(10, 10, "Hello 多种语言 Многоязычный többnyelvű World!");
|
||||||
|
|
||||||
|
/* free resources exit */
|
||||||
|
free(font);
|
||||||
|
return 0;
|
||||||
|
}
|
BIN
examples/0A_bmpfont/font.sfn
Normal file
BIN
examples/0A_bmpfont/font.sfn
Normal file
Binary file not shown.
BIN
examples/0A_bmpfont/screenshot.png
Normal file
BIN
examples/0A_bmpfont/screenshot.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 928 B |
1
examples/0A_bmpfont/uefi
Symbolic link
1
examples/0A_bmpfont/uefi
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
../../uefi
|
4
examples/0B_vecfont/Makefile
Normal file
4
examples/0B_vecfont/Makefile
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
TARGET = vecfont.efi
|
||||||
|
|
||||||
|
#USE_GCC=1
|
||||||
|
include uefi/Makefile
|
BIN
examples/0B_vecfont/font.sfn
Normal file
BIN
examples/0B_vecfont/font.sfn
Normal file
Binary file not shown.
BIN
examples/0B_vecfont/screenshot.png
Normal file
BIN
examples/0B_vecfont/screenshot.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.4 KiB |
1641
examples/0B_vecfont/ssfn.h
Normal file
1641
examples/0B_vecfont/ssfn.h
Normal file
File diff suppressed because it is too large
Load diff
1
examples/0B_vecfont/uefi
Symbolic link
1
examples/0B_vecfont/uefi
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
../../uefi
|
89
examples/0B_vecfont/vecfont.c
Normal file
89
examples/0B_vecfont/vecfont.c
Normal file
|
@ -0,0 +1,89 @@
|
||||||
|
#include <uefi.h>
|
||||||
|
|
||||||
|
/* Scalable Screen Font (https://gitlab.com/bztsrc/scalable-font2) */
|
||||||
|
#define SSFN_IMPLEMENTATION /* get the normal renderer implementation */
|
||||||
|
#define SSFN_MAXLINES 8192 /* configure for static memory management */
|
||||||
|
#include "ssfn.h"
|
||||||
|
|
||||||
|
ssfn_buf_t dst = {0}; /* framebuffer properties */
|
||||||
|
ssfn_t ctx = {0}; /* renderer context */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display string using the SSFN library. This works with both bitmap and vector fonts
|
||||||
|
*/
|
||||||
|
void printString(int x, int y, char *s)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
dst.x = x; dst.y = y;
|
||||||
|
do {
|
||||||
|
if(*s == '\r') { dst.x = 0; ret = 1; } else
|
||||||
|
if(*s == '\n') { dst.x = 0; dst.y += ctx.size; ret = 1; } else
|
||||||
|
ret = ssfn_render(&ctx, &dst, s);
|
||||||
|
s += ret;
|
||||||
|
} while(ret > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display vector fonts
|
||||||
|
*/
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
efi_status_t status;
|
||||||
|
efi_guid_t gopGuid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
|
||||||
|
efi_gop_t *gop = NULL;
|
||||||
|
efi_gop_mode_info_t *info = NULL;
|
||||||
|
uintn_t isiz = sizeof(efi_gop_mode_info_t), currentMode, i;
|
||||||
|
FILE *f;
|
||||||
|
ssfn_font_t *font;
|
||||||
|
long int size;
|
||||||
|
|
||||||
|
/* load font */
|
||||||
|
if((f = fopen("\\0B_vecfont\\font.sfn", "r"))) {
|
||||||
|
fseek(f, 0, SEEK_END);
|
||||||
|
size = ftell(f);
|
||||||
|
fseek(f, 0, SEEK_SET);
|
||||||
|
font = (ssfn_font_t*)malloc(size + 1);
|
||||||
|
if(!font) {
|
||||||
|
fprintf(stderr, "unable to allocate memory\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
fread(font, size, 1, f);
|
||||||
|
fclose(f);
|
||||||
|
ssfn_load(&ctx, font);
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "Unable to load font\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* set video mode */
|
||||||
|
status = BS->LocateProtocol(&gopGuid, NULL, (void**)&gop);
|
||||||
|
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)) {
|
||||||
|
fprintf(stderr, "unable to set video mode\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/* set up destination buffer */
|
||||||
|
dst.ptr = (unsigned char*)gop->Mode->FrameBufferBase;
|
||||||
|
dst.w = gop->Mode->Information->HorizontalResolution;
|
||||||
|
dst.h = gop->Mode->Information->VerticalResolution;
|
||||||
|
dst.p = sizeof(unsigned int) * gop->Mode->Information->PixelsPerScanLine;
|
||||||
|
dst.fg = 0xFFFFFFFF;
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "unable to get graphics output protocol\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* select typeface to use */
|
||||||
|
ssfn_select(&ctx, SSFN_FAMILY_ANY, NULL, SSFN_STYLE_REGULAR | SSFN_STYLE_NOCACHE, 40);
|
||||||
|
|
||||||
|
/* display multilingual text */
|
||||||
|
printString(10, ctx.size, "Hello! Здравствуйте! Καλως ηρθες!");
|
||||||
|
|
||||||
|
/* free resources exit */
|
||||||
|
ssfn_free(&ctx);
|
||||||
|
free(font);
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -39,6 +39,8 @@ extern "C" {
|
||||||
#define USE_UTF8 1
|
#define USE_UTF8 1
|
||||||
|
|
||||||
/* get these from the compiler */
|
/* get these from the compiler */
|
||||||
|
#ifndef _STDINT_H
|
||||||
|
#define _STDINT_H
|
||||||
typedef char int8_t;
|
typedef char int8_t;
|
||||||
typedef unsigned char uint8_t;
|
typedef unsigned char uint8_t;
|
||||||
typedef short int16_t;
|
typedef short int16_t;
|
||||||
|
@ -54,6 +56,7 @@ typedef long long int64_t;
|
||||||
typedef unsigned long long uint64_t;
|
typedef unsigned long long uint64_t;
|
||||||
typedef unsigned long long uintptr_t;
|
typedef unsigned long long uintptr_t;
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
extern char c_assert1[sizeof(uint32_t) == 4 ? 1 : -1];
|
extern char c_assert1[sizeof(uint32_t) == 4 ? 1 : -1];
|
||||||
extern char c_assert2[sizeof(uint64_t) == 8 ? 1 : -1];
|
extern char c_assert2[sizeof(uint64_t) == 8 ? 1 : -1];
|
||||||
extern char c_assert3[sizeof(uintptr_t) == 8 ? 1 : -1];
|
extern char c_assert3[sizeof(uintptr_t) == 8 ? 1 : -1];
|
||||||
|
|
Loading…
Reference in a new issue