]> git.sur5r.net Git - cc65/blobdiff - libsrc/c64/c64-potmouse.s
Changed the existing Commodore mouse drivers for the new API. UNTESTED!
[cc65] / libsrc / c64 / c64-potmouse.s
index cd2bc9543fbf622eaf92edc06ee67d7d215fc830..b49552ae865160d45cb054aaaa15694ddf9bd3c7 100644 (file)
@@ -1,7 +1,7 @@
 ;
 ; Driver for a potentiometer "mouse" e.g. Koala Pad
 ;
-; Ullrich von Bassewitz, 2004-03-29
+; Ullrich von Bassewitz, 2004-03-29, 2009-09-26
 ; Stefan Haubenthal, 2006-08-20
 ;
 
@@ -29,7 +29,8 @@ HEADER:
        .addr   UNINSTALL
        .addr   HIDE
        .addr   SHOW
-       .addr   BOX
+       .addr   SETBOX
+        .addr   GETBOX
        .addr   MOVE
        .addr   BUTTONS
        .addr   POS
@@ -61,22 +62,23 @@ SCREEN_WIDTH        = 320
 
 ;----------------------------------------------------------------------------
 ; Global variables. The bounding box values are sorted so that they can be
-; written with the least effort in the BOX routine, so don't reorder them.
+; written with the least effort in the SETBOX and GETBOX routines, so don't
+; reorder them.
 
 .bss
 
 Vars:
-YPos:          .res    2               ; Current mouse position, Y
-XPos:          .res    2               ; Current mouse position, X
-YMax:          .res    2               ; Y2 value of bounding box
-XMax:          .res    2               ; X2 value of bounding box
-YMin:          .res    2               ; Y1 value of bounding box
-XMin:          .res    2               ; X1 value of bounding box
-Buttons:       .res    1               ; Button mask
+YPos:          .res    2               ; Current mouse position, Y
+XPos:          .res    2               ; Current mouse position, X
+XMin:          .res    2               ; X1 value of bounding box
+YMin:          .res    2               ; Y1 value of bounding box
+XMax:          .res    2               ; X2 value of bounding box
+YMax:          .res    2               ; Y2 value of bounding box
+Buttons:       .res    1               ; Button mask
 
 ; Temporary value used in the int handler
 
-Temp:          .res    1
+Temp:          .res    1
 
 ; Default values for above variables
 
@@ -85,10 +87,10 @@ Temp:               .res    1
 .proc  DefVars
        .word   SCREEN_HEIGHT/2         ; YPos
        .word   SCREEN_WIDTH/2          ; XPos
-       .word   SCREEN_HEIGHT           ; YMax
-       .word   SCREEN_WIDTH            ; XMax
-       .word   0                       ; YMin
        .word   0                       ; XMin
+       .word   0                       ; YMin
+       .word   SCREEN_WIDTH            ; XMax
+       .word   SCREEN_HEIGHT           ; YMax
        .byte   0                       ; Buttons
 .endproc
 
@@ -160,26 +162,43 @@ SHOW:     sei
        rts
 
 ;----------------------------------------------------------------------------
-; BOX: Set the mouse bounding box. The parameters are passed as they come from
-; the C program, that is, maxy in a/x and the other parameters on the stack.
-; The C wrapper will remove the parameters from the stack when the driver
-; routine returns.
+; SETBOX: Set the mouse bounding box. The parameters are passed as they come
+; from the C program, that is, a pointer to a mouse_box struct in a/x.
 ; No checks are done if the mouse is currently inside the box, this is the job
 ; of the caller. It is not necessary to validate the parameters, trust the
 ; caller and save some code here. No return code required.
 
-BOX:   ldy     #5
-       sei
-       sta     YMax
-       stx     YMax+1
+SETBOX: sta     ptr1
+        stx     ptr1+1                  ; Save data pointer
 
-@L1:   lda     (sp),y
-       sta     XMax,y
-       dey
-       bpl     @L1
+        ldy     #.sizeof (MOUSE_BOX)-1
+        sei
 
-       cli
-       rts
+@L1:    lda     (ptr1),y
+        sta     XMin,y
+        dey
+        bpl     @L1
+
+        cli
+               rts
+
+;----------------------------------------------------------------------------
+; GETBOX: Return the mouse bounding box. The parameters are passed as they
+; come from the C program, that is, a pointer to a mouse_box struct in a/x.
+
+GETBOX: sta     ptr1
+        stx     ptr1+1                  ; Save data pointer
+
+        ldy     #.sizeof (MOUSE_BOX)-1
+        sei
+
+@L1:    lda     XMin,y
+        sta     (ptr1),y
+        dey
+        bpl     @L1
+
+        cli
+               rts
 
 ;----------------------------------------------------------------------------
 ; MOVE: Move the mouse to a new position. The position is passed as it comes