mirror of
https://github.com/isometimes/rpi4-osdev
synced 2024-11-22 02:00:40 +00:00
Added samples/wgt36.c and wgt/wxor.c
This commit is contained in:
parent
1147917580
commit
32f99ca5d9
3 changed files with 139 additions and 0 deletions
|
@ -158,3 +158,4 @@ void msetxy (short x, short y);
|
|||
void msetbut (short event, short bnum);
|
||||
void msetbounds (short x1, short y1, short x2, short y2);
|
||||
void noclick();
|
||||
void wxorbox (short x, short y, short x2, short y2, unsigned char col);
|
||||
|
|
96
part12-wgt/samples/wgt36.c
Normal file
96
part12-wgt/samples/wgt36.c
Normal file
|
@ -0,0 +1,96 @@
|
|||
#include "include/wgt.h"
|
||||
#include "include/mem.h"
|
||||
#include "include/multicore.h"
|
||||
|
||||
// ######## REQUIRED FUNCTIONS ########
|
||||
|
||||
unsigned long state0 = 1000;
|
||||
unsigned long state1 = 2000;
|
||||
|
||||
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 ########
|
||||
|
||||
#define NUM_IN 5 /* number of random points */
|
||||
#define NUM_OUT 30 /* number of points of bezier curve */
|
||||
/* Fewer points will make more chunky line */
|
||||
|
||||
int ox, oy; /* old mouse coordinates */
|
||||
int i;
|
||||
|
||||
void wgt36()
|
||||
{
|
||||
set_clock_rate(get_max_clock());
|
||||
mem_init();
|
||||
vga256 (); /* Initialize graphics mode */
|
||||
|
||||
start_core2(minit); // Start the comms engine (core 2)
|
||||
while (!comms_up); // Wait for comms up
|
||||
|
||||
for (i = 0; i < 200; i++) /* Draw a background */
|
||||
{
|
||||
wsetcolor (vgapal[i]);
|
||||
wline (0, i, 319, i);
|
||||
}
|
||||
|
||||
do { /* Draws a filled xorbox using mouse coordinates as one corner. */
|
||||
ox = mx;
|
||||
oy = my;
|
||||
wxorbox (50, 50, ox, oy, vgapal[128]); /* Draw the box */
|
||||
while ((mx == ox) && (my == oy) && (!but)); /* Do nothing while mouse is
|
||||
stationary. */
|
||||
wxorbox (50, 50, ox, oy, vgapal[128]);
|
||||
/* Erase the box by drawing the same thing */
|
||||
} while (but == 0);
|
||||
|
||||
noclick ();
|
||||
|
||||
do { /* Draws a hollow rubber box using mouse coordinates as one corner. */
|
||||
ox = mx;
|
||||
oy = my;
|
||||
wxorbox (50, 50, ox, 50, vgapal[128]);
|
||||
wxorbox (ox, 50, ox, oy, vgapal[128]); /* Draw the box */
|
||||
wxorbox (50, oy, ox, oy, vgapal[128]);
|
||||
wxorbox (50, 50, 50, oy, vgapal[128]);
|
||||
while ((mx == ox) && (my == oy) && (!but)); /* Do nothing while mouse is
|
||||
stationary. */
|
||||
wxorbox (50, 50, ox, 50, vgapal[128]);
|
||||
wxorbox (ox, 50, ox, oy, vgapal[128]); /* Erase the box */
|
||||
wxorbox (50, oy, ox, oy, vgapal[128]);
|
||||
wxorbox (50, 50, 50, oy, vgapal[128]);
|
||||
} while (but == 0);
|
||||
mdeinit (); /* Deinitialize the mouse handler */
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
wgt36();
|
||||
while (1);
|
||||
}
|
42
part12-wgt/wgt/wxor.c
Normal file
42
part12-wgt/wgt/wxor.c
Normal file
|
@ -0,0 +1,42 @@
|
|||
#include "../include/wgt.h"
|
||||
|
||||
void wxorbox (short x, short y, short x2, short y2, unsigned char col)
|
||||
{
|
||||
short i, j; /* Loop Control */
|
||||
block temp; /* Temp pointer to screen */
|
||||
|
||||
if (y2 < y)
|
||||
{
|
||||
/* swap y's */
|
||||
i = y;
|
||||
y = y2;
|
||||
y2 = i;
|
||||
}
|
||||
|
||||
if (x2 < x)
|
||||
{
|
||||
/* swap x's */
|
||||
i = x;
|
||||
x = x2;
|
||||
x2 = i;
|
||||
}
|
||||
|
||||
if (y2 > by) y2 = by; /* Clip box */
|
||||
if (x2 > bx) x2 = bx;
|
||||
if (y < ty) y = ty;
|
||||
if (x < tx) x = tx;
|
||||
|
||||
temp = &abuf[y*WGT_SYS.xres + x]; /* Move to first offset */
|
||||
|
||||
for (j = y; j <= y2; j++)
|
||||
{
|
||||
for (i = x; i <= x2; i++)
|
||||
{
|
||||
/* This can be change to perform any logical operation
|
||||
on the pixels, such as & or | */
|
||||
*temp = *temp ^ col; /* XOR the pixel on screen with col and put it back on screen */
|
||||
temp++; /* Go to next pixel */
|
||||
} /* x loop */
|
||||
temp += (WGT_SYS.xres - 1) - (x2 - x); /* Advance to next row */
|
||||
} /* y loop */
|
||||
}
|
Loading…
Reference in a new issue