rpi4-osdev/part12-wgt/samples/wgt04.c
2021-03-25 09:20:48 +00:00

111 lines
3.5 KiB
C

#include "include/wgt.h"
#define MAX_RADIUS 100
// ######## REQUIRED FUNCTIONS ########
unsigned long state0 = 1;
unsigned long state1 = 2;
unsigned long rand(void)
{
unsigned long s1 = state0;
unsigned long s0 = state1;
state0 = s0;
s1 ^= s1 << 23;
s1 ^= s1 >> 17;
s1 ^= s0;
s1 ^= s0 >> 26;
state1 = s1;
return state0 + state1;
}
// ######## STUB FUNCTIONS ########
unsigned int kb = 0;
unsigned int kbhit(void) {
kb++;
return kb / 500;
}
void getch(void) {
wait_msec(0x500000);
kb = 0;
}
// ######## WGT EXAMPLES ########
void wgt04()
{
color pal[256];
int x, y, x2, y2, col, ctr;
vga256 (); /* Start graphics mode */
wtextcolor (vgapal[15]); /* Text will be white */
ctr = 0; /* Start counter for first primitive */
do {
wclip (0, 0, 319, 199); /* Clip to full screen */
wouttextxy (230, 0, NULL, "WGT DEMO 4"); /* Display text */
switch (ctr) /* Show primitive type */
{
case 0 : wouttextxy (0, 0, NULL, "Now using WLINE"); break;
case 1 : wouttextxy (0, 0, NULL, "Now using WFLINE"); break;
case 2 : wouttextxy (0, 0, NULL, "Now using WRECTANGLE"); break;
case 3 : wouttextxy (0, 0, NULL, "Now using WBAR"); break;
case 4 : wouttextxy (0, 0, NULL, "Now using WCIRCLE"); break;
case 5 : wouttextxy (0, 0, NULL, "Now using WFILL_CIRCLE"); break;
case 6 : wouttextxy (0, 0, NULL, "Now using WELLIPSE"); break;
case 7 : wouttextxy (0, 0, NULL, "Now using WFILL_ELLIPSE"); break;
case 8 : wouttextxy (0, 0, NULL, "Now using WSTYLELINE"); break;
case 9 : wouttextxy (0, 0, NULL, "Now using WBUTT");
wreadpalette (0, 255, pal);
wsetrgb (253, 60, 60, 60, pal);
wsetrgb (254, 50, 50, 50, pal);
wsetrgb (255, 40, 40, 40, pal);
wsetpalette (0, 255, pal);
break;
}
wclip (0, 8, 319, 199); /* Clip all primitives below text line */
do {
x = rand() % 320; /* Randomize first point - (x,y) */
y = rand() % 200;
x2 = rand() % 320; /* Randomize second point - (x2,y2) */
y2 = rand() % 200;
col = rand() % 256; /* Pick a color index to use */
wsetcolor (vgapal[col]); /* Now use it */
switch (ctr) /* Perform primitive */
{
case 0 : wline (x, y, x2, y2); break;
case 1 : wfline (x, rand() % 192 + 8, x2, rand() % 192 + 8); break;
case 2 : wrectangle (x, y, x2, y2); break;
case 3 : wbar (x, y, x2, y2); break;
case 4 : wcircle (x, y, rand() % MAX_RADIUS); break;
case 5 : wfill_circle (x, y, rand() % 100); break;
case 6 : wellipse (x, y, rand() % MAX_RADIUS,
rand() % MAX_RADIUS); break;
case 7 : wfill_ellipse (x, y, rand() % MAX_RADIUS,
rand() % MAX_RADIUS); break;
case 8 : wstyleline (x, rand() % 192 + 8, x2, rand() % 192 + 8,
rand() ); break;
case 9 : wbutt (x, y, x2, y2); break;
}
} while (!kbhit ()); /* Stop when key is pressed */
getch (); /* Get key from buffer */
wcls (vgapal[0]); /* Clear screen with black */
ctr++; /* Increment counter to next primitive */
} while (ctr < 10); /* Have we done all 10 ? */
}
void main()
{
wgt04();
while (1);
}