]> git.sur5r.net Git - cc65/blob - libsrc/c64/emd/c64-reu.s
Renamed JUMPTABLE and cleaned up module.cfg.
[cc65] / libsrc / c64 / emd / c64-reu.s
1 ;
2 ; Extended memory driver for the Commodore REU. Driver works without
3 ; problems when statically linked.
4 ;
5 ; Ullrich von Bassewitz, 2002-11-29
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        "HEADER"
21
22 ; Driver signature
23
24         .byte   $65, $6d, $64           ; "emd"
25         .byte   EMD_API_VERSION         ; EM API version number
26
27 ; Library reference
28
29         .addr   $0000
30
31 ; Jump table
32
33         .addr   INSTALL
34         .addr   UNINSTALL
35         .addr   PAGECOUNT
36         .addr   MAP
37         .addr   USE
38         .addr   COMMIT
39         .addr   COPYFROM
40         .addr   COPYTO
41
42 ; ------------------------------------------------------------------------
43 ; Constants
44
45 REU_STATUS      = $DF00                 ; Status register
46 REU_COMMAND     = $DF01                 ; Command register
47 REU_C64ADDR     = $DF02                 ; C64 base address register
48 REU_REUADDR     = $DF04                 ; REU base address register
49 REU_COUNT       = $DF07                 ; Transfer count register
50 REU_IRQMASK     = $DF09                 ; IRQ mask register
51 REU_CONTROL     = $DF0A                 ; Control register
52 REU_TRIGGER     = $FF00                 ; REU command trigger
53
54 OP_COPYFROM     = $ED
55 OP_COPYTO       = $EC
56
57
58 ; ------------------------------------------------------------------------
59 ; Data.
60
61 .bss
62 pagecount:      .res    2               ; Number of pages available
63 curpage:        .res    2               ; Current page number
64
65 window:         .res    256             ; Memory "window"
66
67 reu_params:     .word   $0000           ; Host address, lo, hi
68                 .word   $0000           ; Exp  address, lo, hi
69                 .byte   $00             ; Expansion  bank no.
70                 .word   $0000           ; # bytes to move, lo, hi
71                 .byte   $00             ; Interrupt mask reg.
72                 .byte   $00             ; Adress control reg.
73
74 .code
75
76 ; ------------------------------------------------------------------------
77 ; INSTALL routine. Is called after the driver is loaded into memory. If
78 ; possible, check if the hardware is present and determine the amount of
79 ; memory available.
80 ; Must return an EM_ERR_xx code in a/x.
81 ;
82
83 INSTALL:
84         ldx     #$00                    ; High byte of return code
85         lda     #$55
86         sta     REU_REUADDR
87         cmp     REU_REUADDR             ; Check for presence of REU
88         bne     nodevice
89         asl     a                       ; A = $AA
90         sta     REU_REUADDR
91         cmp     REU_REUADDR             ; Check for presence of REU
92         bne     nodevice
93
94         ldy     #>(128*4)               ; Assume 128KB
95         lda     REU_STATUS
96         and     #$10                    ; Check size bit
97         beq     @L1
98         ldy     #>(256*4)               ; 256KB when size bit is set
99 @L1:    sty     pagecount+1
100
101         ldy     #$FF
102         sty     curpage
103         sty     curpage+1               ; Invalidate the current page
104         txa                             ; X = A = EM_ERR_OK
105         rts
106
107 ; No REU found
108
109 nodevice:
110         lda     #EM_ERR_NO_DEVICE
111 ;       rts                             ; Run into UNINSTALL instead
112
113 ; ------------------------------------------------------------------------
114 ; UNINSTALL routine. Is called before the driver is removed from memory.
115 ; Can do cleanup or whatever. Must not return anything.
116 ;
117
118 UNINSTALL:
119         rts
120
121
122 ; ------------------------------------------------------------------------
123 ; PAGECOUNT: Return the total number of available pages in a/x.
124 ;
125
126 PAGECOUNT:
127         lda     pagecount
128         ldx     pagecount+1
129         rts
130
131 ; ------------------------------------------------------------------------
132 ; MAP: Map the page in a/x into memory and return a pointer to the page in
133 ; a/x.  The contents of the currently mapped page (if any) may be discarded
134 ; by the driver.
135 ;
136
137 MAP:    sta     curpage
138         stx     curpage+1               ; Remember the new page
139
140         ldy     #OP_COPYFROM
141         jsr     common                  ; Copy the window
142
143         lda     #<window
144         ldx     #>window                ; Return the window address
145 done:   rts
146
147 ; ------------------------------------------------------------------------
148 ; USE: Tell the driver that the window is now associated with a given page.
149                                         
150 USE:    sta     curpage
151         stx     curpage+1               ; Remember the page
152         lda     #<window
153         ldx     #>window                ; Return the window
154         rts
155
156 ; ------------------------------------------------------------------------
157 ; COMMIT: Commit changes in the memory window to extended storage.
158
159 COMMIT: lda     curpage
160         ldx     curpage+1               ; Do we have a page mapped?
161         bmi     done                    ; Jump if no page mapped
162
163         ldy     #OP_COPYTO
164 common: sty     tmp1
165
166         ldy     #<window
167         sty     REU_C64ADDR
168         ldy     #>window
169         sty     REU_C64ADDR+1
170
171         ldy     #0
172         sty     REU_REUADDR+0
173         sta     REU_REUADDR+1
174         stx     REU_REUADDR+2
175
176         sty     REU_COUNT+0
177         ldy     #1
178         sty     REU_COUNT+1             ; Move 256 bytes
179         bne     transfer1               ; Transfer 256 bytes into REU
180
181 ; ------------------------------------------------------------------------
182 ; COPYFROM: Copy from extended into linear memory. A pointer to a structure
183 ; describing the request is passed in a/x.
184 ; The function must not return anything.
185 ;
186
187 COPYFROM:
188         ldy     #OP_COPYFROM
189         .byte   $2C
190
191 ; ------------------------------------------------------------------------
192 ; COPYTO: Copy from linear into extended memory. A pointer to a structure
193 ; describing the request is passed in a/x.
194 ; The function must not return anything.
195 ;
196
197 COPYTO:
198         ldy     #OP_COPYTO
199         sty     tmp1
200
201 ; Remember the passed pointer
202
203         sta     ptr1
204         stx     ptr1+1          ; Save the pointer
205
206 ; The structure passed to the functions has the same layout as the registers
207 ; of the Commodore REU, so register programming is easy.
208
209         ldy     #7-1
210 @L1:    lda     (ptr1),y
211         sta     REU_C64ADDR,y
212         dey
213         bpl     @L1
214
215 ; Invalidate the page in the memory window
216
217         sty     curpage+1       ; Y = $FF
218
219 ; Reload the REU command and start the transfer
220
221 transfer1:
222         ldy     tmp1
223
224 ; Transfer subroutine for the REU. Expects command in Y.
225
226 transfer:
227         sty     REU_COMMAND     ; Issue command
228
229         ldy     $01             ; Save the value of the c64 control port...
230         tya                     ;
231         and     #$F8            ; Disable ROMs and I/O.
232         sei                     ;
233         sta     $01
234         lda     REU_TRIGGER     ; Don't change $FF00
235         sta     REU_TRIGGER     ; Start the transfer...
236
237         sty     $01             ; Restore the old configuration
238         cli
239         rts
240