]> git.sur5r.net Git - cc65/blobdiff - include/mouse.h
Make mouse driver loadable
[cc65] / include / mouse.h
index 6af499baecc1a6a6d9dd093346483fc08dc492f5..cdc3053153149c0d5533646a09235872d8dd2948 100644 (file)
@@ -1,8 +1,37 @@
-/*
- * mouse.h
- *
- * Ullrich von Bassewitz, 24.04.1999
- */
+/*****************************************************************************/
+/*                                                                           */
+/*                                 mouse.h                                  */
+/*                                                                           */
+/*                                Mouse API                                 */
+/*                                                                           */
+/*                                                                           */
+/*                                                                           */
+/* (C) 2003      Ullrich von Bassewitz                                       */
+/*               Römerstraße 52                                              */
+/*               D-70794 Filderstadt                                         */
+/* EMail:        uz@cc65.org                                                 */
+/*                                                                           */
+/*                                                                           */
+/*                                                                           */
+/*                                                                           */
+/* This software is provided 'as-is', without any expressed or implied       */
+/* warranty.  In no event will the authors be held liable for any damages    */
+/* arising from the use of this software.                                    */
+/*                                                                           */
+/* Permission is granted to anyone to use this software for any purpose,     */
+/* including commercial applications, and to alter it and redistribute it    */
+/* freely, subject to the following restrictions:                            */
+/*                                                                           */
+/* 1. The origin of this software must not be misrepresented; you must not   */
+/*    claim that you wrote the original software. If you use this software   */
+/*    in a product, an acknowledgment in the product documentation would be  */
+/*    appreciated but is not required.                                       */
+/* 2. Altered source versions must be plainly marked as such, and must not   */
+/*    be misrepresented as being the original software.                      */
+/* 3. This notice may not be removed or altered from any source              */
+/*    distribution.                                                          */
+/*                                                                           */
+/*****************************************************************************/
 
 
 
 
 
 
-/* Define __MOUSE__ for systems that support a proportional mouse */
-#ifdef __C64__
-#  define __MOUSE__
-#endif
-#ifdef __C128__
-#  define __MOUSE__
-#endif
+/*****************************************************************************/
+/*                               Definitions                                */
+/*****************************************************************************/
 
 
 
-void __fastcall__ mouse_init (unsigned char port, unsigned char sprite);
-/* Setup the mouse interrupt handler. If the sprite value is != zero, the
- * mouse routines will manage the sprite with this number. That means, it
- * is moved if the mouse is moved (provided that the mouse cursor is visible),
- * and switch on and off in the show and hide functions.
- * The port parameter gives the joystick port used for the mouse and is only
- * needed to read the mouse button state.
- * After calling this function, the mouse is invisble, the cursor is placed
- * at 0/0 (upper left corner), and the bounding box is reset to cover the
- * whole screen. Call mouse_show once to make the mouse cursor visible.
- */
+/* Error codes */
+#define MOUSE_ERR_OK            0       /* No error */
+#define MOUSE_ERR_NO_DRIVER     1       /* No driver available */
+#define MOUSE_ERR_CANNOT_LOAD   2       /* Error loading driver */
+#define MOUSE_ERR_INV_DRIVER    3       /* Invalid driver */
+#define MOUSE_ERR_NO_DEVICE     4       /* Mouse hardware not found */
+
+/* Mouse button masks */
+#define MOUSE_BTN_LEFT      0x10
+#define MOUSE_BTN_RIGHT      0x01
 
-void mouse_done (void);
-/* Disable the mouse, remove the interrupt handler. This function MUST be
- * called before terminating the program, otherwise odd things may happen.
- * If in doubt, install an exit handler (using atexit) that calls this
- * function.
+/* Structure containing the mouse coordinates */
+struct mouse_pos {
+    int x;
+    int y;
+};
+
+/* Structure containing information about the mouse */
+struct mouse_info {
+    struct mouse_pos    pos;           /* Mouse position */
+    unsigned char       buttons;       /* Mouse button mask */
+};
+
+/* Structure containing mouse callback functions. These functions are declared
+ * in C notation here, but they cannot be C functions (at least not easily),
+ * since they may be called from within an interrupt.
  */
+struct mouse_callbacks {
+
+    void (*hide) (void);
+    /* Hide the mouse cursor. */
+
+    void (*show) (void);
+    /* Show the mouse cursor */
+
+    void (*move) (void);
+    /* Move the mouse cursor. This function is called, even when the cursor
+     * is currently invisible.
+     */
+};
+
 
-void mouse_hide (void);
-/* Hide the mouse. This function doesn't do anything visible if no sprite is
- * used. The function manages a counter and may be called more than once.
- * For each call to mouse_hide there must be a call to mouse_show to make
+
+/*****************************************************************************/
+/*                                Functions                                 */
+/*****************************************************************************/
+
+
+
+unsigned char __fastcall__ mouse_set_callbacks (const struct mouse_callbacks* c);
+/* Sets the callbacks to be used by the driver. */
+
+unsigned char __fastcall__ mouse_load_driver (const char* driver);
+/* Load and install a mouse driver, return an error code. */
+
+unsigned char __fastcall__ mouse_unload (void);
+/* Uninstall, then unload the currently loaded driver. */
+
+unsigned char __fastcall__ mouse_install (void* driver);
+/* Install an already loaded driver. Returns an error code. */
+
+unsigned char __fastcall__ mouse_uninstall (void);
+/* Uninstall the currently loaded driver. Returns an error code. */
+
+void __fastcall__ mouse_hide (void);
+/* Hide the mouse. The function manages a counter and may be called more than
+ * once. For each call to mouse_hide there must be a call to mouse_show to make
  * the mouse visible again.
  */
 
-void mouse_show (void);
-/* Show the mouse. This function doesn't do anything visible if no sprite is
- * used. See mouse_hide for more information.
- */
+void __fastcall__ mouse_show (void);
+/* Show the mouse. See mouse_hide for more information. */
 
 void __fastcall__ mouse_box (int minx, int miny, int maxx, int maxy);
 /* Set the bounding box for the mouse pointer movement. The mouse X and Y
@@ -75,10 +142,17 @@ void __fastcall__ mouse_move (int x, int y);
  * inside the bounding box.
  */
 
-void mouse_info (void);
-/* Hmmm...
+unsigned char __fastcall__ mouse_buttons (void);
+/* Return a bit mask encoding the states of the mouse buttons. Use the
+ * MOUSE_BTN_XXX flags to decode a specific button.
  */
 
+void __fastcall__ mouse_pos (struct mouse_pos* pos);
+/* Return the current mouse position */
+
+void __fastcall__ mouse_info (struct mouse_info* info);
+/* Return the state of the mouse buttons and the position of the mouse */
+
 
 
 /* End of mouse.h */