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