]> git.sur5r.net Git - cc65/blob - libsrc/em/em-kernel.s
Fixed capslock on startup
[cc65] / libsrc / em / em-kernel.s
1 ;
2 ; Ullrich von Bassewitz, 2002-11-29
3 ;
4 ; Common functions of the extended memory API.
5 ;
6
7         .export         em_clear_ptr
8         .import         return0
9         .importzp       ptr1
10
11         .include        "em-kernel.inc"
12         .include        "em-error.inc"
13
14
15 ;----------------------------------------------------------------------------
16 ; Variables
17
18
19 .bss
20 _em_drv:        .res    2               ; Pointer to driver
21
22 ; Jump table for the driver functions.
23 .data
24 emd_vectors:
25 emd_install:    jmp     return0
26 emd_uninstall:  jmp     return0
27 emd_pagecount:  jmp     return0
28 emd_map:        jmp     return0
29 emd_use:        jmp     return0
30 emd_commit:     jmp     return0
31 emd_copyfrom:   jmp     return0
32 emd_copyto:     jmp     return0
33
34 ; Driver header signature
35 .rodata
36 emd_sig:        .byte   $65, $6d, $64, $00      ; "emd", version
37 emd_sig_len     = * - emd_sig
38
39
40 ;----------------------------------------------------------------------------
41 ; unsigned char __fastcall__ em_install (void* driver);
42 ; /* Install the driver once it is loaded */
43
44
45 _em_install:
46         sta     _em_drv
47         sta     ptr1
48         stx     _em_drv+1
49         stx     ptr1+1
50
51 ; Check the driver signature
52
53         ldy     #emd_sig_len-1
54 @L0:    lda     (ptr1),y
55         cmp     emd_sig,y
56         bne     inv_drv
57         dey
58         bpl     @L0
59
60 ; Copy the jump vectors
61
62         ldy     #EMD_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     #(EMD_HDR_JUMPCOUNT*3)
68         bne     @L1
69
70         jmp     emd_install             ; Call driver install routine
71
72 ; Driver signature invalid
73
74 inv_drv:
75         lda     #EM_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     emd_vectors,x
83         iny
84         inx
85         rts
86
87 ;----------------------------------------------------------------------------
88 ; unsigned char __fastcall__ em_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 _em_uninstall:
94         jsr     emd_uninstall           ; Call driver routine
95
96 em_clear_ptr:                           ; External entry point
97         lda     #0
98         sta     _em_drv
99         sta     _em_drv+1               ; Clear the driver pointer
100
101         tax
102         rts                             ; Return zero
103