]> git.sur5r.net Git - c128-kasse/commitdiff
replace getchar() with cgetc() in more places, implement backspace support, beautify...
authorMichael Stapelberg <michael@stapelberg.de>
Mon, 1 Nov 2010 18:26:31 +0000 (19:26 +0100)
committerMichael Stapelberg <michael@stapelberg.de>
Mon, 1 Nov 2010 18:26:31 +0000 (19:26 +0100)
src/general.c
src/kasse.c

index 59945444f12ac9219117c5751e9c908b80af9e63..cae149a6dc86eedc2eb2feb9f7f672f960845b3b 100644 (file)
  */
 char *get_input() {
        BYTE i = 0;
+       BYTE c, x, y;
        static char output[32];
-       BYTE c;
+       x = wherex();
+       y = wherey();
        memset(output, '\0', 32);
        while (1) {
                if (i == 31)
@@ -29,6 +31,13 @@ char *get_input() {
                c = cgetc();
                if (c == 13)
                        break;
+               /* backspace? */
+               if (c == 20) {
+                       i--;
+                       cputcxy(x+i, y, ' ');
+                       gotoxy(x+i, y);
+                       continue;
+               }
                cputc(c);
                output[i++] = c;
        }
index 70863885b2972845f6ee5f551b08a5bc28b75e30..865890a34c06eb9a237095e0bec7d40bf7b91f47 100644 (file)
@@ -103,18 +103,20 @@ static signed int buy(char *name, unsigned int price) {
        int einheiten;
        char *input;
        char nickname[11];
-       char rest[9];
+       char rest[11];
        struct credits_t *credit;
 
        memset(rest, ' ', sizeof(rest));
        rest[8] = '\0';
 
+       clrscr();
        cprintf("Wieviel Einheiten \"%s\"? [1] \r\n", name);
        while (1) {
-               c = getchar();
+               c = cgetc();
                if (c == 13)
                        break;
-               else if (c == 27) {
+               cputc(c);
+               if (c == 27) {
                        cprintf("Kauf abgebrochen, druecke RETURN...\r\n");
                        get_input();
                        return 1;
@@ -126,7 +128,8 @@ static signed int buy(char *name, unsigned int price) {
        einheiten = atoi(entered) * negative;
        
        toggle_videomode();
-       cprintf("%dx %s fuer ", einheiten, name);
+       cprintf("\r\n             *** VERKAUF ***\r\n\r\n");
+       cprintf("%dx %s", einheiten, name);
        toggle_videomode();
        
        cprintf("\r\nAuf ein Guthaben kaufen? Wenn ja, Nickname eingeben:\r\n");
@@ -134,11 +137,11 @@ static signed int buy(char *name, unsigned int price) {
        strncpy(nickname, input, 11);
        if (*nickname != '\0') {
                toggle_videomode();
-               cprintf("%s\r\n", nickname);
+               cprintf(" fuer %s\r\n", nickname);
                toggle_videomode();
        }
 
-       if (nickname != NULL && *nickname != '\0' && *nickname != 32) {
+       if (*nickname != '\0' && *nickname != 32) {
                nickname_len = strlen(nickname);
                /* go through credits and remove the amount of money or set nickname
                 * to NULL if no such credit could be found */
@@ -160,7 +163,7 @@ static signed int buy(char *name, unsigned int price) {
                        cprintf("\r\nVerbleibendes Guthaben fuer %s: %s. Druecke RETURN...\r\n",
                                nickname, rest);
                        toggle_videomode();
-                       cprintf("\r\nDein verbleibendes Guthaben betraegt %s.\r\n", rest);
+                       cprintf("\r\nDein Guthaben betraegt noch %s.\r\n", rest);
                        toggle_videomode();
                        get_input();
                        matches++;
@@ -209,10 +212,11 @@ void buy_custom() {
 
        cprintf("\r\nWie teuer ist \"%s\" (in cents)?\r\n", name);
        while (1) {
-               c = getchar();
+               c = cgetc();
                if (c == 13)
                        break;
-               else if (c == 27) {
+               cputc(c);
+               if (c == 27) {
                        cprintf("Kauf abgebrochen, druecke RETURN...\r\n");
                        get_input();
                        return;