void console_poll()
{
	int ch = 0;

	if(!uart_getchar)
		return;
	ch = uart_getchar();
	if (ch == -1)
		return;

	console_putc((unsigned int)ch);

	if (console_buf_loc + 1 >= MAX_CONSOLE_BUF
		|| ch == '\r'
		|| ch == '\n') {
		console_buf[console_buf_loc++] = (char)ch;
		console_buf[console_buf_loc] = 0;
		console_putc('\n');
		console_rx_cmd_complete(console_buf);
		console_buf_loc = 0;
		console_buf[console_buf_loc] = 0;
	}
	else {
		console_buf[console_buf_loc++] = (char)ch;
	}
}
Example #2
0
/*
 * This then will render a digit to the console, its good for
 * debugging.
 */
void
print_digit(int n) {
	uint8_t *row;
	unsigned int tx, ty;

	printf("Digit FB size (W, H) = (%d, %d)\n", DIGIT_FB_WIDTH, DIGIT_FB_HEIGHT);
	row = (uint8_t *)&digit_fb[(n % 10) * (DISP_WIDTH+SKEW_MAX)];
	for (ty = 0; ty < DISP_HEIGHT; ty++) {
		for (tx = 0; tx < (DISP_WIDTH + SKEW_MAX); tx++) {
			switch (*(row + tx)) {
			case 0:
				console_putc(' ');
				break;
			case 1:
				console_putc('*');
				break;
			case 2:
				console_putc('.');
				break;
			default:
				console_putc('X');
				break;
			}
		}
		printf("\n");
		row += DIGIT_FB_WIDTH;
	}
	/* END DEBUG CODE */
}
Example #3
0
void console_puts(unsigned int ch, const char *str)
{
	const char *s = str;
	while (*s) {
		if (*s == '\n')
			console_putc(ch, '\r');
		console_putc(ch, *s);
		s++;
	}
}
Example #4
0
/*
 * void console_puts(char *s)
 *
 * Send a string to the console, one character at a time, return
 * after the last character, as indicated by a NUL character, is
 * reached.
 */
void console_puts(char *s)
{
	while (*s != '\000') {
		console_putc(*s);
		/* Add in a carraige return, after sending line feed */
		if (*s == '\n') {
			console_putc('\r');
		}
		s++;
	}
}
Example #5
0
static ssize_t console_write(void *cookie, const char *buf, size_t size)
{
    cookie = cookie;            // -Wunused-parameter
    for (size_t i = 0; i < size; i++) {
        char c = buf[i];
        if (c == '\n')
            console_putc('\r');
        console_putc(c);
    }
    return size;
}
Example #6
0
/**
 * Output the line and place the cursor at the current position.
 *
 * @param editor        Line editor state.
 */
void line_editor_output(line_editor_t *editor) {
  size_t i;

  for (i = 0; i <= editor->len; i++) {
    console_putc(editor->console, editor->buf[i]);
  }

  while (i > editor->offset) {
    console_putc(editor->console, '\b');
    i--;
  }
}
Example #7
0
/**
 * Reprint from the current offset, mainting cursor position.
 *
 * @param editor        Line editor state.
 * @param space         Whether to print an additional space at the end (after
 *                      removing a character).
 */
static void reprint_from_current(line_editor_t *editor, bool space) {
  size_t i;

  for (i = editor->offset; i < editor->len; i++) {
    console_putc(editor->console, editor->buf[i]);
  }

  if (space) { console_putc(editor->console, '\b'); }

  while (i > editor->offset) {
    console_putc(editor->console, '\b');
    i--;
  }
}
Example #8
0
int console_puts(unsigned int ch, const char *str)
{
	int n = 0;

	while (*str) {
		if (*str == '\n')
			console_putc(CONSOLE_STDOUT, '\r');

		console_putc(CONSOLE_STDOUT, *str);
		str++;
		n++;
	}

	return n;
}
Example #9
0
/** Helper for vprintf().
 * @param ch            Character to display.
 * @param data          Unused.
 * @param total         Pointer to total character count. */
static void vprintf_helper(char ch, void *data, int *total) {
    console_putc(current_console, ch);
    console_putc(debug_console, ch);

    if (kboot_log) {
        kboot_log->buffer[(kboot_log->start + kboot_log->length) % kboot_log_size] = ch;
        if (kboot_log->length < kboot_log_size) {
            kboot_log->length++;
        } else {
            kboot_log->start = (kboot_log->start + 1) % kboot_log_size;
        }
    }

    *total = *total + 1;
}
Example #10
0
int console_puts(unsigned int ch, const char *str)
{
	const char *s = str;
	int i = 0;

	while (*s) {
		console_putc(ch, *s);
		if (*s == '\n')
			console_putc(ch, '\r');
		s++;
		i++;
	}

	return i;
}
Example #11
0
//prints a hex value of a string
void console_puth(const uint8_t *str,uint8_t count)
{
    uint8_t a;
    for(a=0;a<count;a++){
        console_puts(" 0x");
            if(((*str>>4)&0x0F)<=9)                     //check if the upper nibble is 0-9
                console_putc(((*str>>4)&0x0F)+48);      //hex 0x30 is ASCII 0
            else
                console_putc(((*str>>4)&0x0F)+55);      //hex 0x41 is ASCII 0
            if((*str&0x0F)<=9)                          //check if the upper nibble is 0-9
                console_putc((*str&0x0F)+48);           //hex 0x30 is ASCII 0
            else
                console_putc((*str&0x0F)+55);           //hex 0x41 is ASCII 0
        str++;                                          //increment pointer
    }
Example #12
0
/**
 * Handle input on the line editor.
 *
 * @param editor        Line editor state.
 * @param key           Key that was pressed.
 */
void line_editor_input(line_editor_t *editor, uint16_t key) {
  switch (key) {
  case CONSOLE_KEY_LEFT:
    if (editor->offset) {
      console_putc(editor->console, '\b');
      editor->offset--;
    }

    break;
  case CONSOLE_KEY_RIGHT:
    if (editor->offset != editor->len) {
      console_putc(editor->console, editor->buf[editor->offset]);
      editor->offset++;
    }

    break;
  case CONSOLE_KEY_HOME:
    while (editor->offset) {
      console_putc(editor->console, '\b');
      editor->offset--;
    }

    break;
  case CONSOLE_KEY_END:
    while (editor->offset < editor->len) {
      console_putc(editor->console, editor->buf[editor->offset]);
      editor->offset++;
    }

    break;
  case '\b':
    erase_char(editor, false);
    break;
  case 0x7f:
    erase_char(editor, true);
    break;
  case '\n':
    /* The shell code sends \n to place it at the end of the buffer. */
    editor->offset = editor->len;
    insert_char(editor, key);
    break;
  default:
    if (isprint(key))
      insert_char(editor, key);

    break;
  }
}
Example #13
0
void console_rx_callback(uint8_t c)
{
    switch(console_mode)
    {
        case CONSOLE_MODE_KEY:
            got_key = TRUE;
            last_key = c;
            break;

        case CONSOLE_MODE_LINE:
            if (got_line)   // throw away chars until the line is handled
                return;

            switch(c)
            {
                case 0x0D:
                //case '\r':
                    got_line = TRUE;
                    if (echo)
                        console_newline();
                    break;
                case '\b':  // backspace
                case 0x7F:  // del
                    if (cmdbuf_len > 0)
                    {
                        cmdbuf_len--;
                        if (echo)
                        {
                            console_putc('\b');
                            console_putc(' ');
                            console_putc('\b');
                        }
                    }
                    break;
                default:
                    if (cmdbuf_len < sizeof(cmdbuf)-1)
                    {
                        if (echo)
                            console_putc(c);
                        cmdbuf[cmdbuf_len++] = c;
                    }
                    else
                        console_putc('\a');  // bell
                    break;
            }
        break;
    }
}
Example #14
0
int console_puts(unsigned int ch, const char *str)
{
	const char *s = str;
	int n = 0;

	while (*s) {
		if (*s == '\n') {
			console_putc(ch, '\r');
			n++;
		}
		console_putc(ch, *s);
		n++;
		s++;
	}
	return n;
}
Example #15
0
void DMXMonitor::SetData(const uint8_t nPort, const uint8_t *pData, const uint16_t nLength) {
    uint8_t row = TOP_ROW;
    uint8_t *p = (uint8_t *)pData;
    uint16_t slot = 0;
    uint8_t i, j;

    for (i = 0; (i < 16) && (slot < nLength); i++) {

        console_set_cursor(4, ++row);

        for (j = 0; (j < 32) && (slot < nLength); j++) {
            const uint8_t d = *p++;
            if (d == (uint8_t) 0) {
                console_puts(" 0");
            } else {
                console_puthex_fg_bg(d, (uint16_t)(d > 92 ? CONSOLE_BLACK : CONSOLE_WHITE), (uint16_t)RGB(d,d,d));
            }
            (void) console_putc((int) ' ');
            slot++;
        }

        for (; j < 32; j++) {
            console_puts("-- ");
        }
    }

    for (; i < 16; i++) {
        console_set_cursor(4, ++row);
        console_puts("-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --");
    }

}
Example #16
0
int console_status(uint16_t color, const char *s) {
	char c;
	int i = 0;

	const uint16_t fore_current = cur_fore;
	const uint16_t back_current = cur_back;

	const uint16_t s_y = current_y;
	const uint16_t s_x = current_x;

	console_clear_line(29);

	cur_fore = color;
	cur_back = CONSOLE_BLACK;

	while ((c = *s++) != (char) 0) {
		i++;
		(void) console_putc((int) c);
	}

	current_y = s_y;
	current_x = s_x;

	cur_fore = fore_current;
	cur_back = back_current;

	return i;
}
Example #17
0
/*
 * int console_gets(char *s, int len)
 *
 * Wait for a string to be entered on the console, limited
 * support for editing characters (back space and delete)
 * end when a <CR> character is received.
 */
int console_gets(char *s, int len)
{
	char *t = s;
	char c;

	*t = '\000';
	/* read until a <CR> is received */
	while ((c = console_getc(1)) != '\r') {
		if ((c == '\010') || (c == '\127')) {
			if (t > s) {
				/* send ^H ^H to erase previous character */
				console_puts("\010 \010");
				t--;
			}
		} else {
			*t = c;
			console_putc(c);
			if ((t - s) < len) {
				t++;
			}
		}
		/* update end of string with NUL */
		*t = '\000';
	}
	return t - s;
}
Example #18
0
/* Put a character on the screen at the given position */
void tty_native_setc(tty_t t, int pos, char c)
{
	if(pos < 0) pos = 0;
	if(pos >= CONSOLE_ROWS * CONSOLE_COLS)
		pos = (CONSOLE_ROWS * CONSOLE_COLS) - 1;

        /* Is this a serial tty? */
        if(t->type==TTY_TYPE_SERIAL)
        {
                // if(t->active) serial_write(&c, 1);
                return;
        }

        /* If this tty is active, print out to the screen */
        if(t->active)
        {
                console_putc(pos, c, t->sgr.color,
                                t->type==TTY_TYPE_COLOR,
                                (char*)t->mem_start);
        }

        /* Update back buffer */
        if(t->type == TTY_TYPE_COLOR)
        {
                char* vid_addr = t->buffer + (pos * 2);
                *(vid_addr)     = c;
                *(vid_addr + 1) = t->sgr.color;
        } else {
                char* vid_addr = t->buffer + (pos);
                *(vid_addr)     = c;
        }
}
Example #19
0
static
int
serial_store(unsigned cpunum, void *d, uint32_t offset, uint32_t val)
{
    struct ser_data *sd = d;

    (void)cpunum;

    switch (offset) {
    case SERREG_CHAR:
        if (!sd->sd_wbusy) {
            sd->sd_wbusy = 1;
            g_stats.s_wchars++;
            console_putc(val);
            schedule_event(SERIAL_NSECS, sd, 0,
                           serial_writedone, "serial write");
        }
        return 0;
    case SERREG_RIRQ:
        storeirq(&sd->sd_rirq, val);
        setirq(sd);
        return 0;
    case SERREG_WIRQ:
        storeirq(&sd->sd_wirq, val);
        setirq(sd);
        return 0;
    }
    return -1;
}
Example #20
0
void console_puts(const char *str)
{
    const char *c;

    for (c = str; *c; c++)
        console_putc(*c);
}
Example #21
0
/*
 * Diag print handler
 */
static void
console_puts(char *str)
{
	size_t count;
	char c;

	sched_lock();
	for (count = 0; count < 128; count++) {
		c = *str;
		if (c == '\0')
			break;
		console_putc(c);
#if defined(CONFIG_DIAG_BOCHS)
		if (inb(0xe9) == 0xe9) {
			if (c == '\n')
				outb((int)'\r', 0xe9);
			outb(c, 0xe9);
		}
#endif
		str++;
	}
	move_cursor();
	esc_index = 0;
	sched_unlock();
}
Example #22
0
static int read_record(char *buf, ulong len)
{
	char *p;
	char c;

	--len;	/* always leave room for terminating '\0' byte */

	for (p=buf; p < buf+len; ++p) {
		c = getc();		/* read character		*/
		if (do_echo)
			console_putc(CONSOLE_STDOUT, c);

		switch (c) {
		case '\r':
		case '\n':
			*p = '\0';
			return p - buf;
		case '\0':
		case 0x03:			/* ^C - Control C		*/
			return -1;
		default:
			*p = c;
		}
	}

	/* line too long - truncate */
	*p = '\0';
	return p - buf;
}
Example #23
0
/**
 *
 * @param s
 * @param n
 */
void console_write(const char *s, int n) {
	char c;

	while (((c = *s++) != (char) 0) && (n-- != 0)) {
		(void) console_putc((int) c);
	}
}
Example #24
0
static ulong load_serial(ulong offset)
{
	char	record[SREC_MAXRECLEN + 1];	/* buffer for one S-Record	*/
	char	binbuf[SREC_MAXBINLEN];		/* buffer for binary data	*/
	int	binlen;				/* no. of data bytes in S-Rec.	*/
	int	type;				/* return code for record type	*/
	ulong	addr;				/* load address from S-Record	*/
	ulong	size;				/* number of bytes transferred	*/
	char	buf[32];
	ulong	store_addr;
	ulong	start_addr = ~0;
	ulong	end_addr   =  0;
	int	line_count =  0;

	while (read_record(record, SREC_MAXRECLEN + 1) >= 0) {
		type = srec_decode(record, &binlen, &addr, binbuf);

		if (type < 0) {
			return ~0;	/* Invalid S-Record		*/
		}

		switch (type) {
		case SREC_DATA2:
		case SREC_DATA3:
		case SREC_DATA4:
			store_addr = addr + offset;
			memcpy((char *)(store_addr), binbuf, binlen);
			if ((store_addr) < start_addr)
				start_addr = store_addr;
			if ((store_addr + binlen - 1) > end_addr)
				end_addr = store_addr + binlen - 1;
		break;
		case SREC_END2:
		case SREC_END3:
		case SREC_END4:
			udelay(10000);
			size = end_addr - start_addr + 1;
			printf("\n"
			    "## First Load Addr = 0x%08lX\n"
			    "## Last  Load Addr = 0x%08lX\n"
			    "## Total Size      = 0x%08lX = %ld Bytes\n",
			    start_addr, end_addr, size, size
			    );
			sprintf(buf, "%lX", size);
			setenv("filesize", buf);
			return addr;
		case SREC_START:
			break;
		default:
			break;
		}
		if (!do_echo) {	/* print a '.' every 100 lines */
			if ((++line_count % 100) == 0)
				console_putc(CONSOLE_STDOUT, '.');
		}
	}

	return ~0;			/* Download aborted		*/
}
Example #25
0
File: sys_stdio.c Project: gz/aos10
static size_t
console_write(char *data, long int position, size_t count, void *handle /*unused*/)
{
	size_t i;
	for (i = 0; i < count; i++)
		console_putc(data[i]);
	return count;
}
Example #26
0
static void printchar(char **str, int c)
{
  if (str) {
    **str = c;
    ++(*str);
  }
  else console_putc(c);
}
Example #27
0
File: bind.c Project: ccxvii/mio
static int ffi_print(lua_State *L)
{
	int i, n = lua_gettop(L);
	lua_getglobal(L, "tostring");
	for (i=1; i<=n; i++) {
		const char *s;
		lua_pushvalue(L, -1); /* tostring */
		lua_pushvalue(L, i); /* value to print */
		lua_call(L, 1, 1);
		s = lua_tostring(L, -1); /* get result */
		if (!s) return luaL_error(L, "'tostring' must return a string to 'print'");
		if (i > 1) console_putc('\t');
		console_print(s);
		lua_pop(L, 1); /* pop result */
	}
	console_putc('\n');
	return 0;
}
Example #28
0
void load_rom(file_descr_t *entry)
{
	file_t file;
	int i;
	DWORD size;

	console_clear();
	console_puts("Loading ");
	for (i=0; i<8; i++) {
		console_putc(entry->name[i]);
	}
	console_putc('.');
	for (i=8; i<11; i++) {
		console_putc(entry->name[i]);
	}
	console_puts("\n\n");

	fat_open_file(&file, entry->cluster);
	size = 0;
	while (1) {
		UBYTE* data;
		if ((size&0x3fff)==0) {
			// switch page 1
			*((UBYTE*)0xffff) = (size>>14)&0xff;
		}
		// write to page 2
		data = 0x8000+(size&0x3fff);
		data = fat_load_file_sector(&file,data);
		if (data==0) {
			console_puts("Error while reading file\n");
		} else if (data==FAT_EOF) {
			console_gotoxy(0,2);
			return;
		} else {
			// process data
			size += 0x200;
			if ((size)%16384 == 0)
			   console_puts(".");
			//console_gotoxy(0,3);
			//console_print_dword(size);
			//console_puts(" bytes loaded");
		}
	}
int putchar(int c)
{
	int res;
	if (console_putc((unsigned char)c) >= 0)
		res = c;
	else
		res = EOF;

	return res;
}
Example #30
0
/**
 *
 * @param s
 * @return
 */
int console_puts(const char *s) {
	char c;
	int i = 0;;

	while ((c = *s++) != (char) 0) {
		i++;
		(void) console_putc((int) c);
	}

	return i;
}