Skip to content

Commit a4514ec

Browse files
committed
made small optimizations to multiple routines
1 parent 3e00e04 commit a4514ec

File tree

1 file changed

+34
-41
lines changed

1 file changed

+34
-41
lines changed

src/graphx/graphx.asm

Lines changed: 34 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2512,9 +2512,7 @@ gfx_GetClipRegion:
25122512
ld hl,3
25132513
add hl,sp
25142514
ld iy,(hl)
2515-
dec iy
2516-
dec iy
2517-
dec iy
2515+
lea iy, iy - 3
25182516
call _ClipRegion ; get the clipping region
25192517
sbc a,a ; return false if offscreen (0)
25202518
inc a
@@ -3221,20 +3219,7 @@ _Tilemap:
32213219
ld (ix-3),h
32223220
sbc hl,bc
32233221
ld (ix-12),hl
3224-
jp .yloop
3225-
3226-
.xres := $+3
3227-
.loop:
3228-
ld (ix-1),0
3229-
ld hl,0
3230-
.xoffset := $-3
3231-
ld (ix-7),hl
3232-
ld l,(iy+t_width)
3233-
ld h,(ix-4)
3234-
mlt hl
3235-
ld (.ynext),hl
3236-
xor a,a
3237-
jr .xloop
3222+
jr .yloop
32383223

32393224
.xloopinner:
32403225
or a,a
@@ -3290,7 +3275,20 @@ _Tilemap:
32903275
.yloop:
32913276
ld a,(iy+t_draw_height)
32923277
cp a,(ix-3)
3293-
jp nz,.loop
3278+
jr z,.finish_loop
3279+
.xres := $+3
3280+
; .loop:
3281+
ld (ix-1),0
3282+
ld hl,0
3283+
.xoffset := $-3
3284+
ld (ix-7),hl
3285+
ld l,(iy+t_width)
3286+
ld h,(ix-4)
3287+
mlt hl
3288+
ld (.ynext),hl
3289+
xor a,a
3290+
jr .xloop
3291+
.finish_loop:
32943292
ld sp,ix
32953293
pop ix
32963294
ret
@@ -3857,8 +3855,7 @@ gfx_GetStringWidth:
38573855
; Returns:
38583856
; Width of string in pixels
38593857
pop de
3860-
pop hl
3861-
push hl ; hl -> string
3858+
ex (sp), hl ; hl -> string
38623859
push de
38633860
ld de,0
38643861
.loop:
@@ -3882,10 +3879,11 @@ gfx_GetCharWidth:
38823879
; arg0 : Character
38833880
; Returns:
38843881
; Width of character in pixels
3885-
ld iy,0
3886-
lea de,iy
3887-
add iy,sp
3888-
ld a,(iy+3) ; a = character
3882+
ld hl, 3
3883+
add hl, sp
3884+
ld a, (hl) ; a = character
3885+
sbc hl, hl
3886+
ex de, hl
38893887
_GetCharWidth:
38903888
sbc hl,hl
38913889
ld l,a
@@ -3998,8 +3996,7 @@ gfx_SetFontData:
39983996
; Returns:
39993997
; Pointer to previous font data
40003998
pop de
4001-
pop hl
4002-
push hl ; hl -> custom font data
3999+
ex (sp), hl ; hl -> custom font data
40034000
push de
40044001
add hl,de
40054002
or a,a
@@ -4050,8 +4047,7 @@ gfx_SetFontSpacing:
40504047
; Returns:
40514048
; None
40524049
pop de
4053-
pop hl
4054-
push hl ; hl -> custom font width
4050+
ex (sp), hl ; hl -> custom font width
40554051
push de
40564052
add hl,de
40574053
or a,a
@@ -4072,10 +4068,9 @@ gfx_SetMonospaceFont:
40724068
pop hl
40734069
pop de
40744070
push de
4075-
push hl
40764071
ld a,e ; a = width
40774072
ld (_TextFixedWidth),a ; store the value of the monospace width
4078-
ret
4073+
jp (hl)
40794074

40804075
;-------------------------------------------------------------------------------
40814076
gfx_FillTriangle_NoClip:
@@ -4215,9 +4210,6 @@ _FillTriangle:
42154210
push de
42164211
call 0 ; horizline(a, y0, b-a+1);
42174212
.line0 := $-3
4218-
pop bc
4219-
pop bc
4220-
pop bc
42214213
ld sp,ix
42224214
pop ix
42234215
ret ; return;
@@ -4260,7 +4252,7 @@ _FillTriangle:
42604252
.sublast:
42614253
ld bc,(ix+9)
42624254
ld (ix-12),bc ; for (y = y0; y <= last; y++)
4263-
jp .firstloopstart
4255+
jr .firstloopstart
42644256
.firstloop:
42654257
ld hl,(ix-15)
42664258
ld bc,(ix-33)
@@ -4337,7 +4329,7 @@ _FillTriangle:
43374329
ld de,(ix-21)
43384330
call _MultiplyHLDE ; sb = dx02 * (y - y0);
43394331
ld (ix-18),hl
4340-
jp .secondloopstart ; for(; y <= y2; y++)
4332+
jr .secondloopstart ; for(; y <= y2; y++)
43414333
.secondloop:
43424334
ld hl,(ix-15)
43434335
ld bc,(ix-39)
@@ -4838,8 +4830,7 @@ gfx_ScaleSprite:
48384830
pop de ; de->tgt_data
48394831
ld iy,0
48404832
ld iyl,a
4841-
ld a,c ; du = bc:iyl
4842-
ld (du),a ; ixl = target_height
4833+
ld ixh,c ; (.du) = bc:iyl, ixl = target_height
48434834

48444835
; b = out_loop_times
48454836
; de = target buffer adress
@@ -4849,9 +4840,9 @@ ScaleWidth := $+2
48494840
ld iyh, 0
48504841
xor a,a
48514842
ld b,a
4852-
ld c,0
4853-
du := $-1
4854-
.loop: ldi
4843+
ld c,ixh ; (.du)
4844+
.loop:
4845+
ldi
48554846
add a,iyl
48564847
adc hl,bc ; xu += du
48574848
inc bc ; bc:iyl is du
@@ -6392,6 +6383,7 @@ _Maximum:
63926383
; Oututs:
63936384
; HL=max number
63946385
or a,a
6386+
.no_carry:
63956387
sbc hl,de
63966388
add hl,de
63976389
jp p,.skip
@@ -6410,6 +6402,7 @@ _Minimum:
64106402
; Oututs:
64116403
; HL=min number
64126404
or a,a
6405+
.no_carry:
64136406
sbc hl,de
64146407
ex de,hl
64156408
jp p,.skip
@@ -6447,7 +6440,7 @@ smcWord _XMax
64476440
smcWord _YMin
64486441
.YMin := $-3
64496442
ld de,(iy+6)
6450-
call _Maximum
6443+
call _Maximum.no_carry
64516444
ld (iy+6),hl
64526445
ld hl,ti.lcdHeight
64536446
smcWord _YMax

0 commit comments

Comments
 (0)