]>
Commit | Line | Data |
---|---|---|
1 | ; Various Management functions for the Interaction with the File-\r | |
2 | ; systems\r | |
3 | ;\r | |
4 | ; Copyright (C) 2010 Frank Zoll\r | |
5 | ;\r | |
6 | ; This file is part of avrcpm.\r | |
7 | ;\r | |
8 | ; avrcpm is free software: you can redistribute it and/or modify it\r | |
9 | ; under the terms of the GNU General Public License as published by\r | |
10 | ; the Free Software Foundation, either version 3 of the License, or\r | |
11 | ; (at your option) any later version.\r | |
12 | ;\r | |
13 | ; avrcpm is distributed in the hope that it will be useful,\r | |
14 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of\r | |
15 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r | |
16 | ; GNU General Public License for more details.\r | |
17 | ;\r | |
18 | ; You should have received a copy of the GNU General Public License\r | |
19 | ; along with avrcpm. If not, see <http://www.gnu.org/licenses/>.\r | |
20 | ;\r | |
21 | ; $Id$\r | |
22 | ;\r | |
23 | \r | |
24 | \r | |
25 | ; ------------------------- Defines for the disk management Structures\r | |
26 | \r | |
27 | ;----------------------------------------------- Start of Data Segment\r | |
28 | \r | |
29 | .dseg\r | |
30 | \r | |
31 | \r | |
32 | \r | |
33 | ; ------------------------------- Start of Code Segment\r | |
34 | .cseg\r | |
35 | \r | |
36 | ; ====================================================================\r | |
37 | ; Function: Scans a Disk for CP/M Partions\r | |
38 | ; ====================================================================\r | |
39 | ; Parameters\r | |
40 | ; --------------------------------------------------------------------\r | |
41 | ; Registers : none\r | |
42 | ; Variables : [w] temp Status of Operation\r | |
43 | ; (0x80 - Operation Failure )\r | |
44 | ; (others - Operation Suceded)\r | |
45 | ; --------------------------------------------------------------------\r | |
46 | ; Description:\r | |
47 | ; This Function scans an SD-Cards Boot-Sector for valid Partitions.\r | |
48 | ; First all original CP/M Partitions will be usesed as Drives for\r | |
49 | ; the CPM-System. Wenn all CP/M Partitions are found, a second\r | |
50 | ; scann will be made. In the second Scan, the first FAT16 Partition\r | |
51 | ; on the Disk will be used for a detailed analyses. If there\r | |
52 | ; are any Files like "cpm_x.img" are found, these Files will be\r | |
53 | ; used as Disks by the CP/M- System. ( x must be in the Range A to D )\r | |
54 | ; ==================================================================== \r | |
55 | mgr_init_partitions:\r | |
56 | \r | |
57 | sts ndisks,_0 ; Set Number of Disks to 0\r | |
58 | \r | |
59 | ; Initialize temp partition table\r | |
60 | ldiw y,tmp_tbl\r | |
61 | ldi temp2,PARTENTRY_SIZE*MAXDISKS\r | |
62 | mgr_picl:\r | |
63 | st y+,_0\r | |
64 | dec temp2\r | |
65 | brne mgr_picl\r | |
66 | \r | |
67 | ; Start mmc Card interaction\r | |
68 | rcall mmcInit\r | |
69 | andi temp,MMCST_NOINIT & MMCST_NODISK\r | |
70 | brne mgr_pierr\r | |
71 | \r | |
72 | ;Load first sector from MMC (boot sector)\r | |
73 | ldiw y,0 ; Sector 0\r | |
74 | movw x,y\r | |
75 | lcall mmcReadSect\r | |
76 | tst temp\r | |
77 | breq mgr_check_bootsektor\r | |
78 | \r | |
79 | mgr_pierr:\r | |
80 | clr temp\r | |
81 | ret\r | |
82 | \r | |
83 | mgr_check_bootsektor:\r | |
84 | ;Pointer to first temp table entry\r | |
85 | ldiw y,tmp_tbl\r | |
86 | ;Test, if it has a valid MBR\r | |
87 | \r | |
88 | ldiw z,hostbuf+510-1 ;Point to last byte of partition table\r | |
89 | \r | |
90 | ldi temp3,0 ;temp3 holds number of found disks (paritions)\r | |
91 | ldd temp,z+1 ;MBR signature (0xAA55) at and of sector?\r | |
92 | ldd temp2,z+2\r | |
93 | ldi temp4,0xAA\r | |
94 | cpi temp,0x55 \r | |
95 | cpc temp2,temp4\r | |
96 | breq mgr_search\r | |
97 | \r | |
98 | ;No MBR, no partition table ...\r | |
99 | inc temp3 ;pretend we have one.\r | |
100 | ldi temp,high((1<<16) * 128/512)\r | |
101 | ldi temp2,dskType_CPM\r | |
102 | std y+0,temp2\r | |
103 | std y+1,_0 ;start at beginning of card\r | |
104 | std y+2,_0\r | |
105 | std y+3,_0\r | |
106 | std y+4,_0\r | |
107 | std y+5,_0 ;max CP/M 2.2 disk size\r | |
108 | std y+6,temp ;\r | |
109 | std y+7,_0\r | |
110 | std y+8,_0\r | |
111 | rjmp mgr_pend\r | |
112 | \r | |
113 | ; Search for valid Partitions and ImageFiles \r | |
114 | mgr_search:\r | |
115 | sbiw z,63 ;Now at first byte of partition table\r | |
116 | ldi temp4,high(hostbuf+510)\r | |
117 | \r | |
118 | mgr_ploop:\r | |
119 | \r | |
120 | ; Get Partitiontype\r | |
121 | ldd temp,z+PART_TYPE\r | |
122 | \r | |
123 | ; Test for CP/M Partition\r | |
124 | cpi temp,PARTID_CPM\r | |
125 | brne mgr_nextp\r | |
126 | \r | |
127 | rcall cpm_add_partition\r | |
128 | \r | |
129 | inc temp3\r | |
130 | cpi temp3,MAXDISKS\r | |
131 | breq mgr_pend\r | |
132 | \r | |
133 | mgr_nextp:\r | |
134 | adiw zl,16\r | |
135 | cpi zl,low(hostbuf+510)\r | |
136 | cpc zh,temp4\r | |
137 | brlo mgr_ploop\r | |
138 | \r | |
139 | #if FAT16_SUPPORT\r | |
140 | \r | |
141 | ; Test for FAT16 Partition\r | |
142 | ldiw z,hostbuf+510-1-63 ;Point to first byte of partition table\r | |
143 | ldi temp4,high(hostbuf+510)\r | |
144 | \r | |
145 | mgr_ploop2:\r | |
146 | \r | |
147 | ; Get Partitiontype\r | |
148 | ldd temp,z+PART_TYPE\r | |
149 | \r | |
150 | ; Test for FAT Partition\r | |
151 | cpi temp,PARTID_FAT16\r | |
152 | brne mgr_nextp2\r | |
153 | \r | |
154 | rcall fat_add_partition\r | |
155 | \r | |
156 | rjmp mgr_pend\r | |
157 | \r | |
158 | mgr_nextp2:\r | |
159 | adiw zl,16\r | |
160 | cpi zl,low(hostbuf+510)\r | |
161 | cpc zh,temp4\r | |
162 | brlo mgr_ploop2\r | |
163 | #endif\r | |
164 | \r | |
165 | mgr_pend:\r | |
166 | \r | |
167 | ; Initialize RAM-Disks\r | |
168 | rcall rdsk_add_partition\r | |
169 | \r | |
170 | ;Store new partitions and check if the SD card has been changed.\r | |
171 | \r | |
172 | ldiw y,tmp_tbl\r | |
173 | ldiw z,hostparttbl\r | |
174 | ldi temp4,PARTENTRY_SIZE*MAXDISKS\r | |
175 | clt\r | |
176 | \r | |
177 | mgr_pcpl:\r | |
178 | ld temp,y+\r | |
179 | ld temp2,z\r | |
180 | st z+,temp\r | |
181 | cpse temp,temp2\r | |
182 | set\r | |
183 | dec temp4\r | |
184 | brne mgr_pcpl\r | |
185 | \r | |
186 | mov temp,temp3\r | |
187 | sts ndisks,temp\r | |
188 | brtc mgr_pcpe\r | |
189 | \r | |
190 | tst temp\r | |
191 | breq mgr_pcpe\r | |
192 | \r | |
193 | ; SD card not changed.\r | |
194 | \r | |
195 | #if FAT16_SUPPORT\r | |
196 | rcall fat_scan_partition\r | |
197 | #endif\r | |
198 | lds temp,ndisks\r | |
199 | sbr temp,0x80\r | |
200 | \r | |
201 | mgr_pcpe:\r | |
202 | \r | |
203 | ret\r | |
204 | \r | |
205 | \r | |
206 | ; ====================================================================\r | |
207 | ; Function: Print partition table info\r | |
208 | ; ====================================================================\r | |
209 | ; Parameters\r | |
210 | ; --------------------------------------------------------------------\r | |
211 | ; Registers : none\r | |
212 | ; Variables : [r] hostparttbl Table with Partitioninformations\r | |
213 | ; [r] hostparttbltop Pointer to the Top of the Table\r | |
214 | ; --------------------------------------------------------------------\r | |
215 | ; Description:\r | |
216 | ; ====================================================================\r | |
217 | \r | |
218 | mgr_prnt_parttbl:\r | |
219 | ldiw z,hostparttbl\r | |
220 | pprl:\r | |
221 | ; Partitiontype examining\r | |
222 | \r | |
223 | ldd xl,z+0\r | |
224 | ; Empty slot?\r | |
225 | cpi xl,dskType_None\r | |
226 | breq mgr_goto_next_part\r | |
227 | \r | |
228 | printnewline\r | |
229 | \r | |
230 | ; CP/M ?\r | |
231 | cpi xl,dskType_CPM\r | |
232 | brne mgr_prtb_nocpm\r | |
233 | rcall mgr_prnt_table_cpm\r | |
234 | rjmp mgr_prnt_size\r | |
235 | \r | |
236 | ; FAT16 ?\r | |
237 | mgr_prtb_nocpm:\r | |
238 | cpi xl,dskType_FAT\r | |
239 | brne mgr_prtb_nofat\r | |
240 | rcall mgr_prnt_table_fat\r | |
241 | rjmp mgr_prnt_size\r | |
242 | ; RAMDISK ?\r | |
243 | mgr_prtb_nofat:\r | |
244 | cpi xl,dskType_RAM\r | |
245 | brne mgr_prnt_err\r | |
246 | rcall mgr_prnt_table_ram\r | |
247 | rjmp mgr_prnt_size\r | |
248 | ; Entry Error\r | |
249 | mgr_prnt_err: \r | |
250 | rcall mgr_prnt_table_err\r | |
251 | rjmp mgr_prnt_size\r | |
252 | \r | |
253 | mgr_prnop:\r | |
254 | rcall mgr_prnt_image\r | |
255 | \r | |
256 | mgr_prnt_size:\r | |
257 | ldd temp ,z+1 ;Get partition start\r | |
258 | ldd temp2,z+2\r | |
259 | ldd temp3,z+3\r | |
260 | ldd temp4,z+4\r | |
261 | lcall print_ultoa\r | |
262 | printstring ", size: "\r | |
263 | \r | |
264 | ldd temp ,z+5 ;Get partition size\r | |
265 | ldd temp2,z+6 ;Get partition size\r | |
266 | ldd temp3,z+7 ;Get partition size\r | |
267 | ldd temp4,z+8 ;Get partition size\r | |
268 | \r | |
269 | lsr temp4\r | |
270 | ror temp3\r | |
271 | ror temp2\r | |
272 | ror temp\r | |
273 | lcall print_ultoa\r | |
274 | printstring "KB."\r | |
275 | \r | |
276 | mgr_goto_next_part: \r | |
277 | adiw z,PARTENTRY_SIZE\r | |
278 | ldi temp,high(hostparttbltop)\r | |
279 | cpi zl, low (hostparttbltop)\r | |
280 | cpc zh,temp\r | |
281 | brlo pprl\r | |
282 | \r | |
283 | mgr_pppre:\r | |
284 | ret\r | |
285 | \r | |
286 | \r | |
287 | mgr_prnt_fatsize:\r | |
288 | lcall print_ultoa\r | |
289 | printstring ", size: "\r | |
290 | \r | |
291 | ldd temp ,z+5 ;Get partition size\r | |
292 | ldd temp2,z+6 ;Get partition size\r | |
293 | ldd temp3,z+7 ;Get partition size\r | |
294 | ldd temp4,z+8 ;Get partition size\r | |
295 | \r | |
296 | lcall print_ultoa\r | |
297 | printstring "BYTE."\r | |
298 | \r | |
299 | rjmp mgr_goto_next_part\r | |
300 | \r | |
301 | mgr_prnt_table_cpm:\r | |
302 | printstring "CP/M partition at: "\r | |
303 | ret\r | |
304 | \r | |
305 | mgr_prnt_table_fat:\r | |
306 | printstring "FAT16 File-Image at: "\r | |
307 | ret\r | |
308 | \r | |
309 | mgr_prnt_table_ram:\r | |
310 | printstring "Ramdisk at: "\r | |
311 | ret\r | |
312 | \r | |
313 | mgr_prnt_table_err:\r | |
314 | printstring "Unknown Entry at: "\r | |
315 | ret\r | |
316 | \r | |
317 | mgr_prnt_image:\r | |
318 | printstring "Assuming CP/M image at: "\r | |
319 | ret\r | |
320 | \r | |
321 | \r |