diff --git a/c_os/devices/CGA.cc b/c_os/devices/CGA.cc index 894e7c3..d5a6e33 100755 --- a/c_os/devices/CGA.cc +++ b/c_os/devices/CGA.cc @@ -17,9 +17,9 @@ const IOport CGA::index_port(0x3d4); const IOport CGA::data_port(0x3d5); -bse::span CGA::SCREEN{reinterpret_cast(0xb8000U)}; -bse::span CGA::SCREEN_ROWS{reinterpret_cast(0xb8000U)}; -CGA::cga_page_t* CGA::SCREEN_PAGE {reinterpret_cast(0xb8000U)}; +const bse::span CGA::SCREEN{reinterpret_cast(0xb8000U)}; +const bse::span CGA::SCREEN_ROWS{reinterpret_cast(0xb8000U)}; +CGA::cga_page_t* const CGA::SCREEN_PAGE {reinterpret_cast(0xb8000U)}; /***************************************************************************** * Methode: CGA::setpos * @@ -86,7 +86,7 @@ void CGA::show(unsigned int x, unsigned int y, char character, unsigned char att return; } - cga_char_t* pos= SCREEN[x + y * COLUMNS]; + cga_char_t* pos = SCREEN[x + y * COLUMNS]; pos->cga_char = character; pos->cga_attribute = attrib; } @@ -98,11 +98,11 @@ void CGA::show(unsigned int x, unsigned int y, char character, unsigned char att * '\n' fuer Zeilenvorschub. * * * * Parameter: * - * string Auszugebende Zeichenkette * + * substring Auszugebende Zeichenkette * * n Laenger der Zeichenkette * * attrib Attributbyte fuer alle Zeichen der Zeichenkette * *****************************************************************************/ -void CGA::print(const char* string, unsigned int n, unsigned char attrib) const { +void CGA::print(const bse::string_view string, unsigned char attrib) const { /* Hier muess Code eingefuegt werden */ @@ -110,8 +110,7 @@ void CGA::print(const char* string, unsigned int n, unsigned char attrib) const unsigned int cursor_y = 0; // Don't poll registers every stroke getpos(cursor_x, cursor_y); - for (int byte = 0; byte < n; ++byte) { - char current = *(string + byte); + for (char current : string) { if (current == '\n') { cursor_x = 0; cursor_y = cursor_y + 1; @@ -149,14 +148,6 @@ void CGA::print(const char* string, unsigned int n, unsigned char attrib) const setpos(cursor_x, cursor_y); } -void CGA::print(const bse::string& string, const unsigned int n, const unsigned char attrib) const { - print(static_cast(string), n, attrib); -} - -void CGA::print(const bse::string& string, const unsigned char attrib) const { - print(static_cast(string), string.size(), attrib); -} - /***************************************************************************** * Methode: CGA::scrollup * *---------------------------------------------------------------------------* diff --git a/c_os/devices/CGA.h b/c_os/devices/CGA.h index fc92797..821916f 100755 --- a/c_os/devices/CGA.h +++ b/c_os/devices/CGA.h @@ -18,6 +18,7 @@ #include "user/lib/Array.h" #include "user/lib/Span.h" #include "user/lib/String.h" +#include "user/lib/StringView.h" class CGA { private: @@ -77,9 +78,9 @@ public: bse::array cga_page; }; - static bse::span SCREEN; - static bse::span SCREEN_ROWS; - static cga_page_t* SCREEN_PAGE; // No span because can't address anything in [0, 1] + static const bse::span SCREEN; + static const bse::span SCREEN_ROWS; + static cga_page_t* const SCREEN_PAGE; // No span because can't address anything in [0, 1] // Setzen des Cursors in Spalte x und Zeile y. static void setpos(unsigned int x, unsigned int y); @@ -91,9 +92,7 @@ public: static void show(unsigned int x, unsigned int y, char character, unsigned char attrib = STD_ATTR); // Anzeige mehrerer Zeichen ab der aktuellen Cursorposition - void print(const char* string, unsigned int n, unsigned char attrib = STD_ATTR) const; - void print(const bse::string& string, unsigned int n, unsigned char attrib = STD_ATTR) const; - void print(const bse::string& string, unsigned char attrib = STD_ATTR) const; + void print(const bse::string_view substring, unsigned char attrib = STD_ATTR) const; // Verschiebt den Bildschirminhalt um eine Zeile nach oben. // Neue Zeile am unteren Bildrand mit Leerzeichen fuellen diff --git a/c_os/devices/CGA_Stream.cc b/c_os/devices/CGA_Stream.cc index c54d74d..0b95f92 100755 --- a/c_os/devices/CGA_Stream.cc +++ b/c_os/devices/CGA_Stream.cc @@ -24,7 +24,8 @@ * verwendet werden, um eine Ausgabe zu erzwingen. * *****************************************************************************/ void CGA_Stream::flush() { - print(buffer.data(), pos, attribute(color_bg, color_fg, blink)); // print(buffer...) would work syntactically + buffer[pos] = '\0'; // I removed the n argument from print so nullterminate the string + print(buffer.data(), attribute(color_bg, color_fg, blink)); // print(buffer...) would work syntactically // but the system wouldn't start, as the bse::array // would be implicitly converted to bse::string and // that is dynamically allocated.