KernOS
vga.h
Go to the documentation of this file.
1 #ifndef KERNOS_VGA_H
2 #define KERNOS_VGA_H
3 
4 #include <utilities.h>
5 
9 namespace VGA
10 {
11 
21  enum class COLOR : uint8_t
22  {
23  BLACK = 0,
24  BLUE,
25  GREEN,
26  CYAN,
27  RED,
28  MAGENTA,
29  BROWN,
30  LIGHT_GREY,
31  DARK_GREY,
32  LIGHT_BLUE,
34  LIGHT_CYAN,
35  LIGHT_RED,
38  WHITE
39  };
40 
41  typedef uint8_t VgaColor;
42  typedef uint16_t VgaChar;
43 
47  class Vga
48  {
49  static const size_t VGA_WIDTH = 80;
50  static const size_t VGA_HEIGHT = 25;
51 
52  size_t m_Row;
53  size_t m_Col;
54  uint16_t *const m_Buffer = (uint16_t *) 0xB8000;
55  VgaColor m_Color;
56 
57  VgaColor EntryColor(COLOR Fore, COLOR Back) const;
58 
59  VgaChar Entry(unsigned char uc, VgaColor Color) const;
60 
61  void Fill(const VgaChar Char);
62 
63  void PutChar(unsigned char Char);
64 
65  void Initialize();
66 
67  public:
68 
69  Vga()
70  {
71 #ifndef TEST_BUILD // TODO: temporary until we mock vga's direct memory map
72  Initialize();
73 #endif
74  }
75 
79  void Puts(const char *Str);
80 
86  void PutChar(VgaChar Char, size_t Row, size_t Col);
87 
92  void SetColor(VgaColor Color);
93  };
94 
95  inline VgaColor Vga::EntryColor(COLOR Fore, COLOR Back) const
96  {
97  return static_cast<VgaColor>(Fore)
98  | static_cast<VgaColor>(Back) << 4;
99  }
100 
101  inline VgaChar Vga::Entry(unsigned char uc, VgaColor Color) const
102  {
103  return static_cast<VgaChar> (uc)
104  | static_cast<VgaChar> (Color) << 8;
105  }
106 
107  inline void Vga::PutChar(VgaChar Char, size_t Row, size_t Col)
108  {
109  m_Buffer[Row * VGA_WIDTH + Col] = Char;
110  }
111 
112  inline void Vga::SetColor(VgaColor Color)
113  {
114  m_Color = Color;
115  }
116 
117 
118 } // namespace VGA
119 
120 namespace INIT
121 {
124  void VGA();
125 }
126 
127 #endif //KERNOS_VGA_H
void SetColor(VgaColor Color)
Set text color.
Definition: vga.h:112
Video Graphics Array namespace.
Definition: vga.h:9
COLOR
VGA text buffer convention.
Definition: vga.h:21
Manages access to VGA driver.
Definition: vga.h:47
contains all kernel initialization routines
Definition: cpu.h:10
uint16_t VgaChar
Definition: vga.h:42
void VGA()
Clear VGA display, and print kernel banner.
Definition: vga.cpp:67
uint8_t VgaColor
Definition: vga.h:41
Vga()
Definition: vga.h:69