Commit 3ce16712 authored by Mathieu Maret's avatar Mathieu Maret

Add way to print int

parent 1dd69e16
#include "vga.h"
void clearScreen(int bgColor)
void clearScreen(uint bgColor)
{
volatile short *vga = (short *)VGA_ADDR;
long int colorAttr = bgColor << 12;
......@@ -9,18 +9,37 @@ void clearScreen(int bgColor)
}
}
void printChar(const char str, int color, int bgColor, int startX, int startY)
void printInt(int integer, uint color, uint bgColor, int startX, int startY)
{
volatile short *vga = (short *)VGA_ADDR;
long int colorAttr = (bgColor << 4 | (color & 0x0f)) << 8;
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, int color, int bgColor, int startX,
int startY)
void printString(const char *str, uint color, uint bgColor, int startX, int startY)
{
volatile short *vga = (short *)VGA_ADDR;
int i = 0;
int i = 0;
long int colorAttr = (bgColor << 4 | (color & 0x0f)) << 8;
while (*str) {
vga[80 * startY + startX + i] = colorAttr | *str;
......
#pragma once
#include "types.h"
#define BLACK 0x00
#define BLUE 0x01
......@@ -14,6 +15,7 @@
#define VGA_WIDTH 80
#define VGA_HEIGHT 15
void clearScreen(int bgColor);
void printChar(const char str, int color, int bgColor, int startX, int startY);
void printString(const char *str, int color, int bgColor, int startX, int startY);
void clearScreen(uint bgColor);
void printInt(int integer, uint color, uint bgColor, int startX, int startY);
void printChar(char str, uint color, uint bgColor, int startX, int startY);
void printString(const char *str, uint color, uint bgColor, int startX, int startY);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment