]>
Commit | Line | Data |
---|---|---|
64219415 | 1 | ; Various Management functions for the Interaction with the File-\r |
b741422e | 2 | ; systems\r |
64219415 | 3 | ;\r |
b741422e L |
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 | |
64219415 | 24 | \r |
eb85ce65 | 25 | ;-------------------------- Defines for the disk management Structures\r |
64219415 | 26 | \r |
b741422e | 27 | ;----------------------------------------------- Start of Data Segment\r |
64219415 | 28 | \r |
64219415 FZ |
29 | .dseg\r |
30 | \r | |
31 | \r | |
eb85ce65 L |
32 | ; Partition table offsets:\r |
33 | tmp_tbl:\r | |
34 | .byte PARTENTRY_SIZE*MAXDISKS\r | |
64219415 | 35 | \r |
b741422e | 36 | ; ------------------------------- Start of Code Segment\r |
64219415 FZ |
37 | .cseg\r |
38 | \r | |
39 | ; ====================================================================\r | |
b741422e | 40 | ; Function: Scans a Disk for CP/M Partions\r |
64219415 FZ |
41 | ; ====================================================================\r |
42 | ; Parameters\r | |
43 | ; --------------------------------------------------------------------\r | |
eb85ce65 L |
44 | ; \r |
45 | ; Registers : [w] temp Number of disk images (raw and fat16) found.\r | |
46 | ; + 0x80 if sd card changes. (not used, doesn't work)\r | |
47 | ; SREG : Z according to temp\r | |
64219415 FZ |
48 | ; --------------------------------------------------------------------\r |
49 | ; Description:\r | |
50 | ; This Function scans an SD-Cards Boot-Sector for valid Partitions.\r | |
51 | ; First all original CP/M Partitions will be usesed as Drives for\r | |
52 | ; the CPM-System. Wenn all CP/M Partitions are found, a second\r | |
53 | ; scann will be made. In the second Scan, the first FAT16 Partition\r | |
54 | ; on the Disk will be used for a detailed analyses. If there\r | |
55 | ; are any Files like "cpm_x.img" are found, these Files will be\r | |
56 | ; used as Disks by the CP/M- System. ( x must be in the Range A to D )\r | |
b741422e | 57 | ; ==================================================================== \r |
64219415 FZ |
58 | mgr_init_partitions:\r |
59 | \r | |
60 | sts ndisks,_0 ; Set Number of Disks to 0\r | |
61 | \r | |
62 | ; Initialize temp partition table\r | |
b741422e L |
63 | ldiw y,tmp_tbl\r |
64 | ldi temp2,PARTENTRY_SIZE*MAXDISKS\r | |
65 | mgr_picl:\r | |
66 | st y+,_0\r | |
67 | dec temp2\r | |
64219415 FZ |
68 | brne mgr_picl\r |
69 | \r | |
b741422e | 70 | ; Start mmc Card interaction\r |
a5b2e36e | 71 | lcall mmcInit\r |
b741422e L |
72 | andi temp,MMCST_NOINIT & MMCST_NODISK\r |
73 | brne mgr_pierr\r | |
74 | \r | |
75 | ;Load first sector from MMC (boot sector)\r | |
76 | ldiw y,0 ; Sector 0\r | |
77 | movw x,y\r | |
78 | lcall mmcReadSect\r | |
79 | tst temp\r | |
80 | breq mgr_check_bootsektor\r | |
81 | \r | |
82 | mgr_pierr:\r | |
83 | clr temp\r | |
64219415 FZ |
84 | ret\r |
85 | \r | |
86 | mgr_check_bootsektor:\r | |
87 | ;Pointer to first temp table entry\r | |
b741422e L |
88 | ldiw y,tmp_tbl\r |
89 | ;Test, if it has a valid MBR\r | |
90 | \r | |
91 | ldiw z,hostbuf+510-1 ;Point to last byte of partition table\r | |
92 | \r | |
93 | ldi temp3,0 ;temp3 holds number of found disks (paritions)\r | |
94 | ldd temp,z+1 ;MBR signature (0xAA55) at and of sector?\r | |
95 | ldd temp2,z+2\r | |
96 | ldi temp4,0xAA\r | |
97 | cpi temp,0x55 \r | |
98 | cpc temp2,temp4\r | |
99 | breq mgr_search\r | |
100 | \r | |
101 | ;No MBR, no partition table ...\r | |
102 | inc temp3 ;pretend we have one.\r | |
64219415 FZ |
103 | ldi temp,high((1<<16) * 128/512)\r |
104 | ldi temp2,dskType_CPM\r | |
b741422e L |
105 | std y+0,temp2\r |
106 | std y+1,_0 ;start at beginning of card\r | |
107 | std y+2,_0\r | |
108 | std y+3,_0\r | |
109 | std y+4,_0\r | |
110 | std y+5,_0 ;max CP/M 2.2 disk size\r | |
111 | std y+6,temp ;\r | |
112 | std y+7,_0\r | |
113 | std y+8,_0\r | |
64219415 FZ |
114 | rjmp mgr_pend\r |
115 | \r | |
116 | ; Search for valid Partitions and ImageFiles \r | |
117 | mgr_search:\r | |
b741422e L |
118 | sbiw z,63 ;Now at first byte of partition table\r |
119 | ldi temp4,high(hostbuf+510)\r | |
64219415 | 120 | \r |
b741422e | 121 | mgr_ploop:\r |
64219415 FZ |
122 | \r |
123 | ; Get Partitiontype\r | |
b741422e | 124 | ldd temp,z+PART_TYPE\r |
64219415 FZ |
125 | \r |
126 | ; Test for CP/M Partition\r | |
b741422e L |
127 | cpi temp,PARTID_CPM\r |
128 | brne mgr_nextp\r | |
129 | \r | |
130 | rcall cpm_add_partition\r | |
64219415 | 131 | \r |
b741422e L |
132 | inc temp3\r |
133 | cpi temp3,MAXDISKS\r | |
64219415 | 134 | breq mgr_pend\r |
b741422e L |
135 | \r |
136 | mgr_nextp:\r | |
137 | adiw zl,16\r | |
138 | cpi zl,low(hostbuf+510)\r | |
139 | cpc zh,temp4\r | |
64219415 FZ |
140 | brlo mgr_ploop\r |
141 | \r | |
b741422e L |
142 | #if FAT16_SUPPORT\r |
143 | \r | |
64219415 | 144 | ; Test for FAT16 Partition\r |
b741422e L |
145 | ldiw z,hostbuf+510-1-63 ;Point to first byte of partition table\r |
146 | ldi temp4,high(hostbuf+510)\r | |
64219415 | 147 | \r |
b741422e | 148 | mgr_ploop2:\r |
64219415 FZ |
149 | \r |
150 | ; Get Partitiontype\r | |
b741422e | 151 | ldd temp,z+PART_TYPE\r |
64219415 FZ |
152 | \r |
153 | ; Test for FAT Partition\r | |
b741422e L |
154 | cpi temp,PARTID_FAT16\r |
155 | brne mgr_nextp2\r | |
156 | \r | |
157 | rcall fat_add_partition\r | |
158 | \r | |
64219415 | 159 | rjmp mgr_pend\r |
b741422e L |
160 | \r |
161 | mgr_nextp2:\r | |
162 | adiw zl,16\r | |
163 | cpi zl,low(hostbuf+510)\r | |
164 | cpc zh,temp4\r | |
64219415 | 165 | brlo mgr_ploop2\r |
b741422e | 166 | #endif\r |
64219415 FZ |
167 | \r |
168 | mgr_pend:\r | |
169 | \r | |
eb85ce65 | 170 | #if 0 /* ToDo: ramdisks are not in sd-card partitions */\r |
64219415 FZ |
171 | ; Initialize RAM-Disks\r |
172 | rcall rdsk_add_partition\r | |
eb85ce65 L |
173 | #endif\r |
174 | \r | |
175 | /*\r | |
176 | Don't use change info. It doesn't word reliably with partitions, \r | |
177 | and it doesn't work at all with fat images:\r | |
178 | */\r | |
179 | #define CHANGEINFO 0\r | |
64219415 | 180 | \r |
b741422e L |
181 | ;Store new partitions and check if the SD card has been changed.\r |
182 | \r | |
183 | ldiw y,tmp_tbl\r | |
184 | ldiw z,hostparttbl\r | |
185 | ldi temp4,PARTENTRY_SIZE*MAXDISKS\r | |
64219415 | 186 | clt\r |
64219415 | 187 | \r |
b741422e L |
188 | mgr_pcpl:\r |
189 | ld temp,y+\r | |
190 | ld temp2,z\r | |
191 | st z+,temp\r | |
192 | cpse temp,temp2\r | |
193 | set\r | |
194 | dec temp4\r | |
195 | brne mgr_pcpl\r | |
196 | \r | |
197 | mov temp,temp3\r | |
198 | sts ndisks,temp\r | |
eb85ce65 | 199 | #if CHANGEINFO\r |
b741422e L |
200 | brtc mgr_pcpe\r |
201 | \r | |
eb85ce65 L |
202 | ; SD card changed.\r |
203 | #endif\r | |
b741422e L |
204 | tst temp\r |
205 | breq mgr_pcpe\r | |
206 | \r | |
b741422e L |
207 | \r |
208 | #if FAT16_SUPPORT\r | |
209 | rcall fat_scan_partition\r | |
b2017655 | 210 | rcall fat_reset_cache |
b741422e | 211 | #endif\r |
64219415 | 212 | lds temp,ndisks\r |
eb85ce65 | 213 | #if CHANGEINFO\r |
b741422e | 214 | sbr temp,0x80\r |
eb85ce65 | 215 | #endif\r |
b741422e | 216 | \r |
64219415 | 217 | mgr_pcpe:\r |
b741422e | 218 | \r |
eb85ce65 | 219 | tst temp\r |
64219415 FZ |
220 | ret\r |
221 | \r | |
222 | \r | |
223 | ; ====================================================================\r | |
b741422e | 224 | ; Function: Print partition table info\r |
64219415 FZ |
225 | ; ====================================================================\r |
226 | ; Parameters\r | |
227 | ; --------------------------------------------------------------------\r | |
228 | ; Registers : none\r | |
229 | ; Variables : [r] hostparttbl Table with Partitioninformations\r | |
230 | ; [r] hostparttbltop Pointer to the Top of the Table\r | |
231 | ; --------------------------------------------------------------------\r | |
232 | ; Description:\r | |
233 | ; ====================================================================\r | |
64219415 | 234 | \r |
b741422e L |
235 | mgr_prnt_parttbl:\r |
236 | ldiw z,hostparttbl\r | |
b2017655 FZ |
237 | lds yl,ndisks\r |
238 | ldi xh,'A'\r | |
b741422e | 239 | \r |
b2017655 FZ |
240 | pprl: |
241 | ldd temp ,z+1 ;Get partition start | |
242 | ldd temp2,z+2 | |
243 | ldd temp3,z+3 | |
244 | ldd temp4,z+4 | |
b741422e L |
245 | \r |
246 | printnewline\r | |
247 | \r | |
b2017655 FZ |
248 | cp temp,_0 ;If zero ... |
249 | cpc temp2,_0 | |
250 | cpc temp3,_0 | |
251 | cpc temp4,_0 | |
252 | breq mgr_prnop ;... no partition table at 0 | |
253 | \r | |
254 | ; Partitiontype examining\r | |
255 | ldd xl,z+0\r | |
64219415 FZ |
256 | ; CP/M ?\r |
257 | cpi xl,dskType_CPM\r | |
258 | brne mgr_prtb_nocpm\r | |
b2017655 | 259 | rcall mgr_prnt_diskname\r |
b741422e | 260 | rcall mgr_prnt_table_cpm\r |
64219415 FZ |
261 | rjmp mgr_prnt_size\r |
262 | \r | |
263 | ; FAT16 ?\r | |
b741422e | 264 | mgr_prtb_nocpm:\r |
64219415 FZ |
265 | cpi xl,dskType_FAT\r |
266 | brne mgr_prtb_nofat\r | |
b2017655 | 267 | rcall mgr_prnt_diskname\r |
b741422e L |
268 | rcall mgr_prnt_table_fat\r |
269 | rjmp mgr_prnt_size\r | |
64219415 FZ |
270 | ; RAMDISK ?\r |
271 | mgr_prtb_nofat:\r | |
272 | cpi xl,dskType_RAM\r | |
273 | brne mgr_prnt_err\r | |
b2017655 | 274 | rcall mgr_prnt_diskname\r |
b741422e | 275 | rcall mgr_prnt_table_ram\r |
64219415 FZ |
276 | rjmp mgr_prnt_size\r |
277 | ; Entry Error\r | |
278 | mgr_prnt_err: \r | |
b741422e | 279 | rcall mgr_prnt_table_err\r |
64219415 FZ |
280 | rjmp mgr_prnt_size\r |
281 | \r | |
b741422e | 282 | mgr_prnop:\r |
b2017655 | 283 | rcall mgr_prnt_diskname\r |
b741422e | 284 | rcall mgr_prnt_image\r |
64219415 FZ |
285 | \r |
286 | mgr_prnt_size:\r | |
b2017655 | 287 | call print_ultoa |
b741422e L |
288 | printstring ", size: "\r |
289 | \r | |
290 | ldd temp ,z+5 ;Get partition size\r | |
291 | ldd temp2,z+6 ;Get partition size\r | |
292 | ldd temp3,z+7 ;Get partition size\r | |
293 | ldd temp4,z+8 ;Get partition size\r | |
294 | \r | |
295 | lsr temp4\r | |
296 | ror temp3\r | |
297 | ror temp2\r | |
298 | ror temp\r | |
b2017655 | 299 | call print_ultoa |
64219415 | 300 | printstring "KB."\r |
b741422e L |
301 | \r |
302 | mgr_goto_next_part: \r | |
303 | adiw z,PARTENTRY_SIZE\r | |
b2017655 FZ |
304 | inc xh |
305 | dec yl\r | |
306 | tst yl\r | |
307 | brne pprl | |
b741422e L |
308 | \r |
309 | mgr_pppre:\r | |
310 | ret\r | |
64219415 FZ |
311 | \r |
312 | \r | |
b741422e L |
313 | mgr_prnt_fatsize:\r |
314 | lcall print_ultoa\r | |
315 | printstring ", size: "\r | |
64219415 | 316 | \r |
b741422e L |
317 | ldd temp ,z+5 ;Get partition size\r |
318 | ldd temp2,z+6 ;Get partition size\r | |
319 | ldd temp3,z+7 ;Get partition size\r | |
320 | ldd temp4,z+8 ;Get partition size\r | |
321 | \r | |
322 | lcall print_ultoa\r | |
323 | printstring "BYTE."\r | |
324 | \r | |
325 | rjmp mgr_goto_next_part\r | |
326 | \r | |
b2017655 FZ |
327 | mgr_prnt_diskname:\r |
328 | push temp\r | |
329 | mov temp,xh | |
330 | call uartputc\r | |
331 | ldi temp,':' | |
332 | call uartputc\r | |
333 | pop temp\r | |
334 | ret\r | |
335 | \r | |
b741422e L |
336 | mgr_prnt_table_cpm:\r |
337 | printstring "CP/M partition at: "\r | |
64219415 FZ |
338 | ret\r |
339 | \r | |
b741422e L |
340 | mgr_prnt_table_fat:\r |
341 | printstring "FAT16 File-Image at: "\r | |
64219415 FZ |
342 | ret\r |
343 | \r | |
b741422e L |
344 | mgr_prnt_table_ram:\r |
345 | printstring "Ramdisk at: "\r | |
64219415 FZ |
346 | ret\r |
347 | \r | |
b741422e L |
348 | mgr_prnt_table_err:\r |
349 | printstring "Unknown Entry at: "\r | |
64219415 | 350 | ret\r |
b741422e L |
351 | \r |
352 | mgr_prnt_image:\r | |
353 | printstring "Assuming CP/M image at: "\r | |
64219415 | 354 | ret\r |
b741422e | 355 | \r |
64219415 | 356 | \r |