]> cloudbase.mooo.com Git - avrcpm.git/blob - avrcpm/avr/dsk_mgr.asm
ac9b0d414c87725fc3e47a54cee3230c3f12222a
[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 call 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 call 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 rjmp mgr_nextp
133
134 mgr_nextp:
135 adiw zl,16
136 cpi zl,low(hostbuf+510)
137 cpc zh,temp4
138 brlo mgr_ploop
139
140 ; Test for FAT16 Partition
141 ldiw z,hostbuf+510-1-63 ;Point to first byte of partition table
142 ldi temp4,high(hostbuf+510)
143
144 mgr_ploop2:
145
146 ; Get Partitiontype
147 ldd temp,z+PART_TYPE
148
149 ; Test for FAT Partition
150 cpi temp,PARTID_FAT16
151 brne mgr_nextp2
152
153 rcall fat_add_partition
154
155 rjmp mgr_pend
156
157 mgr_nextp2:
158 adiw zl,16
159 cpi zl,low(hostbuf+510)
160 cpc zh,temp4
161 brlo mgr_ploop2
162
163 mgr_pend:
164
165 ; Initialize RAM-Disks
166 rcall rdsk_add_partition
167
168 ;Store new partitions and check if the SD card has been changed.
169
170 ldiw y,tmp_tbl
171 ldiw z,hostparttbl
172 ldi temp4,PARTENTRY_SIZE*MAXDISKS
173 clt
174
175 mgr_pcpl:
176 ld temp,y+
177 ld temp2,z
178 st z+,temp
179 cpse temp,temp2
180 set
181 dec temp4
182 brne mgr_pcpl
183
184 mov temp,temp3
185 sts ndisks,temp
186 brtc mgr_pcpe
187
188 tst temp
189 breq mgr_pcpe
190
191 ; SD card not changed.
192 rcall fat_scan_partition
193
194 lds temp,ndisks
195 sbr temp,0x80
196
197 mgr_pcpe:
198
199 ret
200
201
202 ; ====================================================================
203 ; Function: Print partition table info
204 ; ====================================================================
205 ; Parameters
206 ; --------------------------------------------------------------------
207 ; Registers : none
208 ; Variables : [r] hostparttbl Table with Partitioninformations
209 ; [r] hostparttbltop Pointer to the Top of the Table
210 ; --------------------------------------------------------------------
211 ; Description:
212 ; ====================================================================
213
214 mgr_prnt_parttbl:
215 ldiw z,hostparttbl
216 pprl:
217 ldd temp ,z+1 ;Get partition start
218 ldd temp2,z+2
219 ldd temp3,z+3
220 ldd temp4,z+4
221 printnewline
222 cp temp,_0 ;If zero ...
223 cpc temp2,_0
224 cpc temp3,_0
225 cpc temp4,_0
226 breq mgr_prnop ;... no partition table at 0
227
228 ; Partitiontype examining
229 ldd xl,z+0
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 rcall print_ultoa
258 printstring ", size: "
259
260 ldd temp ,z+5 ;Get partition size
261 ldd temp2,z+6 ;Get partition size
262 ldd temp3,z+7 ;Get partition size
263 ldd temp4,z+8 ;Get partition size
264
265 lsr temp4
266 ror temp3
267 ror temp2
268 ror temp
269 rcall print_ultoa
270 printstring "KB."
271
272 mgr_goto_next_part:
273 adiw z,PARTENTRY_SIZE
274 ldi temp,high(hostparttbltop)
275 cpi zl, low (hostparttbltop)
276 cpc zh,temp
277 brlo pprl
278
279 mgr_pppre:
280 ret
281
282
283 mgr_prnt_fatsize:
284 rcall print_ultoa
285 printstring ", size: "
286
287 ldd temp ,z+5 ;Get partition size
288 ldd temp2,z+6 ;Get partition size
289 ldd temp3,z+7 ;Get partition size
290 ldd temp4,z+8 ;Get partition size
291
292 rcall print_ultoa
293 printstring "BYTE."
294
295 jmp mgr_goto_next_part
296
297 mgr_prnt_table_cpm:
298 printstring "CP/M partition at: "
299 ret
300
301 mgr_prnt_table_fat:
302 printstring "FAT16 File-Image at: "
303 ret
304
305 mgr_prnt_table_ram:
306 printstring "Ramdisk at: "
307 ret
308
309 mgr_prnt_table_err:
310 printstring "Unknown Entry at: "
311 ret
312
313 mgr_prnt_image:
314 printstring "Assuming CP/M image at: "
315 ret
316
317