2021-03-08 22:51:02 +00:00
|
|
|
#include "wgt.h"
|
2021-03-09 22:16:25 +00:00
|
|
|
#include "include/mem.h"
|
2021-03-08 22:51:02 +00:00
|
|
|
|
|
|
|
// ######## 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 wgt08()
|
|
|
|
{
|
2021-03-09 22:16:25 +00:00
|
|
|
short x;
|
2021-03-08 22:51:02 +00:00
|
|
|
|
2021-03-09 22:16:25 +00:00
|
|
|
mem_init();
|
|
|
|
vga256 ();
|
|
|
|
wcls (vgapal[0]);
|
2021-03-08 22:51:02 +00:00
|
|
|
|
2021-03-09 22:16:25 +00:00
|
|
|
wsetcolor (vgapal[1]);
|
2021-03-12 22:02:57 +00:00
|
|
|
wcircle (160, 100, 50); /* try filling a circle */
|
2021-03-09 22:16:25 +00:00
|
|
|
getch ();
|
2021-03-08 22:51:02 +00:00
|
|
|
|
2021-03-09 22:16:25 +00:00
|
|
|
wsetcolor (vgapal[40]);
|
2021-03-12 22:02:57 +00:00
|
|
|
wregionfill (160, 100);
|
2021-03-09 22:16:25 +00:00
|
|
|
wsetcolor (vgapal[170]);
|
|
|
|
wregionfill (0, 0);
|
2021-03-08 22:51:02 +00:00
|
|
|
|
2021-03-09 22:16:25 +00:00
|
|
|
getch ();
|
2021-03-08 22:51:02 +00:00
|
|
|
|
2021-03-10 18:35:08 +00:00
|
|
|
wcls (vgapal[0]);
|
2021-03-09 22:16:25 +00:00
|
|
|
for (x = 1; x < 10000; x++) /* try filling 10,000 random pixels */
|
|
|
|
{
|
|
|
|
wsetcolor (vgapal[rand() % 255]);
|
2021-03-12 22:02:57 +00:00
|
|
|
wputpixel (rand() % 320, rand() % 200);
|
2021-03-09 22:16:25 +00:00
|
|
|
}
|
2021-03-08 22:51:02 +00:00
|
|
|
|
2021-03-09 22:16:25 +00:00
|
|
|
getch ();
|
|
|
|
wsetcolor (vgapal[40]);
|
2021-03-12 22:02:57 +00:00
|
|
|
wclip (50, 50, 250, 150); /* fill works with clipping too! */
|
|
|
|
wregionfill (160, 100);
|
2021-03-08 22:51:02 +00:00
|
|
|
|
2021-03-09 22:16:25 +00:00
|
|
|
wsetcolor (vgapal[7]);
|
2021-03-12 22:02:57 +00:00
|
|
|
wclip (10, 10, 40, 40);
|
|
|
|
wregionfill (20, 20);
|
2021-03-08 22:51:02 +00:00
|
|
|
|
2021-03-09 22:16:25 +00:00
|
|
|
wsetcolor (vgapal[9]);
|
2021-03-12 22:02:57 +00:00
|
|
|
wclip (260, 160, 300, 190);
|
|
|
|
wregionfill (270, 170);
|
2021-03-08 22:51:02 +00:00
|
|
|
|
2021-03-09 22:16:25 +00:00
|
|
|
wsetcolor (vgapal[10]);
|
2021-03-12 22:02:57 +00:00
|
|
|
wclip (0, 0, 319, 199);
|
2021-03-09 22:16:25 +00:00
|
|
|
wregionfill (0, 0);
|
2021-03-08 22:51:02 +00:00
|
|
|
|
2021-03-09 22:16:25 +00:00
|
|
|
getch ();
|
2021-03-08 22:51:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
|
|
|
wgt08();
|
|
|
|
while (1);
|
|
|
|
}
|