diff options
-rw-r--r-- | taipan.c | 240 | ||||
-rw-r--r-- | timed_getch.s | 2 |
2 files changed, 31 insertions, 211 deletions
@@ -3,20 +3,19 @@ #include <stdlib.h> // #include <stdio.h> // finally got rid of it! #include <ctype.h> -#include <string.h> +#include <string.h> /* only for memcpy() */ #include <peekpoke.h> #include "sounds.h" /* define this to use cc65's rand() instead of POKEY's RANDOM - register. Leave disabled for now as POKEY never returns 0 (it's an - LFSR, I should have known that would happen...) */ + register. No need to disable this now */ #define POKEY_RANDOM /* define this for testing sea_battle(). it causes a pirate attack every time you leave port. Don't leave defined for a release!! */ -// #define COMBAT_TEST +#define COMBAT_TEST /* define this to show internals of damage calculation */ // #define DAMAGE_TEST @@ -519,8 +518,17 @@ void fancy_numbers(unsigned long num, char *fancy) { } */ -void fight_stats(int ships, int orders) -{ +void update_guns() { + revers(1); + gotoxy(31, 1); + if(guns < 1000) cputc(' '); + if(guns < 100) cputc(' '); + if(guns < 10) cputc(' '); + cprintulong(guns); + revers(0); +} + +void fight_stats(int ships, int orders) { cursor(0); gotoxy(0, 0); @@ -533,26 +541,13 @@ void fight_stats(int ships, int orders) if(ships != 1) cputc('s'); cputs(" attacking, Taipan! \r\n"); - cputs("Your orders are to: "); + cputs("Your orders are to:"); if(orders == 1) cputs("Fight "); else if(orders == 2) cputs("Run "); else if(orders == 3) cputs("Throw Cargo"); - - revers(1); - gotoxy(30, 0); - cputs(" We have"); - gotoxy(30, 1); - cputc(' '); - if(guns < 1000) cputc(' '); - if(guns < 100) cputc(' '); - if(guns < 10) cputc(' '); - cprintulong(guns); - cputs(" guns"); - revers(0); - return; } /* print an inverse video plus if there are offscreen ships, @@ -594,6 +589,18 @@ int sea_battle(int id, int num_ships) { clrscr(); cursor(0); flushinp(); + +/* the static part of "we have N guns" display, gets printed + only once per battle. Bloats the code by 30-odd bytes, but + updates are smoother-looking. Maybe. */ + revers(1); + gotoxy(30, 0); + cputs(" We have"); + gotoxy(30, 1); + cputs(" guns"); + revers(0); + update_guns(); + fight_stats(num_ships, orders); while(num_ships > 0) { @@ -1026,6 +1033,7 @@ int sea_battle(int id, int num_ships) { cputs("The buggers hit a gun, Taipan!!"); under_attack_sound(); fight_stats(num_ships, orders); + update_guns(); timed_getch(TMOUT_3S); } @@ -1080,7 +1088,7 @@ int sea_battle(int id, int num_ships) { } if(orders == 1) { - clrscr(); + // clrscr(); fight_stats(num_ships, orders); gotoxy(0, 3); clrtoeol(); @@ -1094,117 +1102,7 @@ int sea_battle(int id, int num_ships) { } } -#if 0 -/* TODO: rewrite in asm - get_one() gets one character of input, but waits for Enter - to be pressed, and allows backspacing over it. - Honestly I don't see the value in using this instead of - cgetc(). Plenty of prompts in the game (e.g. Buy/Sell/Quit Trading), - and all the stuff in combat, just accept one character without - need to press Enter. - This is called from: - mchenry() (y or n) - cash_or_guns() (1 or 2) - final_stats() (play again, y or n) - li_yuen_extortion() (y or n, twice) - elder_brother_wu() (y or n, twice) - buy() (for picking item) - sell() (idem) - */ -int get_one(void) -{ - int input, - choice = 0, - character = 0; - - // 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) - - /* these 2 lines make the cursor visible */ - cursor(1); - cblank(1); - - while ((input = cgetc()) != '\n') - { - if (((input == BKSP) || (input == 127)) && (character == 0)) - { - } else if ((input == BKSP) || (input == 127)) { - backspace(); - character--; - } else if (character >= 1) { - } else if (input == '\33') { - flushinp(); - } else { - cputc(input); - choice = input; - character++; - } - } - cursor(0); - - return choice; -} - -/* new version. Still too much code! */ -int get_one(void) { - cursor(1); - cblank(1); - return agetc(); -} -#endif - /* TODO: rewrite in asm. Maybe. */ -#if 0 -unsigned long get_num(int maxlen) -{ - static char number[20]; - - int input, - character = 0; - - long amount; - - /* new: */ - cursor(1); - cblank(1); - - while ((input = cgetc()) != '\n') - { - if (((input == BKSP) || (input == 127)) && (character == 0)) - { - } else if ((input == BKSP) || (input == 127)) { - backspace(); - number[character] = '\0'; - character--; - } else if (character >= maxlen) { - } else if (input == '\33') { - flushinp(); - } else if (((input == 'A') || (input == 'a')) && - (character == 0) && (maxlen > 1)) { - cputc(input); - number[character] = input; - character++; - } else if ((input < 48) || (input > 57)) { - } else { - cputc(input); - number[character] = input; - character++; - } - } - - number[character] = '\0'; - if ((strcmp(number, "A") == 0) || (strcmp(number, "a") == 0)) - { - amount = -1; - } else { - amount = strtol(number, (char **)NULL, 10); - } - - cursor(0); - return amount; -} -#else long get_num(void) { static char number[20]; unsigned char count = 0; @@ -1230,7 +1128,6 @@ long get_num(void) { number[count] = '\0'; return strtol(number, (char **)NULL, 10); } -#endif /* TODO: rewrite in asm */ void cash_or_guns(void) @@ -2374,81 +2271,6 @@ void good_prices(void) timed_getch(TMOUT_3S); } -#if 0 -int port_choices(void) -{ - int choice = 0; - - compradores_report(); - cputs("Taipan, present prices per unit here are"); /* NB: exactly 40 cols */ - cputs(" Opium: Silk:\r\n"); - cputs(" Arms: General:\r\n"); - gotoxy(11, 19); - cprintulong(price[0]); - gotoxy(29, 19); - cprintulong(price[1]); - gotoxy(11, 20); - cprintulong(price[2]); - gotoxy(29, 20); - cprintulong(price[3]); - - for (;;) - { - gotoxy(0, 22); - clrtobot(); - - 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?"); - cursor(1); cputc(' '); - - choice = agetc(); - if ((choice == 'b') || - (choice == 's') || - (choice == 'v') || - (choice == 't') || - (choice == 'q') || - (choice == 'r')) - { - break; - } - } else { - cputs("Shall I Buy, Sell, Visit bank, Transfer\r\n"); - cputs("cargo, or Quit trading?"); - cursor(1); cputc(' '); - - choice = agetc(); - if ((choice == 'b') || - (choice == 's') || - (choice == 'v') || - (choice == 't') || - (choice == 'q')) - { - break; - } - } - } else { - cputs("Shall I Buy, Sell, or Quit trading?"); - cursor(1); cputc(' '); - - choice = agetc(); - if ((choice == 'b') || - (choice == 's') || - (choice == 'q')) - { - break; - } - } - cursor(0); - } - - return choice; -} -#else int port_choices(void) { int choice = 0; char retire_ok; @@ -2470,7 +2292,7 @@ int port_choices(void) { clrtobot(); cursor(0); - retire_ok = (port == 1 && ((cash + bank) >= 1000000)); + retire_ok = (port == 1 && ((cash + bank) >= 1000000L)); cputs("Shall I Buy, Sell, "); if(port ==1) { cputs("Visit bank, Transfer\r\ncargo, "); @@ -2495,8 +2317,6 @@ int port_choices(void) { cursor(0); return choice; } -#endif - /* TODO: rewrite in asm, or at least better C */ void name_firm(void) { diff --git a/timed_getch.s b/timed_getch.s index 25a2320..5dea09c 100644 --- a/timed_getch.s +++ b/timed_getch.s @@ -72,7 +72,7 @@ notcontrol: lda #$20 ok: pha - lda #1 + ldx #0 lda FR1+2 jsr _cursor pla |