Working on loadable mouse drivers
git-svn-id: svn://svn.cc65.org/cc65/trunk@2953 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
@@ -24,7 +24,8 @@ S_OBJS = mouse-kernel.o \
|
||||
mouse_info.o \
|
||||
mouse_ioctl.o \
|
||||
mouse_pos.o \
|
||||
mouse_show.o
|
||||
mouse_show.o \
|
||||
mouse_unload.o
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
# Targets
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
; Common functions of the mouse driver API.
|
||||
;
|
||||
|
||||
.import return0
|
||||
.importzp ptr1
|
||||
.import return0, popsreg, incsp2
|
||||
.importzp sreg, ptr1, tmp1, tmp2
|
||||
.condes mouse_irq, 2 ; Export as IRQ handler
|
||||
|
||||
.include "mouse-kernel.inc"
|
||||
@@ -42,15 +42,14 @@ mouse_sig: .byte $6d, $6f, $75, MOUSE_API_VERSION ; "mou", version
|
||||
|
||||
|
||||
;----------------------------------------------------------------------------
|
||||
; unsigned char __fastcall__ mouse_install (void* driver);
|
||||
; unsigned char __fastcall__ mouse_install (const struct mouse_callbacks* c,
|
||||
; void* driver);
|
||||
; /* Install an already loaded driver. Returns an error code. */
|
||||
|
||||
|
||||
|
||||
_mouse_install:
|
||||
sta _mouse_drv
|
||||
sta ptr1
|
||||
stx _mouse_drv+1
|
||||
stx _mouse_drv+1
|
||||
stx ptr1+1
|
||||
|
||||
; Check the driver signature
|
||||
@@ -72,34 +71,62 @@ _mouse_install:
|
||||
ldy #MOUSE_HDR::JUMPTAB
|
||||
ldx #0
|
||||
@L1: inx ; Skip the JMP opcode
|
||||
jsr copy ; Copy one byte
|
||||
jsr copy ; Copy one byte
|
||||
jsr copyjv ; Copy one byte
|
||||
jsr copyjv ; Copy one byte
|
||||
cpy #(MOUSE_HDR::JUMPTAB + .sizeof(MOUSE_HDR::JUMPTAB))
|
||||
bne @L1
|
||||
|
||||
jsr mouse_install ; Call driver install routine
|
||||
; 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
|
||||
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.
|
||||
|
||||
ldy mouse_irq+2 ; Check high byte of IRQ vector
|
||||
beq @L2 ; Jump if vector invalid
|
||||
ldy #$4C ; Jump opcode
|
||||
beq @L3 ; Jump if vector invalid
|
||||
ldy #$4C ; Jump opcode
|
||||
sty mouse_irq ; Activate IRQ routine
|
||||
@L2: rts
|
||||
@L3: rts
|
||||
|
||||
; Driver signature invalid
|
||||
; Driver signature invalid. One word is still on the stack
|
||||
|
||||
inv_drv:
|
||||
lda #MOUSE_ERR_INV_DRIVER
|
||||
ldx #0
|
||||
rts
|
||||
jmp incsp2
|
||||
|
||||
; Copy one byte from the jump vectors
|
||||
|
||||
copy: lda (ptr1),y
|
||||
copyjv: lda (ptr1),y
|
||||
sta mouse_vectors,x
|
||||
iny
|
||||
inx
|
||||
rts
|
||||
|
||||
; Copy one byte from the callback vectors
|
||||
|
||||
copycb: lda (sreg),y
|
||||
dec tmp1
|
||||
ldy tmp2
|
||||
sta (ptr1),y
|
||||
dec tmp2
|
||||
rts
|
||||
|
||||
;----------------------------------------------------------------------------
|
||||
; unsigned char __fastcall__ mouse_uninstall (void);
|
||||
; /* Uninstall the currently loaded driver. Returns an error code. */
|
||||
|
||||
@@ -42,7 +42,13 @@
|
||||
|
||||
|
||||
|
||||
unsigned char __fastcall__ mouse_load_driver (const char* name)
|
||||
/* Use static local variables, since the module is not reentrant anyway */
|
||||
#pragma staticlocals (on);
|
||||
|
||||
|
||||
|
||||
unsigned char __fastcall__ mouse_load_driver (const struct mouse_callbacks* c,
|
||||
const char* name)
|
||||
/* Load a mouse driver and return an error code */
|
||||
{
|
||||
static struct mod_ctrl ctrl = {
|
||||
@@ -69,7 +75,7 @@ unsigned char __fastcall__ mouse_load_driver (const char* name)
|
||||
if (Res == MLOAD_OK) {
|
||||
|
||||
/* Check the driver signature, install the driver */
|
||||
return mouse_install (ctrl.module);
|
||||
return mouse_install (c, ctrl.module);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
35
libsrc/mouse/mouse_unload.s
Normal file
35
libsrc/mouse/mouse_unload.s
Normal file
@@ -0,0 +1,35 @@
|
||||
;
|
||||
; Ullrich von Bassewitz, 2004-03-21
|
||||
;
|
||||
; unsigned char __fastcall__ mouse_unload (void);
|
||||
; /* Uninstall, then unload the currently loaded driver. */
|
||||
|
||||
|
||||
.import mouse_clear_ptr
|
||||
|
||||
.include "mouse-kernel.inc"
|
||||
.include "modload.inc"
|
||||
|
||||
|
||||
_mouse_unload:
|
||||
lda _mouse_drv
|
||||
ora _mouse_drv+1
|
||||
beq no_driver ; No driver
|
||||
|
||||
lda _mouse_drv
|
||||
pha
|
||||
lda _mouse_drv+1
|
||||
pha ; Save pointer to driver
|
||||
|
||||
jsr _mouse_uninstall ; Uninstall the driver
|
||||
|
||||
pla
|
||||
tax
|
||||
pla ; Get pointer to driver
|
||||
jmp _mod_free ; Free the driver
|
||||
|
||||
no_driver:
|
||||
tax ; X = 0
|
||||
lda #<MOUSE_ERR_NO_DRIVER
|
||||
rts
|
||||
|
||||
Reference in New Issue
Block a user