]> git.sur5r.net Git - cc65/blobdiff - libsrc/joystick/joy-kernel.s
Moved the CAPS LOCK code out of the startup file, and into its own file.
[cc65] / libsrc / joystick / joy-kernel.s
index 0bb49463f15667cfb041bc4759f3137d2915b749..1ba3056d8f66d3399c881eaa23d946720e0a8811 100644 (file)
@@ -4,10 +4,9 @@
 ; Common functions of the joystick API.
 ;
 
-        .export         joy_clear_ptr
-
+        .import         joy_libref
         .importzp       ptr1
-               .interruptor    joy_irq         ; Export as IRQ handler
+        .interruptor    joy_irq         ; Export as IRQ handler
 
         .include        "joy-kernel.inc"
         .include        "joy-error.inc"
 
 
 .bss
-_joy_drv:       .res    2                      ; Pointer to driver
+_joy_drv:       .res    2               ; Pointer to driver
 
 _joy_masks:     .res    .sizeof(JOY_HDR::MASKS)
 
 ; Jump table for the driver functions.
 .data
 joy_vectors:
-joy_install:           jmp     $0000
-joy_uninstall:         jmp     $0000
+joy_install:    jmp     $0000
+joy_uninstall:  jmp     $0000
 joy_count:      jmp     $0000
 joy_read:       jmp     $0000
 joy_irq:        .byte   $60, $00, $00   ; RTS plus two dummy bytes
 
 ; Driver header signature
 .rodata
-joy_sig:        .byte   $6A, $6F, $79, JOY_API_VERSION ; "joy", version
+joy_sig:        .byte   $6A, $6F, $79, JOY_API_VERSION  ; "joy", version
 
 
+.code
 ;----------------------------------------------------------------------------
 ; 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
+        sta     _joy_drv
+        sta     ptr1
+        stx     _joy_drv+1
+        stx     ptr1+1
 
 ; Check the driver signature
 
@@ -56,6 +56,15 @@ _joy_install:
         dey
         bpl     @L0
 
+; Set the library reference
+
+        ldy     #JOY_HDR::LIBREF
+        lda     #<joy_libref
+        sta     (ptr1),y
+        iny
+        lda     #>joy_libref
+        sta     (ptr1),y
+
 ; Copy the mask array
 
         ldy     #JOY_HDR::MASKS + .sizeof(JOY_HDR::MASKS) - 1
@@ -77,14 +86,16 @@ _joy_install:
         bne     @L2
 
         jsr     joy_install             ; Call driver install routine
+        tay                             ; Test error code
+        bne     @L3                     ; Bail out if install had errors
 
 ; Install the IRQ vector if the driver needs it. A/X contains the error code
 ; from joy_install, so don't use it.
 
         ldy     joy_irq+2               ; Check high byte of IRQ vector
         beq     @L3                     ; Jump if vector invalid
-       ldy     #$4C                    ; JMP opcode
-               sty     joy_irq                 ; Activate IRQ routine
+        ldy     #$4C                    ; JMP opcode
+        sty     joy_irq                 ; Activate IRQ routine
 @L3:    rts
 
 ; Driver signature invalid
@@ -103,22 +114,21 @@ set:    sta     joy_vectors,x
         rts
 
 ;----------------------------------------------------------------------------
-; unsigned char __fastcall__ joy_uninstall (void);
+; unsigned char joy_uninstall (void);
 ; /* Uninstall the currently loaded driver. Note: This call does not free
-;  * allocated memory.
-;  */
+; ** allocated memory.
+; */
 
 _joy_uninstall:
-       lda     #$60                    ; RTS opcode
-               sta     joy_irq                 ; Disable IRQ entry point
+        lda     #$60                    ; RTS opcode
+        sta     joy_irq                 ; Disable IRQ entry point
 
         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
 
         tax                             ; Return zero
         rts
-