]> git.sur5r.net Git - cc65/commitdiff
Rewrote the xxx_load routines for the drivers in assembler to save some
authorcuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Mon, 5 Jun 2006 16:59:29 +0000 (16:59 +0000)
committercuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Mon, 5 Jun 2006 16:59:29 +0000 (16:59 +0000)
space.

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

12 files changed:
libsrc/joystick/.cvsignore
libsrc/joystick/Makefile
libsrc/joystick/joy_load.c [deleted file]
libsrc/joystick/joy_load.s [new file with mode: 0644]
libsrc/mouse/.cvsignore
libsrc/mouse/Makefile
libsrc/mouse/mouse_load.c [deleted file]
libsrc/mouse/mouse_load.s [new file with mode: 0644]
libsrc/serial/.cvsignore
libsrc/serial/Makefile
libsrc/serial/ser_load.c [deleted file]
libsrc/serial/ser_load.s [new file with mode: 0644]

index 3b18bbb05ed2a8c59a2ac5ec16ba52efbc9be882..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 (file)
@@ -1 +0,0 @@
-joy_load.s
index e1099a5e734d4c136bde46b9d3c820ca6d874e0f..bc59422b08e17a9cc43017a55d9ad922ada3995d 100644 (file)
@@ -29,11 +29,12 @@ CFLAGS      = -Osir -g -T -t $(SYS) --forget-inc-paths -I . -I ../../include
 #--------------------------------------------------------------------------
 # Object files
 
-C_OBJS =        joy_load.o
+C_OBJS =        
 
 S_OBJS =               joy-kernel.o    \
                        joy_read.o      \
                        joy_count.o     \
+                joy_load.o      \
                joy_unload.o
 
 #--------------------------------------------------------------------------
diff --git a/libsrc/joystick/joy_load.c b/libsrc/joystick/joy_load.c
deleted file mode 100644 (file)
index c234d43..0000000
+++ /dev/null
@@ -1,99 +0,0 @@
-/*****************************************************************************/
-/*                                                                           */
-/*                                joy_load.c                                 */
-/*                                                                           */
-/*                    Loader module for joystick drivers                     */
-/*                                                                           */
-/*                                                                           */
-/*                                                                           */
-/* (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       */
-/* 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.                                                          */
-/*                                                                           */
-/*****************************************************************************/
-
-
-
-#include <unistd.h>
-#include <fcntl.h>
-#include <modload.h>
-#include <joystick.h>
-#include <joystick/joy-kernel.h>
-
-
-
-/* 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 */
-{
-    static struct mod_ctrl ctrl = {
-        read            /* Read from disk */
-    };
-    unsigned char Res;
-
-    /* Check if we do already have a driver loaded. If so, remove it. */
-    if (joy_drv != 0) {
-        joy_uninstall ();
-    }
-
-    /* Now open the file */
-    ctrl.callerdata = open (name, O_RDONLY);
-    if (ctrl.callerdata >= 0) {
-
-        /* Load the module */
-        Res = mod_load (&ctrl);
-
-        /* Close the input file */
-        close (ctrl.callerdata);
-
-        /* Check the return code */
-        if (Res == MLOAD_OK) {
-
-            /* Check the driver signature, install the driver */
-            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;
-        }
-    }
-
-    /* Error loading the driver */
-    return JOY_ERR_CANNOT_LOAD;
-}
-
-
-
diff --git a/libsrc/joystick/joy_load.s b/libsrc/joystick/joy_load.s
new file mode 100644 (file)
index 0000000..7115f5d
--- /dev/null
@@ -0,0 +1,121 @@
+;
+; Ullrich von Bassewitz, 2006-06-05
+;
+; unsigned char __fastcall__ joy_load_driver (const char* driver);
+; /* Load and install a joystick driver. Return an error code. */
+
+
+        .include        "joy-kernel.inc"
+        .include        "joy-error.inc"
+        .include        "modload.inc"
+        .include        "fcntl.inc"
+
+        .import         pushax
+        .import         pusha0
+        .import         incsp2
+        .import         _open
+        .import         _read
+        .import         _close
+
+
+
+;----------------------------------------------------------------------------
+; Variables
+
+.data
+
+ctrl:   .addr   _read
+        .res    2                       ; CALLERDATA
+        .res    2                       ; MODULE
+        .res    2                       ; MODULE_SIZE
+        .res    2                       ; MODULE_ID
+
+;----------------------------------------------------------------------------
+; Code
+
+.code
+
+.proc   _joy_load_driver
+
+; Save name on the C stack. We will need it later as parameter passed to open()
+
+        jsr     pushax
+
+; Check if we do already have a driver loaded. If so, remove it.
+
+        lda     _joy_drv
+        ora     _joy_drv+1
+        beq     @L1
+        jsr     _joy_uninstall
+
+; Open the file. The name parameter is already on stack and will get removed
+; by open().
+; ctrl.callerdata = open (name, O_RDONLY);
+
+@L1:    lda     #<O_RDONLY
+        jsr     pusha0
+        ldy     #4                      ; Argument size
+        jsr     _open
+        sta     ctrl + MOD_CTRL::CALLERDATA
+        stx     ctrl + MOD_CTRL::CALLERDATA+1
+
+; if (ctrl.callerdata >= 0) {
+
+        txa
+        bmi     @L3
+
+; /* Load the module */
+; Res = mod_load (&ctrl);
+
+        lda     #<ctrl
+        ldx     #>ctrl
+        jsr     _mod_load
+        pha
+
+; /* Close the input file */
+; close (ctrl.callerdata);
+
+        lda     ctrl + MOD_CTRL::CALLERDATA
+        ldx     ctrl + MOD_CTRL::CALLERDATA+1
+        jsr     _close
+
+; /* Check the return code */
+; if (Res == MLOAD_OK) {
+
+        pla
+        bne     @L3
+
+; Check the driver signature, install the driver. c is already on stack and
+; will get removed by joy_install().
+; Res = joy_install (ctrl.module);  
+
+        lda     ctrl + MOD_CTRL::MODULE
+        ldx     ctrl + MOD_CTRL::MODULE+1
+        jsr     _joy_install
+
+; If joy_install was successful, we're done
+
+        tax
+        beq     @L2
+
+; The driver didn't install correctly. Remove it from memory and return the
+; error code.
+
+        pha                             ; Save the error code
+        lda     _joy_drv
+        ldx     _joy_drv+1
+        jsr     _mod_free               ; Free the driver memory
+        jsr     _joy_clear_ptr          ; Clear joy_drv
+        pla                             ; Restore the error code
+        ldx     #0                      ; We must return an int
+@L2:    rts                             ; Done
+
+; Open or mod_load failed. Return an error code.
+
+@L3:    lda     #<JOY_ERR_CANNOT_LOAD
+        ldx     #>JOY_ERR_CANNOT_LOAD
+        rts
+
+.endproc
+
+
index d8548c2a2d026b5e83eda6b0d3cd7df677232b50..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 (file)
@@ -1 +0,0 @@
-mouse_load.s
index 7d32f465255a4add0c573e1222b97cb7ca789a62..47841ab8f76fbd9eac0fcc86d136cf12c4e3f905 100644 (file)
@@ -29,7 +29,7 @@ CFLAGS        = -Osir -g -T -t $(SYS) --forget-inc-paths -I . -I ../../include
 #--------------------------------------------------------------------------
 # Object files
 
-C_OBJS =        mouse_load.o
+C_OBJS =
 
 S_OBJS =        mouse-kernel.o          \
                 mouse_box.o             \
@@ -38,6 +38,7 @@ S_OBJS =        mouse-kernel.o          \
                 mouse_hide.o            \
                 mouse_info.o            \
                 mouse_ioctl.o           \
+                mouse_load.o            \
                 mouse_move.o            \
                 mouse_pos.o             \
                 mouse_show.o            \
diff --git a/libsrc/mouse/mouse_load.c b/libsrc/mouse/mouse_load.c
deleted file mode 100644 (file)
index bc15f26..0000000
+++ /dev/null
@@ -1,101 +0,0 @@
-/*****************************************************************************/
-/*                                                                           */
-/*                               mouse_load.c                                */
-/*                                                                           */
-/*                     Loader for mouse drivers modules                      */
-/*                                                                           */
-/*                                                                           */
-/*                                                                           */
-/* (C) 2002-2003 Ullrich von Bassewitz                                       */
-/*               Römerstrasse 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.                                                          */
-/*                                                                           */
-/*****************************************************************************/
-
-
-
-#include <string.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <modload.h>
-#include <mouse.h>
-#include <mouse/mouse-kernel.h>
-
-
-
-/* Use static local variables, since the module is not reentrant anyway */
-#pragma staticlocals (on);
-
-
-
-unsigned char __fastcall__ mouse_load_driver (const struct mouse_callbacks* c,
-                                              const char* name)
-/* Load a mouse driver and return an error code */
-{
-    static struct mod_ctrl ctrl = {
-        read            /* Read from disk */
-    };
-    unsigned char Res;
-
-    /* Check if we do already have a driver loaded. If so, remove it. */
-    if (mouse_drv != 0) {
-        mouse_uninstall ();
-    }
-
-    /* Now open the file */
-    ctrl.callerdata = open (name, O_RDONLY);
-    if (ctrl.callerdata >= 0) {
-
-        /* Load the module */
-        Res = mod_load (&ctrl);
-
-        /* Close the input file */
-        close (ctrl.callerdata);
-
-        /* Check the return code */
-        if (Res == MLOAD_OK) {
-
-            /* Check the driver signature, install the driver */
-            Res = mouse_install (c, ctrl.module);
-
-           /* If the driver did not install correctly, remove it from
-            * memory again.
-            */
-           if (Res != MOUSE_ERR_OK) {
-                /* Do not call mouse_uninstall here, since the driver is not
-                 * correctly installed.
-                 */
-                mod_free (mouse_drv);
-                mouse_clear_ptr ();
-            }
-
-            /* Return the error code */
-            return Res;
-        }
-    }
-
-    /* Error loading the driver */
-    return MOUSE_ERR_CANNOT_LOAD;
-}
-
-
-
diff --git a/libsrc/mouse/mouse_load.s b/libsrc/mouse/mouse_load.s
new file mode 100644 (file)
index 0000000..3472508
--- /dev/null
@@ -0,0 +1,123 @@
+;                         
+; Ullrich von Bassewitz, 2006-06-05
+;
+; unsigned char __fastcall__ mouse_load_driver (const struct mouse_callbacks* c,
+;                                               const char* name)
+; /* Load a mouse driver and return an error code */
+
+
+        .include        "mouse-kernel.inc"
+        .include        "modload.inc"
+        .include        "fcntl.inc"
+
+        .import         pushax
+        .import         pusha0
+        .import         incsp2
+        .import         _open
+        .import         _read
+        .import         _close
+
+
+
+;----------------------------------------------------------------------------
+; Variables
+
+.data
+
+ctrl:   .addr   _read
+        .res    2                       ; CALLERDATA
+        .res    2                       ; MODULE
+        .res    2                       ; MODULE_SIZE
+        .res    2                       ; MODULE_ID
+
+;----------------------------------------------------------------------------
+; Code
+
+.code
+
+.proc   _mouse_load_driver
+
+; Save name on the C stack. We will need it later as parameter passed to open()
+
+        jsr     pushax
+
+; Check if we do already have a driver loaded. If so, remove it.
+
+        lda     _mouse_drv
+        ora     _mouse_drv+1
+        beq     @L1
+        jsr     _mouse_uninstall
+
+; Open the file. The name parameter is already on stack and will get removed
+; by open().
+; ctrl.callerdata = open (name, O_RDONLY);
+
+@L1:    lda     #<O_RDONLY
+        jsr     pusha0
+        ldy     #4                      ; Argument size
+        jsr     _open
+        sta     ctrl + MOD_CTRL::CALLERDATA
+        stx     ctrl + MOD_CTRL::CALLERDATA+1
+
+; if (ctrl.callerdata >= 0) {
+
+        txa
+        bmi     @L3
+
+; /* Load the module */
+; Res = mod_load (&ctrl);
+
+        lda     #<ctrl
+        ldx     #>ctrl
+        jsr     _mod_load
+        pha
+
+; /* Close the input file */
+; close (ctrl.callerdata);
+
+        lda     ctrl + MOD_CTRL::CALLERDATA
+        ldx     ctrl + MOD_CTRL::CALLERDATA+1
+        jsr     _close
+
+; /* Check the return code */
+; if (Res == MLOAD_OK) {
+
+        pla
+        bne     @L3
+
+; Check the driver signature, install the driver. c is already on stack and
+; will get removed by mouse_install().
+; Res = mouse_install (c, ctrl.module);
+
+        lda     ctrl + MOD_CTRL::MODULE
+        ldx     ctrl + MOD_CTRL::MODULE+1
+        jsr     _mouse_install
+
+; If mouse_install was successful, we're done
+
+        tax
+        beq     @L2
+
+; The driver didn't install correctly. Remove it from memory and return the
+; error code.
+
+        pha                             ; Save the error code
+        lda     _mouse_drv
+        ldx     _mouse_drv+1
+        jsr     _mod_free               ; Free the driver memory
+        jsr     _mouse_clear_ptr        ; Clear mouse_drv
+        pla                             ; Restore the error code
+        ldx     #0                      ; We must return an int
+@L2:    rts                             ; Done
+
+; Open or mod_load failed. Remove excess arguments from stack and return an
+; error code.
+
+@L3:    jsr     incsp2
+        lda     #<MOUSE_ERR_CANNOT_LOAD
+        ldx     #>MOUSE_ERR_CANNOT_LOAD
+        rts
+
+.endproc
+
+
index c81f22f084950bded0b36fc34144ff7ade49265d..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 (file)
@@ -1 +0,0 @@
-ser_load.s
index cef55eccfc4880e1f5a515906502eb4a15b8ab7e..51407e6109f711478c9fe8dfe2bc531bb67fd610 100644 (file)
@@ -29,12 +29,13 @@ CFLAGS      = -Osir -g -T -t $(SYS) --forget-inc-paths -I . -I ../../include
 #--------------------------------------------------------------------------
 # Object files
 
-C_OBJS =        ser_load.o
+C_OBJS =        
 
 S_OBJS =               ser-kernel.o    \
                 ser_close.o     \
                 ser_get.o       \
                 ser_ioctl.o     \
+                ser_load.o      \
                 ser_open.o      \
                 ser_put.o       \
                 ser_status.o    \
diff --git a/libsrc/serial/ser_load.c b/libsrc/serial/ser_load.c
deleted file mode 100644 (file)
index 11ca23a..0000000
+++ /dev/null
@@ -1,119 +0,0 @@
-/*****************************************************************************/
-/*                                                                           */
-/*                                ser_load.c                                 */
-/*                                                                           */
-/*                     Loader module for serial drivers                      */
-/*                                                                           */
-/*                                                                           */
-/*                                                                           */
-/* (C) 2003-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       */
-/* 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.                                                          */
-/*                                                                           */
-/*****************************************************************************/
-
-
-
-#include <string.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <modload.h>
-#include <serial.h>
-
-
-
-/*****************************************************************************/
-/*                                          Data                                    */
-/*****************************************************************************/
-
-
-
-/* Pointer to serial driver, exported from ser-kernel.s */
-extern void* ser_drv;
-
-/* Function that clears the driver pointer (ser-kernel.s) */
-void ser_clear_ptr (void);
-
-
-
-/*****************************************************************************/
-/*                                          Code                                    */
-/*****************************************************************************/
-
-
-
-/* Use static local variables, since the module is not reentrant anyway */
-#pragma staticlocals (on);
-
-
-
-unsigned char __fastcall__ ser_load_driver (const char* name)
-/* Load a serial driver and return an error code */
-{
-    static struct mod_ctrl ctrl = {
-        read            /* Read from disk */
-    };
-    unsigned char Res;
-
-    /* Check if we do already have a driver loaded. If so, remove it. */
-    if (ser_drv != 0) {
-        ser_uninstall ();
-    }
-
-    /* Now open the file */
-    ctrl.callerdata = open (name, O_RDONLY);
-    if (ctrl.callerdata >= 0) {
-
-        /* Load the module */
-        Res = mod_load (&ctrl);
-
-        /* Close the input file */
-        close (ctrl.callerdata);
-
-        /* Check the return code */
-        if (Res == MLOAD_OK) {
-
-            /* Check the driver signature, install the driver */
-            Res = ser_install (ctrl.module);
-
-           /* If the driver did not install correctly, remove it from
-            * memory again.
-            */
-           if (Res != SER_ERR_OK) {
-                /* Do not call ser_uninstall here, since the driver is not
-                 * correctly installed.
-                 */
-                mod_free (ser_drv);
-                ser_clear_ptr ();
-            }
-
-            /* Return the error code */
-            return Res;
-        }
-    }
-
-    /* Error loading the driver */
-    return SER_ERR_CANNOT_LOAD;
-}
-
-
-
diff --git a/libsrc/serial/ser_load.s b/libsrc/serial/ser_load.s
new file mode 100644 (file)
index 0000000..d711a74
--- /dev/null
@@ -0,0 +1,121 @@
+;
+; Ullrich von Bassewitz, 2006-06-05
+;
+; unsigned char __fastcall__ ser_load_driver (const char* name)
+; /* Load a serial driver and return an error code */
+
+
+        .include        "ser-kernel.inc"
+        .include        "ser-error.inc"
+        .include        "modload.inc"
+        .include        "fcntl.inc"
+
+        .import         pushax
+        .import         pusha0
+        .import         incsp2
+        .import         _open
+        .import         _read
+        .import         _close
+
+
+
+;----------------------------------------------------------------------------
+; Variables
+
+.data
+
+ctrl:   .addr   _read
+        .res    2                       ; CALLERDATA
+        .res    2                       ; MODULE
+        .res    2                       ; MODULE_SIZE
+        .res    2                       ; MODULE_ID
+
+;----------------------------------------------------------------------------
+; Code
+
+.code
+
+.proc   _ser_load_driver
+
+; Save name on the C stack. We will need it later as parameter passed to open()
+
+        jsr     pushax
+
+; Check if we do already have a driver loaded. If so, remove it.
+
+        lda     _ser_drv
+        ora     _ser_drv+1
+        beq     @L1
+        jsr     _ser_uninstall
+
+; Open the file. The name parameter is already on stack and will get removed
+; by open().
+; ctrl.callerdata = open (name, O_RDONLY);
+
+@L1:    lda     #<O_RDONLY
+        jsr     pusha0
+        ldy     #4                      ; Argument size
+        jsr     _open
+        sta     ctrl + MOD_CTRL::CALLERDATA
+        stx     ctrl + MOD_CTRL::CALLERDATA+1
+
+; if (ctrl.callerdata >= 0) {
+
+        txa
+        bmi     @L3
+
+; /* Load the module */
+; Res = mod_load (&ctrl);
+
+        lda     #<ctrl
+        ldx     #>ctrl
+        jsr     _mod_load
+        pha
+
+; /* Close the input file */
+; close (ctrl.callerdata);
+
+        lda     ctrl + MOD_CTRL::CALLERDATA
+        ldx     ctrl + MOD_CTRL::CALLERDATA+1
+        jsr     _close
+
+; /* Check the return code */
+; if (Res == MLOAD_OK) {
+
+        pla
+        bne     @L3
+
+; Check the driver signature, install the driver. c is already on stack and
+; will get removed by ser_install().
+; Res = ser_install (ctrl.module);
+
+        lda     ctrl + MOD_CTRL::MODULE
+        ldx     ctrl + MOD_CTRL::MODULE+1
+        jsr     _ser_install
+
+; If ser_install was successful, we're done
+
+        tax
+        beq     @L2
+
+; The driver didn't install correctly. Remove it from memory and return the
+; error code.
+
+        pha                             ; Save the error code
+        lda     _ser_drv
+        ldx     _ser_drv+1
+        jsr     _mod_free               ; Free the driver memory
+        jsr     _ser_clear_ptr          ; Clear ser_drv
+        pla                             ; Restore the error code
+        ldx     #0                      ; We must return an int
+@L2:    rts                             ; Done
+
+; Open or mod_load failed. Return an error code.
+
+@L3:    lda     #<SER_ERR_CANNOT_LOAD
+        ldx     #>SER_ERR_CANNOT_LOAD
+        rts
+
+.endproc
+
+