int kmain() { fb_write_cell(0, 'A', FB_GREEN, FB_DARK_GRAY); char *hello = "Hello, World!"; write_out(hello, 13); return 0xDEADBABE; }
/** fb_write_word: * Writes out word */ void fb_write_word() { // prints out 'ABCDE' in white on black font unsigned char black = 0x7; unsigned char grey = 0x0; unsigned int addr = 0; fb_write_cell(addr, 'T', grey, black); addr += 2; fb_write_cell(addr, 'O', grey, black); addr += 2; fb_write_cell(addr, 'N', grey, black); addr += 2; fb_write_cell(addr, 'Y', grey, black); addr += 2; fb_write_cell(addr, '!', grey, black); addr += 2; }
int fb_write(char *buf) { while(*buf != 0) { fb_move_cursor(currPos); fb_write_cell(2 * currPos++, *buf, FB_GREEN, FB_DARK_GREY); buf++; } return currPos; }
// Write the contents of a buffer of length len to the screen. Should // automatically advance the cursor after a character has been written, and // scroll if necessary. void fb_puts(char *buf, unsigned int len) { unsigned int i; for (i = 0; i < len; ++i) { fb_write_cell(cursor_pos, buf[i], curr_color & 0xF0, curr_color & 0x0F); cursor_pos = (cursor_pos + 1) % FB_NUM_CELLS; } fb_move_cursor(); }
/** write: * Writes a character buffer * * @param buf The character buffer * @param len The length of the buffer */ void write(char *buf, unsigned int len) { unsigned short i; for(i = 0; i < len; i++) { fb_write_cell(fb_current_pos, buf[i], 0, 15); fb_current_pos += 2; } }
// Write a null-terminated string to the monitor. void fb_write(char *str) { unsigned int i; i = 0; while (str[i] != '\0') { fb_write_cell(cursor_pos, str[i++], curr_color & 0xF0, curr_color & 0x0F); cursor_pos = (cursor_pos + 1) % FB_NUM_CELLS; } fb_move_cursor(); }
void fb_write_char(const char c) { if (c == '\n') { fb_curr_pos += (ROW_WIDTH-(fb_curr_pos%ROW_WIDTH)); } else { fb_write_cell(fb_curr_pos, c, FB_LIGHTGREY, FB_BLACK); fb_curr_pos+=2; } fb_set_cursor_pos(fb_curr_pos/2); }
void fb_clear() { unsigned int i, k; for (i = 0; i < ROW_HEIGHT; ++i) { for (k = 0; k < ROW_WIDTH; k+=2) { fb_write_cell((i*ROW_HEIGHT)+k, '\0', FB_LIGHTGREY, FB_BLACK); } } fb_set_cursor_pos(0); fb_curr_pos = 0; }
/** fb_clear: * Clears the framebuffer */ void fb_clear() { unsigned char black = 0x0; unsigned int addr = 0; unsigned int addr_max = 80 * 50; unsigned int i = 0; for (i = addr; i < addr_max; i += 2) { fb_write_cell(i, ' ', black, black); } }
/* Write a single character to the terminal */ void fb_write_char(char c) { if (c == '\t') { if (fb_cursor_column > 72) { c = '\n'; } else { fb_cursor_column += 8 - (fb_cursor_column % 8); return; } } /* Handle newline characters */ if (c == '\n') { fb_cursor_column = 0; fb_cursor_row++; return; } /* Wrap text by bumping the row when the column hits maximum width */ if (fb_cursor_column == VGA_WIDTH) { fb_cursor_column = 0; fb_cursor_row++; } if (fb_cursor_row == VGA_HEIGHT) { // Shift everyone up to make a new row available for (size_t row = 1; row < VGA_HEIGHT; row++) { for (size_t column = 0; column < VGA_WIDTH; column++) { const size_t entry = row * VGA_WIDTH + column; framebuffer[entry - VGA_WIDTH] = framebuffer[entry]; framebuffer[entry] = make_vga_entry(' ', COLOR_LIGHT_GREY, COLOR_BLACK); } } fb_cursor_column = 0; fb_cursor_row--; } fb_write_cell(c, COLOR_LIGHT_GREY, COLOR_BLACK, fb_cursor_row, fb_cursor_column); fb_cursor_column++; }
int fb_write(char *buf, unsigned int len) { unsigned int i; for(i=0; i<len; i++) { /* Write character at position i */ fb_write_cell(2*__fb_present_pos, buf[i], (unsigned char)0, (unsigned char)15); fb_move_cursor(__fb_present_pos + 1); /* If __fb_present_pos goes off the screen, move everything one line up */ if(__fb_present_pos == FRAMEBUFFER_WIDTH * FRAMEBUFFER_HEIGHT) { fb_move_cursor((FRAMEBUFFER_HEIGHT-1)*FRAMEBUFFER_WIDTH); int j; for(j=0; j<2*FRAMEBUFFER_WIDTH*(FRAMEBUFFER_HEIGHT-1); j++) { __fb[j] = __fb[j + FRAMEBUFFER_WIDTH*2]; } for(j=j; j<2*FRAMEBUFFER_WIDTH*FRAMEBUFFER_HEIGHT; j++) { __fb[j] = 0; } } } return len; }
// Write a single character to the screen from wherever the cursor is. void fb_putc(char c) { fb_write_cell(cursor_pos, c, curr_color & 0xF0, curr_color & 0x0F); cursor_pos = (cursor_pos + 1) % FB_NUM_CELLS; fb_move_cursor(); }