2004-03-21 22:12:06 +00:00
|
|
|
;
|
|
|
|
; Driver for the 1351 proportional mouse. Parts of the code are from
|
|
|
|
; the Commodore 1351 mouse users guide.
|
|
|
|
;
|
2010-02-15 17:52:41 +00:00
|
|
|
; 2009-09-26, Ullrich von Bassewitz
|
|
|
|
; 2010-02-06, Greg King
|
2010-02-20 09:52:05 +00:00
|
|
|
;
|
2010-03-07 21:00:42 +00:00
|
|
|
; The driver prevents the keyboard from interfering by changing the
|
|
|
|
; keyboard's output port into an input port while the driver reads its
|
|
|
|
; controller device. That disables a wire that is left active by the
|
|
|
|
; Kernal. That wire is used by the STOP-key to break out of BASIC
|
|
|
|
; programs -- CC65 programs don't use that feature. The wire is shared
|
|
|
|
; by these keys: STOP, "Q", Commodore, Space, "2", CTRL, Left-Arrow, and
|
|
|
|
; "1". I listed them, in order, from bit 7 over to bit 0. The
|
|
|
|
; rightmost five keys can look like joystick switches.
|
|
|
|
;
|
|
|
|
; The driver prevents the mouse/joystick from interfering by "blinding"
|
|
|
|
; the keyboard scanner while any button/switch is active. It changes
|
|
|
|
; the input port into an output port, then stores all zero-bits in that
|
|
|
|
; port's latch. Reading from an output port sees the bitwise-AND of the
|
|
|
|
; latch and the input signals. Therefore, the scanner thinks that eight
|
|
|
|
; keys are being pushed at the same time. It doesn't know what to do
|
|
|
|
; about that condition; so, it does nothing. The driver lets the
|
2010-02-20 09:52:05 +00:00
|
|
|
; scanner see normally, again, when no buttons/switches are active.
|
2004-03-21 22:12:06 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
.include "zeropage.inc"
|
|
|
|
.include "mouse-kernel.inc"
|
2013-05-09 11:56:54 +00:00
|
|
|
.include "c64.inc"
|
2004-03-21 22:12:06 +00:00
|
|
|
|
|
|
|
.macpack generic
|
2014-06-04 21:50:18 +00:00
|
|
|
.macpack module
|
|
|
|
|
2004-03-21 22:12:06 +00:00
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; Header. Includes jump table
|
|
|
|
|
2014-06-04 21:50:18 +00:00
|
|
|
module_header _c64_1351_mou
|
2004-03-21 22:12:06 +00:00
|
|
|
|
|
|
|
HEADER:
|
|
|
|
|
|
|
|
; Driver signature
|
|
|
|
|
|
|
|
.byte $6d, $6f, $75 ; "mou"
|
|
|
|
.byte MOUSE_API_VERSION ; Mouse driver API version number
|
|
|
|
|
2013-05-31 22:53:17 +00:00
|
|
|
; Library reference
|
|
|
|
|
|
|
|
.addr $0000
|
|
|
|
|
|
|
|
; Jump table
|
2004-03-21 22:12:06 +00:00
|
|
|
|
|
|
|
.addr INSTALL
|
|
|
|
.addr UNINSTALL
|
|
|
|
.addr HIDE
|
|
|
|
.addr SHOW
|
2009-09-26 11:35:32 +00:00
|
|
|
.addr SETBOX
|
|
|
|
.addr GETBOX
|
2004-03-21 22:12:06 +00:00
|
|
|
.addr MOVE
|
|
|
|
.addr BUTTONS
|
|
|
|
.addr POS
|
|
|
|
.addr INFO
|
|
|
|
.addr IOCTL
|
|
|
|
.addr IRQ
|
|
|
|
|
2006-05-21 11:25:31 +00:00
|
|
|
; Mouse driver flags
|
|
|
|
|
|
|
|
.byte MOUSE_FLAG_LATE_IRQ
|
|
|
|
|
2004-03-21 22:12:06 +00:00
|
|
|
; Callback table, set by the kernel before INSTALL is called
|
|
|
|
|
|
|
|
CHIDE: jmp $0000 ; Hide the cursor
|
|
|
|
CSHOW: jmp $0000 ; Show the cursor
|
2014-01-17 20:09:15 +00:00
|
|
|
CPREP: jmp $0000 ; Prepare to move the cursor
|
2014-01-15 21:47:59 +00:00
|
|
|
CDRAW: jmp $0000 ; Draw the cursor
|
2004-03-21 22:12:06 +00:00
|
|
|
CMOVEX: jmp $0000 ; Move the cursor to X coord
|
|
|
|
CMOVEY: jmp $0000 ; Move the cursor to Y coord
|
|
|
|
|
|
|
|
|
|
|
|
;----------------------------------------------------------------------------
|
|
|
|
; Constants
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
SCREEN_HEIGHT = YSIZE * 8 - 1 ; (origin is zero)
|
2010-02-15 17:52:41 +00:00
|
|
|
SCREEN_WIDTH = XSIZE * 8 - 1
|
2004-03-21 22:12:06 +00:00
|
|
|
|
|
|
|
;----------------------------------------------------------------------------
|
2004-03-23 21:54:24 +00:00
|
|
|
; Global variables. The bounding box values are sorted so that they can be
|
2009-09-26 11:35:32 +00:00
|
|
|
; written with the least effort in the SETBOX and GETBOX routines, so don't
|
|
|
|
; reorder them.
|
2004-03-21 22:12:06 +00:00
|
|
|
|
|
|
|
.bss
|
|
|
|
|
|
|
|
Vars:
|
2013-05-09 11:56:54 +00:00
|
|
|
OldPotX: .res 1 ; Old hw counter values
|
|
|
|
OldPotY: .res 1
|
2004-03-21 22:12:06 +00:00
|
|
|
|
2004-03-23 21:54:24 +00:00
|
|
|
XPos: .res 2 ; Current mouse position, X
|
2010-02-15 17:52:41 +00:00
|
|
|
YPos: .res 2 ; Current mouse position, Y
|
2013-05-09 11:56:54 +00:00
|
|
|
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 status bits
|
2004-03-21 22:12:06 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
OldValue: .res 1 ; Temp for MoveCheck routine
|
|
|
|
NewValue: .res 1 ; Temp for MoveCheck routine
|
2004-03-21 22:12:06 +00:00
|
|
|
|
|
|
|
.rodata
|
|
|
|
|
2014-01-12 20:52:18 +00:00
|
|
|
; Default values for above variables
|
2010-02-15 17:52:41 +00:00
|
|
|
; (We use ".proc" because we want to define both a label and a scope.)
|
|
|
|
|
2004-03-21 22:12:06 +00:00
|
|
|
.proc DefVars
|
|
|
|
.byte 0, 0 ; OldPotX/OldPotY
|
2004-03-23 21:54:24 +00:00
|
|
|
.word SCREEN_WIDTH/2 ; XPos
|
2010-02-15 17:52:41 +00:00
|
|
|
.word SCREEN_HEIGHT/2 ; YPos
|
2004-03-23 21:54:24 +00:00
|
|
|
.word 0 ; XMin
|
2009-09-26 11:35:32 +00:00
|
|
|
.word 0 ; YMin
|
|
|
|
.word SCREEN_WIDTH ; XMax
|
|
|
|
.word SCREEN_HEIGHT ; YMax
|
2013-05-09 11:56:54 +00:00
|
|
|
.byte %00000000 ; Buttons
|
2004-03-21 22:12:06 +00:00
|
|
|
.endproc
|
|
|
|
|
|
|
|
.code
|
|
|
|
|
|
|
|
;----------------------------------------------------------------------------
|
|
|
|
; INSTALL routine. Is called after the driver is loaded into memory. If
|
|
|
|
; possible, check if the hardware is present.
|
|
|
|
; Must return an MOUSE_ERR_xx code in a/x.
|
|
|
|
|
|
|
|
INSTALL:
|
|
|
|
|
|
|
|
; Initialize variables. Just copy the default stuff over
|
|
|
|
|
|
|
|
ldx #.sizeof(DefVars)-1
|
|
|
|
@L1: lda DefVars,x
|
|
|
|
sta Vars,x
|
|
|
|
dex
|
|
|
|
bpl @L1
|
|
|
|
|
2004-03-23 21:54:24 +00:00
|
|
|
; Be sure the mouse cursor is invisible and at the default location. We
|
|
|
|
; need to do that here, because our mouse interrupt handler doesn't set the
|
|
|
|
; mouse position if it hasn't changed.
|
|
|
|
|
|
|
|
sei
|
|
|
|
jsr CHIDE
|
|
|
|
lda XPos
|
|
|
|
ldx XPos+1
|
|
|
|
jsr CMOVEX
|
|
|
|
lda YPos
|
|
|
|
ldx YPos+1
|
|
|
|
jsr CMOVEY
|
|
|
|
cli
|
|
|
|
|
2004-03-21 22:12:06 +00:00
|
|
|
; Done, return zero (= MOUSE_ERR_OK)
|
|
|
|
|
2004-03-23 21:54:24 +00:00
|
|
|
ldx #$00
|
2004-03-21 22:12:06 +00:00
|
|
|
txa
|
2010-02-15 17:52:41 +00:00
|
|
|
rts
|
2004-03-21 22:12:06 +00:00
|
|
|
|
|
|
|
;----------------------------------------------------------------------------
|
|
|
|
; UNINSTALL routine. Is called before the driver is removed from memory.
|
|
|
|
; No return code required (the driver is removed from memory on return).
|
|
|
|
|
2004-03-23 21:54:24 +00:00
|
|
|
UNINSTALL = HIDE ; Hide cursor on exit
|
2004-03-21 22:12:06 +00:00
|
|
|
|
|
|
|
;----------------------------------------------------------------------------
|
|
|
|
; HIDE routine. Is called to hide the mouse pointer. The mouse kernel manages
|
|
|
|
; a counter for calls to show/hide, and the driver entry point is only called
|
|
|
|
; if the mouse is currently visible and should get hidden. For most drivers,
|
|
|
|
; no special action is required besides hiding the mouse cursor.
|
|
|
|
; No return code required.
|
|
|
|
|
2004-03-23 21:54:24 +00:00
|
|
|
HIDE: sei
|
|
|
|
jsr CHIDE
|
|
|
|
cli
|
|
|
|
rts
|
2004-03-21 22:12:06 +00:00
|
|
|
|
|
|
|
;----------------------------------------------------------------------------
|
|
|
|
; SHOW routine. Is called to show the mouse pointer. The mouse kernel manages
|
|
|
|
; a counter for calls to show/hide, and the driver entry point is only called
|
|
|
|
; if the mouse is currently hidden and should become visible. For most drivers,
|
|
|
|
; no special action is required besides enabling the mouse cursor.
|
|
|
|
; No return code required.
|
|
|
|
|
2004-03-23 21:54:24 +00:00
|
|
|
SHOW: sei
|
|
|
|
jsr CSHOW
|
|
|
|
cli
|
|
|
|
rts
|
2004-03-21 22:12:06 +00:00
|
|
|
|
|
|
|
;----------------------------------------------------------------------------
|
2009-09-26 11:35:32 +00:00
|
|
|
; 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.
|
2004-03-23 21:54:24 +00:00
|
|
|
; 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.
|
|
|
|
|
2009-09-26 11:35:32 +00:00
|
|
|
SETBOX: sta ptr1
|
|
|
|
stx ptr1+1 ; Save data pointer
|
|
|
|
|
|
|
|
ldy #.sizeof (MOUSE_BOX)-1
|
|
|
|
sei
|
|
|
|
|
|
|
|
@L1: lda (ptr1),y
|
|
|
|
sta XMin,y
|
|
|
|
dey
|
|
|
|
bpl @L1
|
|
|
|
|
|
|
|
cli
|
2013-05-09 11:56:54 +00:00
|
|
|
rts
|
2009-09-26 11:35:32 +00:00
|
|
|
|
|
|
|
;----------------------------------------------------------------------------
|
|
|
|
; 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
|
|
|
|
@L1: lda XMin,y
|
|
|
|
sta (ptr1),y
|
2004-03-23 21:54:24 +00:00
|
|
|
dey
|
|
|
|
bpl @L1
|
2013-05-09 11:56:54 +00:00
|
|
|
rts
|
2004-03-21 22:12:06 +00:00
|
|
|
|
|
|
|
;----------------------------------------------------------------------------
|
2004-03-29 16:44:39 +00:00
|
|
|
; MOVE: Move the mouse to a new position. The position is passed as it comes
|
|
|
|
; from the C program, that is: X on the stack and Y in a/x. The C wrapper will
|
|
|
|
; remove the parameter from the stack on return.
|
2005-04-25 20:10:10 +00:00
|
|
|
; No checks are done if the new position is valid (within the bounding box or
|
2004-03-21 22:12:06 +00:00
|
|
|
; the screen). No return code required.
|
|
|
|
;
|
|
|
|
|
|
|
|
MOVE: sei ; No interrupts
|
|
|
|
|
|
|
|
sta YPos
|
|
|
|
stx YPos+1 ; New Y position
|
|
|
|
jsr CMOVEY ; Set it
|
|
|
|
|
2004-03-29 16:44:39 +00:00
|
|
|
ldy #$01
|
|
|
|
lda (sp),y
|
|
|
|
sta XPos+1
|
|
|
|
tax
|
|
|
|
dey
|
|
|
|
lda (sp),y
|
|
|
|
sta XPos ; New X position
|
2004-03-21 22:12:06 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
jsr CMOVEX ; Move the cursor
|
2004-03-21 22:12:06 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
cli ; Allow interrupts
|
|
|
|
rts
|
2004-03-21 22:12:06 +00:00
|
|
|
|
|
|
|
;----------------------------------------------------------------------------
|
|
|
|
; BUTTONS: Return the button mask in a/x.
|
|
|
|
|
|
|
|
BUTTONS:
|
2013-05-09 11:56:54 +00:00
|
|
|
lda Buttons
|
2004-03-21 22:12:06 +00:00
|
|
|
ldx #0
|
2013-05-09 11:56:54 +00:00
|
|
|
and #$1F
|
2004-03-21 22:12:06 +00:00
|
|
|
rts
|
|
|
|
|
|
|
|
;----------------------------------------------------------------------------
|
|
|
|
; POS: Return the mouse position in the MOUSE_POS struct pointed to by ptr1.
|
|
|
|
; No return code required.
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
POS: ldy #MOUSE_POS::XCOORD ; Structure offset
|
2004-03-21 22:12:06 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
sei ; Disable interrupts
|
|
|
|
lda XPos ; Transfer the position
|
|
|
|
sta (ptr1),y
|
|
|
|
lda XPos+1
|
|
|
|
iny
|
|
|
|
sta (ptr1),y
|
|
|
|
lda YPos
|
2004-03-21 22:12:06 +00:00
|
|
|
iny
|
|
|
|
sta (ptr1),y
|
2013-05-09 11:56:54 +00:00
|
|
|
lda YPos+1
|
|
|
|
cli ; Enable interrupts
|
2004-03-21 22:12:06 +00:00
|
|
|
|
|
|
|
iny
|
|
|
|
sta (ptr1),y ; Store last byte
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
rts ; Done
|
2004-03-21 22:12:06 +00:00
|
|
|
|
|
|
|
;----------------------------------------------------------------------------
|
|
|
|
; INFO: Returns mouse position and current button mask in the MOUSE_INFO
|
|
|
|
; struct pointed to by ptr1. No return code required.
|
|
|
|
;
|
|
|
|
; We're cheating here to keep the code smaller: The first fields of the
|
|
|
|
; mouse_info struct are identical to the mouse_pos struct, so we will just
|
|
|
|
; call _mouse_pos to initialize the struct pointer and fill the position
|
|
|
|
; fields.
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
INFO: jsr POS
|
2004-03-21 22:12:06 +00:00
|
|
|
|
|
|
|
; Fill in the button state
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
jsr BUTTONS ; Will not touch ptr1
|
|
|
|
ldy #MOUSE_INFO::BUTTONS
|
|
|
|
sta (ptr1),y
|
2004-03-21 22:12:06 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
rts
|
2004-03-21 22:12:06 +00:00
|
|
|
|
|
|
|
;----------------------------------------------------------------------------
|
|
|
|
; IOCTL: Driver defined entry point. The wrapper will pass a pointer to ioctl
|
|
|
|
; specific data in ptr1, and the ioctl code in A.
|
|
|
|
; Must return an error code in a/x.
|
|
|
|
;
|
|
|
|
|
|
|
|
IOCTL: lda #<MOUSE_ERR_INV_IOCTL ; We don't support ioclts for now
|
|
|
|
ldx #>MOUSE_ERR_INV_IOCTL
|
|
|
|
rts
|
|
|
|
|
|
|
|
;----------------------------------------------------------------------------
|
|
|
|
; IRQ: Irq handler entry point. Called as a subroutine but in IRQ context
|
2005-04-25 20:10:10 +00:00
|
|
|
; (so be careful). The routine MUST return carry set if the interrupt has been
|
|
|
|
; 'handled' - which means that the interrupt source is gone. Otherwise it
|
|
|
|
; MUST return carry clear.
|
2004-03-21 22:12:06 +00:00
|
|
|
;
|
|
|
|
|
2014-01-17 20:09:15 +00:00
|
|
|
IRQ: jsr CPREP
|
2010-02-15 17:52:41 +00:00
|
|
|
|
|
|
|
; Record the state of the buttons.
|
|
|
|
; Avoid crosstalk between the keyboard and the mouse.
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
ldy #%00000000 ; Set ports A and B to input
|
|
|
|
sty CIA1_DDRB
|
|
|
|
sty CIA1_DDRA ; Keyboard won't look like mouse
|
|
|
|
lda CIA1_PRB ; Read Control-Port 1
|
|
|
|
dec CIA1_DDRA ; Set port A back to output
|
|
|
|
eor #%11111111 ; Bit goes up when button goes down
|
|
|
|
sta Buttons
|
|
|
|
beq @L0 ;(bze)
|
|
|
|
dec CIA1_DDRB ; Mouse won't look like keyboard
|
|
|
|
sty CIA1_PRB ; Set "all keys pushed"
|
|
|
|
|
|
|
|
@L0: lda SID_ADConv1 ; Get mouse X movement
|
|
|
|
ldy OldPotX
|
|
|
|
jsr MoveCheck ; Calculate movement vector
|
2004-03-21 22:12:06 +00:00
|
|
|
|
|
|
|
; Skip processing if nothing has changed
|
|
|
|
|
2004-03-23 21:54:24 +00:00
|
|
|
bcc @SkipX
|
2013-05-09 11:56:54 +00:00
|
|
|
sty OldPotX
|
2004-03-21 22:12:06 +00:00
|
|
|
|
|
|
|
; Calculate the new X coordinate (--> a/y)
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
add XPos
|
|
|
|
tay ; Remember low byte
|
|
|
|
txa
|
|
|
|
adc XPos+1
|
|
|
|
tax
|
2004-03-21 22:12:06 +00:00
|
|
|
|
|
|
|
; Limit the X coordinate to the bounding box
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
cpy XMin
|
|
|
|
sbc XMin+1
|
|
|
|
bpl @L1
|
|
|
|
ldy XMin
|
|
|
|
ldx XMin+1
|
|
|
|
jmp @L2
|
|
|
|
@L1: txa
|
|
|
|
|
|
|
|
cpy XMax
|
|
|
|
sbc XMax+1
|
|
|
|
bmi @L2
|
|
|
|
ldy XMax
|
|
|
|
ldx XMax+1
|
|
|
|
@L2: sty XPos
|
|
|
|
stx XPos+1
|
2004-03-21 22:12:06 +00:00
|
|
|
|
|
|
|
; Move the mouse pointer to the new X pos
|
|
|
|
|
|
|
|
tya
|
2004-03-23 21:54:24 +00:00
|
|
|
jsr CMOVEX
|
2004-03-21 22:12:06 +00:00
|
|
|
|
|
|
|
; Calculate the Y movement vector
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
@SkipX: lda SID_ADConv2 ; Get mouse Y movement
|
|
|
|
ldy OldPotY
|
|
|
|
jsr MoveCheck ; Calculate movement
|
2004-03-21 22:12:06 +00:00
|
|
|
|
|
|
|
; Skip processing if nothing has changed
|
|
|
|
|
2004-03-23 21:54:24 +00:00
|
|
|
bcc @SkipY
|
2013-05-09 11:56:54 +00:00
|
|
|
sty OldPotY
|
2004-03-21 22:12:06 +00:00
|
|
|
|
|
|
|
; Calculate the new Y coordinate (--> a/y)
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
sta OldValue
|
|
|
|
lda YPos
|
|
|
|
sub OldValue
|
|
|
|
tay
|
|
|
|
stx OldValue
|
|
|
|
lda YPos+1
|
|
|
|
sbc OldValue
|
|
|
|
tax
|
2004-03-21 22:12:06 +00:00
|
|
|
|
|
|
|
; Limit the Y coordinate to the bounding box
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
cpy YMin
|
|
|
|
sbc YMin+1
|
|
|
|
bpl @L3
|
|
|
|
ldy YMin
|
|
|
|
ldx YMin+1
|
|
|
|
jmp @L4
|
|
|
|
@L3: txa
|
|
|
|
|
|
|
|
cpy YMax
|
|
|
|
sbc YMax+1
|
|
|
|
bmi @L4
|
|
|
|
ldy YMax
|
|
|
|
ldx YMax+1
|
|
|
|
@L4: sty YPos
|
|
|
|
stx YPos+1
|
2004-03-21 22:12:06 +00:00
|
|
|
|
2010-02-15 17:52:41 +00:00
|
|
|
; Move the mouse pointer to the new Y pos
|
2004-03-21 22:12:06 +00:00
|
|
|
|
|
|
|
tya
|
2006-05-21 11:25:31 +00:00
|
|
|
jsr CMOVEY
|
2004-03-21 22:12:06 +00:00
|
|
|
|
|
|
|
; Done
|
|
|
|
|
2014-01-15 21:47:59 +00:00
|
|
|
@SkipY: jsr CDRAW
|
2010-02-15 17:52:41 +00:00
|
|
|
clc ; Interrupt not "handled"
|
2014-01-15 21:47:59 +00:00
|
|
|
rts
|
2004-03-21 22:12:06 +00:00
|
|
|
|
|
|
|
; --------------------------------------------------------------------------
|
|
|
|
;
|
|
|
|
; Move check routine, called for both coordinates.
|
|
|
|
;
|
2013-05-09 11:56:54 +00:00
|
|
|
; Entry: y = old value of pot register
|
|
|
|
; a = current value of pot register
|
|
|
|
; Exit: y = value to use for old value
|
|
|
|
; x/a = delta value for position
|
2004-03-21 22:12:06 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
MoveCheck:
|
2013-05-09 11:56:54 +00:00
|
|
|
sty OldValue
|
|
|
|
sta NewValue
|
|
|
|
ldx #$00
|
|
|
|
|
|
|
|
sub OldValue ; a = mod64 (new - old)
|
|
|
|
and #%01111111
|
|
|
|
cmp #%01000000 ; if (a > 0)
|
|
|
|
bcs @L1 ;
|
|
|
|
lsr a ; a /= 2;
|
|
|
|
beq @L2 ; if (a != 0)
|
|
|
|
ldy NewValue ; y = NewValue
|
|
|
|
sec
|
|
|
|
rts ; return
|
|
|
|
|
|
|
|
@L1: ora #%11000000 ; else, "or" in high-order bits
|
|
|
|
cmp #$FF ; if (a != -1)
|
|
|
|
beq @L2
|
2004-03-23 21:54:24 +00:00
|
|
|
sec
|
2013-05-09 11:56:54 +00:00
|
|
|
ror a ; a /= 2
|
|
|
|
dex ; high byte = -1 (X = $FF)
|
|
|
|
ldy NewValue
|
2004-03-23 21:54:24 +00:00
|
|
|
sec
|
2013-05-09 11:56:54 +00:00
|
|
|
rts
|
2004-03-21 22:12:06 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
@L2: txa ; A = $00
|
2004-03-23 21:54:24 +00:00
|
|
|
clc
|
2013-05-09 11:56:54 +00:00
|
|
|
rts
|
2004-03-21 22:12:06 +00:00
|
|
|
|