2001-09-13 15:58:32 +00:00
|
|
|
/*
|
2013-06-27 14:01:47 +00:00
|
|
|
** Test/demo program for mouse usage.
|
|
|
|
** Will work for the C64/C128/CBM510/Atari/Apple2.
|
|
|
|
**
|
|
|
|
** 2001-09-13, Ullrich von Bassewitz
|
2013-09-09 21:09:33 +00:00
|
|
|
** 2013-09-05, Greg King
|
2013-06-27 14:01:47 +00:00
|
|
|
**
|
|
|
|
*/
|
2001-09-13 15:58:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2013-06-27 14:01:47 +00:00
|
|
|
#include <stdbool.h>
|
2001-09-13 15:58:32 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <mouse.h>
|
2013-07-25 17:32:40 +00:00
|
|
|
#include <pen.h>
|
2001-09-13 15:58:32 +00:00
|
|
|
#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>
|
|
|
|
|
2013-06-27 14:01:47 +00:00
|
|
|
#define max(a,b) (((a) > (b)) ? (a) : (b))
|
|
|
|
#define min(a,b) (((a) < (b)) ? (a) : (b))
|
|
|
|
|
|
|
|
|
2001-09-13 15:58:32 +00:00
|
|
|
|
2013-06-27 14:01:47 +00:00
|
|
|
#ifdef MOUSE_DRIVER
|
|
|
|
|
|
|
|
/* A statically linked driver was named on the compiler's command line.
|
|
|
|
** Make sure that it is used instead of a dynamic one.
|
|
|
|
*/
|
|
|
|
# undef DYN_DRV
|
|
|
|
# define DYN_DRV 0
|
2014-06-04 21:50:46 +00:00
|
|
|
#else
|
|
|
|
|
|
|
|
/* Use a dynamically loaded driver, by default. */
|
|
|
|
# ifndef DYN_DRV
|
|
|
|
# define DYN_DRV 1
|
|
|
|
# endif
|
2013-06-27 14:01:47 +00:00
|
|
|
#endif
|
2001-09-13 15:58:32 +00:00
|
|
|
|
|
|
|
|
2013-06-27 14:01:47 +00:00
|
|
|
|
|
|
|
#if defined(__C64__) || defined(__C128__) || defined(__CBM510__)
|
|
|
|
|
|
|
|
/* Addresses of data for sprite 0 */
|
2001-09-13 15:58:32 +00:00
|
|
|
#if defined(__C64__)
|
2013-06-27 14:01:47 +00:00
|
|
|
# define SPRITE0_DATA ((unsigned char[64])0x0340)
|
|
|
|
# define SPRITE0_PTR ((unsigned char *)0x07F8)
|
2001-09-13 15:58:32 +00:00
|
|
|
#elif defined(__C128__)
|
2013-06-27 14:01:47 +00:00
|
|
|
# define SPRITE0_DATA ((unsigned char[64])0x0E00)
|
|
|
|
# define SPRITE0_PTR ((unsigned char *)0x07F8)
|
|
|
|
#elif defined(__CBM510__)
|
|
|
|
# define SPRITE0_DATA ((unsigned char[64])0xF400)
|
|
|
|
# define SPRITE0_PTR ((unsigned char *)0xF3F8)
|
2001-09-13 15:58:32 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* The mouse sprite (an arrow) */
|
|
|
|
static const unsigned char MouseSprite[64] = {
|
2013-06-27 14:01:47 +00:00
|
|
|
0xFE, 0x00, 0x00,
|
|
|
|
0xFC, 0x00, 0x00,
|
|
|
|
0xF8, 0x00, 0x00,
|
|
|
|
0xFC, 0x00, 0x00,
|
|
|
|
0xDE, 0x00, 0x00,
|
|
|
|
0x8F, 0x00, 0x00,
|
|
|
|
0x07, 0x80, 0x00,
|
|
|
|
0x03, 0xC0, 0x00,
|
|
|
|
0x01, 0xE0, 0x00,
|
|
|
|
0x00, 0xF0, 0x00,
|
|
|
|
0x00, 0x78, 0x00,
|
|
|
|
0x00, 0x38, 0x00,
|
2001-09-13 15:58:32 +00:00
|
|
|
0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00,
|
2013-06-27 14:01:47 +00:00
|
|
|
0x00, 0x00, 0x00
|
2001-09-13 15:58:32 +00:00
|
|
|
};
|
2012-11-04 22:01:51 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2009-09-27 22:33:12 +00:00
|
|
|
|
2013-06-27 14:01:47 +00:00
|
|
|
static void __fastcall__ CheckError (const char* S, unsigned char Error)
|
2004-11-07 12:54:30 +00:00
|
|
|
{
|
|
|
|
if (Error != MOUSE_ERR_OK) {
|
2013-08-23 07:12:16 +00:00
|
|
|
cprintf ("\n%s: %s(%u)\r\n", S, mouse_geterrormsg (Error), Error);
|
|
|
|
|
|
|
|
/* Wait for a key-press, so that some platforms can show the error
|
|
|
|
** message before they remove the current screen.
|
|
|
|
*/
|
|
|
|
cgetc();
|
2004-11-07 12:54:30 +00:00
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-06-27 14:01:47 +00:00
|
|
|
#if DYN_DRV
|
|
|
|
|
|
|
|
/* Points to the dynamic driver's name. */
|
|
|
|
static const char *mouse_name;
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-11-07 12:54:30 +00:00
|
|
|
static void DoWarning (void)
|
2013-06-27 14:01:47 +00:00
|
|
|
/* Warn the user that a driver is needed for this program. */
|
2004-11-07 12:54:30 +00:00
|
|
|
{
|
2013-06-27 14:01:47 +00:00
|
|
|
cprintf ("Warning: This program needs\r\n"
|
|
|
|
"the driver with the name\r\n"
|
2012-11-04 21:10:24 +00:00
|
|
|
" %s\r\n"
|
2013-06-27 14:01:47 +00:00
|
|
|
"on a disk! Press 'y' if you have it;\r\n"
|
|
|
|
"or, any other key to exit.\r\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);
|
|
|
|
}
|
2013-06-27 14:01:47 +00:00
|
|
|
cprintf ("OK. Please wait patiently...\r\n");
|
2004-11-07 12:54:30 +00:00
|
|
|
}
|
2013-06-27 14:01:47 +00:00
|
|
|
#endif
|
2004-11-07 12:54:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2013-06-27 14:01:47 +00:00
|
|
|
static void __fastcall__ ShowState (unsigned char Jailed, unsigned char Invisible)
|
|
|
|
/* Display jail and cursor states. */
|
2001-09-13 15:58:32 +00:00
|
|
|
{
|
2013-06-27 14:01:47 +00:00
|
|
|
cclearxy (0, 7, 32);
|
|
|
|
gotoxy (0, 7);
|
|
|
|
cprintf ("Pointer is %svisible%s.", Invisible? "in" : "", Jailed? " and jailed" : "");
|
2001-09-13 15:58:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-06-27 14:01:47 +00:00
|
|
|
#if DYN_DRV
|
|
|
|
int main (int argc, char *argv[])
|
|
|
|
#else
|
2001-09-13 15:58:32 +00:00
|
|
|
int main (void)
|
2013-06-27 14:01:47 +00:00
|
|
|
#endif
|
2001-09-13 15:58:32 +00:00
|
|
|
{
|
|
|
|
struct mouse_info info;
|
2013-06-27 14:01:47 +00:00
|
|
|
struct mouse_box full_box, small_box;
|
|
|
|
unsigned char width, height;
|
|
|
|
char C;
|
|
|
|
bool Invisible = true, Done = false, Jailed = false;
|
2001-09-13 15:58:32 +00:00
|
|
|
|
|
|
|
/* Initialize the debugger */
|
|
|
|
DbgInit (0);
|
|
|
|
|
2013-06-27 14:01:47 +00:00
|
|
|
/* Set dark-on-light colors. Clear the screen. */
|
|
|
|
#ifdef __CBM__
|
|
|
|
(void) bordercolor (COLOR_GRAY2);
|
|
|
|
(void) bgcolor (COLOR_WHITE);
|
|
|
|
(void) textcolor (COLOR_GRAY1);
|
|
|
|
#else
|
|
|
|
(void) bordercolor (COLOR_BLUE);
|
|
|
|
(void) bgcolor (COLOR_WHITE);
|
|
|
|
(void) textcolor (COLOR_BLACK);
|
|
|
|
#endif
|
2001-09-13 15:58:32 +00:00
|
|
|
cursor (0);
|
|
|
|
clrscr ();
|
|
|
|
|
2013-08-23 07:12:16 +00:00
|
|
|
/* The pointer should be created before the driver is installed,
|
2013-06-27 14:01:47 +00:00
|
|
|
** in case a lightpen driver needs it during calibration.
|
|
|
|
*/
|
|
|
|
|
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));
|
|
|
|
|
2013-06-27 14:01:47 +00:00
|
|
|
/* Set the VIC-II sprite pointer. */
|
|
|
|
*SPRITE0_PTR = ((unsigned) SPRITE0_DATA & 0x3FFF) / sizeof SPRITE0_DATA;
|
2001-09-13 15:58:32 +00:00
|
|
|
|
|
|
|
/* Set the color of sprite 0 */
|
2013-06-27 14:01:47 +00:00
|
|
|
# ifdef __CBM510__
|
|
|
|
pokebsys ((unsigned) &VIC.spr0_color, COLOR_BLACK);
|
|
|
|
# else
|
|
|
|
VIC.spr0_color = COLOR_BLACK;
|
|
|
|
# endif
|
2001-09-20 14:08:24 +00:00
|
|
|
#endif
|
2001-09-13 15:58:32 +00:00
|
|
|
|
2013-06-27 14:01:47 +00:00
|
|
|
/* If a lightpen driver is installed, then it can get a calibration value
|
|
|
|
** from this file (if it exists). Or, the user can adjust the pen; and,
|
|
|
|
** the value will be put into this file, for the next time.
|
|
|
|
** (Other drivers will ignore this.)
|
|
|
|
*/
|
2013-09-09 21:09:33 +00:00
|
|
|
#if defined(__C64__) || defined(__C128__) || defined(__CBM510__)
|
2013-06-27 14:01:47 +00:00
|
|
|
pen_adjust ("pen.dat");
|
2001-09-13 15:58:32 +00:00
|
|
|
#endif
|
|
|
|
|
2012-11-04 22:01:51 +00:00
|
|
|
#if DYN_DRV
|
2013-06-27 14:01:47 +00:00
|
|
|
/* If a dynamically loadable driver is named on the command line,
|
|
|
|
** then use that driver instead of the standard one.
|
|
|
|
*/
|
|
|
|
if (argc > 1) {
|
|
|
|
mouse_name = argv[1];
|
|
|
|
} else {
|
|
|
|
/* Output a warning about the standard driver that is needed. */
|
|
|
|
DoWarning ();
|
|
|
|
mouse_name = mouse_stddrv;
|
|
|
|
}
|
2012-11-04 21:10:24 +00:00
|
|
|
|
2013-06-27 14:01:47 +00:00
|
|
|
/* Load and install the driver. */
|
2009-09-11 16:55:20 +00:00
|
|
|
CheckError ("mouse_load_driver",
|
2013-06-27 14:01:47 +00:00
|
|
|
mouse_load_driver (&mouse_def_callbacks, mouse_name));
|
2012-11-04 22:01:51 +00:00
|
|
|
#else
|
2013-06-27 14:01:47 +00:00
|
|
|
/* Install the driver. */
|
2012-11-04 22:01:51 +00:00
|
|
|
CheckError ("mouse_install",
|
2013-06-27 14:01:47 +00:00
|
|
|
mouse_install (&mouse_def_callbacks,
|
|
|
|
# ifdef MOUSE_DRIVER
|
|
|
|
MOUSE_DRIVER
|
|
|
|
# else
|
|
|
|
mouse_static_stddrv
|
|
|
|
# endif
|
|
|
|
));
|
2012-11-04 22:01:51 +00:00
|
|
|
#endif
|
2004-11-07 12:54:30 +00:00
|
|
|
|
2013-06-27 14:01:47 +00:00
|
|
|
/* Get the initial bounding box. */
|
2009-09-27 11:24:43 +00:00
|
|
|
mouse_getbox (&full_box);
|
|
|
|
|
2013-06-27 14:01:47 +00:00
|
|
|
screensize (&width, &height);
|
|
|
|
|
|
|
|
top:
|
2012-11-04 21:10:24 +00:00
|
|
|
clrscr ();
|
2013-06-27 14:01:47 +00:00
|
|
|
|
|
|
|
/* Print a help line */
|
|
|
|
cputs (" d)ebug h)ide q)uit s)how j)ail");
|
|
|
|
|
|
|
|
/* Put a cross at the center of the screen. */
|
|
|
|
gotoxy (width / 2 - 3, height / 2 - 1);
|
2013-08-23 07:12:16 +00:00
|
|
|
#if defined(__CBM__)
|
2013-06-27 14:01:47 +00:00
|
|
|
cprintf ("%3u,%3u\r\n%*s\xDB", width / 2 * 8 + 4, height / 2 * 8 + 4,
|
|
|
|
width / 2, "");
|
2013-08-23 07:12:16 +00:00
|
|
|
#else
|
|
|
|
cprintf ("%3u,%3u\r\n%*s+", width / 2 * 8 + 4, height / 2 * 8 + 4,
|
|
|
|
width / 2, "");
|
|
|
|
#endif
|
2001-12-10 23:49:42 +00:00
|
|
|
|
2001-09-13 15:58:32 +00:00
|
|
|
/* Test loop */
|
2009-09-27 11:24:43 +00:00
|
|
|
ShowState (Jailed, Invisible);
|
2013-06-27 14:01:47 +00:00
|
|
|
do {
|
|
|
|
/* Get the current co-ordinates and button states; and, print them. */
|
2012-11-04 21:10:24 +00:00
|
|
|
mouse_info (&info);
|
|
|
|
gotoxy (0, 2);
|
2013-06-27 14:01:47 +00:00
|
|
|
cprintf (" X = %3d\r\n", info.pos.x);
|
|
|
|
cprintf (" Y = %3d\r\n", info.pos.y);
|
|
|
|
cprintf (" B1 = %c\r\n", (info.buttons & MOUSE_BTN_LEFT) ?
|
|
|
|
#ifdef __CBM__
|
|
|
|
0x5F
|
|
|
|
#else
|
|
|
|
'v'
|
|
|
|
#endif
|
|
|
|
: '^');
|
|
|
|
cprintf (" B2 = %c", (info.buttons & MOUSE_BTN_RIGHT) ?
|
|
|
|
#ifdef __CBM__
|
|
|
|
0x5F
|
|
|
|
#else
|
|
|
|
'v'
|
|
|
|
#endif
|
|
|
|
: '^');
|
2009-09-27 11:24:43 +00:00
|
|
|
|
|
|
|
/* Handle user input */
|
2012-11-04 21:10:24 +00:00
|
|
|
if (kbhit ()) {
|
2013-06-27 14:01:47 +00:00
|
|
|
cclearxy (1, 9, 23);
|
|
|
|
switch (tolower (C = cgetc ())) {
|
2012-11-04 21:10:24 +00:00
|
|
|
case 'd':
|
|
|
|
BREAK();
|
2013-06-27 14:01:47 +00:00
|
|
|
|
|
|
|
/* The debugger might have changed the colors.
|
|
|
|
** Restore them.
|
|
|
|
*/
|
|
|
|
#ifdef __CBM__
|
|
|
|
(void) bordercolor (COLOR_GRAY2);
|
|
|
|
(void) bgcolor (COLOR_WHITE);
|
|
|
|
(void) textcolor (COLOR_GRAY1);
|
|
|
|
#else
|
|
|
|
(void) bordercolor (COLOR_BLUE);
|
|
|
|
(void) bgcolor (COLOR_WHITE);
|
|
|
|
(void) textcolor (COLOR_BLACK);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* The debugger changed the screen; restore it. */
|
|
|
|
goto top;
|
2009-09-27 11:24:43 +00:00
|
|
|
|
2012-11-04 21:10:24 +00:00
|
|
|
case 'h':
|
|
|
|
mouse_hide ();
|
2013-06-27 14:01:47 +00:00
|
|
|
ShowState (Jailed, ++Invisible);
|
2012-11-04 21:10:24 +00:00
|
|
|
break;
|
2009-09-27 11:24:43 +00:00
|
|
|
|
|
|
|
case 'j':
|
|
|
|
if (Jailed) {
|
|
|
|
mouse_setbox (&full_box);
|
2013-06-27 14:01:47 +00:00
|
|
|
Jailed = false;
|
2009-09-27 11:24:43 +00:00
|
|
|
} else {
|
2009-09-27 22:33:12 +00:00
|
|
|
small_box.minx = max (info.pos.x - 10, full_box.minx);
|
|
|
|
small_box.miny = max (info.pos.y - 10, full_box.miny);
|
|
|
|
small_box.maxx = min (info.pos.x + 10, full_box.maxx);
|
|
|
|
small_box.maxy = min (info.pos.y + 10, full_box.maxy);
|
2009-09-27 11:24:43 +00:00
|
|
|
mouse_setbox (&small_box);
|
2013-06-27 14:01:47 +00:00
|
|
|
Jailed = true;
|
2009-09-27 11:24:43 +00:00
|
|
|
}
|
|
|
|
ShowState (Jailed, Invisible);
|
|
|
|
break;
|
|
|
|
|
2012-11-04 21:10:24 +00:00
|
|
|
case 's':
|
2013-06-27 14:01:47 +00:00
|
|
|
mouse_show ();
|
2012-11-04 21:10:24 +00:00
|
|
|
if (Invisible) {
|
|
|
|
ShowState (Jailed, --Invisible);
|
|
|
|
}
|
|
|
|
break;
|
2009-09-27 11:24:43 +00:00
|
|
|
|
2012-11-04 21:10:24 +00:00
|
|
|
case 'q':
|
2013-06-27 14:01:47 +00:00
|
|
|
Done = true;
|
2012-11-04 21:10:24 +00:00
|
|
|
break;
|
2013-06-27 14:01:47 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
gotoxy (1, 9);
|
|
|
|
cprintf ("Spurious character: $%02X", C);
|
2012-11-04 21:10:24 +00:00
|
|
|
}
|
|
|
|
}
|
2013-06-27 14:01:47 +00:00
|
|
|
} while (!Done);
|
2001-09-13 15:58:32 +00:00
|
|
|
|
2012-11-04 22:01:51 +00:00
|
|
|
#if DYN_DRV
|
2013-06-27 14:01:47 +00:00
|
|
|
/* Uninstall and unload the driver. */
|
2004-11-07 12:54:30 +00:00
|
|
|
CheckError ("mouse_unload", mouse_unload ());
|
2012-11-04 22:01:51 +00:00
|
|
|
#else
|
2013-06-27 14:01:47 +00:00
|
|
|
/* Uninstall the static driver. */
|
2012-11-04 22:01:51 +00:00
|
|
|
CheckError ("mouse_uninstall", mouse_uninstall ());
|
|
|
|
#endif
|
2004-11-07 12:54:30 +00:00
|
|
|
|
|
|
|
/* Say goodbye */
|
2013-06-27 14:01:47 +00:00
|
|
|
cputsxy (0, height / 2 + 3, "Goodbye!");
|
2001-09-13 15:58:32 +00:00
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|