use enum
This commit is contained in:
15
arch/cga.cc
15
arch/cga.cc
@@ -1,10 +1,21 @@
|
|||||||
#include "cga.h"
|
#include "cga.h"
|
||||||
|
#include "arch/ioport.h"
|
||||||
|
|
||||||
namespace CGA {
|
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 setCursor(unsigned abs_x, unsigned abs_y) {
|
||||||
(void)abs_x;
|
uint16_t pos = abs_y * COLUMNS + abs_x;
|
||||||
(void)abs_y;
|
|
||||||
|
writeCGAReg(RegisterIndex::CURSOR_LOW, pos & 0xFF);
|
||||||
|
writeCGAReg(RegisterIndex::CURSOR_HIGH, ((pos >> 8) & 0xFF));
|
||||||
}
|
}
|
||||||
|
|
||||||
void getCursor(unsigned& abs_x, unsigned& abs_y) {
|
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 ROWS = 25; ///< Visible rows in text mode
|
||||||
constexpr unsigned COLUMNS = 80; ///< Visible columns 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
|
/*! \brief CGA color palette
|
||||||
*
|
*
|
||||||
* Colors for the attribute byte.
|
* Colors for the attribute byte.
|
||||||
@@ -62,7 +71,9 @@ enum Color {
|
|||||||
*/
|
*/
|
||||||
union Attribute {
|
union Attribute {
|
||||||
struct {
|
struct {
|
||||||
uint8_t todo : 8;
|
uint8_t foreground : 4;
|
||||||
|
uint8_t background : 3;
|
||||||
|
uint8_t blink : 1;
|
||||||
} __attribute__((packed));
|
} __attribute__((packed));
|
||||||
uint8_t value; ///< combined value
|
uint8_t value; ///< combined value
|
||||||
|
|
||||||
@@ -75,11 +86,7 @@ union Attribute {
|
|||||||
* \param blink Blink if `true` (default: no blinking)
|
* \param blink Blink if `true` (default: no blinking)
|
||||||
*/
|
*/
|
||||||
explicit Attribute(Color foreground = LIGHT_GREY, Color background = BLACK,
|
explicit Attribute(Color foreground = LIGHT_GREY, Color background = BLACK,
|
||||||
bool blink = false) { // NOLINT
|
bool blink = false) : foreground(foreground), background(background), blink(blink) {}
|
||||||
(void)foreground;
|
|
||||||
(void)background;
|
|
||||||
(void)blink;
|
|
||||||
}
|
|
||||||
} __attribute__((packed)); // prevent padding by the compiler
|
} __attribute__((packed)); // prevent padding by the compiler
|
||||||
|
|
||||||
/*! \brief Set the keyboard hardware cursor to absolute screen position
|
/*! \brief Set the keyboard hardware cursor to absolute screen position
|
||||||
|
|||||||
4
main.cc
4
main.cc
@@ -3,12 +3,16 @@
|
|||||||
#include "boot/startup_ap.h"
|
#include "boot/startup_ap.h"
|
||||||
#include "debug/output.h"
|
#include "debug/output.h"
|
||||||
|
|
||||||
|
#include "arch/cga.h"
|
||||||
|
|
||||||
// Main function
|
// Main function
|
||||||
// (the bootstrap processor starts here)}
|
// (the bootstrap processor starts here)}
|
||||||
extern "C" int main() {
|
extern "C" int main() {
|
||||||
unsigned int numCPUs = Core::count();
|
unsigned int numCPUs = Core::count();
|
||||||
DBG_VERBOSE << "Number of CPUs: " << numCPUs << endl;
|
DBG_VERBOSE << "Number of CPUs: " << numCPUs << endl;
|
||||||
|
|
||||||
|
CGA::setCursor(1, 2);
|
||||||
|
|
||||||
/* Start application processors
|
/* Start application processors
|
||||||
* To avoid unexpected behaviour, make sure that interrupts are not
|
* To avoid unexpected behaviour, make sure that interrupts are not
|
||||||
* enabled before the APs are booted. Otherwise it might interfere with the
|
* enabled before the APs are booted. Otherwise it might interfere with the
|
||||||
|
|||||||
Reference in New Issue
Block a user