[Teton] Load a font file and write a character to the screen.
This commit is contained in:
parent
96063126cb
commit
fe44804dd9
19 changed files with 412 additions and 17 deletions
|
|
@ -1,5 +1,6 @@
|
|||
add_executable(teton
|
||||
framebuffer/framebuffer.cpp
|
||||
framebuffer/psf.cpp
|
||||
teton.cpp
|
||||
)
|
||||
|
||||
|
|
@ -10,6 +11,7 @@ target_include_directories(teton
|
|||
target_link_libraries(teton
|
||||
glacier
|
||||
mammoth
|
||||
victoriafalls_yunq
|
||||
yellowstone_yunq
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#include "framebuffer/framebuffer.h"
|
||||
|
||||
Framebuffer::Framebuffer(const FramebufferInfo& info) : fb_info_(info) {
|
||||
Framebuffer::Framebuffer(const FramebufferInfo& info)
|
||||
: fb_info_(info), cursor_pos_(0) {
|
||||
uint64_t buff_size_bytes = fb_info_.height() * fb_info_.pitch();
|
||||
fb_memory_ = OwnedMemoryRegion::DirectPhysical(fb_info_.address_phys(),
|
||||
buff_size_bytes);
|
||||
|
|
@ -11,3 +12,18 @@ void Framebuffer::DrawPixel(uint32_t row, uint32_t col, uint32_t pixel) {
|
|||
// Div by 4 because pitch is in bytes and fb_ is a 32bit array.
|
||||
fb_[(row * fb_info_.pitch() / 4) + col] = pixel;
|
||||
}
|
||||
|
||||
void Framebuffer::DrawGlyph(uint8_t* glyph) {
|
||||
uint32_t gl_width = 8;
|
||||
uint32_t gl_height = 16;
|
||||
|
||||
for (uint8_t r = 0; r < gl_height; r++) {
|
||||
for (uint8_t c = 0; c < gl_width; c++) {
|
||||
if (((glyph[r] >> c) % 2) == 1) {
|
||||
DrawPixel(r, gl_width - c - 1, 0xFFFF'FFFF);
|
||||
} else {
|
||||
DrawPixel(r, gl_width - c - 1, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@ class Framebuffer {
|
|||
|
||||
void DrawPixel(uint32_t row, uint32_t col, uint32_t pixel);
|
||||
|
||||
void DrawGlyph(uint8_t* glyph);
|
||||
|
||||
private:
|
||||
// FIXME: Implement Yunq copy or move so we
|
||||
// don't have to store a reference here.
|
||||
|
|
@ -16,4 +18,5 @@ class Framebuffer {
|
|||
|
||||
OwnedMemoryRegion fb_memory_;
|
||||
uint32_t* fb_;
|
||||
uint32_t cursor_pos_;
|
||||
};
|
||||
|
|
|
|||
46
sys/teton/framebuffer/psf.cpp
Normal file
46
sys/teton/framebuffer/psf.cpp
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
#include "framebuffer/psf.h"
|
||||
|
||||
#include <glacier/memory/move.h>
|
||||
#include <mammoth/debug.h>
|
||||
|
||||
namespace {
|
||||
|
||||
const uint32_t kMagic = 0x864AB572;
|
||||
|
||||
}
|
||||
|
||||
Psf::Psf(OwnedMemoryRegion&& psf_file)
|
||||
: psf_file_(glcr::Move(psf_file)),
|
||||
header_(reinterpret_cast<PsfHeader*>(psf_file_.vaddr())) {
|
||||
EnsureValid();
|
||||
}
|
||||
|
||||
void Psf::DumpHeader() {
|
||||
dbgln("Magic: {x}", header_->magic);
|
||||
dbgln("Version: {x}", header_->version);
|
||||
dbgln("Header Sz: {x}", header_->headersize);
|
||||
dbgln("Flags: {x}", header_->flags);
|
||||
dbgln("Length: {x}", header_->numglyph);
|
||||
dbgln("Glyph Size: {x}", header_->bytesperglyph);
|
||||
dbgln("Height: {x}", header_->height);
|
||||
dbgln("Width: {x}", header_->width);
|
||||
}
|
||||
|
||||
void Psf::EnsureValid() {
|
||||
if (header_->magic != kMagic) {
|
||||
dbgln("PSF: Magic value: {x}", header_->magic);
|
||||
crash("PSF: Invalid magic value", glcr::INVALID_ARGUMENT);
|
||||
}
|
||||
|
||||
if (header_->version != 0) {
|
||||
crash("PSF non-zero version", glcr::INVALID_ARGUMENT);
|
||||
}
|
||||
|
||||
if (header_->height != 0x10) {
|
||||
crash("PSF height other than 16 not handled", glcr::UNIMPLEMENTED);
|
||||
}
|
||||
|
||||
if (header_->width != 0x8) {
|
||||
crash("PSF width other than 8 not handled", glcr::UNIMPLEMENTED);
|
||||
}
|
||||
}
|
||||
34
sys/teton/framebuffer/psf.h
Normal file
34
sys/teton/framebuffer/psf.h
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
#pragma once
|
||||
|
||||
#include <mammoth/memory_region.h>
|
||||
|
||||
struct PsfHeader {
|
||||
uint32_t magic; /* magic bytes to identify PSF */
|
||||
uint32_t version; /* zero */
|
||||
uint32_t headersize; /* offset of bitmaps in file, 32 */
|
||||
uint32_t flags; /* 0 if there's no unicode table */
|
||||
uint32_t numglyph; /* number of glyphs */
|
||||
uint32_t bytesperglyph; /* size of each glyph */
|
||||
uint32_t height; /* height in pixels */
|
||||
uint32_t width; /* width in pixels */
|
||||
};
|
||||
|
||||
class Psf {
|
||||
public:
|
||||
Psf(OwnedMemoryRegion&& psf_file);
|
||||
|
||||
void DumpHeader();
|
||||
|
||||
uint32_t size() { return header_->numglyph; }
|
||||
|
||||
uint8_t* glyph(uint32_t index) {
|
||||
return reinterpret_cast<uint8_t*>(psf_file_.vaddr() + header_->headersize +
|
||||
(index * header_->bytesperglyph));
|
||||
}
|
||||
|
||||
private:
|
||||
OwnedMemoryRegion psf_file_;
|
||||
PsfHeader* header_;
|
||||
|
||||
void EnsureValid();
|
||||
};
|
||||
|
|
@ -1,8 +1,10 @@
|
|||
#include <mammoth/debug.h>
|
||||
#include <mammoth/init.h>
|
||||
#include <victoriafalls/victoriafalls.yunq.client.h>
|
||||
#include <yellowstone/yellowstone.yunq.client.h>
|
||||
|
||||
#include "framebuffer/framebuffer.h"
|
||||
#include "framebuffer/psf.h"
|
||||
|
||||
uint64_t main(uint64_t init_port) {
|
||||
ParseInitPort(init_port);
|
||||
|
|
@ -28,6 +30,23 @@ uint64_t main(uint64_t init_port) {
|
|||
|
||||
// 2. Parse a font file.
|
||||
|
||||
GetEndpointRequest req;
|
||||
req.set_endpoint_name("victoriafalls");
|
||||
Endpoint resp;
|
||||
check(client.GetEndpoint(req, resp));
|
||||
|
||||
VFSClient vfs(resp.endpoint());
|
||||
|
||||
OpenFileRequest freq;
|
||||
freq.set_path("/default8x16.psfu");
|
||||
OpenFileResponse fresp;
|
||||
check(vfs.OpenFile(freq, fresp));
|
||||
|
||||
Psf psf(OwnedMemoryRegion::FromCapability(fresp.memory()));
|
||||
psf.DumpHeader();
|
||||
|
||||
fbuf.DrawGlyph(psf.glyph('C'));
|
||||
|
||||
// 3. Write a line to the screen.
|
||||
|
||||
return 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue