]> git.sur5r.net Git - cc65/commitdiff
Joystick library, first version
authorcuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Fri, 20 Dec 2002 20:59:11 +0000 (20:59 +0000)
committercuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Fri, 20 Dec 2002 20:59:11 +0000 (20:59 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@1796 b7a2c559-68d2-44c3-8de9-860c34a00d81

libsrc/joystick/.cvsignore [new file with mode: 0644]
libsrc/joystick/Makefile [new file with mode: 0644]
libsrc/joystick/joy-kernel.s [new file with mode: 0644]
libsrc/joystick/joy_count.s [new file with mode: 0644]
libsrc/joystick/joy_load.c [new file with mode: 0644]
libsrc/joystick/joy_read.s [new file with mode: 0644]
libsrc/joystick/joy_unload.s [new file with mode: 0644]

diff --git a/libsrc/joystick/.cvsignore b/libsrc/joystick/.cvsignore
new file mode 100644 (file)
index 0000000..3b18bbb
--- /dev/null
@@ -0,0 +1 @@
+joy_load.s
diff --git a/libsrc/joystick/Makefile b/libsrc/joystick/Makefile
new file mode 100644 (file)
index 0000000..7ebcfd9
--- /dev/null
@@ -0,0 +1,30 @@
+#
+# Makefile for the joystick library
+#
+
+.SUFFIXES: .o .s .c
+
+%.o:           %.c
+       @$(CC) $(CFLAGS) $<
+       @$(AS) -g -o $@ $(AFLAGS) $(*).s
+
+%.o:   %.s
+       @$(AS) -g -o $@ $(AFLAGS) $<
+
+C_OBJS =        joy_load.o
+
+S_OBJS =               joy-kernel.o    \
+                       joy_read.o      \
+                       joy_count.o     \
+               joy_unload.o
+
+
+all:   $(C_OBJS) $(S_OBJS)
+
+clean:
+       @rm -f *~
+       @rm -f $(C_OBJS:.o=.s)
+       @rm -f $(C_OBJS)
+       @rm -f $(S_OBJS)
+
+
diff --git a/libsrc/joystick/joy-kernel.s b/libsrc/joystick/joy-kernel.s
new file mode 100644 (file)
index 0000000..9005d93
--- /dev/null
@@ -0,0 +1,100 @@
+;
+; Ullrich von Bassewitz, 2002-12-20
+;
+; Common functions of the joystick API.
+;
+
+        .export         _joy_install, _joy_deinstall
+
+        .importzp       ptr1
+
+        .include        "joy-kernel.inc"
+        .include        "joy-error.inc"
+
+
+;----------------------------------------------------------------------------
+; Variables
+
+
+.bss
+_joy_drv:       .res    2                      ; Pointer to driver
+
+_joy_masks:     .res    JOY_MASK_COUNT
+
+; Jump table for the driver functions.
+.data
+joy_vectors:
+joy_install:           jmp     $0000
+joy_deinstall:         jmp     $0000
+joy_count:      jmp     $0000
+joy_read:       jmp     $0000
+
+; Driver header signature
+.rodata
+joy_sig:        .byte   $6A, $6F, $79, $00      ; "joy", version
+joy_sig_len     = * - joy_sig
+
+
+;----------------------------------------------------------------------------
+; unsigned char __fastcall__ joy_install (void* driver);
+; /* Install the driver once it is loaded */
+
+
+_joy_install:
+               sta     _joy_drv
+       sta     ptr1
+       stx     _joy_drv+1
+       stx     ptr1+1
+
+; Check the driver signature
+
+        ldy     #joy_sig_len-1
+@L0:    lda     (ptr1),y
+        cmp     joy_sig,y
+        bne     inv_drv
+        dey
+        bpl     @L0
+
+; Copy the mask array
+
+        ldy     #JOY_MASKS + JOY_MASK_COUNT - 1
+        ldx     #JOY_MASK_COUNT
+@L1:    lda     (ptr1),y
+        sta     _joy_masks,x
+        dey
+        dex
+        bpl     @L1
+
+; Copy the jump vectors
+
+        ldy     #JOY_HDR_JUMPTAB
+        ldx     #0
+@L2:    inx                             ; Skip the JMP opcode
+        jsr     copy                    ; Copy one byte
+        jsr     copy                    ; Copy one byte
+        cpx     #(JOY_HDR_JUMPCOUNT*3)
+        bne     @L2
+
+        jmp     joy_install             ; Call driver install routine
+
+; Driver signature invalid
+
+inv_drv:
+        lda     #JOY_ERR_INV_DRIVER
+        ldx     #0
+        rts
+
+; Copy one byte from the jump vectors
+
+copy:   lda     (ptr1),y
+        iny
+set:    sta     joy_vectors,x
+        inx
+        rts
+
+;----------------------------------------------------------------------------
+; void __fastcall__ joy_deinstall (void);
+; /* Deinstall the driver before unloading it */
+
+_joy_deinstall  = joy_deinstall           ; Call driver routine
+
diff --git a/libsrc/joystick/joy_count.s b/libsrc/joystick/joy_count.s
new file mode 100644 (file)
index 0000000..c8b2b83
--- /dev/null
@@ -0,0 +1,12 @@
+;
+; Ullrich von Bassewitz, 2002-12-20
+;
+; unsigned char __fastcall__ joy_count (void);
+; /* Return the number of joysticks supported by the driver */
+;
+
+        .include        "joy-kernel.inc"
+
+               _joy_count      = joy_count             ; Use driver entry
+
+
diff --git a/libsrc/joystick/joy_load.c b/libsrc/joystick/joy_load.c
new file mode 100644 (file)
index 0000000..908be88
--- /dev/null
@@ -0,0 +1,81 @@
+/*****************************************************************************/
+/*                                                                           */
+/*                                joy_load.c                                 */
+/*                                                                           */
+/*                    Loader module for joystick drivers                     */
+/*                                                                           */
+/*                                                                           */
+/*                                                                           */
+/* (C) 2002      Ullrich von Bassewitz                                       */
+/*               Wacholderweg 14                                             */
+/*               D-70597 Stuttgart                                           */
+/* EMail:        uz@musoftware.de                                            */
+/*                                                                           */
+/*                                                                           */
+/* 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 <fcntl.h>
+#include <modload.h>
+#include <joystick.h>
+#include <joystick/joy-kernel.h>
+
+
+
+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_deinstall ();
+    }
+
+    /* 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 */
+            return joy_install (ctrl.module);
+
+        }
+    }
+
+    /* Error loading the driver */
+    return JOY_ERR_CANNOT_LOAD;
+}
+
+
+
diff --git a/libsrc/joystick/joy_read.s b/libsrc/joystick/joy_read.s
new file mode 100644 (file)
index 0000000..c03bf95
--- /dev/null
@@ -0,0 +1,12 @@
+;
+; Ullrich von Bassewitz, 2002-12-20
+;
+; unsigned char __fastcall__ joy_read (unsigned char joystick);
+; /* Read a particular joystick */
+;
+
+        .include        "joy-kernel.inc"
+
+               _joy_read       = joy_read              ; Use driver entry
+
+                                                
diff --git a/libsrc/joystick/joy_unload.s b/libsrc/joystick/joy_unload.s
new file mode 100644 (file)
index 0000000..ffca49c
--- /dev/null
@@ -0,0 +1,35 @@
+;
+; Ullrich von Bassewitz, 2002-11-29
+;
+; unsigned char __fastcall__ joy_unload (void);
+; /* Unload the currently loaded driver. */
+
+
+        .include        "joy-kernel.inc"
+        .include        "joy-error.inc"
+        .include        "modload.inc"
+
+_joy_unload:
+       lda     _joy_drv
+       ora     _joy_drv+1
+               beq     no_driver               ; No driver
+
+       jsr     _joy_deinstall          ; Deinstall the driver
+
+        lda     _joy_drv
+        ldx     _joy_drv+1
+        jsr     _mod_free               ; Free the driver
+
+        lda     #0
+        sta     _joy_drv
+        sta     _joy_drv+1               ; Clear the driver pointer
+
+        tax
+        rts                             ; Return zero
+
+no_driver:
+       tax                             ; X = 0
+       lda     #JOY_ERR_NO_DRIVER
+       rts
+
+