jankos/framebuffer.c
shockrahwow 8d1879fe97 - Retesting framebuffer drivers
- clear_fb() fully working
- trying to add positional buffer writes for fancy output
- POSITION macro only seems to work for (0,0) coords for now
haven't tested other edge cases yet
2019-02-25 15:36:31 -08:00

45 lines
1.4 KiB
C

// Driver implementation for Jank's text frame buffer
// Buffer can display 80 columns by 25 Rows
// Start of buffer is at (real)address 0x000B8000
// Memory at this section is divided into 16-bit cells
// | 15-8 | 7-4 | 0-3
// | Asci | FG | BG
#include "framebuffer.h"
static char* Frame_Buffer = (char*)FRAME_BUFFER_ADDR;
static char* Frame_Buffer_End = (char*)(FRAME_BUFFER_ADDR + AREA);
// Writes character to a given cell in the framebuffer
// @cell parameter is the logical (linear)index into the buffer
// _not_ the actual offset from the buffer addr
// also proper location is caller's responsibility
void write_cell_fb(unsigned cell, char c, char fg, char bg) {
Frame_Buffer[cell] = c;
Frame_Buffer[cell+1] = (fg & 0x0f << 4) | (bg & 0x0f);
}
/* this probably doesn't belong here */
void print_fb(char* str, unsigned row, unsigned col) {
// now we can write things to our buffer
for(unsigned i =POSITION(row,col);i<strlen(str);i++) {
write_cell_fb(FRAME_CELL(i), str[i], Green, White);
}
}
void clear_fb() {
char* cell;
unsigned idx = Frame_Buffer_End - Frame_Buffer;
for(cell=Frame_Buffer;cell != Frame_Buffer_End; cell+=2) {
idx = Frame_Buffer_End - cell;
write_cell_fb(idx, ' ', 0x00, 0x00);
}
}
/* generic test func for this module */
void test_fb() {
clear_fb();
//print_fb("Helo from the frame buffer", 0, 0);
print_fb("adsf", 2, 2);
}