From: Greg King Date: Sun, 23 Jun 2013 15:47:45 +0000 (-0400) Subject: Renamed the mouse sample program because it also tests the mouse library. X-Git-Tag: V2.15~248^2~6 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=88c102b993d64fa9b74af6c1a74f992480d1d9a3;p=cc65 Renamed the mouse sample program because it also tests the mouse library. --- diff --git a/samples/Makefile b/samples/Makefile index 046eb8fc9..327adc482 100644 --- a/samples/Makefile +++ b/samples/Makefile @@ -78,7 +78,7 @@ EXELIST = ascii \ gunzip65 \ hello \ mandelbrot \ - mousedemo \ + mousetest \ multdemo \ nachtm \ ovrldemo \ @@ -115,12 +115,12 @@ mandelbrot: mandelbrot.o endif endif -# The Apple ][ needs the start address adjusted for the mousedemo +# The Apple ][ needs the start address adjusted for the mousetest ifeq "$(SYS)" "apple2" -mousedemo: mousedemo.o +mousetest: mousetest.o @$(LD) -t $(SYS) -m $(basename $@).map --start-addr 0x4000 -o $@ $^ $(CLIB) else -mousedemo: mousedemo.o +mousetest: mousetest.o endif multdemo: multidemo.o diff --git a/samples/README b/samples/README index 25ee43118..5997fc8d0 100644 --- a/samples/README +++ b/samples/README @@ -69,8 +69,8 @@ Platforms: Runs on all platforms that have TGI support: Apple ][, C64, C128, Oric Atmos, Geos and Lynx. ----------------------------------------------------------------------------- -Name: mousedemo -Description: Shows how to use the mouse. +Name: mousetest +Description: Tests and shows how to use the mouse. Platforms: All systems with mouse and conio support: C64, C128, CBM510, Atari, Apple ][ diff --git a/samples/mousedemo.c b/samples/mousedemo.c deleted file mode 100644 index d5d0e36a6..000000000 --- a/samples/mousedemo.c +++ /dev/null @@ -1,238 +0,0 @@ -/* - * Demo program for mouse usage. Will work for the C64/C128/CBM510/Atari/Apple2 - * - * Ullrich von Bassewitz, 13.09.2001 - * - */ - - - -#include -#include -#include -#include -#include -#include - - - -#if defined(__C64__) || defined(__C128__) - -/* Address of data for sprite 0 */ -#if defined(__C64__) -# define SPRITE0_DATA 0x0340 -# define SPRITE0_PTR 0x07F8 -#elif defined(__C128__) -# define SPRITE0_DATA 0x0E00 -# define SPRITE0_PTR 0x07F8 -#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__ */ - - -/* Dynamically loaded driver by default */ -#ifndef DYN_DRV -# define DYN_DRV 1 -#endif - - -#define max(a,b) (((a) > (b)) ? (a) : (b)) -#define min(a,b) (((a) < (b)) ? (a) : (b)) - - - -static void CheckError (const char* S, unsigned char Error) -{ - if (Error != MOUSE_ERR_OK) { - cprintf ("%s: %s(%d)\r\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 */ -{ - cprintf ("Warning: This program needs the mouse\r\n" - "driver with the name\r\n" - " %s\r\n" - "on disk! Press 'y' if you have it or\r\n" - "any other key to exit.\r\n", mouse_stddrv); - if (tolower (cgetc ()) != 'y') { - exit (EXIT_SUCCESS); - } - cprintf ("Ok. Please wait patiently...\r\n"); -} - - - -static void ShowState (unsigned char Jailed, unsigned char Invisible) -/* Display jail and cursor state */ -{ - gotoxy (0, 6); - cclear (40); - gotoxy (0, 6); - cprintf ("Mouse cursor %svisible%s", Invisible? "in" : "", Jailed? ", jailed" : ""); -} - - - -int main (void) -{ - struct mouse_info info; - struct mouse_box full_box; - struct mouse_box small_box; - unsigned char Invisible; - unsigned char Done; - unsigned char Jailed; - - /* Initialize the debugger */ - DbgInit (0); - - /* Clear the screen, set white on black */ - (void) bordercolor (COLOR_BLACK); - (void) bgcolor (COLOR_BLACK); - (void) textcolor (COLOR_GRAY3); - cursor (0); - clrscr (); - -#if defined(__C64__) || defined(__C128__) || defined(__CBM510__) - /* 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 */ -#ifdef __CBM510__ - pokebsys ((unsigned) &VIC.spr0_color, COLOR_WHITE); -#else - VIC.spr0_color = COLOR_WHITE; -#endif - -#endif - -#if DYN_DRV - /* Output a warning about the driver that is needed */ - DoWarning (); - - /* Load and install the mouse driver */ - CheckError ("mouse_load_driver", - mouse_load_driver (&mouse_def_callbacks, mouse_stddrv)); -#else - /* Install the mouse driver */ - CheckError ("mouse_install", - mouse_install (&mouse_def_callbacks, mouse_static_stddrv)); -#endif - - /* Get the initial mouse bounding box */ - mouse_getbox (&full_box); - - /* Print a help line */ - clrscr (); - revers (1); - cputsxy (0, 0, "d)ebug h)ide q)uit s)how j)ail "); - revers (0); - - /* Test loop */ - Done = 0; - Jailed = 0; - Invisible = 1; - ShowState (Jailed, Invisible); - while (!Done) { - - /* 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 */ - if (kbhit ()) { - switch (tolower (cgetc ())) { - - case 'd': - BREAK(); - break; - - case 'h': - ShowState (Jailed, ++Invisible); - mouse_hide (); - break; - - case 'j': - if (Jailed) { - Jailed = 0; - mouse_setbox (&full_box); - } else { - Jailed = 1; - 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); - mouse_setbox (&small_box); - } - ShowState (Jailed, Invisible); - break; - - case 's': - if (Invisible) { - ShowState (Jailed, --Invisible); - mouse_show (); - } - break; - - case 'q': - Done = 1; - break; - } - } - - } - -#if DYN_DRV - /* Uninstall and unload the mouse driver */ - CheckError ("mouse_unload", mouse_unload ()); -#else - /* Uninstall the mouse driver */ - CheckError ("mouse_uninstall", mouse_uninstall ()); -#endif - - /* Say goodbye */ - clrscr (); - cputs ("Goodbye!\r\n"); - - return EXIT_SUCCESS; -} diff --git a/samples/mousetest.c b/samples/mousetest.c new file mode 100644 index 000000000..d5d0e36a6 --- /dev/null +++ b/samples/mousetest.c @@ -0,0 +1,238 @@ +/* + * Demo program for mouse usage. Will work for the C64/C128/CBM510/Atari/Apple2 + * + * Ullrich von Bassewitz, 13.09.2001 + * + */ + + + +#include +#include +#include +#include +#include +#include + + + +#if defined(__C64__) || defined(__C128__) + +/* Address of data for sprite 0 */ +#if defined(__C64__) +# define SPRITE0_DATA 0x0340 +# define SPRITE0_PTR 0x07F8 +#elif defined(__C128__) +# define SPRITE0_DATA 0x0E00 +# define SPRITE0_PTR 0x07F8 +#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__ */ + + +/* Dynamically loaded driver by default */ +#ifndef DYN_DRV +# define DYN_DRV 1 +#endif + + +#define max(a,b) (((a) > (b)) ? (a) : (b)) +#define min(a,b) (((a) < (b)) ? (a) : (b)) + + + +static void CheckError (const char* S, unsigned char Error) +{ + if (Error != MOUSE_ERR_OK) { + cprintf ("%s: %s(%d)\r\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 */ +{ + cprintf ("Warning: This program needs the mouse\r\n" + "driver with the name\r\n" + " %s\r\n" + "on disk! Press 'y' if you have it or\r\n" + "any other key to exit.\r\n", mouse_stddrv); + if (tolower (cgetc ()) != 'y') { + exit (EXIT_SUCCESS); + } + cprintf ("Ok. Please wait patiently...\r\n"); +} + + + +static void ShowState (unsigned char Jailed, unsigned char Invisible) +/* Display jail and cursor state */ +{ + gotoxy (0, 6); + cclear (40); + gotoxy (0, 6); + cprintf ("Mouse cursor %svisible%s", Invisible? "in" : "", Jailed? ", jailed" : ""); +} + + + +int main (void) +{ + struct mouse_info info; + struct mouse_box full_box; + struct mouse_box small_box; + unsigned char Invisible; + unsigned char Done; + unsigned char Jailed; + + /* Initialize the debugger */ + DbgInit (0); + + /* Clear the screen, set white on black */ + (void) bordercolor (COLOR_BLACK); + (void) bgcolor (COLOR_BLACK); + (void) textcolor (COLOR_GRAY3); + cursor (0); + clrscr (); + +#if defined(__C64__) || defined(__C128__) || defined(__CBM510__) + /* 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 */ +#ifdef __CBM510__ + pokebsys ((unsigned) &VIC.spr0_color, COLOR_WHITE); +#else + VIC.spr0_color = COLOR_WHITE; +#endif + +#endif + +#if DYN_DRV + /* Output a warning about the driver that is needed */ + DoWarning (); + + /* Load and install the mouse driver */ + CheckError ("mouse_load_driver", + mouse_load_driver (&mouse_def_callbacks, mouse_stddrv)); +#else + /* Install the mouse driver */ + CheckError ("mouse_install", + mouse_install (&mouse_def_callbacks, mouse_static_stddrv)); +#endif + + /* Get the initial mouse bounding box */ + mouse_getbox (&full_box); + + /* Print a help line */ + clrscr (); + revers (1); + cputsxy (0, 0, "d)ebug h)ide q)uit s)how j)ail "); + revers (0); + + /* Test loop */ + Done = 0; + Jailed = 0; + Invisible = 1; + ShowState (Jailed, Invisible); + while (!Done) { + + /* 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 */ + if (kbhit ()) { + switch (tolower (cgetc ())) { + + case 'd': + BREAK(); + break; + + case 'h': + ShowState (Jailed, ++Invisible); + mouse_hide (); + break; + + case 'j': + if (Jailed) { + Jailed = 0; + mouse_setbox (&full_box); + } else { + Jailed = 1; + 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); + mouse_setbox (&small_box); + } + ShowState (Jailed, Invisible); + break; + + case 's': + if (Invisible) { + ShowState (Jailed, --Invisible); + mouse_show (); + } + break; + + case 'q': + Done = 1; + break; + } + } + + } + +#if DYN_DRV + /* Uninstall and unload the mouse driver */ + CheckError ("mouse_unload", mouse_unload ()); +#else + /* Uninstall the mouse driver */ + CheckError ("mouse_uninstall", mouse_uninstall ()); +#endif + + /* Say goodbye */ + clrscr (); + cputs ("Goodbye!\r\n"); + + return EXIT_SUCCESS; +}