Skip to content

Commit 60006ac

Browse files
gfx_FloodFill opts
1 parent a5111ac commit 60006ac

File tree

1 file changed

+35
-37
lines changed

1 file changed

+35
-37
lines changed

src/graphx/graphx.asm

+35-37
Original file line numberDiff line numberDiff line change
@@ -4124,7 +4124,7 @@ _: rla
41244124

41254125
;-------------------------------------------------------------------------------
41264126
_FloodFill:
4127-
; Preforms an implementation of a flood fill so no one hopefully crashes the stack
4127+
; Implements a flood fill so no one hopefully crashes the stack
41284128
; Maximum stack depth is 3224 bytes
41294129
; Arguments:
41304130
; arg0 : X Coordinate
@@ -4140,9 +4140,13 @@ _FloodFill:
41404140
call _PixelPtrNoChks_ASM \.r ; ov = p(x, y);
41414141
ld a,(hl)
41424142

4143-
ld (ff_color0_smc),a \.r
4144-
ld (ff_color1_smc),a \.r
4145-
ld (ff_color2_smc),a \.r
4143+
ld (ff_oldcolor0_smc),a \.r
4144+
ld (ff_oldcolor1_smc),a \.r
4145+
ld (ff_oldcolor2_smc),a \.r
4146+
4147+
ld a,(ix+12)
4148+
ld (ff_newcolor0_smc),a \.r
4149+
ld (ff_newcolor1_smc),a \.r
41464150

41474151
ld hl,(_xmax) \.r ; smc to gain speedz in inner loops
41484152
ld (ff_xmax_smc),hl \.r
@@ -4169,10 +4173,6 @@ _FloodFill:
41694173
ld (iy+7),255 ; sp->dy = -1;
41704174
lea iy,iy+8 ; sp++;
41714175

4172-
ld a,(ix+12)
4173-
ld (ff_newcolor0_smc),a \.r
4174-
ld (ff_newcolor1_smc),a \.r
4175-
41764176
ff_doloop: ; do {
41774177
lea iy,iy-8 ; sp--;
41784178
ld a,(iy+7)
@@ -4191,6 +4191,10 @@ ff_doloop: ; do {
41914191
mlt de
41924192
add hl,de
41934193
add hl,de
4194+
ff_xmin_smc =$+1
4195+
ld de,0
4196+
ff_oldcolor0_smc =$+1
4197+
ld a,0
41944198

41954199
jr +_
41964200
ff_forloop0: ; for (x=x1; !(x & 0x8000) && x>=xmin && p(x, y) == ov; x--) { s(x, y); }
@@ -4200,15 +4204,11 @@ ff_newcolor0_smc =$+1
42004204
dec bc
42014205
_: bit 7,b
42024206
jr nz,+_
4203-
ff_xmin_smc =$+1
4204-
ld de,0
42054207
or a,a
42064208
sbc hl,de
4207-
add hl,de
42084209
jr c,+_
4209-
ld a,(hl)
4210-
ff_color0_smc =$+1
4211-
cp a,0
4210+
add hl,de
4211+
cp a,(hl)
42124212
jr z,ff_forloop0
42134213

42144214
_: ld (ix+6),bc
@@ -4218,8 +4218,8 @@ _: ld (ix+6),bc
42184218
jr nz,+_
42194219
or a,a
42204220
sbc hl,bc
4221-
add hl,bc
42224221
jp nc,ff_skip \.r ; if (!(x & 0x8000) && (unsigned)x>=x1) goto skip;
4222+
add hl,bc
42234223
_: inc hl
42244224
ld (ix-11),hl ; l = x+1;
42254225
or a,a
@@ -4256,8 +4256,6 @@ ff_badpush0:
42564256
ld bc,(ix-8)
42574257
inc bc ; x = x1+1;
42584258

4259-
ld (ix+6),bc
4260-
42614259
ld hl,(currDrawBuffer)
42624260
add hl,bc
42634261
ld e,(ix+9)
@@ -4267,21 +4265,23 @@ ff_badpush0:
42674265
add hl,de
42684266
ex de,hl ; de -> draw location
42694267
; do {
4270-
jr ff_innerdoloop ; for (; (unsigned)x<=xmax && gfx_getpixel(x, y) == ov; x++) { gfx_setpixel(x, y); }
4268+
ff_forloop1start:
4269+
ff_xmax_smc =$+1
4270+
ld hl,0
4271+
4272+
jr +_ ; for (; (unsigned)x<=xmax && gfx_getpixel(x, y) == ov; x++) { gfx_setpixel(x, y); }
42714273
ff_forloop1:
42724274
ff_newcolor1_smc =$+1
42734275
ld a,0
42744276
ld (de),a
42754277
inc de
42764278
inc bc
4277-
ff_xmax_smc =$+1
4278-
ff_innerdoloop:
4279-
ld hl,0
4280-
or a,a
4279+
_: or a,a
42814280
sbc hl,bc
42824281
jr c,+_
4282+
add hl,bc
42834283
ld a,(de)
4284-
ff_color1_smc =$+1
4284+
ff_oldcolor1_smc =$+1
42854285
cp a,0
42864286
jr z,ff_forloop1
42874287

@@ -4301,21 +4301,20 @@ _: ld (ix+6),bc
43014301
ld a,(_ymax) \.r
43024302
cp a,e
43034303
jr c,ff_badpush1 ; compare y values
4304+
dec bc
4305+
ld (iy+3),bc
43044306
ld a,(ix+9)
43054307
ld (iy+6),a
43064308
ld bc,(ix-11)
43074309
ld (iy+0),bc
4308-
ld bc,(ix+6)
4309-
dec bc
4310-
ld (iy+3),bc
43114310
ld a,(ix-4)
43124311
ld (iy+7),a
43134312
lea iy,iy+8
43144313
ff_badpush1:
43154314
ld hl,(ix-15) ; if (x>x2+1) { push(y, x2+1, x-1, -dy); }
4315+
ld bc,(ix+6)
43164316
inc hl
43174317
or a,a
4318-
ld bc,(ix+6)
43194318
sbc hl,bc
43204319
jr nc,ff_skip
43214320
lea de,ix-24
@@ -4334,17 +4333,16 @@ ff_badpush1:
43344333
ld a,(_ymax) \.r
43354334
cp a,e
43364335
jr c,ff_badpush2 ; compare y values
4337-
ld a,(ix+9)
4338-
ld (iy+6),a
4336+
dec bc
4337+
ld (iy+3),bc
43394338
ld bc,(ix-15)
43404339
inc bc
43414340
ld (iy+0),bc
4342-
ld bc,(ix+6)
4343-
dec bc
4344-
ld (iy+3),bc
43454341
ld a,(ix-4)
43464342
neg
43474343
ld (iy+7),a
4344+
ld a,(ix+9)
4345+
ld (iy+6),a
43484346
lea iy,iy+8
43494347
ff_skip:
43504348
ff_badpush2: ; skip: for (x++; (unsigned)x<=x2 && gfx_getpixel(x, y) != ov; x++);
@@ -4359,26 +4357,26 @@ ff_badpush2: ; skip: for (x++; (unsigned)x<=x2 &&
43594357
add hl,de
43604358
add hl,de
43614359
ex de,hl ; de -> draw location
4360+
ld hl,(ix-15)
43624361

43634362
jr +_
43644363
ff_forloop2:
43654364
inc bc
43664365
inc de
4367-
_: ld hl,(ix-15)
4368-
or a,a
4366+
_: or a,a
43694367
sbc hl,bc
4368+
add hl,bc
43704369
jr c,+_
43714370
ld a,(de)
4372-
ff_color2_smc =$+1
4371+
ff_oldcolor2_smc =$+1
43734372
cp a,0
43744373
jr nz,ff_forloop2
43754374

43764375
_: ld (ix+6),bc
43774376
ld (ix-11),bc ; l = x;
4378-
ld hl,(ix-15)
43794377
or a,a
43804378
sbc hl,bc
4381-
jp nc,ff_innerdoloop \.r ; } while ((unsigned)x<=x2);
4379+
jp nc,ff_forloop1start \.r ; } while ((unsigned)x<=x2);
43824380

43834381
ff_stacktop_smc =$+1
43844382
ld hl,0

0 commit comments

Comments
 (0)