2010-06-13 05:17:42 -04:00
|
|
|
#include "../picoc.h"
|
2009-03-15 03:07:21 -04:00
|
|
|
|
|
|
|
|
|
|
|
/* deallocate any storage */
|
|
|
|
void PlatformCleanup()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get a line of interactive input */
|
2011-02-11 23:23:37 -05:00
|
|
|
char *PlatformGetLine(char *Buf, int MaxLen, const char *Prompt)
|
2009-03-15 03:07:21 -04:00
|
|
|
{
|
|
|
|
int ix;
|
|
|
|
char ch, *cp;
|
|
|
|
|
|
|
|
ix = 0;
|
|
|
|
cp = Buf;
|
|
|
|
while (ix++ < MaxLen) {
|
|
|
|
ch = getch();
|
|
|
|
if (ch == 0x1B) { // ESC character - exit
|
|
|
|
printf("leaving picoC\n\r");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (ch == '\n') {
|
|
|
|
*cp++ = '\n'; // if newline, send newline character followed by null
|
|
|
|
*cp = 0;
|
|
|
|
return Buf;
|
|
|
|
}
|
|
|
|
*cp++ = ch;
|
|
|
|
ix++;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* write a character to the console */
|
2009-04-27 00:56:58 -04:00
|
|
|
void PlatformPutc(unsigned char OutCh, union OutputStreamInfo *Stream)
|
2009-03-15 03:07:21 -04:00
|
|
|
{
|
2009-10-22 16:14:47 -04:00
|
|
|
if (OutCh == '\n')
|
|
|
|
putchar('\r');
|
|
|
|
|
2009-03-15 03:07:21 -04:00
|
|
|
putchar(OutCh);
|
|
|
|
}
|
|
|
|
|
2009-03-15 05:57:19 -04:00
|
|
|
/* read a character */
|
|
|
|
int PlatformGetCharacter()
|
2009-03-15 03:07:21 -04:00
|
|
|
{
|
|
|
|
return getch();
|
|
|
|
}
|
|
|
|
|
2009-04-03 23:11:12 -04:00
|
|
|
/* mark where to end the program for platforms which require this */
|
|
|
|
int ExitBuf[41];
|
2009-03-15 03:07:21 -04:00
|
|
|
|
2009-04-03 23:11:12 -04:00
|
|
|
/* exit the program */
|
2011-02-11 23:23:37 -05:00
|
|
|
void PlatformExit(int RetVal)
|
2009-03-15 03:07:21 -04:00
|
|
|
{
|
2011-02-11 23:23:37 -05:00
|
|
|
ExitValue = RetVal;
|
2009-04-03 23:11:12 -04:00
|
|
|
ExitBuf[40] = 1;
|
|
|
|
longjmp(ExitBuf, 1);
|
2009-03-15 03:07:21 -04:00
|
|
|
}
|
|
|
|
|