]> git.sur5r.net Git - cc65/blobdiff - samples/mousedemo.c
The _printf routine does not return anything.
[cc65] / samples / mousedemo.c
index 07998f85f82707e865f6c48c067c8ec5d91f8dc5..96b39eea4060b7bb46a5fe4e3cef5b8a63393b03 100644 (file)
@@ -1,29 +1,31 @@
 /*
- * Demo program for mouse usage. Will work for the C64/C128/Atari
- * 
+ * Demo program for mouse usage. Will work for the C64/C128/CBM510/Atari/Apple2
+ *
  * Ullrich von Bassewitz, 13.09.2001
  *
  */
 
 
 
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <mouse.h>
 #include <conio.h>
+#include <ctype.h>
 #include <dbg.h>
 
 
 
 #if defined(__C64__) || defined(__C128__)
 
-/* Address of data for sprite 1 */
+/* Address of data for sprite 0 */
 #if defined(__C64__)
-#  define SPRITE0_DATA    0x340
-#  define SPRITE0_PTR            0x7F8
+#  define SPRITE0_DATA    0x0340
+#  define SPRITE0_PTR            0x07F8
 #elif defined(__C128__)
-#  define SPRITE0_DATA    0xE00
-#  define SPRITE0_PTR     0x7F8
+#  define SPRITE0_DATA    0x0E00
+#  define SPRITE0_PTR     0x07F8
 #endif
 
 /* The mouse sprite (an arrow) */
@@ -56,6 +58,32 @@ static const unsigned char MouseSprite[64] = {
 
 
 
+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"
+            "any other key to exit.\n", mouse_stddrv);
+    if (tolower (cgetc ()) != 'y') {
+        exit (EXIT_SUCCESS);
+    }
+    printf ("Ok. Please wait patiently...\n");
+}
+
+
+
 static void ShowState (unsigned char Invisible)
 /* Display cursor visibility */
 {
@@ -76,19 +104,17 @@ int main (void)
     /* Initialize the debugger */
     DbgInit (0);
 
+    /* Output a warning about the driver that is needed */
+    DoWarning ();
+
     /* Clear the screen, set white on black */
-    bordercolor (COLOR_BLACK);
-    bgcolor (COLOR_BLACK);
-    textcolor (COLOR_GRAY3);
+    (void) bordercolor (COLOR_BLACK);
+    (void) bgcolor (COLOR_BLACK);
+    (void) textcolor (COLOR_GRAY3);
     cursor (0);
     clrscr ();
 
-    /* Print a help line */
-    revers (1);
-    cputsxy (0, 0, "d: debug   h: hide   q: quit   s: show  ");
-    revers (0);
-
-#if defined(__C64__) || defined(__C128__)
+#if defined(__C64__) || defined(__C128__) || defined(__CBM510__)
     /* Copy the sprite data */
     memcpy ((void*) SPRITE0_DATA, MouseSprite, sizeof (MouseSprite));
 
@@ -96,24 +122,29 @@ int main (void)
     *(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
 
-    /* Initialize the mouse */
-    mouse_init (MOUSE_C64);
-
-#elif defined(__ATARI__)
+#endif
 
-    /* Initialize the mouse */
-    mouse_init (MOUSE_TRAKBALL);
+    /* Load and install the mouse driver */
+    CheckError ("mouse_load_driver",
+                mouse_load_driver (&mouse_def_callbacks, mouse_stddrv));
 
-#endif
+    /* Print a help line */
+    revers (1);
+    cputsxy (0, 0, "d: debug   h: hide   q: quit   s: show  ");
+    revers (0);
 
     /* Test loop */
     Done = 0;
     ShowState (Invisible = 1);
     while (!Done) {
-       if (kbhit()) {
-           switch (cgetc()) {
+       if (kbhit ()) {
+           switch (tolower (cgetc ())) {
                case 'd':
                    BREAK();
                    break;
@@ -146,7 +177,10 @@ int main (void)
 
     }
 
-    mouse_done ();
+    /* Uninstall and unload the mouse driver */
+    CheckError ("mouse_unload", mouse_unload ());
+
+    /* Say goodbye */
     clrscr ();
     cputs ("Goodbye!\r\n");