X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libsrc%2Fmouse%2Fmouse-kernel.s;h=b8d1db185eecf6f20f686281e8d5948579c2b142;hb=9c177602277c9fdf515a29931089738cc70700ee;hp=3cb9a2fa5dc6fed78e298bddca8761f456c7b977;hpb=e5854b0d7a7adabbcc21a447b1db36f37bfe46f4;p=cc65 diff --git a/libsrc/mouse/mouse-kernel.s b/libsrc/mouse/mouse-kernel.s index 3cb9a2fa5..b8d1db185 100644 --- a/libsrc/mouse/mouse-kernel.s +++ b/libsrc/mouse/mouse-kernel.s @@ -1,12 +1,12 @@ ; -; Ullrich von Bassewitz, 2003-12-28 +; Ullrich von Bassewitz, 2003-12-28, 2009-09-26 ; ; Common functions of the mouse driver API. ; .import return0, popsreg, incsp2 .importzp sreg, ptr1, tmp1, tmp2 - .condes mouse_irq, 2 ; Export as IRQ handler + .interruptor mouse_irq ; Export as IRQ handler .include "mouse-kernel.inc" @@ -28,19 +28,22 @@ mouse_install: jmp return0 mouse_uninstall:jmp return0 mouse_hide: jmp return0 mouse_show: jmp return0 -mouse_box: jmp return0 +mouse_setbox: jmp return0 +mouse_getbox: jmp return0 mouse_move: jmp return0 mouse_buttons: jmp return0 mouse_pos: jmp return0 mouse_info: jmp return0 mouse_ioctl: jmp return0 mouse_irq: .byte $60, $00, $00 ; RTS plus two dummy bytes +mouse_flags: .byte $00 ; Driver header signature .rodata mouse_sig: .byte $6d, $6f, $75, MOUSE_API_VERSION ; "mou", version +.code ;---------------------------------------------------------------------------- ; unsigned char __fastcall__ mouse_install (const struct mouse_callbacks* c, ; void* driver); @@ -76,6 +79,12 @@ _mouse_install: cpy #(MOUSE_HDR::JUMPTAB + .sizeof(MOUSE_HDR::JUMPTAB)) bne @L1 +; Copy the flags byte. It is located directly behind the jump vectors, so Y +; is already correct when we come here. To save code, we use copyjv - crude +; but effective. + + jsr copyjv + ; Copy the callback vectors into the driver space jsr popsreg @@ -91,18 +100,36 @@ _mouse_install: ldy tmp1 bpl @L2 -; Call driver install routine +; Install the IRQ vector if the driver needs it + + bit mouse_flags ; Test MOUSE_FLAG_EARLY_IRQ + bvc @L3 ; Jump if no interrupts at this time + jsr install_irq ; Activate IRQ routine - jsr mouse_install +; Call driver install routine and check for errors -; Install the IRQ vector if the driver needs it. A/X contains the error code -; from mouse_install, so don't use it. +@L3: jsr mouse_install + tay ; Test error code + bne uninstall_irq ; Jump on error - ldy mouse_irq+2 ; Check high byte of IRQ vector - beq @L3 ; Jump if vector invalid - ldy #$4C ; Jump opcode +; No errors on INSTALL. If the driver needs late IRQs, enable them now. Be +; careful not to use A/X since these registers contain the error code from +; INSTALL. + + bit mouse_flags ; Test MOUSE_FLAG_LATE_IRQ + bpl Exit ; Jump if vector not needed +install_irq: + ldy #$4C ; Jump opcode sty mouse_irq ; Activate IRQ routine -@L3: rts +Exit: rts + +; Uninstall IRQ vector if install routine had errors. A/X may contain the +; error code from mouse_install, so don't use it. + +uninstall_irq: + ldy #$60 ; RTS opcode + sty mouse_irq ; Disable IRQ entry point + rts ; Driver signature invalid. One word is still on the stack @@ -133,12 +160,22 @@ copycb: lda (sreg),y ; /* Uninstall the currently loaded driver. Returns an error code. */ _mouse_uninstall: - jsr mouse_uninstall ; Call driver routine - lda #$60 ; RTS opcode - sta mouse_irq ; Disable IRQ entry point +; Depending on the late/early IRQ flag, we will disable IRQs before or after +; calling the driver mouse_uninstall routine. + + bit mouse_flags ; Test MOUSE_FLAG_LATE_IRQ + bpl @L1 ; Don't disable interrupts now + jsr uninstall_irq ; Disable driver interrupts +@L1: jsr mouse_uninstall ; Call driver routine + +; We don't check the flag a second time here, since disabling IRQs twice, +; or disabling them if they weren't enabled will do no harm, and the missing +; check will save a few bytes. -mouse_clear_ptr: ; External entry point + jsr uninstall_irq ; Disable driver interrupts + +_mouse_clear_ptr: ; External entry point lda #0 sta _mouse_drv sta _mouse_drv+1 ; Clear the driver pointer @@ -146,3 +183,4 @@ mouse_clear_ptr: ; External entry point tax rts ; Return zero +