33 #include "lib/aengine.h" 34 #include "main/evaluator.h" 38 #include <clib/exec_protos.h> 39 #include <clib/alib_protos.h> 40 #include <clib/dos_protos.h> 41 #include <clib/intuition_protos.h> 42 #include <clib/locale_protos.h> 43 #include <libraries/dos.h> 44 #include <graphics/gfxbase.h> 45 #include <intuition/intuition.h> 46 #include <intuition/intuitionbase.h> 47 #include <devices/conunit.h> 48 #include <devices/console.h> 50 AmigaWindow::AmigaWindow(
const char *prompt, CharValidator *validator) :
53 proc =
new AnsiConoleEngine(prompt, validator);
56 writereq.st =
nullptr;
64 AmigaWindow::~AmigaWindow()
70 void AmigaWindow::Create()
93 succeed = succeed && (writeport = CreatePort((
char*)PORTCR, 0)) != 0;
94 succeed = succeed && (readport = CreatePort((
char*)PORTCW, 0)) != 0;
95 succeed = succeed && (writereq.st = CreateExtIO(writeport,
sizeof(IOStdReq))) != 0;
96 succeed = succeed && (readreq.st = CreateExtIO(readport,
sizeof(IOStdReq))) != 0;
97 succeed = succeed && (window = OpenWindow(&nw)) != 0;
100 windowsig = 1 << window->UserPort->mp_SigBit;
101 writereq.io->io_Data = (APTR) window;
102 writereq.io->io_Length =
sizeof(Window);
104 openconsole = OpenDevice(DEVCONSOLE, CONU_SNIPMAP, writereq.st, CONFLAG_DEFAULT) == 0;
105 succeed = openconsole;
106 if (!openconsole)
return;
108 readreq.st->io_Device = writereq.st->io_Device;
109 readreq.st->io_Unit = writereq.st->io_Unit;
119 void AmigaWindow::Cleanup()
127 CloseDevice(writereq.st);
132 DeleteExtIO(readreq.st);
133 readreq.st =
nullptr;
137 DeletePort(readport);
142 DeleteExtIO(writereq.st);
143 writereq.st =
nullptr;
147 DeletePort(writeport);
162 void AmigaWindow::Start()
171 Evaluator *evaluator =
new Evaluator(line);
172 evaluator->Evaluate();
173 const char *out = evaluator->GetResult();
174 WriteString(out, StrLen(out));
181 void AmigaWindow::Exit()
186 void AmigaWindow::ReadLine()
188 unsigned long conreadsig = 1L << readport->mp_SigBit;
191 while(!proc->InputDone() && !exit)
193 unsigned long signals = Wait(conreadsig | windowsig);
195 if (signals & conreadsig)
197 unsigned char ch = TryGetChar(readport);
200 const char *out = proc->ProcessChar(ch);
205 if (signals & windowsig)
208 while ((w.msg = GetMsg(window->UserPort)))
210 switch(w.imsg->Class)
212 case IDCMP_CLOSEWINDOW:
227 line = proc->GetLine();
230 void AmigaWindow::WriteChar(
const char character)
232 writereq.io->io_Command = CMD_WRITE;
233 writereq.io->io_Data = (APTR)&character;
234 writereq.io->io_Length = 1;
238 void AmigaWindow::WriteString(
const char *string)
240 writereq.io->io_Command = CMD_WRITE;
241 writereq.io->io_Data = (APTR)string;
242 writereq.io->io_Length = (ULONG)-1;
246 void AmigaWindow::WriteString(
const char *string,
unsigned int length)
248 writereq.io->io_Command = CMD_WRITE;
249 writereq.io->io_Data = (APTR)string;
250 writereq.io->io_Length = (LONG)length;
254 unsigned char AmigaWindow::ReadChar(STRequest request)
256 unsigned char result = inputbuf;
257 request.io->io_Command = CMD_READ;
258 request.io->io_Data = (APTR)&inputbuf;
259 request.io->io_Length = 1;
264 unsigned char AmigaWindow::TryGetChar(MsgPort *msgport)
267 readreq.msg = GetMsg(msgport);
268 return readreq.msg == 0 ?
'\0' : ReadChar(readreq);
271 void AmigaWindow::SetPrompt(
const char* string)
273 ConsoleBase::SetPrompt(string);
274 proc->SetPrompt(string);