50 lines
1.3 KiB
C
50 lines
1.3 KiB
C
#include "vga.h"
|
|
|
|
void clearScreen(uint bgColor)
|
|
{
|
|
volatile short *vga = (short *)VGA_ADDR;
|
|
long int colorAttr = bgColor << 12;
|
|
for (int i = 0; i < VGA_WIDTH * VGA_HEIGHT; i++) {
|
|
vga[i] = colorAttr;
|
|
}
|
|
}
|
|
|
|
void printInt(int integer, uint color, uint bgColor, int startX, int startY)
|
|
{
|
|
char num[sizeof(int) *
|
|
3]; // int max is 2^(sizeof(int)*8) which is (2^3)^(sizeof(int)*8/3) =
|
|
// 8^(sizeof(int)*8/3) ~ 10^(sizeof(int)*8/3)
|
|
int x = startX;
|
|
int i = 0, k = 0;
|
|
if (integer < 0) {
|
|
printChar('-', color, bgColor, x++, startY);
|
|
integer = -integer;
|
|
}
|
|
while (integer != 0) {
|
|
num[i++] = integer % 10;
|
|
integer = integer / 10;
|
|
}
|
|
for (k = i - 1; k >= 0; k--) {
|
|
printChar(num[k] + '0', color, bgColor, x++, startY);
|
|
}
|
|
}
|
|
|
|
void printChar(const char str, uint color, uint bgColor, int startX, int startY)
|
|
{
|
|
volatile short *vga = (short *)VGA_ADDR;
|
|
long int colorAttr = (bgColor << 4 | (color & 0x0f)) << 8;
|
|
vga[80 * startY + startX] = colorAttr | str;
|
|
}
|
|
|
|
void printString(const char *str, uint color, uint bgColor, int startX, int startY)
|
|
{
|
|
volatile short *vga = (short *)VGA_ADDR;
|
|
int i = 0;
|
|
long int colorAttr = (bgColor << 4 | (color & 0x0f)) << 8;
|
|
while (*str) {
|
|
vga[80 * startY + startX + i] = colorAttr | *str;
|
|
str++;
|
|
i++;
|
|
}
|
|
}
|