]> git.sur5r.net Git - cc65/blob - libsrc/serial/ser-kernel.s
Working on new serial API
[cc65] / libsrc / serial / ser-kernel.s
1 ;
2 ; Ullrich von Bassewitz, 2003-04-15
3 ;
4 ; Common functions of the serial drivers
5 ;
6
7         .export         ser_clear_ptr
8         .import         return0
9         .importzp       ptr1
10
11         .include        "ser-kernel.inc"
12         .include        "ser-error.inc"
13
14
15 ;----------------------------------------------------------------------------
16 ; Variables
17
18
19 .bss
20 _ser_drv:       .res    2               ; Pointer to driver
21
22 ; Jump table for the driver functions.
23 .data
24 ser_vectors:
25 ser_install:    jmp     return0
26 ser_uninstall:  jmp     return0
27 ser_params:     jmp     return0
28 ser_get:        jmp     return0
29 ser_put:        jmp     return0
30 ser_pause:      jmp     return0
31 ser_unpause:    jmp     return0
32 ser_status:     jmp     return0
33
34 ; Driver header signature
35 .rodata
36 ser_sig:        .byte   $73, $65, $72, $00      ; "ser", version
37 ser_sig_len     = * - ser_sig
38
39
40 ;----------------------------------------------------------------------------
41 ; unsigned char __fastcall__ ser_install (void* driver);
42 ; /* Install the driver once it is loaded */
43
44
45 _ser_install:
46         sta     _ser_drv
47         sta     ptr1
48         stx     _ser_drv+1
49         stx     ptr1+1
50
51 ; Check the driver signature
52
53         ldy     #ser_sig_len-1
54 @L0:    lda     (ptr1),y
55         cmp     ser_sig,y
56         bne     inv_drv
57         dey
58         bpl     @L0
59
60 ; Copy the jump vectors
61
62         ldy     #SER_HDR_JUMPTAB
63         ldx     #0
64 @L1:    inx                             ; Skip the JMP opcode
65         jsr     copy                    ; Copy one byte
66         jsr     copy                    ; Copy one byte
67         cpx     #(SER_HDR_JUMPCOUNT*3)
68         bne     @L1
69
70         jmp     ser_install             ; Call driver install routine
71
72 ; Driver signature invalid
73
74 inv_drv:
75         lda     #SER_ERR_INV_DRIVER
76         ldx     #0
77         rts
78
79 ; Copy one byte from the jump vectors
80
81 copy:   lda     (ptr1),y
82         sta     ser_vectors,x
83         iny
84         inx
85         rts
86
87 ;----------------------------------------------------------------------------
88 ; unsigned char __fastcall__ ser_uninstall (void);
89 ; /* Uninstall the currently loaded driver and return an error code.
90 ;  * Note: This call does not free allocated memory.
91 ;  */
92
93 _ser_uninstall:
94         jsr     ser_uninstall           ; Call driver routine
95
96 ser_clear_ptr:                          ; External entry point
97         lda     #0
98         sta     _ser_drv
99         sta     _ser_drv+1              ; Clear the driver pointer
100
101         tax
102         rts                             ; Return zero
103