From dbbdb31cb1d9f3fd77ffff2ad56e8dba8db2ad9a Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Mon, 30 Mar 2020 21:58:06 +0900 Subject: [PATCH] [qwaq] Add a synchronous printf command This puts a print command (to Sys_Printf) into the queue making it easier to check command sequences since regular printf is asynchronous with the stream. --- ruamoko/qwaq/builtins/curses.c | 48 ++++++++++++++++++++++++++++++---- ruamoko/qwaq/ui/curses.h | 1 + ruamoko/qwaq/ui/textcontext.r | 1 + 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/ruamoko/qwaq/builtins/curses.c b/ruamoko/qwaq/builtins/curses.c index b03533db4..04ef11516 100644 --- a/ruamoko/qwaq/builtins/curses.c +++ b/ruamoko/qwaq/builtins/curses.c @@ -55,6 +55,7 @@ #define CMD_SIZE(x) sizeof(x)/sizeof(x[0]) typedef enum qwaq_commands_e { + qwaq_cmd_syncprint, qwaq_cmd_newwin, qwaq_cmd_delwin, qwaq_cmd_getwrect, @@ -89,6 +90,7 @@ typedef enum qwaq_commands_e { } qwaq_commands; static const char *qwaq_command_names[]= { + "syncprint", "newwin", "delwin", "getwrect", @@ -118,8 +120,8 @@ static const char *qwaq_command_names[]= { "mvwblit_line", "wresize", "resizeterm", - "mvwhline" - "mvwvline" + "mvwhline", + "mvwvline", }; static window_t * @@ -280,6 +282,15 @@ qwaq_wait_result (qwaq_resources_t *res, int *result, int cmd, unsigned len) pthread_mutex_unlock (&res->results_cond.mut); } +static void +cmd_syncprint (qwaq_resources_t *res) +{ + int string_id = RB_PEEK_DATA (res->command_queue, 2); + + Sys_Printf ("%s\n", res->strings[string_id].str); + release_string (res, string_id); +} + static void cmd_newwin (qwaq_resources_t *res) { @@ -636,10 +647,14 @@ dump_command (qwaq_resources_t *res, int len) if (0) { qwaq_commands cmd = RB_PEEK_DATA (res->command_queue, 0); Sys_Printf ("%s[%d]", qwaq_command_names[cmd], len); - for (int i = 2; i < len; i++) { - Sys_Printf (" %d", RB_PEEK_DATA (res->command_queue, i)); + if (cmd == qwaq_cmd_syncprint) { + Sys_Printf (" "); + } else { + for (int i = 2; i < len; i++) { + Sys_Printf (" %d", RB_PEEK_DATA (res->command_queue, i)); + } + Sys_Printf ("\n"); } - Sys_Printf ("\n"); } } @@ -682,6 +697,9 @@ process_commands (qwaq_resources_t *res) dump_command (res, len); qwaq_commands cmd = RB_PEEK_DATA (res->command_queue, 0); switch (cmd) { + case qwaq_cmd_syncprint: + cmd_syncprint (res); + break; case qwaq_cmd_newwin: cmd_newwin (res); break; @@ -829,6 +847,25 @@ bi_shutdown (void *_pr) } } +static void +bi_syncprintf (progs_t *pr) +{ + qwaq_resources_t *res = PR_Resources_Find (pr, "qwaq"); + const char *fmt = P_GSTRING (pr, 0); + int count = pr->pr_argc - 1; + pr_type_t **args = pr->pr_params + 1; + int string_id = acquire_string (res); + dstring_t *print_buffer = res->strings + string_id; + int command[] = { qwaq_cmd_syncprint, 0, string_id }; + + command[1] = CMD_SIZE(command); + + dstring_clearstr (print_buffer); + PR_Sprintf (pr, print_buffer, "mvwaddstr", fmt, count, args); + + qwaq_submit_command (res, command); +} + static void bi_newwin (progs_t *pr) { @@ -1894,6 +1931,7 @@ bi_qwaq_clear (progs_t *pr, void *data) static builtin_t builtins[] = { {"initialize", bi_initialize, -1}, + {"syncprintf", bi_syncprintf, -1}, {"create_window", bi_newwin, -1}, {"destroy_window", bi_delwin, -1}, {"getwrect", bi_getwrect, -1}, diff --git a/ruamoko/qwaq/ui/curses.h b/ruamoko/qwaq/ui/curses.h index 65143159f..1849a6440 100644 --- a/ruamoko/qwaq/ui/curses.h +++ b/ruamoko/qwaq/ui/curses.h @@ -87,6 +87,7 @@ typedef struct panel_s *panel_t; extern window_t stdscr; void initialize (void); +void syncprintf (string fnt, ...); window_t create_window (int xpos, int ypos, int xlen, int ylen); void destroy_window (window_t win); void mvwprintf (window_t win, int x, int y, string fmt, ...); diff --git a/ruamoko/qwaq/ui/textcontext.r b/ruamoko/qwaq/ui/textcontext.r index 1f2ddd066..bbe7a9476 100644 --- a/ruamoko/qwaq/ui/textcontext.r +++ b/ruamoko/qwaq/ui/textcontext.r @@ -179,6 +179,7 @@ static TextContext *screen; window_t stdscr = (window_t) 1; void initialize (void) = #0; +void syncprintf (string fnt, ...) = #0; window_t create_window (int xpos, int ypos, int xlen, int ylen) = #0; void destroy_window (window_t win) = #0; void mvwprintf (window_t win, int x, int y, string fmt, ...) = #0;