Example #1
0
File: vga.c Project: oridb/PhotonOS
void flush_video()
{
	clear_video();
	char c = current_tty->buffer.text[0];
	int vga_row = 0;
	int vga_column = 0;
	uint8_t color;
	
	for (int i = 0; i < STDIO_SIZE && c != 0; i++) {
		c = current_tty->buffer.text[i];
		color = make_color(current_tty->buffer.fg[i], current_tty->bg);

		switch (c) {
			case '\n':
				++vga_row;
				vga_column = -1;
				break;

			case '\t':
				for (int i = 0; i < current_tty->tabstop; ++i) {
					tty_putentryat(' ', color, vga_column, vga_row);
					vga_column++;
					if (vga_column == 80) {
						vga_row++;
						vga_column = 0;
					}
				}
				break;

			case '\b':
				--vga_column;
				tty_putentryat(' ', color, vga_column, vga_row);
				--vga_column;
				break;

			case '\a':
				// no sound support yet
				break;

			default:
				tty_putentryat(c, color, vga_column, vga_row);
				break;
		}
		vga_column++;
		if (vga_column == 80) {
			vga_row++;
			vga_column = 0;
		}
		if (tty_scroll(vga_row)) {
			vga_row = 24;
			vga_column = 0;
		}
	}
	tty_move_cursor(vga_row, vga_column);
}
Example #2
0
/* Do a line feed */
static void tty_new_line(tty_t t)
{
	t->cursor_pos += CONSOLE_COLS - 1;
	t->cursor_pos -= t->cursor_pos % CONSOLE_COLS;

	/* Scroll when needed */
	if(t->cursor_pos >= CONSOLE_COLS * CONSOLE_ROWS)
	{
		tty_scroll(t);
		t->cursor_pos = (CONSOLE_COLS * CONSOLE_ROWS)
			- CONSOLE_COLS;
	}

	/* Adjust cursor position */
	tty_carrige_return(t);
}
Example #3
0
void putchar(char c)
{
    /* Prints a char */
    switch (c)
    {
        case '\n':
            putchar('\r');
            ++tty.y;
            break;

        case '\r':
            tty.x = 0;
            break;

        case '\t':
            tty.x += 4;
            tty.x &= 0xfc; /* Remove the last 2 bits making it aligned by 4 */
            break;

        default:
            if (isprint(c))
            {
                tty.buf[tty.y * SCR_WIDTH + tty.x] = c | (tty.attr << 8);
                ++tty.x;
            }
            break;
    }

    if (tty.x >= SCR_WIDTH)
    {
        tty.x = 0;
        ++tty.y;
    }

    if (tty.y >= SCR_HEIGHT)
    {
        tty.y = SCR_HEIGHT-1;
        tty_scroll();
    }

    tty_move_cursor();
}
Example #4
0
void tty_putc (char c)
{
	const size_t idx = tty_row * VGA_WIDTH + tty_column;

	switch (c)
	{
	case '\n': goto newline;
	case '\r': goto linefeed;
	case '\b': goto backspace;
	default  : goto print;
	}

print:
	tty_buffer[idx] = vga_entry(c, tty_color);

	if (tty_column == VGA_WIDTH - 1)
		goto newline;
	else
		tty_column++;

	goto done;

newline:
	tty_row++;
	tty_scroll();

linefeed:
	tty_column = 0;
	goto done;

backspace:
	if (tty_column != 0) tty_column--;
	goto done;

done:
	tty_updatecur();
	return;
}