2002-12-20 20:59:11 +00:00
|
|
|
;
|
|
|
|
; Ullrich von Bassewitz, 2002-12-20
|
|
|
|
;
|
|
|
|
; Common functions of the joystick API.
|
|
|
|
;
|
|
|
|
|
2003-02-10 22:11:12 +00:00
|
|
|
.export joy_clear_ptr
|
2003-12-16 22:38:12 +00:00
|
|
|
|
2002-12-20 20:59:11 +00:00
|
|
|
.importzp ptr1
|
2004-11-06 13:09:01 +00:00
|
|
|
.interruptor joy_irq ; Export as IRQ handler
|
2002-12-20 20:59:11 +00:00
|
|
|
|
|
|
|
.include "joy-kernel.inc"
|
|
|
|
.include "joy-error.inc"
|
|
|
|
|
|
|
|
|
|
|
|
;----------------------------------------------------------------------------
|
|
|
|
; Variables
|
|
|
|
|
|
|
|
|
|
|
|
.bss
|
|
|
|
_joy_drv: .res 2 ; Pointer to driver
|
|
|
|
|
2003-12-16 22:38:12 +00:00
|
|
|
_joy_masks: .res .sizeof(JOY_HDR::MASKS)
|
2002-12-20 20:59:11 +00:00
|
|
|
|
|
|
|
; Jump table for the driver functions.
|
|
|
|
.data
|
|
|
|
joy_vectors:
|
|
|
|
joy_install: jmp $0000
|
2003-02-10 22:11:12 +00:00
|
|
|
joy_uninstall: jmp $0000
|
2002-12-20 20:59:11 +00:00
|
|
|
joy_count: jmp $0000
|
|
|
|
joy_read: jmp $0000
|
2004-11-06 13:05:26 +00:00
|
|
|
joy_irq: .byte $60, $00, $00 ; RTS plus two dummy bytes
|
2002-12-20 20:59:11 +00:00
|
|
|
|
|
|
|
; Driver header signature
|
|
|
|
.rodata
|
2003-12-16 22:38:12 +00:00
|
|
|
joy_sig: .byte $6A, $6F, $79, JOY_API_VERSION ; "joy", version
|
2002-12-20 20:59:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
;----------------------------------------------------------------------------
|
|
|
|
; unsigned char __fastcall__ joy_install (void* driver);
|
|
|
|
; /* Install the driver once it is loaded */
|
|
|
|
|
|
|
|
|
|
|
|
_joy_install:
|
|
|
|
sta _joy_drv
|
2003-02-10 22:11:12 +00:00
|
|
|
sta ptr1
|
|
|
|
stx _joy_drv+1
|
|
|
|
stx ptr1+1
|
2002-12-20 20:59:11 +00:00
|
|
|
|
|
|
|
; Check the driver signature
|
|
|
|
|
2003-12-16 22:38:12 +00:00
|
|
|
ldy #.sizeof(joy_sig)-1
|
2002-12-20 20:59:11 +00:00
|
|
|
@L0: lda (ptr1),y
|
|
|
|
cmp joy_sig,y
|
|
|
|
bne inv_drv
|
|
|
|
dey
|
|
|
|
bpl @L0
|
|
|
|
|
|
|
|
; Copy the mask array
|
|
|
|
|
2003-12-16 22:38:12 +00:00
|
|
|
ldy #JOY_HDR::MASKS + .sizeof(JOY_HDR::MASKS) - 1
|
|
|
|
ldx #.sizeof(JOY_HDR::MASKS)-1
|
2002-12-20 20:59:11 +00:00
|
|
|
@L1: lda (ptr1),y
|
|
|
|
sta _joy_masks,x
|
|
|
|
dey
|
|
|
|
dex
|
|
|
|
bpl @L1
|
|
|
|
|
|
|
|
; Copy the jump vectors
|
|
|
|
|
2003-12-16 22:38:12 +00:00
|
|
|
ldy #JOY_HDR::JUMPTAB
|
2002-12-20 20:59:11 +00:00
|
|
|
ldx #0
|
|
|
|
@L2: inx ; Skip the JMP opcode
|
|
|
|
jsr copy ; Copy one byte
|
|
|
|
jsr copy ; Copy one byte
|
2003-12-16 22:38:12 +00:00
|
|
|
cpy #(JOY_HDR::JUMPTAB + .sizeof(JOY_HDR::JUMPTAB))
|
2002-12-20 20:59:11 +00:00
|
|
|
bne @L2
|
|
|
|
|
2004-11-06 13:05:26 +00:00
|
|
|
jsr joy_install ; Call driver install routine
|
|
|
|
|
|
|
|
; 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
|
|
|
|
@L3: rts
|
2002-12-20 20:59:11 +00:00
|
|
|
|
|
|
|
; 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
|
|
|
|
|
|
|
|
;----------------------------------------------------------------------------
|
2003-02-10 22:11:12 +00:00
|
|
|
; unsigned char __fastcall__ joy_uninstall (void);
|
|
|
|
; /* Uninstall the currently loaded driver. Note: This call does not free
|
|
|
|
; * allocated memory.
|
|
|
|
; */
|
|
|
|
|
|
|
|
_joy_uninstall:
|
2004-11-06 13:05:26 +00:00
|
|
|
lda #$60 ; RTS opcode
|
|
|
|
sta joy_irq ; Disable IRQ entry point
|
|
|
|
|
2003-02-10 22:11:12 +00:00
|
|
|
jsr joy_uninstall ; Call the driver routine
|
2002-12-20 20:59:11 +00:00
|
|
|
|
2003-02-10 22:11:12 +00:00
|
|
|
joy_clear_ptr: ; External entry point
|
|
|
|
lda #0
|
|
|
|
sta _joy_drv
|
|
|
|
sta _joy_drv+1 ; Clear the driver pointer
|
|
|
|
|
|
|
|
tax ; Return zero
|
|
|
|
rts
|
2002-12-20 20:59:11 +00:00
|
|
|
|