From 3ccfe725cfd1672e04dcf5caa555ceaaf3f27159 Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Thu, 4 Feb 2016 17:33:17 -0500 Subject: rewrite cspace() in asm, save a few more bytes --- Makefile | 4 ++-- clrtobot.s | 66 ------------------------------------------------------ console.s | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ taipan.c | 18 ++++++++------- 4 files changed, 87 insertions(+), 76 deletions(-) delete mode 100644 clrtobot.s create mode 100644 console.s diff --git a/Makefile b/Makefile index dc8a21a..90a45ac 100644 --- a/Makefile +++ b/Makefile @@ -89,7 +89,7 @@ XEX=taipan.xex # All the C and asm sources for taimain.xex: TAIMAIN_HDRS=sounds.h TAIMAIN_C_SRC=taipan.c -TAIMAIN_ASM_SRC=rand.s draw_lorcha.s timed_getch.s portstat.s clrtobot.s ultostr.s soundasm.s explosion.s +TAIMAIN_ASM_SRC=rand.s draw_lorcha.s timed_getch.s portstat.s console.s ultostr.s soundasm.s explosion.s # Comment these lines out to build without big number support. # This will stop being possible at some point. @@ -179,7 +179,7 @@ help.dat: help.txt text2screen.pl taimain.xex: $(TAIMAIN_C_SRC) $(TAIMAIN_ASM_SRC) $(TAIMAIN_HDRS) $(BIGNUM_SRC) $(BIGNUM_HDRS) cl65 -m taipan.map $(CFLAGS) $(BIGNUM_CFLAGS) -o taimain.xex $(TAIMAIN_C_SRC) $(TAIMAIN_ASM_SRC) $(BIGNUM_SRC) -#cl65 --mapfile taipan.map $(CFLAGS) -o taimain.xex taipan.c sounds.c rand.s draw_lorcha.s timed_getch.s jsleep.s portstat.s clrtobot.s +#cl65 --mapfile taipan.map $(CFLAGS) -o taimain.xex taipan.c sounds.c rand.s draw_lorcha.s timed_getch.s jsleep.s portstat.s console.s # With newer cc65s, I have to do this to get an assembly listing of just # taipan.c. This rule not used as part of the main build, it's only for diff --git a/clrtobot.s b/clrtobot.s deleted file mode 100644 index 72f97e5..0000000 --- a/clrtobot.s +++ /dev/null @@ -1,66 +0,0 @@ - - - .include "atari.inc" - .export _clrtobot, _clrtoeol, _clrtoline - - .import mul40 ; from cc65's runtime - .importzp tmp3 ; ditto - .import bump_destptr ; these two are - .importzp destptr ; from draw_lorcha.s - -; void clrtobot(void); -; void clrtoeol(void); -; void clrtoline(unsigned char line); - -; this stuff doesn't disturb conio's (and the OS's) idea of the -; current cursor position. It's *way* faster than writing them in -; C in terms of cclear() (which uses one cputc() call per blank). - -_clrtobot: ; same as clrtoline(24); - lda #24 - bne _clrtoline - -_clrtoeol: - lda ROWCRS - ; fall through to _clrtoline - -_clrtoline: - sta tmp3 ; stash our arg - lda #0 - sta OLDCHR ; stop conio from redrawing stuff after we clear it - - ; setup destptr to start of current line, NOT - ; current cursor position. - lda ROWCRS - jsr mul40 ; AX = A*40 (addr of start-of-row) - clc - adc SAVMSC ; add to screen pointer - sta destptr - txa - adc SAVMSC+1 - sta destptr+1 - - ; X = current row, Y = current column. Stop clearing a line when Y == 40, - ; we're done when X == 24. Apologies, the names X and Y are backwards - ; compared to proper Cartesian coordinates. - ldx ROWCRS - ldy COLCRS - lda #0 - -clrloop: - sta (destptr),y ; blank a character (A == 0, screen code for a space) - iny - cpy #40 - bne clrloop - ldy #0 - inx - cpx tmp3 - bcs done - - jsr bump_destptr - lda #0 - tay - beq clrloop - -done: - rts diff --git a/console.s b/console.s new file mode 100644 index 0000000..2bbdb04 --- /dev/null +++ b/console.s @@ -0,0 +1,75 @@ + + + .include "atari.inc" + .export _clrtobot, _clrtoeol, _clrtoline, _cspaces + + .import mul40 ; from cc65's runtime + .importzp tmp3 ; ditto + .import bump_destptr ; these two are + .importzp destptr ; from draw_lorcha.s + .import _cspace + +; void clrtobot(void); +; void clrtoeol(void); +; void clrtoline(unsigned char line); + +; this stuff doesn't disturb conio's (and the OS's) idea of the +; current cursor position. It's *way* faster than writing them in +; C in terms of cclear() (which uses one cputc() call per blank). + +_clrtobot: ; same as clrtoline(24); + lda #24 + bne _clrtoline + +_clrtoeol: + lda ROWCRS + ; fall through to _clrtoline + +_clrtoline: + sta tmp3 ; stash our arg + lda #0 + sta OLDCHR ; stop conio from redrawing stuff after we clear it + + ; setup destptr to start of current line, NOT + ; current cursor position. + lda ROWCRS + jsr mul40 ; AX = A*40 (addr of start-of-row) + clc + adc SAVMSC ; add to screen pointer + sta destptr + txa + adc SAVMSC+1 + sta destptr+1 + + ; X = current row, Y = current column. Stop clearing a line when Y == 40, + ; we're done when X == 24. Apologies, the names X and Y are backwards + ; compared to proper Cartesian coordinates. + ldx ROWCRS + ldy COLCRS + lda #0 + +clrloop: + sta (destptr),y ; blank a character (A == 0, screen code for a space) + iny + cpy #40 + bne clrloop + ldy #0 + inx + cpx tmp3 + bcs done + + jsr bump_destptr + lda #0 + tay + beq clrloop + +done: + rts + +_cspaces: + sta tmp3 +@lp: + jsr _cspace + dec tmp3 + bne @lp + rts diff --git a/taipan.c b/taipan.c index 6ff242f..039db7e 100644 --- a/taipan.c +++ b/taipan.c @@ -104,10 +104,12 @@ extern const char *port_stat_screen; port_stat_screen into screen RAM) */ char port_stat_dirty = 1; -/* asm curses/conio funcs from clrtobot.s. Old C versions moved to +/* asm curses/conio funcs from console.s. Old C versions moved to oldcurses.c for reference. */ extern void clrtobot(void); extern void clrtoeol(void); +/* print 'count' spaces: */ +extern void __fastcall__ cspaces(unsigned char count); /* asm funcs from draw_lorcha.s for drawing/animating enemy ships. used by sea_battle() */ @@ -155,9 +157,9 @@ void cspace(void) { cputc(' '); } -/* print 'count' spaces */ -void cspaces(unsigned char count) { - while(count--) cspace(); +/* print the letter s (for pluralization) */ +void cputc_s(void) { + cputc('s'); } /* print 'count' spaces, but leave the cursor where it was. @@ -699,7 +701,7 @@ void fight_stats(int ships, int orders) { justify_int(ships); cputs(" ship"); - if(ships != 1) cputc('s'); + if(ships != 1) cputc_s(); // cputs(" attacking, Taipan! \r\n"); cputs(" attacking"); cprint_taipan_bang(); @@ -1726,14 +1728,14 @@ void final_stats(void) cputs(" year"); if (years != 1) { - cputc('s'); + cputc_s(); } cputs(" and "); cprintulong(month); cputs(" month"); if (month > 1) { - cputc('s'); + cputc_s(); } cputs("\r\n\n"); revers(1); @@ -2054,7 +2056,7 @@ void quit(void) } cprintulong(num_ships); cputs(" hostile ship"); - if(num_ships != 1) cputc('s'); + if(num_ships != 1) cputc_s(); // cputs(" approaching, Taipan!\r\n"); cputs(" approaching"); cprint_taipan_bang(); -- cgit v1.2.3