]>
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 | |
1c7e3963 | 8 | public b_ld_a,b_ld_hl,b_st_a,b_st_hl |
d6829fd3 | 9 | |
1c7e3963 L |
10 | |
11 | extrn @cbnk | |
12 | extrn ijphl | |
13 | ||
14 | ||
15 | maclib z180reg.inc | |
16 | maclib config.inc | |
d6829fd3 L |
17 | |
18 | ||
19 | ;---------------------------------------------------------------------- | |
20 | ; Memory Map 1: | |
21 | ; | |
22 | ; Common CAStart .. 0FFFF | |
23 | ; Bank 0 00000 .. CAStart-1 | |
24 | ; Bank 1 10000 .. | |
25 | ; Bank 2 | |
26 | ; | |
27 | ; Memory Map 2: | |
28 | ; | |
29 | ; Common 18000 .. 1BFFF BANK1 | |
30 | ; | |
31 | ; Bank 0 00000 .. 0BFFF 0 | |
32 | ; Bank 1 0C000 .. 17FFF 1*BNK_SIZE | |
33 | ; Bank 2 1C000 .. 27FFF 2*BNK_SIZE + CMN_SIZE | |
34 | ; Bank 3 28000 .. 33FFF 3*BNK_SIZE + CMN_SIZE | |
35 | ; Bank n n*BNK_SIZE + (n < 2) ? 0 : CMN_SIZE | |
36 | ; | |
37 | ;---------------------------------------------------------------------- | |
38 | ||
39 | cseg | |
40 | ||
41 | mmuinit: | |
42 | ld a,USR$CBAR | |
43 | out0 (cbar),a | |
44 | ret | |
45 | ||
46 | ;-------------------------------------------------------------------- | |
47 | ; Return the BBR value for the given bank number | |
48 | ; | |
49 | ; in a: Bank number | |
50 | ; out a: bbr value | |
51 | ||
52 | if 0 ; Memory Map 1 | |
53 | ||
54 | bnk2log: | |
55 | or a ; | |
56 | ret z ; Bank 0 is at physical address 0 | |
57 | ||
58 | dec a ; | |
59 | push bc ; | |
60 | ld c,a ; | |
61 | ld b,BNK_SIZE ; | |
62 | mlt bc ; bank size * bank number | |
63 | ld a,c ; | |
64 | add a,10h ; add bank0 + common | |
65 | pop bc ; | |
66 | ret ; | |
67 | ||
68 | else ; Memory Map 2 | |
69 | ||
70 | bnk2log: | |
71 | or a | |
72 | ret z ; Bank 0 is at physical address 0 | |
73 | ||
74 | push bc | |
75 | ld c,a ; | |
76 | ld b,BNK_SIZE ; | |
77 | mlt bc ; bank size * bank number | |
78 | cp 2 ; | |
79 | ld a,c ; | |
80 | pop bc | |
81 | ret c | |
82 | add a,CMN_SIZE | |
83 | ret | |
84 | ||
85 | endif | |
86 | ||
87 | if 0 ; table version | |
88 | ||
89 | push hl | |
90 | ld hl,bnk_table ; | |
91 | add a,l ; | |
92 | ld l,a ; | |
93 | jr nc,$+3 ; | |
94 | inc h ; | |
95 | ld a,(hl) ; | |
96 | pop hl | |
97 | ret | |
98 | ||
99 | endif | |
100 | ||
101 | ;-------------------------------------------------------------- | |
102 | ||
103 | ;in hl: Log. Address | |
104 | ; a: Bank number | |
105 | ; | |
106 | ;out ahl: Phys. (linear) Address | |
107 | ||
108 | ||
109 | bnk2phy: | |
110 | push bc | |
111 | ld c,a | |
112 | ld a,h | |
113 | and a,0f0h | |
114 | cp CA*16 | |
115 | ld a,c | |
116 | pop bc | |
117 | jr c,b2p_banked | |
118 | ; address is in common | |
119 | if 0 ; Memory Map 1 | |
120 | ld a,0 ; base is 0 | |
121 | else ; Memory Map 2 | |
122 | ld a,1 ; same as bank1 | |
123 | endif | |
124 | ||
125 | b2p_banked: | |
126 | call bnk2log ; get address base | |
127 | ||
128 | ; fall thru | |
129 | ||
130 | ;-------------------------------------------------------------- | |
131 | ; | |
132 | ; hl: Log. Address | |
133 | ; a: Bank base (bbr) | |
134 | ; | |
135 | ; 2 0 0 | |
136 | ; 0 6 8 0 | |
137 | ; hl hhhhhhhhllllllll | |
138 | ; a + bbbbbbbb | |
139 | ; | |
140 | ; OP: ahl = (a<<12) + (h<<8) + l | |
141 | ; | |
142 | ;out ahl: Phys. (linear) Address | |
143 | ||
144 | log2phy: | |
145 | push bc ; | |
146 | l2p_i: | |
147 | ld c,a ; | |
148 | ld b,16 ; | |
149 | mlt bc ; bc = a<<4 | |
150 | ld a,c ; | |
151 | add a,h ; | |
152 | ld h,a ; | |
153 | ld a,b ; | |
154 | adc a,0 ; | |
155 | pop bc ; | |
156 | ret ; | |
157 | ||
158 | ;-------------------------------------------------------------- | |
159 | ; | |
160 | ; hl: Log. Address | |
161 | ; | |
162 | ; | |
163 | ; OP: ahl = (bankbase<<12) + (h<<8) + l | |
164 | ; | |
165 | ;out ahl: Phys. (linear) Address | |
166 | ||
167 | ||
168 | hwl2phy: | |
169 | push bc ; | |
170 | in0 c,(cbar) ; | |
171 | ld a,h ; | |
172 | or 00fh ; log. addr in common1? | |
173 | cp c | |
174 | jr c,hlp_1 | |
175 | ||
176 | in0 a,(cbr) ; yes, cbr is address base | |
177 | jr hl2p_x | |
178 | hlp_1: | |
179 | ld b,16 ; log. address in baked area? | |
180 | mlt bc | |
181 | ld a,h | |
182 | cp c | |
183 | jr c,hlp_2 | |
184 | in0 a,(bbr) ; yes, bbr is address base | |
185 | jr hl2p_x | |
186 | hlp_2: | |
187 | xor a ; common1 | |
188 | hl2p_x: | |
189 | jr nz,l2p_i | |
190 | ||
191 | pop bc ; bank part is 0, no translation | |
192 | ret ; | |
193 | ||
194 | ||
195 | ;-------------------------------------------------------------- | |
196 | ; return logical bank 0 address for given physical address. | |
197 | ; | |
198 | ; in: ahl: pyhsical addres (20 bit) | |
199 | ; out hl: logical address. | |
200 | ; logical address is in bank 0 or common, no bank number returned | |
201 | ; | |
202 | ||
203 | phy2log: | |
204 | or a | |
205 | ret z | |
206 | ||
207 | push bc | |
208 | push hl | |
209 | ld l,h | |
210 | ld h,0 | |
211 | ld bc,-16*SYS$CBR | |
212 | add hl,bc | |
213 | ld h,l | |
214 | pop bc | |
215 | ld l,c | |
216 | pop bc | |
217 | ret | |
218 | ||
219 | ;-------------------------------------------------------------- | |
220 | ; Trampoline for routines in banked ram. | |
221 | ; Switch stack pointer to "system" stack in top ram | |
222 | ; Save cbar | |
223 | ; | |
224 | extrn bs$stack | |
225 | ||
226 | cseg ; common! | |
227 | ||
228 | public _b0call | |
229 | _b0call: | |
230 | push af | |
231 | in0 a,(bbr) | |
232 | jr nz,b0c_doit | |
233 | pop af | |
234 | ||
235 | ex (sp),hl ;16 | |
236 | push de | |
237 | ld e,(hl) | |
238 | inc hl | |
239 | ld d,(hl) | |
240 | inc hl | |
241 | ld (b0c_fast_go),de | |
242 | pop de | |
243 | ex (sp),hl ;16 | |
244 | b0c_fast_go equ $+1 | |
245 | jp 0 | |
246 | ||
247 | b0c_doit: | |
248 | ld (b0_save_hl),hl | |
249 | ld (b0_save_de),de | |
250 | pop hl | |
251 | ld (b0_save_af),hl | |
252 | ||
253 | pop de ;get ptr to 'function address' in de | |
254 | ld hl,2 | |
255 | add hl,de | |
256 | push hl ;put return address on stack | |
257 | ||
258 | if 0 ; link80 | |
259 | ||
260 | ld hl,0 | |
261 | add hl,sp ; | |
262 | ld a,h | |
263 | cp high (bs$stack-bs$stack$size) ;link80 can't process this | |
264 | jr nc,$ + 5 ;skip if stack allready in common bios ram | |
265 | ||
266 | else | |
267 | ||
268 | ld hl,bs$stack-bs$stack$size | |
269 | ld a,h | |
270 | dec a | |
271 | ld hl,0 | |
272 | add hl,sp ; | |
273 | cp h | |
274 | jr c,$ + 5 ;skip if stack allready in common bios ram | |
275 | endif | |
276 | ld sp,bs$stack ; | |
277 | ||
278 | push hl ;save user stack pointer | |
279 | ||
280 | in0 h,(bbr) ; | |
281 | push hl ; | |
282 | ld hl,b0c_ret | |
283 | push hl | |
284 | xor a | |
285 | out0 (bbr),a ; | |
286 | ex de,hl ;ptr | |
287 | ld e,(hl) ;get 'function address' | |
288 | inc hl ; | |
289 | ld d,(hl) ; | |
290 | push de ;put on (switched) stack | |
291 | ||
292 | ld hl,(b0_save_af) ;get back users registers | |
293 | push hl | |
294 | pop af | |
295 | ld de,(b0_save_de) | |
296 | ld hl,(b0_save_hl) | |
297 | ret ;go to function | |
298 | b0c_ret: | |
299 | ld (b0_save_hl),hl | |
300 | ||
301 | pop hl ; | |
302 | out0 (bbr),h ; | |
303 | pop hl ; | |
304 | ld sp,hl ; | |
305 | ld hl,(b0_save_hl) | |
306 | ret ; | |
307 | ||
308 | ||
309 | b0_save_hl: dw 0 | |
310 | b0_save_de: dw 0 | |
311 | b0_save_af: dw 0 | |
312 | ||
313 | ||
314 | ;-------------------------------------------------------------------- | |
315 | ; Trampoline for interrupt routines in banked ram. | |
316 | ; Switch stack pointer to "system" stack in top ram | |
317 | ; Save bbr | |
318 | ||
319 | cseg | |
320 | isv_sw: ; | |
321 | ex (sp),hl ;save hl, 'return adr' in hl | |
322 | push de ; | |
323 | push af ; | |
324 | ex de,hl ;'return address' in de | |
325 | ||
326 | if 0 | |
327 | if 0 ; link80 | |
328 | ||
329 | ld hl,0 | |
330 | add hl,sp ; | |
331 | ld a,h | |
332 | cp high (bs$stack-bs$stack$size) ;link80 can't process this | |
333 | jr nc,$ + 5 ;skip if stack allready in common bios ram | |
334 | ||
335 | else | |
336 | ||
337 | ld hl,bs$stack-bs$stack$size | |
338 | ld a,h | |
339 | dec a | |
340 | ld hl,0 | |
341 | add hl,sp ; | |
342 | cp h | |
343 | jr c,$ + 5 ;skip if stack allready in common bios ram | |
344 | endif | |
345 | ld sp,bs$stack ; | |
346 | else | |
347 | ld hl,0 | |
348 | add hl,sp | |
349 | ld sp,istack | |
350 | endif | |
351 | push hl ;save user stack pointer | |
352 | in0 h,(bbr) ; | |
353 | push hl ; | |
354 | xor a ; | |
355 | out0 (bbr),a ; | |
356 | ex de,hl ; | |
357 | ld e,(hl) ; | |
358 | inc hl ; | |
359 | ld d,(hl) ; | |
360 | ex de,hl ; | |
361 | push bc ; | |
1c7e3963 | 362 | call ijphl ; |
d6829fd3 L |
363 | |
364 | pop bc ; | |
365 | pop hl ; | |
366 | out0 (bbr),h ; | |
367 | pop hl ; | |
368 | ld sp,hl ; | |
369 | pop af ; | |
370 | pop de ; | |
371 | pop hl ; | |
372 | ei ; | |
373 | ret ; | |
d6829fd3 L |
374 | |
375 | ||
376 | ds 24 | |
377 | istack: | |
378 | ||
1c7e3963 L |
379 | dseg |
380 | ||
381 | ;-------------------------------------------------------------------- | |
382 | ; Load byte/word from user ram | |
383 | ; | |
384 | ; de: src address in users bank | |
385 | ; return | |
386 | ; a: value (byte) | |
387 | ; hl: value (word) | |
388 | ||
389 | b_ld_a: | |
390 | push hl | |
391 | or a ; clear carry == byte store | |
392 | jr $+3 | |
393 | b_ld_hl: | |
394 | scf ; set carry == word store | |
395 | push af ; save flag | |
396 | push hl ; make space on stack | |
397 | ||
398 | ld a,(@cbnk) | |
399 | ld b,a ; b = src bank | |
400 | ||
401 | ld hl,0 | |
402 | ld a,l | |
403 | ld c,l ; c = dst bank (0) | |
404 | add hl,sp ; hl = dst | |
405 | adc a,1 ; a = count | |
406 | ex de,hl | |
407 | call dma_move | |
408 | ex de,hl | |
409 | pop hl | |
410 | pop af | |
411 | ret c | |
412 | ld a,l | |
413 | pop hl | |
414 | ret | |
415 | ||
416 | ;-------------------------------------------------------------------- | |
417 | ; Store byte/word to user ram | |
418 | ; | |
419 | ; de: dst address in users bank | |
420 | ; a: value (byte) | |
421 | ; hl: value (word) | |
422 | ||
423 | b_st_a: | |
424 | push hl | |
425 | ld l,a | |
426 | or a ; clear carry == byte store | |
427 | jr $+3 | |
428 | b_st_hl: | |
429 | scf ; set carry == word store | |
430 | push af ; save flag | |
431 | push hl ; put value on stack | |
432 | ||
433 | ld a,(@cbnk) ; | |
434 | ld c,a ; c = dst bank | |
435 | ld a,0 | |
436 | ld l,a | |
437 | ld h,a | |
438 | ld b,a ; b = src bank (0) | |
439 | add hl,sp ; hl = src | |
440 | adc a,1 ; a = count | |
441 | ||
442 | call dma_move | |
443 | ||
444 | pop hl ; restore value | |
445 | pop af ; carry | |
446 | ret c | |
447 | pop hl | |
448 | ret | |
449 | ||
450 | ;-------------------------------------------------------------------- | |
451 | ; | |
452 | ; hl: src | |
453 | ; de: dst | |
454 | ; b: src bank | |
455 | ; c: dst bank | |
456 | ; a: count | |
457 | ||
458 | dma_move: | |
459 | out0 (bcr0l),a ; setup DMA count | |
460 | xor a | |
461 | out0 (bcr0h),a | |
462 | ||
463 | push hl | |
464 | ld a,b | |
465 | call bnk2phy | |
466 | out0 (sar0l),l ; setup DMA src address | |
467 | out0 (sar0h),h | |
468 | out0 (sar0b),a | |
469 | ||
470 | ld l,e | |
471 | ld h,d | |
472 | ld a,c | |
473 | call bnk2phy | |
474 | out0 (dar0l),l ; setup DMA dst address | |
475 | out0 (dar0h),h | |
476 | out0 (dar0b),a | |
477 | ||
478 | ld a,M_MMOD ; DMA burst mode | |
479 | out0 (dmode),a | |
480 | ld a,M_DE0+M_NDWE1 ; enable DMA0 | |
481 | out0 (dstat),a ; move ... | |
482 | pop hl | |
483 | ret | |
484 | ||
485 | ||
d6829fd3 L |
486 | ;==================================================================== |
487 | ||
1c7e3963 L |
488 | cseg |
489 | ||
d6829fd3 L |
490 | if 0 |
491 | ||
492 | ;-------------------------------------------------------------------- | |
493 | ; Return the BBR value for the given bank number | |
494 | ||
495 | bnk2bbr: | |
496 | or a ; 4 | |
497 | ret z ; 5/10 | 11 14 | |
498 | ||
499 | push bc ;11 | 11 | |
500 | ld b,a ; 4 | |
501 | ld c,CA ; 6 | |
502 | mlt bc ;17 >45 | |
503 | ld a,c ; 4 | |
504 | add a,10h ; 6 | |
505 | pop bc ; 9 | 10 | |
506 | ret ; 9 | 10 76 | |
507 | ||
508 | push ix ;2 / 14 | 15 | |
509 | ld ix,bnktbl ;4 / 12 | 14 | |
510 | ld ($+3+2),a ;3 / 15 | 19 | |
511 | ld a,(ix+0) ;3 / 14 | 19 | |
512 | pop ix ;2 / 12 | 14 | |
513 | ret ;1 / 9 | 10 15 / 76|91 | |
514 | ||
515 | push hl ;1 / 11 | 11 | |
516 | ld hl,bnktbl ;3 / 9 | 10 | |
517 | add a,l ;1 / 4 | 4 | |
518 | ld l,a ;1 / 4 | 4 | |
519 | ld a,0 ;1 / 6 | 7 | |
520 | adc a,h ;1 / 4 | 4 | |
521 | ld h,a ;1 / 4 | 4 | |
522 | ld a,(hl) ;1 / 6 | 7 | |
523 | pop hl ;1 / 9 | 10 | |
524 | ret ;1 / 9 | 10 12 / 66|71 | |
525 | ||
526 | push hl ;1 / 11 | 11 | |
527 | add a,low bnktbl ;2 / 6 | 7 | |
528 | ld l,a ;1 / 4 | 4 | |
529 | ld a,0 ;1 / 6 | 7 | |
530 | adc a,high bnktbl ;2 / 6 | 7 | |
531 | ld h,a ;1 / 4 | 4 | |
532 | ld a,(hl) ;1 / 6 | 7 | |
533 | pop hl ;1 / 9 | 10 | |
534 | ret ;1 / 9 | 10 11 / 61|67 | |
535 | ||
536 | endif | |
537 | ||
538 | ||
539 | end |