]> cloudbase.mooo.com Git - avrcpm.git/blob - avrcpm/avr/dsk_mgr.asm
* Start of dynamic disk size code.
[avrcpm.git] / avrcpm / 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 ;----------------------------------------------- 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 ; ====================================================================
53 mgr_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
60 mgr_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
77 mgr_pierr:
78 clr temp
79 ret
80
81 mgr_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
113 mgr_search:
114 ldiw z,hostbuf+510-64 ;Point to first byte of partition table
115 ldi temp4,4 ;Partition table has 4 entries.
116
117 mgr_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
133 mgr_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
144 mgr_ploop2:
145 ; Get Partitiontype
146 ldd temp,z+PART_TYPE
147
148 ; Test for FAT Partition
149 cpi temp,PARTID_FAT16
150 brne mgr_nextp2
151
152 rcall fat_add_partition
153
154 rcall fat_scan_partition
155 rcall fat_reset_cache
156
157 rjmp mgr_pend ;Stop after first FAT16 parrtition found.
158
159 mgr_nextp2:
160 adiw zl,16
161 dec temp4
162 brne mgr_ploop2
163 #endif
164
165 mgr_pend:
166 lds temp,ndisks ;return # of "disks"
167 tst temp
168 ret
169
170
171 ; ====================================================================
172 ; Function: Print partition table info
173 ; ====================================================================
174 ; Parameters
175 ; --------------------------------------------------------------------
176 ; Registers : none
177 ; Variables : [r] hostparttbl Table with Partitioninformations
178 ; [r] hostparttbltop Pointer to the Top of the Table
179 ; --------------------------------------------------------------------
180 ; Description:
181 ; ====================================================================
182
183 mgr_prnt_parttbl:
184 ldiw z,hostparttbl
185 lds yl,ndisks
186 ldi xh,'A'
187
188 pprl:
189 ldd temp ,z+1 ;Get partition start
190 ldd temp2,z+2
191 ldd temp3,z+3
192 ldd temp4,z+4
193
194 printnewline
195
196 cp temp,_0 ;If zero ...
197 cpc temp2,_0
198 cpc temp3,_0
199 cpc temp4,_0
200 breq mgr_prnop ;... no partition table at 0
201
202 ; Partitiontype examining
203 ldd xl,z+0
204 ; CP/M ?
205 cpi xl,dskType_CPM
206 brne mgr_prtb_nocpm
207 rcall mgr_prnt_diskname
208 rcall mgr_prnt_table_cpm
209 rjmp mgr_prnt_size
210
211 mgr_prtb_nocpm:
212 #if FAT16_SUPPORT
213 ; FAT16 ?
214 cpi xl,dskType_FAT
215 brne mgr_prtb_nofat
216 rcall mgr_prnt_diskname
217 rcall mgr_prnt_table_fat
218 rjmp mgr_prnt_size
219 mgr_prtb_nofat:
220 #endif
221 #if 0 /* RAMDISK is not on SD card */
222 ; RAMDISK ?
223 cpi xl,dskType_RAM
224 brne mgr_prnt_err
225 rcall mgr_prnt_diskname
226 rcall mgr_prnt_table_ram
227 rjmp mgr_prnt_size
228 #endif
229 mgr_prnt_err:
230 ; Entry Error
231 rcall mgr_prnt_table_err
232 rjmp mgr_prnt_size
233
234 mgr_prnop:
235 rcall mgr_prnt_diskname
236 rcall mgr_prnt_image
237
238 mgr_prnt_size:
239 lcall print_ultoa
240 printstring ", size: "
241
242 ldd temp ,z+5 ;Get partition size
243 ldd temp2,z+6
244 ldd temp3,z+7
245 ldd temp4,z+8
246
247 lsr temp4
248 ror temp3
249 ror temp2
250 ror temp
251 lcall print_ultoa
252 printstring "KB."
253
254 mgr_goto_next_part:
255 adiw z,PARTENTRY_SIZE
256 inc xh
257 dec yl
258 brne pprl
259
260 mgr_pppre:
261 ret
262
263
264 mgr_prnt_fatsize:
265 lcall print_ultoa
266 printstring ", size: "
267
268 ldd temp ,z+5 ;Get partition size
269 ldd temp2,z+6
270 ldd temp3,z+7
271 ldd temp4,z+8
272
273 lcall print_ultoa
274 printstring "BYTE."
275
276 rjmp mgr_goto_next_part
277
278 mgr_prnt_diskname:
279 push temp
280 mov temp,xh
281 lcall uartputc
282 ldi temp,':'
283 lcall uartputc
284 pop temp
285 ret
286
287 mgr_prnt_table_cpm:
288 printstring "CP/M partition at: "
289 ret
290
291 mgr_prnt_table_fat:
292 printstring "FAT16 File-Image at: "
293 ret
294
295 mgr_prnt_table_ram:
296 printstring "Ramdisk at: "
297 ret
298
299 mgr_prnt_table_err:
300 printstring "Unknown Entry at: "
301 ret
302
303 mgr_prnt_image:
304 printstring "Assuming CP/M image at: "
305 ret
306
307