]> git.sur5r.net Git - cc65/blob - libsrc/em/em-kernel.s
473cbb55c83198baa17278bd28923eab2fde9004
[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_install, _em_deinstall
8
9         .import         return0
10         .importzp       ptr1
11
12         .include        "em-kernel.inc"
13         .include        "em-error.inc"
14
15
16 ;----------------------------------------------------------------------------
17 ; Variables
18
19
20 .bss
21 _em_drv:        .res    2               ; Pointer to driver
22
23 ; Jump table for the driver functions.
24 .data
25 emd_vectors:
26 emd_install:    jmp     return0
27 emd_deinstall:  jmp     return0
28 emd_pagecount:  jmp     return0
29 emd_map:        jmp     return0
30 emd_use:        jmp     return0
31 emd_commit:     jmp     return0
32 emd_copyfrom:   jmp     return0
33 emd_copyto:     jmp     return0
34
35 ; Driver header signature
36 .rodata
37 emd_sig:        .byte   $65, $6d, $64, $00      ; "emd", version
38 emd_sig_len     = * - emd_sig
39
40
41 ;----------------------------------------------------------------------------
42 ; unsigned char __fastcall__ em_install (void* driver);
43 ; /* Install the driver once it is loaded */
44
45
46 _em_install:
47         sta     _em_drv
48         sta     ptr1
49         stx     _em_drv+1
50         stx     ptr1+1
51
52 ; Check the driver signature
53
54         ldy     #emd_sig_len-1
55 @L0:    lda     (ptr1),y
56         cmp     emd_sig,y
57         bne     inv_drv
58         dey
59         bpl     @L0
60
61 ; Copy the jump vectors
62
63         ldy     #EMD_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         cpx     #(EMD_HDR_JUMPCOUNT*3)
69         bne     @L1
70
71         jmp     emd_install             ; Call driver install routine
72
73 ; Driver signature invalid
74
75 inv_drv:
76         lda     #EM_ERR_INV_DRIVER
77         ldx     #0
78         rts
79
80 ; Copy one byte from the jump vectors
81
82 copy:   lda     (ptr1),y
83         iny
84 set:    sta     emd_vectors,x
85         inx
86         rts
87
88 ;----------------------------------------------------------------------------
89 ; void __fastcall__ em_deinstall (void);
90 ; /* Deinstall the driver before unloading it */
91
92 _em_deinstall:
93         jsr     emd_deinstall           ; Call driver routine
94
95 ; Point all jump vectors to return0
96
97         ldx     #0
98 @L1:    inx                             ; Skip JMP opcode
99         lda     #<return0
100         jsr     set
101         lda     #>return0
102         jsr     set
103         cpx     #(EMD_HDR_JUMPCOUNT*3)
104         bne     @L1
105
106         rts
107
108