diff options
author | Benji Dial <benji6283@gmail.com> | 2021-02-17 16:35:02 -0500 |
---|---|---|
committer | Benji Dial <benji6283@gmail.com> | 2021-02-17 16:35:02 -0500 |
commit | 3a3602861226e995d95a8898668cd559c3ca1cf6 (patch) | |
tree | 0d5bc0494297a12e9ccb76b31cb365c843216735 /src | |
parent | 49d76d30a55707e2bf95fd9ba03296489fac8d1d (diff) | |
download | portland-os-3a3602861226e995d95a8898668cd559c3ca1cf6.tar.gz |
quick bitmap font format, borrowing new default font from X
Diffstat (limited to 'src')
-rw-r--r-- | src/kernel/idt.c | 3 | ||||
-rw-r--r-- | src/user/libfont/bdf.c | 15 | ||||
-rw-r--r-- | src/user/libfont/bdf.h | 5 | ||||
-rw-r--r-- | src/user/libfont/fonts.c | 21 | ||||
-rw-r--r-- | src/user/libfont/pbf.c | 43 | ||||
-rw-r--r-- | src/user/libfont/pbf.h | 11 | ||||
-rw-r--r-- | src/user/popups/info.c | 2 | ||||
-rw-r--r-- | src/user/terminal/main.c | 2 |
8 files changed, 75 insertions, 27 deletions
diff --git a/src/kernel/idt.c b/src/kernel/idt.c index 99284ac..c79ae7b 100644 --- a/src/kernel/idt.c +++ b/src/kernel/idt.c @@ -256,9 +256,10 @@ void exception_halt(uint32_t eax, uint32_t ebx, uint32_t ecx, __builtin_unreachable(); } +#define MAX_STACK_EXPAND_PAGES 256 //returns true if stack was expanded bool pf_check_stack(uint32_t cr2) { - if (cr2 >= active_task->stack_bottom - 0x1000) { + if (cr2 >= active_task->stack_bottom - 0x1000 * MAX_STACK_EXPAND_PAGES) { switch_to_kernel_cr3(); pd_user_allocate(active_task->page_directory, active_task->stack_bottom -= 4096, 1, true); switch_to_task_cr3(); diff --git a/src/user/libfont/bdf.c b/src/user/libfont/bdf.c index 2c19a15..de5489d 100644 --- a/src/user/libfont/bdf.c +++ b/src/user/libfont/bdf.c @@ -17,16 +17,10 @@ static inline uint8_t hex_to_n(char ch) { } //very minimal implementation -bool try_load_bdf(const char *path, struct font_info *into) { - struct file *f = open_file(path); - if (!f) - PANIC("Can't open font file sent by get_font."); - +bool try_load_bdf(struct file *f, struct font_info *into) { read_line_from_file(f, line_buf, LINE_BUF_SIZE - 1); - if (!strequ(line_buf, "STARTFONT 2.1")) { - close_file(f); + if (!strequ(line_buf, "STARTFONT 2.1")) return false; - } for (uint16_t i = 0; i < 256; ++i) into->bitmaps[i] = 0; @@ -71,9 +65,6 @@ bool try_load_bdf(const char *path, struct font_info *into) { } } - close_file(f); - f = 0; - if ((into->char_height == -1) || (into->char_width == -1) || (into->space_height == -1) || @@ -90,8 +81,6 @@ bool try_load_bdf(const char *path, struct font_info *into) { return true; bad_format: - if (f) - close_file(f); for (uint16_t i = 0; i < 256; ++i) if (into->bitmaps[i]) free_block(into->bitmaps[i]); diff --git a/src/user/libfont/bdf.h b/src/user/libfont/bdf.h index 4ed4189..cbf3772 100644 --- a/src/user/libfont/bdf.h +++ b/src/user/libfont/bdf.h @@ -1,8 +1,11 @@ #ifndef LIBFONT_BDF_H #define LIBFONT_BDF_H +#include <libfont/fonts.h> +#include <knob/file.h> + #include <stdbool.h> -bool try_load_bdf(const char *path, struct font_info *into); +bool try_load_bdf(struct file *f, struct font_info *into); #endif
\ No newline at end of file diff --git a/src/user/libfont/fonts.c b/src/user/libfont/fonts.c index 1692992..c085604 100644 --- a/src/user/libfont/fonts.c +++ b/src/user/libfont/fonts.c @@ -6,14 +6,18 @@ #include "filist.h" #include "bdf.h" +#include "pbf.h" #define FONT_PATH "fonts/" #define FONT_PATH_L 6 struct font_loader_t { const char *ext; - bool (*func)(const char *, struct font_info *); + bool (*func)(struct file *f, struct font_info *); } font_loaders[] = { + { .ext = ".pbf", + .func = try_load_pbf + }, { .ext = ".bdf", .func = try_load_bdf }, @@ -36,20 +40,17 @@ struct font_info *get_font(const char *name) { blockcpy(buf + FONT_PATH_L, name, name_len); strcpy(buf + FONT_PATH_L + name_len, i->ext); struct file *f = open_file(buf); - if (!f) { - free_block(buf); + free_block(buf); + if (!f) continue; - } - syslogf("[libfont] Loading %s%s...", name, i->ext); - if (i->func(buf, font)) { + //syslogf("[libfont] Loading %s%s...", name, i->ext); + if (i->func(f, font)) { close_file(f); - free_block(buf); - syslogf("[libfont] Loaded %s%s.", name, i->ext); + //syslogf("[libfont] Loaded %s%s.", name, i->ext); return font; } close_file(f); - free_block(buf); - syslogf("[libfont] Failed to load %s%s.", name, i->ext); + //syslogf("[libfont] Failed to load %s%s.", name, i->ext); } del_last(); return 0; diff --git a/src/user/libfont/pbf.c b/src/user/libfont/pbf.c new file mode 100644 index 0000000..34d5be5 --- /dev/null +++ b/src/user/libfont/pbf.c @@ -0,0 +1,43 @@ +#include <libfont/fonts.h> + +#include <knob/panic.h> +#include <knob/file.h> +#include <knob/heap.h> + +#include <stdbool.h> + +bool try_load_pbf(struct file *f, struct font_info *into) { + uint8_t head[4]; + if (read_from_file(f, 4, head) != 4) + return false; + + into->space_width = head[0] + head[2]; + into->space_height = head[1] + head[3]; + into->char_width = head[0]; + into->char_height = head[1]; + + const uint16_t bm_size = head[0] * head[1]; + const uint16_t bm_bytes = (bm_size - 1) / 8 + 1; + + uint32_t bm_offsets[256]; + if (read_from_file(f, 4 * 256, bm_offsets) != 4 * 256) + return false; + + uint8_t bm_buf[256 * 256 / 8]; + + for (uint16_t i = 0; i < 256; ++i) + if (bm_offsets[i] == 0xffffffff) + into->bitmaps[i] = 0; + else { + bool *bp = get_block(bm_size); + if (!bp) + PANIC("couldn't allocate memory in pbf loader (todo: fail gracefully)"); + seek_file_to(f, 4 + 4 * 256 + bm_offsets[i]); + read_from_file(f, bm_bytes, bm_buf); + for (uint16_t j = 0; j < bm_size; ++j) + bp[j] = (bm_buf[j / 8] >> (j % 8)) & 1; + into->bitmaps[i] = bp; + } + + return true; +}
\ No newline at end of file diff --git a/src/user/libfont/pbf.h b/src/user/libfont/pbf.h new file mode 100644 index 0000000..bcf5d18 --- /dev/null +++ b/src/user/libfont/pbf.h @@ -0,0 +1,11 @@ +#ifndef LIBFONT_PBF_H +#define LIBFONT_PBF_H + +#include <libfont/fonts.h> +#include <knob/file.h> + +#include <stdbool.h> + +bool try_load_pbf(struct file *f, struct font_info *into); + +#endif
\ No newline at end of file diff --git a/src/user/popups/info.c b/src/user/popups/info.c index 5b3f6ae..667d440 100644 --- a/src/user/popups/info.c +++ b/src/user/popups/info.c @@ -9,7 +9,7 @@ #include <stdarg.h> #define PADDING 6 -#define FONT "berry" +#define FONT "fixed-10" static const struct font_info *info_font = 0; diff --git a/src/user/terminal/main.c b/src/user/terminal/main.c index 15ca6a1..08c17e1 100644 --- a/src/user/terminal/main.c +++ b/src/user/terminal/main.c @@ -10,7 +10,7 @@ #include <pland/syscall.h> #include <pland/pcrt.h> -#define FONT_HARDCODE "berry" +#define FONT_HARDCODE "fixed-10" _window_handle_t window; uint8_t *pixbuf; |