1
0
mirror of https://github.com/RevCurtisP/C02.git synced 2024-11-20 03:33:14 +00:00
C02/include/vic/paddle.a02
Curtis F Kaylor 35377b5807 Squashed commit of the following:
commit ed00e1d1b5a9783a72dade3f3676b161a9cfe287
Author: Curtis F Kaylor <revcurtis@gmail.com>
Date:   Sun Sep 9 22:20:49 2018 -0400

    Documented joystk, paddle, and lgtpen modules

commit ec0a5ede8d1b043fcf0094ea653255a808dbf8d3
Author: Curtis F Kaylor <revcurtis@gmail.com>
Date:   Sun Sep 9 20:31:11 2018 -0400

    Added joystick, paddle, and lightpen test programs

commit 7b787f432e2f4f7ae5d7f0053ade1d3586a4fad1
Author: Curtis F Kaylor <revcurtis@gmail.com>
Date:   Sun Sep 9 20:30:03 2018 -0400

    Updated Apple II and VIC-20 Batch Files

commit 50568294349d7e3c6b7d0d364aeaece73c9e4ab6
Author: Curtis F Kaylor <revcurtis@gmail.com>
Date:   Sun Sep 9 20:28:09 2018 -0400

    Separated light pen code into separate files

commit d45e59f73d55eef1d30c591d19a043ad79cfd81a
Author: Curtis F Kaylor <revcurtis@gmail.com>
Date:   Sun Sep 9 19:28:56 2018 -0400

    Moved code for paddles into separate include files

commit fc5c5472d758c960332ea14105d5ec4a7c8cbbfb
Author: Curtis F Kaylor <revcurtis@gmail.com>
Date:   Sun Sep 9 16:15:32 2018 -0400

    Added system specific module 'joystk'
2018-09-12 09:54:54 -04:00

49 lines
1.7 KiB
Plaintext

;Paddle Controller Constants and Functions for VIC-20
PADDLS EQU #2 ;Maximum Numbers of Paddles
;Read Paddle
;Args: A = Paddle #
;Returns: A,Y = Paddle Value
; 0 and Carry Set if Paddle # Invalid
; X = Paddle #
PADDLE: LDY #0 ;Preset Result to 0
CMP #PADDLS ;If Paddle# >= # of Paddles
BCS PADDLZ ; Return Zero & Carry Set
TAX ;Copy Paddle # to X Register
LDY $9008,X ;Read Paddle
PADDLZ: TYA ;Copy Result to Accumulator
RTS
BUTTNS EQU #2 ;Maximum Numbers of Paddle Buttons
;Read Paddle Button
;Args: A = Button #
;Affects: Y
;Returns: A = $FF if Paddle Button Pressed
; $00 if Paddle Button Not Pressed
; Carry Set if Button Number Invalid
; X = Button #
BUTTON: CMP #2 ;If Button# >= # of Buttons
BCS BUTTOZ ; Return FALSE & Carry Set
TAX ;Copy Button Number to X Register
LDY BUTTOR,X ;Get Button Register Offset
LDA $9102,Y ;Read Data Direction Register
PHA ;and Save It
LDA #$00 ;Set Port to All Inputs
STA $9102,Y ;
LDA $9100,Y ;Read Button Port
AND BUTTOM,X ;and Isolate Bit
TAX ;Save Result in X
PLA ;Retrieve Original DDR Value
STA $9102,Y ;Restore Data Direction Register
TXA ;Get Result from X, Setting Flags
BNE BUTTOZ ;If Bit Not Set
LDA #$FF ; Return TRUE
RTS ;Else
BUTTOZ: LDA #$00 ; Return FALSE
RTS
;Paddle Buttons 0 = S2 ($9111 bit 4), 1 = S3 ($9120 bit 7)
BUTTOR: DC $11,$20 ;Paddle Button VIC Registers
BUTTOM: DC $10,$80 ;Paddle Button Bit Masks