use enum
This commit is contained in:
15
arch/cga.cc
15
arch/cga.cc
@@ -1,10 +1,21 @@
|
||||
#include "cga.h"
|
||||
#include "arch/ioport.h"
|
||||
|
||||
namespace CGA {
|
||||
|
||||
IOPort index_port = IOPort(0x3d4);
|
||||
IOPort data_port = IOPort(0x3d5);
|
||||
|
||||
void writeCGAReg(int reg, int data){
|
||||
index_port.outb(reg);
|
||||
data_port.outb(data);
|
||||
}
|
||||
|
||||
void setCursor(unsigned abs_x, unsigned abs_y) {
|
||||
(void)abs_x;
|
||||
(void)abs_y;
|
||||
uint16_t pos = abs_y * COLUMNS + abs_x;
|
||||
|
||||
writeCGAReg(RegisterIndex::CURSOR_LOW, pos & 0xFF);
|
||||
writeCGAReg(RegisterIndex::CURSOR_HIGH, ((pos >> 8) & 0xFF));
|
||||
}
|
||||
|
||||
void getCursor(unsigned& abs_x, unsigned& abs_y) {
|
||||
|
||||
19
arch/cga.h
19
arch/cga.h
@@ -18,6 +18,15 @@ namespace CGA {
|
||||
constexpr unsigned ROWS = 25; ///< Visible rows in text mode
|
||||
constexpr unsigned COLUMNS = 80; ///< Visible columns in text mode
|
||||
|
||||
enum RegisterIndex {
|
||||
CURSOR_START = 10,
|
||||
CURSOR_END = 11,
|
||||
START_ADDRESS_HIGH = 12,
|
||||
START_ADDRESS_LOW = 13,
|
||||
CURSOR_HIGH = 14,
|
||||
CURSOR_LOW = 15
|
||||
};
|
||||
|
||||
/*! \brief CGA color palette
|
||||
*
|
||||
* Colors for the attribute byte.
|
||||
@@ -62,7 +71,9 @@ enum Color {
|
||||
*/
|
||||
union Attribute {
|
||||
struct {
|
||||
uint8_t todo : 8;
|
||||
uint8_t foreground : 4;
|
||||
uint8_t background : 3;
|
||||
uint8_t blink : 1;
|
||||
} __attribute__((packed));
|
||||
uint8_t value; ///< combined value
|
||||
|
||||
@@ -75,11 +86,7 @@ union Attribute {
|
||||
* \param blink Blink if `true` (default: no blinking)
|
||||
*/
|
||||
explicit Attribute(Color foreground = LIGHT_GREY, Color background = BLACK,
|
||||
bool blink = false) { // NOLINT
|
||||
(void)foreground;
|
||||
(void)background;
|
||||
(void)blink;
|
||||
}
|
||||
bool blink = false) : foreground(foreground), background(background), blink(blink) {}
|
||||
} __attribute__((packed)); // prevent padding by the compiler
|
||||
|
||||
/*! \brief Set the keyboard hardware cursor to absolute screen position
|
||||
|
||||
Reference in New Issue
Block a user