]> cloudbase.mooo.com Git - z180-stamp-cpm3.git/blob - cbios/mm.180
baudrate configurable
[z180-stamp-cpm3.git] / cbios / mm.180
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
142 if 0
143
144 ;--------------------------------------------------------------------
145 ; Return the BBR value for the given bank number
146
147 bnk2bbr:
148 or a ; 4
149 ret z ; 5/10 | 11 14
150
151 push bc ;11 | 11
152 ld b,a ; 4
153 ld c,CA ; 6
154 mlt bc ;17 >45
155 ld a,c ; 4
156 add a,10h ; 6
157 pop bc ; 9 | 10
158 ret ; 9 | 10 76
159
160 push ix ;2 / 14 | 15
161 ld ix,bnktbl ;4 / 12 | 14
162 ld ($+3+2),a ;3 / 15 | 19
163 ld a,(ix+0) ;3 / 14 | 19
164 pop ix ;2 / 12 | 14
165 ret ;1 / 9 | 10 15 / 76|91
166
167 push hl ;1 / 11 | 11
168 ld hl,bnktbl ;3 / 9 | 10
169 add a,l ;1 / 4 | 4
170 ld l,a ;1 / 4 | 4
171 ld a,0 ;1 / 6 | 7
172 adc a,h ;1 / 4 | 4
173 ld h,a ;1 / 4 | 4
174 ld a,(hl) ;1 / 6 | 7
175 pop hl ;1 / 9 | 10
176 ret ;1 / 9 | 10 12 / 66|71
177
178 push hl ;1 / 11 | 11
179 add a,low bnktbl ;2 / 6 | 7
180 ld l,a ;1 / 4 | 4
181 ld a,0 ;1 / 6 | 7
182 adc a,high bnktbl ;2 / 6 | 7
183 ld h,a ;1 / 4 | 4
184 ld a,(hl) ;1 / 6 | 7
185 pop hl ;1 / 9 | 10
186 ret ;1 / 9 | 10 11 / 61|67
187
188 endif
189
190
191 end