Merge branch 'main' of git.disroot.org:dvonik/omos-tcnj2024
idk
This commit is contained in:
commit
757f313f08
|
@ -16,4 +16,9 @@ typedef char s8;
|
||||||
typedef unsigned int size_t;
|
typedef unsigned int size_t;
|
||||||
typedef int ssize_t;
|
typedef int ssize_t;
|
||||||
|
|
||||||
|
typedef unsigned char *va_list;
|
||||||
|
#define va_start(list, param) (list = (((va_list)¶m) + sizeof(param)))
|
||||||
|
#define va_arg(list, type) (*(type *)((list += sizeof(type)) - sizeof(type)))
|
||||||
|
#define va_end(list) (list = NULL)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
82
sys/lib.c
82
sys/lib.c
|
@ -1,4 +1,5 @@
|
||||||
#include <types.h>
|
#include <types.h>
|
||||||
|
static char strbuf[32];
|
||||||
|
|
||||||
u32
|
u32
|
||||||
strlen(const char *str)
|
strlen(const char *str)
|
||||||
|
@ -10,11 +11,86 @@ strlen(const char *str)
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char*
|
||||||
|
itoa(s32 num, char *str, s32 base)
|
||||||
|
{
|
||||||
|
s32 i = 0;
|
||||||
|
|
||||||
|
if (num < 0 && base == 10) {
|
||||||
|
str[i++] = '-';
|
||||||
|
num = -num;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (num != 0) {
|
||||||
|
s32 remainder = num % base;
|
||||||
|
str[i++] = (remainder < 10) ? remainder + '0' : remainder + 'a' - 10;
|
||||||
|
num/=base;
|
||||||
|
}
|
||||||
|
|
||||||
|
str[i] = '\0';
|
||||||
|
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
char*
|
||||||
|
utoa(u32 num, char *str, s32 base)
|
||||||
|
{
|
||||||
|
s32 i = 0;
|
||||||
|
|
||||||
|
while (num != 0) {
|
||||||
|
s32 remainder = num % base;
|
||||||
|
str[i++] = (remainder < 10) ? remainder + '0' : remainder + 'a' - 10;
|
||||||
|
num/=base;
|
||||||
|
}
|
||||||
|
|
||||||
|
str[i] = '\0';
|
||||||
|
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
s32
|
s32
|
||||||
printf(const char *format, ...)
|
printf(const char *format, ...)
|
||||||
{
|
{
|
||||||
const u32 len = strlen(format);
|
const u32 len = sizeof(format);
|
||||||
|
va_list list;
|
||||||
|
va_start(list, len);
|
||||||
|
|
||||||
vga_write(format, len, 0x0f);
|
for (u32 i = 0; i < len; i++) {
|
||||||
return len;
|
if (format[i] == '%') {
|
||||||
|
if (format[i + 1] == 'd' || format[i + 1] == 'i') {
|
||||||
|
//integer numbers
|
||||||
|
const s32 num = va_arg(list, s32);
|
||||||
|
const char* str = itoa(num, strbuf, 10);
|
||||||
|
vga_write(str, sizeof(str), 0x0f);
|
||||||
|
} else if (format[i + 1] == 'o') {
|
||||||
|
//octal numbers
|
||||||
|
const s32 num = va_arg(list, s32);
|
||||||
|
const char *str = itoa(num, strbuf, 8);
|
||||||
|
vga_write(str, sizeof(str), 0x0f);
|
||||||
|
} else if (format[i + 1] == 'u') {
|
||||||
|
//unsigned integers
|
||||||
|
const u32 num = va_arg(list, u32);
|
||||||
|
const char *str = utoa(num, strbuf, 10);
|
||||||
|
vga_write(str, sizeof(str), 0x0f);
|
||||||
|
} else if (format[i + 1] == 'x') {
|
||||||
|
//hexadecimal numbers
|
||||||
|
const u32 num = va_arg(list, u32);
|
||||||
|
const char* str = utoa(num, strbuf, 16);
|
||||||
|
vga_write(str, sizeof(str), 0x0f);
|
||||||
|
} else if (format[i + 1] == 's') {
|
||||||
|
//strings
|
||||||
|
const char *str = va_arg(list, char*);
|
||||||
|
vga_write(str, strlen(str), 0x0f);
|
||||||
|
} else if (format[i + 1] == 'c') {
|
||||||
|
//one character
|
||||||
|
vga_write(va_arg(list, char), 1, 0x0f);
|
||||||
|
} else if (format[i + 1] == '%') {
|
||||||
|
vga_write('%', 1, 0x0f);
|
||||||
|
}
|
||||||
|
} else if (format[i] == '\\' && format[i + 1] == '%') {
|
||||||
|
vga_write('%', 1, 0x0f);
|
||||||
|
} else {
|
||||||
|
vga_write(format[i], 1, 0x0f);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,48 @@ sysinit(void)
|
||||||
char *howdy = "Om Smart.";
|
char *howdy = "Om Smart.";
|
||||||
|
|
||||||
vga_clearscreen();
|
vga_clearscreen();
|
||||||
|
/*
|
||||||
|
for (s16 i = 0; i < 100; i++) {
|
||||||
|
vga_write(howdy, strlen(howdy), 0x1f);
|
||||||
|
vga_write(howday, strlen(howday), 0x0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
vga_write("sid", 3, 0x07);
|
||||||
|
vga_write("did", 3, 0x07);
|
||||||
|
vga_write("fid", 3, 0x07);
|
||||||
|
*/
|
||||||
|
|
||||||
|
vga_write(
|
||||||
|
"Om Smart.Om Smarter.Om Smart.Om Smarter.Om Smart.Om Smarter.Om Smart.Om Smarter."
|
||||||
|
"Om Smart.Om Smarter.Om Smart.Om Smarter.Om Smart.Om Smarter.Om Smart.Om Smarter."
|
||||||
|
"Om Smart.Om Smarter.Om Smart.Om Smarter.Om Smart.Om Smarter.Om Smart.Om Smarter."
|
||||||
|
"Om Smart.Om Smarter.Om Smart.Om Smarter.Om Smart.Om Smarter.Om Smart.Om Smarter."
|
||||||
|
"Om Smart.Om Smarter.Om Smart.Om Smarter.Om Smart.Om Smarter.Om Smart.Om Smarter."
|
||||||
|
"Om Smart.Om Smarter.Om Smart.Om Smarter.Om Smart.Om Smarter.Om Smart.Om Smarter."
|
||||||
|
"Om Smart.Om Smarter.Om Smart.Om Smarter.Om Smart.Om Smarter.Om Smart.Om Smarter."
|
||||||
|
"Om Smart.Om Smarter.Om Smart.Om Smarter.Om Smart.Om Smarter.Om Smart.Om Smarter."
|
||||||
|
"Om Smart.Om Smarter.Om Smart.Om Smarter.Om Smart.Om Smarter.Om Smart.Om Smarter."
|
||||||
|
"Om Smart.Om Smarter.Om Smart.Om Smarter.Om Smart.Om Smarter.Om Smart.Om Smarter."
|
||||||
|
"Om Smart.Om Smarter.Om Smart.Om Smarter.Om Smart.Om Smarter.Om Smart.Om Smarter."
|
||||||
|
"Om Smart.Om Smarter.Om Smart.Om Smarter.Om Smart.Om Smarter.Om Smart.Om Smarter."
|
||||||
|
"Om Smart.Om Smarter.Om Smart.Om Smarter.Om Smart.Om Smarter.Om Smart.Om Smarter."
|
||||||
|
"Om Smart.Om Smarter.Om Smart.Om Smarter.Om Smart.Om Smarter.Om Smart.Om Smarter."
|
||||||
|
"Om Smart.Om Smarter.Om Smart.Om Smarter.Om Smart.Om Smarter.Om Smart.Om Smarter."
|
||||||
|
"Om Smart.Om Smarter.Om Smart.Om Smarter.Om Smart.Om Smarter.Om Smart.Om Smarter."
|
||||||
|
"Om Smart.Om Smarter.Om Smart.Om Smarter.Om Smart.Om Smarter.Om Smart.Om Smarter."
|
||||||
|
"Om Smart.Om Smarter.Om Smart.Om Smarter.Om Smart.Om Smarter.Om Smart.Om Smarter."
|
||||||
|
"Om Smart.Om Smarter.Om Smart.Om Smarter.Om Smart.Om Smarter.Om Smart.Om Smarter."
|
||||||
|
"Om Smart.Om Smarter.Om Smart.Om Smarter.Om Smart.Om Smarter.Om Smart.Om Smarter."
|
||||||
|
"Om Smart.Om Smarter.Om Smart.Om Smarter.Om Smart.Om Smarter.Om Smart.Om Smarter."
|
||||||
|
"Om Smart.Om Smarter.Om Smart.Om Smarter.Om Smart.Om Smarter.Om Smart.Om Smarter."
|
||||||
|
"Om Smart.Om Smarter.Om Smart.Om Smarter.Om Smart.Om Smarter.Om Smart.Om Smarter."
|
||||||
|
"Om Smart.Om Smarter.Om Smart.Om Smarter.Om Smart.Om Smarter.Om Smart.Om Smarter."
|
||||||
|
"Om Smart.Om Smarter.Om Smart.Om Smarter.Om Smart.Om Smarter.Om Smart.Om Smarter."
|
||||||
|
"bob", 2003, 0x0F);
|
||||||
|
vga_write("indian", 6, 0x07);
|
||||||
|
vga_write("indian", 6, 0x07);
|
||||||
|
|
||||||
|
printf("%s%x", "Omh", 0x2a);
|
||||||
vga_write("Starting omOS...", 16, 0x0F);
|
vga_write("Starting omOS...", 16, 0x0F);
|
||||||
|
|
||||||
memory_init();
|
memory_init();
|
||||||
|
|
Loading…
Reference in New Issue