diff options
| -rw-r--r-- | README.txt | 19 | ||||
| -rw-r--r-- | bigfloat.h | 10 | ||||
| -rw-r--r-- | bigfloat.s | 101 | ||||
| -rw-r--r-- | bignum.h | 4 | ||||
| -rw-r--r-- | taipan.c | 87 | ||||
| -rw-r--r-- | timed_getch.s | 2 | 
6 files changed, 84 insertions, 139 deletions
| @@ -43,6 +43,10 @@ Build Requirements:  - perl. I use version 5.18.1, probably any 5.x version will work. +- git. You don't exactly *need* this to build the code, but if you +  have it, the git hash will be built into the binary and appear on +  the title screen. +  - A UNIX/POSIX environment. At least, you need a 'cat' command and    a shell that does I/O redirection. Linux, BSD, and Mac OS X should    be fine. If you're on Windows, try Cygwin. @@ -116,13 +120,6 @@ arcade game).  BUGS! At least these: -- The BSS can overlap the start of the title screen (it's very close -  anyway). Consequences: There is a momentary graphics glitch when the -  main game is done loading and before it shows the "name your firm" -  screen. Also, we can't go back and display the title screen (but that's -  not something really necessary anyway). The fix: make the damn code -  smaller! Also, rearrange memory layout (see memory_layout.txt). -  - After a battle, the prices don't get reset (or, not always?) when    entering the new port (confirm?). @@ -155,11 +152,9 @@ BUGS! At least these:    I'm using the graphical title screen, I have a few more characters I    can redefine as damaged ship sections. -- One of my playtesters reported that, when running away from combat, it -  said 4 billion ships were attacking (number of ships must have gone -  negative). I was never able to reproduce this.... but another playtester -  reported that (in a later version), the number of enemy ships suddenly -  jumped to 6000+ during a fight, so there's something hinky there. +- Fixed, I think: One of my playtesters reported that, when running away +  from combat, it said 4 billion ships were attacking (number of ships +  must have gone negative).  - After a fight, "Arriving at Manila" or such will sometimes appear on the    fight screen without clearing it first (ships still visible). @@ -15,16 +15,16 @@  /* bignum 100, used for score calculations in final_stats() */  #define BIG_100 { 0x41, 0x01, 0x00, 0x00, 0x00, 0x00 } -/* one thousand, one million, one hundred million */ +/* one thousand, one million, one billion, one trillion +   used by cprintfancy_big() */  #define BIG_1K   { 0x41, 0x10, 0x00, 0x00, 0x00, 0x00 }  #define BIG_1M   { 0x43, 0x01, 0x00, 0x00, 0x00, 0x00 } -#define BIG_100M { 0x44, 0x01, 0x00, 0x00, 0x00, 0x00 } - -/* 10 million, one billion, one trillion */ -#define BIG_10M  { 0x43, 0x10, 0x00, 0x00, 0x00, 0x00 }  #define BIG_1B   { 0x44, 0x10, 0x00, 0x00, 0x00, 0x00 }  #define BIG_1T   { 0x46, 0x01, 0x00, 0x00, 0x00, 0x00 }  /* max value for a ulong, 2**32-1 */  #define BIG_MAX_ULONG { 0x44, 0x42, 0x94, 0x96, 0x72, 0x95 } +/* unused. */ +// #define BIG_100M { 0x44, 0x01, 0x00, 0x00, 0x00, 0x00 } +// #define BIG_10M  { 0x43, 0x10, 0x00, 0x00, 0x00, 0x00 } @@ -1,21 +1,23 @@ - .importzp ptr3, ptr4, sreg + .importzp ptr3, sreg   .import popeax, popax, pushax, _memcmp   .export _ulong_to_big, _big_to_ulong, _big_add, _big_sub, _big_mul, _big_div   .export _bank_maxed_out, _big_cmp, _big_copy, _big_negate   .include "atari.inc" -;IFP = $d9aa -   fptemp = $a0 ; for now   trampoline = $c0 + ; cc65's atari.inc is missing this FP entry point:   NORMALIZE = $dc00 + ; atari.inc also has a typo, PLD1P for FLD1P + FLD1P = PLD1P +   .rodata -BIG_64K: +BIG_64K: ; 65535 (2**16-1) in float format.   .byte $42, $06, $55, $36, $00, $00  ;BIG_ULONG_MAX: @@ -23,7 +25,18 @@ BIG_64K:   .code -; TODO: replace these *_to_* with OS calls +; It seems like fr0_to_fptemp and friends should be using the OS +; FLD* and FST* routines, doesn't it? But look: + +;fr0_to_fptemp: +; lda #<fptemp +; sta FLPTR +; lda #>fptemp +; sta FLPTR+1 +; jmp FST0P + +; ...that's 11 bytes of code. The fr0_to_fptemp saves 1 byte of code, +; plus it runs faster (doesn't use FLPTR, no JMP).  fr0_to_fptemp:   ldx #5 @@ -52,36 +65,35 @@ fptemp_to_fr1:   bpl @l   rts -fr0_to_ptr3: - ldy #5 -@l: - lda FR0,y - sta (ptr3),y - dey - bpl @l - rts - -ptr4_to_fr1: - ldy #5 -@l: - lda (ptr4),y - sta FR1,y - dey - bpl @l - rts +;fr0_to_ptr3: +; ldy #5 +;@l: +; lda FR0,y +; sta (ptr3),y +; dey +; bpl @l +; rts + +;ptr4_to_fr1: +; ldy #5 +;@l: +; lda (ptr4),y +; sta FR1,y +; dey +; bpl @l +; rts  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -; void __fastcall__ big_negate(bignump dest, bignump src); +; void __fastcall__ big_negate(bignump b); +; This doesn't call the ROM or use FR0/FR1, it just inverts the sign +; bit in-place.  _big_negate:   sta ptr3   stx ptr3+1 - jsr popax - sta ptr4 - stx ptr4+1   ldy #0   lda (ptr3),y   eor #$80 - sta (ptr4),y + sta (ptr3),y   rts  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -134,7 +146,7 @@ _big_binary_op:   jsr popax   sta FLPTR   stx FLPTR+1 - jsr PLD1P + jsr FLD1P   ; get 1st operand (a), load into FR0   jsr popax @@ -194,6 +206,9 @@ _big_div:  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  ; void __fastcall__ ulong_to_big(const unsigned long l, bignum *b); +; This works by splitting the 32-bit l into two 16-bit ints and +; converting them separately using the OS, then multiplying the high +; result by 2^16 and adding the low result.  _ulong_to_big:   sta ptr3   stx ptr3+1 ; save b (destination) @@ -211,16 +226,32 @@ _ulong_to_big:   stx FR0+1   jsr IFP    ; convert to fp - lda #<BIG_64K  ; high value needs to be multiplied by 65536 - sta ptr4 + ; high value needs to be multiplied by 65536 + + lda #<BIG_64K + sta FLPTR   lda #>BIG_64K - sta ptr4+1 - jsr ptr4_to_fr1 + sta FLPTR+1 + jsr FLD1P - jsr FMUL       ; multiply... + ; old version: +; lda #<BIG_64K +; sta ptr4 +; lda #>BIG_64K +; sta ptr4+1 +; jsr ptr4_to_fr1 + + jsr FMUL          ; multiply...   jsr fptemp_to_fr1 ; grab low value   jsr FADD          ; add to total - jmp fr0_to_ptr3   ; store it in b and we're done. + + ; store it in b and we're done. + ;jmp fr0_to_ptr3 ; used to do this, use OS instead: + lda ptr3 + sta FLPTR + lda ptr3+1 + sta FLPTR+1 + jmp FST0P  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  ; char __fastcall__ big_to_ulong(bignump b, unsigned long *l); @@ -235,7 +266,7 @@ _big_to_ulong:   sta sreg   stx FLPTR+1   stx sreg+1 - jsr FLD0P ; there's a typo in atari.inc, should be FLD1P + jsr FLD0P   ldx #<BIG_64K ; FR1 = 65536   ldy #>BIG_64K @@ -79,8 +79,8 @@ extern char __cdecl__ big_sub(bignump dest, bignump minuend, bignump subtrahend)  extern char __cdecl__ big_mul(bignump dest, bignump multiplicand, bignump multiplier);  extern char __cdecl__ big_div(bignump dest, bignump dividend, bignump divisor); -/* negation: dest = src * -1, or dest = -src if you prefer. */ -extern void __fastcall__ big_negate(bignump dest, bignump src); +/* negation: b = -b, or b *= -1 */ +extern void __fastcall__ big_negate(bignump b);  /* returns true if the bank is maxed out. We do this by checking the exponent  	byte, so the "max" is tied to the bignum implementation, which is why its @@ -313,8 +313,6 @@ bignum(big1B) = BIG_1B;  bignum(big1M) = BIG_1M;  bignum(big1K) = BIG_1K;  bignum(big0) = BIG_0; -// bignum(big100M) = BIG_100M; -// bignum(big10M) = BIG_10M;  /* what we should have:  	For Million/Billion, 3 significant digits. @@ -337,7 +335,7 @@ void cprintfancy_big(bignump b) {  	if(big_cmp(tmp, big0) < 0) {  		cputc('-'); -		big_negate(tmp, tmp); +		big_negate(tmp);  	}  	if(big_cmp(tmp, big1T) >= 0) { @@ -382,66 +380,7 @@ void cprintfancy_big(bignump b) {  		cputc(letter);  		cputs("illion");  	} - -	// cputs("\r\n"); // TODO: see if this can go away  } - -/* -Requires a bit of explanation. b's value will always be zero or -positive, and can range up to 1.0e+14 (aka 100 trillion). - -magnitude values: -0 - result is used as-is (result range 0 - 999999) -    b range 0 - 999999 -1 - result is in 100000's, print result/10 Million (range 0-9999) -    b range 1,000,000 - 999,999,999 (999 Million) -2 - result is in 100 millions, print result/10 Billion (range 0-9999) -    b range 1,000,000,000 (1 Billion) - 999,999,999,999 (1 trillion - 1) - -The calling code decides whether or not to print a decimal point -and 10ths digit (using integer math only). -*/ - -#if 0 -unsigned long cformat_big(char *magnitude, bignump b) { -	bignum(tmp); -	unsigned long ret; -	if(big_cmp(b, big1M) < 0) { -		*magnitude = 0; -		big_to_ulong(b, &ret); -	} else if(big_cmp(b, big1B) < 0) { -		*magnitude = 1; -		big_to_ulong(b, &ret); -		ret /= 100000L; -	} else { -		*magnitude = 2; -		big_div(tmp, b, big100M); -		big_to_ulong(tmp, &ret); -	} -	return ret; -} - -void cprintfancy_big(bignump b) { -	char m; -	unsigned long l = cformat_big(&m, b); -	if(!m) { -		// cprintf("%lu", l); -		cprintulong(l); -	} else { -		if(l > 100) { -			cprintulong(l / 10L); -		} else { -			cprintulong(l / 10L); -			cputc('.'); -			cprintulong(l % 10L); -		} -		cputc(' '); -		cputc(m == 1 ? 'M' : 'B'); -		cputs("illion"); -	} -	cputs("\r\n"); -} -#endif  #endif  int get_time(void) { @@ -937,33 +876,13 @@ int sea_battle(int id, int num_ships) {  					targeted = randi()%10;  				} while(ships_on_screen[targeted] == 0); -				/* -            targeted = randi()%10; -            while(ships_on_screen[targeted] == 0) { -               targeted = randi()%10; -            } -				*/ -  				/* flash_lorcha must be called an even number of times  					to leave the lorcha in an unflashed state after. */  				for(flashctr = 0; flashctr < 6; flashctr++) {  					flash_lorcha(targeted);  					jsleep(2);  				} -				/* -				flash_lorcha(targeted); -				jsleep(2); -				flash_lorcha(targeted); -				jsleep(2); -				flash_lorcha(targeted); -				jsleep(2); -				flash_lorcha(targeted); -				jsleep(2); -				flash_lorcha(targeted); -				jsleep(2); -				flash_lorcha(targeted); -				jsleep(2); -				*/ +  				damage_lorcha(targeted);              ships_on_screen[targeted] -= randi()%30 + 10; @@ -2989,7 +2908,7 @@ void bignum_test(void) {  	for(i = 0; i < 14; i++) {  		cprintfancy_big(n);  		cputc(' '); -		big_negate(n, n); +		big_negate(n);  		cprintfancy_big(n);  		cputs("\r\n");  		big_mul(n, n, o); diff --git a/timed_getch.s b/timed_getch.s index 5dea09c..f52f50c 100644 --- a/timed_getch.s +++ b/timed_getch.s @@ -67,7 +67,7 @@ notnull:  notcontrol:   cmp #$7c ; | (pipe, vertical bar) allowed as-is.   beq ok - cmp #$7a ; rest of range $7b - $7f is unmappable. + cmp #$7b ; rest of range $7b - $7f is unmappable.   bcc ok   ; (remember, $7e, backspace, was handled above)   lda #$20  ok: | 
