From 5b16da23ed96b7522803d40bf27b7a87bb9dcf97 Mon Sep 17 00:00:00 2001 From: churl Date: Mon, 9 May 2022 14:02:44 +0200 Subject: [PATCH] simplify cga memory manipulation --- c_os/devices/CGA.cc | 25 ++++++++----------------- c_os/devices/CGA.h | 19 ++++++++++++++++--- c_os/main.cc | 22 ++++++++++++++++++++++ 3 files changed, 46 insertions(+), 20 deletions(-) diff --git a/c_os/devices/CGA.cc b/c_os/devices/CGA.cc index 84bc33b..6e6a905 100755 --- a/c_os/devices/CGA.cc +++ b/c_os/devices/CGA.cc @@ -73,14 +73,14 @@ void CGA::show(int x, int y, char character, unsigned char attrib) { /* Hier muess Code eingefuegt werden */ - if (x > COLUMNS || y > ROWS) { + if (x >= COLUMNS || y >= ROWS) { // Out of bounds return; } - char* pos = (char*)(CGA_START + 2 * (x + y * COLUMNS)); // cast to char* to make writable - *pos = character; - *(pos + 1) = attrib; + cga_char_t* pos = (cga_char_t*)(CGA_START + 2 * (x + y * COLUMNS)); // cast to char* to make writable + pos->cga_char = character; + pos->cga_attribute = attrib; } /***************************************************************************** @@ -147,19 +147,13 @@ void CGA::print(char* string, int n, unsigned char attrib) { *****************************************************************************/ void CGA::scrollup() { - /* Hier muess Code eingefuegt werden */ - - // TODO: I really want a scrollback buffer + /* Hier muss Code eingefuegt werden */ // Move up - for (unsigned short byte = 2 * COLUMNS * 1; byte < 2 * COLUMNS * ROWS; ++byte) { - *((char*)(CGA_START + byte - 2 * COLUMNS * 1)) = *(CGA_START + byte); - } + mymemcpy((cga_line_t*)CGA_START, (cga_line_t*)CGA_START + 1, ROWS - 1); // Clear last line - for (unsigned short byte = 2 * COLUMNS * (ROWS - 1); byte < 2 * COLUMNS * ROWS; ++byte) { - *((char*)(CGA_START + byte)) = '\0'; - } + myzero((cga_line_t*)CGA_START + ROWS - 1); } /***************************************************************************** @@ -171,10 +165,7 @@ void CGA::clear() { /* Hier muess Code eingefuegt werden */ - for (unsigned short byte = 2 * COLUMNS * 0; byte < 2 * COLUMNS * ROWS; ++byte) { - *((char*)(CGA_START + byte)) = '\0'; - } - + myzero((cga_page_t*)CGA_START); this->setpos(0, 0); } diff --git a/c_os/devices/CGA.h b/c_os/devices/CGA.h index 0ff9d7b..c9e9129 100755 --- a/c_os/devices/CGA.h +++ b/c_os/devices/CGA.h @@ -15,6 +15,7 @@ #define __CGA_include__ #include "kernel/IOport.h" +#include "lib/MyStdLib.h" class CGA { @@ -63,6 +64,18 @@ public: enum { ROWS = 25, COLUMNS = 80 }; + // NOTE: I added this + typedef struct { + char cga_char; + char cga_attribute; + } cga_char_t; + typedef struct { + cga_char_t cga_line[COLUMNS]; + } cga_line_t; + typedef struct { + cga_line_t cga_page[ROWS]; + } cga_page_t; + // Setzen des Cursors in Spalte x und Zeile y. void setpos(int x, int y); @@ -73,14 +86,14 @@ public: void show(int x, int y, char character, unsigned char attrib = STD_ATTR); // Anzeige mehrerer Zeichen ab der aktuellen Cursorposition - void print(char* string, int n, unsigned char attrib = STD_ATTR); + virtual void print(char* string, int n, unsigned char attrib = STD_ATTR); // Verschiebt den Bildschirminhalt um eine Zeile nach oben. // Neue Zeile am unteren Bildrand mit Leerzeichen fuellen - void scrollup(); + virtual void scrollup(); // Lösche den Textbildschirm - void clear(); + virtual void clear(); // Hilfsfunktion zur Erzeugung eines Attribut-Bytes unsigned char attribute(CGA::color bg, CGA::color fg, bool blink); diff --git a/c_os/main.cc b/c_os/main.cc index 80d1d25..9229c76 100755 --- a/c_os/main.cc +++ b/c_os/main.cc @@ -14,17 +14,39 @@ #include "kernel/Globals.h" #include "user/HeapDemo.h" +// TODO: Where to put this? +void scroll_mode() { + Key key; + // while (true) { + // key = kb.key_hit(); + + // switch (key.ascii()) { + // case 'k': + // kout.pageup(); + // case 'j': + // kout.pagedown(); + // } + // } +} + int main() { kout.clear(); // Speicherverwaltung initialisieren allocator.init(); + // Initialize scrollback buffer + // kout.init(); + + allocator.dump_free_memory(); + // text_demo(); // sound_demo(); // keyboard_demo(); heap_demo(); + // scroll_mode(); + while (1) {}; return 0; }