diff --git a/Console/CMakeLists.txt b/Console/CMakeLists.txt index a67180fa85..5cb28cffa4 100644 --- a/Console/CMakeLists.txt +++ b/Console/CMakeLists.txt @@ -27,3 +27,8 @@ add_library(RetroConsole install(TARGETS RetroConsole DESTINATION lib) +add_application(ConsoleTest + ConsoleTest.cc + ) +target_link_libraries(ConsoleTest RetroConsole) + diff --git a/Console/Console.cc b/Console/Console.cc index cdb002f257..dc309974d5 100644 --- a/Console/Console.cc +++ b/Console/Console.cc @@ -21,6 +21,7 @@ #include "MacUtils.h" #include "Events.h" #include "Fonts.h" +#include "Processes.h" #include @@ -30,7 +31,9 @@ Console *Console::currentInstance = NULL; Console::Console(GrafPtr port, Rect r) : consolePort(port), bounds(r), dirtyRect() -{ +{ + if(currentInstance == NULL) + currentInstance = (Console*) -1; PortSetter setport(consolePort); InsetRect(&bounds, 2,2); @@ -42,7 +45,9 @@ Console::Console(GrafPtr port, Rect r) rows = (bounds.bottom - bounds.top) / cellSizeY; cols = (bounds.right - bounds.left) / cellSizeX; + chars = std::vector(rows*cols, ' '); + onscreen = chars; cursorX = cursorY = 0; diff --git a/Console/Console.h b/Console/Console.h index a976820f1e..b14d5d0089 100644 --- a/Console/Console.h +++ b/Console/Console.h @@ -36,6 +36,9 @@ namespace Retro std::string ReadLine(); static Console *currentInstance; + + short GetRows() const { return rows; } + short GetCols() const { return cols; } private: GrafPtr consolePort; Rect bounds; diff --git a/Console/ConsoleTest.cc b/Console/ConsoleTest.cc new file mode 100644 index 0000000000..6bf0741000 --- /dev/null +++ b/Console/ConsoleTest.cc @@ -0,0 +1,16 @@ +#include "Console.h" +#include + +namespace Retro +{ + void InitConsole(); +} + +int main() +{ + Retro::InitConsole(); + const char *s = "Hello, world.\n"; + Retro::Console::currentInstance->write(s, strlen(s)); + Retro::Console::currentInstance->ReadLine(); + return 0; +} diff --git a/Console/InitConsole.cc b/Console/InitConsole.cc index d3161ec5bd..6f5112fe12 100644 --- a/Console/InitConsole.cc +++ b/Console/InitConsole.cc @@ -63,6 +63,8 @@ extern "C" ssize_t _consolewrite(int fd, const void *buf, size_t count) { if(!Console::currentInstance) InitConsole(); + if(Console::currentInstance == (Console*)-1) + return 0; Console::currentInstance->write((const char*)buf, count); return count; @@ -72,6 +74,8 @@ extern "C" ssize_t _consoleread(int fd, void *buf, size_t count) { if(!Console::currentInstance) InitConsole(); + if(Console::currentInstance == (Console*)-1) + return 0; static std::string consoleBuf; if(consoleBuf.size() == 0)