Skip to content

Commit 3c3c112

Browse files
committed
made small optimizations to multiple routines
1 parent 9cc5e10 commit 3c3c112

File tree

1 file changed

+65
-72
lines changed

1 file changed

+65
-72
lines changed

src/graphx/graphx.asm

Lines changed: 65 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,7 @@ gfx_Rectangle_NoClip:
907907
; de = ti.lcdWidth
908908
sbc hl,de ; hl = &buf[y+height-1][x]
909909
pop bc ; bc = width
910-
jp _HorizLine_NoClip_Draw ; draw bottom horizontal line
910+
jr _HorizLine_NoClip_Draw ; draw bottom horizontal line
911911

912912
;-------------------------------------------------------------------------------
913913
gfx_HorizLine:
@@ -1233,7 +1233,7 @@ gfx_FillEllipse:
12331233
ld hl,_ellipse_ret
12341234
ld (_ellipse_loop_draw_1),hl
12351235
jr _Ellipse
1236-
1236+
12371237
;-------------------------------------------------------------------------------
12381238
gfx_Ellipse_NoClip:
12391239
ld hl,_SetPixel_NoClip_NoWait
@@ -1281,7 +1281,7 @@ _Ellipse:
12811281
add ix,sp
12821282
lea hl,ix - 42
12831283
ld sp,hl
1284-
1284+
12851285
; First, setup all the variables
12861286
ld a,(ix + 12)
12871287
or a,a
@@ -1366,7 +1366,7 @@ _Ellipse:
13661366
ld de,(ix - el_y)
13671367
call _MultiplyHLDE
13681368
ld (ix - el_comp_b),hl
1369-
1369+
13701370
wait_quick
13711371

13721372
.main_loop1:
@@ -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
@@ -2899,15 +2897,15 @@ gfx_GetSprite:
28992897
sbc a,a
29002898
inc a
29012899
ld b,a ; the amount to add to get to the next line
2902-
ld (.offset),bc
2900+
push bc
2901+
pop iy
29032902
ld a,(de)
29042903
inc de
29052904
.loop:
29062905
ld bc,0
29072906
.amount := $-3
29082907
ldir ; copy the data into the struct data
2909-
ld bc,0
2910-
.offset := $-3
2908+
lea bc,iy ; (.offset)
29112909
add hl,bc
29122910
dec a
29132911
jr nz,.loop
@@ -3220,20 +3218,7 @@ _Tilemap:
32203218
ld (ix-3),h
32213219
sbc hl,bc
32223220
ld (ix-12),hl
3223-
jp .yloop
3224-
3225-
.xres := $+3
3226-
.loop:
3227-
ld (ix-1),0
3228-
ld hl,0
3229-
.xoffset := $-3
3230-
ld (ix-7),hl
3231-
ld l,(iy+t_width)
3232-
ld h,(ix-4)
3233-
mlt hl
3234-
ld (.ynext),hl
3235-
xor a,a
3236-
jr .xloop
3221+
jr .yloop
32373222

32383223
.xloopinner:
32393224
or a,a
@@ -3289,7 +3274,20 @@ _Tilemap:
32893274
.yloop:
32903275
ld a,(iy+t_draw_height)
32913276
cp a,(ix-3)
3292-
jp nz,.loop
3277+
jr z,.finish_loop
3278+
.xres := $+3
3279+
; .loop:
3280+
ld (ix-1),0
3281+
ld hl,0
3282+
.xoffset := $-3
3283+
ld (ix-7),hl
3284+
ld l,(iy+t_width)
3285+
ld h,(ix-4)
3286+
mlt hl
3287+
ld (.ynext),hl
3288+
xor a,a
3289+
jr .xloop
3290+
.finish_loop:
32933291
ld sp,ix
32943292
pop ix
32953293
ret
@@ -3856,8 +3854,7 @@ gfx_GetStringWidth:
38563854
; Returns:
38573855
; Width of string in pixels
38583856
pop de
3859-
pop hl
3860-
push hl ; hl -> string
3857+
ex (sp), hl ; hl -> string
38613858
push de
38623859
ld de,0
38633860
.loop:
@@ -3881,10 +3878,11 @@ gfx_GetCharWidth:
38813878
; arg0 : Character
38823879
; Returns:
38833880
; Width of character in pixels
3884-
ld iy,0
3885-
lea de,iy
3886-
add iy,sp
3887-
ld a,(iy+3) ; a = character
3881+
ld hl, 3
3882+
add hl, sp
3883+
ld a, (hl) ; a = character
3884+
sbc hl, hl
3885+
ex de, hl
38883886
_GetCharWidth:
38893887
sbc hl,hl
38903888
ld l,a
@@ -3997,8 +3995,7 @@ gfx_SetFontData:
39973995
; Returns:
39983996
; Pointer to previous font data
39993997
pop de
4000-
pop hl
4001-
push hl ; hl -> custom font data
3998+
ex (sp), hl ; hl -> custom font data
40023999
push de
40034000
add hl,de
40044001
or a,a
@@ -4049,8 +4046,7 @@ gfx_SetFontSpacing:
40494046
; Returns:
40504047
; None
40514048
pop de
4052-
pop hl
4053-
push hl ; hl -> custom font width
4049+
ex (sp), hl ; hl -> custom font width
40544050
push de
40554051
add hl,de
40564052
or a,a
@@ -4071,10 +4067,9 @@ gfx_SetMonospaceFont:
40714067
pop hl
40724068
pop de
40734069
push de
4074-
push hl
40754070
ld a,e ; a = width
40764071
ld (_TextFixedWidth),a ; store the value of the monospace width
4077-
ret
4072+
jp (hl)
40784073

40794074
;-------------------------------------------------------------------------------
40804075
gfx_FillTriangle_NoClip:
@@ -4146,7 +4141,7 @@ _FillTriangle:
41464141
ld hl,(ix+9)
41474142
or a,a
41484143
sbc hl,de
4149-
jp nz,.notflat
4144+
jr nz,.notflat
41504145
ld bc,(ix+6) ; x0
41514146
ld (ix-6),bc ; a = x0
41524147
ld (ix-3),bc ; b = x0;
@@ -4197,29 +4192,6 @@ _FillTriangle:
41974192
jp p,.cmp30
41984193
jp pe,.cmp31
41994194
jr .cmp32
4200-
.cmp30:
4201-
jp po,.cmp31
4202-
.cmp32:
4203-
ld bc,(ix+18)
4204-
ld (ix-6),bc
4205-
.cmp31:
4206-
ld de,(ix-3)
4207-
ld hl,(ix-6)
4208-
or a,a
4209-
sbc hl,de
4210-
inc hl
4211-
push hl
4212-
ld bc,(ix+9)
4213-
push bc
4214-
push de
4215-
call 0 ; horizline(a, y0, b-a+1);
4216-
.line0 := $-3
4217-
pop bc
4218-
pop bc
4219-
pop bc
4220-
ld sp,ix
4221-
pop ix
4222-
ret ; return;
42234195
.notflat:
42244196
ld bc,(ix+6) ; x0
42254197
ld hl,(ix+12)
@@ -4252,14 +4224,34 @@ _FillTriangle:
42524224
jr nz,.elselast ; if (y1 == y2) { last = y1; }
42534225
ld (ix-24),bc
42544226
jr .sublast
4227+
.cmp30:
4228+
jp po,.cmp31
4229+
.cmp32:
4230+
ld bc,(ix+18)
4231+
ld (ix-6),bc
4232+
.cmp31:
4233+
ld de,(ix-3)
4234+
ld hl,(ix-6)
4235+
or a,a
4236+
sbc hl,de
4237+
inc hl
4238+
push hl
4239+
ld bc,(ix+9)
4240+
push bc
4241+
push de
4242+
call 0 ; horizline(a, y0, b-a+1);
4243+
.line0 := $-3
4244+
ld sp,ix
4245+
pop ix
4246+
ret ; return;
42554247
.elselast:
42564248
ld bc,(ix+15) ; else { last = y1-1; }
42574249
dec bc
42584250
ld (ix-24),bc
42594251
.sublast:
42604252
ld bc,(ix+9)
42614253
ld (ix-12),bc ; for (y = y0; y <= last; y++)
4262-
jp .firstloopstart
4254+
jr .firstloopstart
42634255
.firstloop:
42644256
ld hl,(ix-15)
42654257
ld bc,(ix-33)
@@ -4336,7 +4328,7 @@ _FillTriangle:
43364328
ld de,(ix-21)
43374329
call _MultiplyHLDE ; sb = dx02 * (y - y0);
43384330
ld (ix-18),hl
4339-
jp .secondloopstart ; for(; y <= y2; y++)
4331+
jr .secondloopstart ; for(; y <= y2; y++)
43404332
.secondloop:
43414333
ld hl,(ix-15)
43424334
ld bc,(ix-39)
@@ -4837,8 +4829,7 @@ gfx_ScaleSprite:
48374829
pop de ; de->tgt_data
48384830
ld iy,0
48394831
ld iyl,a
4840-
ld a,c ; du = bc:iyl
4841-
ld (du),a ; ixl = target_height
4832+
ld ixh,c ; (.du) = bc:iyl, ixl = target_height
48424833

48434834
; b = out_loop_times
48444835
; de = target buffer adress
@@ -4848,9 +4839,9 @@ ScaleWidth := $+2
48484839
ld iyh, 0
48494840
xor a,a
48504841
ld b,a
4851-
ld c,0
4852-
du := $-1
4853-
.loop: ldi
4842+
ld c,ixh ; (.du)
4843+
.loop:
4844+
ldi
48544845
add a,iyl
48554846
adc hl,bc ; xu += du
48564847
inc bc ; bc:iyl is du
@@ -6410,6 +6401,7 @@ _Maximum:
64106401
; Oututs:
64116402
; HL=max number
64126403
or a,a
6404+
.no_carry:
64136405
sbc hl,de
64146406
add hl,de
64156407
jp p,.skip
@@ -6428,6 +6420,7 @@ _Minimum:
64286420
; Oututs:
64296421
; HL=min number
64306422
or a,a
6423+
.no_carry:
64316424
sbc hl,de
64326425
ex de,hl
64336426
jp p,.skip
@@ -6465,7 +6458,7 @@ smcWord _XMax
64656458
smcWord _YMin
64666459
.YMin := $-3
64676460
ld de,(iy+6)
6468-
call _Maximum
6461+
call _Maximum.no_carry
64696462
ld (iy+6),hl
64706463
ld hl,ti.lcdHeight
64716464
smcWord _YMax
@@ -6734,7 +6727,7 @@ _DefaultCharSpacing:
67346727
db 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8
67356728

67366729
_DefaultTextData:
6737-
db $00,$00,$00,$00,$00,$00,$00,$00 ;
6730+
db $00,$00,$00,$00,$00,$00,$00,$00 ; 0
67386731
db $7E,$81,$A5,$81,$BD,$BD,$81,$7E ; ☺
67396732
db $7E,$FF,$DB,$FF,$C3,$C3,$FF,$7E ; ☻
67406733
db $6C,$FE,$FE,$FE,$7C,$38,$10,$00 ; ♥
@@ -6766,7 +6759,7 @@ _DefaultTextData:
67666759
db $00,$24,$66,$FF,$66,$24,$00,$00 ; ↔
67676760
db $00,$18,$3C,$7E,$FF,$FF,$00,$00 ; ▲
67686761
db $00,$FF,$FF,$7E,$3C,$18,$00,$00 ; ▼
6769-
db $00,$00,$00,$00,$00,$00,$00,$00 ;
6762+
db $00,$00,$00,$00,$00,$00,$00,$00 ; _
67706763
db $C0,$C0,$C0,$C0,$C0,$00,$C0,$00 ; !
67716764
db $D8,$D8,$D8,$00,$00,$00,$00,$00 ; "
67726765
db $6C,$6C,$FE,$6C,$FE,$6C,$6C,$00 ; #
@@ -6861,7 +6854,7 @@ _DefaultTextData:
68616854
db $C0,$C0,$C0,$00,$C0,$C0,$C0,$00 ; |
68626855
db $E0,$30,$30,$1C,$30,$30,$E0,$00 ; }
68636856
db $76,$DC,$00,$00,$00,$00,$00,$00 ; ~
6864-
db $00,$10,$38,$6C,$C6,$C6,$FE,$00 ;
6857+
db $00,$10,$38,$6C,$C6,$C6,$FE,$00 ; Δ
68656858

68666859
_LcdTiming:
68676860
; db 14 shl 2 ; PPL shl 2

0 commit comments

Comments
 (0)