diff options
author | B. Watson <yalhcru@gmail.com> | 2015-12-31 05:54:41 -0500 |
---|---|---|
committer | B. Watson <yalhcru@gmail.com> | 2015-12-31 05:54:41 -0500 |
commit | b400e1273f87c606742d6e897c22729160f8dfda (patch) | |
tree | 786fd8dae9c0a2b84e8f4fe62c874360ed4f7d95 | |
parent | 358ed61e3bdef37ca0f4a3cd0eb8a248b2f2affe (diff) | |
download | taipan-b400e1273f87c606742d6e897c22729160f8dfda.tar.gz |
eliminate stdio.h, fix some bugs
-rw-r--r-- | taipan.c | 99 |
1 files changed, 48 insertions, 51 deletions
@@ -1,7 +1,7 @@ #include <conio.h> #include <time.h> #include <stdlib.h> -#include <stdio.h> +// #include <stdio.h> // finally got rid of it! #include <string.h> #include <peekpoke.h> @@ -11,7 +11,7 @@ // #define COMBAT_TEST /* define this to show internals of damage calculation */ -#define DAMAGE_TEST +// #define DAMAGE_TEST /* define this to test the mchenry() routine by entering damage and capacity numbers directly */ @@ -55,16 +55,6 @@ extern void __fastcall__ jsleep(unsigned int j); extern unsigned int __fastcall__ randi(void); extern unsigned long __fastcall__ randl(void); -/* used to use this: -unsigned long randl() { - unsigned long r = rand(); - char *buf = (char *)r; - buf[2] = PEEK(53770); - buf[3] = PEEK(53770); - return r; -} -*/ - char port_stat_dirty = 1; extern const char *port_stat_screen; @@ -110,6 +100,23 @@ int lcgetch() { return lc(cgetc()); } +/* print 'count' spaces, but leave the cursor where it was. + doesn't work if the cursor wraps to the next line! + */ +void cblank(unsigned char count) { + char oldx = wherex(); + while(count--) cputc(' '); + gotox(oldx); +} + +/* conio doesn't back up the cursor if you cputc(BS), it + prints the graphics character instead. So: */ +void backspace() { + gotox(wherex()-1); + cblank(1); +} + + /* taipan functions (modified as little as possible) */ #define GENERIC 1 #define LI_YUEN 2 @@ -190,34 +197,14 @@ int hold = 0, int newdamage; +// fancy_numbers() will get replaced sooner or later. +// void cprintfancy(unsigned long ul) { +// } /* print an int or long as a string, conio-style */ void cprintulong(unsigned long ul) { cputs(ultoa(ul, fancy_num, 10)); } -/* print 'count' spaces, but leave the cursor where it was. - doesn't work if the cursor wraps to the next line! - */ -void cblank(unsigned char count) { - char oldx = wherex(); - while(count--) cputc(' '); - gotox(oldx); -} - -#ifdef COMBAT_TEST -void show_damage(void) { - cputc(' '); - cprintulong(damage); - cputc('/'); - cprintulong(capacity); -} -#else -#define show_damage() -#endif - -// fancy_numbers() will get replaced sooner or later. -// void cprintfancy(unsigned long ul) { -// } void at_sea() { gotoxy(30, 6); @@ -541,6 +528,7 @@ int sea_battle(int id, int num_ships) { } clrscr(); + cursor(0); flushinp(); fight_stats(num_ships, orders); @@ -559,7 +547,6 @@ int sea_battle(int id, int num_ships) { cprintulong(status); cputs("%)"); gotoxy(0, 4); - show_damage(); for(i = 0; i <= 9; i++) { if (num_ships > num_on_screen) { @@ -990,6 +977,8 @@ int sea_battle(int id, int num_ships) { // cc65 runtime can't detect it... // If ((ed * i * id)/2)) works out to 1, anything%1 is 0. // damage = damage + (randi() % ((ed * i * id)/2)) + (i / 2); + // The is to avoid to % operator if the 2nd arg would be + // 0 or 1: the intended result would just be 0 or 1 anyway. newdamage = ((ed * i * id)/2) + (i / 2); if(newdamage > 1) @@ -1041,22 +1030,24 @@ int get_one(void) // Atari cursor doesn't change visibility until a character // is printed... can't use cputc() here as it escapes the // character (prints graphics char instead of actually backspacing) - putchar(' '); + + /* new: */ cursor(1); - putchar(BKSP); + cblank(1); while ((input = cgetc()) != '\n') { if (((input == BKSP) || (input == 127)) && (character == 0)) { } else if ((input == BKSP) || (input == 127)) { - putchar(BKSP); + // putchar(BKSP); + backspace(); character--; } else if (character >= 1) { } else if (input == '\33') { flushinp(); } else { - putchar(input); + cputc(input); choice = input; character++; } @@ -1077,15 +1068,17 @@ unsigned long get_num(int maxlen) long amount; - putchar(' '); + /* new: */ cursor(1); - putchar(BKSP); + cblank(1); + while ((input = cgetc()) != '\n') { if (((input == BKSP) || (input == 127)) && (character == 0)) { } else if ((input == BKSP) || (input == 127)) { - putchar(BKSP); + // putchar(BKSP); + backspace(); number[character] = '\0'; character--; } else if (character >= maxlen) { @@ -1093,12 +1086,12 @@ unsigned long get_num(int maxlen) flushinp(); } else if (((input == 'A') || (input == 'a')) && (character == 0) && (maxlen > 1)) { - putchar(input); + cputc(input); number[character] = input; character++; } else if ((input < 48) || (input > 57)) { } else { - putchar(input); + cputc(input); number[character] = input; character++; } @@ -1232,7 +1225,6 @@ void port_stats(void) cputs("Firm: "); cputs(firm); cputs(", Hong Kong"); - show_damage(); gotoxy(21, 4); in_use = hkw_[0] + hkw_[1] + hkw_[2] + hkw_[3]; @@ -1736,6 +1728,7 @@ void quit(void) timed_getch(TMOUT_3S); result = sea_battle(GENERIC, num_ships); + gotoxy(0,23); /* to avoid disappearing U in "In use" */ } if (result == 2) @@ -1775,6 +1768,7 @@ void quit(void) timed_getch(TMOUT_3S); sea_battle(LI_YUEN, num_ships); + gotoxy(0,23); /* to avoid disappearing U in "In use" */ } } @@ -2211,13 +2205,14 @@ int port_choices(void) gotoxy(0, 22); clrtobot(); - cursor(1); + cursor(0); if (port == 1) { if ((cash + bank) >= 1000000) { cputs("Shall I Buy, Sell, Visit bank, Transfer\r\n"); - cputs("cargo, Quit trading, or Retire? "); + cputs("cargo, Quit trading, or Retire?"); + cursor(1); cputc(' '); choice = cgetc(); if ((choice == 'B') || (choice == 'b') || @@ -2231,7 +2226,8 @@ int port_choices(void) } } else { cputs("Shall I Buy, Sell, Visit bank, Transfer\r\n"); - cputs("cargo, or Quit trading? "); + cputs("cargo, or Quit trading?"); + cursor(1); cputc(' '); choice = cgetc(); if ((choice == 'B') || (choice == 'b') || @@ -2244,7 +2240,8 @@ int port_choices(void) } } } else { - cputs("Shall I Buy, Sell, or Quit trading? "); + cputs("Shall I Buy, Sell, or Quit trading?"); + cursor(1); cputc(' '); choice = cgetc(); if ((choice == 'B') || (choice == 'b') || @@ -2254,7 +2251,7 @@ int port_choices(void) break; } } - cursor(1); + cursor(0); } return choice; |