Exemple #1
0
/********************************************************************
 * Gets a string of maximum 'len' chars.
 * ToDo:
 *  - use arrow keys which holds history (char *history[]).
 *  - 'str' can hold a default string which will be printed on the
 *    screen.
 *  - decent edit function instead of just backspace.
 *  - timeout (?)
 *
 * In  : con_idx = index number of the console.
 *       *str    = enough room to store the string
 *       len     = maximum length of the string
 *
 * Out : -1 on error, 1 on OK
 */
int con_gets (console_t *console, char *str, int len) {
  unsigned char ch;
  int tmplen=0;

  if (console == NULL) return ERR_CON_INVALID_CONSOLE;

  do {
    // Get a key from the console
    ch = keyboard_poll ();

    switch (ch) {
      // Backspace
      case 8  : // Remove last char by placing a #0 on top of it
                if (tmplen!=0) {
                  tmplen--;
                  str[tmplen]='\0';
                  con_putch (console, 8);         // Backspace
                  con_flush (console);
                }
                break;
      // Enter
      case 13 :
                break;
      default :
                if (tmplen!=len) {       // Only accept char when we're not at the maximum length
                  str[tmplen]=ch;
                  str[tmplen+1]='\0';
                  con_putch (console, ch);
                  con_flush (console);
                  tmplen++;
                }
                break;
    }
  } while (ch!=13); // repeat until <enter> pressed.

  return ERR_OK;
}
Exemple #2
0
/********************************************************************
 * Prints the string to the con_idx's console buffer. Takes care of
 * updating the screen when it's the current console.
 *
 * In  : con_idx = index number of the console.
 *       fmt     = string which holds a normal "printf" format
 *       ...     = unknown number of parameters of all kinds (va_list)
 *
 * Out : -1 on error, 1 on OK
 */
int con_printf (console_t *console, const char *fmt, ...) {
  va_list args;

  if (console == NULL) return ERR_CON_INVALID_CONSOLE;

  va_start (args, fmt);
  do_printf (fmt, args, &con_printf_helper, (void *)console);
  va_end (args);

  // Show the string we just printed if necessary...
  con_flush (console);

  // Return
  return ERR_OK;
}
Exemple #3
0
void handle_break(struct dhdr FAR **pdev, int sft_out)
{
  char *buf = "^C\r\n";

  CB_FLG &= ~CB_MSK;            /* reset the ^Break flag */
  con_flush(pdev);
  if (sft_out == -1)
    cooked_write(pdev, 4, buf);
  else
    DosRWSft(sft_out, 4, buf, XFR_FORCE_WRITE);
  if (!ErrorMode)               /* within int21_handler, InDOS is not incremented */
    if (InDOS)
      --InDOS;                  /* fail-safe */

  spawn_int23();                /* invoke user INT-23 and never come back */
}
Exemple #4
0
/************************************************************************
  Print the prompt if it is not the last thing printed.
************************************************************************/
static void con_update_prompt(void)
{
  if (console_prompt_is_showing || !console_show_prompt)
    return;

#ifdef HAVE_LIBREADLINE
  if (readline_received_enter) {
    readline_received_enter = FALSE;
  } else {
    rl_forced_update_display();
  }
#else
  con_dump(C_READY,"> ");
  con_flush();
#endif

  console_prompt_is_showing = TRUE;
}
Exemple #5
0
/********************************************************************
 * Clears the screenbuffer and updates the screen (if necessary)
 *
 * In  : con_idx = index number of the console.
 *
 * Out : -1 on error, 1 on OK
 */
int con_clrscr (console_t *console) {
  int i;

  if (console == NULL) return ERR_CON_INVALID_CONSOLE;

  // Clear the buffer.
  i=0;
  while (i != console->size) {
    console->buf[i++] = ' ';
    console->buf[i++] = console->attr;
  }

  // The whole screen must be flushed
  con_set_complete_flush (console);

  // Goto start of the screen and flush screen
  con_setxy (console, 0, 0);
  con_flush (console);

  // Return
  return ERR_OK;
}
Exemple #6
0
INT32 prew(UINT32* szb, CHAR** b, CHAR** cbu, INT32* c, UINT32* sty, UINT32 stx, UINT32 scrh, UINT32 scrw)
{
	COLORIZED col[1024];
	static UINT32 ncol = 0;
	static CHAR* cu = NULL;
	static UINT32 insty;
	static UINT32 instx;
	
	if (cu == NULL )
	{
		cu = col[0].word;
		insty = *sty;
		instx = stx;
	}
		
	
	CHAR* buf = *b;
	CHAR* cbuf = *cbu;
	
	UINT32 cb = cbuf - buf;
	UINT32 cy,cx;
	UINT32 i;
	
	cy = *sty + ( cb + stx -1) / scrw;
	if ( cy == *sty ) 
		cx =  (cb + stx) % scrw;
	else
		cx = (cb - (scrw - stx)) % scrw;
		
	if (!cx ) cx = scrw;
	
	if ( insty != *sty )
	{
		insty = *sty;
		for ( i = 0; i < ncol; ++i)
			col[i].syw = insty;
	}
	
	if ( *c != ' ' )
	{
		for ( i = 0; i < ncol; ++i)
		{
			con_gotorc(col[i].syw,col[i].sxw);
			con_setcolor(0,col[i].color);
			printf("%s",col[i].word);
		}
		*cu++ = *c;
		con_setcolor(0,0);
		con_gotorc(cy,cx);
		con_flush();
		return CON_INPEX_NONE;
	}
	
    *cu = '\0';
	
	if ( !strcmp(col[ncol].word,"con") )
	{
		col[ncol].syw = cy;
		col[ncol].sxw = cx - (( cu - col[ncol].word) + 1);
		col[ncol].color = CON_COLOR_RED;
		++ncol;
		cu = col[ncol].word;
	}
	else
	{
		cu = col[ncol].word;
	}
	
	for ( i = 0; i < ncol; ++i)
	{
		con_gotorc(col[i].syw,col[i].sxw);
		con_setcolor(0,col[i].color);
		printf("%s",col[i].word);
	}
	con_setcolor(0,0);
	con_gotorc(cy,cx);
	con_flush();
	
	return CON_INPEX_NONE;
}
Exemple #7
0
int main(int argc, char **argv)
{		
	
	printf("input$ ");
	con_flush();
	CHAR* r = con_input(NULL,NULL,FALSE,NULL,0);
	
	printf("\n[%s]\n",r);
	
	free(r);
	return 0;
	
	
	/*
	CONMSG cm;
	con_msg(&cm,"init",0);
		con_printfk_reg('a',pk_sum);
	con_msg(&cm,NULL,100);
	
	con_printfk("5 + 5 = %5.5a\n");
	
	INT32 a = 13;
	INT32 b = 37;
	con_printfk("%d + %d = %*.*a\n%@",a,b,a,b);
	
	
	con_msg(&cm,"press any key to continue...",0);
		con_async(1,NULL);
			while(!con_kbhit());
			CHAR c = con_getchex();
		con_async(0,NULL);
		if ( c == 27 ) 
		{
			con_msg(&cm,NULL,-1);
			return 0;
		}
	con_msg(&cm,NULL,100);
	
	con_cls();
	UINT32 sw,sh;
	con_getmaxrc(&sh,&sw);
	
	
	con_rect(1,1,sh,sw);
	con_circle(sh/2+1,sw/2,sh/2 - 1,'.');
	
	con_line(sh/2 + 1, sw/2 - sw/4, sh/2 + 1, sw/2 + sw/4, '-');
	con_line(sh/2 - sh/3 + 1, sw/2 - sw/4, sh/2 + sh/3 + 1, sw/2 + sw/4, '\\');
	con_line(sh/2 + sh/3 + 1, sw/2 - sw/4, sh/2 - sh/3 + 1, sw/2 + sw/4, '/');
	
	con_gotorc(2,2);
	con_printfk("press any key to continue...%@");
	con_async(1,NULL);
		while(!con_kbhit());
		c = con_getchex();
	con_async(0,NULL);
	
	con_cls();
	
	return 0;
	*/
	
	
    con_async(1);
    
    INT32 c;
    while (1)
    {
		printf("wait kb\n");
		con_flush();
		while(!con_kbhit()) thr_sleep(0.001);
		printf("get kb\n");	
		con_flush();
		c = con_getchex();
		printf("[%d(%c)]",c,c);
			
		con_flush();
		
		if ( c == 'q' ) break;
	}
    
    con_async(0);
    
    return 0;
}
Exemple #8
0
// returns an ASCII character from the keyboard; will wait here forever until a key is pressed
// not all characters are supported
char con_getkey()
{

	unsigned char result = 0;
	SDL_Event event;

#ifdef CPU_DEBUG
		con_flush(); // print current line
#endif

		SDL_EnableUNICODE(1);
		while (!result && !get_quitflag())
		{
			if (SDL_PollEvent (&event))
			{
				switch (event.type)
				{
				case SDL_KEYDOWN:
					switch (event.key.keysym.sym)
					{
					case SDLK_BACKSPACE:
						result = 8;
						break;
					case SDLK_RETURN:
						result = 13;
						break;
					case SDLK_ESCAPE:
						result = 27;
						break;
					case SDLK_BACKQUOTE:
#ifdef CPU_DEBUG
						toggle_console();
#endif
						result = 0;
						break;
					default:
						result = (unsigned char) event.key.keysym.unicode;
						break;
					}
					break;
				//WO: make any joystick button = enter,
				// so lazy folks (like me) can pass the issues screen
				// without going to the keyboard :)
				case SDL_JOYBUTTONDOWN:
#ifndef GP2X
					result = 13;
#else
					// one of the buttons needs to exit the emulator
					switch(event.jbutton.button)
						{
							// L is #10, and it will map to escape for now ...
							case 10:
								result = 27;
								break;
							case 15:	// Y (hide console)
#ifdef CPU_DEBUG
								toggle_console();
#endif
								result = 0;
								break;
							default:
								result = 13;
								break;
						}
						break;
#endif
					break;
				case SDL_QUIT:
					set_quitflag();
					break;
				default:
					break;
				}
			} // end if

			check_console_refresh();
			SDL_Delay(1);	// sleep to be CPU friendly
			
#ifdef UNIX
			// NOTE : non-blocking I/O should be enabled, so we will get EOF if there is nothing waiting for us ...
			int iRes = getchar();
			if (iRes != EOF)
			{
				result = (unsigned char) iRes;
			}
#endif

			
		} // end while
		SDL_EnableUNICODE(0);

		
	return(result);
}
Exemple #9
0
// ========================================================
int sys_conflush (void) {
    con_flush (_current_task->console);
    return 0;
}