2 ; Ullrich von Bassewitz, 2002-12-20
4 ; Common functions of the joystick API.
8 .interruptor joy_irq ; Export as IRQ handler
10 .include "joy-kernel.inc"
11 .include "joy-error.inc"
14 ;----------------------------------------------------------------------------
19 _joy_drv: .res 2 ; Pointer to driver
21 _joy_masks: .res .sizeof(JOY_HDR::MASKS)
23 ; Jump table for the driver functions.
26 joy_install: jmp $0000
27 joy_uninstall: jmp $0000
30 joy_irq: .byte $60, $00, $00 ; RTS plus two dummy bytes
32 ; Driver header signature
34 joy_sig: .byte $6A, $6F, $79, JOY_API_VERSION ; "joy", version
38 ;----------------------------------------------------------------------------
39 ; unsigned char __fastcall__ joy_install (void* driver);
40 ; /* Install the driver once it is loaded */
49 ; Check the driver signature
51 ldy #.sizeof(joy_sig)-1
60 ldy #JOY_HDR::MASKS + .sizeof(JOY_HDR::MASKS) - 1
61 ldx #.sizeof(JOY_HDR::MASKS)-1
68 ; Copy the jump vectors
72 @L2: inx ; Skip the JMP opcode
73 jsr copy ; Copy one byte
74 jsr copy ; Copy one byte
75 cpy #(JOY_HDR::JUMPTAB + .sizeof(JOY_HDR::JUMPTAB))
78 jsr joy_install ; Call driver install routine
80 bne @L3 ; Bail out if install had errors
82 ; Install the IRQ vector if the driver needs it. A/X contains the error code
83 ; from joy_install, so don't use it.
85 ldy joy_irq+2 ; Check high byte of IRQ vector
86 beq @L3 ; Jump if vector invalid
88 sty joy_irq ; Activate IRQ routine
91 ; Driver signature invalid
94 lda #JOY_ERR_INV_DRIVER
98 ; Copy one byte from the jump vectors
102 set: sta joy_vectors,x
106 ;----------------------------------------------------------------------------
107 ; unsigned char __fastcall__ joy_uninstall (void);
108 ; /* Uninstall the currently loaded driver. Note: This call does not free
109 ; * allocated memory.
113 lda #$60 ; RTS opcode
114 sta joy_irq ; Disable IRQ entry point
116 jsr joy_uninstall ; Call the driver routine
118 _joy_clear_ptr: ; External entry point
121 sta _joy_drv+1 ; Clear the driver pointer