]> cloudbase.mooo.com Git - avrcpm.git/blob - avr/dsk_mgr.asm
* cpm/ipl.mac
[avrcpm.git] / 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 ; Partition Table Structures
28
29 #define PART_TYPE 4
30 #define PART_START 8
31 #define PART_SIZE 12
32
33 /*
34 * Partition table id
35 * (see http://www.win.tue.nl/~aeb/partitions/partition_types-1.html)
36 */
37 #define PARTID1_FAT16 0x0E
38 #define PARTID2_FAT16 0x06
39 #define PARTID_CPM 0x52
40
41
42 ; ------------------------------------------------ Start of Code Segment
43 .cseg
44
45 ; ====================================================================
46 ; Function: Scans a Disk for CP/M Partions
47 ; ====================================================================
48 ; Parameters
49 ; --------------------------------------------------------------------
50 ;
51 ; Registers : [w] temp Number of disk images (raw and fat16) found.
52 ; + 0x80 if sd card changes. (not used, doesn't work)
53 ; SREG : Z according to temp
54 ; --------------------------------------------------------------------
55 ; Description:
56 ; This Function scans an SD-Cards Boot-Sector for valid Partitions.
57 ; First all original CP/M Partitions will be usesed as Drives for
58 ; the CPM-System. Wenn all CP/M Partitions are found, a second
59 ; scann will be made. In the second Scan, the first FAT16 Partition
60 ; on the Disk will be used for a detailed analyses. If there
61 ; are any Files like "cpm_x.img" are found, these Files will be
62 ; used as Disks by the CP/M- System. ( x must be in the Range A to D )
63 ; ====================================================================
64 mgr_init_partitions:
65
66 sts ndisks,_0 ; Set Number of Disks to 0
67
68 ; Initialize partition table
69 ldiw y,hostparttbl
70 ldi temp2,PARTENTRY_SIZE*MAXDISKS
71 mgr_picl:
72 st y+,_0
73 dec temp2
74 brne mgr_picl
75
76 ; Start mmc Card interaction
77 lcall mmcInit
78 andi temp,MMCST_NOINIT & MMCST_NODISK
79 brne mgr_pierr
80
81 ;Load first sector from MMC (boot sector)
82 ldiw y,0 ; Sector 0
83 movw x,y
84 lcall mmcReadSect
85 tst temp
86 breq mgr_check_bootsektor
87
88 mgr_pierr:
89 clr temp
90 ret
91
92 mgr_check_bootsektor:
93 ;Pointer to first table entry
94 ldiw y,hostparttbl
95 ldi temp3,0 ;temp3 holds number of found disks (paritions)
96
97 ;Test, if it has a valid MBR
98
99 lds temp,hostbuf+510 ;MBR signature (0xAA55) at and of sector?
100 lds temp2,hostbuf+510+1
101 ldi temp4,0xAA
102 cpi temp,0x55
103 cpc temp2,temp4
104 breq mgr_search
105
106 ;No MBR, no partition table ...
107
108 inc temp3 ;pretend we have one.
109 sts ndisks,temp3
110 ldi temp,high((1<<16) * 128/512)
111 ldi temp2,dskType_CPM
112 std y+0,temp2
113 std y+1,_0 ;start at beginning of card
114 std y+2,_0
115 std y+3,_0
116 std y+4,_0
117 std y+5,_0 ;max CP/M 2.2 disk size
118 std y+6,temp ;
119
120 ldi temp3,0
121 rcall dpb_imgdata_get
122
123 rjmp mgr_pend
124
125 ; Search for valid Partitions and ImageFiles
126 mgr_search:
127 ldiw z,hostbuf+510-64 ;Point to first byte of partition table
128 ldi temp4,4 ;Partition table has 4 entries.
129
130 mgr_ploop:
131
132 ; Get Partitiontype
133 ldd temp,z+PART_TYPE
134
135 ; Test for CP/M Partition
136 cpi temp,PARTID_CPM
137 brne mgr_nextp
138
139 rcall cpm_add_partition
140 inc temp3
141 sts ndisks,temp3
142 adiw y,PARTENTRY_SIZE
143 cpi temp3,MAXDISKS
144 breq mgr_pend
145
146 mgr_nextp:
147 adiw z,16
148 dec temp4
149 brne mgr_ploop
150
151 #if FAT16_SUPPORT
152
153 ; Test for FAT16 Partition
154 ldiw z,hostbuf+510-64 ;Point to first byte of partition table
155 ldi temp4,4
156
157 mgr_ploop2:
158 ; Get Partitiontype
159 ldd temp,z+PART_TYPE
160
161 ; Test for FAT Partition Type 1
162 cpi temp,PARTID1_FAT16
163 breq mgr_fatfound
164
165 ; Test for FAT Partition Type 2
166 cpi temp,PARTID2_FAT16
167 brne mgr_nextp2
168
169 mgr_fatfound:
170 rcall fat_add_partition
171 rcall fat_scan_partition
172 rcall fat_reset_cache
173 rjmp mgr_pend ;Stop after first FAT16 partition found.
174
175 mgr_nextp2:
176 adiw zl,16
177 dec temp4
178 brne mgr_ploop2
179 #endif
180
181 mgr_pend:
182 lds temp4,ndisks
183 clr temp3
184 mgr_imgd_lp:
185 tst temp4
186 breq mgr_pend2
187 rcall dpb_imgdata_get
188 inc temp3
189 dec temp4
190 rjmp mgr_imgd_lp
191
192 mgr_pend2:
193 lds temp,ndisks ;return # of "disks"
194 tst temp
195 ret
196
197
198 ; ====================================================================
199 ; Function: Print partition table info
200 ; ====================================================================
201 ; Parameters
202 ; --------------------------------------------------------------------
203 ; Registers : none
204 ; Variables : [r] hostparttbl Table with Partitioninformations
205 ; [r] hostparttbltop Pointer to the Top of the Table
206 ; --------------------------------------------------------------------
207 ; Description:
208 ; ====================================================================
209
210 mgr_prnt_parttbl:
211 ldiw z,hostparttbl
212 lds yl,ndisks
213 ldi xh,'A'
214
215 pprl:
216 ldd temp ,z+1 ;Get partition start
217 ldd temp2,z+2
218 ldd temp3,z+3
219 ldd temp4,z+4
220
221 printnewline
222
223 cp temp,_0 ;If zero ...
224 cpc temp2,_0
225 cpc temp3,_0
226 cpc temp4,_0
227 breq mgr_prnop ;... no partition table at 0
228
229 ; Partitiontype examining
230 ldd xl,z+0
231 andi xl,dskType_MASK
232 ; CP/M ?
233 cpi xl,dskType_CPM
234 brne mgr_prtb_nocpm
235 rcall mgr_prnt_diskname
236 rcall mgr_prnt_table_cpm
237 rjmp mgr_prnt_size
238
239 mgr_prtb_nocpm:
240 #if FAT16_SUPPORT
241 ; FAT16 ?
242 cpi xl,dskType_FAT
243 brne mgr_prtb_nofat
244 rcall mgr_prnt_diskname
245 rcall mgr_prnt_table_fat
246 rjmp mgr_prnt_size
247 mgr_prtb_nofat:
248 #endif
249 #if 0 /* RAMDISK is not on SD card */
250 ; RAMDISK ?
251 cpi xl,dskType_RAM
252 brne mgr_prnt_err
253 rcall mgr_prnt_diskname
254 rcall mgr_prnt_table_ram
255 rjmp mgr_prnt_size
256 #endif
257 mgr_prnt_err:
258 ; Entry Error
259 rcall mgr_prnt_table_err
260 rjmp mgr_prnt_size
261
262 mgr_prnop:
263 rcall mgr_prnt_diskname
264 rcall mgr_prnt_image
265
266 mgr_prnt_size:
267 lcall print_ultoa
268 printstring ", size: "
269
270 ldd temp ,z+5 ;Get partition size
271 ldd temp2,z+6
272 ldi temp3,0
273 ldi temp4,0
274
275 lsr temp4
276 ror temp3
277 ror temp2
278 ror temp
279 lcall print_ultoa
280 printstring "KB."
281
282 mgr_goto_next_part:
283 adiw z,PARTENTRY_SIZE
284 inc xh
285 dec yl
286 brne pprl
287
288 mgr_pppre:
289 ret
290
291
292 mgr_prnt_diskname:
293 push temp
294 mov temp,xh
295 lcall uartputc
296 ldi temp,':'
297 lcall uartputc
298 pop temp
299 ret
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