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> #include <algorithm>
using namespace Retro;
Console *Console::currentInstance = NULL; Console *Console::currentInstance = NULL;
Console::Console(GrafPtr port, Rect r) Console::Console(GrafPtr port, Rect r)

View File

@ -21,39 +21,44 @@
#include <vector> #include <vector>
#include <string> #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); class Console
std::string ReadLine(); {
public:
Console(GrafPtr port, Rect r);
~Console();
void Draw();
void putch(char c);
static Console *currentInstance; void write(const char *s, int n);
private: std::string ReadLine();
GrafPtr consolePort;
Rect bounds;
std::vector<char> chars, onscreen; static Console *currentInstance;
private:
GrafPtr consolePort;
Rect bounds;
short cellSizeX; std::vector<char> chars, onscreen;
short cellSizeY;
short rows, cols; short cellSizeX;
short cellSizeY;
short cursorX, cursorY; short rows, cols;
Rect dirtyRect; short cursorX, cursorY;
void PutCharNoUpdate(char c); Rect dirtyRect;
void Update();
Rect CellRect(short x, short y); void PutCharNoUpdate(char c);
void DrawCell(short x, short y, bool erase = true); void Update();
void DrawCells(short x1, short x2, short y, bool erase = true);
void ScrollUp(short n = 1);
};
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 "MacUtils.h"
#include "Console.h" #include "Console.h"
QDGlobals qd; namespace Retro
{
void InitConsole();
}
void InitConsole() using namespace Retro;
void Retro::InitConsole()
{ {
if(Console::currentInstance) if(Console::currentInstance)
return; return;
@ -43,18 +48,18 @@ void InitConsole()
InitFonts(); InitFonts();
InitWindows(); InitWindows();
InitMenus(); InitMenus();
Rect r; Rect r;
SetRect(&r, qd.screenBits.bounds.left + 5, qd.screenBits.bounds.top + 45, qd.screenBits.bounds.right - 5, qd.screenBits.bounds.bottom -5); SetRect(&r, qd.screenBits.bounds.left + 5, qd.screenBits.bounds.top + 45, qd.screenBits.bounds.right - 5, qd.screenBits.bounds.bottom -5);
win = NewWindow(NULL, &r, "\pRetro68 Console", true, 0, (WindowPtr)-1, false, 0); win = NewWindow(NULL, &r, "\pRetro68 Console", true, 0, (WindowPtr)-1, false, 0);
SetPort(win); SetPort(win);
EraseRect(&win->portRect); EraseRect(&win->portRect);
Console *console = new Console(win, win->portRect); 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) if(!Console::currentInstance)
InitConsole(); InitConsole();
@ -63,7 +68,7 @@ extern "C" ssize_t consolewrite(int fd, const void *buf, size_t count)
return 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) if(!Console::currentInstance)
InitConsole(); InitConsole();

View File

@ -1,11 +1,11 @@
#include <sys/types.h> #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; 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; return -1;
} }

View File

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

View File

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