2 * RGB2R-C128-Kassenprogramm
3 * © 2007-2009 phil_fry, sECuRE, sur5r
4 * See LICENSE for license information
15 #include "vdc_patch_charset.h"
18 * get_input_terminated_by() reads input (handling backspace correctly) until
19 * a terminator of |terminators| is encountered or |out| is full (outlen-1
20 * characters were read).
22 * get_input_terminated_by() returns the terminator it encountered.
25 input_terminator_t get_input_terminated_by(input_terminator_mask_t terminators,
26 char *out, BYTE outlen) {
33 if (((terminators & INPUT_TERMINATOR_RETURN) == INPUT_TERMINATOR_RETURN) &&
35 return INPUT_TERMINATOR_RETURN;
36 } else if (((terminators & INPUT_TERMINATOR_SPACE) ==
37 INPUT_TERMINATOR_SPACE) &&
39 return INPUT_TERMINATOR_SPACE;
40 } else if (c == PETSCII_DEL) {
41 /* If you are at the left-most position, do nothing */
45 cputcxy(x + i, y, ' ');
49 if (i == (outlen - 1)) {
58 * Liest (maximal 31) Zeichen ein, bis Enter gedrückt wird.
59 * Vorsicht: Es wird ein statischer Buffer benutzt, sodass man
60 * das Ergebnis via strdup() retten muss, bevor man get_input()
64 char *get_input(void) {
65 static char output[32];
66 memset(output, '\0', sizeof(output));
67 get_input_terminated_by(INPUT_TERMINATOR_RETURN, output, sizeof(output));
71 BYTE cgetn_input(char *s, BYTE len) {
73 get_input_terminated_by(INPUT_TERMINATOR_RETURN, s, len);
77 int16_t cget_number(int16_t default_val) {
80 uint8_t num_chars = 0;
81 char buf[6] = {0, 0, 0, 0, 0, 0};
93 if (c == PETSCII_DEL) {
97 cputcxy(x + i, y, ' ');
103 if (c == PETSCII_ESC) {
107 /* end of buffer? wait for user to press RETURN */
108 if (i == (sizeof(buf) - 1))
111 /* match either numbers or iff it's the first entered char a minus sign */
112 if ((c >= PETSCII_0 && c <= PETSCII_9) || (c == '-' && i == 0)) {
120 if (num_chars == 0) {
122 } else if ((num_chars == 1) && (c == '-')) {
129 uint8_t cget_nickname(char *nickname, uint8_t length) {
130 uint8_t i, x, y, matches;
132 input_terminator_t terminator;
134 memset(nickname, '\0', length);
137 terminator = get_input_terminated_by(
138 INPUT_TERMINATOR_RETURN | INPUT_TERMINATOR_SPACE, nickname, length);
140 /* Clear the screen from any previous completions */
143 for (i = 1; i < 7; i++) {
144 /* "Completion:" is longer than NICKNAME_MAX_LEN */
145 cclearxy(0, y + i, strlen("Completion:"));
149 if (terminator != INPUT_TERMINATOR_SPACE) {
150 return strlen(nickname);
155 for (i = 0; i < credits.num_items; i++) {
156 if (strncasecmp(nickname, credits.credits[i].nickname,
157 strlen(nickname)) != 0) {
164 uniquematch = credits.credits[i].nickname;
167 /* Display the rest of the nickname */
168 textcolor(TC_LIGHT_GREEN);
169 cprintf("%s", uniquematch + strlen(nickname));
170 textcolor(TC_LIGHT_GRAY);
171 strcat(nickname, uniquematch + strlen(nickname));
173 /* Multiple nicknames match what was entered so far. Abort and
174 * display all matches, then prompt the user again. */
175 char completion[NICKNAME_MAX_LEN + 1];
176 BYTE len = strlen(nickname);
179 cprintf("\r\nCompletion:\r\n");
181 for (i = 0; i < credits.num_items; i++) {
182 if (strncasecmp(nickname, credits.credits[i].nickname, len) != 0) {
185 if (++matches == 5) {
189 strcpy(completion, credits.credits[i].nickname);
190 *(completion + len) = '\0';
191 cprintf("%s", completion);
192 textcolor(TC_LIGHT_GREEN);
193 cprintf("%c", *(credits.credits[i].nickname + len));
194 textcolor(TC_LIGHT_GRAY);
195 cprintf("%s\r\n", completion + len + 1);
202 /* wait until user pressed RETURN, ignore all other input */
204 while (cgetc() != PETSCII_CR) {
209 char retry_or_quit(void) {
212 cprintf("\r\nr)etry or q)uit?\r\n");
214 } while ((*c != 'r') && (*c != 'q'));
218 char *format_euro(char *s, int maxlen, int cent) {
219 if (snprintf(s, maxlen, EUR_FORMAT, cent / 100, cent % 100) > maxlen)
224 void c128_perror(BYTE c, char *msg) {
225 cprintf("\r\nError (Code %d) while: %s\r\nOS Error = %d\r\n", c, msg,