2 * RGB2R-C128-Kassenprogramm
3 * © 2007-2009 phil_fry, sECuRE, sur5r
4 * See LICENSE for license information
14 #include "vdc_patch_charset.h"
17 * get_input_terminated_by() reads input (handling backspace correctly) until
18 * a terminator of |terminators| is encountered or |out| is full (outlen-1
19 * characters were read).
21 * get_input_terminated_by() returns the terminator it encountered.
24 input_terminator_t get_input_terminated_by(input_terminator_mask_t terminators,
25 char *out, BYTE outlen) {
32 if (((terminators & INPUT_TERMINATOR_RETURN) == INPUT_TERMINATOR_RETURN) &&
34 return INPUT_TERMINATOR_RETURN;
35 } else if (((terminators & INPUT_TERMINATOR_SPACE) ==
36 INPUT_TERMINATOR_SPACE) &&
38 return INPUT_TERMINATOR_SPACE;
39 } else if (c == PETSCII_DEL) {
40 /* If you are at the left-most position, do nothing */
44 cputcxy(x + i, y, ' ');
48 if (i == (outlen - 1)) {
57 * Liest (maximal 31) Zeichen ein, bis Enter gedrückt wird.
58 * Vorsicht: Es wird ein statischer Buffer benutzt, sodass man
59 * das Ergebnis via strdup() retten muss, bevor man get_input()
63 char *get_input(void) {
64 static char output[32];
65 memset(output, '\0', sizeof(output));
66 get_input_terminated_by(INPUT_TERMINATOR_RETURN, output, sizeof(output));
70 BYTE cgetn_input(char *s, BYTE len) {
72 get_input_terminated_by(INPUT_TERMINATOR_RETURN, s, len);
76 int16_t cget_number(int16_t default_val) {
79 uint8_t num_chars = 0;
80 char buf[6] = {0, 0, 0, 0, 0, 0};
92 if (c == PETSCII_DEL) {
96 cputcxy(x + i, y, ' ');
102 if (c == PETSCII_ESC) {
106 /* end of buffer? wait for user to press RETURN */
107 if (i == (sizeof(buf) - 1))
110 /* match either numbers or iff it's the first entered char a minus sign */
111 if ((c >= PETSCII_0 && c <= PETSCII_9) || (c == '-' && i == 0)) {
119 if (num_chars == 0) {
121 } else if ((num_chars == 1) && (c == '-')) {
129 while (cgetc() != PETSCII_CR) {
134 char retry_or_quit(void) {
137 cprintf("\r\nr)etry or q)uit?\r\n");
139 } while ((*c != 'r') && (*c != 'q'));
143 char *format_euro(char *s, int maxlen, int cent) {
144 if (snprintf(s, maxlen, EUR_FORMAT, cent / 100, cent % 100) > maxlen)
149 void c128_perror(BYTE c, char *msg) {
150 cprintf("\r\nError (Code %d) while: %s\r\nOS Error = %d\r\n", c, msg,