aboutsummaryrefslogtreecommitdiff
path: root/console.s
diff options
context:
space:
mode:
authorB. Watson <yalhcru@gmail.com>2016-02-22 14:56:05 -0500
committerB. Watson <yalhcru@gmail.com>2016-02-22 14:56:05 -0500
commitb4bc2d9b75c7ecf39f26b717b88384b8a5a9f578 (patch)
tree33e46b0cf084f28d72a1d4ead85236fb9c26fa89 /console.s
parent5449141832140561cd44a78057c53ac7abaf3c22 (diff)
downloadtaipan-b4bc2d9b75c7ecf39f26b717b88384b8a5a9f578.tar.gz
more code shrinkage, 7356 bytes free
Diffstat (limited to 'console.s')
-rw-r--r--console.s68
1 files changed, 66 insertions, 2 deletions
diff --git a/console.s b/console.s
index b02403d..7837ce1 100644
--- a/console.s
+++ b/console.s
@@ -1,7 +1,7 @@
.include "atari.inc"
- .export _clrtobot, _clrtoeol, _clr_screen, _clrtoline, _cspaces, _cblank, _backspace
+ .export _clrtobot, _clrtoeol, _clr_screen, _clrtoline, _cspaces, _cblank, _backspace, _cprint_pipe, _cprint_bang, _cspace, _cputc_s, _comma_space, _cprint_colon_space, _cprint_question_space, _cprint_period, _cprint_taipan_prompt
.export _rvs_on, _rvs_off
.import mul40 ; from cc65's runtime
@@ -9,7 +9,8 @@
.import _revflag ; conio/revers.s
.import bump_destptr ; these two are
.importzp destptr ; from draw_lorcha.s
- .import _cspace
+ .importzp sreg
+ .import _cprintulong, _cputc, _cprint_taipan
.ifdef CART_TARGET
.segment "HIGHCODE"
@@ -117,3 +118,66 @@ _rvs_off:
lda #0
sta _revflag
rts
+
+ ; micro-optimizations here.
+ ; the stuff below might be a bit hard to follow, but it saves code.
+ ; calling this: cputs("? ");
+ ; emits code like this:
+ ; lda #<Lxxx
+ ; ldx #>Lxxx
+ ; jsr _cputs
+ ; ...which is 9 bytes per call (plus 3 bytes for the "? " string itself).
+ ; replacing each cputs("? "); with cprint_question_space() means 3 bytes
+ ; per call (a JSR). there are 3 'some char followed by a space' routines
+ ; here, totalling 10 bytes. the actual space is printed by code shared
+ ; with cspace().
+ ; also, there are 5 'print a single character' routines. each one would
+ ; normally be cputc('X'), which compiles to:
+ ; lda #'X'
+ ; jsr _cputc
+ ; ...or 5 bytes each. we have 5 of them, so 25 bytes. using fall-thru
+ ; and the BIT trick, they condense down to 17 bytes.
+ ; if you're not familiar with the "BIT trick" to skip a 2-byte instruction,
+ ; the stuff below looks like gibberish, sorry.
+
+ ; ", Taipan? "
+ ; using fall-thru here saves 3 bytes (normally the last instruction
+ ; would be "jmp _cprint_question_space")
+_cprint_taipan_prompt:
+ jsr _comma_space
+ jsr _cprint_taipan
+ ; fall thru
+
+ ; each entry point here prints one character followed by a space
+ ; "? "
+_cprint_question_space:
+ lda #'?'
+ .byte $2c
+
+ ; ": "
+_cprint_colon_space:
+ lda #':'
+ .byte $2c
+
+ ; ", "
+_comma_space:
+ lda #','
+ jsr _cputc
+ ; fall thru
+
+ ; each entry point here prints one character
+_cspace:
+ lda #' '
+ .byte $2c
+_cprint_pipe:
+ lda #'|'
+ .byte $2c
+_cputc_s:
+ lda #'s'
+ .byte $2c
+_cprint_period:
+ lda #'.'
+ .byte $2c
+_cprint_bang:
+ lda #'!'
+ jmp _cputc