mirror of
https://github.com/cc65/cc65.git
synced 2025-01-15 22:30:04 +00:00
Started debugging the mouse routines
git-svn-id: svn://svn.cc65.org/cc65/trunk@341 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
ee084ac224
commit
9633ff1882
@ -8,6 +8,7 @@
|
|||||||
.export _mouse_init, _mouse_done
|
.export _mouse_init, _mouse_done
|
||||||
.export _mouse_hide, _mouse_show
|
.export _mouse_hide, _mouse_show
|
||||||
.export _mouse_box, _mouse_info
|
.export _mouse_box, _mouse_info
|
||||||
|
.export _mouse_x, _mouse_y
|
||||||
.export _mouse_move
|
.export _mouse_move
|
||||||
|
|
||||||
.import popa, popsreg, addysp1
|
.import popa, popsreg, addysp1
|
||||||
@ -95,8 +96,7 @@ _mouse_hide:
|
|||||||
ldx MouseSprite ; Sprite defined?
|
ldx MouseSprite ; Sprite defined?
|
||||||
beq @L1 ; Jump if no
|
beq @L1 ; Jump if no
|
||||||
|
|
||||||
lda BitMask-1,x ; Get bit mask
|
lda NotMask-1,x ; Get clean mask
|
||||||
eor #$FF ; We must clear the bit
|
|
||||||
|
|
||||||
sei ; Disable interrupts
|
sei ; Disable interrupts
|
||||||
and VIC_SPR_ENA
|
and VIC_SPR_ENA
|
||||||
@ -112,15 +112,21 @@ _mouse_hide:
|
|||||||
;
|
;
|
||||||
|
|
||||||
_mouse_show:
|
_mouse_show:
|
||||||
|
lda Visible ; Mouse already visible?
|
||||||
|
beq @L1 ; Jump if yes
|
||||||
dec Visible ; Get the flag
|
dec Visible ; Get the flag
|
||||||
bne @L1 ; Jump if still invisible
|
bne @L1 ; Jump if still invisible
|
||||||
ldx MouseSprite ; Sprite defined?
|
ldx MouseSprite ; Sprite defined?
|
||||||
beq @L1 ; Jump if no
|
beq @L1 ; Jump if no
|
||||||
|
|
||||||
lda BitMask-1,x ; Get bit mask
|
|
||||||
sei ; Disable interrupts
|
sei ; Disable interrupts
|
||||||
|
jsr MoveSprite1 ; Move the sprite to it's position
|
||||||
|
|
||||||
|
ldx MouseSprite ; Get sprite number (again)
|
||||||
|
lda BitMask-1,x ; Get bit mask
|
||||||
ora VIC_SPR_ENA
|
ora VIC_SPR_ENA
|
||||||
sta VIC_SPR_ENA ; Enable sprite
|
sta VIC_SPR_ENA ; Enable sprite
|
||||||
|
|
||||||
cli ; Enable interrupts
|
cli ; Enable interrupts
|
||||||
|
|
||||||
@L1: rts
|
@L1: rts
|
||||||
@ -131,12 +137,14 @@ _mouse_show:
|
|||||||
;
|
;
|
||||||
|
|
||||||
_mouse_box:
|
_mouse_box:
|
||||||
|
ldy #0 ; Stack offset
|
||||||
|
|
||||||
|
php
|
||||||
sei ; Disable interrupts
|
sei ; Disable interrupts
|
||||||
|
|
||||||
sta YMax
|
sta YMax
|
||||||
stx YMax+1 ; maxy
|
stx YMax+1 ; maxy
|
||||||
|
|
||||||
ldy #0
|
|
||||||
lda (sp),y
|
lda (sp),y
|
||||||
sta XMax
|
sta XMax
|
||||||
iny
|
iny
|
||||||
@ -157,10 +165,36 @@ _mouse_box:
|
|||||||
lda (sp),y
|
lda (sp),y
|
||||||
sta XMin+1 ; minx
|
sta XMin+1 ; minx
|
||||||
|
|
||||||
cli ; Enable interrupts
|
plp ; Enable interrupts
|
||||||
|
|
||||||
jmp addysp1 ; Drop params, return
|
jmp addysp1 ; Drop params, return
|
||||||
|
|
||||||
|
; --------------------------------------------------------------------------
|
||||||
|
;
|
||||||
|
; int __fastcall__ mouse_x (void);
|
||||||
|
;
|
||||||
|
|
||||||
|
_mouse_x:
|
||||||
|
php
|
||||||
|
sei
|
||||||
|
lda XPos
|
||||||
|
ldx XPos+1
|
||||||
|
plp
|
||||||
|
rts
|
||||||
|
|
||||||
|
; --------------------------------------------------------------------------
|
||||||
|
;
|
||||||
|
; int __fastcall__ mouse_y (void);
|
||||||
|
;
|
||||||
|
|
||||||
|
_mouse_y:
|
||||||
|
php
|
||||||
|
sei
|
||||||
|
lda YPos
|
||||||
|
ldx YPos+1
|
||||||
|
plp
|
||||||
|
rts
|
||||||
|
|
||||||
; --------------------------------------------------------------------------
|
; --------------------------------------------------------------------------
|
||||||
;
|
;
|
||||||
; void mouse_info (...);
|
; void mouse_info (...);
|
||||||
@ -186,11 +220,6 @@ _mouse_move:
|
|||||||
sta XPos
|
sta XPos
|
||||||
stx XPos+1 ; Set new position
|
stx XPos+1 ; Set new position
|
||||||
|
|
||||||
lda Visible ; Mouse visible?
|
|
||||||
bne @L9 ; Jump if no
|
|
||||||
lda MouseSprite ; Sprite defined?
|
|
||||||
beq @L9
|
|
||||||
|
|
||||||
jsr MoveSprite ; Move the sprite to the mouse pos
|
jsr MoveSprite ; Move the sprite to the mouse pos
|
||||||
|
|
||||||
@L9: cli ; Enable interrupts
|
@L9: cli ; Enable interrupts
|
||||||
@ -215,26 +244,25 @@ MouseIRQ:
|
|||||||
tay ; Remember low byte
|
tay ; Remember low byte
|
||||||
txa
|
txa
|
||||||
adc XPos+1
|
adc XPos+1
|
||||||
|
tax
|
||||||
|
|
||||||
; Limit the X coordinate to the bounding box
|
; Limit the X coordinate to the bounding box
|
||||||
|
|
||||||
cpy XMin+1
|
cpy XMin
|
||||||
bne @L1
|
sbc XMin+1
|
||||||
cmp XMin
|
bpl @L1
|
||||||
@L1: bpl @L2
|
|
||||||
ldy XMin
|
ldy XMin
|
||||||
lda XMin+1
|
ldx XMin+1
|
||||||
jmp @L4
|
jmp @L2
|
||||||
|
@L1: txa
|
||||||
|
|
||||||
@L2: cpy XMax+1
|
cpy XMax
|
||||||
bne @L3
|
sbc XMax+1
|
||||||
cmp XMax
|
bmi @L2
|
||||||
beq @L4
|
|
||||||
@L3: bmi @L4
|
|
||||||
ldy XMax
|
ldy XMax
|
||||||
lda XMax+1
|
ldx XMax+1
|
||||||
@L4: sty XPos
|
@L2: sty XPos
|
||||||
sta XPos+1
|
stx XPos+1
|
||||||
|
|
||||||
; Calculate the Y movement vector
|
; Calculate the Y movement vector
|
||||||
|
|
||||||
@ -251,25 +279,25 @@ MouseIRQ:
|
|||||||
txa
|
txa
|
||||||
adc YPos+1
|
adc YPos+1
|
||||||
|
|
||||||
; Limit the Y coordinate to the bounding box
|
cpy YMin
|
||||||
|
sbc YMin+1
|
||||||
cpy YMin+1
|
bpl @L3
|
||||||
bne @L5
|
|
||||||
cmp YMin
|
|
||||||
@L5: bpl @L6
|
|
||||||
ldy YMin
|
ldy YMin
|
||||||
lda YMin+1
|
ldx YMin+1
|
||||||
jmp @L8
|
jmp @L4
|
||||||
|
@L3: txa
|
||||||
|
|
||||||
@L6: cpy YMax+1
|
cpy YMax
|
||||||
bne @L7
|
sbc YMax+1
|
||||||
cmp YMax
|
bmi @L4
|
||||||
beq @L8
|
|
||||||
@L7: bmi @L8
|
|
||||||
ldy YMax
|
ldy YMax
|
||||||
lda YMax+1
|
ldx YMax+1
|
||||||
@L8: sty YPos
|
@L4: sty YPos
|
||||||
sta YPos+1
|
stx YPos+1
|
||||||
|
|
||||||
|
; Move the mouse sprite if it is enabled
|
||||||
|
|
||||||
|
jsr MoveSprite ; Move the sprite
|
||||||
|
|
||||||
; Jump to the next IRQ handler
|
; Jump to the next IRQ handler
|
||||||
|
|
||||||
@ -316,40 +344,46 @@ MoveCheck:
|
|||||||
; --------------------------------------------------------------------------
|
; --------------------------------------------------------------------------
|
||||||
;
|
;
|
||||||
; Move the mouse sprite to the current mouse position. Must be called
|
; Move the mouse sprite to the current mouse position. Must be called
|
||||||
; with interrupts off.
|
; with interrupts off. MoveSprite1 is an entry without checking and
|
||||||
|
; loading X
|
||||||
;
|
;
|
||||||
|
|
||||||
MoveSprite:
|
MoveSprite:
|
||||||
lda Visible ; Mouse pointer visible?
|
|
||||||
bne @L9 ; Jump if no
|
lda Visible ; Mouse visible?
|
||||||
|
bne MoveSpriteDone ; Jump if no
|
||||||
ldx MouseSprite ; Sprite defined?
|
ldx MouseSprite ; Sprite defined?
|
||||||
beq @L9 ; Jump if no
|
beq MoveSpriteDone ; Jump if no
|
||||||
ldy BitMask-1,x ; Get high bit mask
|
|
||||||
|
; Set the high X bit
|
||||||
|
|
||||||
|
MoveSprite1:
|
||||||
|
lda VIC_SPR_HI_X ; Get high X bits of all sprites
|
||||||
|
and NotMask-1,x ; Mask out sprite bit
|
||||||
|
ldy XPos+1 ; Test Y position
|
||||||
|
beq @L1
|
||||||
|
ora BitMask-1,x ; Set high X bit
|
||||||
|
@L1: sta VIC_SPR_HI_X ; Set hi X sprite values
|
||||||
|
|
||||||
|
; Set the low X byte
|
||||||
|
|
||||||
txa
|
txa
|
||||||
asl a ; Index*2
|
asl a ; Index*2
|
||||||
tax
|
tax
|
||||||
|
|
||||||
; Set the X position
|
|
||||||
|
|
||||||
lda XPos+1 ; Negative?
|
|
||||||
bmi @L2 ; Jump if yes
|
|
||||||
beq @L1
|
|
||||||
tya ; Load high position bit
|
|
||||||
@L1: ora VIC_SPR_HI_X ; Set high bit
|
|
||||||
sta VIC_SPR_HI_X
|
|
||||||
lda XPos
|
lda XPos
|
||||||
sta VIC_SPR0_X,x ; Set low byte
|
sta VIC_SPR0_X-2,x ; Set low byte
|
||||||
|
|
||||||
; Set the Y position
|
; Set the Y position
|
||||||
|
|
||||||
@L2: ldy YPos+1 ; Negative or too large?
|
ldy YPos+1 ; Negative or too large?
|
||||||
bne @L9 ; Jump if yes
|
bne MoveSpriteDone ; Jump if yes
|
||||||
lda YPos
|
lda YPos
|
||||||
sta VIC_SPR0_Y,x ; Set Y position
|
sta VIC_SPR0_Y-2,x ; Set Y position
|
||||||
|
|
||||||
; Done
|
; Done
|
||||||
|
|
||||||
@L9: rts
|
MoveSpriteDone:
|
||||||
|
rts
|
||||||
|
|
||||||
; --------------------------------------------------------------------------
|
; --------------------------------------------------------------------------
|
||||||
; Data
|
; Data
|
||||||
@ -377,6 +411,7 @@ YMax: .res 2 ; Y2 value of bounding box
|
|||||||
.data
|
.data
|
||||||
|
|
||||||
BitMask: .byte $01, $02, $04, $08, $10, $20, $40, $80
|
BitMask: .byte $01, $02, $04, $08, $10, $20, $40, $80
|
||||||
|
NotMask: .byte $FE, $FD, $FB, $F7, $EF, $DF, $BF, $7F
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user