-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5eda9b8
commit 72719c0
Showing
11 changed files
with
167 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#pragma once | ||
|
||
#include <stddef.h> | ||
|
||
enum __file { | ||
__FILE_LCD, | ||
__FILE_KEYBOARD, | ||
__FILE_UART | ||
}; | ||
|
||
size_t __io_write(enum __file file, const char* buffer, size_t size); | ||
size_t __io_read(enum __file file, char* buffer, size_t size); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#pragma once | ||
|
||
#include <stddef.h> | ||
#include "common/io.h" | ||
|
||
struct kfile { | ||
size_t (*write)(struct kfile* file, const char* buffer, size_t size); | ||
size_t (*read)(struct kfile* file, char* buffer, size_t size); | ||
}; | ||
|
||
size_t kfile_write(enum __file id, const char* buffer, size_t size); | ||
size_t kfile_read(enum __file id, char* buffer, size_t size); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,49 @@ | ||
#pragma once | ||
|
||
#include "common/io.h" | ||
#include "common/syscalls.h" | ||
|
||
#define EOF (-1) | ||
|
||
int putchar(int ch); | ||
int puts(const char* str); | ||
typedef struct FILE FILE; | ||
|
||
#define stdin ((FILE*)__FILE_KEYBOARD) | ||
#define stdout ((FILE*)__FILE_LCD) | ||
#define stderr ((FILE*)__FILE_LCD) | ||
|
||
static inline int fputs(const char* str, FILE* restrict stream) { | ||
size_t len = 0; | ||
while (str[len] != '\0') len++; | ||
|
||
size_t chars = __file_write((enum __file)stream, str, len); | ||
if (chars != len) { | ||
// TODO: set ferror | ||
return EOF; | ||
} | ||
|
||
return chars; | ||
} | ||
|
||
static inline int fputc(int ch, FILE* stream) { | ||
char c = ch; | ||
size_t res = __file_write((enum __file)stream, &c, 1); | ||
if (res != 1) | ||
return EOF; | ||
|
||
return ch; | ||
} | ||
|
||
#define putc(ch, stream) fputc(ch, stream) | ||
|
||
static inline int puts(const char* str) { | ||
int res = fputs(str, stdout); | ||
if (res == EOF) | ||
return EOF; | ||
|
||
if (fputc('\n', stdout) == EOF) | ||
return EOF; | ||
|
||
return res + 1; | ||
} | ||
|
||
static inline int putchar(int ch) { return fputc(ch, stdout); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include "kernel/io.h" | ||
|
||
extern struct kfile klcd; | ||
|
||
struct kfile* files[] = { | ||
[__FILE_LCD] = &klcd | ||
}; | ||
|
||
size_t kfile_write(enum __file id, const char* buffer, size_t size) { | ||
struct kfile* file = files[id]; | ||
return file->write(file, buffer, size); | ||
} | ||
|
||
size_t kfile_read(enum __file id, char* buffer, size_t size) { | ||
struct kfile* file = files[id]; | ||
return file->read(file, buffer, size); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include "kernel/io.h" | ||
#include "devices/lcd.h" | ||
|
||
struct klcd { | ||
char buffer[16][2]; | ||
int cursor_y, cursor_x; | ||
}; | ||
|
||
size_t klcd_write(struct kfile* file, const char* buffer, size_t size) { | ||
struct klcd* lcd = (struct klcd*)file; | ||
|
||
for (size_t i = 0; i < size; i++) { | ||
char ch = buffer[i]; | ||
|
||
// TODO: Fix this | ||
switch (ch) { | ||
case '\n': | ||
lcd_move_cursor(1, 0); | ||
break; | ||
case '\r': | ||
lcd_move_cursor(0, 0); | ||
break; | ||
default: | ||
lcd_write_ch(ch); | ||
break; | ||
} | ||
} | ||
|
||
return size; | ||
} | ||
|
||
struct kfile klcd = { | ||
.write = klcd_write, | ||
.read = NULL | ||
}; |
This file was deleted.
Oops, something went wrong.