Skip to content

Commit c02ed49

Browse files
committed
made small optimizations to multiple routines
1 parent 65f23c0 commit c02ed49

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
@@ -3237,20 +3235,7 @@ _Tilemap:
32373235
ld (ix-3),h
32383236
sbc hl,bc
32393237
ld (ix-12),hl
3240-
jp .yloop
3241-
3242-
.xres := $+3
3243-
.loop:
3244-
ld (ix-1),0
3245-
ld hl,0
3246-
.xoffset := $-3
3247-
ld (ix-7),hl
3248-
ld l,(iy+t_width)
3249-
ld h,(ix-4)
3250-
mlt hl
3251-
ld (.ynext),hl
3252-
xor a,a
3253-
jr .xloop
3238+
jr .yloop
32543239

32553240
.xloopinner:
32563241
or a,a
@@ -3306,7 +3291,20 @@ _Tilemap:
33063291
.yloop:
33073292
ld a,(iy+t_draw_height)
33083293
cp a,(ix-3)
3309-
jp nz,.loop
3294+
jr z,.finish_loop
3295+
.xres := $+3
3296+
; .loop:
3297+
ld (ix-1),0
3298+
ld hl,0
3299+
.xoffset := $-3
3300+
ld (ix-7),hl
3301+
ld l,(iy+t_width)
3302+
ld h,(ix-4)
3303+
mlt hl
3304+
ld (.ynext),hl
3305+
xor a,a
3306+
jr .xloop
3307+
.finish_loop:
33103308
ld sp,ix
33113309
pop ix
33123310
ret
@@ -3898,10 +3896,11 @@ gfx_GetCharWidth:
38983896
; arg0 : Character
38993897
; Returns:
39003898
; Width of character in pixels
3901-
ld iy,0
3902-
lea de,iy
3903-
add iy,sp
3904-
ld a,(iy+3) ; a = character
3899+
ld hl, 3
3900+
add hl, sp
3901+
ld a, (hl) ; a = character
3902+
sbc hl, hl
3903+
ex de, hl
39053904
_GetCharWidth:
39063905
sbc hl,hl
39073906
ld l,a
@@ -4014,8 +4013,7 @@ gfx_SetFontData:
40144013
; Returns:
40154014
; Pointer to previous font data
40164015
pop de
4017-
pop hl
4018-
push hl ; hl -> custom font data
4016+
ex (sp), hl ; hl -> custom font data
40194017
push de
40204018
add hl,de
40214019
or a,a
@@ -4066,8 +4064,7 @@ gfx_SetFontSpacing:
40664064
; Returns:
40674065
; None
40684066
pop de
4069-
pop hl
4070-
push hl ; hl -> custom font width
4067+
ex (sp), hl ; hl -> custom font width
40714068
push de
40724069
add hl,de
40734070
or a,a
@@ -4088,10 +4085,9 @@ gfx_SetMonospaceFont:
40884085
pop hl
40894086
pop de
40904087
push de
4091-
push hl
40924088
ld a,e ; a = width
40934089
ld (_TextFixedWidth),a ; store the value of the monospace width
4094-
ret
4090+
jp (hl)
40954091

40964092
;-------------------------------------------------------------------------------
40974093
gfx_FillTriangle_NoClip:
@@ -4231,9 +4227,6 @@ _FillTriangle:
42314227
push de
42324228
call 0 ; horizline(a, y0, b-a+1);
42334229
.line0 := $-3
4234-
pop bc
4235-
pop bc
4236-
pop bc
42374230
ld sp,ix
42384231
pop ix
42394232
ret ; return;
@@ -4276,7 +4269,7 @@ _FillTriangle:
42764269
.sublast:
42774270
ld bc,(ix+9)
42784271
ld (ix-12),bc ; for (y = y0; y <= last; y++)
4279-
jp .firstloopstart
4272+
jr .firstloopstart
42804273
.firstloop:
42814274
ld hl,(ix-15)
42824275
ld bc,(ix-33)
@@ -4353,7 +4346,7 @@ _FillTriangle:
43534346
ld de,(ix-21)
43544347
call _MultiplyHLDE ; sb = dx02 * (y - y0);
43554348
ld (ix-18),hl
4356-
jp .secondloopstart ; for(; y <= y2; y++)
4349+
jr .secondloopstart ; for(; y <= y2; y++)
43574350
.secondloop:
43584351
ld hl,(ix-15)
43594352
ld bc,(ix-39)
@@ -4856,8 +4849,7 @@ gfx_ScaleSprite:
48564849
pop de ; de->tgt_data
48574850
ld iy,0
48584851
ld iyl,a
4859-
ld a,c ; du = bc:iyl
4860-
ld (du),a ; ixl = target_height
4852+
ld ixh,c ; (.du) = bc:iyl, ixl = target_height
48614853

48624854
; b = out_loop_times
48634855
; de = target buffer adress
@@ -4867,9 +4859,9 @@ ScaleWidth := $+2
48674859
ld iyh, 0
48684860
xor a,a
48694861
ld b,a
4870-
ld c,0
4871-
du := $-1
4872-
.loop: ldi
4862+
ld c,ixh ; (.du)
4863+
.loop:
4864+
ldi
48734865
add a,iyl
48744866
adc hl,bc ; xu += du
48754867
inc bc ; bc:iyl is du
@@ -6354,6 +6346,7 @@ _Maximum:
63546346
; Oututs:
63556347
; HL=max number
63566348
or a,a
6349+
.no_carry:
63576350
sbc hl,de
63586351
add hl,de
63596352
jp p,.skip
@@ -6372,6 +6365,7 @@ _Minimum:
63726365
; Oututs:
63736366
; HL=min number
63746367
or a,a
6368+
.no_carry:
63756369
sbc hl,de
63766370
ex de,hl
63776371
jp p,.skip
@@ -6409,7 +6403,7 @@ smcWord _XMax
64096403
smcWord _YMin
64106404
.YMin := $-3
64116405
ld de,(iy+6)
6412-
call _Maximum
6406+
call _Maximum.no_carry
64136407
ld (iy+6),hl
64146408
ld hl,ti.lcdHeight
64156409
smcWord _YMax

0 commit comments

Comments
 (0)