Merge pull request #3 from VinceAle7082/Coding
Coding is now the "main branch"
This commit is contained in:
commit
60850153ab
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
build/
|
||||
.mailmap
|
||||
.vscode
|
@ -1,3 +1,6 @@
|
||||
<h2>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!</h2>
|
||||
<hr>
|
||||
|
||||
Hey all, Vincenzo Aleskey Brocato (VinceAle7082) here! <br>
|
||||
This is a little project where I try to make an OS just for fun <br>
|
||||
<br>
|
||||
|
@ -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 (;;);
|
||||
|
@ -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
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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
|
@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
void putc(char c);
|
||||
void puts(const char *str);
|
||||
void puts(const char* str);
|
||||
void _cdecl printf(const char *fmt, ...);
|
Loading…
x
Reference in New Issue
Block a user