]>
Commit | Line | Data |
---|---|---|
ea5293bb L |
1 | page 255 |
2 | .z80 | |
3 | ||
4 | ||
5 | global mmuinit | |
1e1c17d3 | 6 | global bnk2log,bnk2phy,hwl2phy,phy2log |
ea5293bb L |
7 | |
8 | include config.inc | |
9 | include z180reg.inc | |
10 | ||
11 | ||
12 | ;---------------------------------------------------------------------- | |
1e1c17d3 | 13 | ; Memory Map 1: |
ea5293bb | 14 | ; |
1e1c17d3 L |
15 | ; Common CAStart .. 0FFFF |
16 | ; Bank 0 00000 .. CAStart-1 | |
17 | ; Bank 1 10000 .. | |
ea5293bb L |
18 | ; Bank 2 |
19 | ; | |
1e1c17d3 L |
20 | ; Memory Map 2: |
21 | ; | |
22 | ; Common 18000 .. 1BFFF BANK1 | |
23 | ; | |
24 | ; Bank 0 00000 .. 0BFFF 0 | |
25 | ; Bank 1 0C000 .. 17FFF 1*BNK_SIZE | |
26 | ; Bank 2 1C000 .. 27FFF 2*BNK_SIZE + CMN_SIZE | |
27 | ; Bank 3 28000 .. 33FFF 3*BNK_SIZE + CMN_SIZE | |
28 | ; Bank n n*BNK_SIZE + (n < 2) ? 0 : CMN_SIZE | |
29 | ; | |
ea5293bb L |
30 | ;---------------------------------------------------------------------- |
31 | ||
32 | cseg | |
33 | ||
34 | mmuinit: | |
35 | ld a,USR$CBAR | |
36 | out0 (cbar),a | |
37 | ret | |
38 | ||
39 | ;-------------------------------------------------------------------- | |
40 | ; Return the BBR value for the given bank number | |
41 | ; | |
42 | ; in a: Bank number | |
43 | ; out a: bbr value | |
44 | ||
1e1c17d3 L |
45 | if 0 ; Memory Map 1 |
46 | ||
ea5293bb L |
47 | bnk2log: |
48 | or a ; | |
49 | ret z ; Bank 0 is at physical address 0 | |
50 | ||
1e1c17d3 | 51 | dec a ; |
ea5293bb | 52 | push bc ; |
1e1c17d3 L |
53 | ld c,a ; |
54 | ld b,BNK_SIZE ; | |
ea5293bb L |
55 | mlt bc ; bank size * bank number |
56 | ld a,c ; | |
57 | add a,10h ; add bank0 + common | |
58 | pop bc ; | |
59 | ret ; | |
60 | ||
1e1c17d3 L |
61 | else ; Memory Map 2 |
62 | ||
63 | bnk2log: | |
64 | or a | |
65 | ret z ; Bank 0 is at physical address 0 | |
66 | ||
67 | push bc | |
68 | ld c,a ; | |
69 | ld b,BNK_SIZE ; | |
70 | mlt bc ; bank size * bank number | |
71 | cp 2 ; | |
72 | ld a,c ; | |
73 | pop bc | |
74 | ret c | |
75 | add a,CMN_SIZE | |
76 | ret | |
77 | ||
78 | endif | |
79 | ||
80 | if 0 ; table version | |
81 | ||
82 | push hl | |
83 | ld hl,bnk_table ; | |
84 | add a,l ; | |
85 | ld l,a ; | |
86 | jr nc,$+3 ; | |
87 | inc h ; | |
88 | ld a,(hl) ; | |
89 | pop hl | |
90 | ret | |
91 | ||
92 | endif | |
93 | ||
ea5293bb L |
94 | ;-------------------------------------------------------------- |
95 | ||
96 | ;in hl: Log. Address | |
97 | ; a: Bank number | |
98 | ; | |
99 | ;out ahl: Phys. (linear) Address | |
100 | ||
101 | ||
102 | bnk2phy: | |
1d26b866 L |
103 | push bc |
104 | ld c,a | |
105 | ld a,h | |
106 | and a,0f0h | |
107 | cp CA*16 | |
108 | ld a,c | |
109 | pop bc | |
1d26b866 | 110 | jr c,b2p_banked |
1e1c17d3 L |
111 | ; address is in common |
112 | if 0 ; Memory Map 1 | |
113 | ld a,0 ; base is 0 | |
114 | else ; Memory Map 2 | |
115 | ld a,1 ; same as bank1 | |
116 | endif | |
117 | ||
1d26b866 L |
118 | b2p_banked: |
119 | call bnk2log ; get address base | |
1d26b866 | 120 | |
ea5293bb L |
121 | ; fall thru |
122 | ||
123 | ;-------------------------------------------------------------- | |
124 | ; | |
125 | ; hl: Log. Address | |
126 | ; a: Bank base (bbr) | |
127 | ; | |
128 | ; 2 0 0 | |
129 | ; 0 6 8 0 | |
130 | ; hl hhhhhhhhllllllll | |
131 | ; a + bbbbbbbb | |
132 | ; | |
133 | ; OP: ahl = (a<<12) + (h<<8) + l | |
134 | ; | |
135 | ;out ahl: Phys. (linear) Address | |
136 | ||
137 | log2phy: | |
138 | push bc ; | |
139 | l2p_i: | |
140 | ld c,a ; | |
141 | ld b,16 ; | |
142 | mlt bc ; bc = a<<4 | |
143 | ld a,c ; | |
144 | add a,h ; | |
145 | ld h,a ; | |
146 | ld a,b ; | |
147 | adc a,0 ; | |
148 | pop bc ; | |
149 | ret ; | |
150 | ||
151 | ;-------------------------------------------------------------- | |
152 | ; | |
1e1c17d3 | 153 | ; hl: Log. Address |
ea5293bb L |
154 | ; |
155 | ; | |
1e1c17d3 | 156 | ; OP: ahl = (bankbase<<12) + (h<<8) + l |
ea5293bb L |
157 | ; |
158 | ;out ahl: Phys. (linear) Address | |
159 | ||
160 | ||
161 | hwl2phy: | |
162 | push bc ; | |
163 | in0 c,(cbar) ; | |
164 | ld a,h ; | |
165 | or 00fh ; log. addr in common1? | |
166 | cp c | |
167 | jr c,hlp_1 | |
168 | ||
169 | in0 a,(cbr) ; yes, cbr is address base | |
170 | jr hl2p_x | |
171 | hlp_1: | |
172 | ld b,16 ; log. address in baked area? | |
173 | mlt bc | |
174 | ld a,h | |
175 | cp c | |
176 | jr c,hlp_2 | |
177 | in0 a,(bbr) ; yes, bbr is address base | |
178 | jr hl2p_x | |
179 | hlp_2: | |
180 | xor a ; common1 | |
181 | hl2p_x: | |
182 | jr nz,l2p_i | |
183 | ||
184 | pop bc ; bank part is 0, no translation | |
185 | ret ; | |
186 | ||
187 | ||
1e1c17d3 L |
188 | ;-------------------------------------------------------------- |
189 | ; return logical bank 0 address for given physical address. | |
190 | ; | |
191 | ; in: ahl: pyhsical addres (20 bit) | |
192 | ; out hl: logical address. | |
193 | ; logical address is in bank 0 or common, no bank number returned | |
194 | ; | |
195 | ||
196 | phy2log: | |
197 | or a | |
198 | ret z | |
199 | ||
200 | push bc | |
201 | push hl | |
202 | ld l,h | |
203 | ld h,0 | |
204 | ld bc,-16*SYS$CBR | |
205 | add hl,bc | |
206 | ld h,l | |
207 | pop bc | |
208 | ld l,c | |
209 | pop bc | |
210 | ret | |
211 | ||
b43b4662 L |
212 | ;-------------------------------------------------------------- |
213 | ; Trampoline for routines in banked ram. | |
214 | ; Switch stack pointer to "system" stack in top ram | |
215 | ; Save cbar | |
216 | ; | |
217 | extrn bs$stack | |
218 | ||
219 | cseg ; common! | |
220 | ||
221 | public _b0call | |
222 | _b0call: | |
40df51ae L |
223 | push af |
224 | in0 a,(bbr) | |
225 | jr nz,b0c_doit | |
226 | pop af | |
b43b4662 | 227 | |
40df51ae L |
228 | ex (sp),hl ;16 |
229 | push de | |
230 | ld e,(hl) | |
231 | inc hl | |
232 | ld d,(hl) | |
233 | inc hl | |
234 | ld (b0c_fast_go),de | |
235 | pop de | |
236 | ex (sp),hl ;16 | |
237 | b0c_fast_go equ $+1 | |
238 | jp 0 | |
239 | ||
240 | b0c_doit: | |
b43b4662 L |
241 | ld (b0_save_hl),hl |
242 | ld (b0_save_de),de | |
b43b4662 L |
243 | pop hl |
244 | ld (b0_save_af),hl | |
245 | ||
246 | pop de ;get ptr to 'function address' in de | |
247 | ld hl,2 | |
248 | add hl,de | |
249 | push hl ;put return address on stack | |
250 | ||
251 | if 0 ; link80 | |
252 | ||
253 | ld hl,0 | |
254 | add hl,sp ; | |
255 | ld a,h | |
256 | cp high (bs$stack-bs$stack$size) ;link80 can't process this | |
257 | jr nc,$ + 5 ;skip if stack allready in common bios ram | |
258 | ||
259 | else | |
260 | ||
261 | ld hl,bs$stack-bs$stack$size | |
262 | ld a,h | |
263 | dec a | |
264 | ld hl,0 | |
265 | add hl,sp ; | |
266 | cp h | |
267 | jr c,$ + 5 ;skip if stack allready in common bios ram | |
268 | endif | |
269 | ld sp,bs$stack ; | |
270 | ||
271 | push hl ;save user stack pointer | |
40df51ae L |
272 | |
273 | in0 h,(bbr) ; | |
b43b4662 L |
274 | push hl ; |
275 | ld hl,b0c_ret | |
276 | push hl | |
40df51ae L |
277 | xor a |
278 | out0 (bbr),a ; | |
b43b4662 L |
279 | ex de,hl ;ptr |
280 | ld e,(hl) ;get 'function address' | |
281 | inc hl ; | |
282 | ld d,(hl) ; | |
283 | push de ;put on (switched) stack | |
284 | ||
285 | ld hl,(b0_save_af) ;get back users registers | |
286 | push hl | |
287 | pop af | |
288 | ld de,(b0_save_de) | |
289 | ld hl,(b0_save_hl) | |
290 | ret ;go to function | |
291 | b0c_ret: | |
292 | ld (b0_save_hl),hl | |
293 | ||
294 | pop hl ; | |
40df51ae | 295 | out0 (bbr),h ; |
b43b4662 L |
296 | pop hl ; |
297 | ld sp,hl ; | |
298 | ld hl,(b0_save_hl) | |
299 | ret ; | |
300 | ||
301 | ||
302 | b0_save_hl: dw 0 | |
303 | b0_save_de: dw 0 | |
304 | b0_save_af: dw 0 | |
305 | ||
306 | ||
307 | ||
ea5293bb L |
308 | ;==================================================================== |
309 | ||
310 | if 0 | |
311 | ||
312 | ;-------------------------------------------------------------------- | |
313 | ; Return the BBR value for the given bank number | |
314 | ||
315 | bnk2bbr: | |
316 | or a ; 4 | |
317 | ret z ; 5/10 | 11 14 | |
318 | ||
319 | push bc ;11 | 11 | |
320 | ld b,a ; 4 | |
321 | ld c,CA ; 6 | |
322 | mlt bc ;17 >45 | |
323 | ld a,c ; 4 | |
324 | add a,10h ; 6 | |
325 | pop bc ; 9 | 10 | |
326 | ret ; 9 | 10 76 | |
327 | ||
328 | push ix ;2 / 14 | 15 | |
329 | ld ix,bnktbl ;4 / 12 | 14 | |
330 | ld ($+3+2),a ;3 / 15 | 19 | |
331 | ld a,(ix+0) ;3 / 14 | 19 | |
332 | pop ix ;2 / 12 | 14 | |
333 | ret ;1 / 9 | 10 15 / 76|91 | |
334 | ||
335 | push hl ;1 / 11 | 11 | |
336 | ld hl,bnktbl ;3 / 9 | 10 | |
337 | add a,l ;1 / 4 | 4 | |
338 | ld l,a ;1 / 4 | 4 | |
339 | ld a,0 ;1 / 6 | 7 | |
340 | adc a,h ;1 / 4 | 4 | |
341 | ld h,a ;1 / 4 | 4 | |
342 | ld a,(hl) ;1 / 6 | 7 | |
343 | pop hl ;1 / 9 | 10 | |
344 | ret ;1 / 9 | 10 12 / 66|71 | |
345 | ||
346 | push hl ;1 / 11 | 11 | |
347 | add a,low bnktbl ;2 / 6 | 7 | |
348 | ld l,a ;1 / 4 | 4 | |
349 | ld a,0 ;1 / 6 | 7 | |
350 | adc a,high bnktbl ;2 / 6 | 7 | |
351 | ld h,a ;1 / 4 | 4 | |
352 | ld a,(hl) ;1 / 6 | 7 | |
353 | pop hl ;1 / 9 | 10 | |
354 | ret ;1 / 9 | 10 11 / 61|67 | |
355 | ||
356 | endif | |
357 | ||
358 | ||
359 | end |