diff --git a/.gitignore b/.gitignore
index 07b498d..17a1953 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
build/
-.mailmap
\ No newline at end of file
+.mailmap
+.vscode
\ No newline at end of file
diff --git a/README.md b/README.md
index a1074ce..70c23f8 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,6 @@
+
This is the "Coding" branch, the code in this branch is full of bugs and errors or simply doesn't compile, please use the main branch!
+
+
Hey all, Vincenzo Aleskey Brocato (VinceAle7082) here!
This is a little project where I try to make an OS just for fun
diff --git a/src/bootloader/stage2/main.c b/src/bootloader/stage2/main.c
index 7592ea9..1e7137d 100644
--- a/src/bootloader/stage2/main.c
+++ b/src/bootloader/stage2/main.c
@@ -1,7 +1,7 @@
#include "stdint.h"
#include "stdio.h"
-void _cdecl cstart_(uint16_t bootDrive)
+void _cdecl cstart_(uint16_t bootDrive)
{
puts("Hello World from the Stage 2 of the bootloader written in C!");
for (;;);
diff --git a/src/bootloader/stage2/main.err b/src/bootloader/stage2/main.err
deleted file mode 100644
index f07be74..0000000
--- a/src/bootloader/stage2/main.err
+++ /dev/null
@@ -1,3 +0,0 @@
-stdio.h(4): Warning! W138: No newline at end of file
-main.c(8): Warning! W138: No newline at end of file
-main.c(4): Warning! W303: Parameter 'bootDrive' has been defined, but not referenced
diff --git a/src/bootloader/stage2/stdint.h b/src/bootloader/stage2/stdint.h
index a250c54..2999fd9 100644
--- a/src/bootloader/stage2/stdint.h
+++ b/src/bootloader/stage2/stdint.h
@@ -8,5 +8,7 @@ typedef signed long int int32_t;
typedef unsigned long int uint32_t;
typedef signed long int int64_t;
typedef unsigned long int uint64_t;
+typedef uint8_t bool;
-
+#define true 1
+#define false 0
diff --git a/src/bootloader/stage2/stdio.c b/src/bootloader/stage2/stdio.c
index 327355c..439bf8f 100644
--- a/src/bootloader/stage2/stdio.c
+++ b/src/bootloader/stage2/stdio.c
@@ -13,3 +13,154 @@ void puts(const char *str)
str++;
}
}
+
+#define PRINTF_STATE_NORMAL 0
+#define PRINTF_STATE_LENGHT 1
+#define PRINTF_STATE_LENGHT_SHORT 2
+#define PRINTF_STATE_LENGHT_LONG 1
+#define PRINTF_STATE_SPEC 4
+#define PRINTF_LENGTH_DEFAULT 0
+#define PRINTF_LENGTH_SHORT_SHORT 1
+#define PRINTF_LENGTH_SHORT 2
+#define PRINTF_LENGTH_LONG 3
+#define PRINTF_LENGTH_LONG_LONG 4
+int* printf_number(int *argp, int length, bool sign, int radix)
+const char g_HexChars[] = '0123456789abcdef'
+
+void _cdecl printf(const char *fmt, ...)
+{
+ int *argp = (int*)&fmt;
+ int state = PRINTF_STATE_NORMAL;
+ int length = PRINTF_LENGTH_DEFAULT;
+ int radix = 10;
+ bool sign = false;
+ argp++;
+ while (*fmt)
+ {
+ switch (state)
+ {
+ case PRINTF_STATE_NORMAL:
+ switch (*fmt)
+ {
+ case '%':
+ state = PRINTF_STATE_LENGHT;
+ break;
+ default:
+ putc(*fmt);
+ break;
+ }
+
+ case PRINTF_STATE_LENGHT:
+ switch (*fmt)
+ {
+ case 'h':
+ length = PRINTF_LENGTH_SHORT;
+ state = PRINTF_STATE_LENGHT_SHORT;
+ break;
+ case 'l':
+ length = PRINTF_LENGTH_LONG;
+ state = PRINTF_STATE_LENGHT_LONG;
+ break;
+
+ default:
+ goto PRINTF_STATE_SPEC;
+ }
+ break;
+
+ case PRINTF_LENGTH_SHORT:
+ if (*fmt == 'h')
+ {
+ length = PRINTF_LENGTH_SHORT_SHORT;
+ state = PRINTF_STATE_SPEC;
+ }
+ else
+ {
+ goto PRINTF_STATE_SPEC;
+ }
+ break;
+
+ case PRINTF_STATE_SPEC:
+ switch (*fmt)
+ {
+ case 'c':
+ putc((char)*argp);
+ argp++;
+ break;
+ case 's':
+ puts(*(char **)argp);
+ argp++;
+ break;
+ case '%':
+ putc('%');
+ break;
+ case 'd':
+ case 'i':
+ radix = 10;
+ sign = true;
+ argp = printf_number(argp, length, sign, radix);
+ break;
+ case 'u':
+ radix = 10;
+ sign = false;
+ argp = printf_number(argp, length, sign, radix);
+ break;
+ case 'x':
+ case 'X':
+ case 'p':
+ radix = 16;
+ sign = false;
+ argp = printf_number(argp, length, sign, radix);
+ break;
+ case 'o':
+ radix = 8;
+ sign = false;
+ argp = printf_number(argp, length, sign, radix);
+ break;
+ //Se รจ messo un carattere non valido questo codice fa in modo che li ignora.
+ default:
+ break;
+ }
+ //Porta le variabili allo stato di default / normale.
+ state = PRINTF_STATE_NORMAL;
+ length = PRINTF_LENGTH_DEFAULT;
+ radix = 10;
+ sign = false;
+ break;
+ }
+ fmt++;
+ }
+}
+
+int* printf_number(int* argp, int length, bool sign, int radix)
+{
+ char buffer[32];
+ unsigned long long number;
+ int number_sign = 1;
+ int pos = 0;
+
+ switch (length)
+ {
+ case PRINTF_LENGTH_SHORT_SHORT:
+ case PRINTF_LENGTH_SHORT:
+ case PRINTF_LENGTH_LONG:
+ case PRINTF_LENGTH_LONG_LONG:
+ case PRINTF_LENGTH_DEFAULT:
+ if (sign)
+ {
+ int n = *argp;
+ if (n < 0)
+ {
+ n = -n;
+ number_sign = -1;
+ }
+ number = n;
+ }
+ else
+ {
+ number = (*unsigned int*)argp;
+
+ }
+ argp++;
+ break;
+ }
+}
\ No newline at end of file
diff --git a/src/bootloader/stage2/stdio.err b/src/bootloader/stage2/stdio.err
deleted file mode 100644
index f5ae572..0000000
--- a/src/bootloader/stage2/stdio.err
+++ /dev/null
@@ -1,2 +0,0 @@
-stdio.h(4): Warning! W138: No newline at end of file
-x86.h(4): Warning! W138: No newline at end of file
diff --git a/src/bootloader/stage2/stdio.h b/src/bootloader/stage2/stdio.h
index f25dc1c..0735127 100644
--- a/src/bootloader/stage2/stdio.h
+++ b/src/bootloader/stage2/stdio.h
@@ -1,4 +1,5 @@
#pragma once
void putc(char c);
-void puts(const char *str);
\ No newline at end of file
+void puts(const char* str);
+void _cdecl printf(const char *fmt, ...);
\ No newline at end of file