diff options
author | Paul Gilbert | 2018-11-12 11:51:49 -0800 |
---|---|---|
committer | Paul Gilbert | 2018-12-08 19:05:59 -0800 |
commit | ce7113b34a808ef8136114881f9d19ce857d13bc (patch) | |
tree | b91aeba5fae54a65c284a8b3d062bcef3f4a5a5c /engines/gargoyle | |
parent | 7d2406870e733258c7d59d54a7b490fbf52c2109 (diff) | |
download | scummvm-rg350-ce7113b34a808ef8136114881f9d19ce857d13bc.tar.gz scummvm-rg350-ce7113b34a808ef8136114881f9d19ce857d13bc.tar.bz2 scummvm-rg350-ce7113b34a808ef8136114881f9d19ce857d13bc.zip |
GLK: FROTZ: Added OS read line and character methods
Diffstat (limited to 'engines/gargoyle')
-rw-r--r-- | engines/gargoyle/frotz/glk_interface.cpp | 90 | ||||
-rw-r--r-- | engines/gargoyle/frotz/glk_interface.h | 18 | ||||
-rw-r--r-- | engines/gargoyle/frotz/processor.h | 10 | ||||
-rw-r--r-- | engines/gargoyle/frotz/processor_streams.cpp | 11 |
4 files changed, 124 insertions, 5 deletions
diff --git a/engines/gargoyle/frotz/glk_interface.cpp b/engines/gargoyle/frotz/glk_interface.cpp index c536a48df5..c376dc0056 100644 --- a/engines/gargoyle/frotz/glk_interface.cpp +++ b/engines/gargoyle/frotz/glk_interface.cpp @@ -404,5 +404,95 @@ void GlkInterface::gos_cancel_pending_line() { gos_linepending = 0; } +zchar GlkInterface::os_read_key(int timeout, bool show_cursor) { + event_t ev; + winid_t win = gos_curwin ? gos_curwin : gos_lower; + + if (gos_linepending) + gos_cancel_pending_line(); + + glk_request_char_event_uni(win); + if (timeout != 0) + glk_request_timer_events(timeout * 100); + + while (!shouldQuit()) { + glk_select(&ev); + if (ev.type == evtype_Arrange) { + gos_update_height(); + gos_update_width(); + } else if (ev.type == evtype_Timer) { + glk_cancel_char_event(win); + glk_request_timer_events(0); + return ZC_TIME_OUT; + } else if (ev.type == evtype_CharInput) + break; + } + if (shouldQuit()) + return 0; + + glk_request_timer_events(0); + + if (gos_upper && mach_status_ht < curr_status_ht) + reset_status_ht(); + curr_status_ht = 0; + + switch (ev.val1) { + case keycode_Escape: return ZC_ESCAPE; + case keycode_PageUp: return ZC_ARROW_MIN; + case keycode_PageDown: return ZC_ARROW_MAX; + case keycode_Left: return ZC_ARROW_LEFT; + case keycode_Right: return ZC_ARROW_RIGHT; + case keycode_Up: return ZC_ARROW_UP; + case keycode_Down: return ZC_ARROW_DOWN; + case keycode_Return: return ZC_RETURN; + case keycode_Delete: return ZC_BACKSPACE; + case keycode_Tab: return ZC_INDENT; + default: + return ev.val1; + } +} + +zchar GlkInterface::os_read_line(int max, zchar *buf, int timeout, int width, int continued) { + event_t ev; + winid_t win = gos_curwin ? gos_curwin : gos_lower; + + if (!continued && gos_linepending) + gos_cancel_pending_line(); + + if (!continued || !gos_linepending) { + glk_request_line_event_uni(win, buf, max, os_string_length(buf)); + if (timeout != 0) + glk_request_timer_events(timeout * 100); + } + + gos_linepending = 0; + + while (!shouldQuit()) { + glk_select(&ev); + if (ev.type == evtype_Arrange) { + gos_update_height(); + gos_update_width(); + } else if (ev.type == evtype_Timer) { + gos_linewin = win; + gos_linepending = 1; + gos_linebuf = buf; + return ZC_TIME_OUT; + } else if (ev.type == evtype_LineInput) { + break; + } + } + if (shouldQuit()) + return 0; + + glk_request_timer_events(0); + buf[ev.val1] = '\0'; + + if (gos_upper && mach_status_ht < curr_status_ht) + reset_status_ht(); + curr_status_ht = 0; + + return ZC_RETURN; +} + } // End of namespace Scott } // End of namespace Gargoyle diff --git a/engines/gargoyle/frotz/glk_interface.h b/engines/gargoyle/frotz/glk_interface.h index aeb33a8aa1..5393c5de10 100644 --- a/engines/gargoyle/frotz/glk_interface.h +++ b/engines/gargoyle/frotz/glk_interface.h @@ -159,6 +159,24 @@ protected: // Not implemented return 0; } + + void os_scrollback_char(zchar z) { + // Not implemented + } + + void os_scrollback_erase(int amount) { + // Not implemented + } + + /** + * Waits for a keypress + */ + zchar os_read_key(int timeout, bool show_cursor); + + /** + * Waits for the user to type an input line + */ + zchar os_read_line(int max, zchar *buf, int timeout, int width, int continued); public: /** * Constructor diff --git a/engines/gargoyle/frotz/processor.h b/engines/gargoyle/frotz/processor.h index 0a9d0efcdf..6a28121512 100644 --- a/engines/gargoyle/frotz/processor.h +++ b/engines/gargoyle/frotz/processor.h @@ -309,6 +309,16 @@ private: */ /** + * Waits for the user to type an input line + */ + zchar console_read_input(int max, zchar *buf, zword timeout, bool continued); + + /** + * Waits for a keypress + */ + zchar console_read_key(zword timeout); + + /** * Write a single character to the scrollback buffer. * */ diff --git a/engines/gargoyle/frotz/processor_streams.cpp b/engines/gargoyle/frotz/processor_streams.cpp index 97784c8423..d75819e661 100644 --- a/engines/gargoyle/frotz/processor_streams.cpp +++ b/engines/gargoyle/frotz/processor_streams.cpp @@ -25,12 +25,13 @@ namespace Gargoyle { namespace Frotz { -// TODO: Implement method stubs -static void os_scrollback_char(zchar) {} -static void os_scrollback_erase(zword) {} -static zchar console_read_key(zword) { return 0; } -static zchar console_read_input(uint, zchar *, uint, bool) { return 0; } +zchar Processor::console_read_input(int max, zchar *buf, zword timeout, bool continued) { + return os_read_line(max, buf, timeout, max, continued); +} +zchar Processor::console_read_key(zword timeout) { + return os_read_key(timeout, 0); +} void Processor::scrollback_char(zchar c) { if (c == ZC_INDENT) |