]> git.sur5r.net Git - cc65/blob - libsrc/em/em-kernel.s
New extended memory API
[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     $0000
27 emd_deinstall:  jmp     $0000
28 emd_pagecount:  jmp     $0000
29 emd_map:        jmp     $0000
30 emd_mapclean:   jmp     $0000
31 emd_copyfrom:   jmp     $0000
32 emd_copyto:     jmp     $0000
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         iny
83 set:    sta     emd_vectors,x
84         inx
85         rts
86
87 ;----------------------------------------------------------------------------
88 ; void __fastcall__ em_deinstall (void);
89 ; /* Deinstall the driver before unloading it */
90
91 _em_deinstall:
92         jsr     emd_deinstall           ; Call driver routine
93
94 ; Point all jump vectors to return0
95
96         ldx     #0
97 @L1:    inx                             ; Skip JMP opcode
98         lda     #<return0
99         jsr     set
100         lda     #>return0
101         jsr     set
102         cpx     #(EMD_HDR_JUMPCOUNT*3)
103         bne     @L1
104
105         rts
106
107