]> git.sur5r.net Git - cc65/blob - libsrc/c64/c64-georam.s
Replaced em_mapclean by em_commit
[cc65] / libsrc / c64 / c64-georam.s
1 ;
2 ; Extended memory driver for the GEORAM cartridge
3 ;
4 ; Ullrich von Bassewitz, 2002-11-29
5 ;
6
7         .include        "zeropage.inc"
8
9         .include        "em-kernel.inc"
10         .include        "em-error.inc"
11
12
13         .macpack        generic
14
15
16 ; ------------------------------------------------------------------------
17 ; Header. Includes jump table
18
19 .segment        "JUMPTABLE"
20
21 ; Driver signature
22
23         .byte   $65, $6d, $64           ; "emd"
24         .byte   $00                     ; EM API version number
25
26 ; Jump table.
27
28         .word   INSTALL
29         .word   DEINSTALL
30         .word   PAGECOUNT
31         .word   MAP
32         .word   COMMIT
33         .word   COPYFROM
34         .word   COPYTO
35
36 ; ------------------------------------------------------------------------
37 ; Constants
38
39 GR_WINDOW       = $DE00                 ; Address of GEORAM window
40 GR_PAGE_LO      = $DFFE                 ; Page register low
41 GR_PAGE_HI      = $DFFF                 ; Page register high
42
43 ; ------------------------------------------------------------------------
44 ; Data.
45
46 .data
47
48 pagecount:      .word   2048            ; Currently fixed
49
50 .code
51
52 ; ------------------------------------------------------------------------
53 ; INSTALL routine. Is called after the driver is loaded into memory. If
54 ; possible, check if the hardware is present and determine the amount of
55 ; memory available.
56 ; Must return an EM_ERR_xx code in a/x.
57 ;
58
59 INSTALL:
60         lda     #<EM_ERR_OK
61         ldx     #>EM_ERR_OK
62         rts
63
64 ; ------------------------------------------------------------------------
65 ; DEINSTALL routine. Is called before the driver is removed from memory.
66 ; Can do cleanup or whatever. Must not return anything.
67 ;
68
69 DEINSTALL:
70         rts
71
72
73 ; ------------------------------------------------------------------------
74 ; PAGECOUNT: Return the total number of available pages in a/x.
75 ;
76
77 PAGECOUNT:
78         lda     pagecount
79         ldx     pagecount+1
80         rts
81
82 ; ------------------------------------------------------------------------
83 ; MAP: Map the page in a/x into memory and return a pointer to the page in
84 ; a/x. The contents of the currently mapped page (if any) may be discarded
85 ; by the driver.
86 ;
87
88 MAP:    sta     tmp1
89         txa
90         asl     tmp1
91         rol     a
92         asl     tmp1
93         rol     a
94
95         sta     GR_PAGE_HI
96         lda     tmp1
97         lsr     a
98         lsr     a
99         sta     GR_PAGE_LO
100
101         lda     #<GR_WINDOW
102         ldx     #>GR_WINDOW
103
104 ; Use the RTS from COMMIT below to save a precious byte of storage
105
106 ; ------------------------------------------------------------------------
107 ; COMMIT: Commit changes in the memory window to extended storage.
108
109 COMMIT: rts
110
111 ; ------------------------------------------------------------------------
112 ; COPYFROM: Copy from extended into linear memory. A pointer to a structure
113 ; describing the request is passed in a/x.
114 ; The function must not return anything.
115 ;
116
117 COPYFROM:
118         jsr     setup
119
120 ; Setup is:
121 ;
122 ;   - ptr1 contains the struct pointer
123 ;   - ptr2 contains the linear memory buffer
124 ;   - ptr3 contains -(count-1)
125 ;   - tmp1 contains the low page register value
126 ;   - tmp2 contains the high page register value
127 ;   - X contains the page offset
128 ;   - Y contains zero
129
130         jmp     @L5
131
132 @L1:    lda     GR_WINDOW,x
133         sta     (ptr2),y
134         iny
135         bne     @L2
136         inc     ptr2+1
137 @L2:    inx
138         beq     @L4
139
140 ; Bump count and repeat
141
142 @L3:    inc     ptr3
143         bne     @L1
144         inc     ptr3+1
145         bne     @L1
146         rts
147
148 ; Bump page register
149
150 @L4:    inc     tmp1            ; Bump low page register
151         bit     tmp1            ; Check for overflow in bit 6
152         bvc     @L6             ; Jump if no overflow
153         inc     tmp2
154 @L5:    lda     tmp2
155         sta     GR_PAGE_HI
156 @L6:    lda     tmp1
157         sta     GR_PAGE_LO
158         jmp     @L3
159
160 ; ------------------------------------------------------------------------
161 ; COPYTO: Copy from linear into extended memory. A pointer to a structure
162 ; describing the request is passed in a/x.
163 ; The function must not return anything.
164 ;
165
166 COPYTO:
167         jsr     setup
168
169 ; Setup is:
170 ;
171 ;   - ptr1 contains the struct pointer
172 ;   - ptr2 contains the linear memory buffer
173 ;   - ptr3 contains -(count-1)
174 ;   - tmp1 contains the low page register value
175 ;   - tmp2 contains the high page register value
176 ;   - X contains the page offset
177 ;   - Y contains zero
178
179         jmp     @L5
180
181 @L1:    lda     (ptr2),y
182         sta     GR_WINDOW,x
183         iny
184         bne     @L2
185         inc     ptr2+1
186 @L2:    inx
187         beq     @L4
188
189 ; Bump count and repeat
190
191 @L3:    inc     ptr3
192         bne     @L1
193         inc     ptr3+1
194         bne     @L1
195         rts
196
197 ; Bump page register
198
199 @L4:    inc     tmp1            ; Bump low page register
200         bit     tmp1            ; Check for overflow in bit 6
201         bvc     @L6             ; Jump if no overflow
202         inc     tmp2
203 @L5:    lda     tmp2
204         sta     GR_PAGE_HI
205 @L6:    lda     tmp1
206         sta     GR_PAGE_LO
207         jmp     @L3
208
209 ; ------------------------------------------------------------------------
210 ; Helper function for COPYFROM and COPYTO: Store the pointer to the request
211 ; structure and prepare data for the copy
212
213 setup:  sta     ptr1
214         stx     ptr1+1          ; Save passed pointer
215
216 ; Get the page number from the struct and adjust it so that it may be used
217 ; with the hardware. That is: lower 6 bits in tmp1, high bits in tmp2.
218
219         ldy     #EM_COPY_PAGE+1
220         lda     (ptr1),y
221         sta     tmp2
222         dey
223         lda     (ptr1),y
224         asl     a
225         rol     tmp2
226         asl     a
227         rol     tmp2
228         lsr     a
229         lsr     a
230         sta     tmp1
231
232 ; Get the buffer pointer into ptr2
233
234         ldy     #EM_COPY_BUF
235         lda     (ptr1),y
236         sta     ptr2
237         iny
238         lda     (ptr1),y
239         sta     ptr2+1
240
241 ; Get the count, calculate -(count-1) and store it into ptr3
242
243         ldy     #EM_COPY_COUNT
244         lda     (ptr1),y
245         eor     #$FF
246         sta     ptr3
247         iny
248         lda     (ptr1),y
249         eor     #$FF
250         sta     ptr3+1
251
252 ; Get the page offset into X and clear Y
253
254         ldy     #EM_COPY_OFFS
255         lda     (ptr1),y
256         tax
257         ldy     #$00
258
259 ; Done
260
261         rts
262
263