]> cloudbase.mooo.com Git - avrcpm.git/blame - avr/dsk_mgr.asm
Tag for Version 3.2
[avrcpm.git] / 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
e8384f88 5; Copyright (C) 2013 Leo C.
92202636
L
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
92202636
L
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; ====================================================================
47mgr_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
54mgr_picl:
55 st y+,_0
56 dec temp2
57 brne mgr_picl
58
59; Start mmc Card interaction
60 lcall mmcInit
dc705dc0 61 andi temp,MMCST_NOINIT | MMCST_NODISK
92202636
L
62 brne mgr_pierr
63
64;Load first sector from MMC (boot sector)
65 ldiw y,0 ; Sector 0
66 movw x,y
02d57479 67 ldiw z,hostbuf
92202636
L
68 lcall mmcReadSect
69 tst temp
70 breq mgr_check_bootsektor
71
72mgr_pierr:
73 clr temp
74 ret
75
76mgr_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?
92202636 84 cpi temp,0x55
825ecc9d
L
85 lds temp,hostbuf+510+1
86 ldi temp2,0xAA
87 cpc temp,temp2
92202636
L
88 breq mgr_search
89
90;No MBR, no partition table ...
91
ce520bff
L
92#if CPMDSK_SUPPORT
93
92202636
L
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 ;
5482d75f
L
105
106 ldi temp3,0
107 rcall dpb_imgdata_get
108
ce520bff
L
109#endif /* CPMDSK_SUPPORT */
110
92202636
L
111 rjmp mgr_pend
112
92202636 113mgr_search:
ce520bff
L
114
115#if CPMDSK_SUPPORT
116
117; Search for valid Partitions and ImageFiles
92202636 118 ldiw z,hostbuf+510-64 ;Point to first byte of partition table
92202636
L
119
120mgr_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
e8384f88 129 lcall cpm_add_partition
92202636
L
130 inc temp3
131 sts ndisks,temp3
637689de 132 adiw y,PARTENTRY_SIZE
92202636
L
133 cpi temp3,MAXDISKS
134 breq mgr_pend
135
136mgr_nextp:
5482d75f 137 adiw z,16
825ecc9d 138 cpi zl,low(hostbuf+510) ;End of partition table reached?
92202636 139 brne mgr_ploop
ce520bff 140#endif /* CPMDSK_SUPPORT */
92202636
L
141
142#if FAT16_SUPPORT
143
144; Test for FAT16 Partition
145 ldiw z,hostbuf+510-64 ;Point to first byte of partition table
92202636
L
146
147mgr_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
159mgr_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
165mgr_nextp2:
166 adiw zl,16
825ecc9d 167 cpi zl,low(hostbuf+510)
92202636 168 brne mgr_ploop2
ce520bff 169#endif /* FAT16_SUPPORT */
92202636
L
170
171mgr_pend:
5482d75f
L
172 clr temp3
173mgr_imgd_lp:
dcd7e502
L
174 lds temp,ndisks
175 cp temp3,temp
5482d75f
L
176 breq mgr_pend2
177 rcall dpb_imgdata_get
178 inc temp3
5482d75f
L
179 rjmp mgr_imgd_lp
180
181mgr_pend2:
182 lds temp,ndisks ;return # of "disks"
92202636
L
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
199mgr_prnt_parttbl:
ce520bff
L
200 lds yl,ndisks
201 tst yl
202 brne ppr_doit
203 ret
204
205ppr_doit:
dc705dc0
L
206 push r15
207 push r14
92202636 208 ldiw z,hostparttbl
92202636 209 ldi xh,'A'
92202636 210pprl:
92202636
L
211 printnewline
212
825ecc9d
L
213 ldd temp ,z+1 ;Get partition start
214 ldd temp2,z+2
dc705dc0
L
215 ldd r14,z+3
216 ldd r15,z+4
217
ce520bff
L
218; Partitiontype examining
219
220 ldd xl,z+0
221 andi xl,dskType_MASK
222
223#if CPMDSK_SUPPORT
224
dc705dc0
L
225 cp temp,_0 ;If zero ...
226 cpc temp2,_0
227 cpc r14,_0
228 cpc r15,_0
ce520bff 229 brne mgr_prchkcpm ;... no partition table at 0
92202636 230
ce520bff
L
231 rcall mgr_prnt_diskname
232 rcall mgr_prnt_image
233 rjmp mgr_prnt_size
234
235mgr_prchkcpm:
92202636
L
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
92202636 242mgr_prtb_nocpm:
ce520bff
L
243#endif
244
92202636
L
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
252mgr_prtb_nofat:
253#endif
ce520bff 254
92202636 255#if 0 /* RAMDISK is not on SD card */
ce520bff 256#if RAMDISKCNT
92202636
L
257; RAMDISK ?
258 cpi xl,dskType_RAM
ce520bff 259 brne mgr_prnt_noramdisk
92202636
L
260 rcall mgr_prnt_diskname
261 rcall mgr_prnt_table_ram
262 rjmp mgr_prnt_size
ce520bff
L
263mgr_prnt_noramdisk:
264#endif
92202636 265#endif
ce520bff 266
92202636
L
267; Entry Error
268 rcall mgr_prnt_table_err
92202636
L
269
270mgr_prnt_size:
271 lcall print_ultoa
272 printstring ", size: "
273
274 ldd temp ,z+5 ;Get partition size
275 ldd temp2,z+6
825ecc9d
L
276 clr r14
277 clr r15
278 lsr temp2
92202636
L
279 ror temp
280 lcall print_ultoa
281 printstring "KB."
282
283mgr_goto_next_part:
284 adiw z,PARTENTRY_SIZE
285 inc xh
286 dec yl
287 brne pprl
288
289mgr_pppre:
dc705dc0
L
290 pop r14
291 pop r15
92202636
L
292 ret
293
294
92202636
L
295mgr_prnt_diskname:
296 push temp
297 mov temp,xh
298 lcall uartputc
96a054ef 299 printstring ": "
92202636
L
300 pop temp
301 ret
302
ce520bff 303#if CPMDSK_SUPPORT
92202636
L
304mgr_prnt_table_cpm:
305 printstring "CP/M partition at: "
306 ret
307
ce520bff
L
308mgr_prnt_image:
309 printstring "Assuming CP/M image at: "
310 ret
311#endif
312
313#if FAT16_SUPPORT
92202636 314mgr_prnt_table_fat:
96a054ef
L
315 printstring "FAT16 File-Image '"
316 push temp
317 mov temp,r14
318 lcall uartputc
319 clr r14
320 pop temp
321 printstring "' at: "
92202636 322 ret
ce520bff 323#endif
92202636 324
ce520bff 325#if RAMDISKCNT
92202636
L
326mgr_prnt_table_ram:
327 printstring "Ramdisk at: "
328 ret
ce520bff 329#endif
92202636
L
330
331mgr_prnt_table_err:
332 printstring "Unknown Entry at: "
333 ret
334
92202636 335