]> git.sur5r.net Git - cc65/blob - libsrc/vic20/readjoy.s
Fixed a bug
[cc65] / libsrc / vic20 / readjoy.s
1 ;
2 ; Ullrich von Bassewitz, 23.09.1998
3 ; Adapted for Vic20 by Steve Schmidtke 05.08.2002
4 ;
5 ; unsigned readjoy (unsigned char joy);
6 ;
7
8         .export         _readjoy
9
10         .include        "vic20.inc"
11
12
13 ; The current implemenation will ignore the joystick number because we do only
14 ; have one joystick
15
16
17 .proc   _readjoy
18
19         lda     #$7F            ; mask for VIA2 JOYBIT: sw3
20         ldx     #$C3            ; mask for VIA1 JOYBITS: sw0,sw1,sw2,sw4
21         sei                     ; necessary?
22
23         ldy     VIA2_DDRB       ; remember the date of DDRB
24         sta     VIA2_DDRB       ; set JOYBITS on this VIA for input
25         lda     VIA2_JOY        ; read JOYBIT: sw3
26         sty     VIA2_DDRB       ; restore the state of DDRB
27         asl                     ; Shift sw3 into carry
28
29         ldy     VIA1_DDRA       ; remember the state of DDRA
30         stx     VIA1_DDRA       ; set JOYBITS on this VIA for input
31         lda     VIA1_JOY        ; read JOYBITS: sw0,sw1,sw2,sw4
32         sty     VIA1_DDRA       ; restore the state of DDRA
33
34         cli                     ; necessary?
35         ror                     ; Shift sw3 into bit 7
36         and     #$9E            ; Mask relevant bits
37         eor     #$9E            ; Active states are inverted
38
39         rts
40
41 .endproc
42