Skip to content

Commit 6643e90

Browse files
runer112jacobly0
authored andcommitted
Optimized _SetTextXY (#47)
In the process, I eliminated the unclipped version and the _SetTextConfig code that switched between it and the clipped version. The new clipped version is faster than the old unclipped version and should provide the same behavior given onscreen coordinates.
1 parent 4d5770c commit 6643e90

File tree

1 file changed

+8
-35
lines changed

1 file changed

+8
-35
lines changed

CEdev/lib/src/graphics/graphx/graphics_lib.asm

+8-35
Original file line numberDiff line numberDiff line change
@@ -2615,36 +2615,14 @@ _SetTextXY:
26152615
; arg1 : Text Y Pos
26162616
; Returns:
26172617
; None
2618-
jp _SetTextXY_ASM \.r
2619-
SetTextXY_SMC =$-3
2620-
_SetTextXY_ASM:
2621-
ld hl,3
2622-
add hl,sp ; hl -> arg0
2623-
ld de,TextXPos_SMC \.r
2624-
ldi
2625-
ldi ; copy in new x pos
2626-
inc hl
2627-
ld a,(hl)
2628-
ld (TextYPos_SMC),a \.r ; set new y pos
2629-
ret
2630-
2631-
;-------------------------------------------------------------------------------
2632-
_SetTextXY_Clip_ASM:
2633-
; Sets the text X and Y positions
2634-
; Arguments:
2635-
; arg0 : Text X Pos
2636-
; arg1 : Text Y Pos
2637-
; Returns:
2638-
; None
2639-
ld hl,3
2640-
add hl,sp ; hl -> arg0
2641-
ld de,TextXPos_SMC \.r
2642-
ldi
2643-
ldi
2644-
ldi ; copy in new x pos
2645-
ld hl,(hl)
2646-
ld (TextYPos_SMC),hl \.r ; set new y pos
2647-
ret
2618+
pop de ; de=return address, sp=&xpos
2619+
pop hl ; hl=xpos, sp=&ypos
2620+
ld (TextXPos_SMC),hl \.r
2621+
ex (sp),hl ; hl=ypos, ypos=don't care
2622+
ld (TextYPos_SMC),hl \.r
2623+
push hl ; xpos=don't care, sp=&xpos
2624+
ex de,hl ; hl=return address
2625+
jp (hl)
26482626
26492627
;-------------------------------------------------------------------------------
26502628
_PrintStringXY_Clip_ASM:
@@ -2780,12 +2758,10 @@ _SetTextConfig:
27802758
ret nz
27812759
ld de,_PrintChar_ASM \.r
27822760
ld bc,_PrintStringXY_ASM \.r
2783-
ld iy,_SetTextXY_ASM \.r
27842761
jr SetCharSMC ; set unclipped character routine
27852762
SetClipText:
27862763
ld de,_PrintChar_Clip_ASM \.r
27872764
ld bc,_PrintStringXY_Clip_ASM \.r
2788-
ld iy,_SetTextXY_Clip_ASM \.r
27892765
SetCharSMC:
27902766
ld hl,PrintChar_SMC_0 \.r
27912767
ld (hl),de ; holy crap what a hack
@@ -2798,9 +2774,6 @@ SetCharSMC:
27982774
push bc
27992775
pop hl
28002776
ld (PrintStringXY_SMC),hl \.r ; change which text routines we want to use
2801-
push iy
2802-
pop hl
2803-
ld (SetTextXY_SMC),hl \.r
28042777
or a,a
28052778
sbc hl,hl
28062779
ld (TextYPos_SMC),hl \.r

0 commit comments

Comments
 (0)