# HG changeset patch # User Laurens Holst # Date 1497117942 -7200 # Sat Jun 10 20:05:42 2017 +0200 # Node ID d15d2c64ec8da3ad48abbe3ea67c7882f5eb03f9 # Parent 114ca88b773d863bee6ccd5f3b390b84e130ea38 SpanBuffer: Speed up the start and end search loops in Insert. By shifting the buckets left by 1, to avoid special-casing end-x 0 (100H). diff --git a/src/RunLengthImage.asm b/src/RunLengthImage.asm --- a/src/RunLengthImage.asm +++ b/src/RunLengthImage.asm @@ -79,6 +79,7 @@ ld e,(ix + RunLengthImage.spansEnd) ld d,(ix + RunLengthImage.spansEnd + 1) Loop: + dec l ld a,(hl) sub l ld (de),a @@ -90,6 +91,7 @@ ldi ld h,c ld l,a + inc l jr nz,Loop ld (ix + RunLengthImage.spansEnd),e ld (ix + RunLengthImage.spansEnd + 1),d diff --git a/src/SpanBuffer.asm b/src/SpanBuffer.asm --- a/src/SpanBuffer.asm +++ b/src/SpanBuffer.asm @@ -5,9 +5,10 @@ ; http://tfpsly.free.fr/Docs/TomHammersley/sbuffer.htm ; ; It is using a linked list approach, however to avoid needing a span allocation -; mechanism, it puts spans in 256 buckets, one for each pixel. Furthermore, to -; speed up traversing the spans list, the span fields are placed in three -; aligned arrays rather than one array of span objects. +; mechanism, it puts spans in 256 buckets, one for each pixel. To speed up +; traversing the spans list, the span fields are placed in three aligned arrays +; rather than one array of span objects. Also the buckets are shifted left by 1, +; (so x 0 is in bucket 255) to avoid special-casing end x 0 (=100H). ; SpanBuffer: MACRO IF ($ & 0FFH) != 0 @@ -24,13 +25,15 @@ ; hl = this ; hl <- this SpanBuffer_Init: - ld (hl),0 + dec l + ld (hl),255 inc h ld (hl),0FFH inc h ld (hl),0 dec h dec h + inc l ret ; d = x @@ -38,24 +41,24 @@ ; b = z ; c = color ; hl = this -; Modifies: af +; Modifies: af, d, e SpanBuffer_Insert: PROC + dec e ld a,e - dec a cp d call c,System_ThrowException push bc - xor a + dec d + ld a,255 + cp d + jr z,StartNoSplit StartLoop: ld l,a ld a,(hl) - and a - jr z,StartLoopBreak cp d jr c,StartLoop -StartLoopBreak: - cp d jr z,StartNoSplit +StartSplit: ld a,(hl) ld (hl),d inc h @@ -73,12 +76,8 @@ EndLoop: ld l,a ld a,(hl) - and a - jr z,EndLoopBreak cp e jr c,EndLoop -EndLoopBreak: - cp e jr z,EndNoSplit EndSplit: ld a,(hl)