mirror of
https://github.com/isometimes/rpi4-osdev
synced 2024-11-22 02:00:40 +00:00
Added wflipblock and wgt10.c example to exercise it
This commit is contained in:
parent
ac74e42f24
commit
22ac7a36cd
4 changed files with 155 additions and 3 deletions
100
part12-wgt/examples/wgt10.c
Normal file
100
part12-wgt/examples/wgt10.c
Normal file
|
@ -0,0 +1,100 @@
|
||||||
|
#include "wgt.h"
|
||||||
|
#include "include/mem.h"
|
||||||
|
#include "include/mb.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<t);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ######## 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 wgt10()
|
||||||
|
{
|
||||||
|
short x,y;
|
||||||
|
block part1; /* part of the screen */
|
||||||
|
|
||||||
|
set_clock_rate(get_max_clock());
|
||||||
|
mem_init();
|
||||||
|
vga256 ();
|
||||||
|
|
||||||
|
for (y = 216; y >= 4; y--)
|
||||||
|
{
|
||||||
|
wfill_circle (y + 40, y + 10, y); /* draw a pattern */
|
||||||
|
wsetcolor (vgapal[(y % 235) + 20]);
|
||||||
|
}
|
||||||
|
|
||||||
|
part1 = wnewblock (0, 0, 960, 540); /* get the circle in a block */
|
||||||
|
getch();
|
||||||
|
|
||||||
|
wcls (0);
|
||||||
|
|
||||||
|
for (x = 0; x < 1920; x++)
|
||||||
|
{
|
||||||
|
wsetcolor (vgapal[x % 255]);
|
||||||
|
wline (x, 0, x, 1079);
|
||||||
|
}
|
||||||
|
|
||||||
|
getch();
|
||||||
|
|
||||||
|
wputblock (960, 0, part1, 0); /* normal mode */
|
||||||
|
wflipblock (part1, 0);
|
||||||
|
|
||||||
|
wputblock (960, 540, part1, 1); /* XRAY mode */
|
||||||
|
wflipblock (part1, 1);
|
||||||
|
|
||||||
|
wputblock (0, 540, part1, 0); /* normal mode */
|
||||||
|
wflipblock (part1, 0);
|
||||||
|
|
||||||
|
wputblock (0, 0, part1, 1); /* XRAY mode */
|
||||||
|
|
||||||
|
wfreeblock (part1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
wgt10();
|
||||||
|
while (1);
|
||||||
|
}
|
51
part12-wgt/wflipb.c
Normal file
51
part12-wgt/wflipb.c
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
#include "wgt.h"
|
||||||
|
#include "include/mem.h"
|
||||||
|
|
||||||
|
#define fastcopy memcpy
|
||||||
|
|
||||||
|
void wflipblock (block image, short direction)
|
||||||
|
{
|
||||||
|
int width,height;
|
||||||
|
int ctr,ctr2;
|
||||||
|
block temp, temp2;
|
||||||
|
unsigned int *pr2;
|
||||||
|
|
||||||
|
width = wgetblockwidth (image); /* Find width and height of block */
|
||||||
|
height = wgetblockheight (image);
|
||||||
|
temp = malloc (width*4);
|
||||||
|
temp2 = malloc (width*4);
|
||||||
|
image += 4;
|
||||||
|
|
||||||
|
if (direction == 1) /* Horizontal flip */
|
||||||
|
{
|
||||||
|
for (ctr = 1; ctr <= height; ctr++)
|
||||||
|
/* Use each row */
|
||||||
|
{
|
||||||
|
fastcopy (temp, image, width);
|
||||||
|
/* Copy row to buffer */
|
||||||
|
|
||||||
|
for (ctr2 = 0; ctr2 <= width - 1; ctr2++)
|
||||||
|
temp2[width - 1 - ctr2] = temp[ctr2];
|
||||||
|
/* Reverse elements
|
||||||
|
to another buffer */
|
||||||
|
|
||||||
|
fastcopy (image, temp2, width); /* Copy back to original block */
|
||||||
|
image += width; /* Advance pr to next row */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (direction == 0) /* Vertical flip */
|
||||||
|
{
|
||||||
|
pr2 = image + (height*width) - width; /* pr2 points to last row */
|
||||||
|
for (ctr = 1; ctr <= (height / 2); ctr++)
|
||||||
|
/* Only flip halfway */
|
||||||
|
{
|
||||||
|
fastcopy (temp, image, width); /* Get row of image data */
|
||||||
|
fastcopy (image, pr2, width); /* Copy last row to first */
|
||||||
|
fastcopy (pr2, temp, width); /* Put first row on last */
|
||||||
|
image += width; /* Move to next row */
|
||||||
|
pr2 -= width; /* Decrement last row */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
free (temp);
|
||||||
|
free (temp2);
|
||||||
|
}
|
|
@ -98,3 +98,4 @@ void winittimer (void);
|
||||||
void wsettimerspeed (int speed);
|
void wsettimerspeed (int speed);
|
||||||
void wstarttimer (void (*rout)(), int speed);
|
void wstarttimer (void (*rout)(), int speed);
|
||||||
void wstoptimer (void);
|
void wstoptimer (void);
|
||||||
|
void wflipblock (block image, short direction);
|
||||||
|
|
|
@ -10,11 +10,11 @@ void wfreeblock (block ptr)
|
||||||
|
|
||||||
short wgetblockwidth (block ptr)
|
short wgetblockwidth (block ptr)
|
||||||
{
|
{
|
||||||
return *(short *)ptr; /* Width is first 2 bytes of data */
|
return *ptr; /* Width is first 2 bytes of data */
|
||||||
}
|
}
|
||||||
|
|
||||||
short wgetblockheight (block ptr)
|
short wgetblockheight (block ptr)
|
||||||
{
|
{
|
||||||
ptr += 2; /* Skip width */
|
ptr ++; /* Skip width */
|
||||||
return *(short *)ptr; /* Height is second 2 bytes of data */
|
return *ptr; /* Height is second 2 bytes of data */
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue