]> git.sur5r.net Git - cc65/blob - libsrc/cbm510/readjoy.s
Added o65 symbol export capability
[cc65] / libsrc / cbm510 / readjoy.s
1 ;
2 ; Ullrich von Bassewitz, 23.09.1998
3 ;
4 ; unsigned readjoy (unsigned char joy);
5 ;
6
7         .export         _readjoy
8         .import         sys_bank, restore_bank
9         .importzp       cia2, tmp1
10
11         .include        "io.inc"
12
13 ; ------------------------------------------------------------------------
14 ; unsigned __fastcall__ readjoy (unsigned char joy);
15
16
17 .proc   _readjoy
18
19         jsr     sys_bank        ; Switch to the system bank
20         tax                     ; Save joystick number
21
22 ; Get the direction bits
23
24         ldy     #CIA_PRB
25         lda     (cia2),y        ; Read joystick inputs
26         sta     tmp1
27
28 ; Get the fire bits
29
30         ldy     #CIA_PRA
31         lda     (cia2),y
32
33 ; Make the result value
34
35         cpx     #$00            ; Joystick 0?
36         bne     @L1             ; Jump if no
37
38 ; Joystick 1, fire is in bit 6, direction in bit 0-3
39
40         asl     a
41         jmp     @L2
42
43 ; Joystick 2, fire is in bit 7, direction in bit 5-7
44
45 @L1:    ldy     #$00            ; High byte of return value
46         lsr     tmp1
47         lsr     tmp1
48         lsr     tmp1
49         lsr     tmp1
50
51 ; Mask the relavant bits, get the fire bit
52
53 @L2:    asl     a               ; Fire bit into carry
54         lda     tmp1
55         and     #$0F
56         bcc     @L3
57         ora     #$10
58 @L3:    eor     #$1F            ; All bits are inverted
59         jmp     restore_bank
60
61 .endproc
62