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