1
0
mirror of https://github.com/cc65/cc65.git synced 2025-01-10 19:29:45 +00:00

Polished the mouse routines

git-svn-id: svn://svn.cc65.org/cc65/trunk@899 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz 2001-09-13 15:28:21 +00:00
parent 50ccc25f05
commit 6d4953870a

View File

@ -42,13 +42,14 @@ XCORR = SPRITE_WIDTH
_mouse_init: _mouse_init:
jsr popa ; Ignore type and port jsr popa ; Ignore type and port
ldy OldIRQ+1 ; Already initialized? lda OldIRQ+1 ; Already initialized?
bne AlreadyInitialized ; Jump if yes bne AlreadyInitialized ; Jump if yes
; Initialize variables ; Initialize variables
ldx #0 ldx #0
stx XPos lda #XCORR
sta XPos
stx XPos+1 stx XPos+1
stx YPos stx YPos
stx YPos+1 stx YPos+1
@ -56,8 +57,10 @@ _mouse_init:
stx OldPotY stx OldPotY
stx XMin stx XMin
stx XMin+1 ; XMin = 0 stx XMin+1 ; XMin = 0
lda #50 ; ## FIXME: This is the PAL value lda #50 ; ## FIXME: This is the PAL value
sta YCorr sta YCorr
sta YPos
stx YPos+1
sec sec
sbc #SPRITE_HEIGHT ; Sprite height in pixels sbc #SPRITE_HEIGHT ; Sprite height in pixels
sta YMin sta YMin
@ -79,14 +82,13 @@ _mouse_init:
lda IRQVec+1 lda IRQVec+1
sta OldIRQ+1 sta OldIRQ+1
; Set our own IRQ vector. We cheat here to save a few bytes of code: ; Set our own IRQ vector.
; The function is expected to return a value not equal to zero on success,
; and since we know that the high byte of the IRQ handler address is never
; zero, we will return just this byte.
ldx #<MouseIRQ ldx #<MouseIRQ
lda #>MouseIRQ ldy #>MouseIRQ
bne SetIRQ ; Branch always jsr SetIRQ ; Set our IRQ vector, disable sprite 0
lda #1 ; Mouse successfully initialized
rts
AlreadyInitialized: AlreadyInitialized:
lda #0 ; Error lda #0 ; Error
@ -98,17 +100,21 @@ AlreadyInitialized:
; ;
_mouse_done: _mouse_done:
ldx OldIRQ ; Initialized? ldx OldIRQ
lda OldIRQ+1 ldy OldIRQ+1 ; Initialized?
beq Done ; Jump if no beq Done ; Jump if no
ldy #0 lda #0
sty OldIRQ+1 ; Reset the initialized flag sta OldIRQ+1 ; Reset the initialized flag
SetIRQ: sei ; Disable interrupts SetIRQ: sei ; Disable interrupts
stx IRQVec ; Set the new/old vector stx IRQVec ; Set the new/old vector
sta IRQVec+1 sty IRQVec+1
cli ; Enable interrupts lda VIC_SPR_ENA ; Get sprite enable register
and #$FE ; Disable sprite #0
sta VIC_SPR_ENA ; Write back
cli ; Enable interrupts
Done: rts Done: rts
; -------------------------------------------------------------------------- ; --------------------------------------------------------------------------
; ;
; void mouse_hide (void); ; void mouse_hide (void);