]> git.sur5r.net Git - cc65/commitdiff
Fixed a problem when loading joystick drivers: When an install error occurred,
authorcuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sun, 4 Jun 2006 10:15:18 +0000 (10:15 +0000)
committercuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sun, 4 Jun 2006 10:15:18 +0000 (10:15 +0000)
the driver wasn't removed from memory.

git-svn-id: svn://svn.cc65.org/cc65/trunk@3752 b7a2c559-68d2-44c3-8de9-860c34a00d81

asminc/joy-kernel.inc
include/joystick/joy-kernel.h
libsrc/joystick/joy-kernel.s
libsrc/joystick/joy_load.c

index 7f600ed1b9bf03c978ef5a75ee12db98102e51a7..048517a689ba637f30bcf3f4a872d70d78f53b99 100644 (file)
@@ -6,10 +6,10 @@
 ;/*                                                                           */
 ;/*                                                                           */
 ;/*                                                                           */
-;/* (C) 2002      Ullrich von Bassewitz                                       */
-;/*               Wacholderweg 14                                             */
-;/*               D-70597 Stuttgart                                           */
-;/* EMail:        uz@musoftware.de                                            */
+;/* (C) 2002-2006, 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       */
@@ -80,4 +80,5 @@ JOY_API_VERSION         = $01
                .global _joy_count
                .global _joy_read
 
+        .global _joy_clear_ptr
 
index 7c3d7f889f967ea6b40bacf9aa0a1e9f206469cd..d57ad5dc76b8d12dfd1ccebee50ccfa9a0fe8461 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2002-2004 Ullrich von Bassewitz                                       */
-/*               Römerstrasse 52                                             */
-/*               D-70794 Filderstadt                                         */
-/* EMail:        uz@cc65.org                                                 */
+/* (C) 2002-2006, Ullrich von Bassewitz                                      */
+/*                Römerstrasse 52                                            */
+/*                D-70794 Filderstadt                                        */
+/* EMail:         uz@cc65.org                                                */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
@@ -72,6 +72,17 @@ extern joy_drv_header*       joy_drv;        /* Pointer to driver */
 
 
 
+/*****************************************************************************/
+/*                                   Code                                    */
+/*****************************************************************************/
+
+
+
+void joy_clear_ptr (void);
+/* Clear the joy_drv pointer */
+
+
+
 /* End of joy-kernel.h */
 #endif
 
index 975166b7eea08b7a1856ca2ff0551b04742476b9..d863b9c3da63617cd93960e602d85fabdca7322a 100644 (file)
@@ -4,8 +4,6 @@
 ; Common functions of the joystick API.
 ;
 
-        .export         joy_clear_ptr
-
         .importzp       ptr1
                .interruptor    joy_irq         ; Export as IRQ handler
 
@@ -117,7 +115,7 @@ _joy_uninstall:
 
         jsr     joy_uninstall           ; Call the driver routine
 
-joy_clear_ptr:                          ; External entry point
+_joy_clear_ptr:                         ; External entry point
         lda     #0
         sta     _joy_drv
         sta     _joy_drv+1              ; Clear the driver pointer
index bd32c299796350eced822c477ca20b18ff298992..c234d439e59e541437b1899730ae9624cbb32fff 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2002-2003 Ullrich von Bassewitz                                       */
-/*               Römerstrasse 52                                             */
-/*               D-70794 Filderstadt                                         */
-/* EMail:        uz@cc65.org                                                 */
+/* (C) 2002-2006, Ullrich von Bassewitz                                      */
+/*                Römerstrasse 52                                            */
+/*                D-70794 Filderstadt                                        */
+/* EMail:         uz@cc65.org                                                */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
 
 
 
+/* Use static local variables, since the module is not reentrant anyway */
+#pragma staticlocals (on);
+
+
+
 unsigned char __fastcall__ joy_load_driver (const char* name)
 /* Load a joystick driver and return an error code */
 {
@@ -68,8 +73,21 @@ unsigned char __fastcall__ joy_load_driver (const char* name)
         if (Res == MLOAD_OK) {
 
             /* Check the driver signature, install the driver */
-            return joy_install (ctrl.module);
-
+            Res = joy_install (ctrl.module);
+
+           /* If the driver did not install correctly, remove it from
+            * memory again.
+            */
+           if (Res != JOY_ERR_OK) {
+                /* Do not call mouse_uninstall here, since the driver is not
+                 * correctly installed.
+                 */
+                mod_free (joy_drv);
+                joy_clear_ptr ();
+            }
+
+            /* Return the error code */
+            return Res;
         }
     }