jankos/framebuffer.c
2019-01-23 00:53:28 -08:00

53 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
// The following colors are available(from 0x0 to 0xF):
// Black Blue Green Cyan Red Magenta
// Brown LightGrey DarkGrey LightBlue LightGreen
// LightCyan LightRed LightMagenta LightBrown White
/*
enum typedef Colors{
Black, Blue, Green,
Cyan, Red, Magenta,
Brown, LightGrey, DarkGrey,
LightBlue, LightGreen, LightCyan,
LightRed, LightMagenta, LightBrown,
White,
};
*/
#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
// Safety handled by caller function
// also proper location is caller's responsibility
void write_cell(unsigned cell, char c, char fg, char bg) {
Frame_Buffer[cell] = c;
Frame_Buffer[cell+1] = (fg & 0x0f << 4) | (bg & 0x0f);
}
void clear_buffer() {
char* fp = Frame_Buffer;
while(fp!=Frame_Buffer_End) {
*fp = 0x00;
}
}
static void print(char* str) {
unsigned idx = 0;
char* c = str;
while(c != 0x00) {
write_cell(idx, *c, Green, White);
idx += 2;
}
}
void yote() {
print(" JankOS ");
}