1

simplify cga memory manipulation

This commit is contained in:
churl
2022-05-09 14:02:44 +02:00
parent 27d8f13b5e
commit 5b16da23ed
3 changed files with 46 additions and 20 deletions

View File

@ -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_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_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_page_t*)CGA_START);
this->setpos(0, 0);
}

View File

@ -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);

View File

@ -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;
}