aboutsummaryrefslogtreecommitdiff
path: root/taipan.c
diff options
context:
space:
mode:
Diffstat (limited to 'taipan.c')
-rw-r--r--taipan.c65
1 files changed, 48 insertions, 17 deletions
diff --git a/taipan.c b/taipan.c
index a30eb93..1ba5751 100644
--- a/taipan.c
+++ b/taipan.c
@@ -165,15 +165,23 @@ void backspace() {
if allow_all is true, allows '*', which is used for
'throw cargo' in sea_battle. */
unsigned char get_item(unsigned char allow_all) {
- unsigned char i;
+ // unsigned char i;
+
for(;;) {
+ /* using a switch makes the code 12 bytes smaller here
i = lcgetc();
- switch(i) {
+ if(i == 'o') return 0;
+ if(i == 's') return 1;
+ if(i == 'a') return 2;
+ if(i == 'g') return 3;
+ if(allow_all && i == '*') return 4;
+ */
+ switch(lcgetc()) {
case 'o': return 0;
case 's': return 1;
case 'a': return 2;
case 'g': return 3;
- case '*': if(allow_all) return 4; /* else fall thru */
+ case '*': if(allow_all) return 4; // else fall thru
default: break;
}
}
@@ -292,9 +300,15 @@ void at_sea() {
revers(1);
cputs(location[0]);
revers(0);
+
+ /* this is 24 bytes smaller: */
+ cputs(" ");
+
+ /* than this:
cputc(' ');
cputc(' ');
cputc(' ');
+ */
}
/* this bit of code was duplicated a *bunch* of times,
@@ -465,9 +479,12 @@ void cprintfancy_ctr(unsigned long num, unsigned char center) {
mil = 0;
if(center) {
+ cputs(" ");
+ /*
cputc(' ');
cputc(' ');
cputc(' ');
+ */
tmp = 0;
for(tmp = 100L; tmp < 1000000L; tmp *= 100L)
if(num < tmp) cputc(' ');
@@ -521,17 +538,22 @@ void fancy_numbers(unsigned long num, char *fancy) {
}
*/
+void justify_int(unsigned int num) {
+ if(num < 1000) cputc(' ');
+ if(num < 100) cputc(' ');
+ if(num < 10) cputc(' ');
+ cprintulong(num);
+}
+
void hide_cursor() {
- gotoxy(0,23); cputc(' ');
+ gotoxy(0,23);
+ cputc(' ');
}
void update_guns() {
revers(1);
gotoxy(31, 1);
- if(guns < 1000) cputc(' ');
- if(guns < 100) cputc(' ');
- if(guns < 10) cputc(' ');
- cprintulong(guns);
+ justify_int(guns);
revers(0);
hide_cursor();
}
@@ -540,11 +562,7 @@ void fight_stats(int ships, int orders) {
cursor(0);
gotoxy(0, 0);
- if(ships < 1000) cputc(' ');
- if(ships < 100) cputc(' ');
- if(ships < 10) cputc(' ');
- cprintulong(ships);
-
+ justify_int(ships);
cputs(" ship");
if(ships != 1) cputc('s');
cputs(" attacking, Taipan! \r\n");
@@ -651,6 +669,16 @@ int sea_battle(int id, int num_ships) {
cputs("\r\n");
input = timed_getch(TMOUT_3S);
+ /* using a switch() instead of a chain of if/else
+ actually increases code size by 16 bytes!
+ switch(orders) {
+ case 'f': orders == 1;
+ case 'r': orders == 2;
+ case 't': orders == 3;
+ default: break;
+ }
+ */
+
if(input == 'f') {
orders = 1;
} else if(input == 'r') {
@@ -734,8 +762,7 @@ int sea_battle(int id, int num_ships) {
plus_or_space(num_ships > num_on_screen);
gotoxy(0, 16);
- cputc('\r');
- cputc('\n');
+ cputs("\r\n");
targeted = randi()%10;
while(ships_on_screen[targeted] == 0) {
@@ -1116,7 +1143,7 @@ int sea_battle(int id, int num_ships) {
long get_num(void) {
static char number[20];
unsigned char count = 0;
- int input;
+ char input;
cursor(1);
cblank(1);
@@ -1609,7 +1636,11 @@ void final_stats(void)
// __asm__("jmp $e477");
/* exit(0) works in DOS 2.0s and 2.5, known to fail in Sparta */
- exit(0);
+ // exit(0);
+
+ /* let's try doing it this way. I suspect it will have the same
+ results as exit(0)... */
+ __asm__("jmp (10)"); // aka DOSVEC
}
void transfer(void)