2014-09-17 01:35:18 +00:00
|
|
|
/*
|
|
|
|
Copyright 2014 Wolfgang Thaller.
|
|
|
|
|
|
|
|
This file is part of Retro68.
|
|
|
|
|
|
|
|
Retro68 is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Retro68 is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Retro68. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include <Quickdraw.h>
|
|
|
|
#include <MacMemory.h>
|
|
|
|
#include <Sound.h>
|
|
|
|
#include <Events.h>
|
|
|
|
#include <Fonts.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "MacUtils.h"
|
|
|
|
#include "Console.h"
|
2015-10-15 22:52:50 +00:00
|
|
|
#include "ConsoleWindow.h"
|
2014-09-17 01:35:18 +00:00
|
|
|
|
2014-09-30 09:00:33 +00:00
|
|
|
namespace Retro
|
|
|
|
{
|
|
|
|
void InitConsole();
|
|
|
|
}
|
|
|
|
|
|
|
|
using namespace Retro;
|
2014-09-17 01:35:18 +00:00
|
|
|
|
2014-09-30 09:00:33 +00:00
|
|
|
void Retro::InitConsole()
|
2014-09-17 01:35:18 +00:00
|
|
|
{
|
|
|
|
if(Console::currentInstance)
|
|
|
|
return;
|
2015-10-11 23:02:21 +00:00
|
|
|
|
|
|
|
#if !TARGET_API_MAC_CARBON
|
2014-09-17 01:35:18 +00:00
|
|
|
InitGraf(&qd.thePort);
|
|
|
|
InitFonts();
|
|
|
|
InitWindows();
|
|
|
|
InitMenus();
|
2014-09-30 09:00:33 +00:00
|
|
|
|
2015-10-11 23:02:21 +00:00
|
|
|
Rect r = qd.screenBits.bounds;
|
|
|
|
#else
|
|
|
|
Rect r = (*GetMainDevice())->gdRect;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
r.top += 40;
|
|
|
|
InsetRect(&r, 5,5);
|
2015-10-15 22:52:50 +00:00
|
|
|
|
|
|
|
new ConsoleWindow(r, "\pRetro68 Console");
|
|
|
|
InitCursor();
|
2014-09-17 01:35:18 +00:00
|
|
|
}
|
|
|
|
|
2014-09-30 09:00:33 +00:00
|
|
|
extern "C" ssize_t _consolewrite(int fd, const void *buf, size_t count)
|
2014-09-17 01:35:18 +00:00
|
|
|
{
|
|
|
|
if(!Console::currentInstance)
|
|
|
|
InitConsole();
|
2015-09-08 21:47:46 +00:00
|
|
|
if(Console::currentInstance == (Console*)-1)
|
|
|
|
return 0;
|
2014-09-17 01:35:18 +00:00
|
|
|
|
2014-09-21 20:38:48 +00:00
|
|
|
Console::currentInstance->write((const char*)buf, count);
|
2014-09-17 01:35:18 +00:00
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2014-09-30 09:00:33 +00:00
|
|
|
extern "C" ssize_t _consoleread(int fd, void *buf, size_t count)
|
2014-09-17 01:35:18 +00:00
|
|
|
{
|
|
|
|
if(!Console::currentInstance)
|
|
|
|
InitConsole();
|
2015-09-08 21:47:46 +00:00
|
|
|
if(Console::currentInstance == (Console*)-1)
|
|
|
|
return 0;
|
2014-09-17 01:35:18 +00:00
|
|
|
|
|
|
|
static std::string consoleBuf;
|
|
|
|
if(consoleBuf.size() == 0)
|
|
|
|
{
|
|
|
|
consoleBuf = Console::currentInstance->ReadLine() + "\n";
|
|
|
|
}
|
|
|
|
if(count > consoleBuf.size())
|
|
|
|
count = consoleBuf.size();
|
|
|
|
memcpy(buf, consoleBuf.data(), count);
|
|
|
|
consoleBuf = consoleBuf.substr(count);
|
|
|
|
return count;
|
|
|
|
}
|