aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/boucane.cc8
-rw-r--r--src/drivers/framebuffer.cc8
-rw-r--r--src/libs/math.cc12
-rw-r--r--src/libs/math.hpp10
-rw-r--r--src/libs/stdio.cc6
-rw-r--r--src/libs/stdio.hpp2
-rw-r--r--src/libs/string.cc36
-rw-r--r--src/libs/string.hpp9
8 files changed, 56 insertions, 35 deletions
diff --git a/src/boucane.cc b/src/boucane.cc
index 74dad9d..94f266f 100644
--- a/src/boucane.cc
+++ b/src/boucane.cc
@@ -1,11 +1,19 @@
#include "boucane.hpp"
+#include "libs/string.hpp"
extern "C" void boucane(){
clear();
char a[]="Loic Guegan";
printk("Booting Boucane v%d.%d.%d",VERSION_MAJOR,VERSION_MINOR, VERSION_PATH);
+ char b[10];
+ substr(8, 9, a, b);
+ print("\n");
+ printk(b);
+ int gg=0;
+ gg+=((1>2) ? 1 : 0)+9;
+ printi(gg);
while(1);
} \ No newline at end of file
diff --git a/src/drivers/framebuffer.cc b/src/drivers/framebuffer.cc
index b945e77..2fbe153 100644
--- a/src/drivers/framebuffer.cc
+++ b/src/drivers/framebuffer.cc
@@ -40,19 +40,19 @@ void putchar(char c){
}
void clear(){
- for(char i=0;i<MAX_LINE;i++){
+ for(u8 i=0;i<MAX_LINE;i++){
scrollup();
}
}
void scrollup(){
// Move VS.line up
- for(char i=1;i<=MAX_LINE;i++){
- for(char j=0;j<=MAX_COL;j++)
+ for(u8 i=1;i<=MAX_LINE;i++){
+ for(u8 j=0;j<=MAX_COL;j++)
VS.mem[j*2+MAX_COL*(i-1)*2]=VS.mem[j*2+MAX_COL*i*2];
}
// Clear last VS.line
- for(char i=0;i<=MAX_COL;i++){
+ for(u8 i=0;i<=MAX_COL;i++){
VS.mem[i*2+MAX_COL*(MAX_LINE-1)*2]='\0';
}
}
diff --git a/src/libs/math.cc b/src/libs/math.cc
index 63487b2..27f009a 100644
--- a/src/libs/math.cc
+++ b/src/libs/math.cc
@@ -1,31 +1,31 @@
#include "math.hpp"
-int pow(int x, int n) {
+u32 pow(u32 x, u32 n) {
if (n < 0)
return -1;
else if (n == 0)
return 1;
else if (n == 1)
return x;
- int ret = x;
- for (int i = 0; i < (n - 1); i++)
+ u32 ret = x;
+ for (u32 i = 0; i < (n - 1); i++)
ret *= x;
return ret;
}
-int max(int x, int y) {
+u32 max(u32 x, u32 y) {
if (x > y)
return x;
return y;
}
-int min(int x, int y) {
+u32 min(u32 x, u32 y) {
if (x < y)
return x;
return y;
}
-int abs(int x) {
+u32 abs(u32 x) {
if (x < 0)
return -x;
return x;
diff --git a/src/libs/math.hpp b/src/libs/math.hpp
index 1eaac1c..c5b7c46 100644
--- a/src/libs/math.hpp
+++ b/src/libs/math.hpp
@@ -1,6 +1,8 @@
#pragma once
-int pow(int x, int n);
-int max(int x, int y);
-int min(int x, int y);
-int abs(int x);
+#include "core/types.hpp"
+
+u32 pow(u32 x, u32 n);
+u32 max(u32 x, u32 y);
+u32 min(u32 x, u32 y);
+u32 abs(u32 x);
diff --git a/src/libs/stdio.cc b/src/libs/stdio.cc
index 4a20c05..e73e4af 100644
--- a/src/libs/stdio.cc
+++ b/src/libs/stdio.cc
@@ -109,12 +109,12 @@ void printh(int h) {
itoh(h, str);
print(str);
}
-void printh(int h, int size) {
+void printh(int h, u32 size) {
char str[17];
char str2[17];
itoh(h, str);
- int a = 0;
- for (int i = min(max(16 - size, 0), 15); i < 16; i++) {
+ u32 a = 0;
+ for (u32 i = min(max(16 - size, 0), 15); i < 16; i++) {
str2[a] = str[i];
a++;
}
diff --git a/src/libs/stdio.hpp b/src/libs/stdio.hpp
index f48ae81..fd266a5 100644
--- a/src/libs/stdio.hpp
+++ b/src/libs/stdio.hpp
@@ -33,4 +33,4 @@ void printh(int h);
/**
* Print an integer as hex using itoh() truncated to size
*/
-void printh(int h, int size);
+void printh(int h, u32 size);
diff --git a/src/libs/string.cc b/src/libs/string.cc
index f8ae3ca..73c3318 100644
--- a/src/libs/string.cc
+++ b/src/libs/string.cc
@@ -1,16 +1,16 @@
#include "string.hpp"
#include "math.hpp"
-void memcpy(void* src, void* dst, int size){
- char *c_src=(char*)src;
- char *c_dst=(char*)dst;
- for(int i=0;i<size;i++)
- *c_dst=*c_src;
+void memcpy(void* src, void* dst, u32 size){
+ u8 *c_src=(u8*)src;
+ u8 *c_dst=(u8*)dst;
+ for(u32 i=0;i<size;i++)
+ *(c_dst+i)=*(c_src+i);
}
void itoa(u64 i, char *a){
// Check if lower than 0
- char neg=0;
+ u8 neg=0;
if(i<0){
neg=1;
i=-i;
@@ -18,17 +18,17 @@ void itoa(u64 i, char *a){
}
// Count number of digits
- int len=1;
+ u32 len=1;
while(i/pow(10,len)>=1)
{
len++;
}
// Build string
- int max_pow=len-1;
- for(int j=0;j<=max_pow;j++){
- int cur_pow=pow(10,max_pow-j);
- char digit=i/cur_pow;
+ u32 max_pow=len-1;
+ for(u32 j=0;j<=max_pow;j++){
+ u32 cur_pow=pow(10,max_pow-j);
+ u8 digit=i/cur_pow;
a[j+neg]='0'+digit;
i=i-digit*cur_pow; // Remove first digits (most significant)
}
@@ -45,7 +45,7 @@ void itoh(u64 i, char *a){
u32 i_a=i&0xFFFFFFFF;
u32 i_b=i>>32;
- for(char j=0;j<8;j++){
+ for(u8 j=0;j<8;j++){
u64 t=(j*4);
u64 mask=0xF;
mask=mask << t;
@@ -53,7 +53,7 @@ void itoh(u64 i, char *a){
a[15-j]=hex[index];
}
- for(char j=0;j<8;j++){
+ for(u8 j=0;j<8;j++){
u64 t=(j*4);
u64 mask=0xF;
mask=mask << t;
@@ -63,9 +63,15 @@ void itoh(u64 i, char *a){
a[16]='\0';
}
-int strlen(char *s){
- int i=0;
+u32 strlen(char *s){
+ u32 i=0;
while(s[i]!='\0')
i++;
return i;
+}
+
+void substr(u32 s, u32 e, char *src, char *dst){
+ u32 size=abs(e-s)+1;
+ memcpy(src+s, dst, size);
+ dst[size]='\0';
} \ No newline at end of file
diff --git a/src/libs/string.hpp b/src/libs/string.hpp
index 305b9a8..a7dce0a 100644
--- a/src/libs/string.hpp
+++ b/src/libs/string.hpp
@@ -5,7 +5,7 @@
/**
* Copy data byte per byte from src to dst
*/
-void memcpy(void *src, void *dst, int size);
+void memcpy(void *src, void *dst, u32 size);
/**
* Convert int to char array
@@ -20,4 +20,9 @@ void itoh(u64 i, char *a);
/**
* Length of a char*
*/
-int strlen(char *s);
+u32 strlen(char *s);
+
+/**
+ * Substr
+ */
+void substr(u32 s, u32 e, char *src, char *dst);