Skip to content

Commit 8bc5bb7

Browse files
committed
made small optimizations to multiple routines
1 parent 8ca2ac3 commit 8bc5bb7

File tree

1 file changed

+33
-39
lines changed

1 file changed

+33
-39
lines changed

src/graphx/graphx.asm

Lines changed: 33 additions & 39 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
@@ -3882,10 +3880,11 @@ gfx_GetCharWidth:
38823880
; arg0 : Character
38833881
; Returns:
38843882
; Width of character in pixels
3885-
ld iy,0
3886-
lea de,iy
3887-
add iy,sp
3888-
ld a,(iy+3) ; a = character
3883+
ld hl, 3
3884+
add hl, sp
3885+
ld a, (hl) ; a = character
3886+
sbc hl, hl
3887+
ex de, hl
38893888
_GetCharWidth:
38903889
sbc hl,hl
38913890
ld l,a
@@ -3998,8 +3997,7 @@ gfx_SetFontData:
39983997
; Returns:
39993998
; Pointer to previous font data
40003999
pop de
4001-
pop hl
4002-
push hl ; hl -> custom font data
4000+
ex (sp), hl ; hl -> custom font data
40034001
push de
40044002
add hl,de
40054003
or a,a
@@ -4050,8 +4048,7 @@ gfx_SetFontSpacing:
40504048
; Returns:
40514049
; None
40524050
pop de
4053-
pop hl
4054-
push hl ; hl -> custom font width
4051+
ex (sp), hl ; hl -> custom font width
40554052
push de
40564053
add hl,de
40574054
or a,a
@@ -4072,10 +4069,9 @@ gfx_SetMonospaceFont:
40724069
pop hl
40734070
pop de
40744071
push de
4075-
push hl
40764072
ld a,e ; a = width
40774073
ld (_TextFixedWidth),a ; store the value of the monospace width
4078-
ret
4074+
jp (hl)
40794075

40804076
;-------------------------------------------------------------------------------
40814077
gfx_FillTriangle_NoClip:
@@ -4215,9 +4211,6 @@ _FillTriangle:
42154211
push de
42164212
call 0 ; horizline(a, y0, b-a+1);
42174213
.line0 := $-3
4218-
pop bc
4219-
pop bc
4220-
pop bc
42214214
ld sp,ix
42224215
pop ix
42234216
ret ; return;
@@ -4260,7 +4253,7 @@ _FillTriangle:
42604253
.sublast:
42614254
ld bc,(ix+9)
42624255
ld (ix-12),bc ; for (y = y0; y <= last; y++)
4263-
jp .firstloopstart
4256+
jr .firstloopstart
42644257
.firstloop:
42654258
ld hl,(ix-15)
42664259
ld bc,(ix-33)
@@ -4337,7 +4330,7 @@ _FillTriangle:
43374330
ld de,(ix-21)
43384331
call _MultiplyHLDE ; sb = dx02 * (y - y0);
43394332
ld (ix-18),hl
4340-
jp .secondloopstart ; for(; y <= y2; y++)
4333+
jr .secondloopstart ; for(; y <= y2; y++)
43414334
.secondloop:
43424335
ld hl,(ix-15)
43434336
ld bc,(ix-39)
@@ -4838,8 +4831,7 @@ gfx_ScaleSprite:
48384831
pop de ; de->tgt_data
48394832
ld iy,0
48404833
ld iyl,a
4841-
ld a,c ; du = bc:iyl
4842-
ld (du),a ; ixl = target_height
4834+
ld ixh,c ; (.du) = bc:iyl, ixl = target_height
48434835

48444836
; b = out_loop_times
48454837
; de = target buffer adress
@@ -4849,9 +4841,9 @@ ScaleWidth := $+2
48494841
ld iyh, 0
48504842
xor a,a
48514843
ld b,a
4852-
ld c,0
4853-
du := $-1
4854-
.loop: ldi
4844+
ld c,ixh ; (.du)
4845+
.loop:
4846+
ldi
48554847
add a,iyl
48564848
adc hl,bc ; xu += du
48574849
inc bc ; bc:iyl is du
@@ -6387,6 +6379,7 @@ _Maximum:
63876379
; Oututs:
63886380
; HL=max number
63896381
or a,a
6382+
.no_carry:
63906383
sbc hl,de
63916384
add hl,de
63926385
jp p,.skip
@@ -6405,6 +6398,7 @@ _Minimum:
64056398
; Oututs:
64066399
; HL=min number
64076400
or a,a
6401+
.no_carry:
64086402
sbc hl,de
64096403
ex de,hl
64106404
jp p,.skip
@@ -6442,7 +6436,7 @@ smcWord _XMax
64426436
smcWord _YMin
64436437
.YMin := $-3
64446438
ld de,(iy+6)
6445-
call _Maximum
6439+
call _Maximum.no_carry
64466440
ld (iy+6),hl
64476441
ld hl,ti.lcdHeight
64486442
smcWord _YMax

0 commit comments

Comments
 (0)