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