]>
Commit | Line | Data |
---|---|---|
1 | ; Various Management functions for the Interaction with the File-\r | |
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 | ;\r | |
23 | \r | |
24 | \r | |
25 | ; ------------------------- Defines for the disk management Structures | |
26 | \r | |
27 | ;----------------------------------------------- Start of Data Segment | |
28 | ||
29 | .dseg\r | |
30 | \r | |
31 | \r | |
32 | \r | |
33 | ; ------------------------------- Start of Code Segment | |
34 | .cseg\r | |
35 | \r | |
36 | ; ====================================================================\r | |
37 | ; Function: Scans a Disk for CP/M Partions | |
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 | ; ==================================================================== | |
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 | |
61 | ldi temp2,PARTENTRY_SIZE*MAXDISKS | |
62 | mgr_picl: | |
63 | st y+,_0 | |
64 | dec temp2 | |
65 | brne mgr_picl\r | |
66 | \r | |
67 | ; Start mmc Card interaction | |
68 | call mmcInit | |
69 | andi temp,MMCST_NOINIT & MMCST_NODISK | |
70 | brne mgr_pierr | |
71 | ||
72 | ;Load first sector from MMC (boot sector) | |
73 | ldiw y,0 ; Sector 0 | |
74 | movw x,y | |
75 | call mmcReadSect | |
76 | tst temp | |
77 | breq mgr_check_bootsektor | |
78 | ||
79 | mgr_pierr: | |
80 | clr temp | |
81 | ret\r | |
82 | \r | |
83 | mgr_check_bootsektor:\r | |
84 | ;Pointer to first temp table entry\r | |
85 | ldiw y,tmp_tbl | |
86 | ;Test, if it has a valid MBR | |
87 | ||
88 | ldiw z,hostbuf+510-1 ;Point to last byte of partition table | |
89 | ||
90 | ldi temp3,0 ;temp3 holds number of found disks (paritions) | |
91 | ldd temp,z+1 ;MBR signature (0xAA55) at and of sector? | |
92 | ldd temp2,z+2 | |
93 | ldi temp4,0xAA | |
94 | cpi temp,0x55 | |
95 | cpc temp2,temp4 | |
96 | breq mgr_search | |
97 | ||
98 | ;No MBR, no partition table ... | |
99 | inc temp3 ;pretend we have one. | |
100 | ldi temp,high((1<<16) * 128/512)\r | |
101 | ldi temp2,dskType_CPM\r | |
102 | std y+0,temp2 | |
103 | std y+1,_0 ;start at beginning of card | |
104 | std y+2,_0 | |
105 | std y+3,_0 | |
106 | std y+4,_0 | |
107 | std y+5,_0 ;max CP/M 2.2 disk size | |
108 | std y+6,temp ; | |
109 | std y+7,_0 | |
110 | std y+8,_0 | |
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 | |
116 | ldi temp4,high(hostbuf+510) | |
117 | \r | |
118 | mgr_ploop: | |
119 | \r | |
120 | ; Get Partitiontype\r | |
121 | ldd temp,z+PART_TYPE | |
122 | \r | |
123 | ; Test for CP/M Partition\r | |
124 | cpi temp,PARTID_CPM | |
125 | brne mgr_nextp | |
126 | ||
127 | rcall cpm_add_partition | |
128 | \r | |
129 | inc temp3 | |
130 | cpi temp3,MAXDISKS | |
131 | breq mgr_pend\r | |
132 | rjmp mgr_nextp\r | |
133 | ||
134 | mgr_nextp: | |
135 | adiw zl,16 | |
136 | cpi zl,low(hostbuf+510) | |
137 | cpc zh,temp4 | |
138 | brlo mgr_ploop\r | |
139 | \r | |
140 | ; Test for FAT16 Partition\r | |
141 | ldiw z,hostbuf+510-1-63 ;Point to first byte of partition table | |
142 | ldi temp4,high(hostbuf+510) | |
143 | \r | |
144 | mgr_ploop2: | |
145 | \r | |
146 | ; Get Partitiontype\r | |
147 | ldd temp,z+PART_TYPE | |
148 | \r | |
149 | ; Test for FAT Partition\r | |
150 | cpi temp,PARTID_FAT16 | |
151 | brne mgr_nextp2 | |
152 | ||
153 | rcall fat_add_partition | |
154 | ||
155 | rjmp mgr_pend\r | |
156 | ||
157 | mgr_nextp2: | |
158 | adiw zl,16 | |
159 | cpi zl,low(hostbuf+510) | |
160 | cpc zh,temp4 | |
161 | brlo mgr_ploop2\r | |
162 | \r | |
163 | mgr_pend:\r | |
164 | \r | |
165 | ; Initialize RAM-Disks\r | |
166 | rcall rdsk_add_partition\r | |
167 | \r | |
168 | ;Store new partitions and check if the SD card has been changed. | |
169 | ||
170 | ldiw y,tmp_tbl | |
171 | ldiw z,hostparttbl | |
172 | ldi temp4,PARTENTRY_SIZE*MAXDISKS | |
173 | clt\r | |
174 | ||
175 | mgr_pcpl: | |
176 | ld temp,y+ | |
177 | ld temp2,z | |
178 | st z+,temp | |
179 | cpse temp,temp2 | |
180 | set | |
181 | dec temp4 | |
182 | brne mgr_pcpl | |
183 | ||
184 | mov temp,temp3 | |
185 | sts ndisks,temp | |
186 | brtc mgr_pcpe | |
187 | ||
188 | tst temp | |
189 | breq mgr_pcpe | |
190 | ||
191 | ; SD card not changed. | |
192 | rcall fat_scan_partition\r | |
193 | \r | |
194 | lds temp,ndisks\r | |
195 | sbr temp,0x80 | |
196 | ||
197 | mgr_pcpe:\r | |
198 | ||
199 | ret\r | |
200 | \r | |
201 | \r | |
202 | ; ====================================================================\r | |
203 | ; Function: Print partition table info | |
204 | ; ====================================================================\r | |
205 | ; Parameters\r | |
206 | ; --------------------------------------------------------------------\r | |
207 | ; Registers : none\r | |
208 | ; Variables : [r] hostparttbl Table with Partitioninformations\r | |
209 | ; [r] hostparttbltop Pointer to the Top of the Table\r | |
210 | ; --------------------------------------------------------------------\r | |
211 | ; Description:\r | |
212 | ; ====================================================================\r | |
213 | ||
214 | mgr_prnt_parttbl: | |
215 | ldiw z,hostparttbl | |
216 | pprl: | |
217 | ldd temp ,z+1 ;Get partition start | |
218 | ldd temp2,z+2 | |
219 | ldd temp3,z+3 | |
220 | ldd temp4,z+4 | |
221 | printnewline | |
222 | cp temp,_0 ;If zero ... | |
223 | cpc temp2,_0 | |
224 | cpc temp3,_0 | |
225 | cpc temp4,_0 | |
226 | breq mgr_prnop ;... no partition table at 0 | |
227 | \r | |
228 | ; Partitiontype examining\r | |
229 | ldd xl,z+0\r | |
230 | ; CP/M ?\r | |
231 | cpi xl,dskType_CPM\r | |
232 | brne mgr_prtb_nocpm\r | |
233 | rcall mgr_prnt_table_cpm | |
234 | rjmp mgr_prnt_size\r | |
235 | \r | |
236 | ; FAT16 ?\r | |
237 | mgr_prtb_nocpm: | |
238 | cpi xl,dskType_FAT\r | |
239 | brne mgr_prtb_nofat\r | |
240 | rcall mgr_prnt_table_fat | |
241 | rjmp mgr_prnt_size | |
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 | |
247 | rjmp mgr_prnt_size\r | |
248 | ; Entry Error\r | |
249 | mgr_prnt_err: \r | |
250 | rcall mgr_prnt_table_err | |
251 | rjmp mgr_prnt_size\r | |
252 | \r | |
253 | mgr_prnop: | |
254 | rcall mgr_prnt_image | |
255 | \r | |
256 | mgr_prnt_size:\r | |
257 | rcall print_ultoa | |
258 | printstring ", size: " | |
259 | \r | |
260 | ldd temp ,z+5 ;Get partition size | |
261 | ldd temp2,z+6 ;Get partition size | |
262 | ldd temp3,z+7 ;Get partition size | |
263 | ldd temp4,z+8 ;Get partition size | |
264 | ||
265 | lsr temp4 | |
266 | ror temp3 | |
267 | ror temp2 | |
268 | ror temp | |
269 | rcall print_ultoa | |
270 | printstring "KB."\r | |
271 | ||
272 | mgr_goto_next_part: | |
273 | adiw z,PARTENTRY_SIZE | |
274 | ldi temp,high(hostparttbltop) | |
275 | cpi zl, low (hostparttbltop) | |
276 | cpc zh,temp | |
277 | brlo pprl | |
278 | \r | |
279 | mgr_pppre: | |
280 | ret | |
281 | \r | |
282 | \r | |
283 | mgr_prnt_fatsize: | |
284 | rcall print_ultoa | |
285 | printstring ", size: " | |
286 | \r | |
287 | ldd temp ,z+5 ;Get partition size | |
288 | ldd temp2,z+6 ;Get partition size | |
289 | ldd temp3,z+7 ;Get partition size | |
290 | ldd temp4,z+8 ;Get partition size | |
291 | ||
292 | rcall print_ultoa | |
293 | printstring "BYTE." | |
294 | ||
295 | jmp mgr_goto_next_part\r | |
296 | ||
297 | mgr_prnt_table_cpm: | |
298 | printstring "CP/M partition at: " | |
299 | ret\r | |
300 | \r | |
301 | mgr_prnt_table_fat: | |
302 | printstring "FAT16 File-Image at: " | |
303 | ret\r | |
304 | \r | |
305 | mgr_prnt_table_ram: | |
306 | printstring "Ramdisk at: " | |
307 | ret\r | |
308 | \r | |
309 | mgr_prnt_table_err: | |
310 | printstring "Unknown Entry at: " | |
311 | ret\r | |
312 | ||
313 | mgr_prnt_image: | |
314 | printstring "Assuming CP/M image at: " | |
315 | ret\r | |
316 | ||
317 | \r |