File: joy-kernel.s

package info (click to toggle)
cc65 2.19-2
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 20,268 kB
  • sloc: ansic: 117,151; asm: 66,339; pascal: 4,248; makefile: 1,009; perl: 607
file content (106 lines) | stat: -rw-r--r-- 2,520 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
;
; Ullrich von Bassewitz, 2002-12-20
;
; Common functions of the joystick API.
;

        .import         joy_libref
        .importzp       ptr1

        .include        "joy-kernel.inc"
        .include        "joy-error.inc"


;----------------------------------------------------------------------------
; Variables


.bss
_joy_drv:       .res    2               ; Pointer to driver

; Jump table for the driver functions.
.data
joy_vectors:
joy_install:    jmp     $0000
joy_uninstall:  jmp     $0000
joy_count:      jmp     $0000
joy_read:       jmp     $0000

; Driver header signature
.rodata
joy_sig:        .byte   $6A, $6F, $79, JOY_API_VERSION  ; "joy", version


.code
;----------------------------------------------------------------------------
; unsigned char __fastcall__ joy_install (void* driver);
; /* Install the driver once it is loaded */


_joy_install:
        sta     _joy_drv
        sta     ptr1
        stx     _joy_drv+1
        stx     ptr1+1

; Check the driver signature

        ldy     #.sizeof(joy_sig)-1
@L0:    lda     (ptr1),y
        cmp     joy_sig,y
        bne     inv_drv
        dey
        bpl     @L0

; Set the library reference

        ldy     #JOY_HDR::LIBREF
        lda     #<joy_libref
        sta     (ptr1),y
        iny
        lda     #>joy_libref
        sta     (ptr1),y

; Copy the jump vectors

        ldy     #JOY_HDR::JUMPTAB
        ldx     #0
@L1:    inx                             ; Skip the JMP opcode
        jsr     copy                    ; Copy one byte
        jsr     copy                    ; Copy one byte
        cpy     #(JOY_HDR::JUMPTAB + .sizeof(JOY_HDR::JUMPTAB))
        bne     @L1

        jmp     joy_install             ; Call driver install routine

; Driver signature invalid

inv_drv:
        lda     #JOY_ERR_INV_DRIVER
        ldx     #0
        rts

; Copy one byte from the jump vectors

copy:   lda     (ptr1),y
        iny
        sta     joy_vectors,x
        inx
        rts

;----------------------------------------------------------------------------
; unsigned char joy_uninstall (void);
; /* Uninstall the currently loaded driver. Note: This call does not free
; ** allocated memory.
; */

_joy_uninstall:
        jsr     joy_uninstall           ; Call the driver routine

_joy_clear_ptr:                         ; External entry point
        lda     #0
        sta     _joy_drv
        sta     _joy_drv+1              ; Clear the driver pointer

        tax                             ; Return zero
        rts