xaizek / tos (License: GPLv3 only) (since 2018-12-07)
This is an alternative version of sources presented as part of Write Your Own OS video tutorial by Viktor Engelmann.
<root> / src / drv / VGA.hpp (15f244f79d6025437a7b44f540c6fcaa2423ff46) (1,413B) (mode 100644) [raw]
#ifndef TOS__DRV__VGA_HPP__
#define TOS__DRV__VGA_HPP__

#include <cstdint>

#include <drv/drivers.hpp>
#include <hwcomm/Port.hpp>

namespace drv {

struct Mode
{
    int width;
    int height;
    int colorDepth;
};

struct Position
{
    int x;
    int y;
};

struct Dimentions
{
    int w;
    int h;
};

struct Color
{
    std::uint8_t r;
    std::uint8_t g;
    std::uint8_t b;
};

class VGA
{
public:
    VGA();

public:
    bool supportsMode(const Mode &mode);
    bool setMode(const Mode &mode);

    void beginDrawing();
    void endDrawing();

    void putPixel(Position pos, Color color);
    void fillRectangle(Position pos, Dimentions size, Color color);

private:
    void putPixel(Position pos, std::uint8_t colorIndex);
    void writeRegisters(std::uint8_t *registers);
    std::uint8_t * getFrameBufferSegment();

    std::uint8_t getColorIndex(Color color);

private:
    hwcomm::Port8 miscPort;
    hwcomm::Port8 crtcIndexPort;
    hwcomm::Port8 crtcDataPort;
    hwcomm::Port8 sequencerIndexPort;
    hwcomm::Port8 sequencerDataPort;
    hwcomm::Port8 graphicsControllerIndexPort;
    hwcomm::Port8 graphicsControllerDataPort;
    hwcomm::Port8 attrControllerIndexPort;
    hwcomm::Port8 attrControllerReadPort;
    hwcomm::Port8 attrControllerWritePort;
    hwcomm::Port8 attrControllerResetPort;

    Mode currentMode;

    std::uint8_t buffer[320*200];
};

}

#endif // TOS__DRV__VGA_HPP__
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/tos

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/tos

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master