]> git.sur5r.net Git - cc65/blobdiff - samples/mousetest.c
Merge pull request #332 from greg-king5/interrupt-functions
[cc65] / samples / mousetest.c
index b2d49b072b2e96b342ee327fe878e8372d47f03e..3910d5a0a17d71cfa7ec0c2d3c102bd093916d60 100644 (file)
@@ -3,7 +3,7 @@
 ** Will work for the C64/C128/CBM510/Atari/Apple2.
 **
 ** 2001-09-13, Ullrich von Bassewitz
-** 2013-06-26, Greg King
+** 2013-09-05, Greg King
 **
 */
 
 #include <stdlib.h>
 #include <string.h>
 #include <mouse.h>
+#include <pen.h>
 #include <conio.h>
 #include <ctype.h>
 #include <dbg.h>
+#include <cc65.h>
 
 #define max(a,b)  (((a) > (b)) ? (a) : (b))
 #define min(a,b)  (((a) < (b)) ? (a) : (b))
 
 
 
-#if defined(__C64__) || defined(__C128__) || defined(__CBM510__)
+#ifdef __CBM__
 
-/* Addresses of data for sprite 0 */
-#if defined(__C64__)
-#  define SPRITE0_DATA  ((unsigned char[64])0x0340)
-#  define SPRITE0_PTR   ((unsigned char *)0x07F8)
-#elif defined(__C128__)
-#  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)
-#endif
+/* Set dark-on-light colors. */
+const unsigned char mouse_def_pointercolor = COLOR_BLACK;
 
-/* The mouse sprite (an arrow) */
-static const unsigned char MouseSprite[64] = {
-    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,
-    0x00, 0x00, 0x00,
-    0x00, 0x00, 0x00,
-    0x00, 0x00, 0x00,
-    0x00, 0x00, 0x00,
-    0x00, 0x00, 0x00,
-    0x00, 0x00, 0x00,
-    0x00, 0x00, 0x00,
-    0x00, 0x00, 0x00,
-    0x00, 0x00, 0x00
-};
 #endif
 
 
@@ -84,7 +53,14 @@ static const unsigned char MouseSprite[64] = {
 static void __fastcall__ CheckError (const char* S, unsigned char Error)
 {
     if (Error != MOUSE_ERR_OK) {
-        cprintf ("%s: %s(%u)\r\n", S, mouse_geterrormsg (Error), Error);
+        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.
+        */
+        if (doesclrscrafterexit ()) {
+            cgetc ();
+        }
         exit (EXIT_FAILURE);
     }
 }
@@ -153,31 +129,12 @@ int main (void)
     cursor (0);
     clrscr ();
 
-    /* The pointer is created before the driver is installed,
-    ** in case a lightpen driver needs it during calibration.
-    */
-
-#if defined(__C64__) || defined(__C128__) || defined(__CBM510__)
-    /* Copy the sprite data */
-    memcpy ((void*) SPRITE0_DATA, MouseSprite, sizeof (MouseSprite));
-
-    /* Set the VIC-II sprite pointer. */
-    *SPRITE0_PTR = ((unsigned) SPRITE0_DATA & 0x3FFF) / sizeof SPRITE0_DATA;
-
-    /* Set the color of sprite 0 */
-#  ifdef __CBM510__
-    pokebsys ((unsigned) &VIC.spr0_color, COLOR_BLACK);
-#  else
-    VIC.spr0_color = COLOR_BLACK;
-#  endif
-#endif
-
     /* 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.)
     */
-#ifdef __CBM__
+#if defined(__C64__) || defined(__C128__) || defined(__CBM510__)
     pen_adjust ("pen.dat");
 #endif
 
@@ -221,8 +178,13 @@ top:
 
     /* Put a cross at the center of the screen. */
     gotoxy (width / 2 - 3, height / 2 - 1);
+#if defined(__CBM__)
     cprintf ("%3u,%3u\r\n%*s\xDB", width / 2 * 8 + 4, height / 2 * 8 + 4,
              width / 2, "");
+#else
+    cprintf ("%3u,%3u\r\n%*s+", width / 2 * 8 + 4, height / 2 * 8 + 4,
+             width / 2, "");
+#endif
 
     /* Test loop */
     ShowState (Jailed, Invisible);