mirror of
https://github.com/isometimes/rpi4-osdev
synced 2024-11-24 19:20:40 +00:00
Added mouse support to examples/wgt22.c and examples/wgt60.c
This commit is contained in:
parent
d9a0eaa864
commit
b4b1195a0b
4 changed files with 59 additions and 14 deletions
|
@ -1,5 +1,6 @@
|
||||||
#include "wgtspr.h"
|
#include "wgtspr.h"
|
||||||
#include "include/mem.h"
|
#include "include/mem.h"
|
||||||
|
#include "include/multicore.h"
|
||||||
|
|
||||||
// ######## REQUIRED FUNCTIONS ########
|
// ######## REQUIRED FUNCTIONS ########
|
||||||
|
|
||||||
|
@ -49,6 +50,9 @@ void wgt22()
|
||||||
mem_init();
|
mem_init();
|
||||||
vga256 (); /* Initializes WGT system */
|
vga256 (); /* Initializes WGT system */
|
||||||
|
|
||||||
|
start_core2(minit); // Start the comms engine (core 2)
|
||||||
|
while (!comms_up); // Wait for comms up
|
||||||
|
|
||||||
extern unsigned char _binary_bin_invader_spr_start[];
|
extern unsigned char _binary_bin_invader_spr_start[];
|
||||||
wloadsprites (palette, &_binary_bin_invader_spr_start[0], sprites, 0, SPRITES_IN_FILE);
|
wloadsprites (palette, &_binary_bin_invader_spr_start[0], sprites, 0, SPRITES_IN_FILE);
|
||||||
/* load first 50 sprites */
|
/* load first 50 sprites */
|
||||||
|
@ -61,16 +65,14 @@ void wgt22()
|
||||||
Sprite number, x coord, y coord, sprite number in array of sprites
|
Sprite number, x coord, y coord, sprite number in array of sprites
|
||||||
Therefore sprite #1 would be displayed at 160,150 with sprite 1 in the array */
|
Therefore sprite #1 would be displayed at 160,150 with sprite 1 in the array */
|
||||||
|
|
||||||
spriteon (1, 160, 150, 1); /* turn on any sprites */
|
spriteon (1, 160, 100, 1); /* turn on any sprites */
|
||||||
spriteon (2, 10, 100, 3); /* you need */
|
spriteon (2, 10, 100, 3); /* you need */
|
||||||
|
|
||||||
/* This move will go left 1, for 300 times, and right 1 for 300 times,
|
/* This move will go left 1, for 300 times, and right 1 for 300 times,
|
||||||
and repeat */
|
and repeat */
|
||||||
movex (2, "(1,300,0)(-1,300,0)R");
|
|
||||||
movexon (2);
|
|
||||||
|
|
||||||
movex (1, "(1,150,0)(-1,150,0)R"); /* set up any movement */
|
movex (2, "(1,300,0)(-1,300,0)R"); /* set up any movement */
|
||||||
movexon (1); /* or animation needed */
|
movexon (2); /* or animation needed */
|
||||||
|
|
||||||
/* This animation will animate sprite 2 through a sequence of sprites
|
/* This animation will animate sprite 2 through a sequence of sprites
|
||||||
in the sprite array and keep repeating. */
|
in the sprite array and keep repeating. */
|
||||||
|
@ -89,6 +91,7 @@ void wgt22()
|
||||||
|
|
||||||
wfreesprites (sprites, 0, SPRITES_IN_FILE); /* free memory */
|
wfreesprites (sprites, 0, SPRITES_IN_FILE); /* free memory */
|
||||||
|
|
||||||
|
mdeinit();
|
||||||
deinitialize_sprites ();
|
deinitialize_sprites ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,10 +99,12 @@ void looper (void)
|
||||||
{
|
{
|
||||||
erase_sprites (); /* clear the sprites */
|
erase_sprites (); /* clear the sprites */
|
||||||
|
|
||||||
/* any direct sprite movements must be placed */
|
s[1].x = mx; /* any direct sprite movements must be placed */
|
||||||
/* between erase_sprites and draw_sprites */
|
s[1].y = my; /* between erase_sprites and draw_sprites */
|
||||||
/* notice how sprites #1 and #2 move and animates on their own now!
|
/* This will set sprite one's coordinate to the mouse
|
||||||
You don't need to change anything to make them move! */
|
coordinates. Move it around! */
|
||||||
|
/* notice how sprite #2 moves and animates on its own now!
|
||||||
|
You don't need to change anything to make it move! */
|
||||||
|
|
||||||
draw_sprites (1); /* draw them back on */
|
draw_sprites (1); /* draw them back on */
|
||||||
wait_msec(0x3E9F); /* Try removing this to see how fast the
|
wait_msec(0x3E9F); /* Try removing this to see how fast the
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include "wgtspr.h"
|
#include "wgtspr.h"
|
||||||
#include "include/mem.h"
|
#include "include/mem.h"
|
||||||
|
#include "include/multicore.h"
|
||||||
|
|
||||||
// ######## REQUIRED FUNCTIONS ########
|
// ######## REQUIRED FUNCTIONS ########
|
||||||
|
|
||||||
|
@ -70,6 +71,9 @@ void wgt60()
|
||||||
mem_init();
|
mem_init();
|
||||||
vga256 (); /* Initializes WGT system */
|
vga256 (); /* Initializes WGT system */
|
||||||
|
|
||||||
|
start_core2(minit); // Start the comms engine (core 2)
|
||||||
|
while (!comms_up); // Wait for comms up
|
||||||
|
|
||||||
wtexttransparent (TEXTFGBG); /* Turn foreground and background on */
|
wtexttransparent (TEXTFGBG); /* Turn foreground and background on */
|
||||||
|
|
||||||
extern unsigned char _binary_bin_break_spr_start[];
|
extern unsigned char _binary_bin_break_spr_start[];
|
||||||
|
@ -110,6 +114,8 @@ void wgt60()
|
||||||
spriteon (0, 160, 150, 1); /* Turn on our sprites */
|
spriteon (0, 160, 150, 1); /* Turn on our sprites */
|
||||||
spriteon (1, 160, 100, 2);
|
spriteon (1, 160, 100, 2);
|
||||||
|
|
||||||
|
msetbounds (50, 129, 245, 179); /* Limit mouse movement */
|
||||||
|
|
||||||
xsp = 1.1; /* Set initial ball speeds */
|
xsp = 1.1; /* Set initial ball speeds */
|
||||||
ysp = 1.3;
|
ysp = 1.3;
|
||||||
|
|
||||||
|
@ -122,15 +128,18 @@ void wgt60()
|
||||||
looper ();
|
looper ();
|
||||||
} while (1); /* Until the right mouse button is clicked */
|
} while (1); /* Until the right mouse button is clicked */
|
||||||
|
|
||||||
|
mdeinit();
|
||||||
deinitialize_sprites (); /* Deinit the sprite system */
|
deinitialize_sprites (); /* Deinit the sprite system */
|
||||||
}
|
}
|
||||||
|
|
||||||
void looper(void)
|
void looper(void)
|
||||||
{
|
{
|
||||||
// wretrace (); /* Time our updates to the vertical retrace */
|
wait_msec(0x411B);
|
||||||
wait_msec(0x3E9F);
|
|
||||||
erase_sprites (); /* Clear sprites from sprite screen */
|
erase_sprites (); /* Clear sprites from sprite screen */
|
||||||
|
|
||||||
|
s[0].x = mx; /* Set paddle position to mouse position */
|
||||||
|
s[0].y = my;
|
||||||
|
|
||||||
if (lx > 267) /* Is ball bouncing off right wall? */
|
if (lx > 267) /* Is ball bouncing off right wall? */
|
||||||
{
|
{
|
||||||
dobounce ();
|
dobounce ();
|
||||||
|
|
|
@ -33,6 +33,10 @@ int but;
|
||||||
int mx;
|
int mx;
|
||||||
int my;
|
int my;
|
||||||
|
|
||||||
|
/* Mouse boundaries */
|
||||||
|
int mbx1, mby1;
|
||||||
|
int mbx2, mby2;
|
||||||
|
|
||||||
void hci_poll2(unsigned char byte)
|
void hci_poll2(unsigned char byte)
|
||||||
{
|
{
|
||||||
switch (poll_state) {
|
switch (poll_state) {
|
||||||
|
@ -178,8 +182,30 @@ void acl_poll()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void msetbounds (short x1, short y1, short x2, short y2)
|
||||||
|
{
|
||||||
|
if (x1 < WGT_SYS.xres && x1 >= 0) {
|
||||||
|
if (x2 < WGT_SYS.xres && x2 >= x1) {
|
||||||
|
if (y1 < WGT_SYS.yres && y1 >= 0) {
|
||||||
|
if (y2 < WGT_SYS.yres && y2 >= y1) {
|
||||||
|
mbx1 = x1;
|
||||||
|
mbx2 = x2;
|
||||||
|
mby1 = y1;
|
||||||
|
mby2 = y2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void msetxy (short x, short y)
|
void msetxy (short x, short y)
|
||||||
{
|
{
|
||||||
|
if (x < mbx1) x = mbx1;
|
||||||
|
if (y < mby1) y = mby1;
|
||||||
|
|
||||||
|
if (x > mbx2) x = mbx2;
|
||||||
|
if (y > mby2) y = mby2;
|
||||||
|
|
||||||
mx = x;
|
mx = x;
|
||||||
my = y;
|
my = y;
|
||||||
}
|
}
|
||||||
|
@ -218,8 +244,12 @@ void minit()
|
||||||
// Subscribe to updates
|
// Subscribe to updates
|
||||||
sendACLsubscribe(connection_handle);
|
sendACLsubscribe(connection_handle);
|
||||||
|
|
||||||
mx = 160;
|
mx = WGT_SYS.xres / 2;
|
||||||
my = 100;
|
my = WGT_SYS.yres / 2;
|
||||||
|
mbx1 = 0;
|
||||||
|
mby1 = 0;
|
||||||
|
mbx2 = WGT_SYS.xres;
|
||||||
|
mby2 = WGT_SYS.yres;
|
||||||
but = 0;
|
but = 0;
|
||||||
|
|
||||||
comms_up = 1;
|
comms_up = 1;
|
||||||
|
|
|
@ -155,3 +155,4 @@ void wbezier (tpolypoint *rawpts, short numraw, tpolypoint *curvepts, short numc
|
||||||
void minit();
|
void minit();
|
||||||
void mdeinit();
|
void mdeinit();
|
||||||
void msetxy (short x, short y);
|
void msetxy (short x, short y);
|
||||||
|
void msetbounds (short x1, short y1, short x2, short y2);
|
||||||
|
|
Loading…
Reference in a new issue