Fast and reasonably complete (framebuffer) terminal emulator (Zig fork)

Compare changes

Choose any two refs to compare.

+2 -1
.gitignore
···
*.d
-
*.o
+
*.o
+
.zig-cache
+4 -4
README.md
···
To quickly set up and use a framebuffer Flanterm instance, it is possible to
use the `flanterm_fb_init()` function as such:
```c
-
#include <flanterm/flanterm.h>
-
#include <flanterm/backends/fb.h>
+
#include <flanterm.h>
+
#include <flanterm_backends/fb.h>
struct flanterm_context *ft_ctx = flanterm_fb_init(
NULL,
···
Where `framebuffer_ptr, width, height, pitch` and `{red,green,blue}_mask_{size,shift}`
represent the corresponding info about the framebuffer to use for this given instance.
-
The meaning of the other arguments can be found in `backends/fb.h`.
+
The meaning of the other arguments can be found in `flanterm_backends/fb.h`.
To then print to the terminal instance, simply use the `flanterm_write()`
function on the given instance. For example:
```c
-
#include <flanterm/flanterm.h>
+
#include <flanterm.h>
const char msg[] = "Hello world\n";
+17
README.zig.md
···
+
# Flanterm
+
Adapted from [https://codeberg.org/Mintsuki/Flanterm](https://codeberg.org/Mintsuki/Flanterm)
+
for Zig. Read the C code and original README for more information.
+
+
## Usage
+
First, add the package to your build.zig.zon:
+
`zig fetch --save git+https://tangled.sh/@sydney.blue/flanterm.zig#trunk`
+
Then, add the following to your build.zig:
+
```zig
+
const flanterm_dep = b.dependency("flanterm", .{});
+
const flanterm_mod = flanterm.module("flanterm");
+
exe.root_module.addImport("flanterm", flanterm_mod);
+
```
+
+
Now, you can import the `flanterm` module and use the helpers. More
+
bindings will be added as needed, feel free to contribute anything
+
you would find useful.
+17
build.zig
···
+
const std = @import("std");
+
+
pub fn build(b: *std.Build) void {
+
// Create the exported module
+
const mod = b.addModule("flanterm", .{
+
.root_source_file = b.path("src/root.zig"),
+
});
+
+
// Add the C source files and includes
+
mod.addIncludePath(b.path("src"));
+
mod.addCSourceFiles(.{
+
.files = &.{
+
"src/flanterm.c",
+
"src/flanterm_backends/fb.c",
+
},
+
});
+
}
+15
build.zig.zon
···
+
.{
+
.name = .flanterm,
+
.version = "2.0.0",
+
.fingerprint = 0x5e517d869e9f7b42, // Changing this has security and trust implications.
+
.minimum_zig_version = "0.15.1",
+
.dependencies = .{},
+
.paths = .{
+
"build.zig",
+
"build.zig.zon",
+
"src",
+
"LICENSE",
+
"README.md",
+
".gitignore",
+
},
+
}
-1252
src/backends/fb.c
···
-
/* Copyright (C) 2022-2025 mintsuki and contributors.
-
*
-
* Redistribution and use in source and binary forms, with or without
-
* modification, are permitted provided that the following conditions are met:
-
*
-
* 1. Redistributions of source code must retain the above copyright notice,
-
* this list of conditions and the following disclaimer.
-
*
-
* 2. Redistributions in binary form must reproduce the above copyright notice,
-
* this list of conditions and the following disclaimer in the documentation
-
* and/or other materials provided with the distribution.
-
*
-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
-
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-
* POSSIBILITY OF SUCH DAMAGE.
-
*/
-
-
#ifdef __cplusplus
-
#error "Please do not compile Flanterm as C++ code! Flanterm should be compiled as C99 or newer."
-
#endif
-
-
#ifndef __STDC_VERSION__
-
#error "Flanterm must be compiled as C99 or newer."
-
#endif
-
-
#if defined(_MSC_VER)
-
#define ALWAYS_INLINE __forceinline
-
#elif defined(__GNUC__) || defined(__clang__)
-
#define ALWAYS_INLINE __attribute__((always_inline)) inline
-
#else
-
#define ALWAYS_INLINE inline
-
#endif
-
-
#include <stdint.h>
-
#include <stddef.h>
-
#include <stdbool.h>
-
-
#define FLANTERM_IN_FLANTERM
-
-
#include "../flanterm.h"
-
#include "fb.h"
-
-
void *memset(void *, int, size_t);
-
void *memcpy(void *, const void *, size_t);
-
-
#ifndef FLANTERM_FB_DISABLE_BUMP_ALLOC
-
-
#ifndef FLANTERM_FB_BUMP_ALLOC_POOL_SIZE
-
#define FLANTERM_FB_BUMP_ALLOC_POOL_SIZE 873000
-
-
#define FLANTERM_FB_WIDTH_LIMIT 1920
-
#define FLANTERM_FB_HEIGHT_LIMIT 1200
-
#endif
-
-
static uint8_t bump_alloc_pool[FLANTERM_FB_BUMP_ALLOC_POOL_SIZE];
-
static size_t bump_alloc_ptr = 0;
-
-
static void *bump_alloc(size_t s) {
-
static bool base_offset_added = false;
-
if (!base_offset_added) {
-
if ((uintptr_t)bump_alloc_pool & 0xf) {
-
bump_alloc_ptr += 0x10 - ((uintptr_t)bump_alloc_pool & 0xf);
-
}
-
base_offset_added = true;
-
}
-
-
if ((s & 0xf) != 0) {
-
s += 0x10;
-
s &= ~(size_t)0xf;
-
}
-
-
size_t next_ptr = bump_alloc_ptr + s;
-
if (next_ptr > FLANTERM_FB_BUMP_ALLOC_POOL_SIZE) {
-
return NULL;
-
}
-
void *ret = &bump_alloc_pool[bump_alloc_ptr];
-
bump_alloc_ptr = next_ptr;
-
return ret;
-
}
-
-
static bool bump_allocated_instance = false;
-
-
#endif
-
-
// Builtin font originally taken from:
-
// https://github.com/viler-int10h/vga-text-mode-fonts/raw/master/FONTS/PC-OTHER/TOSH-SAT.F16
-
static const uint8_t builtin_font[] = {
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x42, 0x81, 0x81, 0xa5, 0xa5, 0x81,
-
0x81, 0xa5, 0x99, 0x81, 0x42, 0x3c, 0x00, 0x00, 0x00, 0x3c, 0x7e, 0xff,
-
0xff, 0xdb, 0xdb, 0xff, 0xff, 0xdb, 0xe7, 0xff, 0x7e, 0x3c, 0x00, 0x00,
-
0x00, 0x00, 0x00, 0x6c, 0xfe, 0xfe, 0xfe, 0x7c, 0x7c, 0x38, 0x38, 0x10,
-
0x10, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x38, 0x38, 0x7c, 0x7c, 0xfe,
-
0x7c, 0x7c, 0x38, 0x38, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18,
-
0x3c, 0x3c, 0xdb, 0xff, 0xff, 0xdb, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0x00, 0x18, 0x3c, 0x7e, 0xff, 0xff, 0xff, 0x66, 0x18, 0x18,
-
0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x78,
-
0x78, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
-
0xff, 0xff, 0xe7, 0xc3, 0xc3, 0xe7, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0xcc, 0x84, 0x84, 0xcc, 0x78, 0x00,
-
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc3, 0x99, 0xbd,
-
0xbd, 0x99, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x1e,
-
0x0e, 0x1e, 0x32, 0x78, 0xcc, 0xcc, 0xcc, 0x78, 0x00, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0x00, 0x78, 0xcc, 0xcc, 0xcc, 0x78, 0x30, 0xfc, 0x30, 0x30,
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x18, 0x1c, 0x1e, 0x16, 0x12,
-
0x10, 0x10, 0x70, 0xf0, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x30, 0x38, 0x2c,
-
0x26, 0x32, 0x3a, 0x2e, 0x26, 0x22, 0x62, 0xe2, 0xc6, 0x0e, 0x0c, 0x00,
-
0x00, 0x00, 0x00, 0x18, 0x18, 0xdb, 0x3c, 0xe7, 0x3c, 0xdb, 0x18, 0x18,
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xc0, 0xe0, 0xf8, 0xfe,
-
0xf8, 0xe0, 0xc0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
-
0x06, 0x0e, 0x3e, 0xfe, 0x3e, 0x0e, 0x06, 0x02, 0x00, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0x30, 0x78, 0xfc, 0x30, 0x30, 0x30, 0x30, 0x30, 0xfc, 0x78,
-
0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
-
0xcc, 0xcc, 0x00, 0xcc, 0xcc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xdb,
-
0xdb, 0xdb, 0xdb, 0x7b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0x7c, 0xc6, 0x60, 0x38, 0x6c, 0xc6, 0xc6, 0x6c, 0x38, 0x0c,
-
0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0xfe, 0xfe, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x78,
-
0xfc, 0x30, 0x30, 0x30, 0x30, 0x30, 0xfc, 0x78, 0x30, 0xfc, 0x00, 0x00,
-
0x00, 0x00, 0x30, 0x78, 0xfc, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
-
0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
-
0x30, 0x30, 0xfc, 0x78, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-
0x00, 0x18, 0x0c, 0xfe, 0xfe, 0x0c, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x60, 0xfe, 0xfe, 0x60, 0x30, 0x00,
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0,
-
0xc0, 0xc0, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-
0x00, 0x24, 0x66, 0xff, 0xff, 0x66, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x38, 0x38, 0x7c, 0x7c, 0xfe, 0xfe,
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xfe, 0x7c, 0x7c,
-
0x38, 0x38, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0x30, 0x78, 0x78, 0x78, 0x78, 0x30, 0x30, 0x30, 0x00, 0x30,
-
0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x00,
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6c, 0x6c,
-
0x6c, 0xfe, 0x6c, 0x6c, 0x6c, 0xfe, 0x6c, 0x6c, 0x6c, 0x00, 0x00, 0x00,
-
0x00, 0x18, 0x18, 0x7c, 0xc6, 0xc0, 0xc0, 0x7c, 0x06, 0x06, 0xc6, 0x7c,
-
0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xc6, 0x0c, 0x0c, 0x18, 0x38,
-
0x30, 0x60, 0x60, 0xc6, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x6c,
-
0x6c, 0x38, 0x30, 0x76, 0xde, 0xcc, 0xcc, 0xde, 0x76, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0x18, 0x18, 0x18, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x30, 0x60, 0x60, 0x60, 0x60,
-
0x60, 0x60, 0x60, 0x30, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x30,
-
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x30, 0x60, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x6c, 0x38, 0xfe, 0x38, 0x6c, 0x00, 0x00,
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x7e,
-
0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x30, 0x00, 0x00,
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x06,
-
0x0c, 0x0c, 0x18, 0x38, 0x30, 0x60, 0x60, 0xc0, 0xc0, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xd6, 0xd6, 0xd6, 0xc6, 0xc6, 0xc6,
-
0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x38, 0x78, 0x18, 0x18, 0x18,
-
0x18, 0x18, 0x18, 0x18, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6,
-
0x06, 0x06, 0x0c, 0x18, 0x30, 0x60, 0xc0, 0xc0, 0xfe, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0x7c, 0xc6, 0x06, 0x06, 0x3c, 0x06, 0x06, 0x06, 0x06, 0xc6,
-
0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x0c, 0x1c, 0x3c, 0x6c, 0xcc,
-
0xfe, 0x0c, 0x0c, 0x0c, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xc0,
-
0xc0, 0xc0, 0xfc, 0x06, 0x06, 0x06, 0x06, 0xc6, 0x7c, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0x3c, 0x60, 0xc0, 0xc0, 0xfc, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6,
-
0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xc6, 0x06, 0x06, 0x0c, 0x18,
-
0x30, 0x30, 0x30, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6,
-
0xc6, 0xc6, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0x7e, 0x06, 0x06, 0x06, 0x0c,
-
0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18,
-
0x18, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x18, 0x18, 0x30, 0x00, 0x00,
-
0x00, 0x00, 0x06, 0x0c, 0x18, 0x30, 0x60, 0xc0, 0x60, 0x30, 0x18, 0x0c,
-
0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x00,
-
0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x60,
-
0x30, 0x18, 0x0c, 0x06, 0x0c, 0x18, 0x30, 0x60, 0xc0, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0x7c, 0xc6, 0xc6, 0x06, 0x0c, 0x18, 0x30, 0x30, 0x00, 0x30,
-
0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xde, 0xde,
-
0xde, 0xde, 0xc0, 0xc0, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x6c,
-
0xc6, 0xc6, 0xc6, 0xc6, 0xfe, 0xc6, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0xfc, 0xc6, 0xc6, 0xc6, 0xfc, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6,
-
0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc0, 0xc0, 0xc0, 0xc0,
-
0xc0, 0xc0, 0xc0, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xcc,
-
0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xcc, 0xf8, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0xfe, 0xc0, 0xc0, 0xc0, 0xfc, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0,
-
0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xc0, 0xc0, 0xc0, 0xfc, 0xc0,
-
0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6,
-
0xc0, 0xc0, 0xc0, 0xde, 0xc6, 0xc6, 0xc6, 0xc6, 0x7e, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xfe, 0xc6, 0xc6, 0xc6, 0xc6,
-
0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x30, 0x30, 0x30, 0x30, 0x30,
-
0x30, 0x30, 0x30, 0x30, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x0c,
-
0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0xcc, 0xcc, 0x78, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0xc6, 0xc6, 0xcc, 0xd8, 0xf0, 0xe0, 0xf0, 0xd8, 0xcc, 0xc6,
-
0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0,
-
0xc0, 0xc0, 0xc0, 0xc0, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xc6,
-
0xee, 0xfe, 0xd6, 0xd6, 0xd6, 0xc6, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0xc6, 0xc6, 0xe6, 0xe6, 0xf6, 0xde, 0xce, 0xce, 0xc6, 0xc6,
-
0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6,
-
0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xc6,
-
0xc6, 0xc6, 0xc6, 0xfc, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xf6, 0xda,
-
0x6c, 0x06, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xc6, 0xc6, 0xc6, 0xc6, 0xfc,
-
0xd8, 0xcc, 0xcc, 0xc6, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6,
-
0xc0, 0x60, 0x30, 0x18, 0x0c, 0x06, 0x06, 0xc6, 0x7c, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0xff, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
-
0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6,
-
0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xc6,
-
0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x6c, 0x38, 0x10, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xd6, 0xd6, 0xd6, 0xd6, 0xfe, 0x6c,
-
0x6c, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xc6, 0xc6, 0x6c, 0x38, 0x38,
-
0x38, 0x6c, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcc, 0xcc,
-
0xcc, 0xcc, 0xcc, 0x78, 0x30, 0x30, 0x30, 0x30, 0x30, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0xfe, 0x06, 0x06, 0x0c, 0x18, 0x30, 0x60, 0xc0, 0xc0, 0xc0,
-
0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x60, 0x60, 0x60, 0x60, 0x60,
-
0x60, 0x60, 0x60, 0x60, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xc0,
-
0x60, 0x60, 0x30, 0x38, 0x18, 0x0c, 0x0c, 0x06, 0x06, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0x78, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
-
0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x38, 0x6c, 0xc6, 0x00, 0x00,
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00,
-
0x00, 0x00, 0x18, 0x18, 0x18, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0x06, 0x06,
-
0x7e, 0xc6, 0xc6, 0xc6, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xc0,
-
0xc0, 0xdc, 0xe6, 0xc6, 0xc6, 0xc6, 0xc6, 0xe6, 0xdc, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc0, 0xc0, 0xc0, 0xc0, 0xc6,
-
0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x06, 0x06, 0x76, 0xce, 0xc6,
-
0xc6, 0xc6, 0xc6, 0xce, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-
0x00, 0x7c, 0xc6, 0xc6, 0xfe, 0xc0, 0xc0, 0xc0, 0x7e, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0x1c, 0x36, 0x30, 0x30, 0xfc, 0x30, 0x30, 0x30, 0x30, 0x30,
-
0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0xce, 0xc6,
-
0xc6, 0xc6, 0xce, 0x76, 0x06, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0xc0, 0xc0,
-
0xc0, 0xdc, 0xe6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0x18, 0x00, 0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
-
0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x1e, 0x06, 0x06,
-
0x06, 0x06, 0x06, 0x06, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0xc0, 0xc0,
-
0xc0, 0xc6, 0xcc, 0xd8, 0xf0, 0xf0, 0xd8, 0xcc, 0xc6, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
-
0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xec, 0xfe, 0xd6,
-
0xd6, 0xd6, 0xd6, 0xc6, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-
0x00, 0xdc, 0xe6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6,
-
0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xdc, 0xe6, 0xc6,
-
0xc6, 0xc6, 0xe6, 0xdc, 0xc0, 0xc0, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00,
-
0x00, 0x76, 0xce, 0xc6, 0xc6, 0xc6, 0xce, 0x76, 0x06, 0x06, 0x06, 0x00,
-
0x00, 0x00, 0x00, 0x00, 0x00, 0xdc, 0xe6, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0,
-
0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc0,
-
0x70, 0x1c, 0x06, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30,
-
0x30, 0xfe, 0x30, 0x30, 0x30, 0x30, 0x30, 0x36, 0x1c, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6,
-
0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xc6, 0xc6,
-
0xc6, 0xc6, 0x6c, 0x38, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-
0x00, 0xc6, 0xc6, 0xd6, 0xd6, 0xd6, 0xd6, 0xfe, 0x6c, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xc6, 0x6c, 0x38, 0x38, 0x6c, 0xc6,
-
0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xc6, 0xc6,
-
0xc6, 0xc6, 0xce, 0x76, 0x06, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00,
-
0x00, 0xfe, 0x06, 0x0c, 0x18, 0x30, 0x60, 0xc0, 0xfe, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0x1c, 0x30, 0x30, 0x30, 0x30, 0xe0, 0x30, 0x30, 0x30, 0x30,
-
0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x30, 0x30, 0x30, 0x00,
-
0x30, 0x30, 0x30, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x30,
-
0x30, 0x30, 0x30, 0x1c, 0x30, 0x30, 0x30, 0x30, 0xe0, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0x00, 0x76, 0xdc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x38, 0x38, 0x6c,
-
0x6c, 0xc6, 0xc6, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x66,
-
0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x66, 0x3c, 0x18, 0xcc, 0x78, 0x00,
-
0x00, 0x00, 0x6c, 0x6c, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6,
-
0x7c, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x18, 0x30, 0x00, 0x7c, 0xc6, 0xc6,
-
0xfe, 0xc0, 0xc0, 0xc0, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x10, 0x38, 0x6c,
-
0x00, 0x7c, 0x06, 0x06, 0x7e, 0xc6, 0xc6, 0xc6, 0x7e, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0x6c, 0x6c, 0x00, 0x7c, 0x06, 0x06, 0x7e, 0xc6, 0xc6, 0xc6,
-
0x7e, 0x00, 0x00, 0x00, 0x00, 0x60, 0x30, 0x18, 0x00, 0x7c, 0x06, 0x06,
-
0x7e, 0xc6, 0xc6, 0xc6, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x38, 0x6c, 0x38,
-
0x00, 0x7c, 0x06, 0x06, 0x7e, 0xc6, 0xc6, 0xc6, 0x7e, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc0, 0xc0, 0xc0, 0xc0, 0xc6,
-
0x7c, 0x18, 0x0c, 0x38, 0x00, 0x10, 0x38, 0x6c, 0x00, 0x7c, 0xc6, 0xc6,
-
0xfe, 0xc0, 0xc0, 0xc0, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6c, 0x6c,
-
0x00, 0x7c, 0xc6, 0xc6, 0xfe, 0xc0, 0xc0, 0xc0, 0x7e, 0x00, 0x00, 0x00,
-
0x00, 0x60, 0x30, 0x18, 0x00, 0x7c, 0xc6, 0xc6, 0xfe, 0xc0, 0xc0, 0xc0,
-
0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6c, 0x6c, 0x00, 0x38, 0x18, 0x18,
-
0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x10, 0x38, 0x6c,
-
0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00,
-
0x00, 0x60, 0x30, 0x18, 0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
-
0x3c, 0x00, 0x00, 0x00, 0xc6, 0xc6, 0x10, 0x38, 0x6c, 0xc6, 0xc6, 0xc6,
-
0xfe, 0xc6, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00, 0x38, 0x6c, 0x38, 0x00,
-
0x38, 0x6c, 0xc6, 0xc6, 0xc6, 0xfe, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00,
-
0x18, 0x30, 0x60, 0x00, 0xfe, 0xc0, 0xc0, 0xfc, 0xc0, 0xc0, 0xc0, 0xc0,
-
0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xec, 0x36, 0x36,
-
0x76, 0xde, 0xd8, 0xd8, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x3c,
-
0x6c, 0xcc, 0xcc, 0xfe, 0xcc, 0xcc, 0xcc, 0xcc, 0xce, 0x00, 0x00, 0x00,
-
0x00, 0x10, 0x38, 0x6c, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6,
-
0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6c, 0x6c, 0x00, 0x7c, 0xc6, 0xc6,
-
0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x60, 0x30, 0x18,
-
0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00,
-
0x00, 0x10, 0x38, 0x6c, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6,
-
0x7c, 0x00, 0x00, 0x00, 0x00, 0x60, 0x30, 0x18, 0x00, 0xc6, 0xc6, 0xc6,
-
0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6c, 0x6c,
-
0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xce, 0x76, 0x06, 0xc6, 0x7c, 0x00,
-
0x6c, 0x6c, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6,
-
0x7c, 0x00, 0x00, 0x00, 0x6c, 0x6c, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6,
-
0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30,
-
0x30, 0x78, 0xcc, 0xc0, 0xc0, 0xcc, 0x78, 0x30, 0x30, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0x38, 0x6c, 0x60, 0x60, 0x60, 0xf8, 0x60, 0x60, 0x60, 0xe6,
-
0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc, 0x78, 0x30, 0xfc,
-
0x30, 0xfc, 0x30, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xcc,
-
0xcc, 0xf8, 0xc4, 0xcc, 0xde, 0xcc, 0xcc, 0xcc, 0xc6, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0x0e, 0x1b, 0x18, 0x18, 0x18, 0x7e, 0x18, 0x18, 0x18, 0x18,
-
0x18, 0xd8, 0x70, 0x00, 0x00, 0x0c, 0x18, 0x30, 0x00, 0x7c, 0x06, 0x06,
-
0x7e, 0xc6, 0xc6, 0xc6, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x18, 0x30,
-
0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00,
-
0x00, 0x0c, 0x18, 0x30, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6,
-
0x7c, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x18, 0x30, 0x00, 0xc6, 0xc6, 0xc6,
-
0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x76, 0xdc, 0x00,
-
0x00, 0xdc, 0xe6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00,
-
0x76, 0xdc, 0x00, 0xc6, 0xc6, 0xe6, 0xf6, 0xfe, 0xde, 0xce, 0xc6, 0xc6,
-
0xc6, 0x00, 0x00, 0x00, 0x00, 0x78, 0xd8, 0xd8, 0x6c, 0x00, 0xfc, 0x00,
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x6c, 0x6c,
-
0x38, 0x00, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0x18, 0x18, 0x00, 0x18, 0x18, 0x30, 0x60, 0xc0, 0xc6, 0xc6,
-
0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-
0xfe, 0xc0, 0xc0, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0x00, 0x00, 0xfe, 0x06, 0x06, 0x06, 0x00, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0xc0, 0xc2, 0xc6, 0xcc, 0xd8, 0x30, 0x60, 0xdc, 0x86, 0x0c,
-
0x18, 0x3e, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xc2, 0xc6, 0xcc, 0xd8, 0x30,
-
0x66, 0xce, 0x9e, 0x3e, 0x06, 0x06, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30,
-
0x00, 0x30, 0x30, 0x30, 0x78, 0x78, 0x78, 0x78, 0x30, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x6c, 0xd8, 0x6c, 0x36, 0x00, 0x00,
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd8, 0x6c, 0x36,
-
0x6c, 0xd8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x88, 0x22, 0x88,
-
0x22, 0x88, 0x22, 0x88, 0x22, 0x88, 0x22, 0x88, 0x22, 0x88, 0x22, 0x88,
-
0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa,
-
0x55, 0xaa, 0x55, 0xaa, 0xdd, 0x77, 0xdd, 0x77, 0xdd, 0x77, 0xdd, 0x77,
-
0xdd, 0x77, 0xdd, 0x77, 0xdd, 0x77, 0xdd, 0x77, 0x18, 0x18, 0x18, 0x18,
-
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
-
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xf8, 0xf8, 0x18, 0x18, 0x18,
-
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xf8, 0xf8, 0x18,
-
0x18, 0xf8, 0xf8, 0x18, 0x18, 0x18, 0x18, 0x18, 0x36, 0x36, 0x36, 0x36,
-
0x36, 0x36, 0x36, 0xf6, 0xf6, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xfe, 0x36, 0x36, 0x36,
-
0x36, 0x36, 0x36, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xf8, 0x18,
-
0x18, 0xf8, 0xf8, 0x18, 0x18, 0x18, 0x18, 0x18, 0x36, 0x36, 0x36, 0x36,
-
0x36, 0xf6, 0xf6, 0x06, 0x06, 0xf6, 0xf6, 0x36, 0x36, 0x36, 0x36, 0x36,
-
0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
-
0x36, 0x36, 0x36, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xfe, 0x06,
-
0x06, 0xf6, 0xf6, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
-
0x36, 0xf6, 0xf6, 0x06, 0x06, 0xfe, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00,
-
0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0xfe, 0xfe, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0xf8, 0xf8, 0x18,
-
0x18, 0xf8, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0x00, 0xf8, 0xf8, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
-
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1f, 0x1f, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xff,
-
0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0x00, 0xff, 0xff, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
-
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1f, 0x1f, 0x18, 0x18, 0x18,
-
0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff,
-
0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18,
-
0x18, 0x18, 0x18, 0xff, 0xff, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
-
0x18, 0x18, 0x18, 0x18, 0x18, 0x1f, 0x1f, 0x18, 0x18, 0x1f, 0x1f, 0x18,
-
0x18, 0x18, 0x18, 0x18, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x37,
-
0x37, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
-
0x36, 0x37, 0x37, 0x30, 0x30, 0x3f, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x3f, 0x30, 0x30, 0x37, 0x37, 0x36,
-
0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0xf7, 0xf7, 0x00,
-
0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-
0x00, 0xff, 0xff, 0x00, 0x00, 0xf7, 0xf7, 0x36, 0x36, 0x36, 0x36, 0x36,
-
0x36, 0x36, 0x36, 0x36, 0x36, 0x37, 0x37, 0x30, 0x30, 0x37, 0x37, 0x36,
-
0x36, 0x36, 0x36, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00,
-
0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x36, 0x36, 0x36,
-
0x36, 0xf7, 0xf7, 0x00, 0x00, 0xf7, 0xf7, 0x36, 0x36, 0x36, 0x36, 0x36,
-
0x18, 0x18, 0x18, 0x18, 0x18, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00,
-
0x00, 0x00, 0x00, 0x00, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0xff,
-
0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-
0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x18, 0x18, 0x18, 0x18, 0x18,
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x36, 0x36, 0x36,
-
0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x3f,
-
0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18,
-
0x18, 0x1f, 0x1f, 0x18, 0x18, 0x1f, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x1f, 0x18, 0x18, 0x1f, 0x1f, 0x18,
-
0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f,
-
0x3f, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
-
0x36, 0x36, 0x36, 0xff, 0xff, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
-
0x18, 0x18, 0x18, 0x18, 0x18, 0xff, 0xff, 0x18, 0x18, 0xff, 0xff, 0x18,
-
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xf8,
-
0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0x00, 0x1f, 0x1f, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
-
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
-
0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0,
-
0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
-
0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f,
-
0x0f, 0x0f, 0x0f, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-
0x00, 0x76, 0xd6, 0xdc, 0xc8, 0xc8, 0xdc, 0xd6, 0x76, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0x78, 0xcc, 0xcc, 0xcc, 0xd8, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
-
0xd8, 0xc0, 0xc0, 0x00, 0x00, 0x00, 0xfe, 0xc6, 0xc6, 0xc0, 0xc0, 0xc0,
-
0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-
0x00, 0x7e, 0xfe, 0x24, 0x24, 0x24, 0x24, 0x66, 0xc6, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0xfe, 0xfe, 0xc2, 0x60, 0x30, 0x18, 0x30, 0x60, 0xc2, 0xfe,
-
0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0xc8, 0xcc,
-
0xcc, 0xcc, 0xcc, 0xcc, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-
0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x76, 0x6c, 0x60, 0xc0, 0x00,
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0xfc, 0x98, 0x18, 0x18, 0x18, 0x18,
-
0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x30, 0x30, 0x78, 0xcc, 0xcc,
-
0xcc, 0x78, 0x30, 0x30, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x6c,
-
0xc6, 0xc6, 0xc6, 0xfe, 0xc6, 0xc6, 0xc6, 0x6c, 0x38, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0x38, 0x6c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x6c, 0x6c, 0x6c,
-
0xee, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0xcc, 0x60, 0x30, 0x78, 0xcc,
-
0xcc, 0xcc, 0xcc, 0xcc, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-
0x00, 0x76, 0xbb, 0x99, 0x99, 0xdd, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0x02, 0x06, 0x3c, 0x6c, 0xce, 0xd6, 0xd6, 0xe6, 0x6c, 0x78,
-
0xc0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x30, 0x60, 0xc0, 0xc0, 0xfe,
-
0xc0, 0xc0, 0x60, 0x30, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x6c,
-
0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0x00, 0x00, 0xfe, 0x00, 0x00, 0xfe, 0x00, 0x00, 0xfe, 0x00,
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0xfc,
-
0x30, 0x30, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-
0x60, 0x30, 0x18, 0x0c, 0x18, 0x30, 0x60, 0x00, 0xfc, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0x00, 0x00, 0x18, 0x30, 0x60, 0xc0, 0x60, 0x30, 0x18, 0x00,
-
0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x36, 0x36, 0x30, 0x30, 0x30,
-
0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x18, 0x18, 0x18, 0x18,
-
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xd8, 0xd8, 0x70, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x00, 0xfc, 0x00, 0x30, 0x30, 0x00,
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0xdc, 0x00,
-
0x76, 0xdc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0xcc, 0xcc,
-
0xcc, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30,
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x0c, 0x0c,
-
0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0xcc, 0x6c, 0x3c, 0x1c, 0x0c, 0x00, 0x00,
-
0x00, 0xd8, 0xec, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x00, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x6c, 0x0c, 0x18, 0x30, 0x60, 0x7c,
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-
0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-
0x00, 0x00, 0x00, 0x00
-
};
-
-
static ALWAYS_INLINE uint32_t convert_colour(struct flanterm_context *_ctx, uint32_t colour) {
-
struct flanterm_fb_context *ctx = (void *)_ctx;
-
uint32_t r = (colour >> 16) & 0xff;
-
uint32_t g = (colour >> 8) & 0xff;
-
uint32_t b = colour & 0xff;
-
return (r << ctx->red_mask_shift) | (g << ctx->green_mask_shift) | (b << ctx->blue_mask_shift);
-
}
-
-
static void flanterm_fb_save_state(struct flanterm_context *_ctx) {
-
struct flanterm_fb_context *ctx = (void *)_ctx;
-
ctx->saved_state_text_fg = ctx->text_fg;
-
ctx->saved_state_text_bg = ctx->text_bg;
-
ctx->saved_state_cursor_x = ctx->cursor_x;
-
ctx->saved_state_cursor_y = ctx->cursor_y;
-
}
-
-
static void flanterm_fb_restore_state(struct flanterm_context *_ctx) {
-
struct flanterm_fb_context *ctx = (void *)_ctx;
-
ctx->text_fg = ctx->saved_state_text_fg;
-
ctx->text_bg = ctx->saved_state_text_bg;
-
ctx->cursor_x = ctx->saved_state_cursor_x;
-
ctx->cursor_y = ctx->saved_state_cursor_y;
-
}
-
-
static void flanterm_fb_swap_palette(struct flanterm_context *_ctx) {
-
struct flanterm_fb_context *ctx = (void *)_ctx;
-
uint32_t tmp = ctx->text_bg;
-
ctx->text_bg = ctx->text_fg;
-
ctx->text_fg = tmp;
-
}
-
-
static void plot_char_scaled_canvas(struct flanterm_context *_ctx, struct flanterm_fb_char *c, size_t x, size_t y) {
-
struct flanterm_fb_context *ctx = (void *)_ctx;
-
-
if (x >= _ctx->cols || y >= _ctx->rows) {
-
return;
-
}
-
-
x = ctx->offset_x + x * ctx->glyph_width;
-
y = ctx->offset_y + y * ctx->glyph_height;
-
-
bool *glyph = &ctx->font_bool[c->c * ctx->font_height * ctx->font_width];
-
// naming: fx,fy for font coordinates, gx,gy for glyph coordinates
-
for (size_t gy = 0; gy < ctx->glyph_height; gy++) {
-
uint8_t fy = gy / ctx->font_scale_y;
-
volatile uint32_t *fb_line = ctx->framebuffer + x + (y + gy) * (ctx->pitch / 4);
-
uint32_t *canvas_line = ctx->canvas + x + (y + gy) * ctx->width;
-
bool *glyph_pointer = glyph + (fy * ctx->font_width);
-
for (size_t fx = 0; fx < ctx->font_width; fx++) {
-
for (size_t i = 0; i < ctx->font_scale_x; i++) {
-
size_t gx = ctx->font_scale_x * fx + i;
-
uint32_t bg = c->bg == 0xffffffff ? canvas_line[gx] : c->bg;
-
uint32_t fg = c->fg == 0xffffffff ? canvas_line[gx] : c->fg;
-
fb_line[gx] = *glyph_pointer ? fg : bg;
-
}
-
glyph_pointer++;
-
}
-
}
-
}
-
-
static void plot_char_scaled_uncanvas(struct flanterm_context *_ctx, struct flanterm_fb_char *c, size_t x, size_t y) {
-
struct flanterm_fb_context *ctx = (void *)_ctx;
-
-
if (x >= _ctx->cols || y >= _ctx->rows) {
-
return;
-
}
-
-
uint32_t default_bg = ctx->default_bg;
-
-
uint32_t bg = c->bg == 0xffffffff ? default_bg : c->bg;
-
uint32_t fg = c->fg == 0xffffffff ? default_bg : c->fg;
-
-
x = ctx->offset_x + x * ctx->glyph_width;
-
y = ctx->offset_y + y * ctx->glyph_height;
-
-
bool *glyph = &ctx->font_bool[c->c * ctx->font_height * ctx->font_width];
-
// naming: fx,fy for font coordinates, gx,gy for glyph coordinates
-
for (size_t gy = 0; gy < ctx->glyph_height; gy++) {
-
uint8_t fy = gy / ctx->font_scale_y;
-
volatile uint32_t *fb_line = ctx->framebuffer + x + (y + gy) * (ctx->pitch / 4);
-
bool *glyph_pointer = glyph + (fy * ctx->font_width);
-
for (size_t fx = 0; fx < ctx->font_width; fx++) {
-
for (size_t i = 0; i < ctx->font_scale_x; i++) {
-
size_t gx = ctx->font_scale_x * fx + i;
-
fb_line[gx] = *glyph_pointer ? fg : bg;
-
}
-
glyph_pointer++;
-
}
-
}
-
}
-
-
static void plot_char_unscaled_canvas(struct flanterm_context *_ctx, struct flanterm_fb_char *c, size_t x, size_t y) {
-
struct flanterm_fb_context *ctx = (void *)_ctx;
-
-
if (x >= _ctx->cols || y >= _ctx->rows) {
-
return;
-
}
-
-
x = ctx->offset_x + x * ctx->glyph_width;
-
y = ctx->offset_y + y * ctx->glyph_height;
-
-
bool *glyph = &ctx->font_bool[c->c * ctx->font_height * ctx->font_width];
-
// naming: fx,fy for font coordinates, gx,gy for glyph coordinates
-
for (size_t gy = 0; gy < ctx->glyph_height; gy++) {
-
volatile uint32_t *fb_line = ctx->framebuffer + x + (y + gy) * (ctx->pitch / 4);
-
uint32_t *canvas_line = ctx->canvas + x + (y + gy) * ctx->width;
-
bool *glyph_pointer = glyph + (gy * ctx->font_width);
-
for (size_t fx = 0; fx < ctx->font_width; fx++) {
-
uint32_t bg = c->bg == 0xffffffff ? canvas_line[fx] : c->bg;
-
uint32_t fg = c->fg == 0xffffffff ? canvas_line[fx] : c->fg;
-
fb_line[fx] = *(glyph_pointer++) ? fg : bg;
-
}
-
}
-
}
-
-
static void plot_char_unscaled_uncanvas(struct flanterm_context *_ctx, struct flanterm_fb_char *c, size_t x, size_t y) {
-
struct flanterm_fb_context *ctx = (void *)_ctx;
-
-
if (x >= _ctx->cols || y >= _ctx->rows) {
-
return;
-
}
-
-
uint32_t default_bg = ctx->default_bg;
-
-
uint32_t bg = c->bg == 0xffffffff ? default_bg : c->bg;
-
uint32_t fg = c->fg == 0xffffffff ? default_bg : c->fg;
-
-
x = ctx->offset_x + x * ctx->glyph_width;
-
y = ctx->offset_y + y * ctx->glyph_height;
-
-
bool *glyph = &ctx->font_bool[c->c * ctx->font_height * ctx->font_width];
-
// naming: fx,fy for font coordinates, gx,gy for glyph coordinates
-
for (size_t gy = 0; gy < ctx->glyph_height; gy++) {
-
volatile uint32_t *fb_line = ctx->framebuffer + x + (y + gy) * (ctx->pitch / 4);
-
bool *glyph_pointer = glyph + (gy * ctx->font_width);
-
for (size_t fx = 0; fx < ctx->font_width; fx++) {
-
fb_line[fx] = *(glyph_pointer++) ? fg : bg;
-
}
-
}
-
}
-
-
static inline bool compare_char(struct flanterm_fb_char *a, struct flanterm_fb_char *b) {
-
return !(a->c != b->c || a->bg != b->bg || a->fg != b->fg);
-
}
-
-
static void push_to_queue(struct flanterm_context *_ctx, struct flanterm_fb_char *c, size_t x, size_t y) {
-
struct flanterm_fb_context *ctx = (void *)_ctx;
-
-
if (x >= _ctx->cols || y >= _ctx->rows) {
-
return;
-
}
-
-
size_t i = y * _ctx->cols + x;
-
-
struct flanterm_fb_queue_item *q = ctx->map[i];
-
-
if (q == NULL) {
-
if (compare_char(&ctx->grid[i], c)) {
-
return;
-
}
-
q = &ctx->queue[ctx->queue_i++];
-
q->x = x;
-
q->y = y;
-
ctx->map[i] = q;
-
}
-
-
q->c = *c;
-
}
-
-
static void flanterm_fb_revscroll(struct flanterm_context *_ctx) {
-
struct flanterm_fb_context *ctx = (void *)_ctx;
-
-
for (size_t i = (_ctx->scroll_bottom_margin - 1) * _ctx->cols - 1;
-
i >= _ctx->scroll_top_margin * _ctx->cols; i--) {
-
if (i == (size_t)-1) {
-
break;
-
}
-
struct flanterm_fb_char *c;
-
struct flanterm_fb_queue_item *q = ctx->map[i];
-
if (q != NULL) {
-
c = &q->c;
-
} else {
-
c = &ctx->grid[i];
-
}
-
push_to_queue(_ctx, c, (i + _ctx->cols) % _ctx->cols, (i + _ctx->cols) / _ctx->cols);
-
}
-
-
// Clear the first line of the screen.
-
struct flanterm_fb_char empty;
-
empty.c = ' ';
-
empty.fg = ctx->text_fg;
-
empty.bg = ctx->text_bg;
-
for (size_t i = 0; i < _ctx->cols; i++) {
-
push_to_queue(_ctx, &empty, i, _ctx->scroll_top_margin);
-
}
-
}
-
-
static void flanterm_fb_scroll(struct flanterm_context *_ctx) {
-
struct flanterm_fb_context *ctx = (void *)_ctx;
-
-
for (size_t i = (_ctx->scroll_top_margin + 1) * _ctx->cols;
-
i < _ctx->scroll_bottom_margin * _ctx->cols; i++) {
-
struct flanterm_fb_char *c;
-
struct flanterm_fb_queue_item *q = ctx->map[i];
-
if (q != NULL) {
-
c = &q->c;
-
} else {
-
c = &ctx->grid[i];
-
}
-
push_to_queue(_ctx, c, (i - _ctx->cols) % _ctx->cols, (i - _ctx->cols) / _ctx->cols);
-
}
-
-
// Clear the last line of the screen.
-
struct flanterm_fb_char empty;
-
empty.c = ' ';
-
empty.fg = ctx->text_fg;
-
empty.bg = ctx->text_bg;
-
for (size_t i = 0; i < _ctx->cols; i++) {
-
push_to_queue(_ctx, &empty, i, _ctx->scroll_bottom_margin - 1);
-
}
-
}
-
-
static void flanterm_fb_clear(struct flanterm_context *_ctx, bool move) {
-
struct flanterm_fb_context *ctx = (void *)_ctx;
-
-
struct flanterm_fb_char empty;
-
empty.c = ' ';
-
empty.fg = ctx->text_fg;
-
empty.bg = ctx->text_bg;
-
for (size_t i = 0; i < _ctx->rows * _ctx->cols; i++) {
-
push_to_queue(_ctx, &empty, i % _ctx->cols, i / _ctx->cols);
-
}
-
-
if (move) {
-
ctx->cursor_x = 0;
-
ctx->cursor_y = 0;
-
}
-
}
-
-
static void flanterm_fb_set_cursor_pos(struct flanterm_context *_ctx, size_t x, size_t y) {
-
struct flanterm_fb_context *ctx = (void *)_ctx;
-
-
if (x >= _ctx->cols) {
-
if ((int)x < 0) {
-
x = 0;
-
} else {
-
x = _ctx->cols - 1;
-
}
-
}
-
if (y >= _ctx->rows) {
-
if ((int)y < 0) {
-
y = 0;
-
} else {
-
y = _ctx->rows - 1;
-
}
-
}
-
ctx->cursor_x = x;
-
ctx->cursor_y = y;
-
}
-
-
static void flanterm_fb_get_cursor_pos(struct flanterm_context *_ctx, size_t *x, size_t *y) {
-
struct flanterm_fb_context *ctx = (void *)_ctx;
-
-
*x = ctx->cursor_x >= _ctx->cols ? _ctx->cols - 1 : ctx->cursor_x;
-
*y = ctx->cursor_y >= _ctx->rows ? _ctx->rows - 1 : ctx->cursor_y;
-
}
-
-
static void flanterm_fb_move_character(struct flanterm_context *_ctx, size_t new_x, size_t new_y, size_t old_x, size_t old_y) {
-
struct flanterm_fb_context *ctx = (void *)_ctx;
-
-
if (old_x >= _ctx->cols || old_y >= _ctx->rows
-
|| new_x >= _ctx->cols || new_y >= _ctx->rows) {
-
return;
-
}
-
-
size_t i = old_x + old_y * _ctx->cols;
-
-
struct flanterm_fb_char *c;
-
struct flanterm_fb_queue_item *q = ctx->map[i];
-
if (q != NULL) {
-
c = &q->c;
-
} else {
-
c = &ctx->grid[i];
-
}
-
-
push_to_queue(_ctx, c, new_x, new_y);
-
}
-
-
static void flanterm_fb_set_text_fg(struct flanterm_context *_ctx, size_t fg) {
-
struct flanterm_fb_context *ctx = (void *)_ctx;
-
-
ctx->text_fg = ctx->ansi_colours[fg];
-
}
-
-
static void flanterm_fb_set_text_bg(struct flanterm_context *_ctx, size_t bg) {
-
struct flanterm_fb_context *ctx = (void *)_ctx;
-
-
ctx->text_bg = ctx->ansi_colours[bg];
-
}
-
-
static void flanterm_fb_set_text_fg_bright(struct flanterm_context *_ctx, size_t fg) {
-
struct flanterm_fb_context *ctx = (void *)_ctx;
-
-
ctx->text_fg = ctx->ansi_bright_colours[fg];
-
}
-
-
static void flanterm_fb_set_text_bg_bright(struct flanterm_context *_ctx, size_t bg) {
-
struct flanterm_fb_context *ctx = (void *)_ctx;
-
-
ctx->text_bg = ctx->ansi_bright_colours[bg];
-
}
-
-
static void flanterm_fb_set_text_fg_rgb(struct flanterm_context *_ctx, uint32_t fg) {
-
struct flanterm_fb_context *ctx = (void *)_ctx;
-
-
ctx->text_fg = convert_colour(_ctx, fg);
-
}
-
-
static void flanterm_fb_set_text_bg_rgb(struct flanterm_context *_ctx, uint32_t bg) {
-
struct flanterm_fb_context *ctx = (void *)_ctx;
-
-
ctx->text_bg = convert_colour(_ctx, bg);
-
}
-
-
static void flanterm_fb_set_text_fg_default(struct flanterm_context *_ctx) {
-
struct flanterm_fb_context *ctx = (void *)_ctx;
-
-
ctx->text_fg = ctx->default_fg;
-
}
-
-
static void flanterm_fb_set_text_bg_default(struct flanterm_context *_ctx) {
-
struct flanterm_fb_context *ctx = (void *)_ctx;
-
-
ctx->text_bg = 0xffffffff;
-
}
-
-
static void flanterm_fb_set_text_fg_default_bright(struct flanterm_context *_ctx) {
-
struct flanterm_fb_context *ctx = (void *)_ctx;
-
-
ctx->text_fg = ctx->default_fg_bright;
-
}
-
-
static void flanterm_fb_set_text_bg_default_bright(struct flanterm_context *_ctx) {
-
struct flanterm_fb_context *ctx = (void *)_ctx;
-
-
ctx->text_bg = ctx->default_bg_bright;
-
}
-
-
static void draw_cursor(struct flanterm_context *_ctx) {
-
struct flanterm_fb_context *ctx = (void *)_ctx;
-
-
if (ctx->cursor_x >= _ctx->cols || ctx->cursor_y >= _ctx->rows) {
-
return;
-
}
-
-
size_t i = ctx->cursor_x + ctx->cursor_y * _ctx->cols;
-
-
struct flanterm_fb_char c;
-
struct flanterm_fb_queue_item *q = ctx->map[i];
-
if (q != NULL) {
-
c = q->c;
-
} else {
-
c = ctx->grid[i];
-
}
-
uint32_t tmp = c.fg;
-
c.fg = c.bg;
-
c.bg = tmp;
-
ctx->plot_char(_ctx, &c, ctx->cursor_x, ctx->cursor_y);
-
if (q != NULL) {
-
ctx->grid[i] = q->c;
-
ctx->map[i] = NULL;
-
}
-
}
-
-
static void flanterm_fb_double_buffer_flush(struct flanterm_context *_ctx) {
-
struct flanterm_fb_context *ctx = (void *)_ctx;
-
-
if (_ctx->cursor_enabled) {
-
draw_cursor(_ctx);
-
}
-
-
for (size_t i = 0; i < ctx->queue_i; i++) {
-
struct flanterm_fb_queue_item *q = &ctx->queue[i];
-
size_t offset = q->y * _ctx->cols + q->x;
-
if (ctx->map[offset] == NULL) {
-
continue;
-
}
-
ctx->plot_char(_ctx, &q->c, q->x, q->y);
-
ctx->grid[offset] = q->c;
-
ctx->map[offset] = NULL;
-
}
-
-
if ((ctx->old_cursor_x != ctx->cursor_x || ctx->old_cursor_y != ctx->cursor_y) || _ctx->cursor_enabled == false) {
-
if (ctx->old_cursor_x < _ctx->cols && ctx->old_cursor_y < _ctx->rows) {
-
ctx->plot_char(_ctx, &ctx->grid[ctx->old_cursor_x + ctx->old_cursor_y * _ctx->cols], ctx->old_cursor_x, ctx->old_cursor_y);
-
}
-
}
-
-
ctx->old_cursor_x = ctx->cursor_x;
-
ctx->old_cursor_y = ctx->cursor_y;
-
-
ctx->queue_i = 0;
-
}
-
-
static void flanterm_fb_raw_putchar(struct flanterm_context *_ctx, uint8_t c) {
-
struct flanterm_fb_context *ctx = (void *)_ctx;
-
-
if (ctx->cursor_x >= _ctx->cols && (ctx->cursor_y < _ctx->scroll_bottom_margin - 1 || _ctx->scroll_enabled)) {
-
ctx->cursor_x = 0;
-
ctx->cursor_y++;
-
if (ctx->cursor_y == _ctx->scroll_bottom_margin) {
-
ctx->cursor_y--;
-
flanterm_fb_scroll(_ctx);
-
}
-
if (ctx->cursor_y >= _ctx->cols) {
-
ctx->cursor_y = _ctx->cols - 1;
-
}
-
}
-
-
struct flanterm_fb_char ch;
-
ch.c = c;
-
ch.fg = ctx->text_fg;
-
ch.bg = ctx->text_bg;
-
push_to_queue(_ctx, &ch, ctx->cursor_x++, ctx->cursor_y);
-
}
-
-
static void flanterm_fb_full_refresh(struct flanterm_context *_ctx) {
-
struct flanterm_fb_context *ctx = (void *)_ctx;
-
-
uint32_t default_bg = ctx->default_bg;
-
-
for (size_t y = 0; y < ctx->height; y++) {
-
for (size_t x = 0; x < ctx->width; x++) {
-
if (ctx->canvas != NULL) {
-
ctx->framebuffer[y * (ctx->pitch / sizeof(uint32_t)) + x] = ctx->canvas[y * ctx->width + x];
-
} else {
-
ctx->framebuffer[y * (ctx->pitch / sizeof(uint32_t)) + x] = default_bg;
-
}
-
}
-
}
-
-
for (size_t i = 0; i < (size_t)_ctx->rows * _ctx->cols; i++) {
-
size_t x = i % _ctx->cols;
-
size_t y = i / _ctx->cols;
-
-
ctx->plot_char(_ctx, &ctx->grid[i], x, y);
-
}
-
-
if (_ctx->cursor_enabled) {
-
draw_cursor(_ctx);
-
}
-
}
-
-
static void flanterm_fb_deinit(struct flanterm_context *_ctx, void (*_free)(void *, size_t)) {
-
struct flanterm_fb_context *ctx = (void *)_ctx;
-
-
if (_free == NULL) {
-
#ifndef FLANTERM_FB_DISABLE_BUMP_ALLOC
-
if (bump_allocated_instance == true) {
-
bump_alloc_ptr = 0;
-
bump_allocated_instance = false;
-
}
-
#endif
-
return;
-
}
-
-
_free(ctx->font_bits, ctx->font_bits_size);
-
_free(ctx->font_bool, ctx->font_bool_size);
-
_free(ctx->grid, ctx->grid_size);
-
_free(ctx->queue, ctx->queue_size);
-
_free(ctx->map, ctx->map_size);
-
-
if (ctx->canvas != NULL) {
-
_free(ctx->canvas, ctx->canvas_size);
-
}
-
-
_free(ctx, sizeof(struct flanterm_fb_context));
-
}
-
-
struct flanterm_context *flanterm_fb_init(
-
void *(*_malloc)(size_t),
-
void (*_free)(void *, size_t),
-
uint32_t *framebuffer, size_t width, size_t height, size_t pitch,
-
uint8_t red_mask_size, uint8_t red_mask_shift,
-
uint8_t green_mask_size, uint8_t green_mask_shift,
-
uint8_t blue_mask_size, uint8_t blue_mask_shift,
-
uint32_t *canvas,
-
uint32_t *ansi_colours, uint32_t *ansi_bright_colours,
-
uint32_t *default_bg, uint32_t *default_fg,
-
uint32_t *default_bg_bright, uint32_t *default_fg_bright,
-
void *font, size_t font_width, size_t font_height, size_t font_spacing,
-
size_t font_scale_x, size_t font_scale_y,
-
size_t margin
-
) {
-
if (font_scale_x == 0 || font_scale_y == 0) {
-
font_scale_x = 1;
-
font_scale_y = 1;
-
if (width >= (1920 + 1920 / 3) && height >= (1080 + 1080 / 3)) {
-
font_scale_x = 2;
-
font_scale_y = 2;
-
}
-
if (width >= (3840 + 3840 / 3) && height >= (2160 + 2160 / 3)) {
-
font_scale_x = 4;
-
font_scale_y = 4;
-
}
-
}
-
-
if (red_mask_size < 8 || red_mask_size != green_mask_size || red_mask_size != blue_mask_size) {
-
return NULL;
-
}
-
-
if (_malloc == NULL) {
-
#ifndef FLANTERM_FB_DISABLE_BUMP_ALLOC
-
if (bump_allocated_instance == true) {
-
return NULL;
-
}
-
_malloc = bump_alloc;
-
// Limit terminal size if needed
-
if (width > FLANTERM_FB_WIDTH_LIMIT || height > FLANTERM_FB_HEIGHT_LIMIT) {
-
size_t width_limit = width > FLANTERM_FB_WIDTH_LIMIT ? FLANTERM_FB_WIDTH_LIMIT : width;
-
size_t height_limit = height > FLANTERM_FB_HEIGHT_LIMIT ? FLANTERM_FB_HEIGHT_LIMIT : height;
-
-
framebuffer = (uint32_t *)((uintptr_t)framebuffer + ((((height / 2) - (height_limit / 2)) * pitch) + (((width / 2) - (width_limit / 2)) * 4)));
-
-
width = width_limit;
-
height = height_limit;
-
}
-
-
// Force disable canvas
-
canvas = NULL;
-
#else
-
return NULL;
-
#endif
-
}
-
-
struct flanterm_fb_context *ctx = NULL;
-
ctx = _malloc(sizeof(struct flanterm_fb_context));
-
if (ctx == NULL) {
-
goto fail;
-
}
-
-
struct flanterm_context *_ctx = (void *)ctx;
-
memset(ctx, 0, sizeof(struct flanterm_fb_context));
-
-
ctx->red_mask_size = red_mask_size;
-
ctx->red_mask_shift = red_mask_shift + (red_mask_size - 8);
-
ctx->green_mask_size = green_mask_size;
-
ctx->green_mask_shift = green_mask_shift + (green_mask_size - 8);
-
ctx->blue_mask_size = blue_mask_size;
-
ctx->blue_mask_shift = blue_mask_shift + (blue_mask_size - 8);
-
-
if (ansi_colours != NULL) {
-
for (size_t i = 0; i < 8; i++) {
-
ctx->ansi_colours[i] = convert_colour(_ctx, ansi_colours[i]);
-
}
-
} else {
-
ctx->ansi_colours[0] = convert_colour(_ctx, 0x00000000); // black
-
ctx->ansi_colours[1] = convert_colour(_ctx, 0x00aa0000); // red
-
ctx->ansi_colours[2] = convert_colour(_ctx, 0x0000aa00); // green
-
ctx->ansi_colours[3] = convert_colour(_ctx, 0x00aa5500); // brown
-
ctx->ansi_colours[4] = convert_colour(_ctx, 0x000000aa); // blue
-
ctx->ansi_colours[5] = convert_colour(_ctx, 0x00aa00aa); // magenta
-
ctx->ansi_colours[6] = convert_colour(_ctx, 0x0000aaaa); // cyan
-
ctx->ansi_colours[7] = convert_colour(_ctx, 0x00aaaaaa); // grey
-
}
-
-
if (ansi_bright_colours != NULL) {
-
for (size_t i = 0; i < 8; i++) {
-
ctx->ansi_bright_colours[i] = convert_colour(_ctx, ansi_bright_colours[i]);
-
}
-
} else {
-
ctx->ansi_bright_colours[0] = convert_colour(_ctx, 0x00555555); // black
-
ctx->ansi_bright_colours[1] = convert_colour(_ctx, 0x00ff5555); // red
-
ctx->ansi_bright_colours[2] = convert_colour(_ctx, 0x0055ff55); // green
-
ctx->ansi_bright_colours[3] = convert_colour(_ctx, 0x00ffff55); // brown
-
ctx->ansi_bright_colours[4] = convert_colour(_ctx, 0x005555ff); // blue
-
ctx->ansi_bright_colours[5] = convert_colour(_ctx, 0x00ff55ff); // magenta
-
ctx->ansi_bright_colours[6] = convert_colour(_ctx, 0x0055ffff); // cyan
-
ctx->ansi_bright_colours[7] = convert_colour(_ctx, 0x00ffffff); // grey
-
}
-
-
if (default_bg != NULL) {
-
ctx->default_bg = convert_colour(_ctx, *default_bg);
-
} else {
-
ctx->default_bg = 0x00000000; // background (black)
-
}
-
-
if (default_fg != NULL) {
-
ctx->default_fg = convert_colour(_ctx, *default_fg);
-
} else {
-
ctx->default_fg = convert_colour(_ctx, 0x00aaaaaa); // foreground (grey)
-
}
-
-
if (default_bg_bright != NULL) {
-
ctx->default_bg_bright = convert_colour(_ctx, *default_bg_bright);
-
} else {
-
ctx->default_bg_bright = convert_colour(_ctx, 0x00555555); // background (black)
-
}
-
-
if (default_fg_bright != NULL) {
-
ctx->default_fg_bright = convert_colour(_ctx, *default_fg_bright);
-
} else {
-
ctx->default_fg_bright = convert_colour(_ctx, 0x00ffffff); // foreground (grey)
-
}
-
-
ctx->text_fg = ctx->default_fg;
-
ctx->text_bg = 0xffffffff;
-
-
ctx->framebuffer = (void *)framebuffer;
-
ctx->width = width;
-
ctx->height = height;
-
ctx->pitch = pitch;
-
-
#define FONT_BYTES ((font_width * font_height * FLANTERM_FB_FONT_GLYPHS) / 8)
-
-
if (font != NULL) {
-
ctx->font_width = font_width;
-
ctx->font_height = font_height;
-
ctx->font_bits_size = FONT_BYTES;
-
ctx->font_bits = _malloc(ctx->font_bits_size);
-
if (ctx->font_bits == NULL) {
-
goto fail;
-
}
-
memcpy(ctx->font_bits, font, ctx->font_bits_size);
-
} else {
-
ctx->font_width = font_width = 8;
-
ctx->font_height = font_height = 16;
-
ctx->font_bits_size = FONT_BYTES;
-
font_spacing = 1;
-
ctx->font_bits = _malloc(ctx->font_bits_size);
-
if (ctx->font_bits == NULL) {
-
goto fail;
-
}
-
memcpy(ctx->font_bits, builtin_font, ctx->font_bits_size);
-
}
-
-
#undef FONT_BYTES
-
-
ctx->font_width += font_spacing;
-
-
ctx->font_bool_size = FLANTERM_FB_FONT_GLYPHS * font_height * ctx->font_width * sizeof(bool);
-
ctx->font_bool = _malloc(ctx->font_bool_size);
-
if (ctx->font_bool == NULL) {
-
goto fail;
-
}
-
-
for (size_t i = 0; i < FLANTERM_FB_FONT_GLYPHS; i++) {
-
uint8_t *glyph = &ctx->font_bits[i * font_height];
-
-
for (size_t y = 0; y < font_height; y++) {
-
// NOTE: the characters in VGA fonts are always one byte wide.
-
// 9 dot wide fonts have 8 dots and one empty column, except
-
// characters 0xC0-0xDF replicate column 9.
-
for (size_t x = 0; x < 8; x++) {
-
size_t offset = i * font_height * ctx->font_width + y * ctx->font_width + x;
-
-
if ((glyph[y] & (0x80 >> x))) {
-
ctx->font_bool[offset] = true;
-
} else {
-
ctx->font_bool[offset] = false;
-
}
-
}
-
// fill columns above 8 like VGA Line Graphics Mode does
-
for (size_t x = 8; x < ctx->font_width; x++) {
-
size_t offset = i * font_height * ctx->font_width + y * ctx->font_width + x;
-
-
if (i >= 0xc0 && i <= 0xdf) {
-
ctx->font_bool[offset] = (glyph[y] & 1);
-
} else {
-
ctx->font_bool[offset] = false;
-
}
-
}
-
}
-
}
-
-
ctx->font_scale_x = font_scale_x;
-
ctx->font_scale_y = font_scale_y;
-
-
ctx->glyph_width = ctx->font_width * font_scale_x;
-
ctx->glyph_height = font_height * font_scale_y;
-
-
_ctx->cols = (ctx->width - margin * 2) / ctx->glyph_width;
-
_ctx->rows = (ctx->height - margin * 2) / ctx->glyph_height;
-
-
ctx->offset_x = margin + ((ctx->width - margin * 2) % ctx->glyph_width) / 2;
-
ctx->offset_y = margin + ((ctx->height - margin * 2) % ctx->glyph_height) / 2;
-
-
ctx->grid_size = _ctx->rows * _ctx->cols * sizeof(struct flanterm_fb_char);
-
ctx->grid = _malloc(ctx->grid_size);
-
if (ctx->grid == NULL) {
-
goto fail;
-
}
-
for (size_t i = 0; i < _ctx->rows * _ctx->cols; i++) {
-
ctx->grid[i].c = ' ';
-
ctx->grid[i].fg = ctx->text_fg;
-
ctx->grid[i].bg = ctx->text_bg;
-
}
-
-
ctx->queue_size = _ctx->rows * _ctx->cols * sizeof(struct flanterm_fb_queue_item);
-
ctx->queue = _malloc(ctx->queue_size);
-
if (ctx->queue == NULL) {
-
goto fail;
-
}
-
ctx->queue_i = 0;
-
memset(ctx->queue, 0, ctx->queue_size);
-
-
ctx->map_size = _ctx->rows * _ctx->cols * sizeof(struct flanterm_fb_queue_item *);
-
ctx->map = _malloc(ctx->map_size);
-
if (ctx->map == NULL) {
-
goto fail;
-
}
-
memset(ctx->map, 0, ctx->map_size);
-
-
if (canvas != NULL) {
-
ctx->canvas_size = ctx->width * ctx->height * sizeof(uint32_t);
-
ctx->canvas = _malloc(ctx->canvas_size);
-
if (ctx->canvas == NULL) {
-
goto fail;
-
}
-
for (size_t i = 0; i < ctx->width * ctx->height; i++) {
-
ctx->canvas[i] = convert_colour(_ctx, canvas[i]);
-
}
-
}
-
-
if (font_scale_x == 1 && font_scale_y == 1) {
-
if (canvas == NULL) {
-
ctx->plot_char = plot_char_unscaled_uncanvas;
-
} else {
-
ctx->plot_char = plot_char_unscaled_canvas;
-
}
-
} else {
-
if (canvas == NULL) {
-
ctx->plot_char = plot_char_scaled_uncanvas;
-
} else {
-
ctx->plot_char = plot_char_scaled_canvas;
-
}
-
}
-
-
_ctx->raw_putchar = flanterm_fb_raw_putchar;
-
_ctx->clear = flanterm_fb_clear;
-
_ctx->set_cursor_pos = flanterm_fb_set_cursor_pos;
-
_ctx->get_cursor_pos = flanterm_fb_get_cursor_pos;
-
_ctx->set_text_fg = flanterm_fb_set_text_fg;
-
_ctx->set_text_bg = flanterm_fb_set_text_bg;
-
_ctx->set_text_fg_bright = flanterm_fb_set_text_fg_bright;
-
_ctx->set_text_bg_bright = flanterm_fb_set_text_bg_bright;
-
_ctx->set_text_fg_rgb = flanterm_fb_set_text_fg_rgb;
-
_ctx->set_text_bg_rgb = flanterm_fb_set_text_bg_rgb;
-
_ctx->set_text_fg_default = flanterm_fb_set_text_fg_default;
-
_ctx->set_text_bg_default = flanterm_fb_set_text_bg_default;
-
_ctx->set_text_fg_default_bright = flanterm_fb_set_text_fg_default_bright;
-
_ctx->set_text_bg_default_bright = flanterm_fb_set_text_bg_default_bright;
-
_ctx->move_character = flanterm_fb_move_character;
-
_ctx->scroll = flanterm_fb_scroll;
-
_ctx->revscroll = flanterm_fb_revscroll;
-
_ctx->swap_palette = flanterm_fb_swap_palette;
-
_ctx->save_state = flanterm_fb_save_state;
-
_ctx->restore_state = flanterm_fb_restore_state;
-
_ctx->double_buffer_flush = flanterm_fb_double_buffer_flush;
-
_ctx->full_refresh = flanterm_fb_full_refresh;
-
_ctx->deinit = flanterm_fb_deinit;
-
-
flanterm_context_reinit(_ctx);
-
flanterm_fb_full_refresh(_ctx);
-
-
#ifndef FLANTERM_FB_DISABLE_BUMP_ALLOC
-
if (_malloc == bump_alloc) {
-
bump_allocated_instance = true;
-
}
-
#endif
-
-
return _ctx;
-
-
fail:
-
if (ctx == NULL) {
-
return NULL;
-
}
-
-
#ifndef FLANTERM_FB_DISABLE_BUMP_ALLOC
-
if (_malloc == bump_alloc) {
-
bump_alloc_ptr = 0;
-
return NULL;
-
}
-
#endif
-
-
if (_free == NULL) {
-
return NULL;
-
}
-
-
if (ctx->canvas != NULL) {
-
_free(ctx->canvas, ctx->canvas_size);
-
}
-
if (ctx->map != NULL) {
-
_free(ctx->map, ctx->map_size);
-
}
-
if (ctx->queue != NULL) {
-
_free(ctx->queue, ctx->queue_size);
-
}
-
if (ctx->grid != NULL) {
-
_free(ctx->grid, ctx->grid_size);
-
}
-
if (ctx->font_bool != NULL) {
-
_free(ctx->font_bool, ctx->font_bool_size);
-
}
-
if (ctx->font_bits != NULL) {
-
_free(ctx->font_bits, ctx->font_bits_size);
-
}
-
if (ctx != NULL) {
-
_free(ctx, sizeof(struct flanterm_fb_context));
-
}
-
-
return NULL;
-
}
-68
src/backends/fb.h
···
-
/* Copyright (C) 2022-2025 mintsuki and contributors.
-
*
-
* Redistribution and use in source and binary forms, with or without
-
* modification, are permitted provided that the following conditions are met:
-
*
-
* 1. Redistributions of source code must retain the above copyright notice,
-
* this list of conditions and the following disclaimer.
-
*
-
* 2. Redistributions in binary form must reproduce the above copyright notice,
-
* this list of conditions and the following disclaimer in the documentation
-
* and/or other materials provided with the distribution.
-
*
-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
-
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-
* POSSIBILITY OF SUCH DAMAGE.
-
*/
-
-
#ifndef FLANTERM_FB_H
-
#define FLANTERM_FB_H 1
-
-
#include <stdint.h>
-
#include <stddef.h>
-
#include <stdbool.h>
-
-
#ifdef __cplusplus
-
extern "C" {
-
#endif
-
-
#include "../flanterm.h"
-
-
#ifdef FLANTERM_IN_FLANTERM
-
-
#include "fb_private.h"
-
-
#endif
-
-
struct flanterm_context *flanterm_fb_init(
-
/* If _malloc and _free are nulled, use the bump allocated instance (1 use only). */
-
void *(*_malloc)(size_t size),
-
void (*_free)(void *ptr, size_t size),
-
uint32_t *framebuffer, size_t width, size_t height, size_t pitch,
-
uint8_t red_mask_size, uint8_t red_mask_shift,
-
uint8_t green_mask_size, uint8_t green_mask_shift,
-
uint8_t blue_mask_size, uint8_t blue_mask_shift,
-
uint32_t *canvas, /* If nulled, no canvas. */
-
uint32_t *ansi_colours, uint32_t *ansi_bright_colours, /* If nulled, default. */
-
uint32_t *default_bg, uint32_t *default_fg, /* If nulled, default. */
-
uint32_t *default_bg_bright, uint32_t *default_fg_bright, /* If nulled, default. */
-
/* If font is null, use default font and font_width and font_height ignored. */
-
void *font, size_t font_width, size_t font_height, size_t font_spacing,
-
/* If scale_x and scale_y are 0, automatically scale font based on resolution. */
-
size_t font_scale_x, size_t font_scale_y,
-
size_t margin
-
);
-
-
#ifdef __cplusplus
-
}
-
#endif
-
-
#endif
-121
src/backends/fb_private.h
···
-
/* Copyright (C) 2022-2025 mintsuki and contributors.
-
*
-
* Redistribution and use in source and binary forms, with or without
-
* modification, are permitted provided that the following conditions are met:
-
*
-
* 1. Redistributions of source code must retain the above copyright notice,
-
* this list of conditions and the following disclaimer.
-
*
-
* 2. Redistributions in binary form must reproduce the above copyright notice,
-
* this list of conditions and the following disclaimer in the documentation
-
* and/or other materials provided with the distribution.
-
*
-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
-
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-
* POSSIBILITY OF SUCH DAMAGE.
-
*/
-
-
#ifndef FLANTERM_FB_PRIVATE_H
-
#define FLANTERM_FB_PRIVATE_H 1
-
-
#ifndef FLANTERM_IN_FLANTERM
-
#error "Do not use fb_private.h. Use interfaces defined in fb.h only."
-
#endif
-
-
#include <stdint.h>
-
#include <stddef.h>
-
#include <stdbool.h>
-
-
#ifdef __cplusplus
-
extern "C" {
-
#endif
-
-
#define FLANTERM_FB_FONT_GLYPHS 256
-
-
struct flanterm_fb_char {
-
uint32_t c;
-
uint32_t fg;
-
uint32_t bg;
-
};
-
-
struct flanterm_fb_queue_item {
-
size_t x, y;
-
struct flanterm_fb_char c;
-
};
-
-
struct flanterm_fb_context {
-
struct flanterm_context term;
-
-
void (*plot_char)(struct flanterm_context *ctx, struct flanterm_fb_char *c, size_t x, size_t y);
-
-
size_t font_width;
-
size_t font_height;
-
size_t glyph_width;
-
size_t glyph_height;
-
-
size_t font_scale_x;
-
size_t font_scale_y;
-
-
size_t offset_x, offset_y;
-
-
volatile uint32_t *framebuffer;
-
size_t pitch;
-
size_t width;
-
size_t height;
-
size_t bpp;
-
-
uint8_t red_mask_size, red_mask_shift;
-
uint8_t green_mask_size, green_mask_shift;
-
uint8_t blue_mask_size, blue_mask_shift;
-
-
size_t font_bits_size;
-
uint8_t *font_bits;
-
size_t font_bool_size;
-
bool *font_bool;
-
-
uint32_t ansi_colours[8];
-
uint32_t ansi_bright_colours[8];
-
uint32_t default_fg, default_bg;
-
uint32_t default_fg_bright, default_bg_bright;
-
-
size_t canvas_size;
-
uint32_t *canvas;
-
-
size_t grid_size;
-
size_t queue_size;
-
size_t map_size;
-
-
struct flanterm_fb_char *grid;
-
-
struct flanterm_fb_queue_item *queue;
-
size_t queue_i;
-
-
struct flanterm_fb_queue_item **map;
-
-
uint32_t text_fg;
-
uint32_t text_bg;
-
size_t cursor_x;
-
size_t cursor_y;
-
-
uint32_t saved_state_text_fg;
-
uint32_t saved_state_text_bg;
-
size_t saved_state_cursor_x;
-
size_t saved_state_cursor_y;
-
-
size_t old_cursor_x;
-
size_t old_cursor_y;
-
};
-
-
#ifdef __cplusplus
-
}
-
#endif
-
-
#endif
+60
src/colors.zig
···
+
const std = @import("std");
+
+
pub const Palette = extern struct {
+
black: u32,
+
red: u32,
+
green: u32,
+
yellow: u32,
+
blue: u32,
+
magenta: u32,
+
cyan: u32,
+
white: u32,
+
};
+
+
/// Used for escape sequences
+
pub const Color = enum(u8) {
+
black = 30,
+
red = 31,
+
green = 32,
+
yellow = 33,
+
blue = 34,
+
magenta = 35,
+
cyan = 36,
+
white = 37,
+
default = 39,
+
bright_black = 90,
+
bright_red = 91,
+
bright_green = 92,
+
bright_yellow = 93,
+
bright_blue = 94,
+
bright_magenta = 95,
+
bright_cyan = 96,
+
bright_white = 97,
+
+
pub fn esc_seq(comptime self: Color) []const u8 {
+
if (self == .default) return "\x1b[0m";
+
return std.fmt.comptimePrint("\x1b[{}m", .{@intFromEnum(self)});
+
}
+
};
+
+
pub var default_colors: Palette = .{
+
.black = 0x000000,
+
.red = 0xff0000,
+
.green = 0x37dd21,
+
.yellow = 0xfee409,
+
.blue = 0x1460d2,
+
.magenta = 0xff005d,
+
.cyan = 0x00bbbb,
+
.white = 0xbbbbbb,
+
};
+
+
pub var default_bold_colors: Palette = .{
+
.black = 0x545454,
+
.red = 0xf40d17,
+
.green = 0x3bcf1d,
+
.yellow = 0xecc809,
+
.blue = 0x5555ff,
+
.magenta = 0xff55ff,
+
.cyan = 0x6ae3f9,
+
.white = 0xffffff,
+
};
+50 -14
src/flanterm.c
···
#include <stddef.h>
#include <stdbool.h>
+
#ifndef FLANTERM_IN_FLANTERM
#define FLANTERM_IN_FLANTERM
+
#endif
#include "flanterm.h"
···
ctx->reverse_video = false;
ctx->dec_private = false;
ctx->insert_mode = false;
+
ctx->csi_unhandled = false;
ctx->unicode_remaining = 0;
ctx->g_select = 0;
ctx->charsets[0] = CHARSET_DEFAULT;
···
}
}
-
static void osc_parse(struct flanterm_context *ctx, uint8_t c) {
-
if (ctx->osc_escape && c == '\\') {
-
goto cleanup;
+
static bool osc_parse(struct flanterm_context *ctx, uint8_t c) {
+
// ESC \ terminates an OSC sequence cleanly
+
// but if ESC is followed by non-\, report failure from osc_parse and
+
// try parsing the character as another escape code
+
if (ctx->osc_escape) {
+
if (c == '\\') {
+
ctx->osc = false;
+
ctx->osc_escape = false;
+
ctx->escape = false;
+
return true;
+
} else {
+
ctx->osc_escape = false;
+
ctx->osc = false;
+
// escape stays true here
+
return false;
+
}
}
-
-
ctx->osc_escape = false;
-
switch (c) {
case 0x1b:
ctx->osc_escape = true;
-
return;
+
break;
+
// BEL is the other terminator
case '\a':
+
ctx->osc_escape = false;
+
ctx->osc = false;
+
ctx->escape = false;
+
break;
default:
break;
}
-
-
cleanup:
-
ctx->osc_escape = false;
-
ctx->osc = false;
-
ctx->escape = false;
+
return true;
}
static void control_sequence_parse(struct flanterm_context *ctx, uint8_t c) {
···
ctx->scroll_enabled = false;
size_t x, y;
ctx->get_cursor_pos(ctx, &x, &y);
+
+
// CSI sequences are terminated by a byte in [0x40,0x7E]
+
// so skip all bytes until the terminator byte
+
if (ctx->csi_unhandled) {
+
if (c >= 0x40 && c <= 0x7E) {
+
ctx->csi_unhandled = false;
+
goto cleanup;
+
}
+
return;
+
}
switch (c) {
+
// Got ESC in the middle of an escape sequence, start a new one
+
case 0x1B:
+
return;
case 'F':
x = 0;
// FALLTHRU
···
case ']':
linux_private_parse(ctx);
break;
+
default:
+
ctx->csi_unhandled = true;
+
return;
}
ctx->scroll_enabled = r;
···
ctx->escape_offset++;
if (ctx->osc == true) {
-
osc_parse(ctx, c);
-
return;
+
// ESC \ is one of the two possible terminators of OSC sequences,
+
// so osc_parse consumes ESC.
+
// If it is then followed by \ it cleans correctly,
+
// otherwise it returns false, and it tries parsing it as another escape sequence
+
if (osc_parse(ctx, c)) {
+
return;
+
}
}
if (ctx->control_sequence == true) {
···
ctx->esc_values[i] = 0;
ctx->esc_values_i = 0;
ctx->rrr = false;
+
ctx->csi_unhandled = false;
ctx->control_sequence = true;
return;
case '7':
+1254
src/flanterm_backends/fb.c
···
+
/* Copyright (C) 2022-2025 mintsuki and contributors.
+
*
+
* Redistribution and use in source and binary forms, with or without
+
* modification, are permitted provided that the following conditions are met:
+
*
+
* 1. Redistributions of source code must retain the above copyright notice,
+
* this list of conditions and the following disclaimer.
+
*
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
+
* this list of conditions and the following disclaimer in the documentation
+
* and/or other materials provided with the distribution.
+
*
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+
* POSSIBILITY OF SUCH DAMAGE.
+
*/
+
+
#ifdef __cplusplus
+
#error "Please do not compile Flanterm as C++ code! Flanterm should be compiled as C99 or newer."
+
#endif
+
+
#ifndef __STDC_VERSION__
+
#error "Flanterm must be compiled as C99 or newer."
+
#endif
+
+
#if defined(_MSC_VER)
+
#define ALWAYS_INLINE __forceinline
+
#elif defined(__GNUC__) || defined(__clang__)
+
#define ALWAYS_INLINE __attribute__((always_inline)) inline
+
#else
+
#define ALWAYS_INLINE inline
+
#endif
+
+
#include <stdint.h>
+
#include <stddef.h>
+
#include <stdbool.h>
+
+
#ifndef FLANTERM_IN_FLANTERM
+
#define FLANTERM_IN_FLANTERM
+
#endif
+
+
#include "../flanterm.h"
+
#include "fb.h"
+
+
void *memset(void *, int, size_t);
+
void *memcpy(void *, const void *, size_t);
+
+
#ifndef FLANTERM_FB_DISABLE_BUMP_ALLOC
+
+
#ifndef FLANTERM_FB_BUMP_ALLOC_POOL_SIZE
+
#define FLANTERM_FB_BUMP_ALLOC_POOL_SIZE 873000
+
+
#define FLANTERM_FB_WIDTH_LIMIT 1920
+
#define FLANTERM_FB_HEIGHT_LIMIT 1200
+
#endif
+
+
static uint8_t bump_alloc_pool[FLANTERM_FB_BUMP_ALLOC_POOL_SIZE];
+
static size_t bump_alloc_ptr = 0;
+
+
static void *bump_alloc(size_t s) {
+
static bool base_offset_added = false;
+
if (!base_offset_added) {
+
if ((uintptr_t)bump_alloc_pool & 0xf) {
+
bump_alloc_ptr += 0x10 - ((uintptr_t)bump_alloc_pool & 0xf);
+
}
+
base_offset_added = true;
+
}
+
+
if ((s & 0xf) != 0) {
+
s += 0x10;
+
s &= ~(size_t)0xf;
+
}
+
+
size_t next_ptr = bump_alloc_ptr + s;
+
if (next_ptr > FLANTERM_FB_BUMP_ALLOC_POOL_SIZE) {
+
return NULL;
+
}
+
void *ret = &bump_alloc_pool[bump_alloc_ptr];
+
bump_alloc_ptr = next_ptr;
+
return ret;
+
}
+
+
static bool bump_allocated_instance = false;
+
+
#endif
+
+
// Builtin font originally taken from:
+
// https://github.com/viler-int10h/vga-text-mode-fonts/raw/master/FONTS/PC-OTHER/TOSH-SAT.F16
+
static const uint8_t builtin_font[] = {
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x42, 0x81, 0x81, 0xa5, 0xa5, 0x81,
+
0x81, 0xa5, 0x99, 0x81, 0x42, 0x3c, 0x00, 0x00, 0x00, 0x3c, 0x7e, 0xff,
+
0xff, 0xdb, 0xdb, 0xff, 0xff, 0xdb, 0xe7, 0xff, 0x7e, 0x3c, 0x00, 0x00,
+
0x00, 0x00, 0x00, 0x6c, 0xfe, 0xfe, 0xfe, 0x7c, 0x7c, 0x38, 0x38, 0x10,
+
0x10, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x38, 0x38, 0x7c, 0x7c, 0xfe,
+
0x7c, 0x7c, 0x38, 0x38, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18,
+
0x3c, 0x3c, 0xdb, 0xff, 0xff, 0xdb, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0x00, 0x18, 0x3c, 0x7e, 0xff, 0xff, 0xff, 0x66, 0x18, 0x18,
+
0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x78,
+
0x78, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
+
0xff, 0xff, 0xe7, 0xc3, 0xc3, 0xe7, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0xcc, 0x84, 0x84, 0xcc, 0x78, 0x00,
+
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc3, 0x99, 0xbd,
+
0xbd, 0x99, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x1e,
+
0x0e, 0x1e, 0x32, 0x78, 0xcc, 0xcc, 0xcc, 0x78, 0x00, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0x00, 0x78, 0xcc, 0xcc, 0xcc, 0x78, 0x30, 0xfc, 0x30, 0x30,
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x18, 0x1c, 0x1e, 0x16, 0x12,
+
0x10, 0x10, 0x70, 0xf0, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x30, 0x38, 0x2c,
+
0x26, 0x32, 0x3a, 0x2e, 0x26, 0x22, 0x62, 0xe2, 0xc6, 0x0e, 0x0c, 0x00,
+
0x00, 0x00, 0x00, 0x18, 0x18, 0xdb, 0x3c, 0xe7, 0x3c, 0xdb, 0x18, 0x18,
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xc0, 0xe0, 0xf8, 0xfe,
+
0xf8, 0xe0, 0xc0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
+
0x06, 0x0e, 0x3e, 0xfe, 0x3e, 0x0e, 0x06, 0x02, 0x00, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0x30, 0x78, 0xfc, 0x30, 0x30, 0x30, 0x30, 0x30, 0xfc, 0x78,
+
0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
+
0xcc, 0xcc, 0x00, 0xcc, 0xcc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xdb,
+
0xdb, 0xdb, 0xdb, 0x7b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0x7c, 0xc6, 0x60, 0x38, 0x6c, 0xc6, 0xc6, 0x6c, 0x38, 0x0c,
+
0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0xfe, 0xfe, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x78,
+
0xfc, 0x30, 0x30, 0x30, 0x30, 0x30, 0xfc, 0x78, 0x30, 0xfc, 0x00, 0x00,
+
0x00, 0x00, 0x30, 0x78, 0xfc, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
+
0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
+
0x30, 0x30, 0xfc, 0x78, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+
0x00, 0x18, 0x0c, 0xfe, 0xfe, 0x0c, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x60, 0xfe, 0xfe, 0x60, 0x30, 0x00,
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0,
+
0xc0, 0xc0, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+
0x00, 0x24, 0x66, 0xff, 0xff, 0x66, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x38, 0x38, 0x7c, 0x7c, 0xfe, 0xfe,
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xfe, 0x7c, 0x7c,
+
0x38, 0x38, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0x30, 0x78, 0x78, 0x78, 0x78, 0x30, 0x30, 0x30, 0x00, 0x30,
+
0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x00,
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6c, 0x6c,
+
0x6c, 0xfe, 0x6c, 0x6c, 0x6c, 0xfe, 0x6c, 0x6c, 0x6c, 0x00, 0x00, 0x00,
+
0x00, 0x18, 0x18, 0x7c, 0xc6, 0xc0, 0xc0, 0x7c, 0x06, 0x06, 0xc6, 0x7c,
+
0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xc6, 0x0c, 0x0c, 0x18, 0x38,
+
0x30, 0x60, 0x60, 0xc6, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x6c,
+
0x6c, 0x38, 0x30, 0x76, 0xde, 0xcc, 0xcc, 0xde, 0x76, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0x18, 0x18, 0x18, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x30, 0x60, 0x60, 0x60, 0x60,
+
0x60, 0x60, 0x60, 0x30, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x30,
+
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x30, 0x60, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x6c, 0x38, 0xfe, 0x38, 0x6c, 0x00, 0x00,
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x7e,
+
0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x30, 0x00, 0x00,
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x06,
+
0x0c, 0x0c, 0x18, 0x38, 0x30, 0x60, 0x60, 0xc0, 0xc0, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xd6, 0xd6, 0xd6, 0xc6, 0xc6, 0xc6,
+
0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x38, 0x78, 0x18, 0x18, 0x18,
+
0x18, 0x18, 0x18, 0x18, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6,
+
0x06, 0x06, 0x0c, 0x18, 0x30, 0x60, 0xc0, 0xc0, 0xfe, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0x7c, 0xc6, 0x06, 0x06, 0x3c, 0x06, 0x06, 0x06, 0x06, 0xc6,
+
0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x0c, 0x1c, 0x3c, 0x6c, 0xcc,
+
0xfe, 0x0c, 0x0c, 0x0c, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xc0,
+
0xc0, 0xc0, 0xfc, 0x06, 0x06, 0x06, 0x06, 0xc6, 0x7c, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0x3c, 0x60, 0xc0, 0xc0, 0xfc, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6,
+
0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xc6, 0x06, 0x06, 0x0c, 0x18,
+
0x30, 0x30, 0x30, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6,
+
0xc6, 0xc6, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0x7e, 0x06, 0x06, 0x06, 0x0c,
+
0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18,
+
0x18, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x18, 0x18, 0x30, 0x00, 0x00,
+
0x00, 0x00, 0x06, 0x0c, 0x18, 0x30, 0x60, 0xc0, 0x60, 0x30, 0x18, 0x0c,
+
0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x00,
+
0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x60,
+
0x30, 0x18, 0x0c, 0x06, 0x0c, 0x18, 0x30, 0x60, 0xc0, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0x7c, 0xc6, 0xc6, 0x06, 0x0c, 0x18, 0x30, 0x30, 0x00, 0x30,
+
0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xde, 0xde,
+
0xde, 0xde, 0xc0, 0xc0, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x6c,
+
0xc6, 0xc6, 0xc6, 0xc6, 0xfe, 0xc6, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0xfc, 0xc6, 0xc6, 0xc6, 0xfc, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6,
+
0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc0, 0xc0, 0xc0, 0xc0,
+
0xc0, 0xc0, 0xc0, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xcc,
+
0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xcc, 0xf8, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0xfe, 0xc0, 0xc0, 0xc0, 0xfc, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0,
+
0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xc0, 0xc0, 0xc0, 0xfc, 0xc0,
+
0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6,
+
0xc0, 0xc0, 0xc0, 0xde, 0xc6, 0xc6, 0xc6, 0xc6, 0x7e, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xfe, 0xc6, 0xc6, 0xc6, 0xc6,
+
0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x30, 0x30, 0x30, 0x30, 0x30,
+
0x30, 0x30, 0x30, 0x30, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x0c,
+
0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0xcc, 0xcc, 0x78, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0xc6, 0xc6, 0xcc, 0xd8, 0xf0, 0xe0, 0xf0, 0xd8, 0xcc, 0xc6,
+
0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0,
+
0xc0, 0xc0, 0xc0, 0xc0, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xc6,
+
0xee, 0xfe, 0xd6, 0xd6, 0xd6, 0xc6, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0xc6, 0xc6, 0xe6, 0xe6, 0xf6, 0xde, 0xce, 0xce, 0xc6, 0xc6,
+
0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6,
+
0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xc6,
+
0xc6, 0xc6, 0xc6, 0xfc, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xf6, 0xda,
+
0x6c, 0x06, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xc6, 0xc6, 0xc6, 0xc6, 0xfc,
+
0xd8, 0xcc, 0xcc, 0xc6, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6,
+
0xc0, 0x60, 0x30, 0x18, 0x0c, 0x06, 0x06, 0xc6, 0x7c, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0xff, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
+
0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6,
+
0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xc6,
+
0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x6c, 0x38, 0x10, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xd6, 0xd6, 0xd6, 0xd6, 0xfe, 0x6c,
+
0x6c, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xc6, 0xc6, 0x6c, 0x38, 0x38,
+
0x38, 0x6c, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcc, 0xcc,
+
0xcc, 0xcc, 0xcc, 0x78, 0x30, 0x30, 0x30, 0x30, 0x30, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0xfe, 0x06, 0x06, 0x0c, 0x18, 0x30, 0x60, 0xc0, 0xc0, 0xc0,
+
0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x60, 0x60, 0x60, 0x60, 0x60,
+
0x60, 0x60, 0x60, 0x60, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xc0,
+
0x60, 0x60, 0x30, 0x38, 0x18, 0x0c, 0x0c, 0x06, 0x06, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0x78, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
+
0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x38, 0x6c, 0xc6, 0x00, 0x00,
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00,
+
0x00, 0x00, 0x18, 0x18, 0x18, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0x06, 0x06,
+
0x7e, 0xc6, 0xc6, 0xc6, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xc0,
+
0xc0, 0xdc, 0xe6, 0xc6, 0xc6, 0xc6, 0xc6, 0xe6, 0xdc, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc0, 0xc0, 0xc0, 0xc0, 0xc6,
+
0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x06, 0x06, 0x76, 0xce, 0xc6,
+
0xc6, 0xc6, 0xc6, 0xce, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+
0x00, 0x7c, 0xc6, 0xc6, 0xfe, 0xc0, 0xc0, 0xc0, 0x7e, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0x1c, 0x36, 0x30, 0x30, 0xfc, 0x30, 0x30, 0x30, 0x30, 0x30,
+
0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0xce, 0xc6,
+
0xc6, 0xc6, 0xce, 0x76, 0x06, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0xc0, 0xc0,
+
0xc0, 0xdc, 0xe6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0x18, 0x00, 0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
+
0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x1e, 0x06, 0x06,
+
0x06, 0x06, 0x06, 0x06, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0xc0, 0xc0,
+
0xc0, 0xc6, 0xcc, 0xd8, 0xf0, 0xf0, 0xd8, 0xcc, 0xc6, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
+
0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xec, 0xfe, 0xd6,
+
0xd6, 0xd6, 0xd6, 0xc6, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+
0x00, 0xdc, 0xe6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6,
+
0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xdc, 0xe6, 0xc6,
+
0xc6, 0xc6, 0xe6, 0xdc, 0xc0, 0xc0, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00,
+
0x00, 0x76, 0xce, 0xc6, 0xc6, 0xc6, 0xce, 0x76, 0x06, 0x06, 0x06, 0x00,
+
0x00, 0x00, 0x00, 0x00, 0x00, 0xdc, 0xe6, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0,
+
0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc0,
+
0x70, 0x1c, 0x06, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30,
+
0x30, 0xfe, 0x30, 0x30, 0x30, 0x30, 0x30, 0x36, 0x1c, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6,
+
0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xc6, 0xc6,
+
0xc6, 0xc6, 0x6c, 0x38, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+
0x00, 0xc6, 0xc6, 0xd6, 0xd6, 0xd6, 0xd6, 0xfe, 0x6c, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xc6, 0x6c, 0x38, 0x38, 0x6c, 0xc6,
+
0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xc6, 0xc6,
+
0xc6, 0xc6, 0xce, 0x76, 0x06, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00,
+
0x00, 0xfe, 0x06, 0x0c, 0x18, 0x30, 0x60, 0xc0, 0xfe, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0x1c, 0x30, 0x30, 0x30, 0x30, 0xe0, 0x30, 0x30, 0x30, 0x30,
+
0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x30, 0x30, 0x30, 0x00,
+
0x30, 0x30, 0x30, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x30,
+
0x30, 0x30, 0x30, 0x1c, 0x30, 0x30, 0x30, 0x30, 0xe0, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0x00, 0x76, 0xdc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x38, 0x38, 0x6c,
+
0x6c, 0xc6, 0xc6, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x66,
+
0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x66, 0x3c, 0x18, 0xcc, 0x78, 0x00,
+
0x00, 0x00, 0x6c, 0x6c, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6,
+
0x7c, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x18, 0x30, 0x00, 0x7c, 0xc6, 0xc6,
+
0xfe, 0xc0, 0xc0, 0xc0, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x10, 0x38, 0x6c,
+
0x00, 0x7c, 0x06, 0x06, 0x7e, 0xc6, 0xc6, 0xc6, 0x7e, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0x6c, 0x6c, 0x00, 0x7c, 0x06, 0x06, 0x7e, 0xc6, 0xc6, 0xc6,
+
0x7e, 0x00, 0x00, 0x00, 0x00, 0x60, 0x30, 0x18, 0x00, 0x7c, 0x06, 0x06,
+
0x7e, 0xc6, 0xc6, 0xc6, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x38, 0x6c, 0x38,
+
0x00, 0x7c, 0x06, 0x06, 0x7e, 0xc6, 0xc6, 0xc6, 0x7e, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc0, 0xc0, 0xc0, 0xc0, 0xc6,
+
0x7c, 0x18, 0x0c, 0x38, 0x00, 0x10, 0x38, 0x6c, 0x00, 0x7c, 0xc6, 0xc6,
+
0xfe, 0xc0, 0xc0, 0xc0, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6c, 0x6c,
+
0x00, 0x7c, 0xc6, 0xc6, 0xfe, 0xc0, 0xc0, 0xc0, 0x7e, 0x00, 0x00, 0x00,
+
0x00, 0x60, 0x30, 0x18, 0x00, 0x7c, 0xc6, 0xc6, 0xfe, 0xc0, 0xc0, 0xc0,
+
0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6c, 0x6c, 0x00, 0x38, 0x18, 0x18,
+
0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x10, 0x38, 0x6c,
+
0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00,
+
0x00, 0x60, 0x30, 0x18, 0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
+
0x3c, 0x00, 0x00, 0x00, 0xc6, 0xc6, 0x10, 0x38, 0x6c, 0xc6, 0xc6, 0xc6,
+
0xfe, 0xc6, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00, 0x38, 0x6c, 0x38, 0x00,
+
0x38, 0x6c, 0xc6, 0xc6, 0xc6, 0xfe, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00,
+
0x18, 0x30, 0x60, 0x00, 0xfe, 0xc0, 0xc0, 0xfc, 0xc0, 0xc0, 0xc0, 0xc0,
+
0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xec, 0x36, 0x36,
+
0x76, 0xde, 0xd8, 0xd8, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x3c,
+
0x6c, 0xcc, 0xcc, 0xfe, 0xcc, 0xcc, 0xcc, 0xcc, 0xce, 0x00, 0x00, 0x00,
+
0x00, 0x10, 0x38, 0x6c, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6,
+
0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6c, 0x6c, 0x00, 0x7c, 0xc6, 0xc6,
+
0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x60, 0x30, 0x18,
+
0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00,
+
0x00, 0x10, 0x38, 0x6c, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6,
+
0x7c, 0x00, 0x00, 0x00, 0x00, 0x60, 0x30, 0x18, 0x00, 0xc6, 0xc6, 0xc6,
+
0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6c, 0x6c,
+
0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xce, 0x76, 0x06, 0xc6, 0x7c, 0x00,
+
0x6c, 0x6c, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6,
+
0x7c, 0x00, 0x00, 0x00, 0x6c, 0x6c, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6,
+
0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30,
+
0x30, 0x78, 0xcc, 0xc0, 0xc0, 0xcc, 0x78, 0x30, 0x30, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0x38, 0x6c, 0x60, 0x60, 0x60, 0xf8, 0x60, 0x60, 0x60, 0xe6,
+
0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc, 0x78, 0x30, 0xfc,
+
0x30, 0xfc, 0x30, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xcc,
+
0xcc, 0xf8, 0xc4, 0xcc, 0xde, 0xcc, 0xcc, 0xcc, 0xc6, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0x0e, 0x1b, 0x18, 0x18, 0x18, 0x7e, 0x18, 0x18, 0x18, 0x18,
+
0x18, 0xd8, 0x70, 0x00, 0x00, 0x0c, 0x18, 0x30, 0x00, 0x7c, 0x06, 0x06,
+
0x7e, 0xc6, 0xc6, 0xc6, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x18, 0x30,
+
0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00,
+
0x00, 0x0c, 0x18, 0x30, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6,
+
0x7c, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x18, 0x30, 0x00, 0xc6, 0xc6, 0xc6,
+
0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x76, 0xdc, 0x00,
+
0x00, 0xdc, 0xe6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00,
+
0x76, 0xdc, 0x00, 0xc6, 0xc6, 0xe6, 0xf6, 0xfe, 0xde, 0xce, 0xc6, 0xc6,
+
0xc6, 0x00, 0x00, 0x00, 0x00, 0x78, 0xd8, 0xd8, 0x6c, 0x00, 0xfc, 0x00,
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x6c, 0x6c,
+
0x38, 0x00, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0x18, 0x18, 0x00, 0x18, 0x18, 0x30, 0x60, 0xc0, 0xc6, 0xc6,
+
0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+
0xfe, 0xc0, 0xc0, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0x00, 0x00, 0xfe, 0x06, 0x06, 0x06, 0x00, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0xc0, 0xc2, 0xc6, 0xcc, 0xd8, 0x30, 0x60, 0xdc, 0x86, 0x0c,
+
0x18, 0x3e, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xc2, 0xc6, 0xcc, 0xd8, 0x30,
+
0x66, 0xce, 0x9e, 0x3e, 0x06, 0x06, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30,
+
0x00, 0x30, 0x30, 0x30, 0x78, 0x78, 0x78, 0x78, 0x30, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x6c, 0xd8, 0x6c, 0x36, 0x00, 0x00,
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd8, 0x6c, 0x36,
+
0x6c, 0xd8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x88, 0x22, 0x88,
+
0x22, 0x88, 0x22, 0x88, 0x22, 0x88, 0x22, 0x88, 0x22, 0x88, 0x22, 0x88,
+
0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa,
+
0x55, 0xaa, 0x55, 0xaa, 0xdd, 0x77, 0xdd, 0x77, 0xdd, 0x77, 0xdd, 0x77,
+
0xdd, 0x77, 0xdd, 0x77, 0xdd, 0x77, 0xdd, 0x77, 0x18, 0x18, 0x18, 0x18,
+
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
+
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xf8, 0xf8, 0x18, 0x18, 0x18,
+
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xf8, 0xf8, 0x18,
+
0x18, 0xf8, 0xf8, 0x18, 0x18, 0x18, 0x18, 0x18, 0x36, 0x36, 0x36, 0x36,
+
0x36, 0x36, 0x36, 0xf6, 0xf6, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xfe, 0x36, 0x36, 0x36,
+
0x36, 0x36, 0x36, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xf8, 0x18,
+
0x18, 0xf8, 0xf8, 0x18, 0x18, 0x18, 0x18, 0x18, 0x36, 0x36, 0x36, 0x36,
+
0x36, 0xf6, 0xf6, 0x06, 0x06, 0xf6, 0xf6, 0x36, 0x36, 0x36, 0x36, 0x36,
+
0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
+
0x36, 0x36, 0x36, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xfe, 0x06,
+
0x06, 0xf6, 0xf6, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
+
0x36, 0xf6, 0xf6, 0x06, 0x06, 0xfe, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00,
+
0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0xfe, 0xfe, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0xf8, 0xf8, 0x18,
+
0x18, 0xf8, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0x00, 0xf8, 0xf8, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
+
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1f, 0x1f, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xff,
+
0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0x00, 0xff, 0xff, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
+
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1f, 0x1f, 0x18, 0x18, 0x18,
+
0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff,
+
0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18,
+
0x18, 0x18, 0x18, 0xff, 0xff, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
+
0x18, 0x18, 0x18, 0x18, 0x18, 0x1f, 0x1f, 0x18, 0x18, 0x1f, 0x1f, 0x18,
+
0x18, 0x18, 0x18, 0x18, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x37,
+
0x37, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
+
0x36, 0x37, 0x37, 0x30, 0x30, 0x3f, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x3f, 0x30, 0x30, 0x37, 0x37, 0x36,
+
0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0xf7, 0xf7, 0x00,
+
0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+
0x00, 0xff, 0xff, 0x00, 0x00, 0xf7, 0xf7, 0x36, 0x36, 0x36, 0x36, 0x36,
+
0x36, 0x36, 0x36, 0x36, 0x36, 0x37, 0x37, 0x30, 0x30, 0x37, 0x37, 0x36,
+
0x36, 0x36, 0x36, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00,
+
0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x36, 0x36, 0x36,
+
0x36, 0xf7, 0xf7, 0x00, 0x00, 0xf7, 0xf7, 0x36, 0x36, 0x36, 0x36, 0x36,
+
0x18, 0x18, 0x18, 0x18, 0x18, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00,
+
0x00, 0x00, 0x00, 0x00, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0xff,
+
0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+
0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x18, 0x18, 0x18, 0x18, 0x18,
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x36, 0x36, 0x36,
+
0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x3f,
+
0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18,
+
0x18, 0x1f, 0x1f, 0x18, 0x18, 0x1f, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x1f, 0x18, 0x18, 0x1f, 0x1f, 0x18,
+
0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f,
+
0x3f, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
+
0x36, 0x36, 0x36, 0xff, 0xff, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
+
0x18, 0x18, 0x18, 0x18, 0x18, 0xff, 0xff, 0x18, 0x18, 0xff, 0xff, 0x18,
+
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xf8,
+
0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0x00, 0x1f, 0x1f, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
+
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+
0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0,
+
0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
+
0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f,
+
0x0f, 0x0f, 0x0f, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+
0x00, 0x76, 0xd6, 0xdc, 0xc8, 0xc8, 0xdc, 0xd6, 0x76, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0x78, 0xcc, 0xcc, 0xcc, 0xd8, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
+
0xd8, 0xc0, 0xc0, 0x00, 0x00, 0x00, 0xfe, 0xc6, 0xc6, 0xc0, 0xc0, 0xc0,
+
0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+
0x00, 0x7e, 0xfe, 0x24, 0x24, 0x24, 0x24, 0x66, 0xc6, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0xfe, 0xfe, 0xc2, 0x60, 0x30, 0x18, 0x30, 0x60, 0xc2, 0xfe,
+
0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0xc8, 0xcc,
+
0xcc, 0xcc, 0xcc, 0xcc, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+
0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x76, 0x6c, 0x60, 0xc0, 0x00,
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0xfc, 0x98, 0x18, 0x18, 0x18, 0x18,
+
0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x30, 0x30, 0x78, 0xcc, 0xcc,
+
0xcc, 0x78, 0x30, 0x30, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x6c,
+
0xc6, 0xc6, 0xc6, 0xfe, 0xc6, 0xc6, 0xc6, 0x6c, 0x38, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0x38, 0x6c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x6c, 0x6c, 0x6c,
+
0xee, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0xcc, 0x60, 0x30, 0x78, 0xcc,
+
0xcc, 0xcc, 0xcc, 0xcc, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+
0x00, 0x76, 0xbb, 0x99, 0x99, 0xdd, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0x02, 0x06, 0x3c, 0x6c, 0xce, 0xd6, 0xd6, 0xe6, 0x6c, 0x78,
+
0xc0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x30, 0x60, 0xc0, 0xc0, 0xfe,
+
0xc0, 0xc0, 0x60, 0x30, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x6c,
+
0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0x00, 0x00, 0xfe, 0x00, 0x00, 0xfe, 0x00, 0x00, 0xfe, 0x00,
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0xfc,
+
0x30, 0x30, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+
0x60, 0x30, 0x18, 0x0c, 0x18, 0x30, 0x60, 0x00, 0xfc, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0x00, 0x00, 0x18, 0x30, 0x60, 0xc0, 0x60, 0x30, 0x18, 0x00,
+
0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x36, 0x36, 0x30, 0x30, 0x30,
+
0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x18, 0x18, 0x18, 0x18,
+
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xd8, 0xd8, 0x70, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x00, 0xfc, 0x00, 0x30, 0x30, 0x00,
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0xdc, 0x00,
+
0x76, 0xdc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0xcc, 0xcc,
+
0xcc, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30,
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x0c, 0x0c,
+
0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0xcc, 0x6c, 0x3c, 0x1c, 0x0c, 0x00, 0x00,
+
0x00, 0xd8, 0xec, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x00, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x6c, 0x0c, 0x18, 0x30, 0x60, 0x7c,
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+
0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+
0x00, 0x00, 0x00, 0x00
+
};
+
+
static ALWAYS_INLINE uint32_t convert_colour(struct flanterm_context *_ctx, uint32_t colour) {
+
struct flanterm_fb_context *ctx = (void *)_ctx;
+
uint32_t r = (colour >> 16) & 0xff;
+
uint32_t g = (colour >> 8) & 0xff;
+
uint32_t b = colour & 0xff;
+
return (r << ctx->red_mask_shift) | (g << ctx->green_mask_shift) | (b << ctx->blue_mask_shift);
+
}
+
+
static void flanterm_fb_save_state(struct flanterm_context *_ctx) {
+
struct flanterm_fb_context *ctx = (void *)_ctx;
+
ctx->saved_state_text_fg = ctx->text_fg;
+
ctx->saved_state_text_bg = ctx->text_bg;
+
ctx->saved_state_cursor_x = ctx->cursor_x;
+
ctx->saved_state_cursor_y = ctx->cursor_y;
+
}
+
+
static void flanterm_fb_restore_state(struct flanterm_context *_ctx) {
+
struct flanterm_fb_context *ctx = (void *)_ctx;
+
ctx->text_fg = ctx->saved_state_text_fg;
+
ctx->text_bg = ctx->saved_state_text_bg;
+
ctx->cursor_x = ctx->saved_state_cursor_x;
+
ctx->cursor_y = ctx->saved_state_cursor_y;
+
}
+
+
static void flanterm_fb_swap_palette(struct flanterm_context *_ctx) {
+
struct flanterm_fb_context *ctx = (void *)_ctx;
+
uint32_t tmp = ctx->text_bg;
+
ctx->text_bg = ctx->text_fg;
+
ctx->text_fg = tmp;
+
}
+
+
static void plot_char_scaled_canvas(struct flanterm_context *_ctx, struct flanterm_fb_char *c, size_t x, size_t y) {
+
struct flanterm_fb_context *ctx = (void *)_ctx;
+
+
if (x >= _ctx->cols || y >= _ctx->rows) {
+
return;
+
}
+
+
x = ctx->offset_x + x * ctx->glyph_width;
+
y = ctx->offset_y + y * ctx->glyph_height;
+
+
bool *glyph = &ctx->font_bool[c->c * ctx->font_height * ctx->font_width];
+
// naming: fx,fy for font coordinates, gx,gy for glyph coordinates
+
for (size_t gy = 0; gy < ctx->glyph_height; gy++) {
+
uint8_t fy = gy / ctx->font_scale_y;
+
volatile uint32_t *fb_line = ctx->framebuffer + x + (y + gy) * (ctx->pitch / 4);
+
uint32_t *canvas_line = ctx->canvas + x + (y + gy) * ctx->width;
+
bool *glyph_pointer = glyph + (fy * ctx->font_width);
+
for (size_t fx = 0; fx < ctx->font_width; fx++) {
+
for (size_t i = 0; i < ctx->font_scale_x; i++) {
+
size_t gx = ctx->font_scale_x * fx + i;
+
uint32_t bg = c->bg == 0xffffffff ? canvas_line[gx] : c->bg;
+
uint32_t fg = c->fg == 0xffffffff ? canvas_line[gx] : c->fg;
+
fb_line[gx] = *glyph_pointer ? fg : bg;
+
}
+
glyph_pointer++;
+
}
+
}
+
}
+
+
static void plot_char_scaled_uncanvas(struct flanterm_context *_ctx, struct flanterm_fb_char *c, size_t x, size_t y) {
+
struct flanterm_fb_context *ctx = (void *)_ctx;
+
+
if (x >= _ctx->cols || y >= _ctx->rows) {
+
return;
+
}
+
+
uint32_t default_bg = ctx->default_bg;
+
+
uint32_t bg = c->bg == 0xffffffff ? default_bg : c->bg;
+
uint32_t fg = c->fg == 0xffffffff ? default_bg : c->fg;
+
+
x = ctx->offset_x + x * ctx->glyph_width;
+
y = ctx->offset_y + y * ctx->glyph_height;
+
+
bool *glyph = &ctx->font_bool[c->c * ctx->font_height * ctx->font_width];
+
// naming: fx,fy for font coordinates, gx,gy for glyph coordinates
+
for (size_t gy = 0; gy < ctx->glyph_height; gy++) {
+
uint8_t fy = gy / ctx->font_scale_y;
+
volatile uint32_t *fb_line = ctx->framebuffer + x + (y + gy) * (ctx->pitch / 4);
+
bool *glyph_pointer = glyph + (fy * ctx->font_width);
+
for (size_t fx = 0; fx < ctx->font_width; fx++) {
+
for (size_t i = 0; i < ctx->font_scale_x; i++) {
+
size_t gx = ctx->font_scale_x * fx + i;
+
fb_line[gx] = *glyph_pointer ? fg : bg;
+
}
+
glyph_pointer++;
+
}
+
}
+
}
+
+
static void plot_char_unscaled_canvas(struct flanterm_context *_ctx, struct flanterm_fb_char *c, size_t x, size_t y) {
+
struct flanterm_fb_context *ctx = (void *)_ctx;
+
+
if (x >= _ctx->cols || y >= _ctx->rows) {
+
return;
+
}
+
+
x = ctx->offset_x + x * ctx->glyph_width;
+
y = ctx->offset_y + y * ctx->glyph_height;
+
+
bool *glyph = &ctx->font_bool[c->c * ctx->font_height * ctx->font_width];
+
// naming: fx,fy for font coordinates, gx,gy for glyph coordinates
+
for (size_t gy = 0; gy < ctx->glyph_height; gy++) {
+
volatile uint32_t *fb_line = ctx->framebuffer + x + (y + gy) * (ctx->pitch / 4);
+
uint32_t *canvas_line = ctx->canvas + x + (y + gy) * ctx->width;
+
bool *glyph_pointer = glyph + (gy * ctx->font_width);
+
for (size_t fx = 0; fx < ctx->font_width; fx++) {
+
uint32_t bg = c->bg == 0xffffffff ? canvas_line[fx] : c->bg;
+
uint32_t fg = c->fg == 0xffffffff ? canvas_line[fx] : c->fg;
+
fb_line[fx] = *(glyph_pointer++) ? fg : bg;
+
}
+
}
+
}
+
+
static void plot_char_unscaled_uncanvas(struct flanterm_context *_ctx, struct flanterm_fb_char *c, size_t x, size_t y) {
+
struct flanterm_fb_context *ctx = (void *)_ctx;
+
+
if (x >= _ctx->cols || y >= _ctx->rows) {
+
return;
+
}
+
+
uint32_t default_bg = ctx->default_bg;
+
+
uint32_t bg = c->bg == 0xffffffff ? default_bg : c->bg;
+
uint32_t fg = c->fg == 0xffffffff ? default_bg : c->fg;
+
+
x = ctx->offset_x + x * ctx->glyph_width;
+
y = ctx->offset_y + y * ctx->glyph_height;
+
+
bool *glyph = &ctx->font_bool[c->c * ctx->font_height * ctx->font_width];
+
// naming: fx,fy for font coordinates, gx,gy for glyph coordinates
+
for (size_t gy = 0; gy < ctx->glyph_height; gy++) {
+
volatile uint32_t *fb_line = ctx->framebuffer + x + (y + gy) * (ctx->pitch / 4);
+
bool *glyph_pointer = glyph + (gy * ctx->font_width);
+
for (size_t fx = 0; fx < ctx->font_width; fx++) {
+
fb_line[fx] = *(glyph_pointer++) ? fg : bg;
+
}
+
}
+
}
+
+
static inline bool compare_char(struct flanterm_fb_char *a, struct flanterm_fb_char *b) {
+
return !(a->c != b->c || a->bg != b->bg || a->fg != b->fg);
+
}
+
+
static void push_to_queue(struct flanterm_context *_ctx, struct flanterm_fb_char *c, size_t x, size_t y) {
+
struct flanterm_fb_context *ctx = (void *)_ctx;
+
+
if (x >= _ctx->cols || y >= _ctx->rows) {
+
return;
+
}
+
+
size_t i = y * _ctx->cols + x;
+
+
struct flanterm_fb_queue_item *q = ctx->map[i];
+
+
if (q == NULL) {
+
if (compare_char(&ctx->grid[i], c)) {
+
return;
+
}
+
q = &ctx->queue[ctx->queue_i++];
+
q->x = x;
+
q->y = y;
+
ctx->map[i] = q;
+
}
+
+
q->c = *c;
+
}
+
+
static void flanterm_fb_revscroll(struct flanterm_context *_ctx) {
+
struct flanterm_fb_context *ctx = (void *)_ctx;
+
+
for (size_t i = (_ctx->scroll_bottom_margin - 1) * _ctx->cols - 1;
+
i >= _ctx->scroll_top_margin * _ctx->cols; i--) {
+
if (i == (size_t)-1) {
+
break;
+
}
+
struct flanterm_fb_char *c;
+
struct flanterm_fb_queue_item *q = ctx->map[i];
+
if (q != NULL) {
+
c = &q->c;
+
} else {
+
c = &ctx->grid[i];
+
}
+
push_to_queue(_ctx, c, (i + _ctx->cols) % _ctx->cols, (i + _ctx->cols) / _ctx->cols);
+
}
+
+
// Clear the first line of the screen.
+
struct flanterm_fb_char empty;
+
empty.c = ' ';
+
empty.fg = ctx->text_fg;
+
empty.bg = ctx->text_bg;
+
for (size_t i = 0; i < _ctx->cols; i++) {
+
push_to_queue(_ctx, &empty, i, _ctx->scroll_top_margin);
+
}
+
}
+
+
static void flanterm_fb_scroll(struct flanterm_context *_ctx) {
+
struct flanterm_fb_context *ctx = (void *)_ctx;
+
+
for (size_t i = (_ctx->scroll_top_margin + 1) * _ctx->cols;
+
i < _ctx->scroll_bottom_margin * _ctx->cols; i++) {
+
struct flanterm_fb_char *c;
+
struct flanterm_fb_queue_item *q = ctx->map[i];
+
if (q != NULL) {
+
c = &q->c;
+
} else {
+
c = &ctx->grid[i];
+
}
+
push_to_queue(_ctx, c, (i - _ctx->cols) % _ctx->cols, (i - _ctx->cols) / _ctx->cols);
+
}
+
+
// Clear the last line of the screen.
+
struct flanterm_fb_char empty;
+
empty.c = ' ';
+
empty.fg = ctx->text_fg;
+
empty.bg = ctx->text_bg;
+
for (size_t i = 0; i < _ctx->cols; i++) {
+
push_to_queue(_ctx, &empty, i, _ctx->scroll_bottom_margin - 1);
+
}
+
}
+
+
static void flanterm_fb_clear(struct flanterm_context *_ctx, bool move) {
+
struct flanterm_fb_context *ctx = (void *)_ctx;
+
+
struct flanterm_fb_char empty;
+
empty.c = ' ';
+
empty.fg = ctx->text_fg;
+
empty.bg = ctx->text_bg;
+
for (size_t i = 0; i < _ctx->rows * _ctx->cols; i++) {
+
push_to_queue(_ctx, &empty, i % _ctx->cols, i / _ctx->cols);
+
}
+
+
if (move) {
+
ctx->cursor_x = 0;
+
ctx->cursor_y = 0;
+
}
+
}
+
+
static void flanterm_fb_set_cursor_pos(struct flanterm_context *_ctx, size_t x, size_t y) {
+
struct flanterm_fb_context *ctx = (void *)_ctx;
+
+
if (x >= _ctx->cols) {
+
if ((int)x < 0) {
+
x = 0;
+
} else {
+
x = _ctx->cols - 1;
+
}
+
}
+
if (y >= _ctx->rows) {
+
if ((int)y < 0) {
+
y = 0;
+
} else {
+
y = _ctx->rows - 1;
+
}
+
}
+
ctx->cursor_x = x;
+
ctx->cursor_y = y;
+
}
+
+
static void flanterm_fb_get_cursor_pos(struct flanterm_context *_ctx, size_t *x, size_t *y) {
+
struct flanterm_fb_context *ctx = (void *)_ctx;
+
+
*x = ctx->cursor_x >= _ctx->cols ? _ctx->cols - 1 : ctx->cursor_x;
+
*y = ctx->cursor_y >= _ctx->rows ? _ctx->rows - 1 : ctx->cursor_y;
+
}
+
+
static void flanterm_fb_move_character(struct flanterm_context *_ctx, size_t new_x, size_t new_y, size_t old_x, size_t old_y) {
+
struct flanterm_fb_context *ctx = (void *)_ctx;
+
+
if (old_x >= _ctx->cols || old_y >= _ctx->rows
+
|| new_x >= _ctx->cols || new_y >= _ctx->rows) {
+
return;
+
}
+
+
size_t i = old_x + old_y * _ctx->cols;
+
+
struct flanterm_fb_char *c;
+
struct flanterm_fb_queue_item *q = ctx->map[i];
+
if (q != NULL) {
+
c = &q->c;
+
} else {
+
c = &ctx->grid[i];
+
}
+
+
push_to_queue(_ctx, c, new_x, new_y);
+
}
+
+
static void flanterm_fb_set_text_fg(struct flanterm_context *_ctx, size_t fg) {
+
struct flanterm_fb_context *ctx = (void *)_ctx;
+
+
ctx->text_fg = ctx->ansi_colours[fg];
+
}
+
+
static void flanterm_fb_set_text_bg(struct flanterm_context *_ctx, size_t bg) {
+
struct flanterm_fb_context *ctx = (void *)_ctx;
+
+
ctx->text_bg = ctx->ansi_colours[bg];
+
}
+
+
static void flanterm_fb_set_text_fg_bright(struct flanterm_context *_ctx, size_t fg) {
+
struct flanterm_fb_context *ctx = (void *)_ctx;
+
+
ctx->text_fg = ctx->ansi_bright_colours[fg];
+
}
+
+
static void flanterm_fb_set_text_bg_bright(struct flanterm_context *_ctx, size_t bg) {
+
struct flanterm_fb_context *ctx = (void *)_ctx;
+
+
ctx->text_bg = ctx->ansi_bright_colours[bg];
+
}
+
+
static void flanterm_fb_set_text_fg_rgb(struct flanterm_context *_ctx, uint32_t fg) {
+
struct flanterm_fb_context *ctx = (void *)_ctx;
+
+
ctx->text_fg = convert_colour(_ctx, fg);
+
}
+
+
static void flanterm_fb_set_text_bg_rgb(struct flanterm_context *_ctx, uint32_t bg) {
+
struct flanterm_fb_context *ctx = (void *)_ctx;
+
+
ctx->text_bg = convert_colour(_ctx, bg);
+
}
+
+
static void flanterm_fb_set_text_fg_default(struct flanterm_context *_ctx) {
+
struct flanterm_fb_context *ctx = (void *)_ctx;
+
+
ctx->text_fg = ctx->default_fg;
+
}
+
+
static void flanterm_fb_set_text_bg_default(struct flanterm_context *_ctx) {
+
struct flanterm_fb_context *ctx = (void *)_ctx;
+
+
ctx->text_bg = 0xffffffff;
+
}
+
+
static void flanterm_fb_set_text_fg_default_bright(struct flanterm_context *_ctx) {
+
struct flanterm_fb_context *ctx = (void *)_ctx;
+
+
ctx->text_fg = ctx->default_fg_bright;
+
}
+
+
static void flanterm_fb_set_text_bg_default_bright(struct flanterm_context *_ctx) {
+
struct flanterm_fb_context *ctx = (void *)_ctx;
+
+
ctx->text_bg = ctx->default_bg_bright;
+
}
+
+
static void draw_cursor(struct flanterm_context *_ctx) {
+
struct flanterm_fb_context *ctx = (void *)_ctx;
+
+
if (ctx->cursor_x >= _ctx->cols || ctx->cursor_y >= _ctx->rows) {
+
return;
+
}
+
+
size_t i = ctx->cursor_x + ctx->cursor_y * _ctx->cols;
+
+
struct flanterm_fb_char c;
+
struct flanterm_fb_queue_item *q = ctx->map[i];
+
if (q != NULL) {
+
c = q->c;
+
} else {
+
c = ctx->grid[i];
+
}
+
uint32_t tmp = c.fg;
+
c.fg = c.bg;
+
c.bg = tmp;
+
ctx->plot_char(_ctx, &c, ctx->cursor_x, ctx->cursor_y);
+
if (q != NULL) {
+
ctx->grid[i] = q->c;
+
ctx->map[i] = NULL;
+
}
+
}
+
+
static void flanterm_fb_double_buffer_flush(struct flanterm_context *_ctx) {
+
struct flanterm_fb_context *ctx = (void *)_ctx;
+
+
if (_ctx->cursor_enabled) {
+
draw_cursor(_ctx);
+
}
+
+
for (size_t i = 0; i < ctx->queue_i; i++) {
+
struct flanterm_fb_queue_item *q = &ctx->queue[i];
+
size_t offset = q->y * _ctx->cols + q->x;
+
if (ctx->map[offset] == NULL) {
+
continue;
+
}
+
ctx->plot_char(_ctx, &q->c, q->x, q->y);
+
ctx->grid[offset] = q->c;
+
ctx->map[offset] = NULL;
+
}
+
+
if ((ctx->old_cursor_x != ctx->cursor_x || ctx->old_cursor_y != ctx->cursor_y) || _ctx->cursor_enabled == false) {
+
if (ctx->old_cursor_x < _ctx->cols && ctx->old_cursor_y < _ctx->rows) {
+
ctx->plot_char(_ctx, &ctx->grid[ctx->old_cursor_x + ctx->old_cursor_y * _ctx->cols], ctx->old_cursor_x, ctx->old_cursor_y);
+
}
+
}
+
+
ctx->old_cursor_x = ctx->cursor_x;
+
ctx->old_cursor_y = ctx->cursor_y;
+
+
ctx->queue_i = 0;
+
}
+
+
static void flanterm_fb_raw_putchar(struct flanterm_context *_ctx, uint8_t c) {
+
struct flanterm_fb_context *ctx = (void *)_ctx;
+
+
if (ctx->cursor_x >= _ctx->cols && (ctx->cursor_y < _ctx->scroll_bottom_margin - 1 || _ctx->scroll_enabled)) {
+
ctx->cursor_x = 0;
+
ctx->cursor_y++;
+
if (ctx->cursor_y == _ctx->scroll_bottom_margin) {
+
ctx->cursor_y--;
+
flanterm_fb_scroll(_ctx);
+
}
+
if (ctx->cursor_y >= _ctx->cols) {
+
ctx->cursor_y = _ctx->cols - 1;
+
}
+
}
+
+
struct flanterm_fb_char ch;
+
ch.c = c;
+
ch.fg = ctx->text_fg;
+
ch.bg = ctx->text_bg;
+
push_to_queue(_ctx, &ch, ctx->cursor_x++, ctx->cursor_y);
+
}
+
+
static void flanterm_fb_full_refresh(struct flanterm_context *_ctx) {
+
struct flanterm_fb_context *ctx = (void *)_ctx;
+
+
uint32_t default_bg = ctx->default_bg;
+
+
for (size_t y = 0; y < ctx->height; y++) {
+
for (size_t x = 0; x < ctx->width; x++) {
+
if (ctx->canvas != NULL) {
+
ctx->framebuffer[y * (ctx->pitch / sizeof(uint32_t)) + x] = ctx->canvas[y * ctx->width + x];
+
} else {
+
ctx->framebuffer[y * (ctx->pitch / sizeof(uint32_t)) + x] = default_bg;
+
}
+
}
+
}
+
+
for (size_t i = 0; i < (size_t)_ctx->rows * _ctx->cols; i++) {
+
size_t x = i % _ctx->cols;
+
size_t y = i / _ctx->cols;
+
+
ctx->plot_char(_ctx, &ctx->grid[i], x, y);
+
}
+
+
if (_ctx->cursor_enabled) {
+
draw_cursor(_ctx);
+
}
+
}
+
+
static void flanterm_fb_deinit(struct flanterm_context *_ctx, void (*_free)(void *, size_t)) {
+
struct flanterm_fb_context *ctx = (void *)_ctx;
+
+
if (_free == NULL) {
+
#ifndef FLANTERM_FB_DISABLE_BUMP_ALLOC
+
if (bump_allocated_instance == true) {
+
bump_alloc_ptr = 0;
+
bump_allocated_instance = false;
+
}
+
#endif
+
return;
+
}
+
+
_free(ctx->font_bits, ctx->font_bits_size);
+
_free(ctx->font_bool, ctx->font_bool_size);
+
_free(ctx->grid, ctx->grid_size);
+
_free(ctx->queue, ctx->queue_size);
+
_free(ctx->map, ctx->map_size);
+
+
if (ctx->canvas != NULL) {
+
_free(ctx->canvas, ctx->canvas_size);
+
}
+
+
_free(ctx, sizeof(struct flanterm_fb_context));
+
}
+
+
struct flanterm_context *flanterm_fb_init(
+
void *(*_malloc)(size_t),
+
void (*_free)(void *, size_t),
+
uint32_t *framebuffer, size_t width, size_t height, size_t pitch,
+
uint8_t red_mask_size, uint8_t red_mask_shift,
+
uint8_t green_mask_size, uint8_t green_mask_shift,
+
uint8_t blue_mask_size, uint8_t blue_mask_shift,
+
uint32_t *canvas,
+
uint32_t *ansi_colours, uint32_t *ansi_bright_colours,
+
uint32_t *default_bg, uint32_t *default_fg,
+
uint32_t *default_bg_bright, uint32_t *default_fg_bright,
+
void *font, size_t font_width, size_t font_height, size_t font_spacing,
+
size_t font_scale_x, size_t font_scale_y,
+
size_t margin
+
) {
+
if (font_scale_x == 0 || font_scale_y == 0) {
+
font_scale_x = 1;
+
font_scale_y = 1;
+
if (width >= (1920 + 1920 / 3) && height >= (1080 + 1080 / 3)) {
+
font_scale_x = 2;
+
font_scale_y = 2;
+
}
+
if (width >= (3840 + 3840 / 3) && height >= (2160 + 2160 / 3)) {
+
font_scale_x = 4;
+
font_scale_y = 4;
+
}
+
}
+
+
if (red_mask_size < 8 || red_mask_size != green_mask_size || red_mask_size != blue_mask_size) {
+
return NULL;
+
}
+
+
if (_malloc == NULL) {
+
#ifndef FLANTERM_FB_DISABLE_BUMP_ALLOC
+
if (bump_allocated_instance == true) {
+
return NULL;
+
}
+
_malloc = bump_alloc;
+
// Limit terminal size if needed
+
if (width > FLANTERM_FB_WIDTH_LIMIT || height > FLANTERM_FB_HEIGHT_LIMIT) {
+
size_t width_limit = width > FLANTERM_FB_WIDTH_LIMIT ? FLANTERM_FB_WIDTH_LIMIT : width;
+
size_t height_limit = height > FLANTERM_FB_HEIGHT_LIMIT ? FLANTERM_FB_HEIGHT_LIMIT : height;
+
+
framebuffer = (uint32_t *)((uintptr_t)framebuffer + ((((height / 2) - (height_limit / 2)) * pitch) + (((width / 2) - (width_limit / 2)) * 4)));
+
+
width = width_limit;
+
height = height_limit;
+
}
+
+
// Force disable canvas
+
canvas = NULL;
+
#else
+
return NULL;
+
#endif
+
}
+
+
struct flanterm_fb_context *ctx = NULL;
+
ctx = _malloc(sizeof(struct flanterm_fb_context));
+
if (ctx == NULL) {
+
goto fail;
+
}
+
+
struct flanterm_context *_ctx = (void *)ctx;
+
memset(ctx, 0, sizeof(struct flanterm_fb_context));
+
+
ctx->red_mask_size = red_mask_size;
+
ctx->red_mask_shift = red_mask_shift + (red_mask_size - 8);
+
ctx->green_mask_size = green_mask_size;
+
ctx->green_mask_shift = green_mask_shift + (green_mask_size - 8);
+
ctx->blue_mask_size = blue_mask_size;
+
ctx->blue_mask_shift = blue_mask_shift + (blue_mask_size - 8);
+
+
if (ansi_colours != NULL) {
+
for (size_t i = 0; i < 8; i++) {
+
ctx->ansi_colours[i] = convert_colour(_ctx, ansi_colours[i]);
+
}
+
} else {
+
ctx->ansi_colours[0] = convert_colour(_ctx, 0x00000000); // black
+
ctx->ansi_colours[1] = convert_colour(_ctx, 0x00aa0000); // red
+
ctx->ansi_colours[2] = convert_colour(_ctx, 0x0000aa00); // green
+
ctx->ansi_colours[3] = convert_colour(_ctx, 0x00aa5500); // brown
+
ctx->ansi_colours[4] = convert_colour(_ctx, 0x000000aa); // blue
+
ctx->ansi_colours[5] = convert_colour(_ctx, 0x00aa00aa); // magenta
+
ctx->ansi_colours[6] = convert_colour(_ctx, 0x0000aaaa); // cyan
+
ctx->ansi_colours[7] = convert_colour(_ctx, 0x00aaaaaa); // grey
+
}
+
+
if (ansi_bright_colours != NULL) {
+
for (size_t i = 0; i < 8; i++) {
+
ctx->ansi_bright_colours[i] = convert_colour(_ctx, ansi_bright_colours[i]);
+
}
+
} else {
+
ctx->ansi_bright_colours[0] = convert_colour(_ctx, 0x00555555); // black
+
ctx->ansi_bright_colours[1] = convert_colour(_ctx, 0x00ff5555); // red
+
ctx->ansi_bright_colours[2] = convert_colour(_ctx, 0x0055ff55); // green
+
ctx->ansi_bright_colours[3] = convert_colour(_ctx, 0x00ffff55); // brown
+
ctx->ansi_bright_colours[4] = convert_colour(_ctx, 0x005555ff); // blue
+
ctx->ansi_bright_colours[5] = convert_colour(_ctx, 0x00ff55ff); // magenta
+
ctx->ansi_bright_colours[6] = convert_colour(_ctx, 0x0055ffff); // cyan
+
ctx->ansi_bright_colours[7] = convert_colour(_ctx, 0x00ffffff); // grey
+
}
+
+
if (default_bg != NULL) {
+
ctx->default_bg = convert_colour(_ctx, *default_bg);
+
} else {
+
ctx->default_bg = 0x00000000; // background (black)
+
}
+
+
if (default_fg != NULL) {
+
ctx->default_fg = convert_colour(_ctx, *default_fg);
+
} else {
+
ctx->default_fg = convert_colour(_ctx, 0x00aaaaaa); // foreground (grey)
+
}
+
+
if (default_bg_bright != NULL) {
+
ctx->default_bg_bright = convert_colour(_ctx, *default_bg_bright);
+
} else {
+
ctx->default_bg_bright = convert_colour(_ctx, 0x00555555); // background (black)
+
}
+
+
if (default_fg_bright != NULL) {
+
ctx->default_fg_bright = convert_colour(_ctx, *default_fg_bright);
+
} else {
+
ctx->default_fg_bright = convert_colour(_ctx, 0x00ffffff); // foreground (grey)
+
}
+
+
ctx->text_fg = ctx->default_fg;
+
ctx->text_bg = 0xffffffff;
+
+
ctx->framebuffer = (void *)framebuffer;
+
ctx->width = width;
+
ctx->height = height;
+
ctx->pitch = pitch;
+
+
#define FONT_BYTES ((font_width * font_height * FLANTERM_FB_FONT_GLYPHS) / 8)
+
+
if (font != NULL) {
+
ctx->font_width = font_width;
+
ctx->font_height = font_height;
+
ctx->font_bits_size = FONT_BYTES;
+
ctx->font_bits = _malloc(ctx->font_bits_size);
+
if (ctx->font_bits == NULL) {
+
goto fail;
+
}
+
memcpy(ctx->font_bits, font, ctx->font_bits_size);
+
} else {
+
ctx->font_width = font_width = 8;
+
ctx->font_height = font_height = 16;
+
ctx->font_bits_size = FONT_BYTES;
+
font_spacing = 1;
+
ctx->font_bits = _malloc(ctx->font_bits_size);
+
if (ctx->font_bits == NULL) {
+
goto fail;
+
}
+
memcpy(ctx->font_bits, builtin_font, ctx->font_bits_size);
+
}
+
+
#undef FONT_BYTES
+
+
ctx->font_width += font_spacing;
+
+
ctx->font_bool_size = FLANTERM_FB_FONT_GLYPHS * font_height * ctx->font_width * sizeof(bool);
+
ctx->font_bool = _malloc(ctx->font_bool_size);
+
if (ctx->font_bool == NULL) {
+
goto fail;
+
}
+
+
for (size_t i = 0; i < FLANTERM_FB_FONT_GLYPHS; i++) {
+
uint8_t *glyph = &ctx->font_bits[i * font_height];
+
+
for (size_t y = 0; y < font_height; y++) {
+
// NOTE: the characters in VGA fonts are always one byte wide.
+
// 9 dot wide fonts have 8 dots and one empty column, except
+
// characters 0xC0-0xDF replicate column 9.
+
for (size_t x = 0; x < 8; x++) {
+
size_t offset = i * font_height * ctx->font_width + y * ctx->font_width + x;
+
+
if ((glyph[y] & (0x80 >> x))) {
+
ctx->font_bool[offset] = true;
+
} else {
+
ctx->font_bool[offset] = false;
+
}
+
}
+
// fill columns above 8 like VGA Line Graphics Mode does
+
for (size_t x = 8; x < ctx->font_width; x++) {
+
size_t offset = i * font_height * ctx->font_width + y * ctx->font_width + x;
+
+
if (i >= 0xc0 && i <= 0xdf) {
+
ctx->font_bool[offset] = (glyph[y] & 1);
+
} else {
+
ctx->font_bool[offset] = false;
+
}
+
}
+
}
+
}
+
+
ctx->font_scale_x = font_scale_x;
+
ctx->font_scale_y = font_scale_y;
+
+
ctx->glyph_width = ctx->font_width * font_scale_x;
+
ctx->glyph_height = font_height * font_scale_y;
+
+
_ctx->cols = (ctx->width - margin * 2) / ctx->glyph_width;
+
_ctx->rows = (ctx->height - margin * 2) / ctx->glyph_height;
+
+
ctx->offset_x = margin + ((ctx->width - margin * 2) % ctx->glyph_width) / 2;
+
ctx->offset_y = margin + ((ctx->height - margin * 2) % ctx->glyph_height) / 2;
+
+
ctx->grid_size = _ctx->rows * _ctx->cols * sizeof(struct flanterm_fb_char);
+
ctx->grid = _malloc(ctx->grid_size);
+
if (ctx->grid == NULL) {
+
goto fail;
+
}
+
for (size_t i = 0; i < _ctx->rows * _ctx->cols; i++) {
+
ctx->grid[i].c = ' ';
+
ctx->grid[i].fg = ctx->text_fg;
+
ctx->grid[i].bg = ctx->text_bg;
+
}
+
+
ctx->queue_size = _ctx->rows * _ctx->cols * sizeof(struct flanterm_fb_queue_item);
+
ctx->queue = _malloc(ctx->queue_size);
+
if (ctx->queue == NULL) {
+
goto fail;
+
}
+
ctx->queue_i = 0;
+
memset(ctx->queue, 0, ctx->queue_size);
+
+
ctx->map_size = _ctx->rows * _ctx->cols * sizeof(struct flanterm_fb_queue_item *);
+
ctx->map = _malloc(ctx->map_size);
+
if (ctx->map == NULL) {
+
goto fail;
+
}
+
memset(ctx->map, 0, ctx->map_size);
+
+
if (canvas != NULL) {
+
ctx->canvas_size = ctx->width * ctx->height * sizeof(uint32_t);
+
ctx->canvas = _malloc(ctx->canvas_size);
+
if (ctx->canvas == NULL) {
+
goto fail;
+
}
+
for (size_t i = 0; i < ctx->width * ctx->height; i++) {
+
ctx->canvas[i] = convert_colour(_ctx, canvas[i]);
+
}
+
}
+
+
if (font_scale_x == 1 && font_scale_y == 1) {
+
if (canvas == NULL) {
+
ctx->plot_char = plot_char_unscaled_uncanvas;
+
} else {
+
ctx->plot_char = plot_char_unscaled_canvas;
+
}
+
} else {
+
if (canvas == NULL) {
+
ctx->plot_char = plot_char_scaled_uncanvas;
+
} else {
+
ctx->plot_char = plot_char_scaled_canvas;
+
}
+
}
+
+
_ctx->raw_putchar = flanterm_fb_raw_putchar;
+
_ctx->clear = flanterm_fb_clear;
+
_ctx->set_cursor_pos = flanterm_fb_set_cursor_pos;
+
_ctx->get_cursor_pos = flanterm_fb_get_cursor_pos;
+
_ctx->set_text_fg = flanterm_fb_set_text_fg;
+
_ctx->set_text_bg = flanterm_fb_set_text_bg;
+
_ctx->set_text_fg_bright = flanterm_fb_set_text_fg_bright;
+
_ctx->set_text_bg_bright = flanterm_fb_set_text_bg_bright;
+
_ctx->set_text_fg_rgb = flanterm_fb_set_text_fg_rgb;
+
_ctx->set_text_bg_rgb = flanterm_fb_set_text_bg_rgb;
+
_ctx->set_text_fg_default = flanterm_fb_set_text_fg_default;
+
_ctx->set_text_bg_default = flanterm_fb_set_text_bg_default;
+
_ctx->set_text_fg_default_bright = flanterm_fb_set_text_fg_default_bright;
+
_ctx->set_text_bg_default_bright = flanterm_fb_set_text_bg_default_bright;
+
_ctx->move_character = flanterm_fb_move_character;
+
_ctx->scroll = flanterm_fb_scroll;
+
_ctx->revscroll = flanterm_fb_revscroll;
+
_ctx->swap_palette = flanterm_fb_swap_palette;
+
_ctx->save_state = flanterm_fb_save_state;
+
_ctx->restore_state = flanterm_fb_restore_state;
+
_ctx->double_buffer_flush = flanterm_fb_double_buffer_flush;
+
_ctx->full_refresh = flanterm_fb_full_refresh;
+
_ctx->deinit = flanterm_fb_deinit;
+
+
flanterm_context_reinit(_ctx);
+
flanterm_fb_full_refresh(_ctx);
+
+
#ifndef FLANTERM_FB_DISABLE_BUMP_ALLOC
+
if (_malloc == bump_alloc) {
+
bump_allocated_instance = true;
+
}
+
#endif
+
+
return _ctx;
+
+
fail:
+
if (ctx == NULL) {
+
return NULL;
+
}
+
+
#ifndef FLANTERM_FB_DISABLE_BUMP_ALLOC
+
if (_malloc == bump_alloc) {
+
bump_alloc_ptr = 0;
+
return NULL;
+
}
+
#endif
+
+
if (_free == NULL) {
+
return NULL;
+
}
+
+
if (ctx->canvas != NULL) {
+
_free(ctx->canvas, ctx->canvas_size);
+
}
+
if (ctx->map != NULL) {
+
_free(ctx->map, ctx->map_size);
+
}
+
if (ctx->queue != NULL) {
+
_free(ctx->queue, ctx->queue_size);
+
}
+
if (ctx->grid != NULL) {
+
_free(ctx->grid, ctx->grid_size);
+
}
+
if (ctx->font_bool != NULL) {
+
_free(ctx->font_bool, ctx->font_bool_size);
+
}
+
if (ctx->font_bits != NULL) {
+
_free(ctx->font_bits, ctx->font_bits_size);
+
}
+
if (ctx != NULL) {
+
_free(ctx, sizeof(struct flanterm_fb_context));
+
}
+
+
return NULL;
+
}
+68
src/flanterm_backends/fb.h
···
+
/* Copyright (C) 2022-2025 mintsuki and contributors.
+
*
+
* Redistribution and use in source and binary forms, with or without
+
* modification, are permitted provided that the following conditions are met:
+
*
+
* 1. Redistributions of source code must retain the above copyright notice,
+
* this list of conditions and the following disclaimer.
+
*
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
+
* this list of conditions and the following disclaimer in the documentation
+
* and/or other materials provided with the distribution.
+
*
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+
* POSSIBILITY OF SUCH DAMAGE.
+
*/
+
+
#ifndef FLANTERM_FB_H
+
#define FLANTERM_FB_H 1
+
+
#include <stdint.h>
+
#include <stddef.h>
+
#include <stdbool.h>
+
+
#ifdef __cplusplus
+
extern "C" {
+
#endif
+
+
#include "../flanterm.h"
+
+
#ifdef FLANTERM_IN_FLANTERM
+
+
#include "fb_private.h"
+
+
#endif
+
+
struct flanterm_context *flanterm_fb_init(
+
/* If _malloc and _free are nulled, use the bump allocated instance (1 use only). */
+
void *(*_malloc)(size_t size),
+
void (*_free)(void *ptr, size_t size),
+
uint32_t *framebuffer, size_t width, size_t height, size_t pitch,
+
uint8_t red_mask_size, uint8_t red_mask_shift,
+
uint8_t green_mask_size, uint8_t green_mask_shift,
+
uint8_t blue_mask_size, uint8_t blue_mask_shift,
+
uint32_t *canvas, /* If nulled, no canvas. */
+
uint32_t *ansi_colours, uint32_t *ansi_bright_colours, /* If nulled, default. */
+
uint32_t *default_bg, uint32_t *default_fg, /* If nulled, default. */
+
uint32_t *default_bg_bright, uint32_t *default_fg_bright, /* If nulled, default. */
+
/* If font is null, use default font and font_width and font_height ignored. */
+
void *font, size_t font_width, size_t font_height, size_t font_spacing,
+
/* If scale_x and scale_y are 0, automatically scale font based on resolution. */
+
size_t font_scale_x, size_t font_scale_y,
+
size_t margin
+
);
+
+
#ifdef __cplusplus
+
}
+
#endif
+
+
#endif
+121
src/flanterm_backends/fb_private.h
···
+
/* Copyright (C) 2022-2025 mintsuki and contributors.
+
*
+
* Redistribution and use in source and binary forms, with or without
+
* modification, are permitted provided that the following conditions are met:
+
*
+
* 1. Redistributions of source code must retain the above copyright notice,
+
* this list of conditions and the following disclaimer.
+
*
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
+
* this list of conditions and the following disclaimer in the documentation
+
* and/or other materials provided with the distribution.
+
*
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+
* POSSIBILITY OF SUCH DAMAGE.
+
*/
+
+
#ifndef FLANTERM_FB_PRIVATE_H
+
#define FLANTERM_FB_PRIVATE_H 1
+
+
#ifndef FLANTERM_IN_FLANTERM
+
#error "Do not use fb_private.h. Use interfaces defined in fb.h only."
+
#endif
+
+
#include <stdint.h>
+
#include <stddef.h>
+
#include <stdbool.h>
+
+
#ifdef __cplusplus
+
extern "C" {
+
#endif
+
+
#define FLANTERM_FB_FONT_GLYPHS 256
+
+
struct flanterm_fb_char {
+
uint32_t c;
+
uint32_t fg;
+
uint32_t bg;
+
};
+
+
struct flanterm_fb_queue_item {
+
size_t x, y;
+
struct flanterm_fb_char c;
+
};
+
+
struct flanterm_fb_context {
+
struct flanterm_context term;
+
+
void (*plot_char)(struct flanterm_context *ctx, struct flanterm_fb_char *c, size_t x, size_t y);
+
+
size_t font_width;
+
size_t font_height;
+
size_t glyph_width;
+
size_t glyph_height;
+
+
size_t font_scale_x;
+
size_t font_scale_y;
+
+
size_t offset_x, offset_y;
+
+
volatile uint32_t *framebuffer;
+
size_t pitch;
+
size_t width;
+
size_t height;
+
size_t bpp;
+
+
uint8_t red_mask_size, red_mask_shift;
+
uint8_t green_mask_size, green_mask_shift;
+
uint8_t blue_mask_size, blue_mask_shift;
+
+
size_t font_bits_size;
+
uint8_t *font_bits;
+
size_t font_bool_size;
+
bool *font_bool;
+
+
uint32_t ansi_colours[8];
+
uint32_t ansi_bright_colours[8];
+
uint32_t default_fg, default_bg;
+
uint32_t default_fg_bright, default_bg_bright;
+
+
size_t canvas_size;
+
uint32_t *canvas;
+
+
size_t grid_size;
+
size_t queue_size;
+
size_t map_size;
+
+
struct flanterm_fb_char *grid;
+
+
struct flanterm_fb_queue_item *queue;
+
size_t queue_i;
+
+
struct flanterm_fb_queue_item **map;
+
+
uint32_t text_fg;
+
uint32_t text_bg;
+
size_t cursor_x;
+
size_t cursor_y;
+
+
uint32_t saved_state_text_fg;
+
uint32_t saved_state_text_bg;
+
size_t saved_state_cursor_x;
+
size_t saved_state_cursor_y;
+
+
size_t old_cursor_x;
+
size_t old_cursor_y;
+
};
+
+
#ifdef __cplusplus
+
}
+
#endif
+
+
#endif
+1
src/flanterm_private.h
···
bool reverse_video;
bool dec_private;
bool insert_mode;
+
bool csi_unhandled;
uint64_t code_point;
size_t unicode_remaining;
uint8_t g_select;
+92
src/root.zig
···
+
pub const Colors = @import("colors.zig");
+
const std = @import("std");
+
const c = @cImport({
+
@cInclude("flanterm.h");
+
@cInclude("flanterm_backends/fb.h");
+
});
+
+
pub const Context = struct {
+
backing: ?*c.struct_flanterm_context,
+
+
const Self = @This();
+
+
/// Initialize the context
+
pub fn init(
+
args: struct {
+
// Malloc and Free
+
malloc: ?*const fn (usize) callconv(.c) ?*anyopaque = null,
+
free: ?*const fn (?*anyopaque, usize) callconv(.c) void = null,
+
// Framebuffer Info (required)
+
fb: [*]u32,
+
width: usize,
+
height: usize,
+
pitch: usize,
+
// Framebuffer Color Info
+
red_mask_size: u8,
+
red_mask_shift: u8,
+
green_mask_size: u8,
+
green_mask_shift: u8,
+
blue_mask_size: u8,
+
blue_mask_shift: u8,
+
// Canvas (scratch space)
+
canvas: ?[*]u32 = null,
+
// Color Pointers
+
ansi_colours: *Colors.Palette = &Colors.default_colors,
+
ansi_bright_colours: *Colors.Palette = &Colors.default_bold_colors,
+
// Default Color choices
+
default_bg: *u32 = &Colors.default_colors.black,
+
default_fg: *u32 = &Colors.default_colors.cyan,
+
default_bg_bright: *u32 = &Colors.default_bold_colors.black,
+
default_fg_bright: *u32 = &Colors.default_bold_colors.cyan,
+
// Font Information
+
font: ?*anyopaque = null,
+
font_width: usize = 0,
+
font_height: usize = 0,
+
font_spacing: usize = 1,
+
// Font Scale values
+
font_scale_x: usize = 0,
+
font_scale_y: usize = 0,
+
// Margin
+
margin: usize = 0,
+
},
+
) Self {
+
const ansi_colours: [*]u32 = @ptrCast(args.ansi_colours);
+
const ansi_bright_colours: [*]u32 = @ptrCast(args.ansi_bright_colours);
+
const ctx = c.flanterm_fb_init(
+
args.malloc,
+
args.free,
+
args.fb,
+
args.width,
+
args.height,
+
args.pitch,
+
args.red_mask_size,
+
args.red_mask_shift,
+
args.green_mask_size,
+
args.green_mask_shift,
+
args.blue_mask_size,
+
args.blue_mask_shift,
+
args.canvas,
+
ansi_colours,
+
ansi_bright_colours,
+
args.default_bg,
+
args.default_fg,
+
args.default_bg_bright,
+
args.default_fg_bright,
+
args.font,
+
args.font_width,
+
args.font_height,
+
args.font_spacing,
+
args.font_scale_x,
+
args.font_scale_y,
+
args.margin,
+
);
+
return .{
+
.backing = ctx,
+
};
+
}
+
+
/// Write to the console
+
pub fn write_slice(self: *Self, buf: []u8) void {
+
c.flanterm_write(self.backing, buf.ptr, buf.len);
+
}
+
};