-
-
Save ScriptedDeveloper/b2840aebc82099c10fe8acd062c50812 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "video.h" | |
#define VGA_WIDTH 25 | |
#define VGA_HEIGHT 80 | |
char* vgaBuffer = (char*) 0xb8000; // screen buffer (VGA Text Mode) | |
int vgaBufferInt = 8000; // to change newlines | |
int term_height = 0; | |
int term_width = 0; | |
void print(char *string){ | |
for(long i = 0; string[i] != '\0'; i++){ | |
const int id = (VGA_HEIGHT * term_width) + term_height; | |
term_height++; | |
if(string[i] == '\n'){ | |
term_height = 0; | |
term_width++; term_width++; | |
} | |
else if(string[i] == '\e'){ | |
terminal_clear_screen(); | |
print("CrazeOS > "); | |
} | |
else{ | |
vgaBuffer[id] = string[i]; | |
term_height++; | |
vgaBuffer[id + 1] = 15; | |
} | |
} | |
return; | |
} | |
void putchar(char c){ | |
const int id = (VGA_HEIGHT * term_width) + term_height; | |
term_height++; | |
vgaBuffer[id] = c; | |
term_height++; | |
vgaBuffer[id + 1] = 15; | |
return; | |
} | |
void terminal_clear_screen(){ | |
term_height = 0; | |
term_width = 0; | |
int limit = (VGA_WIDTH * 2) * (VGA_HEIGHT); | |
for (int i = 0; i < limit; ++i) { | |
vgaBuffer[i] = 0; | |
} | |
return; | |
} | |
void printf(char *args, ...){ | |
va_list ap; | |
va_start(ap, args); | |
char *s; | |
char c; | |
int i; | |
uint32_t x; | |
for(; *args != '\0'; args++) { | |
if(*args != '%') { | |
print(*args); | |
args++; | |
} | |
args++; | |
switch(*args) { | |
case 's' : | |
s = va_arg(ap, char*); | |
args++; | |
print(s); | |
break; | |
case 'c' : | |
c = va_arg(ap, int); | |
args++; | |
putchar(c); | |
break; | |
case 'i' : | |
i = va_arg(ap, int); | |
print(itoa(i, 10)); | |
args++; | |
break; | |
case 'x' : | |
x = va_arg(ap, uint32_t); | |
print("0x"); | |
print(itoa(x, 16)); | |
args++; | |
break; | |
} | |
} | |
va_end(ap); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment