]> git.sur5r.net Git - cc65/blobdiff - samples/mousedemo.c
Added an additional precondition before replacing code in OptPushPop. Fixed a
[cc65] / samples / mousedemo.c
index c8dc6302c962443b5975963e0a7203bcffc48ecd..effc667160ea9f0e43bb7816e0e82ba222f35ab1 100644 (file)
 
 
 
-#if defined(__C64__) || defined(__C128__) || defined(__CBM510__)
+#if defined(__C64__) || defined(__C128__)
 
 /* Address of data for sprite 0 */
 #if defined(__C64__)
 #  define SPRITE0_DATA    0x0340
 #  define SPRITE0_PTR            0x07F8
-#  define DRIVER          "c64-1351.mou"
 #elif defined(__C128__)
 #  define SPRITE0_DATA    0x0E00
 #  define SPRITE0_PTR     0x07F8
-#  define DRIVER          "c128-1351.mou"
-#elif defined(__CBM510__)
-#  define SPRITE0_DATA    0xF400
-#  define SPRITE0_PTR     0xF3F8
-#  define DRIVER          ""            /* Currently unavailable */
 #endif
 
 /* The mouse sprite (an arrow) */
@@ -62,13 +56,9 @@ static const unsigned char MouseSprite[64] = {
 
 #endif  /* __C64__ or __C128__ */
 
-#ifdef __APPLE2__
-#  define DRIVER  "a2.stdmou.mou"
-#endif
 
-#ifdef __APPLE2ENH__
-#  define DRIVER  "a2e.stdmou.mou"
-#endif
+#define max(a,b)  (((a) > (b)) ? (a) : (b))\r
+#define min(a,b)  (((a) < (b)) ? (a) : (b))\r
 
 
 
@@ -89,7 +79,7 @@ static void DoWarning (void)
             "driver with the name\n"
             "    %s\n"
             "on disk! Press 'y' if you have it or\n"
-            "any other key to exit.\n", DRIVER);
+            "any other key to exit.\n", mouse_stddrv);
     if (tolower (cgetc ()) != 'y') {
         exit (EXIT_SUCCESS);
     }
@@ -98,13 +88,13 @@ static void DoWarning (void)
 
 
 
-static void ShowState (unsigned char Invisible)
-/* Display cursor visibility */
+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", Invisible? "in" : "");
+    cprintf ("Mouse cursor %svisible%s", Invisible? "in" : "", Jailed? ", jailed" : "");
 }
 
 
@@ -112,8 +102,11 @@ static void ShowState (unsigned char Invisible)
 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);
@@ -145,49 +138,76 @@ int main (void)
 #endif
 
     /* Load and install the mouse driver */
-    CheckError ("mouse_load_driver", mouse_load_driver (&mouse_def_callbacks, DRIVER));
+    CheckError ("mouse_load_driver",
+                mouse_load_driver (&mouse_def_callbacks, mouse_stddrv));
+
+    /* Get the initial mouse bounding box */
+    mouse_getbox (&full_box);
 
     /* Print a help line */
     revers (1);
-    cputsxy (0, 0, "d: debug   h: hide   q: quit   s: show  ");
+    cputsxy (0, 0, "d)ebug  h)ide   q)uit   s)how   j)ail   ");
     revers (0);
 
     /* Test loop */
     Done = 0;
-    ShowState (Invisible = 1);
+    Jailed = 0;
+    Invisible = 1;
+    ShowState (Jailed, Invisible);
     while (!Done) {
-       if (kbhit ()) {                
+
+       /* 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 (++Invisible);
+                   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 (--Invisible);
+                       ShowState (Jailed, --Invisible);
                        mouse_show ();
                    }
                    break;
+
                case 'q':
                    Done = 1;
                    break;
            }
        }
 
-       /* 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');
-
     }
 
     /* Uninstall and unload the mouse driver */