1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-23 09:29:34 +00:00

Changed the mouse API: Introduced a new flag byte that contains information

about the driver, the mouse kernel needs to know. Current supported: Two flags
to enable interrupts before or after calling the driver INSTALL routine.


git-svn-id: svn://svn.cc65.org/cc65/trunk@3741 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz 2006-05-21 11:25:31 +00:00
parent b6cb833560
commit 4b8d90d2de
7 changed files with 75 additions and 30 deletions

View File

@ -2,11 +2,11 @@
;/* */ ;/* */
;/* mouse-kernel.inc */ ;/* mouse-kernel.inc */
;/* */ ;/* */
;/* Mouse API */ ;/* Mouse API */
;/* */ ;/* */
;/* */ ;/* */
;/* */ ;/* */
;/* (C) 2003-2004 Ullrich von Bassewitz */ ;/* (C) 2003-2006 Ullrich von Bassewitz */
;/* Römerstraße 52 */ ;/* Römerstraße 52 */
;/* D-70794 Filderstadt */ ;/* D-70794 Filderstadt */
;/* EMail: uz@cc65.org */ ;/* EMail: uz@cc65.org */
@ -69,6 +69,7 @@
IOCTL .addr IOCTL .addr
IRQ .addr IRQ .addr
.endstruct .endstruct
FLAGS .byte ; Mouse driver flags
CALLBACKS .struct ; Jump instructions CALLBACKS .struct ; Jump instructions
.byte ; JMP opcode .byte ; JMP opcode
CHIDE .addr ; Jump address CHIDE .addr ; Jump address
@ -94,7 +95,16 @@
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
; The mouse API version, stored in MOUSE_HDR::VERSION ; The mouse API version, stored in MOUSE_HDR::VERSION
MOUSE_API_VERSION = $00 MOUSE_API_VERSION = $01
;------------------------------------------------------------------------------
; Bitmapped mouse driver flags, stored in MOUSE_HDR::FLAGS.
; Note: If neither of MOUSE_FLAG_XXX_IRQ is set, no interrupts are supplied
; to the driver. If one of the bits is set, the interrupt vector MUST be
; valid.
MOUSE_FLAG_EARLY_IRQ = $40 ; Enable IRQ *before* calling INSTALL
MOUSE_FLAG_LATE_IRQ = $80 ; Enable IRQ *after* calling INSTALL
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
; Mouse button definitions ; Mouse button definitions

View File

@ -46,6 +46,9 @@ status := $0778
.addr IOCTL .addr IOCTL
.addr IRQ .addr IRQ
; Mouse driver flags
.byte MOUSE_FLAG_EARLY_IRQ
; Callback table, set by the kernel before INSTALL is called ; Callback table, set by the kernel before INSTALL is called
CHIDE: jmp $0000 ; Hide the cursor CHIDE: jmp $0000 ; Hide the cursor
CSHOW: jmp $0000 ; Show the cursor CSHOW: jmp $0000 ; Show the cursor
@ -55,10 +58,10 @@ CMOVEY: jmp $0000 ; Move the cursor to Y coord
; ------------------------------------------------------------------------ ; ------------------------------------------------------------------------
.bss .bss
slot: .res 1 slot: .res 1
visible:.res 1 visible:.res 1
; ------------------------------------------------------------------------ ; ------------------------------------------------------------------------
.rodata .rodata
@ -78,7 +81,7 @@ size = * - values
; ------------------------------------------------------------------------ ; ------------------------------------------------------------------------
.data .data
info: .word 279 / 2 ; MOUSE_INFO::MOUSE_POS::XCOORD info: .word 279 / 2 ; MOUSE_INFO::MOUSE_POS::XCOORD
.word 191 / 2 ; MOUSE_INFO::MOUSE_POS::YCOORD .word 191 / 2 ; MOUSE_INFO::MOUSE_POS::YCOORD
.byte %00000000 ; MOUSE_INFO::BUTTONS .byte %00000000 ; MOUSE_INFO::BUTTONS
@ -95,7 +98,7 @@ xparam: ldx #$FF ; Patched at runtime
yparam: ldy #$FF ; Patched at runtime yparam: ldy #$FF ; Patched at runtime
jump: jmp $FFFF ; Patched at runtime jump: jmp $FFFF ; Patched at runtime
; ------------------------------------------------------------------------ ; ------------------------------------------------------------------------
.code .code
@ -127,13 +130,13 @@ next: inc ptr1+1
bne next bne next
dex dex
bpl :- bpl :-
; Get and patch firmware address hibyte ; Get and patch firmware address hibyte
lda ptr1+1 lda ptr1+1
sta lookup+2 sta lookup+2
sta xparam+1 sta xparam+1
sta jump+2 sta jump+2
; Convert to and save slot number ; Convert to and save slot number
and #$0F and #$0F
sta slot sta slot
@ -158,7 +161,7 @@ next: inc ptr1+1
ldx #SETMOUSE ldx #SETMOUSE
jsr firmware jsr firmware
; Set initial mouse clamps ; Set initial mouse clamps
lda #<279 lda #<279
ldx #>279 ldx #>279
sta pos2_lo sta pos2_lo
@ -206,7 +209,7 @@ UNINSTALL:
; Hide cursor ; Hide cursor
sei sei
jsr CHIDE jsr CHIDE
; Turn mouse off ; Turn mouse off
lda #%00000000 lda #%00000000
ldx #SETMOUSE ldx #SETMOUSE
@ -252,7 +255,7 @@ BOX:
ldx #$01 ; Set y clamps ldx #$01 ; Set y clamps
ldy #$00 ; Start at top of stack ldy #$00 ; Start at top of stack
jsr :+ jsr :+
ldx #$00 ; Set x clamps ldx #$00 ; Set x clamps
ldy #$00 ; Start at top of stack ldy #$00 ; Start at top of stack
@ -307,7 +310,7 @@ MOVE:
; Update cursor ; Update cursor
jsr update jsr update
ldx #POSMOUSE ldx #POSMOUSE
bne common ; Branch always bne common ; Branch always
@ -345,7 +348,7 @@ IOCTL:
lda #<MOUSE_ERR_INV_IOCTL lda #<MOUSE_ERR_INV_IOCTL
ldx #>MOUSE_ERR_INV_IOCTL ldx #>MOUSE_ERR_INV_IOCTL
rts rts
; IRQ: Called from the builtin runtime IRQ handler as a subroutine. All ; IRQ: Called from the builtin runtime IRQ handler as a subroutine. All
; registers are already saved, no parameters are passed, but the carry flag ; registers are already saved, no parameters are passed, but the carry flag
; is clear on entry. The routine must return with carry set if the interrupt ; is clear on entry. The routine must return with carry set if the interrupt
@ -365,7 +368,7 @@ IRQ:
ldy slot ldy slot
lda status,y lda status,y
tax ; Save status tax ; Save status
; Extract button down values ; Extract button down values
asl ; C = Button 0 is currently down asl ; C = Button 0 is currently down
and #%00100000 ; !Z = Button 1 is currently down and #%00100000 ; !Z = Button 1 is currently down
@ -376,7 +379,7 @@ IRQ:
: bcc :+ : bcc :+
ora #MOUSE_BTN_LEFT ora #MOUSE_BTN_LEFT
: sta info + MOUSE_INFO::BUTTONS : sta info + MOUSE_INFO::BUTTONS
; Check for mouse movement ; Check for mouse movement
txa ; Restore status txa ; Restore status
and #%00100000 ; X or Y changed since last READMOUSE and #%00100000 ; X or Y changed since last READMOUSE
@ -384,7 +387,7 @@ IRQ:
; Remove the cursor at the old position ; Remove the cursor at the old position
update: jsr CHIDE update: jsr CHIDE
; Get and set the new X position ; Get and set the new X position
ldy slot ldy slot
lda pos1_lo,y lda pos1_lo,y
@ -392,7 +395,7 @@ update: jsr CHIDE
sta info + MOUSE_POS::XCOORD sta info + MOUSE_POS::XCOORD
stx info + MOUSE_POS::XCOORD+1 stx info + MOUSE_POS::XCOORD+1
jsr CMOVEX jsr CMOVEX
; Get and set the new Y position ; Get and set the new Y position
ldy slot ldy slot
lda pos2_lo,y lda pos2_lo,y

View File

@ -37,6 +37,10 @@ HEADER:
.addr IOCTL .addr IOCTL
.addr IRQ .addr IRQ
; Mouse driver flags
.byte MOUSE_FLAG_LATE_IRQ
; Callback table, set by the kernel before INSTALL is called ; Callback table, set by the kernel before INSTALL is called
CHIDE: jmp $0000 ; Hide the cursor CHIDE: jmp $0000 ; Hide the cursor

View File

@ -36,6 +36,10 @@ HEADER:
.addr IOCTL .addr IOCTL
.addr IRQ .addr IRQ
; Mouse driver flags
.byte MOUSE_FLAG_LATE_IRQ
; Callback table, set by the kernel before INSTALL is called ; Callback table, set by the kernel before INSTALL is called
CHIDE: jmp $0000 ; Hide the cursor CHIDE: jmp $0000 ; Hide the cursor

View File

@ -37,6 +37,10 @@ HEADER:
.addr IOCTL .addr IOCTL
.addr IRQ .addr IRQ
; Mouse driver flags
.byte MOUSE_FLAG_LATE_IRQ
; Callback table, set by the kernel before INSTALL is called ; Callback table, set by the kernel before INSTALL is called
CHIDE: jmp $0000 ; Hide the cursor CHIDE: jmp $0000 ; Hide the cursor
@ -357,7 +361,7 @@ IRQ: lda SID_ADConv1 ; Get mouse X movement
; Move the mouse pointer to the new X pos ; Move the mouse pointer to the new X pos
tya tya
jsr CMOVEY jsr CMOVEY
; Done ; Done

View File

@ -36,6 +36,10 @@ HEADER:
.addr IOCTL .addr IOCTL
.addr IRQ .addr IRQ
; Mouse driver flags
.byte MOUSE_FLAG_LATE_IRQ
; Callback table, set by the kernel before INSTALL is called ; Callback table, set by the kernel before INSTALL is called
CHIDE: jmp $0000 ; Hide the cursor CHIDE: jmp $0000 ; Hide the cursor

View File

@ -35,6 +35,7 @@ mouse_pos: jmp return0
mouse_info: jmp return0 mouse_info: jmp return0
mouse_ioctl: jmp return0 mouse_ioctl: jmp return0
mouse_irq: .byte $60, $00, $00 ; RTS plus two dummy bytes mouse_irq: .byte $60, $00, $00 ; RTS plus two dummy bytes
mouse_flags: .byte $00
; Driver header signature ; Driver header signature
.rodata .rodata
@ -77,6 +78,12 @@ _mouse_install:
cpy #(MOUSE_HDR::JUMPTAB + .sizeof(MOUSE_HDR::JUMPTAB)) cpy #(MOUSE_HDR::JUMPTAB + .sizeof(MOUSE_HDR::JUMPTAB))
bne @L1 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 ; Copy the callback vectors into the driver space
jsr popsreg jsr popsreg
@ -94,23 +101,34 @@ _mouse_install:
; Install the IRQ vector if the driver needs it ; Install the IRQ vector if the driver needs it
lda mouse_irq+2 ; Check high byte of IRQ vector bit mouse_flags ; Test MOUSE_FLAG_EARLY_IRQ
beq @L3 ; Jump if vector invalid bvc @L3 ; Jump if no interrupts at this time
lda #$4C ; Jump opcode jsr install_irq ; Activate IRQ routine
sta mouse_irq ; Activate IRQ routine
; Call driver install routine and check for errors ; Call driver install routine and check for errors
@L3: jsr mouse_install @L3: jsr mouse_install
tay ; Test error code tay ; Test error code
beq @L4 ; Jump if no error bne uninstall_irq ; Jump on error
; Uninstall IRQ vector if install routine had errors. A/X contains the error ; No errors on INSTALL. If the driver needs late IRQs, enable them now. Be
; code from mouse_install, so don't use it. ; 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
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 ldy #$60 ; RTS opcode
sty mouse_irq ; Disable IRQ entry point sty mouse_irq ; Disable IRQ entry point
@L4: rts rts
; Driver signature invalid. One word is still on the stack ; Driver signature invalid. One word is still on the stack
@ -141,9 +159,7 @@ copycb: lda (sreg),y
; /* Uninstall the currently loaded driver. Returns an error code. */ ; /* Uninstall the currently loaded driver. Returns an error code. */
_mouse_uninstall: _mouse_uninstall:
lda #$60 ; RTS opcode jsr uninstall_irq ; Disable driver interrupts
sta mouse_irq ; Disable IRQ entry point
jsr mouse_uninstall ; Call driver routine jsr mouse_uninstall ; Call driver routine
mouse_clear_ptr: ; External entry point mouse_clear_ptr: ; External entry point