From b4bc2d9b75c7ecf39f26b717b88384b8a5a9f578 Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Mon, 22 Feb 2016 14:56:05 -0500 Subject: more code shrinkage, 7356 bytes free --- console.s | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 66 insertions(+), 2 deletions(-) (limited to 'console.s') 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 + ; 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 -- cgit v1.2.3