]> git.sur5r.net Git - cc65/blob - libsrc/serial/ser-kernel.s
Fix calculation of text width for bitmap fonts.
[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         .import         return0
8         .importzp       ptr1
9         .interruptor    ser_irq, 29     ; Export as high priority IRQ handler
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_open:       jmp     return0
28 ser_close:      jmp     return0
29 ser_get:        jmp     return0
30 ser_put:        jmp     return0
31 ser_status:     jmp     return0
32 ser_ioctl:      jmp     return0
33 ser_irq:        .byte   $60, $00, $00   ; RTS plus two dummy bytes
34
35 ; Driver header signature
36 .rodata
37 ser_sig:        .byte   $73, $65, $72, SER_API_VERSION  ; "ser", version
38
39
40 .code
41 ;----------------------------------------------------------------------------
42 ; unsigned char __fastcall__ ser_install (void* driver);
43 ; /* Install the driver once it is loaded */
44
45
46 _ser_install:
47         sta     _ser_drv
48         sta     ptr1
49         stx     _ser_drv+1
50         stx     ptr1+1
51
52 ; Check the driver signature
53
54         ldy     #.sizeof(ser_sig)-1
55 @L0:    lda     (ptr1),y
56         cmp     ser_sig,y
57         bne     inv_drv
58         dey
59         bpl     @L0
60
61 ; Copy the jump vectors
62
63         ldy     #SER_HDR::JUMPTAB
64         ldx     #0
65 @L1:    inx                             ; Skip the JMP opcode
66         jsr     copy                    ; Copy one byte
67         jsr     copy                    ; Copy one byte
68         cpy     #(SER_HDR::JUMPTAB + .sizeof(SER_HDR::JUMPTAB))
69         bne     @L1
70
71         jsr     ser_install             ; Call driver install routine
72
73         ldy     ser_irq+2               ; Check high byte of IRQ vector
74         beq     @L2                     ; Jump if vector invalid
75         ldy     #$4C                    ; Jump opcode
76         sty     ser_irq                 ; Activate IRQ routine
77 @L2:    rts
78
79 ; Driver signature invalid
80
81 inv_drv:
82         lda     #SER_ERR_INV_DRIVER
83         ldx     #0
84         rts
85
86 ; Copy one byte from the jump vectors
87
88 copy:   lda     (ptr1),y
89         sta     ser_vectors,x
90         iny
91         inx
92         rts
93
94 ;----------------------------------------------------------------------------
95 ; unsigned char ser_uninstall (void);
96 ; /* Uninstall the currently loaded driver and return an error code.
97 ;  * Note: This call does not free allocated memory.
98 ;  */
99
100 _ser_uninstall:
101         jsr     ser_uninstall           ; Call driver routine
102
103         lda     #$60                    ; RTS opcode
104         sta     ser_irq                 ; Disable IRQ entry point
105
106 _ser_clear_ptr:                         ; External entry point
107         lda     #0
108         sta     _ser_drv
109         sta     _ser_drv+1              ; Clear the driver pointer
110
111         tax
112         rts                             ; Return zero