CPCWiki forum

General Category => Programming => Topic started by: norecess464 on 15:38, 04 September 23

Title: Faster TXT_OUTPUT (BB5A) routine
Post by: norecess464 on 15:38, 04 September 23
Hi,

I have a program of mine that prints text in both MODE 1 and MODE 2, and relies on the TXT_OUTPUT (&BB5A) firmware routine.
Sometimes, the screen requires to scroll vertically, as in BASIC when too much information gets printed to screen, etc.

I tried to optimize TXT_OUTPUT a little bit while keeping 464/6128 compatibility, and reached an interesting 2.8 faster time execution.
Putting here my findings. Maybe a similar effort existed in the past, I did not check. That was quite fun to implement!
Warning, it also comes with few restrictions (no management of PEN 2/3, reverse character mode, etc).

Sharing is caring!
 :-*

The info as found at the beginning of the attach Fast_TXT_OUTPUT.asm file. Compiles with RASM.
; Originally written by norecess464 in 2023
; Compiles with RASM by roudoudou
;
; This routine is 2.8 times faster than the original TXT_OUTPUT
; Compatible with all the CPC firmware versions
;
; It entirely relies on firmware's cursor position routine,
; and supports well the screen hardware scrolling / window management routines.
;
; The main acceleration is provided by outputting the "go right" character code (9)
; with the original TXT_OUTPUT, so all the firmware handling, character positionning,
; screen scrolling etc. gets correctly handled
; But instead of relying on TXT_OUTPUT's print-to-screen routine, we directly
; copy the character bitmap from the LOWER ROM. MODE2 is a direct copy,
; while MODE 1 relies on a table (512 bytes) to make a quick conversion to MODE 1.
;
; Notes:
; - TXT_GET_CURSOR KL_L_ROM_ENABLE SCR_CHAR_POSITION SCR_GET_MODE.. are not what makes
;  this routine "slow", it doesn't worth to try optimizing to hell those ones.
;  Plus, it would be risky to break 464/6128 compatibility
;
; It comes with few restrictions:
; - no support PEN 2 and PEN 3
; - no support for MODE 0
; - no support for reverse character mode, etc.

Title: Re: Faster TXT_OUTPUT (BB5A) routine
Post by: McArti0 on 20:48, 04 September 23
Other insertion point is BDD3 but realy BB5A is called earlier in FW.
Title: Re: Faster TXT_OUTPUT (BB5A) routine
Post by: Prodatron on 11:41, 05 September 23
Thanks, @NoRecess!

seems, that you can even save additional 4 NOPs/char in the Mode 2 routine by replacing every 2nd

ld a, d
 add a, b
ld d, a

with SET 3,D

Title: Re: Faster TXT_OUTPUT (BB5A) routine
Post by: Prodatron on 11:59, 05 September 23
MODE2PIXEL

inc l
    set 3,d
; D=#C8
MODE2PIXEL

inc l
inc l
    set 4,d

; D=#D8
MODE2PIXEL

dec l
    res 3,d
; D=#D0
MODE2PIXEL

    set 2,l
    set 5,d
; D=#F0
MODE2PIXEL

inc l
    set 3,d
; D=#F8
MODE2PIXEL

    res 1,l
    res 4,d
; D=#E8
MODE2PIXEL

dec l
    res 3,d
; D=#E0
MODE2PIXEL

This should save another 2 NOPs, as you don't need
LD B,8
anymore.
(not tested)
Title: Re: Faster TXT_OUTPUT (BB5A) routine
Post by: Prodatron on 12:10, 05 September 23
Oh, and with the same method (using SET/RES for L as well) you can save 2 NOPs in the Mode1 routine, too :D
I know, nobody will recognize it, but it is always fun :)
Title: Re: Faster TXT_OUTPUT (BB5A) routine
Post by: norecess464 on 13:31, 05 September 23
Ahah yes, good catch, thank you! Updated source code attached.
Powered by SMFPacks Menu Editor Mod