mirror of
https://github.com/RevCurtisP/C02.git
synced 2025-02-19 19:31:04 +00:00
Added modules joystk and paddle for c64
This commit is contained in:
parent
967d2c01e3
commit
271d0bd009
22
include/c64/joystk.a02
Normal file
22
include/c64/joystk.a02
Normal file
@ -0,0 +1,22 @@
|
||||
;Joystick Assembly Language Module for C64
|
||||
|
||||
JYSTKS EQU $02 ;Number of Joysticks
|
||||
|
||||
;Joystick Bit Masks
|
||||
JOYUP EQU $01 ;Bit 0 - Up
|
||||
JOYDN EQU $02 ;Bit 1 - Down
|
||||
JOYLF EQU $04 ;Bit 2 - Left
|
||||
JOYRT EQU $08 ;Bit 3 - Right
|
||||
JOYB0 EQU $10 ;Bit 4 - Button
|
||||
|
||||
;Read Joystick
|
||||
JOYSTK: CMP #JYSTKS ;If Invalid Joystick#
|
||||
BCS JOYSTZ ; Return Error
|
||||
EOR #$01 ;Invert Joystick Number
|
||||
TAX ;and Copy to X Register
|
||||
LDA $DC00,X ;Read Joystick
|
||||
EOR #$FF ;Invert and
|
||||
AND #$1F ;Mask Bits
|
||||
RTS
|
||||
JOYSTZ: LDA #$FF ;Return Error
|
||||
RTS
|
15
include/c64/joystk.h02
Normal file
15
include/c64/joystk.h02
Normal file
@ -0,0 +1,15 @@
|
||||
/* Joystick Module Header File for C64 */
|
||||
|
||||
#define JYSTKS 2 //Number of Joysticks
|
||||
|
||||
#define JOYUP $01 //Bit 0 - Up
|
||||
#define JOYDN $02 //Bit 1 - Down
|
||||
#define JOYLF $04 //Bit 2 - Left
|
||||
#define JOYRT $08 //Bit 3 - Right
|
||||
#define JOYB0 $10 //Bit 4 - Button
|
||||
|
||||
/* Read Joystick State *
|
||||
* Args: n = Joystick Number *
|
||||
* Returns: Joystick Status *
|
||||
* $FF = Invalid Argument */
|
||||
char joystk();
|
57
include/c64/paddle.a02
Normal file
57
include/c64/paddle.a02
Normal file
@ -0,0 +1,57 @@
|
||||
;Paddle Controller Constants and Functions for C64
|
||||
|
||||
PADDLS EQU #$04 ;Maximum Numbers of Paddles
|
||||
|
||||
;Read Paddle
|
||||
;Args: A = Paddle #
|
||||
;Affects: X,Y
|
||||
;Returns: A = Paddle Value
|
||||
; 0 and Carry Set if Paddle # Invalid
|
||||
PADDLE: CMP #PADDLS ;If Invalid Paddle #
|
||||
BCS BUTTOZ ; Return 0 & Carry Set
|
||||
EOR #$03 ;Invert Paddle #
|
||||
TAY ;Copy Paddle # to Y
|
||||
AND #$01 ;Get Paddle Index
|
||||
TAX ;and Copy to X
|
||||
SEI ;Turn off Interrupts
|
||||
LDA $DC02 ;Save Data Direction Register A
|
||||
PHA
|
||||
LDA #$C0
|
||||
STA $DC02 ;Set Port A for Output
|
||||
LDA PADDLT,Y ;Get Bit Mask and
|
||||
STA $DC00 ;Address Pair of Paddles
|
||||
LDY #$FF ;Wait for SID to Read Paddles
|
||||
PADDLL: NOP
|
||||
DEY
|
||||
BMI PADDLL ;Y contains $7F when Done
|
||||
PLA ;Restore Data Direction Register A
|
||||
STA $DC02
|
||||
LDA $D419,X ;Read Paddle
|
||||
STY $DC00 ;Reset Port A for Button Read
|
||||
CLI ;Turn on Interrupts
|
||||
RTS
|
||||
PADDLT: DC $80,$80,$40,$40 ;Port A Bit Mask Table
|
||||
|
||||
BUTTNS EQU #$04 ;Maximum Numbers of Paddle Buttons
|
||||
|
||||
;Read Paddle Button
|
||||
;Args: A = Button #
|
||||
;Affects: X,Y
|
||||
;Returns: A = $FF if Paddle Button Pressed
|
||||
; $00 if Paddle Button Not Pressed
|
||||
; Carry Set if Button Number Invalid
|
||||
BUTTON: CMP #BUTTNS ;If Button# >= # of Buttons
|
||||
BCS BUTTOZ ; Return FALSE & Carry Set
|
||||
EOR #$03 ;Invert Button #
|
||||
TAX ;and Copy to X Register
|
||||
ROR ;Divide Button # by 2
|
||||
TAY ;and Transfer to Y Register
|
||||
LDA $DC00,Y ;Read Joystick Port
|
||||
AND BUTTOM,X ;Mask off Relevant Bit
|
||||
BNE BUTTOZ ;If Bit is 0
|
||||
LDA #$FF ; Return TRUE
|
||||
RTS ;Else
|
||||
BUTTOZ: LDA #$00 ; Return FALSE
|
||||
RTS
|
||||
;Paddle Buttons 0 = S2 (bit 2), 1 = S3 (bit 3)
|
||||
BUTTOM: DC $08,$04,$08,$04 ;Paddle Button Bit Masks
|
20
include/c64/paddle.h02
Normal file
20
include/c64/paddle.h02
Normal file
@ -0,0 +1,20 @@
|
||||
/* Psddle Controllers Header File for C64 */
|
||||
|
||||
#define BUTTNS 4 //Number of Paddle Buttons
|
||||
#define PADDLS 4 //Number of Paddles
|
||||
|
||||
/* Get Paddle Button Status *
|
||||
* Args: b = Button Number *
|
||||
* Same as Paddle Number *
|
||||
* Returns: $FF if Button Pressed *
|
||||
* $00 if Not Pressed */
|
||||
void button();
|
||||
|
||||
/* Get Paddle Status *
|
||||
* Args: p = Paddle Number *
|
||||
* 0 - Port 1 Paddle X *
|
||||
* 1 - Port 1 Paddle Y *
|
||||
* 2 - Port 2 Paddle X *
|
||||
* 3 - Port 2 Paddle Y *
|
||||
* Returns: Paddle Value (0-255) */
|
||||
void paddle();
|
@ -22,6 +22,10 @@ main:
|
||||
setpos(1,r);
|
||||
putchr('J'); prhex(i); putchr(':');
|
||||
}
|
||||
for (i=0; i<4; i++) {
|
||||
setpos(25,i);
|
||||
prbyte($D0); prbyte(i);
|
||||
}
|
||||
while() {
|
||||
for(i=0; i<#JYSTKS; i++) {
|
||||
j = joystk(i);
|
||||
|
@ -17,13 +17,12 @@ main:
|
||||
setpos(1,i);
|
||||
putchr('P'); prhex(i); putchr(':');
|
||||
}
|
||||
|
||||
for (i=0;i<#BUTTNS;i++) {
|
||||
setpos(7,i);
|
||||
putchr('B'); prhex(i); putchr(':');
|
||||
}
|
||||
|
||||
loop:
|
||||
loop:
|
||||
if (getkey() == #ESCKEY) goto exit;
|
||||
for (i=0;i<#PADDLS;i++) {
|
||||
p = paddle(i);
|
||||
|
@ -1,9 +1,8 @@
|
||||
[C64]
|
||||
Window0Xpos=572
|
||||
Window0Ypos=19
|
||||
FullscreenWidth=640
|
||||
FullscreenHeight=480
|
||||
SaveResourcesOnExit=1
|
||||
Window0Width=735
|
||||
Window0Height=645
|
||||
ConfirmOnExit=0
|
||||
SoundDeviceName="dx"
|
||||
SoundBufferSize=100
|
||||
|
Loading…
x
Reference in New Issue
Block a user