accelleon wrote:No more exception but it still freezes. Yea i wanted a basic working vga driver (im not too far away) that's why i wanted to start as basic as possible then make my code faster/better.
Edit: Yea that works but im still wondering why my floats wouldn't work?
Edit 2: Btw do you happen to know a replacement for this vga_drawcircle() function:
Code: Select all
void vga_drawcircle(int x,int y, int radius, byte color)
{
fixed16_16 n=0,invradius=(1/(float)radius)*0x10000L;
int dx=0,dy=radius-1;
word dxoffset,dyoffset,offset = (y<<8)+(y<<6)+x;
while (dx<=dy)
{
dxoffset = (dx<<8) + (dx<<6);
dyoffset = (dy<<8) + (dy<<6);
VGA[offset+dy-dxoffset] = color; /* octant 0 */
VGA[offset+dx-dyoffset] = color; /* octant 1 */
VGA[offset-dx-dyoffset] = color; /* octant 2 */
VGA[offset-dy-dxoffset] = color; /* octant 3 */
VGA[offset-dy+dxoffset] = color; /* octant 4 */
VGA[offset-dx+dyoffset] = color; /* octant 5 */
VGA[offset+dx+dyoffset] = color; /* octant 6 */
VGA[offset+dy+dxoffset] = color; /* octant 7 */
dx++;
n+=invradius;
dy = (int)((radius * SIN_ACOS[(int)(n>>6)]) >> 16);
}
}
It relies on floats and doesn't work just like vga_drawline()
I don't have the whole algorithm on me at the moment but you can derive it fairly easily
Assume center is at 0,0 and radius r. The equation is x² + y² = r². Initial conditions are y=r
Plot the 8 pixels like you are now and increase x.
Decrease y if (x+1)² + y² > r²
Stop when x >= y
An example with r=6
Draw 0,6. 1+36 > 36 goto 1,5
Draw 1,5. 4+25 < 36
Draw 2,5. 9+25 < 36
Draw 3,5. 16+25 > 36 goto 4,4
Draw 4,4. x=y stop
This algorithm, as-is tends to give a more compressed circle since it plots pixels whose center falls inside the theoretical line. You can adjust it to plot the pixels that the theoretical line passes through by changing the decrease condition like so:
x² + y² > (r+0.5)² which can be approximated by x² + y² > r² + r
This would plot (0,6) (1,6) (2,6) (3,5) (4,5) (5,4 (note that this pixel is partially redundant since it will also be plotted by the y,x segment, but you can't do anything about it)) for the above example.