mbr_asm/vga.c

50 lines
1.3 KiB
C
Raw Normal View History

#include "vga.h"
2018-07-12 14:07:24 +02:00
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;
}
}
2018-07-12 14:07:24 +02:00
void printInt(int integer, uint color, uint bgColor, int startX, int startY)
{
2018-07-12 14:07:24 +02:00
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);
}
while (integer != 0) {
2018-07-12 14:18:21 +02:00
int digit = integer % 10;
num[i++] = (digit > 0) ? digit : -digit;
integer = integer / 10;
2018-07-12 14:07:24 +02:00
}
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;
}
2018-07-12 14:07:24 +02:00
void printString(const char *str, uint color, uint bgColor, int startX, int startY)
{
volatile short *vga = (short *)VGA_ADDR;
2018-07-12 14:07:24 +02:00
int i = 0;
long int colorAttr = (bgColor << 4 | (color & 0x0f)) << 8;
while (*str) {
vga[80 * startY + startX + i] = colorAttr | *str;
str++;
i++;
}
}