diff options
author | Benji Dial <benji6283@gmail.com> | 2021-01-24 12:00:11 -0500 |
---|---|---|
committer | Benji Dial <benji6283@gmail.com> | 2021-01-24 12:00:11 -0500 |
commit | bce944d1498eaa3b6940ee234c863b3548a66b37 (patch) | |
tree | ea40c087ab4f0f236aee8d158cf68550f5209f72 /src/user/include | |
parent | ca731aa747214919df7b3dfe3478dbe787ce5b68 (diff) | |
download | portland-os-bce944d1498eaa3b6940ee234c863b3548a66b37.tar.gz |
graphics!
Diffstat (limited to 'src/user/include')
-rw-r--r-- | src/user/include/knob/block.h | 5 | ||||
-rw-r--r-- | src/user/include/knob/env.h | 9 | ||||
-rw-r--r-- | src/user/include/knob/format.h | 27 | ||||
-rw-r--r-- | src/user/include/knob/ipc.h | 16 | ||||
-rw-r--r-- | src/user/include/knob/key.h | 8 | ||||
-rw-r--r-- | src/user/include/knob/panic.h | 9 | ||||
-rw-r--r-- | src/user/include/knob/task.h | 7 | ||||
-rw-r--r-- | src/user/include/knob/user.h | 22 | ||||
-rw-r--r-- | src/user/include/libfont/fonts.h | 21 | ||||
-rw-r--r-- | src/user/include/pland/pcrt.h | 7 | ||||
-rw-r--r-- | src/user/include/pland/syscall.h | 206 | ||||
-rw-r--r-- | src/user/include/popups/info.h | 14 | ||||
-rw-r--r-- | src/user/include/popups/popup.h | 23 | ||||
-rw-r--r-- | src/user/include/terminal/readline.h | 10 | ||||
-rw-r--r-- | src/user/include/terminal/terminal.h | 57 |
15 files changed, 267 insertions, 174 deletions
diff --git a/src/user/include/knob/block.h b/src/user/include/knob/block.h index 56d3740..f77709d 100644 --- a/src/user/include/knob/block.h +++ b/src/user/include/knob/block.h @@ -13,4 +13,9 @@ uint32_t strcpy(char *to, const char *from); //allocates new memory char *strdup(const char *from); +//without null-terminator +uint32_t strlen(const char *str) __attribute__ ((pure)); + +bool strequ(const char *a, const char *b) __attribute__ ((pure)); + #endif
\ No newline at end of file diff --git a/src/user/include/knob/env.h b/src/user/include/knob/env.h deleted file mode 100644 index 6d750ae..0000000 --- a/src/user/include/knob/env.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef KNOB_ENV_H -#define KNOB_ENV_H - -#include <stdint.h> - -//not implemented yet -extern uint32_t current_drive; - -#endif
\ No newline at end of file diff --git a/src/user/include/knob/format.h b/src/user/include/knob/format.h index d55036c..fed31c7 100644 --- a/src/user/include/knob/format.h +++ b/src/user/include/knob/format.h @@ -1,12 +1,29 @@ #ifndef KNOB_FORMAT_H #define KNOB_FORMAT_H -#include <stdbool.h> +#include <knob/heap.h> + #include <stdint.h> +#include <stdarg.h> + +//allocates new memory +char *format_v(const char *fmt, va_list args); + +//allocates new memory +char *format(const char *fmt, ...); + +void syslogf_v(const char *fmt, va_list args); + +void syslogf(const char *fmt, ...); + +//reads a unsigned decimal terminated by either null or whitespace +//returns length of string plus length of whitespace +//returns 0 on failure +uint32_t try_swtou(const char *from, uint32_t *i_out); -bool try_sntoi(const char *s, uint32_t n, uint32_t *out); -void itosz(uint32_t i, char *out) __attribute__ ((access (write_only, 2))); -void itosz_h8(uint8_t i, char *out) __attribute__ ((access (write_only, 2))); -void itosz_h32(uint32_t i, char *out) __attribute__ ((access (write_only, 2))); +//reads a hexadecimal terminated by either null or whitespace +//returns length of string plus length of whitespace +//returns 0 on failure +uint32_t try_swtoh(const char *from, uint32_t *i_out); #endif
\ No newline at end of file diff --git a/src/user/include/knob/ipc.h b/src/user/include/knob/ipc.h new file mode 100644 index 0000000..3eab562 --- /dev/null +++ b/src/user/include/knob/ipc.h @@ -0,0 +1,16 @@ +#ifndef KNOB_IPC_H +#define KNOB_IPC_H + +#include <pland/syscall.h> + +//blocking, returns early if other process is dead. +//return value is number of bytes written. +uint32_t try_send_ipc(_task_handle_t to, void *buffer, uint32_t size); + +//blocking, returns early if other process is dead. +//return value is number of bytes read. +uint32_t try_read_ipc(_task_handle_t from, void *buffer, uint32_t size); + +void flush_ipc(_task_handle_t from); + +#endif
\ No newline at end of file diff --git a/src/user/include/knob/key.h b/src/user/include/knob/key.h new file mode 100644 index 0000000..90509fc --- /dev/null +++ b/src/user/include/knob/key.h @@ -0,0 +1,8 @@ +#ifndef KNOB_KEY_H +#define KNOB_KEY_H + +#include <keypack.h> + +char key_to_char(struct key_packet kp) __attribute__ ((pure)); + +#endif
\ No newline at end of file diff --git a/src/user/include/knob/panic.h b/src/user/include/knob/panic.h new file mode 100644 index 0000000..1dd33a0 --- /dev/null +++ b/src/user/include/knob/panic.h @@ -0,0 +1,9 @@ +#ifndef KNOB_PANIC_H +#define KNOB_PANIC_H + +#include <stdint.h> + +#define PANIC(msg) panic(__FILE__, __LINE__, msg) +void panic(const char *filename, uint32_t line, const char *message) __attribute__ ((noreturn)); + +#endif
\ No newline at end of file diff --git a/src/user/include/knob/task.h b/src/user/include/knob/task.h index 6539a00..cd51c37 100644 --- a/src/user/include/knob/task.h +++ b/src/user/include/knob/task.h @@ -1,11 +1,12 @@ #ifndef KNOB_TASK_H #define KNOB_TASK_H +#include <pland/syscall.h> + #include <stdint.h> #include <stdbool.h> -uint32_t run_command(const char *path); -bool try_run_command_blocking(const char *path); -void yield_task(); +uint32_t run_command(const char *path, _task_handle_t stdio_task); +bool try_run_command_blocking(const char *path, _task_handle_t stdio_task); #endif
\ No newline at end of file diff --git a/src/user/include/knob/user.h b/src/user/include/knob/user.h deleted file mode 100644 index fb11c9b..0000000 --- a/src/user/include/knob/user.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef KNOB_USER_H -#define KNOB_USER_H - -#include <stdint.h> -#include <pland/syscall.h> - -struct history; - -char key_to_char(_key_code_t key) __attribute__ ((const)); - -void tell_user_sz(const char *sz); - -//return value and max_length don't include null terminator -//returns the real length of the string -uint32_t ask_user_line_sz(char *sz, uint32_t max_length); - -struct history *new_history(uint32_t max_entries); -void del_history(struct history *hs); - -uint32_t ask_user_line_sz_with_history(char *sz, uint32_t max_length, struct history *hs); - -#endif
\ No newline at end of file diff --git a/src/user/include/libfont/fonts.h b/src/user/include/libfont/fonts.h new file mode 100644 index 0000000..b66659f --- /dev/null +++ b/src/user/include/libfont/fonts.h @@ -0,0 +1,21 @@ +#ifndef LIBFONT_FONTS_H +#define LIBFONT_FONTS_H + +#include <stdbool.h> +#include <stdint.h> + +struct font_info { + uint32_t space_width; + uint32_t space_height; + uint32_t char_width; + uint32_t char_height; + bool *bitmaps[256];//left to right then top to bottom + //null pointer for unsupported character + //unsupported characters drawn as bitmaps[0] +}; + +struct font_info *get_font(const char *name); + +void put_char(const struct font_info *font, char ch, uint8_t *pb_ptr, uint32_t pb_pitch, uint8_t bg, uint8_t fg); + +#endif
\ No newline at end of file diff --git a/src/user/include/pland/pcrt.h b/src/user/include/pland/pcrt.h index 07ad453..42158cd 100644 --- a/src/user/include/pland/pcrt.h +++ b/src/user/include/pland/pcrt.h @@ -1,6 +1,8 @@ #ifndef PLAND_PCRT_H #define PLAND_PCRT_H +#include <pland/syscall.h> + #define BEFORE_MAIN(f) \ __attribute__ ((section (".__pcrt_before_main"))) \ __attribute__ ((unused)) \ @@ -13,4 +15,7 @@ void __pcrt_quit() __attribute__ ((noreturn)); -#endif
\ No newline at end of file +extern _task_handle_t calling_task; +extern _task_handle_t stdio_task; + +#endif diff --git a/src/user/include/pland/syscall.h b/src/user/include/pland/syscall.h index ead5fea..6d327d5 100644 --- a/src/user/include/pland/syscall.h +++ b/src/user/include/pland/syscall.h @@ -4,119 +4,12 @@ #include <stdint.h> #include <stdbool.h> +#include <winact.h> + typedef uint32_t _file_handle_t; typedef uint32_t _task_handle_t; typedef uint32_t _drive_number_t; -typedef uint32_t _process_handle_t; - -typedef enum { - _KEY_LSHIFT = 0x00000100, - _KEY_RSHIFT = 0x00000200, - _KEY_CAPS = 0x00000400, - _KEY_INSERT = 0x00000800, - _KEY_NUM = 0x00001000, - _KEY_SCROLL = 0x00002000, - _KEY_LALT = 0x00004000, - _KEY_RALT = 0x00008000, - _KEY_LCTRL = 0x00010000, - _KEY_RCTRL = 0x00020000, - _KEY_LMETA = 0x00040000, - _KEY_RMETA = 0x00080000, - - _KEY_SHIFT = 0x00000300, - _KEY_SCAPS = 0x00000700, - _KEY_ALT = 0x0000c000, - _KEY_CTRL = 0x00030000, - _KEY_META = 0x000c0000, - - _KEY_BEGIN_CAPS = 0x80, - _KEY_BEGIN_INSERT, - _KEY_BEGIN_NUM, - _KEY_BEGIN_SCROLL, - _KEY_BEGIN_LSHIFT, - _KEY_BEGIN_RSHIFT, - _KEY_BEGIN_LALT, - _KEY_BEGIN_RALT, - _KEY_BEGIN_LCTRL, - _KEY_BEGIN_RCTRL, - _KEY_BEGIN_LMETA, - _KEY_BEGIN_RMETA, - /* 0x8c - 0x97 reserved */ - /* 0x98 - 0x9f unassigned */ - _KEY_F1 = 0xa0, - _KEY_F2, - _KEY_F3, - _KEY_F4, - _KEY_F5, - _KEY_F6, - _KEY_F7, - _KEY_F8, - _KEY_F9, - _KEY_F10, - _KEY_F11, - _KEY_F12, - /* 0xac - 0xaf unassigned */ - _KEY_NUM0 = 0xb0, - _KEY_NUM1, - _KEY_NUM2, - _KEY_NUM3, - _KEY_NUM4, - _KEY_NUM5, - _KEY_NUM6, - _KEY_NUM7, - _KEY_NUM8, - _KEY_NUM9, - _KEY_NTIMES, - _KEY_NPLUS, - _KEY_NENTER, - _KEY_NMINUS, - _KEY_NDOT, - _KEY_NSLASH, - /* 0xc0 unassigned */ - _KEY_DELETE = 0xc1, - _KEY_HOME, - _KEY_END, - _KEY_PUP, - _KEY_PDOWN, - _KEY_UP, - _KEY_DOWN, - _KEY_LEFT, - _KEY_RIGHT, - _KEY_ESC, - _KEY_MENU, - _KEY_PAUSE, - _KEY_PRSCR, - /* 0xce - 0xef unassigned */ -} _key_code_t; - -typedef enum { - _COLOR_FG_BLACK = 0x00, - _COLOR_FG_BLUE = 0x01, - _COLOR_FG_GREEN = 0x02, - _COLOR_FG_CYAN = 0x03, - _COLOR_FG_RED = 0x04, - _COLOR_FG_MAGENTA = 0x05, - _COLOR_FG_BROWN = 0x06, - _COLOR_FG_LGRAY = 0x07, - - _COLOR_FG_DGRAY = 0x08, - _COLOR_FG_LBLUE = 0x09, - _COLOR_FG_LGREEN = 0x0a, - _COLOR_FG_LCYAN = 0x0b, - _COLOR_FG_LRED = 0x0c, - _COLOR_FG_PINK = 0x0d, - _COLOR_FG_YELLOW = 0x0e, - _COLOR_FG_WHITE = 0x0f, - - _COLOR_BG_BLACK = 0x00, - _COLOR_BG_BLUE = 0x10, - _COLOR_BG_GREEN = 0x20, - _COLOR_BG_CYAN = 0x30, - _COLOR_BG_RED = 0x40, - _COLOR_BG_MAGENTA = 0x50, - _COLOR_BG_BROWN = 0x60, - _COLOR_BG_LGRAY = 0x70 -} _vga_color_t; +typedef void *_window_handle_t; typedef struct __attribute__ ((packed)) { char name[100]; @@ -131,17 +24,26 @@ enum _scn { _SCN_FILE_READ, _SCN_FILE_SIZE, _SCN_START_TASK, - _SCN_LOG_STRING, - _SCN_GET_KEY, + _SCN_IPC_SEND, + _SCN_IPC_READ, _SCN_ALLOCATE_RAM, _SCN_MEMORY_INFO, _SCN_WAIT_FOR_TASK, _SCN_ENUMERATE_DIR, - _SCN_PRINT_AT, + _SCN_SYSTEM_LOG, _SCN_COUNT_OF_DIR, - _SCN_CLEAR_SCREEN, - _SCN_SET_COLOR, - _SCN_SWAP_COLOR + _SCN_NEW_WINDOW, + _SCN_DELETE_WINDOW, + _SCN_RESIZE_WINDOW, + _SCN_REASSIGN_PIXBUF, + _SCN_PAINT_WINDOW, + _SCN_GET_WIN_ACTION, + _SCN_WAIT_FOR_ACTION, + _SCN_WAIT_IPC_SEND, + _SCN_WAIT_FOR_ANY_IPC, + _SCN_FIND_UNREAD_IPC, + _SCN_WAIT_IPC_READ, + _SCN_IS_TASK_RUNNING }; static inline uint32_t _sc0(enum _scn eax) { @@ -211,7 +113,7 @@ static inline void _exit_task() { } static inline _file_handle_t _open_file(_drive_number_t drive_number, const char *path) { - return _sc2(_SCN_OPEN_FILE, drive_number, (uint32_t)path); + return (_file_handle_t)_sc2(_SCN_OPEN_FILE, drive_number, (uint32_t)path); } static inline void _close_file(_file_handle_t handle) { @@ -226,16 +128,16 @@ static inline uint32_t _file_size(_file_handle_t handle) { return _sc1(_SCN_FILE_SIZE, handle); } -static inline _process_handle_t _start_task(_drive_number_t drive_number, const char *path, const char *pass) { - return _sc3(_SCN_START_TASK, drive_number, (uint32_t)path, (uint32_t)pass); +static inline _task_handle_t _start_task(_drive_number_t drive_number, const char *path, const char *pass, _task_handle_t stdio_task) { + return (_task_handle_t)_sc4(_SCN_START_TASK, drive_number, (uint32_t)path, (uint32_t)pass, (uint32_t)stdio_task); } -static inline void _log_string(const char *sz) { - _sc1(_SCN_LOG_STRING, (uint32_t)sz); +static inline uint32_t _ipc_send(_task_handle_t handle, uint32_t count, const void *buffer) { + return _sc3(_SCN_IPC_SEND, handle, count, (uint32_t)buffer); } -static inline _key_code_t _get_key() { - return _sc0(_SCN_GET_KEY); +static inline uint32_t _ipc_read(_task_handle_t handle, uint32_t count, void *buffer) { + return _sc3(_SCN_IPC_SEND, handle, count, (uint32_t)buffer); } static inline void *_allocate_ram(uint32_t pages) { @@ -262,7 +164,7 @@ static inline uint32_t _this_process_memory_left() { return _sc1(_SCN_MEMORY_INFO, 0x4); } -static inline void _wait_for_task(_process_handle_t handle) { +static inline void _wait_for_task(_task_handle_t handle) { _sc1(_SCN_WAIT_FOR_TASK, handle); } @@ -270,24 +172,60 @@ static inline uint32_t _enumerate_dir(_drive_number_t drive_number, const char * return _sc4(_SCN_ENUMERATE_DIR, drive_number, (uint32_t)path, (uint32_t)buffer, max_count); } -static inline void _print_at(uint8_t row, uint8_t col, const char *sz) { - _sc2(_SCN_PRINT_AT, (row << 8) | col, (uint32_t)sz); -} - static inline uint32_t _count_of_dir(uint8_t drive_number, const char *path) { return _sc2(_SCN_COUNT_OF_DIR, drive_number, (uint32_t)path); } -static inline void _clear_screen() { - _sc0(_SCN_CLEAR_SCREEN); +static inline _window_handle_t _new_window(uint16_t width, uint16_t height, void *pixel_buffer) { + return (_window_handle_t)_sc3(_SCN_NEW_WINDOW, width, height, (uint32_t)pixel_buffer); +} + +static inline void _delete_window(_window_handle_t window) { + _sc1(_SCN_DELETE_WINDOW, (uint32_t)window); +} + +static inline void _resize_window(_window_handle_t window, uint16_t width, uint16_t height) { + _sc3(_SCN_RESIZE_WINDOW, (uint32_t)window, width, height); +} + +static inline void _reassign_pixbuf(_window_handle_t window, void *pixel_buffer) { + _sc2(_SCN_REASSIGN_PIXBUF, (uint32_t)window, (uint32_t)pixel_buffer); +} + +static inline void _paint_window(_window_handle_t window) { + _sc1(_SCN_PAINT_WINDOW, (uint32_t)window); +} + +static inline void _get_win_action(_window_handle_t window, struct window_action *action_pointer) { + _sc2(_SCN_GET_WIN_ACTION, (uint32_t)window, (uint32_t)action_pointer); +} + +static inline void _wait_for_action() { + _sc0(_SCN_WAIT_FOR_ACTION); +} + +static inline void _wait_ipc_send(_task_handle_t sending_task) { + _sc1(_SCN_WAIT_IPC_SEND, sending_task); +} + +static inline void _system_log(const char *sz) { + _sc1(_SCN_SYSTEM_LOG, (uint32_t)sz); +} + +static inline void _wait_for_any_ipc() { + _sc0(_SCN_WAIT_FOR_ANY_IPC); +} + +static inline _task_handle_t _find_unread_ipc() { + return _sc0(_SCN_FIND_UNREAD_IPC); } -static inline void _set_color(_vga_color_t color) { - _sc1(_SCN_SET_COLOR, color); +static inline void _wait_ipc_read(_task_handle_t reading_task) { + _sc1(_SCN_WAIT_IPC_READ, reading_task); } -static inline void _swap_color(uint8_t row, uint8_t col) { - _sc1(_SCN_SWAP_COLOR, (row << 8) | col); +static inline bool _is_task_running(_task_handle_t handle) { + return (bool)_sc1(_SCN_IS_TASK_RUNNING, handle); } #endif
\ No newline at end of file diff --git a/src/user/include/popups/info.h b/src/user/include/popups/info.h new file mode 100644 index 0000000..2c4e83f --- /dev/null +++ b/src/user/include/popups/info.h @@ -0,0 +1,14 @@ +#ifndef POPUPS_INFO_H +#define POPUPS_INFO_H + +#include <popups/popup.h> + +#include <pland/syscall.h> + +#include <stdarg.h> + +void info_popup(struct popup *into, const char *text, uint8_t fg, uint8_t bg); +void info_popupf(struct popup *into, const char *text, uint8_t fg, uint8_t bg, ...); +void info_popupf_v(struct popup *into, const char *text, uint8_t fg, uint8_t bg, va_list args); + +#endif
\ No newline at end of file diff --git a/src/user/include/popups/popup.h b/src/user/include/popups/popup.h new file mode 100644 index 0000000..1a3c531 --- /dev/null +++ b/src/user/include/popups/popup.h @@ -0,0 +1,23 @@ +#ifndef POPUPS_POPUP_H +#define POPUPS_POPUP_H + +#include <pland/syscall.h> + +struct popup { + _window_handle_t handle; + uint8_t *pixbuf; + + bool has_quit; + struct key_packet quit_as; + + //terminated by one with .key_id == 0 + struct key_packet *quit_binds; + bool free_quit_binds; +}; + +void handle_actions(struct popup *p); +//deletes popup before returning +void make_modal(struct popup *p); +void delete_popup(struct popup *p); + +#endif
\ No newline at end of file diff --git a/src/user/include/terminal/readline.h b/src/user/include/terminal/readline.h new file mode 100644 index 0000000..9046610 --- /dev/null +++ b/src/user/include/terminal/readline.h @@ -0,0 +1,10 @@ +#ifndef TERMINAL_READLINE_H +#define TERMINAL_READLINE_H + +#include <stdint.h> + +//returns length of string without null terminator +//max_length doesn't include null terminator +uint32_t read_line(char *sz, uint32_t max_length, const char *prompt); + +#endif
\ No newline at end of file diff --git a/src/user/include/terminal/terminal.h b/src/user/include/terminal/terminal.h new file mode 100644 index 0000000..1782173 --- /dev/null +++ b/src/user/include/terminal/terminal.h @@ -0,0 +1,57 @@ +#ifndef TERMINAL_TERMINAL_H +#define TERMINAL_TERMINAL_H + +#include <libfont/fonts.h> + +#include <pland/syscall.h> + +#include <stdarg.h> +#include <stdint.h> + +struct terminal { + _window_handle_t window; + uint8_t *pixbuf; + uint32_t window_width; + uint32_t window_height; + + struct font_info *font; + + uint32_t cols; + uint32_t rows; + char *charbuf; + + uint32_t cursor_y; + uint32_t cursor_x; + + uint8_t fg; + uint8_t bg; +}; + +struct terminal *make_term(struct font_info *font, uint32_t cols, uint32_t rows); +void del_term(struct terminal *term); + +extern struct terminal *active_term; + +void paint_term(); + +void set_color(uint8_t fg, uint8_t bg); +void clear_term(); + +void move_cursor(uint32_t new_y, uint32_t new_x); + +void cursor_left(); +void cursor_right(); +void cursor_up(); +void cursor_down(); + +void term_newline(); +void term_add_char(char ch); +void term_add_sz_no_ww(const char *sz); +void term_add_sz(const char *sz); + +void term_addf_no_ww_v(const char *fmt, va_list args); +void term_addf_no_ww(const char *fmt, ...); +void term_addf_v(const char *fmt, va_list args); +void term_addf(const char *fmt, ...); + +#endif
\ No newline at end of file |