]> git.sur5r.net Git - cc65/blob - libsrc/em/em-kernel.s
Implement packed mode
[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         .import         return0
8         .importzp       ptr1
9
10         .include        "em-kernel.inc"
11         .include        "em-error.inc"
12
13
14 ;----------------------------------------------------------------------------
15 ; Variables
16
17
18 .bss
19 _em_drv:        .res    2               ; Pointer to driver
20
21 ; Jump table for the driver functions.
22 .data
23 emd_vectors:
24 emd_install:    jmp     return0
25 emd_uninstall:  jmp     return0
26 emd_pagecount:  jmp     return0
27 emd_map:        jmp     return0
28 emd_use:        jmp     return0
29 emd_commit:     jmp     return0
30 emd_copyfrom:   jmp     return0
31 emd_copyto:     jmp     return0
32
33 ; Driver header signature
34 .rodata
35 emd_sig:        .byte   $65, $6d, $64, EMD_API_VERSION  ; "emd", version
36
37
38 ;----------------------------------------------------------------------------
39 ; unsigned char __fastcall__ em_install (void* driver);
40 ; /* Install the driver once it is loaded */
41
42
43 _em_install:
44         sta     _em_drv
45         sta     ptr1
46         stx     _em_drv+1
47         stx     ptr1+1
48
49 ; Check the driver signature
50
51         ldy     #.sizeof(emd_sig)-1
52 @L0:    lda     (ptr1),y
53         cmp     emd_sig,y
54         bne     inv_drv
55         dey
56         bpl     @L0
57
58 ; Copy the jump vectors
59
60         ldy     #EMD_HDR::JUMPTAB
61         ldx     #0
62 @L1:    inx                             ; Skip the JMP opcode
63         jsr     copy                    ; Copy one byte
64         jsr     copy                    ; Copy one byte
65         cpy     #(EMD_HDR::JUMPTAB + .sizeof(EMD_HDR::JUMPTAB))
66         bne     @L1
67
68         jmp     emd_install             ; Call driver install routine
69
70 ; Driver signature invalid
71
72 inv_drv:
73         lda     #EM_ERR_INV_DRIVER
74         ldx     #0
75         rts
76
77 ; Copy one byte from the jump vectors
78
79 copy:   lda     (ptr1),y
80         sta     emd_vectors,x
81         iny
82         inx
83         rts
84
85 ;----------------------------------------------------------------------------
86 ; unsigned char em_uninstall (void);
87 ; /* Uninstall the currently loaded driver and return an error code.
88 ;  * Note: This call does not free allocated memory.
89 ;  */
90
91 _em_uninstall:
92         jsr     emd_uninstall           ; Call driver routine
93
94 em_clear_ptr:                           ; External entry point
95         lda     #0
96         sta     _em_drv
97         sta     _em_drv+1               ; Clear the driver pointer
98
99         tax
100         rts                             ; Return zero