]>
Commit | Line | Data |
---|---|---|
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: | |
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 | ||
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 | ||
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: | |
151 | ||
152 | ld (b0_save_hl),hl | |
153 | ld (b0_save_de),de | |
154 | push af | |
155 | pop hl | |
156 | ld (b0_save_af),hl | |
157 | ||
158 | pop de ;get ptr to 'function address' in de | |
159 | ld hl,2 | |
160 | add hl,de | |
161 | push hl ;put return address on stack | |
162 | ||
163 | if 0 ; link80 | |
164 | ||
165 | ld hl,0 | |
166 | add hl,sp ; | |
167 | ld a,h | |
168 | cp high (bs$stack-bs$stack$size) ;link80 can't process this | |
169 | jr nc,$ + 5 ;skip if stack allready in common bios ram | |
170 | ||
171 | else | |
172 | ||
173 | ld hl,bs$stack-bs$stack$size | |
174 | ld a,h | |
175 | dec a | |
176 | ld hl,0 | |
177 | add hl,sp ; | |
178 | cp h | |
179 | jr c,$ + 5 ;skip if stack allready in common bios ram | |
180 | endif | |
181 | ld sp,bs$stack ; | |
182 | ||
183 | push hl ;save user stack pointer | |
184 | in0 h,(cbar) ; | |
185 | push hl ; | |
186 | ld hl,b0c_ret | |
187 | push hl | |
188 | ld a,SYS$CBAR ; | |
189 | out0 (cbar),a ; | |
190 | ex de,hl ;ptr | |
191 | ld e,(hl) ;get 'function address' | |
192 | inc hl ; | |
193 | ld d,(hl) ; | |
194 | push de ;put on (switched) stack | |
195 | ||
196 | ld hl,(b0_save_af) ;get back users registers | |
197 | push hl | |
198 | pop af | |
199 | ld de,(b0_save_de) | |
200 | ld hl,(b0_save_hl) | |
201 | ret ;go to function | |
202 | b0c_ret: | |
203 | ld (b0_save_hl),hl | |
204 | ||
205 | pop hl ; | |
206 | out0 (cbar),h ; | |
207 | pop hl ; | |
208 | ld sp,hl ; | |
209 | ld hl,(b0_save_hl) | |
210 | ret ; | |
211 | ||
212 | ||
213 | b0_save_hl: dw 0 | |
214 | b0_save_de: dw 0 | |
215 | b0_save_af: dw 0 | |
216 | ||
217 | ||
218 | ||
219 | ;==================================================================== | |
220 | ||
221 | if 0 | |
222 | ||
223 | ;-------------------------------------------------------------------- | |
224 | ; Return the BBR value for the given bank number | |
225 | ||
226 | bnk2bbr: | |
227 | or a ; 4 | |
228 | ret z ; 5/10 | 11 14 | |
229 | ||
230 | push bc ;11 | 11 | |
231 | ld b,a ; 4 | |
232 | ld c,CA ; 6 | |
233 | mlt bc ;17 >45 | |
234 | ld a,c ; 4 | |
235 | add a,10h ; 6 | |
236 | pop bc ; 9 | 10 | |
237 | ret ; 9 | 10 76 | |
238 | ||
239 | push ix ;2 / 14 | 15 | |
240 | ld ix,bnktbl ;4 / 12 | 14 | |
241 | ld ($+3+2),a ;3 / 15 | 19 | |
242 | ld a,(ix+0) ;3 / 14 | 19 | |
243 | pop ix ;2 / 12 | 14 | |
244 | ret ;1 / 9 | 10 15 / 76|91 | |
245 | ||
246 | push hl ;1 / 11 | 11 | |
247 | ld hl,bnktbl ;3 / 9 | 10 | |
248 | add a,l ;1 / 4 | 4 | |
249 | ld l,a ;1 / 4 | 4 | |
250 | ld a,0 ;1 / 6 | 7 | |
251 | adc a,h ;1 / 4 | 4 | |
252 | ld h,a ;1 / 4 | 4 | |
253 | ld a,(hl) ;1 / 6 | 7 | |
254 | pop hl ;1 / 9 | 10 | |
255 | ret ;1 / 9 | 10 12 / 66|71 | |
256 | ||
257 | push hl ;1 / 11 | 11 | |
258 | add a,low bnktbl ;2 / 6 | 7 | |
259 | ld l,a ;1 / 4 | 4 | |
260 | ld a,0 ;1 / 6 | 7 | |
261 | adc a,high bnktbl ;2 / 6 | 7 | |
262 | ld h,a ;1 / 4 | 4 | |
263 | ld a,(hl) ;1 / 6 | 7 | |
264 | pop hl ;1 / 9 | 10 | |
265 | ret ;1 / 9 | 10 11 / 61|67 | |
266 | ||
267 | endif | |
268 | ||
269 | ||
270 | end |