2002-12-20 20:59:11 +00:00
|
|
|
;
|
|
|
|
; Ullrich von Bassewitz, 2002-12-20
|
|
|
|
;
|
|
|
|
; Common functions of the joystick API.
|
|
|
|
;
|
|
|
|
|
2013-05-31 22:36:08 +00:00
|
|
|
.import joy_libref
|
2002-12-20 20:59:11 +00:00
|
|
|
.importzp ptr1
|
2013-05-09 11:56:54 +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
|
2013-05-09 11:56:54 +00:00
|
|
|
_joy_drv: .res 2 ; Pointer to driver
|
2002-12-20 20:59:11 +00:00
|
|
|
|
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:
|
2013-05-09 11:56:54 +00:00
|
|
|
joy_install: jmp $0000
|
|
|
|
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
|
2013-05-09 11:56:54 +00:00
|
|
|
joy_sig: .byte $6A, $6F, $79, JOY_API_VERSION ; "joy", version
|
2002-12-20 20:59:11 +00:00
|
|
|
|
|
|
|
|
2006-03-31 20:07:43 +00:00
|
|
|
.code
|
2002-12-20 20:59:11 +00:00
|
|
|
;----------------------------------------------------------------------------
|
|
|
|
; unsigned char __fastcall__ joy_install (void* driver);
|
|
|
|
; /* Install the driver once it is loaded */
|
|
|
|
|
|
|
|
|
|
|
|
_joy_install:
|
2013-05-09 11:56:54 +00:00
|
|
|
sta _joy_drv
|
|
|
|
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
|
|
|
|
|
2013-05-31 22:36:08 +00:00
|
|
|
; Set the library reference
|
|
|
|
|
|
|
|
ldy #JOY_HDR::LIBREF
|
|
|
|
lda #<joy_libref
|
|
|
|
sta (ptr1),y
|
|
|
|
iny
|
|
|
|
lda #>joy_libref
|
|
|
|
sta (ptr1),y
|
|
|
|
|
2002-12-20 20:59:11 +00:00
|
|
|
; 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
|
2005-09-05 20:24:37 +00:00
|
|
|
tay ; Test error code
|
|
|
|
bne @L3 ; Bail out if install had errors
|
2004-11-06 13:05:26 +00:00
|
|
|
|
|
|
|
; 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
|
2013-05-09 11:56:54 +00:00
|
|
|
ldy #$4C ; JMP opcode
|
|
|
|
sty joy_irq ; Activate IRQ routine
|
2004-11-06 13:05:26 +00:00
|
|
|
@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
|
|
|
|
|
|
|
|
;----------------------------------------------------------------------------
|
2012-03-04 13:08:54 +00:00
|
|
|
; unsigned char joy_uninstall (void);
|
2003-02-10 22:11:12 +00:00
|
|
|
; /* Uninstall the currently loaded driver. Note: This call does not free
|
2014-06-30 09:10:35 +00:00
|
|
|
; ** allocated memory.
|
|
|
|
; */
|
2003-02-10 22:11:12 +00:00
|
|
|
|
|
|
|
_joy_uninstall:
|
2013-05-09 11:56:54 +00:00
|
|
|
lda #$60 ; RTS opcode
|
|
|
|
sta joy_irq ; Disable IRQ entry point
|
2004-11-06 13:05:26 +00:00
|
|
|
|
2003-02-10 22:11:12 +00:00
|
|
|
jsr joy_uninstall ; Call the driver routine
|
2002-12-20 20:59:11 +00:00
|
|
|
|
2006-06-04 10:15:18 +00:00
|
|
|
_joy_clear_ptr: ; External entry point
|
2003-02-10 22:11:12 +00:00
|
|
|
lda #0
|
|
|
|
sta _joy_drv
|
|
|
|
sta _joy_drv+1 ; Clear the driver pointer
|
|
|
|
|
|
|
|
tax ; Return zero
|
|
|
|
rts
|