A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd
at master 301 lines 6.2 kB view raw
1/* input.c - High level input functions 2 * Copyright (c) 1995-1997 Stefan Jokisch 3 * 4 * Changes for Rockbox copyright 2009 Torne Wuff 5 * 6 * This file is part of Frotz. 7 * 8 * Frotz is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation; either version 2 of the License, or 11 * (at your option) any later version. 12 * 13 * Frotz is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 21 */ 22 23#include "frotz.h" 24 25extern int save_undo (void); 26 27extern zchar stream_read_key (zword, zword, bool); 28extern zchar stream_read_input (int, zchar *, zword, zword, bool, bool); 29 30extern void tokenise_line (zword, zword, zword, bool); 31 32/* 33 * is_terminator 34 * 35 * Check if the given key is an input terminator. 36 * 37 */ 38 39bool is_terminator (zchar key) 40{ 41 42 if (key == ZC_TIME_OUT) 43 return TRUE; 44 if (key == ZC_RETURN) 45 return TRUE; 46 if (key >= ZC_HKEY_MIN && key <= ZC_HKEY_MAX) 47 return TRUE; 48 49 if (h_terminating_keys != 0) 50 51 if (key >= ZC_ARROW_MIN && key <= ZC_MENU_CLICK) { 52 53 zword addr = h_terminating_keys; 54 zbyte c; 55 56 do { 57 LOW_BYTE (addr, c) 58 if (c == 255 || key == translate_from_zscii (c)) 59 return TRUE; 60 addr++; 61 } while (c != 0); 62 63 } 64 65 return FALSE; 66 67}/* is_terminator */ 68 69/* 70 * z_make_menu, add or remove a menu and branch if successful. 71 * 72 * zargs[0] = number of menu 73 * zargs[1] = table of menu entries or 0 to remove menu 74 * 75 */ 76 77void z_make_menu (void) 78{ 79 80 /* This opcode was only used for the Macintosh version of Journey. 81 It controls menus with numbers greater than 2 (menus 0, 1 and 2 82 are system menus). Frotz doesn't implement menus yet. */ 83 84 branch (FALSE); 85 86}/* z_make_menu */ 87 88extern bool read_yes_or_no (const char *s); 89 90/* 91 * read_string 92 * 93 * Read a string from the current input stream. 94 * 95 */ 96 97void read_string (int max, zchar *buffer) 98{ 99 zchar key; 100 101 buffer[0] = 0; 102 103 do { 104 105 key = stream_read_input (max, buffer, 0, 0, FALSE, FALSE); 106 107 } while (key != ZC_RETURN); 108 109}/* read_string */ 110 111/* 112 * read_number 113 * 114 * Ask the user to type in a number and return it. 115 * 116 */ 117 118int read_number (void) 119{ 120 zchar buffer[6]; 121 int value = 0; 122 int i; 123 124 read_string (5, buffer); 125 126 for (i = 0; buffer[i] != 0; i++) 127 if (buffer[i] >= '0' && buffer[i] <= '9') 128 value = 10 * value + buffer[i] - '0'; 129 130 return value; 131 132}/* read_number */ 133 134/* 135 * z_read, read a line of input and (in V5+) store the terminating key. 136 * 137 * zargs[0] = address of text buffer 138 * zargs[1] = address of token buffer 139 * zargs[2] = timeout in tenths of a second (optional) 140 * zargs[3] = packed address of routine to be called on timeout 141 * 142 */ 143 144void z_read (void) 145{ 146 zchar buffer[INPUT_BUFFER_SIZE]; 147 zword addr; 148 zchar key; 149 zbyte max, size; 150 zbyte c; 151 int i; 152 153 /* Supply default arguments */ 154 155 if (zargc < 3) 156 zargs[2] = 0; 157 158 /* Get maximum input size */ 159 160 addr = zargs[0]; 161 162 LOW_BYTE (addr, max) 163 164 if (h_version <= V4) 165 max--; 166 167 if (max >= INPUT_BUFFER_SIZE) 168 max = INPUT_BUFFER_SIZE - 1; 169 170 /* Get initial input size */ 171 172 if (h_version >= V5) { 173 addr++; 174 LOW_BYTE (addr, size) 175 } else size = 0; 176 177 /* Copy initial input to local buffer */ 178 179 for (i = 0; i < size; i++) { 180 addr++; 181 LOW_BYTE (addr, c) 182 buffer[i] = translate_from_zscii (c); 183 } 184 185 buffer[i] = 0; 186 187 /* Draw status line for V1 to V3 games */ 188 189 if (h_version <= V3) 190 z_show_status (); 191 192 /* Read input from current input stream */ 193 194 key = stream_read_input ( 195 max, buffer, /* buffer and size */ 196 zargs[2], /* timeout value */ 197 zargs[3], /* timeout routine */ 198 TRUE, /* enable hot keys */ 199 h_version == V6); /* no script in V6 */ 200 201 if (key == ZC_BAD) 202 return; 203 204 /* Perform save_undo for V1 to V4 games */ 205 206 if (h_version <= V4) 207 save_undo (); 208 209 /* Copy local buffer back to dynamic memory */ 210 211 for (i = 0; buffer[i] != 0; i++) { 212 213 if (key == ZC_RETURN) { 214 215 if (buffer[i] >= 'A' && buffer[i] <= 'Z') 216 buffer[i] += 'a' - 'A'; 217 if (buffer[i] >= 0xc0 && buffer[i] <= 0xde && buffer[i] != 0xd7) 218 buffer[i] += 0x20; 219 220 } 221 222 storeb ((zword) (zargs[0] + ((h_version <= V4) ? 1 : 2) + i), translate_to_zscii (buffer[i])); 223 224 } 225 226 /* Add null character (V1-V4) or write input length into 2nd byte */ 227 228 if (h_version <= V4) 229 storeb ((zword) (zargs[0] + 1 + i), 0); 230 else 231 storeb ((zword) (zargs[0] + 1), i); 232 233 /* Tokenise line if a token buffer is present */ 234 235 if (key == ZC_RETURN && zargs[1] != 0) 236 tokenise_line (zargs[0], zargs[1], 0, FALSE); 237 238 /* Store key */ 239 240 if (h_version >= V5) 241 store (translate_to_zscii (key)); 242 243}/* z_read */ 244 245/* 246 * z_read_char, read and store a key. 247 * 248 * zargs[0] = input device (must be 1) 249 * zargs[1] = timeout in tenths of a second (optional) 250 * zargs[2] = packed address of routine to be called on timeout 251 * 252 */ 253 254void z_read_char (void) 255{ 256 zchar key; 257 258 /* Supply default arguments */ 259 260 if (zargc < 2) 261 zargs[1] = 0; 262 263 /* Read input from the current input stream */ 264 265 key = stream_read_key ( 266 zargs[1], /* timeout value */ 267 zargs[2], /* timeout routine */ 268 TRUE); /* enable hot keys */ 269 270 if (key == ZC_BAD) 271 return; 272 273 /* Store key */ 274 275 store (translate_to_zscii (key)); 276 277}/* z_read_char */ 278 279/* 280 * z_read_mouse, write the current mouse status into a table. 281 * 282 * zargs[0] = address of table 283 * 284 */ 285 286void z_read_mouse (void) 287{ 288 zword btn; 289 290 /* Read the mouse position and which buttons are down */ 291 292 btn = os_read_mouse (); 293 hx_mouse_y = mouse_y; 294 hx_mouse_x = mouse_x; 295 296 storew ((zword) (zargs[0] + 0), hx_mouse_y); 297 storew ((zword) (zargs[0] + 2), hx_mouse_x); 298 storew ((zword) (zargs[0] + 4), btn); /* mouse button bits */ 299 storew ((zword) (zargs[0] + 6), 0); /* menu selection */ 300 301}/* z_read_mouse */