]> cloudbase.mooo.com Git - avrcpm.git/blob - avrcpm/avr/dsk_mgr.asm
16977f57cf1f3c95ac0b6742ac1086aacb78284b
[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
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 rcall 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 #endif
198 lds temp,ndisks
199 sbr temp,0x80
200
201 mgr_pcpe:
202
203 ret
204
205
206 ; ====================================================================
207 ; Function: Print partition table info
208 ; ====================================================================
209 ; Parameters
210 ; --------------------------------------------------------------------
211 ; Registers : none
212 ; Variables : [r] hostparttbl Table with Partitioninformations
213 ; [r] hostparttbltop Pointer to the Top of the Table
214 ; --------------------------------------------------------------------
215 ; Description:
216 ; ====================================================================
217
218 mgr_prnt_parttbl:
219 ldiw z,hostparttbl
220 pprl:
221 ; Partitiontype examining
222
223 ldd xl,z+0
224 ; Empty slot?
225 cpi xl,dskType_None
226 breq mgr_goto_next_part
227
228 printnewline
229
230 ; CP/M ?
231 cpi xl,dskType_CPM
232 brne mgr_prtb_nocpm
233 rcall mgr_prnt_table_cpm
234 rjmp mgr_prnt_size
235
236 ; FAT16 ?
237 mgr_prtb_nocpm:
238 cpi xl,dskType_FAT
239 brne mgr_prtb_nofat
240 rcall mgr_prnt_table_fat
241 rjmp mgr_prnt_size
242 ; RAMDISK ?
243 mgr_prtb_nofat:
244 cpi xl,dskType_RAM
245 brne mgr_prnt_err
246 rcall mgr_prnt_table_ram
247 rjmp mgr_prnt_size
248 ; Entry Error
249 mgr_prnt_err:
250 rcall mgr_prnt_table_err
251 rjmp mgr_prnt_size
252
253 mgr_prnop:
254 rcall mgr_prnt_image
255
256 mgr_prnt_size:
257 ldd temp ,z+1 ;Get partition start
258 ldd temp2,z+2
259 ldd temp3,z+3
260 ldd temp4,z+4
261 lcall print_ultoa
262 printstring ", size: "
263
264 ldd temp ,z+5 ;Get partition size
265 ldd temp2,z+6 ;Get partition size
266 ldd temp3,z+7 ;Get partition size
267 ldd temp4,z+8 ;Get partition size
268
269 lsr temp4
270 ror temp3
271 ror temp2
272 ror temp
273 lcall print_ultoa
274 printstring "KB."
275
276 mgr_goto_next_part:
277 adiw z,PARTENTRY_SIZE
278 ldi temp,high(hostparttbltop)
279 cpi zl, low (hostparttbltop)
280 cpc zh,temp
281 brlo pprl
282
283 mgr_pppre:
284 ret
285
286
287 mgr_prnt_fatsize:
288 lcall print_ultoa
289 printstring ", size: "
290
291 ldd temp ,z+5 ;Get partition size
292 ldd temp2,z+6 ;Get partition size
293 ldd temp3,z+7 ;Get partition size
294 ldd temp4,z+8 ;Get partition size
295
296 lcall print_ultoa
297 printstring "BYTE."
298
299 rjmp mgr_goto_next_part
300
301 mgr_prnt_table_cpm:
302 printstring "CP/M partition at: "
303 ret
304
305 mgr_prnt_table_fat:
306 printstring "FAT16 File-Image at: "
307 ret
308
309 mgr_prnt_table_ram:
310 printstring "Ramdisk at: "
311 ret
312
313 mgr_prnt_table_err:
314 printstring "Unknown Entry at: "
315 ret
316
317 mgr_prnt_image:
318 printstring "Assuming CP/M image at: "
319 ret
320
321