From ca56c4f1cfd9fe27de2e2781e660953060f1fda0 Mon Sep 17 00:00:00 2001 From: Adam Greenwood-Byrne Date: Sun, 14 Mar 2021 20:18:11 +0000 Subject: [PATCH] Add wwipe.c and examples/wgt24.c to exercise it --- part12-wgt/examples/wgt24.c | 141 ++++++++++++++++++++++++++++++++++++ part12-wgt/wgt.h | 1 + part12-wgt/wwipe.c | 63 ++++++++++++++++ 3 files changed, 205 insertions(+) create mode 100644 part12-wgt/examples/wgt24.c create mode 100644 part12-wgt/wwipe.c diff --git a/part12-wgt/examples/wgt24.c b/part12-wgt/examples/wgt24.c new file mode 100644 index 0000000..3dff3da --- /dev/null +++ b/part12-wgt/examples/wgt24.c @@ -0,0 +1,141 @@ +#include "wgt.h" +#include "include/mem.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; +} + +void wait_msec(unsigned int n) +{ + register unsigned long f, t, r; + + // Get the current counter frequency + asm volatile ("mrs %0, cntfrq_el0" : "=r"(f)); + // Read the current counter + asm volatile ("mrs %0, cntpct_el0" : "=r"(t)); + // Calculate expire value for counter + t+=((f/1000)*n)/1000; + do{asm volatile ("mrs %0, cntpct_el0" : "=r"(r));}while(r= 0; i--) + { + wwipe (159, 99, i, 199, screen1); + delay (1); + } + + for (i = 199; i >= 0; i--) + { + wwipe (159, 99, 0, i, screen1); + delay (1); + } + getch (); + + /* Clear with black screen by wiping top to bottom */ + for (i = 0; i < 200; i++) + { + wwipe (0, i, 319, i, screen2); + delay (1); + } + getch (); + + wfreeblock (screen1); /* remember to free that memory */ + wfreeblock (screen2); +} + +void main() +{ + wgt24(); + while (1); +} diff --git a/part12-wgt/wgt.h b/part12-wgt/wgt.h index 82d6ba6..34fe294 100644 --- a/part12-wgt/wgt.h +++ b/part12-wgt/wgt.h @@ -116,3 +116,4 @@ void wdissolve (block sourceimage, short *pattern, short speed); void wsetscreen (block image); void wnormscreen (void); void wvertres (short x, short y, short y2, block image); +void wwipe (short x, short y, short x2, short y2, block image); diff --git a/part12-wgt/wwipe.c b/part12-wgt/wwipe.c new file mode 100644 index 0000000..8e4495c --- /dev/null +++ b/part12-wgt/wwipe.c @@ -0,0 +1,63 @@ +#include "wgt.h" + +void wwipe (short x, short y, short x2, short y2, block image) +{ + short t, distance; + short wx, wy, dx, dy, bdx, bdy, incx, incy; + unsigned int col; + short swidth; + + swidth = wgetblockwidth (image); + + /* Do the line formula */ + dx = x2 - x; + dy = y2 - y; + t = 0; wx = 0; wy = 0; + if (dy < 0) incy = - 1; else incy = 1; + if (dx < 0) incx = - 1; else incx = 1; + bdx = abs (dx); + bdy = abs (dy); + if (bdx > bdy) distance = bdx; + else distance = bdy; + if (distance == bdx) + { + while (t <= distance) + { + if ((x >= tx) & (y >= ty) & (y <= by) & (x <= bx)) + /* inside clipping? */ + { + col = image[y * swidth + x + 2]; + /* get the colour */ + abuf[y * WGT_SYS.xres + x] = col; + /* put the pixel */ + } + wy += bdy; + x += incx; + t++; + if (wy >= distance) + { + wy -= distance; + y += incy; + } + } + } + else + { + while (t <= distance) + { + if ((x >= tx) & (y >= ty) & (y <= by) & (x <= bx)) + { + col = image[y * swidth + x + 2]; + abuf[y*WGT_SYS.xres + x] = col; + } + wx += bdx; + if (wx >= distance) + { + wx -= distance; + x += incx; + } + y += incy; + t++; + } + } +}