]> git.sur5r.net Git - cc65/blob - libsrc/em/em-kernel.s
Use "override" when appending to CFLAGS, so this works even when CFLAGS is
[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, EMD_API_VERSION  ; "emd", version
37
38
39 ;----------------------------------------------------------------------------
40 ; unsigned char __fastcall__ em_install (void* driver);
41 ; /* Install the driver once it is loaded */
42
43
44 _em_install:
45         sta     _em_drv
46         sta     ptr1
47         stx     _em_drv+1
48         stx     ptr1+1
49
50 ; Check the driver signature
51
52         ldy     #.sizeof(emd_sig)-1
53 @L0:    lda     (ptr1),y
54         cmp     emd_sig,y
55         bne     inv_drv
56         dey
57         bpl     @L0
58
59 ; Copy the jump vectors
60
61         ldy     #EMD_HDR::JUMPTAB
62         ldx     #0
63 @L1:    inx                             ; Skip the JMP opcode
64         jsr     copy                    ; Copy one byte
65         jsr     copy                    ; Copy one byte
66         cpy     #(EMD_HDR::JUMPTAB + .sizeof(EMD_HDR::JUMPTAB))
67         bne     @L1
68
69         jmp     emd_install             ; Call driver install routine
70
71 ; Driver signature invalid
72
73 inv_drv:
74         lda     #EM_ERR_INV_DRIVER
75         ldx     #0
76         rts
77
78 ; Copy one byte from the jump vectors
79
80 copy:   lda     (ptr1),y
81         sta     emd_vectors,x
82         iny
83         inx
84         rts
85
86 ;----------------------------------------------------------------------------
87 ; unsigned char __fastcall__ em_uninstall (void);
88 ; /* Uninstall the currently loaded driver and return an error code.
89 ;  * Note: This call does not free allocated memory.
90 ;  */
91
92 _em_uninstall:
93         jsr     emd_uninstall           ; Call driver routine
94
95 em_clear_ptr:                           ; External entry point
96         lda     #0
97         sta     _em_drv
98         sta     _em_drv+1               ; Clear the driver pointer
99
100         tax
101         rts                             ; Return zero
102