[Stage1] Add IRQ remapping [Stage1] Handle IRQ0 gracefully [Stage1] Add error output functions
103 lines
No EOL
1.7 KiB
C
103 lines
No EOL
1.7 KiB
C
#include "../os3_common/datatypes.h"
|
|
#include "../os3_common/packing.h"
|
|
#include "include/screen.h"
|
|
|
|
int x = 0;
|
|
int y = 0;
|
|
|
|
void write_character(char c, os_u8 color) {
|
|
os_u16* vram = (os_u16*) 0xB8000;
|
|
os_u16* cursor_pos = vram + ((y * 80) + x);
|
|
*cursor_pos = c | (color << 8);
|
|
}
|
|
|
|
void screen_write(const char* str, int max_len, os_u8 color) {
|
|
int i = 0;
|
|
do {
|
|
char c = *str;
|
|
if (c == 0) {
|
|
return;
|
|
}
|
|
|
|
if (c == '\n') {
|
|
if (y == 24) {
|
|
screen_clear();
|
|
}
|
|
y = (y + 1) % 25;
|
|
x = 0;
|
|
str++;
|
|
continue;
|
|
}
|
|
|
|
write_character(c, color);
|
|
x++;
|
|
if (x >= 80) {
|
|
if (y == 24) {
|
|
screen_clear();
|
|
}
|
|
y = (y + 1) % 25;
|
|
x = 0;
|
|
}
|
|
str++;
|
|
i++;
|
|
} while(i < max_len || max_len == 0);
|
|
}
|
|
|
|
void screen_write_string(const char* str, int length) {
|
|
screen_write(str, length, 0x0A);
|
|
}
|
|
|
|
void screen_write_error(const char* str, int length) {
|
|
screen_write(str, length, 0x0C);
|
|
}
|
|
|
|
void screen_clear() {
|
|
os_u16* ptr = (os_u16*) 0xB8000;
|
|
for (int y = 0; y < 25; y++) {
|
|
for (int x = 0; x < 80; x++) {
|
|
*ptr = 0;
|
|
ptr++;
|
|
}
|
|
}
|
|
x = 0;
|
|
y = 0;
|
|
}
|
|
|
|
void screen_write_number_impl(os_u32 number, os_u8 color) {
|
|
char buffer[32];
|
|
char buffer_2[32];
|
|
|
|
os_s32 i = 1;
|
|
while(i < 32) {
|
|
if (i > 1 && number == 0) {
|
|
break;
|
|
}
|
|
|
|
buffer[i] = ((char)(number % 10)) + '0';
|
|
i++;
|
|
number /= 10;
|
|
}
|
|
i--;
|
|
buffer[0] = '\0';
|
|
char* buffer_2_ptr = buffer_2;
|
|
while(i >= 0) {
|
|
*buffer_2_ptr = buffer[i];
|
|
buffer_2_ptr++;
|
|
i--;
|
|
}
|
|
|
|
screen_write(buffer_2, 0, color);
|
|
}
|
|
|
|
void screen_write_number(os_u32 number) {
|
|
screen_write_number_impl(number, 0x0A);
|
|
}
|
|
|
|
void screen_write_number_error(os_u32 number) {
|
|
screen_write_number_impl(number, 0x0C);
|
|
}
|
|
|
|
void screen_set_pos(int nx, int ny) {
|
|
x = nx;
|
|
y = ny;
|
|
} |