]> git.sur5r.net Git - cc65/blob - libsrc/apple2/apple2-auxmem.s
Dito for the enhanced apple2
[cc65] / libsrc / apple2 / apple2-auxmem.s
1 ;
2 ; Extended memory driver for the Apple II auxiliary memory
3 ;
4 ; Stefan Haubenthal, 2003-12-12
5 ; Ullrich von Bassewitz, 2002-12-02
6 ;
7
8         .include        "zeropage.inc"
9
10         .include        "em-kernel.inc"
11         .include        "em-error.inc"
12
13
14         .macpack        generic
15
16
17 ; ------------------------------------------------------------------------
18 ; Header. Includes jump table
19
20 .segment        "JUMPTABLE"
21
22 ; Driver signature
23
24         .byte   $65, $6d, $64           ; "emd"
25         .byte   EMD_API_VERSION         ; EM API version number
26
27 ; Jump table.
28
29         .word   INSTALL
30         .word   DEINSTALL
31         .word   PAGECOUNT
32         .word   MAP
33         .word   USE
34         .word   COMMIT
35         .word   COPYFROM
36         .word   COPYTO
37
38 ; ------------------------------------------------------------------------
39 ; Constants
40
41 BASE    = $0200
42 AUXCARD = $C30C                         ; Card signature
43 AUXMOVE = $C311                         ; Auxiliary move routine
44 PAGES   = ($C000 - BASE) / 256
45
46 ; ------------------------------------------------------------------------
47 ; Data.
48
49 .data
50 curpage:        .byte   $FF             ; Current page number (invalid)
51
52 .bss
53 window:         .res    256             ; Memory "window"
54
55 .code
56
57 ; ------------------------------------------------------------------------
58 ; INSTALL routine. Is called after the driver is loaded into memory. If
59 ; possible, check if the hardware is present and determine the amount of
60 ; memory available.
61 ; Must return an EM_ERR_xx code in a/x.
62 ;
63
64 INSTALL:
65         ldx     #0
66         lda     AUXCARD
67         and     #$f0
68         cmp     #$80
69         bne     @L1
70         lda     #EM_ERR_OK
71         rts
72 @L1:    lda     #EM_ERR_NO_DEVICE
73 ;       rts
74
75 ; ------------------------------------------------------------------------
76 ; DEINSTALL routine. Is called before the driver is removed from memory.
77 ; Can do cleanup or whatever. Must not return anything.
78 ;
79
80 DEINSTALL:
81         rts
82
83
84 ; ------------------------------------------------------------------------
85 ; PAGECOUNT: Return the total number of available pages in a/x.
86 ;
87
88 PAGECOUNT:
89         lda     #<PAGES
90         ldx     #>PAGES
91         rts
92
93 ; ------------------------------------------------------------------------
94 ; MAP: Map the page in a/x into memory and return a pointer to the page in
95 ; a/x. The contents of the currently mapped page (if any) may be discarded
96 ; by the driver.
97 ;
98
99 MAP:    sta     curpage                 ; Remember the new page
100
101         add     #>BASE
102         sta     ptr1+1
103         ldy     #$00
104         sty     ptr1
105
106         lda     #<window
107         sta     ptr2
108         lda     #>window
109         sta     ptr2+1
110
111 ; Transfer one page
112
113         clc                             ; Direction flag
114         jsr     transfer                ; Transfer one page
115
116 ; Return the memory window
117
118         lda     #<window
119         ldx     #>window                ; Return the window address
120
121 ; Done
122
123 done:   rts
124
125 ; ------------------------------------------------------------------------
126 ; USE: Tell the driver that the window is now associated with a given page.
127
128 USE:    sta     curpage                 ; Remember the page
129         lda     #<window
130         ldx     #>window                ; Return the window
131         rts
132
133 ; ------------------------------------------------------------------------
134 ; COMMIT: Commit changes in the memory window to extended storage.
135
136 COMMIT: lda     curpage                 ; Get the current page
137         cmp     #$FF
138         beq     done                    ; Jump if no page mapped
139
140         add     #>BASE
141         sta     ptr2+1
142         ldy     #$00
143         sty     ptr2
144
145         lda     #<window
146         sta     ptr1
147         lda     #>window
148         sta     ptr1+1
149         lda     #<$FF
150         sta     ptr4
151         lda     #>$FF
152         sta     ptr4+1
153         sec                             ; Direction flag
154
155 ; Transfer one page/all bytes
156
157 transfer:
158         php
159         lda     ptr1
160         sta     $3C
161         add     ptr4
162         sta     $3E
163         lda     ptr1+1
164         sta     $3D
165         adc     ptr4+1
166         sta     $3F
167         lda     ptr2
168         sta     $42
169         lda     ptr2+1
170         sta     $43
171         plp
172         jmp     AUXMOVE
173
174 ; ------------------------------------------------------------------------
175 ; COPYFROM: Copy from extended into linear memory. A pointer to a structure
176 ; describing the request is passed in a/x.
177 ; The function must not return anything.
178 ;
179
180 COPYFROM:
181         sta     ptr3
182         stx     ptr3+1                  ; Save the passed em_copy pointer
183
184         ldy     #EM_COPY::OFFS
185         lda     (ptr3),y
186         sta     ptr1
187         ldy     #EM_COPY::PAGE
188         lda     (ptr3),y
189         add     #>BASE
190         sta     ptr1+1                  ; From
191
192         ldy     #EM_COPY::BUF
193         lda     (ptr3),y
194         sta     ptr2
195         iny
196         lda     (ptr3),y
197         sta     ptr2+1                  ; To
198         clc                             ; Direction flag
199
200 common: ldy     #EM_COPY::COUNT
201         lda     (ptr3),y                ; Get bytes in last page
202         sta     ptr4
203         iny
204         lda     (ptr3),y                ; Get number of pages
205         sta     ptr4+1
206
207         jmp     transfer
208
209 ; ------------------------------------------------------------------------
210 ; COPYTO: Copy from linear into extended memory. A pointer to a structure
211 ; describing the request is passed in a/x.
212 ; The function must not return anything.
213 ;
214
215 COPYTO: sta     ptr3
216         stx     ptr3+1                  ; Save the passed em_copy pointer
217
218         ldy     #EM_COPY::OFFS
219         lda     (ptr3),y
220         sta     ptr2
221         ldy     #EM_COPY::PAGE
222         lda     (ptr3),y
223         add     #>BASE
224         sta     ptr2+1                  ; To
225
226         ldy     #EM_COPY::BUF
227         lda     (ptr3),y
228         sta     ptr1
229         iny
230         lda     (ptr3),y
231         sta     ptr1+1                  ; From
232
233         sec                             ; Direction flag
234         jmp     common