[WIP] Implementing "console" output and stuff.
This commit is contained in:
77
targets/_any/include/libs/psf.hpp
Normal file
77
targets/_any/include/libs/psf.hpp
Normal file
@@ -0,0 +1,77 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#if !defined(BAD_APPLE_OS_PSF_HPP_INCLUDED)
|
||||
#define BAD_APPLE_OS_PSF_HPP_INCLUDED
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
namespace psf
|
||||
{
|
||||
inline const uint32_t MAGIC = 0x864ab572;
|
||||
|
||||
struct Header
|
||||
{
|
||||
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 Font
|
||||
{
|
||||
private:
|
||||
const Header* mMemory = nullptr;
|
||||
size_t mSize = 0;
|
||||
public:
|
||||
Font() noexcept = default;
|
||||
Font(const Font&) = default;
|
||||
private:
|
||||
Font(const Header* memory, size_t size) noexcept : mMemory(memory), mSize(size) {}
|
||||
public:
|
||||
Font& operator=(const Font&) noexcept = default;
|
||||
|
||||
[[nodiscard]] uint32_t getGlyphWidth() const noexcept { return mMemory->width; }
|
||||
[[nodiscard]] uint32_t getGlyphHeight() const noexcept { return mMemory->height; }
|
||||
template<typename TColor, typename TDrawFn>
|
||||
void writeGlyph(char chr, const TColor& fgColor, const TColor& bgColor, TDrawFn draw) const noexcept;
|
||||
public:
|
||||
[[nodiscard]] static bool create(const void* data, size_t size, Font& outFont) noexcept;
|
||||
};
|
||||
|
||||
template<typename TColor, typename TDrawFn>
|
||||
void Font::writeGlyph(char chr, const TColor& fgColor, const TColor& bgColor, TDrawFn draw) const noexcept
|
||||
{
|
||||
if (chr > mMemory->numglyph) {
|
||||
chr = 0;
|
||||
}
|
||||
|
||||
const uint8_t* glyphData = reinterpret_cast<const uint8_t*>(mMemory) + mMemory->headersize + chr * mMemory->bytesperglyph;
|
||||
|
||||
for (unsigned y = 0; y < mMemory->height; ++y)
|
||||
{
|
||||
for (unsigned x = 0; x < mMemory->width; ++x)
|
||||
{
|
||||
const unsigned idx = y * mMemory->width + x;
|
||||
const unsigned byte = idx / 8;
|
||||
const unsigned bit = idx % 8;
|
||||
|
||||
if (glyphData[byte] & (0b10000000 >> bit))
|
||||
{
|
||||
draw(x, y, fgColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
draw(x, y, bgColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // !defined(BAD_APPLE_OS_PSF_HPP_INCLUDED)
|
||||
@@ -5,8 +5,13 @@
|
||||
#define BAD_APPLE_OS_DRAW_HPP_INCLUDED
|
||||
|
||||
#include <stdint.h>
|
||||
#include <array>
|
||||
#include <vector>
|
||||
|
||||
namespace psf
|
||||
{
|
||||
class Font;
|
||||
}
|
||||
namespace draw
|
||||
{
|
||||
const unsigned SIZE_FULL = static_cast<unsigned>(-1);
|
||||
@@ -19,6 +24,10 @@ struct Pixel
|
||||
uint8_t reserved_ = 0;
|
||||
};
|
||||
|
||||
inline Pixel PIXEL_WHITE = {255, 255, 255};
|
||||
inline Pixel PIXEL_BLACK = {0, 0, 0};
|
||||
extern const std::array<Pixel, 16> VGA_PIXELS;
|
||||
|
||||
class Framebuffer
|
||||
{
|
||||
protected:
|
||||
@@ -38,6 +47,7 @@ public:
|
||||
[[nodiscard]] unsigned getPitch() const noexcept { return mPitch; }
|
||||
[[nodiscard]] unsigned getBufferSize() const noexcept { return mPitch * mHeight * sizeof(Pixel); }
|
||||
|
||||
const Pixel& getPixel(unsigned posX, unsigned posY) noexcept;
|
||||
void setPixel(unsigned posX, unsigned posY, Pixel pixel) noexcept;
|
||||
};
|
||||
|
||||
@@ -61,9 +71,15 @@ public:
|
||||
};
|
||||
|
||||
void initializeDefaultFramebuffer(const Framebuffer& framebuffer) noexcept;
|
||||
[[nodiscard]] const Framebuffer& getPrimaryFramebuffer() noexcept;
|
||||
|
||||
void setPixelDirect(unsigned posX, unsigned posY, Pixel pixel) noexcept;
|
||||
void setPixel(unsigned posX, unsigned posY, Pixel pixel) noexcept;
|
||||
void flushPixels() noexcept;
|
||||
const Pixel& getPixel(unsigned posX, unsigned posY) noexcept;
|
||||
|
||||
void character(unsigned posX, unsigned posY, const psf::Font& font, char chr, const Pixel& fgColor = PIXEL_WHITE, const Pixel& bgColor = PIXEL_BLACK) noexcept;
|
||||
|
||||
void scrollBy(int scrollX, int scrollY, const Pixel& fillColor = PIXEL_BLACK) noexcept;
|
||||
}
|
||||
|
||||
#endif // !defined(BAD_APPLE_OS_FRAMEBUFFER_HPP_INCLUDED)
|
||||
|
||||
1
targets/_any/include/os/resources/.gitignore
vendored
Normal file
1
targets/_any/include/os/resources/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
*.hpp
|
||||
@@ -35,12 +35,14 @@ struct VgaDoubleColor
|
||||
VgaColor background : 4 = VgaColor::BLACK;
|
||||
};
|
||||
|
||||
void initialize();
|
||||
void setColor(VgaDoubleColor color);
|
||||
void putEntryAt(char chr, VgaDoubleColor color, size_t posX, size_t posY);
|
||||
void putChar(char chr);
|
||||
void write(const char* data, size_t size);
|
||||
void write(const char* data);
|
||||
void initialize() noexcept;
|
||||
void setColor(VgaDoubleColor color) noexcept;
|
||||
void putEntryAt(char chr, VgaDoubleColor color, size_t posX, size_t posY) noexcept;
|
||||
void putChar(char chr) noexcept;
|
||||
void write(const char* data, size_t size) noexcept;
|
||||
void write(const char* data) noexcept;
|
||||
|
||||
bool setPSFFont(const void* data, size_t length) noexcept;
|
||||
} // namespace tty
|
||||
|
||||
#endif // OS_TTY_HPP_INCLUDED
|
||||
|
||||
@@ -11,7 +11,7 @@ BA_EXTERN_C_BEGIN
|
||||
|
||||
int putchar(int chr) BA_CXX_NOEXCEPT;
|
||||
int puts(const char* str) BA_CXX_NOEXCEPT;
|
||||
int printf(const char* format, ...) BA_CXX_NOEXCEPT;
|
||||
int printf(const char* format, ...) BA_CXX_NOEXCEPT __attribute__((format(printf, 1, 2)));
|
||||
int vprintf(const char* format, va_list vlist) BA_CXX_NOEXCEPT;
|
||||
|
||||
BA_EXTERN_C_END
|
||||
|
||||
Reference in New Issue
Block a user