diff options
| author | Hanjie Wu <hanjiew@andrew.cmu.edu> | 2023-04-23 14:56:34 -0400 |
|---|---|---|
| committer | Hanjie Wu <hanjiew@andrew.cmu.edu> | 2023-04-23 14:56:34 -0400 |
| commit | f5df2e1d666a943e17261d089456c9483bc9e998 (patch) | |
| tree | 119cf8284593389e0309224143a0793e242435e8 /kern/inc | |
| parent | 8b93cd18bc1ff2ec1cfd96ead5ff5606cbc35831 (diff) | |
pts console
Diffstat (limited to 'kern/inc')
| -rw-r--r-- | kern/inc/console.h | 94 | ||||
| -rw-r--r-- | kern/inc/sched.h | 2 | ||||
| -rw-r--r-- | kern/inc/usermem.h | 2 |
3 files changed, 43 insertions, 55 deletions
diff --git a/kern/inc/console.h b/kern/inc/console.h index a3649de..0d65922 100644 --- a/kern/inc/console.h +++ b/kern/inc/console.h @@ -26,12 +26,43 @@ #ifndef _CONSOLE_H #define _CONSOLE_H -#include <video_defines.h> +#include <stdbool.h> +#include <stddef.h> +#include <stdint.h> +#include <string.h> +#include <x86/asm.h> +#include <x86/video_defines.h> + +#include <common.h> #include <sync.h> -/** mutex for console operations */ -extern mutex_t console_lock; +/** + * Someone is not satisfied with the type name char_t so we use this + * to reperesent a char on screen so that nobody will mistake it with 'char' + */ +typedef struct a_char_on_screen_s { + uint8_t ch; /** char */ + uint8_t color; /** color */ +} a_char_on_screen_t; + +typedef struct pts_s { + queue_t pts_link; + int refcount; + mutex_t lock; + a_char_on_screen_t mem[CONSOLE_HEIGHT][CONSOLE_WIDTH]; + int cur_x; + int cur_y; + char cur_color; + int cur_shown; +} pts_t; + +extern pts_t* active_pts; +extern spl_t pts_lock; + +void pts_init(pts_t* pts); + +int putbyte(char ch); /** @brief Prints character ch at the current location * of the cursor. @@ -48,7 +79,7 @@ extern mutex_t console_lock; * @param ch the character to print * @return The input character */ -int putbyte(char ch); +int pts_putbyte(pts_t* pts, char ch); /** @brief Prints the string s, starting at the current * location of the cursor. @@ -67,7 +98,7 @@ int putbyte(char ch); * @param len The length of the string s. * @return Void. */ -void putbytes(const char* s, int len); +void pts_putbytes(pts_t* pts, const char* s, int len); /** @brief Changes the foreground and background color * of future characters printed on the console. @@ -78,7 +109,7 @@ void putbytes(const char* s, int len); * @return 0 on success or integer error code less than 0 if * color code is invalid. */ -int set_term_color(int color); +int pts_set_term_color(pts_t* pts, int color); /** @brief Writes the current foreground and background * color of characters printed on the console @@ -87,7 +118,7 @@ int set_term_color(int color); * information will be written. * @return Void. */ -void get_term_color(int* color); +void pts_get_term_color(pts_t* pts, int* color); /** @brief Sets the position of the cursor to the * position (row, col). @@ -102,7 +133,7 @@ void get_term_color(int* color); * @return 0 on success or integer error code less than 0 if * cursor location is invalid. */ -int set_cursor(int row, int col); +int pts_set_cursor(pts_t* pts, int row, int col); /** @brief Writes the current position of the cursor * into the arguments row and col. @@ -112,51 +143,6 @@ int set_cursor(int row, int col); * column will be written. * @return Void. */ -void get_cursor(int* row, int* col); - -/** @brief Hides the cursor. - * - * Subsequent calls to putbytes do not cause the - * cursor to show again. - * - * @return Void. - */ -void hide_cursor(void); - -/** @brief Shows the cursor. - * - * If the cursor is already shown, the function has no effect. - * - * @return Void. - */ -void show_cursor(void); - -/** @brief Clears the entire console. - * - * The cursor is reset to the first row and column - * - * @return Void. - */ -void clear_console(void); - -/** @brief Prints character ch with the specified color - * at position (row, col). - * - * If any argument is invalid, the function has no effect. - * - * @param row The row in which to display the character. - * @param col The column in which to display the character. - * @param ch The character to display. - * @param color The color to use to display the character. - * @return Void. - */ -void draw_char(int row, int col, int ch, int color); - -/** @brief Returns the character displayed at position (row, col). - * @param row Row of the character. - * @param col Column of the character. - * @return The character at (row, col). - */ -char get_char(int row, int col); +void pts_get_cursor(pts_t* pts, int* row, int* col); #endif /* _CONSOLE_H */ diff --git a/kern/inc/sched.h b/kern/inc/sched.h index eddb849..718fdae 100644 --- a/kern/inc/sched.h +++ b/kern/inc/sched.h @@ -16,6 +16,7 @@ #include <x86/seg.h> #include <common.h> +#include <console.h> #include <paging.h> #include <pv.h> #include <sync.h> @@ -148,6 +149,7 @@ typedef struct thread_s { queue_t process_link; /* in process_t's threads queue */ + pts_t* pts; process_t* process; reg_t esp3; diff --git a/kern/inc/usermem.h b/kern/inc/usermem.h index c5622e8..2b90c1b 100644 --- a/kern/inc/usermem.h +++ b/kern/inc/usermem.h @@ -45,6 +45,6 @@ char* copy_string_from_user(va_t addr, int maxlen); * @param maxlen maximum length of to print * @return 0 on success, -1 on failure */ -int print_buf_from_user(va_t addr, int maxlen); +int print_buf_from_user(pts_t* pts, va_t addr, int maxlen); #endif |
