Skip to content

Commit adcf4ff

Browse files
ZERICO2005mateoconlechuga
authored andcommitted
optimized DrawString/GetStringWidth entry points
1 parent bc12b16 commit adcf4ff

1 file changed

Lines changed: 23 additions & 28 deletions

File tree

src/fontlibc/fontlibc.asm

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -735,16 +735,10 @@ fontlib_DrawString:
735735
; Returns:
736736
; New X cursor value
737737
pop bc
738-
ld (.retter + 1),bc
739-
pop de
740-
scf
741-
sbc hl,hl
742-
push hl
743-
push de
744-
call fontlib_DrawStringL
745-
pop de
746-
.retter:
747-
jp 0
738+
ex (sp), hl
739+
push bc
740+
ld bc, -1
741+
jr _DrawStringL
748742

749743

750744
;-------------------------------------------------------------------------------
@@ -758,19 +752,23 @@ fontlib_DrawStringL:
758752
; arg1: Maximum number of characters have been printed
759753
; Returns:
760754
; New X cursor value
761-
push ix
755+
ld hl, arg1
756+
add hl, sp
757+
ld bc, (hl)
758+
dec hl
759+
dec hl
760+
dec hl
761+
ld hl, (hl)
762+
_DrawStringL:
762763
; Since reentrancy isn't likely to be needed. . . .
763764
; Instead of using stack locals, just access all our local and global
764765
; variables via the (IX + offset) addressing mode.
766+
push ix
765767
ld ix,DataBaseAddr
766768
res bWasNewline,(ix + newlineControl)
767-
ld iy,0
768-
add iy,sp
769-
ld hl,(iy + arg1)
769+
ld (ix + charactersLeft), bc
770770
dec hl ; We're reading the string with pre-increment,
771771
ld (ix + strReadPtr),hl ; so we need an initial pre-decrement
772-
ld hl,(iy + arg2)
773-
ld (ix + charactersLeft),hl
774772
.restartX:
775773
; Compute target drawing address
776774
ld hl,(_TextY)
@@ -1348,7 +1346,7 @@ fontlib_GetGlyphWidth:
13481346
xor a, a
13491347
ret
13501348

1351-
;;-------------------------------------------------------------------------------
1349+
;-------------------------------------------------------------------------------
13521350
fontlib_GetStringWidth:
13531351
; Returns the width of a string.
13541352
; Stops when it encounters any control code or a codepoint not in the current
@@ -1357,17 +1355,13 @@ fontlib_GetStringWidth:
13571355
; arg0: Pointer to string
13581356
; Returns:
13591357
; Width of string
1358+
pop hl
13601359
pop bc
1361-
ld (.retter + 1),bc
1362-
pop de
1360+
push bc
1361+
push hl
13631362
scf
13641363
sbc hl,hl
1365-
push hl
1366-
push de
1367-
call fontlib_GetStringWidthL
1368-
pop de
1369-
.retter:
1370-
jp 0
1364+
jr _GetStringWidthL
13711365

13721366

13731367
;-------------------------------------------------------------------------------
@@ -1382,15 +1376,16 @@ fontlib_GetStringWidthL:
13821376
; Width of string
13831377
ld hl,arg0
13841378
add hl,sp
1385-
push ix
1386-
ld ix,DataBaseAddr
13871379
ld bc,(hl)
13881380
inc hl
13891381
inc hl
13901382
inc hl
13911383
ld hl,(hl)
1392-
ld (ix + charactersLeft),hl
1384+
_GetStringWidthL:
1385+
push ix
1386+
ld ix, DataBaseAddr
13931387
ld iy,0
1388+
ld (ix + charactersLeft), hl
13941389
ld de,(ix + strucFont.widthsTablePtr)
13951390
ld a,(bc)
13961391
or a,a

0 commit comments

Comments
 (0)