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