]> git.sur5r.net Git - cc65/blob - libsrc/c64/c64-georam.s
288850acc2811cf9247538af2d78a187cd3838d5
[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   MAPCLEAN
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) are assumed to be
85 ; dirty and must be saved into secondary storage if this is necessary.
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         rts
104
105 ; ------------------------------------------------------------------------
106 ; MAPCLEAN: Map the page in a/x into memory and return a pointer to the page
107 ; in a/x. The contents of the currently mapped page (if any) are assumed to
108 ; be clean, so if this is an advantage for the driver, the current contents
109 ; may be discarded.
110
111 MAPCLEAN        = MAP           ; Identical for GEORAM
112
113
114 ; ------------------------------------------------------------------------
115 ; COPYFROM: Copy from extended into linear memory. A pointer to a structure
116 ; describing the request is passed in a/x.
117 ; The function must not return anything.
118 ;
119
120 COPYFROM:
121         jsr     setup
122
123 ; Setup is:
124 ;
125 ;   - ptr1 contains the struct pointer
126 ;   - ptr2 contains the linear memory buffer
127 ;   - ptr3 contains -(count-1)
128 ;   - tmp1 contains the low page register value
129 ;   - tmp2 contains the high page register value
130 ;   - X contains the page offset
131 ;   - Y contains zero
132
133         jmp     @L5
134
135 @L1:    lda     GR_WINDOW,x
136         sta     (ptr2),y
137         iny
138         bne     @L2
139         inc     ptr2+1
140 @L2:    inx
141         beq     @L4
142
143 ; Bump count and repeat
144
145 @L3:    inc     ptr3
146         bne     @L1
147         inc     ptr3+1
148         bne     @L1
149         rts
150
151 ; Bump page register
152
153 @L4:    inc     tmp1            ; Bump low page register
154         bit     tmp1            ; Check for overflow in bit 6
155         bvc     @L6             ; Jump if no overflow
156         inc     tmp2
157 @L5:    lda     tmp2
158         sta     GR_PAGE_HI
159 @L6:    lda     tmp1
160         sta     GR_PAGE_LO
161         jmp     @L3
162
163 ; ------------------------------------------------------------------------
164 ; COPYTO: Copy from linear into extended memory. A pointer to a structure
165 ; describing the request is passed in a/x.
166 ; The function must not return anything.
167 ;
168
169 COPYTO:
170         jsr     setup
171
172 ; Setup is:
173 ;
174 ;   - ptr1 contains the struct pointer
175 ;   - ptr2 contains the linear memory buffer
176 ;   - ptr3 contains -(count-1)
177 ;   - tmp1 contains the low page register value
178 ;   - tmp2 contains the high page register value
179 ;   - X contains the page offset
180 ;   - Y contains zero
181
182         jmp     @L5
183
184 @L1:    lda     (ptr2),y
185         sta     GR_WINDOW,x
186         iny
187         bne     @L2
188         inc     ptr2+1
189 @L2:    inx
190         beq     @L4
191
192 ; Bump count and repeat
193
194 @L3:    inc     ptr3
195         bne     @L1
196         inc     ptr3+1
197         bne     @L1
198         rts
199
200 ; Bump page register
201
202 @L4:    inc     tmp1            ; Bump low page register
203         bit     tmp1            ; Check for overflow in bit 6
204         bvc     @L6             ; Jump if no overflow
205         inc     tmp2
206 @L5:    lda     tmp2
207         sta     GR_PAGE_HI
208 @L6:    lda     tmp1
209         sta     GR_PAGE_LO
210         jmp     @L3
211
212 ; ------------------------------------------------------------------------
213 ; Helper function for COPYFROM and COPYTO: Store the pointer to the request
214 ; structure and prepare data for the copy
215
216 setup:  sta     ptr1
217         stx     ptr1+1          ; Save passed pointer
218
219 ; Get the page number from the struct and adjust it so that it may be used
220 ; with the hardware. That is: lower 6 bits in tmp1, high bits in tmp2.
221
222         ldy     #EM_COPY_PAGE+1
223         lda     (ptr1),y
224         sta     tmp2
225         dey
226         lda     (ptr1),y
227         asl     a
228         rol     tmp2
229         asl     a
230         rol     tmp2
231         lsr     a
232         lsr     a
233         sta     tmp1
234
235 ; Get the buffer pointer into ptr2
236
237         ldy     #EM_COPY_BUF
238         lda     (ptr1),y
239         sta     ptr2
240         iny
241         lda     (ptr1),y
242         sta     ptr2+1
243
244 ; Get the count, calculate -(count-1) and store it into ptr3
245
246         ldy     #EM_COPY_COUNT
247         lda     (ptr1),y
248         eor     #$FF
249         sta     ptr3
250         iny
251         lda     (ptr1),y
252         eor     #$FF
253         sta     ptr3+1
254
255 ; Get the page offset into X and clear Y
256
257         ldy     #EM_COPY_OFFS
258         lda     (ptr1),y
259         tax
260         ldy     #$00
261
262 ; Done
263
264         rts
265
266