reduce namespace pollution from console library

This commit is contained in:
Wolfgang Thaller 2014-09-30 11:00:33 +02:00
parent c9f832b2c9
commit 4e766452b4
6 changed files with 55 additions and 51 deletions

View File

@ -24,6 +24,8 @@
#include <algorithm>
using namespace Retro;
Console *Console::currentInstance = NULL;
Console::Console(GrafPtr port, Rect r)

View File

@ -21,39 +21,44 @@
#include <vector>
#include <string>
class Console
namespace Retro
{
public:
Console(GrafPtr port, Rect r);
~Console();
void Draw();
void putch(char c);
void write(const char *s, int n);
std::string ReadLine();
class Console
{
public:
Console(GrafPtr port, Rect r);
~Console();
void Draw();
void putch(char c);
static Console *currentInstance;
private:
GrafPtr consolePort;
Rect bounds;
void write(const char *s, int n);
std::string ReadLine();
std::vector<char> chars, onscreen;
static Console *currentInstance;
private:
GrafPtr consolePort;
Rect bounds;
short cellSizeX;
short cellSizeY;
std::vector<char> chars, onscreen;
short rows, cols;
short cellSizeX;
short cellSizeY;
short cursorX, cursorY;
short rows, cols;
Rect dirtyRect;
short cursorX, cursorY;
void PutCharNoUpdate(char c);
void Update();
Rect dirtyRect;
Rect CellRect(short x, short y);
void DrawCell(short x, short y, bool erase = true);
void DrawCells(short x1, short x2, short y, bool erase = true);
void ScrollUp(short n = 1);
};
void PutCharNoUpdate(char c);
void Update();
Rect CellRect(short x, short y);
void DrawCell(short x, short y, bool erase = true);
void DrawCells(short x1, short x2, short y, bool erase = true);
void ScrollUp(short n = 1);
};
}

View File

@ -31,9 +31,14 @@
#include "MacUtils.h"
#include "Console.h"
QDGlobals qd;
namespace Retro
{
void InitConsole();
}
void InitConsole()
using namespace Retro;
void Retro::InitConsole()
{
if(Console::currentInstance)
return;
@ -54,7 +59,7 @@ void InitConsole()
Console *console = new Console(win, win->portRect);
}
extern "C" ssize_t consolewrite(int fd, const void *buf, size_t count)
extern "C" ssize_t _consolewrite(int fd, const void *buf, size_t count)
{
if(!Console::currentInstance)
InitConsole();
@ -63,7 +68,7 @@ extern "C" ssize_t consolewrite(int fd, const void *buf, size_t count)
return count;
}
extern "C" ssize_t consoleread(int fd, void *buf, size_t count)
extern "C" ssize_t _consoleread(int fd, void *buf, size_t count)
{
if(!Console::currentInstance)
InitConsole();

View File

@ -1,11 +1,11 @@
#include <sys/types.h>
__attribute__((weak)) ssize_t consolewrite(int fd, const void *buf, size_t count)
__attribute__((weak)) ssize_t _consolewrite(int fd, const void *buf, size_t count)
{
return -1;
}
__attribute__((weak)) ssize_t consoleread(int fd, void *buf, size_t count)
__attribute__((weak)) ssize_t _consoleread(int fd, void *buf, size_t count)
{
return -1;
}

View File

@ -23,6 +23,10 @@
#include <Files.h>
#include <Devices.h>
#include <Quickdraw.h>
QDGlobals qd;
pascal Size GetPtrSize(Ptr ptr)
{
long tmp;

View File

@ -32,40 +32,28 @@ void *sbrk(long increment)
void _exit(int status)
{
if(status != 0)
Debugger();
//if(status != 0)
// Debugger();
ExitToShell();
for(;;)
;
}
ssize_t (*__write_hook)(int fd, const void*buf, size_t count) = NULL;
ssize_t (*__read_hook)(int fd, void*buf, size_t count) = NULL;
ssize_t consolewrite(int fd, const void *buf, size_t count);
ssize_t consoleread(int fd, void *buf, size_t count);
ssize_t _consolewrite(int fd, const void *buf, size_t count);
ssize_t _consoleread(int fd, void *buf, size_t count);
ssize_t write(int fd, const void *buf, size_t count)
{
if(__write_hook)
return (*__write_hook)(fd,buf,count);
else
return consolewrite(fd,buf,count);
return -1;
return _consolewrite(fd,buf,count);
}
ssize_t read(int fd, void *buf, size_t count)
{
if(__read_hook)
return (*__read_hook)(fd,buf,count);
else
return consoleread(fd,buf,count);
return -1;
return _consoleread(fd,buf,count);
}
int open(const char* name, int flags, mode_t mode)
{
__asm__ __volatile__ ("dc.w 0xa9ff");
return -1;
}