diff options
-rw-r--r-- | taipan.c | 165 | ||||
-rw-r--r-- | timed_getch.s | 22 |
2 files changed, 68 insertions, 119 deletions
@@ -49,15 +49,8 @@ #define ENTER 0x9b #define DEL 0x9c -/* timed_getch() args for seconds, based on jiffy clock of - target system. No adjustment made for PAL, sorry. */ -#define TMOUT_1S 60 -#define TMOUT_3S 180 -#define TMOUT_5S 300 -#define TMOUT_5M 18000 - -/* wait up to j jiffies for a keypress. returns -1 if no key pressed */ -extern int __fastcall__ timed_getch(unsigned int j); +/* wait up to 5 sec for a keypress. returns 0 if no key pressed */ +extern char __fastcall__ timed_getch(void); /* custom Atari-aware cgetc() wrapper. returns only non-inverse plain ASCII characters, except EOL and BS. Unlike the real cgetc(), @@ -454,7 +447,7 @@ void overload(void) { compradores_report(); cputs("Your ship is overloaded, Taipan!!"); good_joss_sound(); - timed_getch(TMOUT_5S); + timed_getch(); return; } @@ -713,7 +706,7 @@ void plus_or_space(unsigned char b) { } char set_orders(char orders) { - switch((char)timed_getch(TMOUT_3S)) { + switch((char)timed_getch()) { case 'f': return 1; case 'r': return 2; case 't': return 3; @@ -809,39 +802,16 @@ int sea_battle(int id, int num_ships) { gotoxy(0, 16); 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; - } - */ orders = set_orders(orders); - /* - if(input == 'f') { - orders = 1; - } else if(input == 'r') { - orders = 2; - } else if (input == 't') { - orders = 3; - } - */ if(orders == 0) { - // input = timed_getch(TMOUT_3S); - orders = set_orders(orders); if(!orders) { gotoxy(0, 3); clrtoeol(); cputs("Taipan, what shall we do??\r\n(Fight, Run, Throw cargo)"); under_attack_sound(); - // timeout(-1); while ((input != 'f') && (input != 'r') && (input != 't')) @@ -872,12 +842,12 @@ int sea_battle(int id, int num_ships) { gotoxy(0, 3); clrtoeol(); cputs("Aye, we'll fight 'em, Taipan."); - timed_getch(TMOUT_3S); + timed_getch(); gotoxy(0, 3); clrtoeol(); cputs("We're firing on 'em, Taipan!"); - timed_getch(TMOUT_1S); + timed_getch(); for(i = 1; i <= guns; i++) { if ((ships_on_screen[0] == 0) && (ships_on_screen[1] == 0) && @@ -949,7 +919,7 @@ int sea_battle(int id, int num_ships) { } else { cputs("Hit 'em, but didn't sink 'em, Taipan!"); } - timed_getch(TMOUT_3S); + timed_getch(); // if ((randi()%s0 > (num_ships * .6 / id)) && (num_ships > 2)) if((randi()%s0 > ((num_ships / 2) / id)) && (num_ships > 2)) { @@ -982,24 +952,13 @@ int sea_battle(int id, int num_ships) { gotoxy(0, 16); - // input = timed_getch(TMOUT_3S); - orders = set_orders(orders); - /* - if(input == 'f') { - orders = 1; - } else if(input == 'r') { - orders = 2; - } else if(input == 't') { - orders = 3; - } - */ } } else if ((orders == 1) && (guns == 0)) { gotoxy(0, 3); clrtoeol(); cputs("We have no guns, Taipan!!"); - timed_getch(TMOUT_3S); + timed_getch(); } else if (orders == 3) { choice = 0; amount = 0; @@ -1072,14 +1031,14 @@ int sea_battle(int id, int num_ships) { // gotoxy(0, 18); // clrtobot(); - timed_getch(TMOUT_3S); + timed_getch(); } else { gotoxy(0, 3); clrtoeol(); cputs("There's nothing there, Taipan!"); good_joss_sound(); - timed_getch(TMOUT_3S); + timed_getch(); } } @@ -1088,7 +1047,7 @@ int sea_battle(int id, int num_ships) { gotoxy(0, 3); clrtoeol(); cputs("Aye, we'll run, Taipan."); - timed_getch(TMOUT_3S); + timed_getch(); } ok += ik++; @@ -1098,13 +1057,13 @@ int sea_battle(int id, int num_ships) { clrtoeol(); cputs("We got away from 'em, Taipan!"); good_joss_sound(); - timed_getch(TMOUT_3S); + timed_getch(); num_ships = 0; } else { gotoxy(0, 3); clrtoeol(); cputs("Couldn't lose 'em."); - timed_getch(TMOUT_3S); + timed_getch(); if((num_ships > 2) && (randi()%5 == 0)) { static int lost; @@ -1133,18 +1092,7 @@ int sea_battle(int id, int num_ships) { gotoxy(0, 16); - // input = timed_getch(TMOUT_3S); - orders = set_orders(orders); - /* - if(input == 'f') { - orders = 1; - } else if(input == 'r') { - orders = 2; - } else if(input == 't') { - orders = 3; - } - */ } } } @@ -1154,8 +1102,7 @@ int sea_battle(int id, int num_ships) { clrtoeol(); cputs("They're firing on us, Taipan!"); - timed_getch(TMOUT_3S); - // flushinp(); + timed_getch(); /* screen flash doesn't change the hue bit of COLOR2 register, since we now support changing @@ -1187,7 +1134,7 @@ int sea_battle(int id, int num_ships) { cputs("We've been hit, Taipan!!"); under_attack_sound(); - timed_getch(TMOUT_3S); + timed_getch(); i = (num_ships > 15) ? 15 : num_ships; @@ -1209,7 +1156,7 @@ int sea_battle(int id, int num_ships) { fight_stats(num_ships, orders); update_guns(); - timed_getch(TMOUT_3S); + timed_getch(); } // damage = damage + ((ed * i * id) * ((float) randi() / RAND_MAX)) + (i / 2); @@ -1270,7 +1217,7 @@ int sea_battle(int id, int num_ships) { clrtoeol(); cputs("We got 'em all, Taipan!"); bad_joss_sound(); - timed_getch(TMOUT_3S); + timed_getch(); return 1; } else { @@ -1670,7 +1617,7 @@ void retire(void) { #endif retire_blanks(); revers(0); - timed_getch(TMOUT_5S); + timed_getch(); final_stats(); } @@ -1881,7 +1828,7 @@ void transfer(void) cputs("You have no cargo, Taipan.\r\n"); good_joss_sound(); - timed_getch(TMOUT_5S); + timed_getch(); return; } @@ -1921,7 +1868,7 @@ void transfer(void) cputs(", Taipan!"); good_joss_sound(); - timed_getch(TMOUT_5S); + timed_getch(); } } else { clear_msg_window(); @@ -1932,7 +1879,7 @@ void transfer(void) cputs(", Taipan.\r\n"); good_joss_sound(); - timed_getch(TMOUT_5S); + timed_getch(); } } port_stats(); @@ -1966,7 +1913,7 @@ void transfer(void) cprintulong(hkw_[i]); cputs(", Taipan.\r\n"); - timed_getch(TMOUT_5S); + timed_getch(); } } port_stats(); @@ -2002,7 +1949,7 @@ void quit(void) { cputs("\r\n\nYou're already here, Taipan."); good_joss_sound(); - timed_getch(TMOUT_5S); + timed_getch(); } else if ((choice >= 1) && (choice <= 7)) { port = choice; break; @@ -2030,7 +1977,7 @@ void quit(void) cputs(" approaching, Taipan!\r\n"); under_attack_sound(); - timed_getch(TMOUT_3S); + timed_getch(); result = sea_battle(GENERIC, num_ships); gotoxy(0,23); /* to avoid disappearing U in "In use" */ @@ -2044,7 +1991,7 @@ void quit(void) captains_report(); cputs("Li Yuen's fleet drove them off!"); - timed_getch(TMOUT_3S); + timed_getch(); } if (((result == 0) && (randi()%(4 + (8 * li))) == 0) || (result == 2)) @@ -2055,14 +2002,14 @@ void quit(void) cputs("Li Yuen's pirates, Taipan!!\r\n\n"); bad_joss_sound(); - timed_getch(TMOUT_3S); + timed_getch(); if (li > 0) { cputs("Good joss!! They let us be!!\r\n"); bad_joss_sound(); - timed_getch(TMOUT_3S); + timed_getch(); // return; // original code, results in prices not changing. result = 0; @@ -2074,7 +2021,7 @@ void quit(void) cputs(" ships of Li Yuen's pirate\r\n"); cputs("fleet, Taipan!!\r\n"); under_attack_sound(); - timed_getch(TMOUT_3S); + timed_getch(); /* WTF, the original code reads: sea_battle(LI_YUEN, num_ships); @@ -2109,13 +2056,13 @@ void quit(void) cputs("The buggers got us, Taipan!!!\r\n"); cputs("It's all over, now!!!"); - timed_getch(TMOUT_5S); + timed_getch(); final_stats(); return; } - timed_getch(TMOUT_3S); + timed_getch(); } if (randi()%10 == 0) @@ -2125,12 +2072,12 @@ void quit(void) // clrtobot(); cputs("Storm, Taipan!!\r\n\n"); bad_joss_sound(); - timed_getch(TMOUT_3S); + timed_getch(); if (randi()%30 == 0) { cputs(" I think we're going down!!\r\n\n"); - timed_getch(TMOUT_3S); + timed_getch(); // if (((damage / capacity * 3) * ((float) randi() / RAND_MAX)) >= 1) // in the float version, damage/capacity*3 is your damage percentage, @@ -2149,7 +2096,7 @@ void quit(void) if(sunk) { cputs("We're going down, Taipan!!\r\n"); under_attack_sound(); - timed_getch(TMOUT_5S); + timed_getch(); final_stats(); } @@ -2157,7 +2104,7 @@ void quit(void) cputs(" We made it!!\r\n\n"); bad_joss_sound(); - timed_getch(TMOUT_3S); + timed_getch(); if (randi()%3 == 0) { @@ -2173,7 +2120,7 @@ void quit(void) // clrtobot(); cputs("We've been blown off course\r\nto "); cputs(location[port]); - timed_getch(TMOUT_3S); + timed_getch(); } } @@ -2240,7 +2187,7 @@ void quit(void) cputs("Arriving at "); cputs(location[port]); cputs("..."); - timed_getch(TMOUT_3S); + timed_getch(); return; } @@ -2299,7 +2246,7 @@ void li_yuen_extortion(void) { // clrtobot(); cputs("Taipan, you do not have enough cash!!\r\n\r\n"); - timed_getch(TMOUT_3S); + timed_getch(); cputs("Do you want Elder Brother Wu to make up\r\n"); cputs("the difference for you? "); @@ -2325,7 +2272,7 @@ void li_yuen_extortion(void) { cputs("Li Yuen the difference. I would be very\r\n"); cputs("wary of pirates if I were you, Taipan.\r\n"); } - timed_getch(TMOUT_5S); + timed_getch(); } } @@ -2348,7 +2295,7 @@ void you_only_have(unsigned char in_bank) { cputs(".\r\n"); good_joss_sound(); - timed_getch(TMOUT_5S); + timed_getch(); } #else void you_only_have(unsigned char in_bank) { @@ -2363,7 +2310,7 @@ void you_only_have(unsigned char in_bank) { cputs(".\r\n"); good_joss_sound(); - timed_getch(TMOUT_5S); + timed_getch(); } #endif @@ -2423,7 +2370,7 @@ void elder_brother_wu(void) cputs("Very well, Taipan, the game is over!\r\n"); under_attack_sound(); - timed_getch(TMOUT_5S); + timed_getch(); final_stats(); } else if (choice == 'y') { @@ -2435,7 +2382,7 @@ void elder_brother_wu(void) cputs("Very well, Taipan. Good joss!!\r\n"); bad_joss_sound(); - timed_getch(TMOUT_5S); + timed_getch(); return; } @@ -2493,7 +2440,7 @@ void elder_brother_wu(void) } else { cputs("\r\n\r\nHe won't loan you so much, Taipan!"); good_joss_sound(); - timed_getch(TMOUT_5S); + timed_getch(); } } port_stats(); @@ -2521,7 +2468,7 @@ void elder_brother_wu(void) cputs("of all of your cash, Taipan!!\r\n"); under_attack_sound(); - timed_getch(TMOUT_5S); + timed_getch(); } return; @@ -2582,7 +2529,7 @@ void good_prices(void) cputs("!!\r\n"); good_joss_sound(); - timed_getch(TMOUT_3S); + timed_getch(); } int port_choices(void) { @@ -2860,7 +2807,7 @@ void too_much_cash(void) { cputs("\r\nYour ship would sink under the weight"); cputs("\r\nof your riches.\r\n"); bad_joss_sound(); - timed_getch(TMOUT_3S); + timed_getch(); } void visit_bank(void) @@ -3037,16 +2984,16 @@ int main(void) { compradores_report(); cputs("Taipan, you have been assassinated!"); under_attack_sound(); - timed_getch(TMOUT_3S); + timed_getch(); compradores_report(); cputs("As the masked figure plunges the blade\r\n"); cputs("into your heart, he says:\r\n"); - timed_getch(TMOUT_3S); + timed_getch(); compradores_report(); cputs("Elder Brother Wu regrets to inform you\r\n"); cputs("that your account has been terminated\r\n"); cputs("with extreme prejudice."); - timed_getch(TMOUT_3S); + timed_getch(); final_stats(); } @@ -3070,7 +3017,7 @@ int main(void) { cputs(" braves\r\n"); cputs("to escort you to the Wu mansion, Taipan.\r\n"); - timed_getch(TMOUT_3S); + timed_getch(); clear_msg_window(); // gotoxy(0, 18); @@ -3080,7 +3027,7 @@ int main(void) { cputs("and how this applies to paying one's\r\n"); cputs("debts.\r\n"); - timed_getch(TMOUT_3S); + timed_getch(); clear_msg_window(); // gotoxy(0, 18); @@ -3091,7 +3038,7 @@ int main(void) { cputs("He hopes no such fate awaits you, his\r\n"); cputs("friend, Taipan.\r\n"); - timed_getch(TMOUT_5S); + timed_getch(); wu_warn = 1; } @@ -3134,7 +3081,7 @@ int main(void) { cprintfancy(fine); cputs(", Taipan!\r\n"); - timed_getch(TMOUT_5S); + timed_getch(); } if ((randi()%50 == 0) && @@ -3155,7 +3102,7 @@ int main(void) { cputs("Messenger reports large theft\r\n"); cputs("from warehouse, Taipan.\r\n"); - timed_getch(TMOUT_5S); + timed_getch(); } if (randi()%20 == 0) @@ -3171,7 +3118,7 @@ int main(void) { cputs("Taipan. He says his admiral wishes\r\n"); cputs("to see you in Hong Kong, posthaste!\r\n"); bad_joss_sound(); - timed_getch(TMOUT_3S); + timed_getch(); } if (randi()%9 == 0) @@ -3198,7 +3145,7 @@ int main(void) { cputs(" in cash, Taipan!!\r\n"); under_attack_sound(); - timed_getch(TMOUT_5S); + timed_getch(); } for (;;) diff --git a/timed_getch.s b/timed_getch.s index 1c5b418..9a0f9a1 100644 --- a/timed_getch.s +++ b/timed_getch.s @@ -25,31 +25,33 @@ _set_jiffy_timer: ; called by jsleep() also. cli rts -; like curses timeout() followed by getch(): sleep until either -; a key is pressed or the timer expires. -; extern int __fastcall__ timed_getch(unsigned int jiffies); +; like curses timeout(5000) followed by getch(): sleep until either +; a key is pressed or the timer expires. returns 0 if no key pressed. +; extern char __fastcall__ timed_getch(void); _timed_getch: + lda #$2c ; $012c jiffies = 5 sec (NTSC) or 6 sec (PAL) + ldx #$01 jsr _set_jiffy_timer -wait4key: +@wait4key: lda CDTMV3 ; has timer counted down to 0? ora CDTMV3+1 - beq done ; yes, return(-1) + beq @done ; yes, return(0) lda CH ; no, check for a keypress ; ...but don't let the capslock or inverse keys count ; as a keypress, here. cmp #$ff ; no key pressed - beq wait4key + beq @wait4key and #$3f ; mask shift/control bits cmp #$3c ; caps-lock - beq wait4key + beq @wait4key cmp #$27 ; inverse (atari) key - beq wait4key + beq @wait4key jmp _agetc ; user hit a key, read it. -done: - lda #$ff ; return -1 +@done: + ;lda #$00 ; return(0), A is already 0 here tax rts |