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