A paddle is connected to both CIA #1 and the SID chip (MOS 6581 Sound
Interface Device) through a game port. The paddle value is read via the
SID registers 54297
($D419
) and
54298
($D41A
). PADDLES ARE NOT RELIABLE WHEN
READ FROM BASIC ALONE!!!! The best way to use paddles, from BASIC or
machine code, is to use the following machine language routine...
(SYS
to it from BASIC then PEEK
the memory
locations used by the subroutine).
1000 ;************************************************** 1010 ;* FOUR PADDLE READ ROUTINE (CAN ALSO BE USED FOR TWO) 1020 ;************************************************** 1030 ;AUTHOR - BILL HINDORFF 1040 PORTA=$DC00 1050 CIDDRA=$DC02 1060 SID=$D400 1070 *=$C100 1080 BUFFER *=*+1 1090 PDLX *=*+2 1100 PDLY *=*+2 1110 BTNA *=*+1 1120 BTNB *=*+1 1130 * = $C000 1140 PDLRD 1150 LDX #1 ; FOR FOUR PADDLES OR TWO ANALOG JOYSTICKS 1160 PDLRD0 ; ENTRY POINT FOR ONE PAIR (CONDITION X 1ST) 1170 SEI 1180 LDA CIDDRA ; GET CURRENT VALUE OF DDR 1190 STA BUFFER ; SAVE IT AWAY 1200 LDA #$C0 1210 STA CIDDRA ; SET PORT A FOR INPUT 1220 LDA #$80 1230 PDLRD1 1240 STA PORTA ; ADDRESS A PAIR OF PADDLES 1250 LDY #$80 ; WAIT A WHILE 1260 PDLRD2 1270 NOP 1280 DEY 1290 BPL PDLRD2 1300 LDA SID+25 ; GET X VALUE 1310 STA PDLX,X 1320 LDA SID+26 1330 STA PDLY,X ; GET Y VALUE 1340 LDA PORTA ; TIME TO READ PADDLE FIRE BUTTONS 1350 ORA #80 ; MAKE IT THE SAME AS OTHER PAIR 1360 STA BTNA ; BIT 2 IS PDL X, BIT 3 IS PDL Y 1370 LDA #$40 1380 DEX ; ALL PAIRS DONE? 1390 BPL PDLRD1 ; NO 1400 LDA BUFFER 1410 STA CIDDRA ; RESTORE PREVIOUS VALUE OF DDR 1420 LDA PORTA+1 ; FOR 2ND PAIR - 1430 STA BTNB ; BIT 2 IS PDL X, BIT 3 IS PDL Y 1440 CLI 1450 RTS 1460 .END
This page has been created by Sami Rautiainen. | |
Read the small print. | Last updated May 20, 1998. |