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