2 ; Ullrich von Bassewitz, 2002-12-20
4 ; Common functions of the joystick API.
9 .interruptor joy_irq ; Export as IRQ handler
11 .include "joy-kernel.inc"
12 .include "joy-error.inc"
15 ;----------------------------------------------------------------------------
20 _joy_drv: .res 2 ; Pointer to driver
22 _joy_masks: .res .sizeof(JOY_HDR::MASKS)
24 ; Jump table for the driver functions.
27 joy_install: jmp $0000
28 joy_uninstall: jmp $0000
31 joy_irq: .byte $60, $00, $00 ; RTS plus two dummy bytes
33 ; Driver header signature
35 joy_sig: .byte $6A, $6F, $79, JOY_API_VERSION ; "joy", version
39 ;----------------------------------------------------------------------------
40 ; unsigned char __fastcall__ joy_install (void* driver);
41 ; /* Install the driver once it is loaded */
50 ; Check the driver signature
52 ldy #.sizeof(joy_sig)-1
59 ; Set the library reference
70 ldy #JOY_HDR::MASKS + .sizeof(JOY_HDR::MASKS) - 1
71 ldx #.sizeof(JOY_HDR::MASKS)-1
78 ; Copy the jump vectors
82 @L2: inx ; Skip the JMP opcode
83 jsr copy ; Copy one byte
84 jsr copy ; Copy one byte
85 cpy #(JOY_HDR::JUMPTAB + .sizeof(JOY_HDR::JUMPTAB))
88 jsr joy_install ; Call driver install routine
90 bne @L3 ; Bail out if install had errors
92 ; Install the IRQ vector if the driver needs it. A/X contains the error code
93 ; from joy_install, so don't use it.
95 ldy joy_irq+2 ; Check high byte of IRQ vector
96 beq @L3 ; Jump if vector invalid
98 sty joy_irq ; Activate IRQ routine
101 ; Driver signature invalid
104 lda #JOY_ERR_INV_DRIVER
108 ; Copy one byte from the jump vectors
112 set: sta joy_vectors,x
116 ;----------------------------------------------------------------------------
117 ; unsigned char joy_uninstall (void);
118 ; /* Uninstall the currently loaded driver. Note: This call does not free
119 ; ** allocated memory.
123 lda #$60 ; RTS opcode
124 sta joy_irq ; Disable IRQ entry point
126 jsr joy_uninstall ; Call the driver routine
128 _joy_clear_ptr: ; External entry point
131 sta _joy_drv+1 ; Clear the driver pointer