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