Thanks Guys,
I am having some trouble with diagonal lines and circles.
When you use a real gfx display with PBP, is it usually the display that
handles the lines and circles, or is it done in PBP?
I'm finding the algorithms are usually in C, and all seem to want to look
for values below zero (signed integer variables), where one of these
variables would wrap back to 0xFF if you decremented from zero using PBP
For the only diagonal lines in the video, I was able to do a trick and
check a value is above #128, pretending that value is zero.
This is so far only working if the destination point of the line has higher
x and y coordinates than the start point..
(ie. I can draw a line at any angle from x-0,y-0, to anywhere).
Here is the difference in the code.
Code:x0 = 3 : y0 = 3 x1 = 21 : y1 = 11 gosub drawline
... and the original CCode:drawline: stepx = 0 stepy = 0 frac = 0 'a line is x0,y0 to x1,y1. dy = y1 - y0 dx = x1 - x0 IF dy > 128 THEN dy = dy - 1 stepy = stepy - 1 ELSE stepy = 1 ENDIF IF dx > 128 THEN dx = dx - 1 stepx = stepx - 1 ELSE stepx = 1 ENDIF dy = dy << 1 dx = dx << 1 'draw pixel px = x0 : py = y0 gosub setpixel IF (dx > dy || dx > 128) THEN frac = dy - (dx >> 1) WHILE x0 != x1 IF (frac < 128) THEN y0 = y0 + stepy frac = frac - dx ENDIF x0 = x0 + stepx frac = frac + dy 'draw pixel px = x0 : py = y0 gosub setpixel WEND ELSE frac = dx - (dy >> 1) WHILE y0 != y1 IF (frac < 128) THEN x0 = x0 + stepx frac = frac - dy ENDIF y0 = y0 + stepy frac = frac + dx 'draw pixel px = x0 : py = y0 gosub setpixel WEND ENDIF return
I wonder what of the C compilers that are for 16F pics.Code:static void drawLine(int x0, int y0, int x1, int y1, int color, Color* destination, int width) { int dy = y1 - y0; int dx = x1 - x0; int stepx, stepy; if (dy < 0) { dy = -dy; stepy = -width; } else { stepy = width; } if (dx < 0) { dx = -dx; stepx = -1; } else { stepx = 1; } dy <<= 1; dx <<= 1; y0 *= width; y1 *= width; destination[x0+y0] = color; if (dx > dy) { int fraction = dy - (dx >> 1); while (x0 != x1) { if (fraction >= 0) { y0 += stepy; fraction -= dx; } x0 += stepx; fraction += dy; destination[x0+y0] = color; } } else { int fraction = dx - (dy >> 1); while (y0 != y1) { if (fraction >= 0) { x0 += stepx; fraction -= dy; } y0 += stepy; fraction += dx; destination[x0+y0] = color; } } }
Maybe they don't do signed integers either?
If I could compile the original C source in a pic C compiler,
and then disassemble it, I could have the result in RISC asm.



At the moment my circles are perfect squares of the




Bookmarks