]> cloudbase.mooo.com Git - avrcpm.git/blob - avr/dsk_mgr.asm
* New config option: CPMDSK_SUPPORT
[avrcpm.git] / avr / dsk_mgr.asm
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 #if CPMDSK_SUPPORT
109
110 inc temp3 ;pretend we have one.
111 sts ndisks,temp3
112 ldi temp,high((1<<16) * 128/512)
113 ldi temp2,dskType_CPM
114 std y+0,temp2
115 std y+1,_0 ;start at beginning of card
116 std y+2,_0
117 std y+3,_0
118 std y+4,_0
119 std y+5,_0 ;max CP/M 2.2 disk size
120 std y+6,temp ;
121
122 ldi temp3,0
123 rcall dpb_imgdata_get
124
125 #endif /* CPMDSK_SUPPORT */
126
127 rjmp mgr_pend
128
129 mgr_search:
130
131 #if CPMDSK_SUPPORT
132
133 ; Search for valid Partitions and ImageFiles
134 ldiw z,hostbuf+510-64 ;Point to first byte of partition table
135
136 mgr_ploop:
137
138 ; Get Partitiontype
139 ldd temp,z+PART_TYPE
140
141 ; Test for CP/M Partition
142 cpi temp,PARTID_CPM
143 brne mgr_nextp
144
145 rcall cpm_add_partition
146 inc temp3
147 sts ndisks,temp3
148 adiw y,PARTENTRY_SIZE
149 cpi temp3,MAXDISKS
150 breq mgr_pend
151
152 mgr_nextp:
153 adiw z,16
154 cpi zl,low(hostbuf+510) ;End of partition table reached?
155 brne mgr_ploop
156 #endif /* CPMDSK_SUPPORT */
157
158 #if FAT16_SUPPORT
159
160 ; Test for FAT16 Partition
161 ldiw z,hostbuf+510-64 ;Point to first byte of partition table
162
163 mgr_ploop2:
164 ; Get Partitiontype
165 ldd temp,z+PART_TYPE
166
167 ; Test for FAT Partition Type 1
168 cpi temp,PARTID1_FAT16
169 breq mgr_fatfound
170
171 ; Test for FAT Partition Type 2
172 cpi temp,PARTID2_FAT16
173 brne mgr_nextp2
174
175 mgr_fatfound:
176 rcall fat_add_partition
177 rcall fat_scan_partition
178 rcall fat_reset_cache
179 rjmp mgr_pend ;Stop after first FAT16 partition found.
180
181 mgr_nextp2:
182 adiw zl,16
183 cpi zl,low(hostbuf+510)
184 brne mgr_ploop2
185 #endif /* FAT16_SUPPORT */
186
187 mgr_pend:
188 clr temp3
189 mgr_imgd_lp:
190 lds temp,ndisks
191 cp temp3,temp
192 breq mgr_pend2
193 rcall dpb_imgdata_get
194 inc temp3
195 rjmp mgr_imgd_lp
196
197 mgr_pend2:
198 lds temp,ndisks ;return # of "disks"
199 tst temp
200 ret
201
202
203 ; ====================================================================
204 ; Function: Print partition table info
205 ; ====================================================================
206 ; Parameters
207 ; --------------------------------------------------------------------
208 ; Registers : none
209 ; Variables : [r] hostparttbl Table with Partitioninformations
210 ; [r] hostparttbltop Pointer to the Top of the Table
211 ; --------------------------------------------------------------------
212 ; Description:
213 ; ====================================================================
214
215 mgr_prnt_parttbl:
216 lds yl,ndisks
217 tst yl
218 brne ppr_doit
219 ret
220
221 ppr_doit:
222 push r15
223 push r14
224 ldiw z,hostparttbl
225 ldi xh,'A'
226 pprl:
227 printnewline
228
229 ldd temp ,z+1 ;Get partition start
230 ldd temp2,z+2
231 ldd r14,z+3
232 ldd r15,z+4
233
234 ; Partitiontype examining
235
236 ldd xl,z+0
237 andi xl,dskType_MASK
238
239 #if CPMDSK_SUPPORT
240
241 cp temp,_0 ;If zero ...
242 cpc temp2,_0
243 cpc r14,_0
244 cpc r15,_0
245 brne mgr_prchkcpm ;... no partition table at 0
246
247 rcall mgr_prnt_diskname
248 rcall mgr_prnt_image
249 rjmp mgr_prnt_size
250
251 mgr_prchkcpm:
252 ; CP/M ?
253 cpi xl,dskType_CPM
254 brne mgr_prtb_nocpm
255 rcall mgr_prnt_diskname
256 rcall mgr_prnt_table_cpm
257 rjmp mgr_prnt_size
258 mgr_prtb_nocpm:
259 #endif
260
261 #if FAT16_SUPPORT
262 ; FAT16 ?
263 cpi xl,dskType_FAT
264 brne mgr_prtb_nofat
265 rcall mgr_prnt_diskname
266 rcall mgr_prnt_table_fat
267 rjmp mgr_prnt_size
268 mgr_prtb_nofat:
269 #endif
270
271 #if 0 /* RAMDISK is not on SD card */
272 #if RAMDISKCNT
273 ; RAMDISK ?
274 cpi xl,dskType_RAM
275 brne mgr_prnt_noramdisk
276 rcall mgr_prnt_diskname
277 rcall mgr_prnt_table_ram
278 rjmp mgr_prnt_size
279 mgr_prnt_noramdisk:
280 #endif
281 #endif
282
283 ; Entry Error
284 rcall mgr_prnt_table_err
285
286 mgr_prnt_size:
287 lcall print_ultoa
288 printstring ", size: "
289
290 ldd temp ,z+5 ;Get partition size
291 ldd temp2,z+6
292 clr r14
293 clr r15
294 lsr temp2
295 ror temp
296 lcall print_ultoa
297 printstring "KB."
298
299 mgr_goto_next_part:
300 adiw z,PARTENTRY_SIZE
301 inc xh
302 dec yl
303 brne pprl
304
305 mgr_pppre:
306 pop r14
307 pop r15
308 ret
309
310
311 mgr_prnt_diskname:
312 push temp
313 mov temp,xh
314 lcall uartputc
315 printstring ": "
316 pop temp
317 ret
318
319 #if CPMDSK_SUPPORT
320 mgr_prnt_table_cpm:
321 printstring "CP/M partition at: "
322 ret
323
324 mgr_prnt_image:
325 printstring "Assuming CP/M image at: "
326 ret
327 #endif
328
329 #if FAT16_SUPPORT
330 mgr_prnt_table_fat:
331 printstring "FAT16 File-Image '"
332 push temp
333 mov temp,r14
334 lcall uartputc
335 clr r14
336 pop temp
337 printstring "' at: "
338 ret
339 #endif
340
341 #if RAMDISKCNT
342 mgr_prnt_table_ram:
343 printstring "Ramdisk at: "
344 ret
345 #endif
346
347 mgr_prnt_table_err:
348 printstring "Unknown Entry at: "
349 ret
350
351