1
0
mirror of https://github.com/cc65/cc65.git synced 2024-07-04 13:29:35 +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:
cuz 2000-09-26 18:46:29 +00:00
parent ee084ac224
commit 9633ff1882

View File

@ -5,15 +5,16 @@
; the Commodore 1351 mouse users guide. ; the Commodore 1351 mouse users guide.
; ;
.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_move .export _mouse_x, _mouse_y
.export _mouse_move
.import popa, popsreg, addysp1 .import popa, popsreg, addysp1
.importzp sp, sreg .importzp sp, sreg
.include "c64.inc" .include "c64.inc"
.code .code
@ -23,21 +24,21 @@
; ;
_mouse_init: _mouse_init:
tax ; Save sprite number tax ; Save sprite number
jsr popa ; Get the port number jsr popa ; Get the port number
ldy OldIRQ+1 ; Already initialized? ldy OldIRQ+1 ; Already initialized?
bne Done ; Jump if yes bne Done ; Jump if yes
stx MouseSprite ; Remember the sprite number stx MouseSprite ; Remember the sprite number
sta MousePort ; Remember the port number sta MousePort ; Remember the port number
; Initialize variables ; Initialize variables
ldx #0 ldx #0
stx XPos stx XPos
stx XPos+1 stx XPos+1
stx YPos stx YPos
stx YPos+1 stx YPos+1
stx OldPotX stx OldPotX
stx OldPotY stx OldPotY
@ -45,7 +46,7 @@ _mouse_init:
stx XMin+1 stx XMin+1
stx YMin stx YMin
stx YMin+1 stx YMin+1
stx YMax+1 stx YMax+1
inx ; X = 1 inx ; X = 1
stx Visible ; Mouse *not* visible stx Visible ; Mouse *not* visible
stx XMax+1 ; >320 stx XMax+1 ; >320
@ -74,14 +75,14 @@ _mouse_init:
_mouse_done: _mouse_done:
lda OldIRQ ; Initialized? lda OldIRQ ; Initialized?
ldx OldIRQ+1 ldx OldIRQ+1
beq Done ; Jump if no beq Done ; Jump if no
ldy #0 ldy #0
sty OldIRQ+1 ; Reset the initialized flag sty OldIRQ+1 ; Reset the initialized flag
SetIRQ: sei ; Disable interrupts SetIRQ: sei ; Disable interrupts
sta IRQVec ; Set the new/old vector sta IRQVec ; Set the new/old vector
stx IRQVec+1 stx IRQVec+1
cli ; Enable interrupts cli ; Enable interrupts
Done: rts Done: rts
; -------------------------------------------------------------------------- ; --------------------------------------------------------------------------
@ -90,20 +91,19 @@ Done: rts
; ;
_mouse_hide: _mouse_hide:
lda Visible ; Get the flag lda Visible ; Get the flag
bne @L1 ; Jump if already invisible bne @L1 ; Jump if already 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 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
sta VIC_SPR_ENA ; Disable sprite sta VIC_SPR_ENA ; Disable sprite
cli ; Enable interrupts cli ; Enable interrupts
@L1: inc Visible ; Set the flag to invisible @L1: inc Visible ; Set the flag to invisible
rts rts
; -------------------------------------------------------------------------- ; --------------------------------------------------------------------------
@ -112,16 +112,22 @@ _mouse_hide:
; ;
_mouse_show: _mouse_show:
dec Visible ; Get the flag lda Visible ; Mouse already visible?
bne @L1 ; Jump if still invisible beq @L1 ; Jump if yes
ldx MouseSprite ; Sprite defined? dec Visible ; Get the flag
beq @L1 ; Jump if no bne @L1 ; Jump if still invisible
ldx MouseSprite ; Sprite defined?
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
ora VIC_SPR_ENA
sta VIC_SPR_ENA ; Enable sprite ldx MouseSprite ; Get sprite number (again)
cli ; Enable interrupts lda BitMask-1,x ; Get bit mask
ora VIC_SPR_ENA
sta VIC_SPR_ENA ; Enable sprite
cli ; Enable interrupts
@L1: rts @L1: rts
@ -131,35 +137,63 @@ _mouse_show:
; ;
_mouse_box: _mouse_box:
sei ; Disable interrupts ldy #0 ; Stack offset
sta YMax php
stx YMax+1 ; maxy sei ; Disable interrupts
ldy #0 sta YMax
lda (sp),y stx YMax+1 ; maxy
sta XMax
iny
lda (sp),y
sta XMax+1 ; maxx
iny lda (sp),y
lda (sp),y sta XMax
sta YMin iny
iny lda (sp),y
lda (sp),y sta XMax+1 ; maxx
sta YMin+1 ; miny
iny iny
lda (sp),y lda (sp),y
sta XMin sta YMin
iny iny
lda (sp),y lda (sp),y
sta XMin+1 ; minx sta YMin+1 ; miny
cli ; Enable interrupts iny
lda (sp),y
sta XMin
iny
lda (sp),y
sta XMin+1 ; minx
jmp addysp1 ; Drop params, return plp ; Enable interrupts
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
; -------------------------------------------------------------------------- ; --------------------------------------------------------------------------
; ;
@ -183,14 +217,9 @@ _mouse_move:
stx YPos+1 stx YPos+1
lda sreg lda sreg
ldx sreg+1 ldx sreg+1
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
@ -203,38 +232,37 @@ _mouse_move:
MouseIRQ: MouseIRQ:
cld cld
lda SID_ADConv1 ; Get mouse X movement lda SID_ADConv1 ; Get mouse X movement
ldy OldPotX ldy OldPotX
jsr MoveCheck ; Calculate movement vector jsr MoveCheck ; Calculate movement vector
sty OldPotX sty OldPotX
; Calculate the new X coordinate (--> a/y) ; Calculate the new X coordinate (--> a/y)
clc clc
adc XPos adc XPos
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 ldx XMin+1
lda XMin+1 jmp @L2
jmp @L4 @L1: txa
@L2: cpy XMax+1 cpy XMax
bne @L3 sbc XMax+1
cmp XMax bmi @L2
beq @L4 ldy XMax
@L3: bmi @L4 ldx XMax+1
ldy XMax @L2: sty XPos
lda XMax+1 stx XPos+1
@L4: sty XPos
sta XPos+1
; Calculate the Y movement vector ; Calculate the Y movement vector
@ -249,47 +277,47 @@ MouseIRQ:
adc YPos adc YPos
tay ; Remember low byte tay ; Remember low byte
txa txa
adc YPos+1 adc YPos+1
; Limit the Y coordinate to the bounding box cpy YMin
sbc YMin+1
bpl @L3
ldy YMin
ldx YMin+1
jmp @L4
@L3: txa
cpy YMin+1 cpy YMax
bne @L5 sbc YMax+1
cmp YMin bmi @L4
@L5: bpl @L6 ldy YMax
ldy YMin ldx YMax+1
lda YMin+1 @L4: sty YPos
jmp @L8 stx YPos+1
@L6: cpy YMax+1 ; Move the mouse sprite if it is enabled
bne @L7
cmp YMax jsr MoveSprite ; Move the sprite
beq @L8
@L7: bmi @L8
ldy YMax
lda YMax+1
@L8: sty YPos
sta YPos+1
; Jump to the next IRQ handler ; Jump to the next IRQ handler
jmp (OldIRQ) jmp (OldIRQ)
; -------------------------------------------------------------------------- ; --------------------------------------------------------------------------
; ;
; Move check routine, called for both coordinates. ; Move check routine, called for both coordinates.
; ;
; Entry: y = old value of pot register ; Entry: y = old value of pot register
; a = current value of pot register ; a = current value of pot register
; Exit: y = value to use for old value ; Exit: y = value to use for old value
; x/a = delta value for position ; x/a = delta value for position
; ;
MoveCheck: MoveCheck:
sty OldValue sty OldValue
sta NewValue sta NewValue
ldx #$00 ldx #$00
sec ; a = mod64 (new - old) sec ; a = mod64 (new - old)
sbc OldValue sbc OldValue
@ -298,58 +326,64 @@ MoveCheck:
bcs @L1 ; bcs @L1 ;
lsr a ; a /= 2; lsr a ; a /= 2;
beq @L2 ; if (a != 0) beq @L2 ; if (a != 0)
ldy NewValue ; y = NewValue ldy NewValue ; y = NewValue
rts ; return rts ; return
@L1: ora #%11000000 ; else or in high order bits @L1: ora #%11000000 ; else or in high order bits
cmp #$FF ; if (a != -1) cmp #$FF ; if (a != -1)
beq @L2 beq @L2
sec sec
ror a ; a /= 2 ror a ; a /= 2
ldx #$FF ; high byte = -1 ldx #$FF ; high byte = -1
ldy NewValue ldy NewValue
rts rts
@L2: lda #0 @L2: lda #0
rts rts
; -------------------------------------------------------------------------- ; --------------------------------------------------------------------------
; ;
; 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
ldx MouseSprite ; Sprite defined?
beq @L9 ; Jump if no
ldy BitMask-1,x ; Get high bit mask
txa
asl a ; Index*2
tax
; Set the X position lda Visible ; Mouse visible?
bne MoveSpriteDone ; Jump if no
ldx MouseSprite ; Sprite defined?
beq MoveSpriteDone ; Jump if no
lda XPos+1 ; Negative? ; Set the high X bit
bmi @L2 ; Jump if yes
beq @L1 MoveSprite1:
tya ; Load high position bit lda VIC_SPR_HI_X ; Get high X bits of all sprites
@L1: ora VIC_SPR_HI_X ; Set high bit and NotMask-1,x ; Mask out sprite bit
sta VIC_SPR_HI_X ldy XPos+1 ; Test Y position
lda XPos beq @L1
sta VIC_SPR0_X,x ; Set low byte 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
asl a ; Index*2
tax
lda XPos
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,8 +411,9 @@ 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