mirror of
https://github.com/autc04/Retro68.git
synced 2024-12-26 00:32:02 +00:00
add ConsoleTest application (test console without going through stdio/iostreams); make Console lib less likely to crash on bad_alloc
This commit is contained in:
parent
4851123ac6
commit
8f9720a31e
@ -27,3 +27,8 @@ add_library(RetroConsole
|
||||
|
||||
install(TARGETS RetroConsole DESTINATION lib)
|
||||
|
||||
add_application(ConsoleTest
|
||||
ConsoleTest.cc
|
||||
)
|
||||
target_link_libraries(ConsoleTest RetroConsole)
|
||||
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "MacUtils.h"
|
||||
#include "Events.h"
|
||||
#include "Fonts.h"
|
||||
#include "Processes.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
@ -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<char>(rows*cols, ' ');
|
||||
|
||||
onscreen = chars;
|
||||
|
||||
cursorX = cursorY = 0;
|
||||
|
@ -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;
|
||||
|
16
Console/ConsoleTest.cc
Normal file
16
Console/ConsoleTest.cc
Normal file
@ -0,0 +1,16 @@
|
||||
#include "Console.h"
|
||||
#include <string.h>
|
||||
|
||||
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;
|
||||
}
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user