TCHAR *amx_gets(TCHAR *string,int size) { int c=-1,num=0; if (createconsole(0, NULL)) { while (num+1<size && !(c==__T('\r') || c==__T('\n'))) { c=amx_getch(); if (c<0) break; if (c==__T('\r')) c=__T('\n'); /* translate carriage return to newline */ if (c==__T('\b')) { if (num>0) string[--num]=__T(' '); } else { string[num++]=(TCHAR)c; } /* if */ amx_putchar(c); /* echo the character read */ } /* while */ if (num<size) string[num]=__T('\0'); return string; } /* if */ return 0; }
int amx_termctl(int cmd,int value) { switch (cmd) { case 0: return 1; /* simple "is terminal support available" check */ case 1: if (createconsole(0, NULL)) { autowrap=value; return 1; } /* if */ return 0; case 2: return 0; case 3: return 0; case 4: while (app != NULL && win != NULL && do_event(app)) /* nothing */; if (win == NULL) deleteconsole(); return (win != NULL); default: return 0; } /* switch */ }
void amx_wherexy(int *x,int *y) { if (createconsole(0, NULL)) { if (x!=NULL) *x=csrx+1; if (y!=NULL) *y=csry+1; } /* if */ }
void amx_clrscr(void) { if (createconsole(0, NULL)) { assert(lines != NULL); memset(lines, __T(' '), NUM_LINES * NUM_COLUMNS); csrx = csry = 0; refresh_screen(0, NUM_LINES); } /* if */ }
void amx_gotoxy(int x,int y) { if (createconsole(0, NULL)) { if (x>0 && x<=NUM_COLUMNS) csrx=x-1; if (y>0 && y<=NUM_LINES) csry=y-1; refresh_screen(0, 0); /* only to set the cursor at the correct location */ } /* if */ }
void amx_clreol(void) { if (createconsole(0, NULL)) { int i; int size=NUM_COLUMNS-csrx; int pos=csry*NUM_COLUMNS+csrx; assert(lines!=NULL); for (i=0; i<size; i++) { lines[pos+i]=__T(' '); //??? lines[pos+i+1]=attrib; } /* for */ refresh_screen(csry, csry + 1); } /* if */ }
int amx_getch(void) { int c=-1; if (createconsole(0, NULL)) { while (keyq_start==keyq_end && app!=NULL) { wait_event(app); do_event(app); } /* while */ c=(int)keyqueue[keyq_start]; keyq_start=(keyq_start+1)%KEYQUEUE_SIZE; } /* if */ return c; }
unsigned int amx_setattr(int foregr,int backgr,int highlight) { int prev=0; if (createconsole(0, NULL)) { int f,b,h; f=attrib & 0x07; b=(attrib >> 4) & 0x0f; h=(attrib & 0x08) ? 1 : 0; prev=(b << 8) | f | (h << 15); if (foregr>=0 && foregr<8) f=foregr; if (backgr>=0 && backgr<8) b=backgr; if (highlight>=0) h=highlight!=0; attrib=(TCHAR)((b << 4) | f | (h << 3)); } /* if */
int amx_putstr(const TCHAR *format) { if (createconsole(0, NULL)) { int pos, i; pos=csry * NUM_COLUMNS + csrx; assert(lines!=NULL); for (i=0; string[i]!=__T('\0'); i++) { if (csry<NUM_LINES && csrx<NUM_COLUMNS) { if (string[i]==__T('\r')) { csrx=0; pos=csry * NUM_COLUMNS + csrx; } else if (string[i]==__T('\n')) { csrx=0; csry++; if (csry>=NUM_LINES) scroll_window(0, -1); pos=csry * NUM_COLUMNS + csrx; } else if (string[i]==__T('\b')) { if (csrx>0) { csrx--; pos--; lines[pos]=__T(' '); //??? lines[pos+1]=attrib; } /* if */ } else { lines[pos]=string[i]; //??? lines[pos+1]=attrib; pos++; csrx++; if (csrx>=NUM_COLUMNS && autowrap) { csrx=0; csry++; if (csry>=NUM_LINES) scroll_window(0, -1); pos=csry * NUM_COLUMNS + csrx; } /* if */ } /* if */ } /* if */ } /* for */ refresh_screen(csry,csry+1); } /* if */ return 0; }
int amx_getch(void) { int c=-1; if (createconsole(0, NULL)) { int cursor=0; if (keyq_start==keyq_end) { amx_putchar(__T('_')); /* must wait for character, so put pseudo-cursor */ cursor=1; } /* if */ while (keyq_start==keyq_end && app!=NULL) { wait_event(app); do_event(app); } /* while */ c=(int)keyqueue[keyq_start]; if (c=='\n') c='\r'; /* enter key must be '\r' for Pawn */ keyq_start=(keyq_start+1)%KEYQUEUE_SIZE; if (cursor) amx_putchar(__T('\b')); /* remove speudo-cursor */ } /* if */ return c; }
int amx_putchar(int c) { if (createconsole(0, NULL)) { if (csry<NUM_LINES && csrx<NUM_COLUMNS) { int pos=csry*NUM_COLUMNS+csrx; assert(lines!=NULL); if (c==__T('\r')) { csrx=0; } else if (c==__T('\n')) { csrx=0; csry++; if (csry>=NUM_LINES) scroll_window(0, -1); } else if (c==__T('\b')) { if (csrx>0) { csrx--; pos--; lines[pos]=__T(' '); //??? lines[pos+1]=attrib; } /* if */ } else { lines[pos]=(TCHAR)c; //??? lines[pos+1]=attrib; csrx++; if (csrx>=NUM_COLUMNS && autowrap) { csrx=0; csry++; if (csry>=NUM_LINES) scroll_window(0, -1); } /* if */ } /* if */ refresh_screen(csry,csry+1); } /* if */ } /* if */ return 1; }
int amx_kbhit(void) { if (createconsole(0, NULL)) return keyq_start!=keyq_end; return 0; }