2001-09-13 15:58:32 +00:00
|
|
|
/*
|
2006-04-06 19:51:37 +00:00
|
|
|
* Demo program for mouse usage. Will work for the C64/C128/CBM510/Atari/Apple2
|
2001-09-14 16:39:48 +00:00
|
|
|
*
|
2001-09-13 15:58:32 +00:00
|
|
|
* Ullrich von Bassewitz, 13.09.2001
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-11-07 12:54:30 +00:00
|
|
|
#include <stdio.h>
|
2001-09-13 15:58:32 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <mouse.h>
|
|
|
|
#include <conio.h>
|
2006-04-06 19:51:37 +00:00
|
|
|
#include <ctype.h>
|
2001-09-13 15:58:32 +00:00
|
|
|
#include <dbg.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-09-11 16:55:20 +00:00
|
|
|
#if defined(__C64__) || defined(__C128__)
|
2001-09-13 15:58:32 +00:00
|
|
|
|
2001-09-14 16:39:48 +00:00
|
|
|
/* Address of data for sprite 0 */
|
2001-09-13 15:58:32 +00:00
|
|
|
#if defined(__C64__)
|
2001-09-14 16:39:48 +00:00
|
|
|
# define SPRITE0_DATA 0x0340
|
|
|
|
# define SPRITE0_PTR 0x07F8
|
2001-09-13 15:58:32 +00:00
|
|
|
#elif defined(__C128__)
|
2001-09-14 16:39:48 +00:00
|
|
|
# define SPRITE0_DATA 0x0E00
|
|
|
|
# define SPRITE0_PTR 0x07F8
|
2001-09-13 15:58:32 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* The mouse sprite (an arrow) */
|
|
|
|
static const unsigned char MouseSprite[64] = {
|
|
|
|
0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00,
|
|
|
|
0x0F, 0xE0, 0x00,
|
|
|
|
0x0F, 0xC0, 0x00,
|
|
|
|
0x0F, 0x80, 0x00,
|
|
|
|
0x0F, 0xC0, 0x00,
|
|
|
|
0x0D, 0xE0, 0x00,
|
|
|
|
0x08, 0xF0, 0x00,
|
|
|
|
0x00, 0x78, 0x00,
|
|
|
|
0x00, 0x3C, 0x00,
|
|
|
|
0x00, 0x1E, 0x00,
|
|
|
|
0x00, 0x0F, 0x00,
|
|
|
|
0x00, 0x07, 0x80,
|
|
|
|
0x00, 0x03, 0x80,
|
|
|
|
0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00,
|
|
|
|
0x00
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* __C64__ or __C128__ */
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-11-07 12:54:30 +00:00
|
|
|
static void CheckError (const char* S, unsigned char Error)
|
|
|
|
{
|
|
|
|
if (Error != MOUSE_ERR_OK) {
|
|
|
|
printf ("%s: %s(%d)\n", S, mouse_geterrormsg (Error), Error);
|
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void DoWarning (void)
|
|
|
|
/* Warn the user that a mouse driver is needed for this program */
|
|
|
|
{
|
|
|
|
printf ("Warning: This program needs the mouse\n"
|
|
|
|
"driver with the name\n"
|
|
|
|
" %s\n"
|
|
|
|
"on disk! Press 'y' if you have it or\n"
|
2009-09-11 16:55:20 +00:00
|
|
|
"any other key to exit.\n", mouse_stddrv);
|
2006-04-06 19:51:37 +00:00
|
|
|
if (tolower (cgetc ()) != 'y') {
|
2004-11-07 12:54:30 +00:00
|
|
|
exit (EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
printf ("Ok. Please wait patiently...\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-09-27 11:24:43 +00:00
|
|
|
static void ShowState (unsigned char Jailed, unsigned char Invisible)
|
|
|
|
/* Display jail and cursor state */
|
2001-09-13 15:58:32 +00:00
|
|
|
{
|
|
|
|
gotoxy (0, 6);
|
|
|
|
cclear (40);
|
|
|
|
gotoxy (0, 6);
|
2009-09-27 11:24:43 +00:00
|
|
|
cprintf ("Mouse cursor %svisible%s", Invisible? "in" : "", Jailed? ", jailed" : "");
|
2001-09-13 15:58:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main (void)
|
|
|
|
{
|
|
|
|
struct mouse_info info;
|
2009-09-27 11:24:43 +00:00
|
|
|
struct mouse_box full_box;
|
|
|
|
struct mouse_box small_box;
|
2001-09-13 15:58:32 +00:00
|
|
|
unsigned char Invisible;
|
|
|
|
unsigned char Done;
|
2009-09-27 11:24:43 +00:00
|
|
|
unsigned char Jailed;
|
2001-09-13 15:58:32 +00:00
|
|
|
|
|
|
|
/* Initialize the debugger */
|
|
|
|
DbgInit (0);
|
|
|
|
|
2004-11-07 12:54:30 +00:00
|
|
|
/* Output a warning about the driver that is needed */
|
|
|
|
DoWarning ();
|
|
|
|
|
2001-09-13 15:58:32 +00:00
|
|
|
/* Clear the screen, set white on black */
|
2006-04-06 19:51:37 +00:00
|
|
|
(void) bordercolor (COLOR_BLACK);
|
|
|
|
(void) bgcolor (COLOR_BLACK);
|
|
|
|
(void) textcolor (COLOR_GRAY3);
|
2001-09-13 15:58:32 +00:00
|
|
|
cursor (0);
|
|
|
|
clrscr ();
|
|
|
|
|
2001-09-14 16:39:48 +00:00
|
|
|
#if defined(__C64__) || defined(__C128__) || defined(__CBM510__)
|
2001-09-13 15:58:32 +00:00
|
|
|
/* Copy the sprite data */
|
|
|
|
memcpy ((void*) SPRITE0_DATA, MouseSprite, sizeof (MouseSprite));
|
|
|
|
|
|
|
|
/* Set the VIC sprite pointer */
|
|
|
|
*(unsigned char*)SPRITE0_PTR = SPRITE0_DATA / 64;
|
|
|
|
|
|
|
|
/* Set the color of sprite 0 */
|
2001-09-20 14:08:24 +00:00
|
|
|
#ifdef __CBM510__
|
|
|
|
pokebsys ((unsigned) &VIC.spr0_color, COLOR_WHITE);
|
|
|
|
#else
|
2001-09-13 15:58:32 +00:00
|
|
|
VIC.spr0_color = COLOR_WHITE;
|
2001-09-20 14:08:24 +00:00
|
|
|
#endif
|
2001-09-13 15:58:32 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2004-11-07 12:54:30 +00:00
|
|
|
/* Load and install the mouse driver */
|
2009-09-11 16:55:20 +00:00
|
|
|
CheckError ("mouse_load_driver",
|
|
|
|
mouse_load_driver (&mouse_def_callbacks, mouse_stddrv));
|
2004-11-07 12:54:30 +00:00
|
|
|
|
2009-09-27 11:24:43 +00:00
|
|
|
/* Get the initial mouse bounding box */
|
|
|
|
mouse_getbox (&full_box);
|
|
|
|
|
2001-12-10 23:49:42 +00:00
|
|
|
/* Print a help line */
|
|
|
|
revers (1);
|
2009-09-27 11:24:43 +00:00
|
|
|
cputsxy (0, 0, "d)ebug h)ide q)uit s)how j)ail ");
|
2001-12-10 23:49:42 +00:00
|
|
|
revers (0);
|
|
|
|
|
2001-09-13 15:58:32 +00:00
|
|
|
/* Test loop */
|
|
|
|
Done = 0;
|
2009-09-27 11:24:43 +00:00
|
|
|
Jailed = 0;
|
|
|
|
Invisible = 1;
|
|
|
|
ShowState (Jailed, Invisible);
|
2001-09-13 15:58:32 +00:00
|
|
|
while (!Done) {
|
2009-09-27 11:24:43 +00:00
|
|
|
|
|
|
|
/* Get the current mouse coordinates and button states and print them */
|
|
|
|
mouse_info (&info);
|
|
|
|
gotoxy (0, 2);
|
|
|
|
cprintf ("X = %3d", info.pos.x);
|
|
|
|
gotoxy (0, 3);
|
|
|
|
cprintf ("Y = %3d", info.pos.y);
|
|
|
|
gotoxy (0, 4);
|
|
|
|
cprintf ("LB = %c", (info.buttons & MOUSE_BTN_LEFT)? '1' : '0');
|
|
|
|
gotoxy (0, 5);
|
|
|
|
cprintf ("RB = %c", (info.buttons & MOUSE_BTN_RIGHT)? '1' : '0');
|
|
|
|
|
|
|
|
/* Handle user input */
|
2009-09-11 16:55:20 +00:00
|
|
|
if (kbhit ()) {
|
2006-04-07 17:49:38 +00:00
|
|
|
switch (tolower (cgetc ())) {
|
2009-09-27 11:24:43 +00:00
|
|
|
|
2001-09-13 15:58:32 +00:00
|
|
|
case 'd':
|
|
|
|
BREAK();
|
|
|
|
break;
|
2009-09-27 11:24:43 +00:00
|
|
|
|
2001-09-13 15:58:32 +00:00
|
|
|
case 'h':
|
2009-09-27 11:24:43 +00:00
|
|
|
ShowState (Jailed, ++Invisible);
|
2001-09-13 15:58:32 +00:00
|
|
|
mouse_hide ();
|
|
|
|
break;
|
2009-09-27 11:24:43 +00:00
|
|
|
|
|
|
|
case 'j':
|
|
|
|
if (Jailed) {
|
|
|
|
Jailed = 0;
|
|
|
|
mouse_setbox (&full_box);
|
|
|
|
} else {
|
|
|
|
Jailed = 1;
|
|
|
|
small_box.minx = info.pos.x - 10;
|
|
|
|
small_box.miny = info.pos.y - 10;
|
|
|
|
small_box.maxx = info.pos.x + 10;
|
|
|
|
small_box.maxy = info.pos.y + 10;
|
|
|
|
mouse_setbox (&small_box);
|
|
|
|
}
|
|
|
|
ShowState (Jailed, Invisible);
|
|
|
|
break;
|
|
|
|
|
2001-09-13 15:58:32 +00:00
|
|
|
case 's':
|
|
|
|
if (Invisible) {
|
2009-09-27 11:24:43 +00:00
|
|
|
ShowState (Jailed, --Invisible);
|
2001-09-13 15:58:32 +00:00
|
|
|
mouse_show ();
|
|
|
|
}
|
|
|
|
break;
|
2009-09-27 11:24:43 +00:00
|
|
|
|
2001-09-13 15:58:32 +00:00
|
|
|
case 'q':
|
|
|
|
Done = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2004-11-07 12:54:30 +00:00
|
|
|
/* Uninstall and unload the mouse driver */
|
|
|
|
CheckError ("mouse_unload", mouse_unload ());
|
|
|
|
|
|
|
|
/* Say goodbye */
|
2001-09-13 15:58:32 +00:00
|
|
|
clrscr ();
|
|
|
|
cputs ("Goodbye!\r\n");
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|