From 32f99ca5d917edecc406a28d3903feadbfd7afde Mon Sep 17 00:00:00 2001 From: Adam Greenwood-Byrne Date: Fri, 16 Apr 2021 20:28:59 +0100 Subject: [PATCH] Added samples/wgt36.c and wgt/wxor.c --- part12-wgt/include/wgt.h | 1 + part12-wgt/samples/wgt36.c | 96 ++++++++++++++++++++++++++++++++++++++ part12-wgt/wgt/wxor.c | 42 +++++++++++++++++ 3 files changed, 139 insertions(+) create mode 100644 part12-wgt/samples/wgt36.c create mode 100644 part12-wgt/wgt/wxor.c diff --git a/part12-wgt/include/wgt.h b/part12-wgt/include/wgt.h index 4a2ff05..c4bd5cd 100644 --- a/part12-wgt/include/wgt.h +++ b/part12-wgt/include/wgt.h @@ -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); diff --git a/part12-wgt/samples/wgt36.c b/part12-wgt/samples/wgt36.c new file mode 100644 index 0000000..99185af --- /dev/null +++ b/part12-wgt/samples/wgt36.c @@ -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); +} diff --git a/part12-wgt/wgt/wxor.c b/part12-wgt/wgt/wxor.c new file mode 100644 index 0000000..ec4a364 --- /dev/null +++ b/part12-wgt/wgt/wxor.c @@ -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 */ +}