2003-12-28 21:25:15 +00:00
|
|
|
;
|
|
|
|
; Ullrich von Bassewitz, 2003-12-28
|
|
|
|
;
|
|
|
|
; Common functions of the mouse driver API.
|
|
|
|
;
|
|
|
|
|
2004-03-21 22:12:06 +00:00
|
|
|
.import return0, popsreg, incsp2
|
|
|
|
.importzp sreg, ptr1, tmp1, tmp2
|
2003-12-30 08:08:07 +00:00
|
|
|
.condes mouse_irq, 2 ; Export as IRQ handler
|
2003-12-28 21:25:15 +00:00
|
|
|
|
|
|
|
.include "mouse-kernel.inc"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;----------------------------------------------------------------------------
|
|
|
|
; Variables
|
|
|
|
|
|
|
|
|
|
|
|
.bss
|
|
|
|
_mouse_drv: .res 2 ; Pointer to driver
|
|
|
|
|
2004-02-02 12:26:50 +00:00
|
|
|
_mouse_hidden: .res 1 ; Mouse visibility flag
|
|
|
|
|
2003-12-28 21:25:15 +00:00
|
|
|
; Jump table for the driver functions.
|
|
|
|
.data
|
|
|
|
mouse_vectors:
|
|
|
|
mouse_install: jmp return0
|
|
|
|
mouse_uninstall:jmp return0
|
|
|
|
mouse_hide: jmp return0
|
|
|
|
mouse_show: jmp return0
|
|
|
|
mouse_box: jmp return0
|
|
|
|
mouse_move: jmp return0
|
|
|
|
mouse_buttons: jmp return0
|
|
|
|
mouse_pos: jmp return0
|
|
|
|
mouse_info: jmp return0
|
2003-12-30 08:08:07 +00:00
|
|
|
mouse_ioctl: jmp return0
|
|
|
|
mouse_irq: .byte $60, $00, $00 ; RTS plus two dummy bytes
|
2003-12-28 21:25:15 +00:00
|
|
|
|
|
|
|
; Driver header signature
|
|
|
|
.rodata
|
|
|
|
mouse_sig: .byte $6d, $6f, $75, MOUSE_API_VERSION ; "mou", version
|
|
|
|
|
|
|
|
|
|
|
|
;----------------------------------------------------------------------------
|
2004-03-21 22:12:06 +00:00
|
|
|
; unsigned char __fastcall__ mouse_install (const struct mouse_callbacks* c,
|
|
|
|
; void* driver);
|
2003-12-28 21:25:15 +00:00
|
|
|
; /* Install an already loaded driver. Returns an error code. */
|
|
|
|
|
|
|
|
_mouse_install:
|
|
|
|
sta _mouse_drv
|
|
|
|
sta ptr1
|
2004-03-21 22:12:06 +00:00
|
|
|
stx _mouse_drv+1
|
2003-12-28 21:25:15 +00:00
|
|
|
stx ptr1+1
|
|
|
|
|
|
|
|
; Check the driver signature
|
|
|
|
|
|
|
|
ldy #.sizeof(mouse_sig)-1
|
|
|
|
@L0: lda (ptr1),y
|
|
|
|
cmp mouse_sig,y
|
|
|
|
bne inv_drv
|
|
|
|
dey
|
|
|
|
bpl @L0
|
|
|
|
|
2004-02-02 12:26:50 +00:00
|
|
|
; Reset flags
|
|
|
|
|
|
|
|
lda #1
|
|
|
|
sta _mouse_hidden
|
|
|
|
|
2003-12-28 21:25:15 +00:00
|
|
|
; Copy the jump vectors
|
|
|
|
|
|
|
|
ldy #MOUSE_HDR::JUMPTAB
|
|
|
|
ldx #0
|
|
|
|
@L1: inx ; Skip the JMP opcode
|
2004-03-21 22:12:06 +00:00
|
|
|
jsr copyjv ; Copy one byte
|
|
|
|
jsr copyjv ; Copy one byte
|
2003-12-28 21:25:15 +00:00
|
|
|
cpy #(MOUSE_HDR::JUMPTAB + .sizeof(MOUSE_HDR::JUMPTAB))
|
|
|
|
bne @L1
|
|
|
|
|
2004-03-21 22:12:06 +00:00
|
|
|
; Copy the callback vectors into the driver space
|
|
|
|
|
|
|
|
jsr popsreg
|
|
|
|
ldy #(MOUSE_HDR::CALLBACKS + .sizeof(MOUSE_HDR::CALLBACKS) - 1)
|
|
|
|
sty tmp2
|
|
|
|
ldy #.sizeof(MOUSE_CALLBACKS)-1
|
|
|
|
sty tmp1
|
|
|
|
|
|
|
|
@L2: jsr copycb
|
2004-03-23 20:37:40 +00:00
|
|
|
ldy tmp1
|
2004-03-21 22:12:06 +00:00
|
|
|
jsr copycb
|
|
|
|
dec tmp2 ; Skip opcode byte
|
|
|
|
ldy tmp1
|
|
|
|
bpl @L2
|
|
|
|
|
|
|
|
; Call driver install routine
|
|
|
|
|
|
|
|
jsr mouse_install
|
|
|
|
|
|
|
|
; Install the IRQ vector if the driver needs it. A/X contains the error code
|
|
|
|
; from mouse_install, so don't use it.
|
2003-12-28 21:25:15 +00:00
|
|
|
|
2003-12-30 08:08:07 +00:00
|
|
|
ldy mouse_irq+2 ; Check high byte of IRQ vector
|
2004-03-21 22:12:06 +00:00
|
|
|
beq @L3 ; Jump if vector invalid
|
|
|
|
ldy #$4C ; Jump opcode
|
2003-12-30 08:08:07 +00:00
|
|
|
sty mouse_irq ; Activate IRQ routine
|
2004-03-21 22:12:06 +00:00
|
|
|
@L3: rts
|
2003-12-30 08:08:07 +00:00
|
|
|
|
2004-03-21 22:12:06 +00:00
|
|
|
; Driver signature invalid. One word is still on the stack
|
2003-12-28 21:25:15 +00:00
|
|
|
|
|
|
|
inv_drv:
|
|
|
|
lda #MOUSE_ERR_INV_DRIVER
|
|
|
|
ldx #0
|
2004-03-21 22:12:06 +00:00
|
|
|
jmp incsp2
|
2003-12-28 21:25:15 +00:00
|
|
|
|
|
|
|
; Copy one byte from the jump vectors
|
|
|
|
|
2004-03-21 22:12:06 +00:00
|
|
|
copyjv: lda (ptr1),y
|
2003-12-28 21:25:15 +00:00
|
|
|
sta mouse_vectors,x
|
|
|
|
iny
|
|
|
|
inx
|
|
|
|
rts
|
|
|
|
|
2004-03-21 22:12:06 +00:00
|
|
|
; Copy one byte from the callback vectors
|
|
|
|
|
|
|
|
copycb: lda (sreg),y
|
|
|
|
dec tmp1
|
|
|
|
ldy tmp2
|
|
|
|
sta (ptr1),y
|
|
|
|
dec tmp2
|
|
|
|
rts
|
|
|
|
|
2003-12-28 21:25:15 +00:00
|
|
|
;----------------------------------------------------------------------------
|
|
|
|
; unsigned char __fastcall__ mouse_uninstall (void);
|
|
|
|
; /* Uninstall the currently loaded driver. Returns an error code. */
|
|
|
|
|
|
|
|
_mouse_uninstall:
|
|
|
|
jsr mouse_uninstall ; Call driver routine
|
|
|
|
|
2003-12-30 08:08:07 +00:00
|
|
|
lda #$60 ; RTS opcode
|
|
|
|
sta mouse_irq ; Disable IRQ entry point
|
|
|
|
|
2003-12-28 21:25:15 +00:00
|
|
|
mouse_clear_ptr: ; External entry point
|
|
|
|
lda #0
|
|
|
|
sta _mouse_drv
|
|
|
|
sta _mouse_drv+1 ; Clear the driver pointer
|
|
|
|
|
|
|
|
tax
|
|
|
|
rts ; Return zero
|
|
|
|
|