Merge pull request #29 from E-Almqvist/dev

String Library & Memory
pull/34/head
Elias Almqvist 3 years ago committed by GitHub
commit cd57cc46c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      Makefile
  2. 9
      TODO.md
  3. 2
      drivers/vga.c
  4. 13
      kernel/kernel.c
  5. 1
      kernel/memory.c
  6. 2
      kernel/memory.h
  7. 28
      lib/str.c
  8. 2
      lib/str.h
  9. 15
      lib/strf.c
  10. 1
      lib/strf.h

@ -1,5 +1,5 @@
C_SOURCES = $(wildcard kernel/*.c drivers/*.c) C_SOURCES = $(wildcard kernel/*.c drivers/*.c lib/*.c)
HEADERS = $(wildcard kernel/*.h drivers/*.h) HEADERS = $(wildcard kernel/*.h drivers/*.h lib/*.h)
OBJ = $(C_SOURCES:.c=.o) OBJ = $(C_SOURCES:.c=.o)
all: os-image all: os-image

@ -1,6 +1,11 @@
# TO DO # TO DO
- Refactor the VGA driver - Malloc
- Finish the book! - String Library
- Concat
- Format
- Scrolling
- Multiboot support (for grub etc) - Multiboot support (for grub etc)
- Rendering (VGA) - Rendering (VGA)
- User input (Keyboard) - User input (Keyboard)

@ -50,7 +50,7 @@ void set_cursor_pos(unsigned int col, unsigned int row) {
void clear_screen() { void clear_screen() {
for( int c = 0; c < MAX_COLS; c++ ) for( int c = 0; c < MAX_COLS; c++ )
for( int r = 0; r < MAX_ROWS; r++ ) for( int r = 0; r < MAX_ROWS; r++ )
writechar(0x20, c, r, 0xf0); writechar(0x20, c, r, 0x0f);
} }
/* /*

@ -1,15 +1,18 @@
#include "../drivers/vga.h" #include "../drivers/vga.h"
#include "../lib/str.h"
#include "../lib/strf.h"
void main() { void main() {
vga_init(); // Initialize the screen first vga_init(); // Initialize the screen first
// i.e. clear the screen et cetera. // i.e. clear the screen et cetera.
set_cursor_pos(28, 2); set_cursor_pos(28, 2);
print("eOS Version 0.1 2021", 0xf0); print("eOS Version 0.1 2021", 0x0f);
/*
char* strbuf = "Hello";
char* str2 = "World!";
strbuf = strcat(strbuf, str2);
set_cursor_pos(0, 0); set_cursor_pos(0, 0);
for( int i = 0; i < 255; i++ ) println(strbuf, 0x0f);
println("X", i);
*/
} }

@ -0,0 +1 @@
#include "memory.h"

@ -0,0 +1,2 @@
char* malloc(unsigned int size);
void mfree(char* p);

@ -0,0 +1,28 @@
#include "str.h"
unsigned int strlen(char* str) {
unsigned int len = 0;
for( char* c = str; *c != '\0'; c++ ) // search for end-of-string
len++;
return len;
}
char* strcat(char* buf, char* str) {
unsigned int bufferlen = strlen(buf);
// remove the 0x0 char from the buffer
*(buf + bufferlen) = 0x3f; // replace end-of-string
// with a placeholder
// concat the str to buf
int cc = 0;
for( char* c = str; *c != '\0'; c++ ) {
*(buf + bufferlen + cc) = *c;
cc++;
}
*(buf + bufferlen + cc) = '\0'; // add end-of-string
return buf;
}

@ -0,0 +1,2 @@
unsigned int strlen(char* str);
char* strcat(char* buf, char* str);

@ -0,0 +1,15 @@
#include "strf.h"
#define int_offset 48
// 0:48 - 9:57
char* int_to_str(int i, char* strbuf) {
if( i == 0 ) {
return (char*)(int_offset);
} else {
char cbuf;
cbuf = (char)((i % 10) + int_offset);
return int_to_str(i / 10, strbuf + cbuf);
}
}

@ -0,0 +1 @@
char* int_to_str(int i, char* strbuf);
Loading…
Cancel
Save