]>
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 |
b741422e | 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 | |
32 | \r | |
b741422e | 33 | ; ------------------------------- Start of Code Segment\r |
64219415 FZ |
34 | .cseg\r |
35 | \r | |
36 | ; ====================================================================\r | |
b741422e | 37 | ; Function: Scans a Disk for CP/M Partions\r |
64219415 FZ |
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 | |
b741422e | 54 | ; ==================================================================== \r |
64219415 FZ |
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 | |
b741422e L |
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 | |
64219415 FZ |
65 | brne mgr_picl\r |
66 | \r | |
b741422e L |
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 | |
64219415 FZ |
81 | ret\r |
82 | \r | |
83 | mgr_check_bootsektor:\r | |
84 | ;Pointer to first temp table entry\r | |
b741422e L |
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 | |
64219415 FZ |
100 | ldi temp,high((1<<16) * 128/512)\r |
101 | ldi temp2,dskType_CPM\r | |
b741422e L |
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 | |
64219415 FZ |
111 | rjmp mgr_pend\r |
112 | \r | |
113 | ; Search for valid Partitions and ImageFiles \r | |
114 | mgr_search:\r | |
b741422e L |
115 | sbiw z,63 ;Now at first byte of partition table\r |
116 | ldi temp4,high(hostbuf+510)\r | |
64219415 | 117 | \r |
b741422e | 118 | mgr_ploop:\r |
64219415 FZ |
119 | \r |
120 | ; Get Partitiontype\r | |
b741422e | 121 | ldd temp,z+PART_TYPE\r |
64219415 FZ |
122 | \r |
123 | ; Test for CP/M Partition\r | |
b741422e L |
124 | cpi temp,PARTID_CPM\r |
125 | brne mgr_nextp\r | |
126 | \r | |
127 | rcall cpm_add_partition\r | |
64219415 | 128 | \r |
b741422e L |
129 | inc temp3\r |
130 | cpi temp3,MAXDISKS\r | |
64219415 | 131 | breq mgr_pend\r |
b741422e L |
132 | \r |
133 | mgr_nextp:\r | |
134 | adiw zl,16\r | |
135 | cpi zl,low(hostbuf+510)\r | |
136 | cpc zh,temp4\r | |
64219415 FZ |
137 | brlo mgr_ploop\r |
138 | \r | |
b741422e L |
139 | #if FAT16_SUPPORT\r |
140 | \r | |
64219415 | 141 | ; Test for FAT16 Partition\r |
b741422e L |
142 | ldiw z,hostbuf+510-1-63 ;Point to first byte of partition table\r |
143 | ldi temp4,high(hostbuf+510)\r | |
64219415 | 144 | \r |
b741422e | 145 | mgr_ploop2:\r |
64219415 FZ |
146 | \r |
147 | ; Get Partitiontype\r | |
b741422e | 148 | ldd temp,z+PART_TYPE\r |
64219415 FZ |
149 | \r |
150 | ; Test for FAT Partition\r | |
b741422e L |
151 | cpi temp,PARTID_FAT16\r |
152 | brne mgr_nextp2\r | |
153 | \r | |
154 | rcall fat_add_partition\r | |
155 | \r | |
64219415 | 156 | rjmp mgr_pend\r |
b741422e L |
157 | \r |
158 | mgr_nextp2:\r | |
159 | adiw zl,16\r | |
160 | cpi zl,low(hostbuf+510)\r | |
161 | cpc zh,temp4\r | |
64219415 | 162 | brlo mgr_ploop2\r |
b741422e | 163 | #endif\r |
64219415 FZ |
164 | \r |
165 | mgr_pend:\r | |
166 | \r | |
167 | ; Initialize RAM-Disks\r | |
168 | rcall rdsk_add_partition\r | |
169 | \r | |
b741422e L |
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 | |
64219415 | 175 | clt\r |
64219415 | 176 | \r |
b741422e L |
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 | |
64219415 | 198 | lds temp,ndisks\r |
b741422e L |
199 | sbr temp,0x80\r |
200 | \r | |
64219415 | 201 | mgr_pcpe:\r |
b741422e | 202 | \r |
64219415 FZ |
203 | ret\r |
204 | \r | |
205 | \r | |
206 | ; ====================================================================\r | |
b741422e | 207 | ; Function: Print partition table info\r |
64219415 FZ |
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 | |
64219415 | 217 | \r |
b741422e L |
218 | mgr_prnt_parttbl:\r |
219 | ldiw z,hostparttbl\r | |
220 | pprl:\r | |
64219415 | 221 | ; Partitiontype examining\r |
b741422e | 222 | \r |
64219415 | 223 | ldd xl,z+0\r |
b741422e L |
224 | ; Empty slot?\r |
225 | cpi xl,dskType_None\r | |
226 | breq mgr_goto_next_part\r | |
227 | \r | |
228 | printnewline\r | |
229 | \r | |
64219415 FZ |
230 | ; CP/M ?\r |
231 | cpi xl,dskType_CPM\r | |
232 | brne mgr_prtb_nocpm\r | |
b741422e | 233 | rcall mgr_prnt_table_cpm\r |
64219415 FZ |
234 | rjmp mgr_prnt_size\r |
235 | \r | |
236 | ; FAT16 ?\r | |
b741422e | 237 | mgr_prtb_nocpm:\r |
64219415 FZ |
238 | cpi xl,dskType_FAT\r |
239 | brne mgr_prtb_nofat\r | |
b741422e L |
240 | rcall mgr_prnt_table_fat\r |
241 | rjmp mgr_prnt_size\r | |
64219415 FZ |
242 | ; RAMDISK ?\r |
243 | mgr_prtb_nofat:\r | |
244 | cpi xl,dskType_RAM\r | |
245 | brne mgr_prnt_err\r | |
b741422e | 246 | rcall mgr_prnt_table_ram\r |
64219415 FZ |
247 | rjmp mgr_prnt_size\r |
248 | ; Entry Error\r | |
249 | mgr_prnt_err: \r | |
b741422e | 250 | rcall mgr_prnt_table_err\r |
64219415 FZ |
251 | rjmp mgr_prnt_size\r |
252 | \r | |
b741422e L |
253 | mgr_prnop:\r |
254 | rcall mgr_prnt_image\r | |
64219415 FZ |
255 | \r |
256 | mgr_prnt_size:\r | |
b741422e L |
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 | |
64219415 | 274 | printstring "KB."\r |
b741422e L |
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 | |
64219415 FZ |
285 | \r |
286 | \r | |
b741422e L |
287 | mgr_prnt_fatsize:\r |
288 | lcall print_ultoa\r | |
289 | printstring ", size: "\r | |
64219415 | 290 | \r |
b741422e L |
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 | |
64219415 FZ |
303 | ret\r |
304 | \r | |
b741422e L |
305 | mgr_prnt_table_fat:\r |
306 | printstring "FAT16 File-Image at: "\r | |
64219415 FZ |
307 | ret\r |
308 | \r | |
b741422e L |
309 | mgr_prnt_table_ram:\r |
310 | printstring "Ramdisk at: "\r | |
64219415 FZ |
311 | ret\r |
312 | \r | |
b741422e L |
313 | mgr_prnt_table_err:\r |
314 | printstring "Unknown Entry at: "\r | |
64219415 | 315 | ret\r |
b741422e L |
316 | \r |
317 | mgr_prnt_image:\r | |
318 | printstring "Assuming CP/M image at: "\r | |
64219415 | 319 | ret\r |
b741422e | 320 | \r |
64219415 | 321 | \r |