Blame |
Last modification |
View Log
| RSS feed
#include "glib.h"
#include <stdlib.h>
#include "../vga.h"
#define fontaddr 0xffa6eL /* indirizzo set caratteri */
unsigned char * flbaddr
;
unsigned int bpr
;
unsigned int height
, width
;
static void circlepixels
(WORD x
, WORD y
, WORD sx
, WORD sy
, DWORD c
)
{
grx_plot
(sx
+ x
, sy
+ y
, c
);
grx_plot
(sx
- x
, sy
+ y
, c
);
grx_plot
(sx
+ x
, sy
- y
, c
);
grx_plot
(sx
- x
, sy
- y
, c
);
grx_plot
(sx
+ y
, sy
+ x
, c
);
grx_plot
(sx
- y
, sy
+ x
, c
);
grx_plot
(sx
+ y
, sy
- x
, c
);
grx_plot
(sx
- y
, sy
- x
, c
);
}
void grx_circle
(WORD sx
, WORD sy
, WORD r
, DWORD c
)
{
int x
, y
, d
;
if (r
< 1) {
grx_plot
(sx
, sy
, c
);
return;
}
x
= 0;
y
= r
;
d
= 1 - r
;
circlepixels
(x
, y
, sx
, sy
, c
);
while (x
< y
) {
if (d
< 0)
d
+= x
* 2 + 3;
else {
d
+= x
* 2 - y
* 2 + 5;
y
--;
}
x
++;
circlepixels
(x
, y
, sx
, sy
, c
);
}
}
/* grx_disc by Massy */
static __inline__
void discpixels
(WORD x
, WORD y
, WORD sx
, WORD sy
, DWORD c
)
{
grx_line
(sx
+ x
, sy
+ y
, sx
+ x
, sy
- y
, c
);
grx_line
(sx
- x
, sy
+ y
, sx
- x
, sy
- y
, c
);
grx_line
(sx
+ y
, sy
+ x
, sx
+ y
, sy
- x
, c
);
grx_line
(sx
- y
, sy
+ x
, sx
- y
, sy
- x
, c
);
}
void grx_disc
(WORD sx
, WORD sy
, WORD r
, DWORD c
)
{
int x
, y
, d
;
if (r
< 1) {
grx_plot
(sx
, sy
, c
);
return;
}
x
= 0;
y
= r
;
d
= 1 - r
;
discpixels
(x
, y
, sx
, sy
, c
);
while (x
< y
) {
if (d
< 0)
d
+= x
* 2 + 3;
else {
d
+= x
* 2 - y
* 2 + 5;
y
--;
}
x
++;
discpixels
(x
, y
, sx
, sy
, c
);
}
}
int grx_setbuffer
(unsigned char *vbuf
, unsigned int w
, unsigned int h
)
{
flbaddr
= vbuf
;
width
= w
;
height
= h
;
bpr
= 4 * w
;
return 1;
}
void grx_clear
(DWORD color
)
{
grx_box
(0, 0, width
, height
, color
);
}
void grx_putimage
(WORD x1
, WORD y1
, WORD x2
, WORD y2
, BYTE
*buf
)
{
}
void grx_box
(WORD x1
, WORD y1
, WORD x2
, WORD y2
, DWORD color
)
{
unsigned char * addr
;
WORD dx
, y
;
addr
= flbaddr
+ (x1
<< 2) + bpr
* y1
;
dx
= (x2
- x1
+ 1);
for (y
= y1
; y
<= y2
; y
++) {
memset((unsigned long int *)(addr
),(DWORD
)(color
),dx
);
addr
+= bpr
;
}
}
void grx_rect
(WORD x1
, WORD y1
, WORD x2
, WORD y2
, DWORD color
)
{
unsigned char * addr
;
WORD dx
, y
;
addr
= flbaddr
+ (x1
<< 2) + bpr
* y1
;
dx
= (x2
- x1
);
memset((unsigned long int *)(addr
),(DWORD
)color
,dx
+2);
addr
+= bpr
;
for (y
= y1
+ 1; y
<= y2
- 1; y
++) {
*(unsigned long int *)addr
= (DWORD
)color
;
*(unsigned long int *)(addr
+ (dx
<<2)) = (DWORD
)color
;
addr
+= bpr
;
}
memset((unsigned long int *)(addr
),(DWORD
)(color
),dx
+2);
}
void grx_text
(char *text
, WORD x
, WORD y
, DWORD fg
, DWORD bg
)
{
unsigned char * fp
, * addr
;
int r
, c
, bits
;
addr
= flbaddr
;
while (*text
) {
fp
= (unsigned char *)(fontaddr
+ (8 * *(BYTE
*)text
));
for (r
=0; r
<8; r
++) {
bits
= *(unsigned char *)(fp
++);
for (c
=0; c
<8; c
++)
if (bits
& (0x80>>c
))
*(unsigned long int *)(addr
+ (y
+ r
) * bpr
+ ((x
+ c
) << 2)) = (DWORD
)fg
;
else
*(unsigned long int *)(addr
+ (y
+ r
) * bpr
+ ((x
+ c
) << 2)) = (DWORD
)bg
;
}
text
++;
x
+= 8;
}
}
void grx_line
(WORD x1
, WORD y1
, WORD x2
, WORD y2
, DWORD color
)
{
register int t
, distance
;
unsigned char * addr
;
int xerr
=0, yerr
=0, deltax
, deltay
;
int incx
, incy
;
addr
= flbaddr
;;
deltax
= x2
- x1
; /* compute both distances */
deltay
= y2
- y1
;
if (deltax
> 0) /* compute increments */
incx
= 1;
else if (deltax
== 0)
incx
= 0;
else
incx
= -1;
if (deltay
> 0)
incy
= 1;
else if (deltay
== 0)
incy
= 0;
else
incy
= -1;
deltax
= abs(deltax
); /* determine greater distance */
deltay
= abs(deltay
);
if (deltax
> deltay
)
distance
= deltax
;
else
distance
= deltay
;
for (t
=0; t
<=distance
+1; t
++) { /* draw the line */
*(unsigned long int *)(addr
+ y1
* bpr
+ (x1
<< 2)) = (DWORD
)color
;
xerr
+= deltax
;
yerr
+= deltay
;
if (xerr
> distance
) {
xerr
-= distance
;
x1
+= incx
;
}
if (yerr
> distance
) {
yerr
-= distance
;
y1
+= incy
;
}
}
}
void grx_plot
(WORD x
, WORD y
, DWORD color
)
{
*(unsigned long int *)(flbaddr
+ y
* bpr
+ (x
<< 2)) = (DWORD
)color
;
}
DWORD grx_getpixel
(WORD x
, WORD y
)
{
DWORD rv
;
(DWORD
)rv
= *(unsigned long int *)(flbaddr
+ y
* bpr
+ (x
<< 2));
return rv
;
}