Created
October 18, 2018 16:11
-
-
Save tschak909/b7f9248f230fabcc8435c8a2d80501ee to your computer and use it in GitHub Desktop.
implementation of scanline fill for CC65 TGI.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* screen_paint - Paint screen scanline_fill | |
*/ | |
void _screen_paint(unsigned short x, unsigned short y) | |
{ | |
static unsigned short xStack[320]; | |
static unsigned char yStack[192]; | |
unsigned char stackentry = 1; | |
unsigned char spanAbove, spanBelow; | |
unsigned char oldColor = tgi_getpixel(x,y); | |
if (oldColor == 1) | |
return; | |
do | |
{ | |
while (x > 0 && tgi_getpixel(x-1,y) == oldColor) | |
--x; | |
spanAbove = spanBelow = false; | |
while(tgi_getpixel(x,y) == oldColor) | |
{ | |
tgi_setpixel(x,y); | |
if (y < (191)) | |
{ | |
unsigned char belowColor = tgi_getpixel(x, y+1); | |
if (!spanBelow && belowColor == oldColor) | |
{ | |
xStack[stackentry] = x; | |
yStack[stackentry] = y+1; | |
++stackentry; | |
spanBelow = true; | |
} | |
else if (spanBelow && belowColor != oldColor) | |
spanBelow = false; | |
} | |
if (y > 0) | |
{ | |
unsigned char aboveColor = tgi_getpixel(x, y-1); | |
if (!spanAbove && aboveColor == oldColor) | |
{ | |
xStack[stackentry] = x; | |
yStack[stackentry] = y-1; | |
++stackentry; | |
spanAbove = true; | |
} | |
else if (spanAbove && aboveColor != oldColor) | |
spanAbove = false; | |
} | |
++x; | |
} | |
--stackentry; | |
x = xStack[stackentry]; | |
y = yStack[stackentry]; | |
} | |
while (stackentry); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment