1 ; Various Management functions for the Interaction with the File-
4 ; Copyright (C) 2010 Frank Zoll
6 ; This file is part of avrcpm.
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.
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.
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/>.
25 ; -------------------------- Defines for the disk management Structures
27 ; Partition Table Structures
35 * (see http://www.win.tue.nl/~aeb/partitions/partition_types-1.html)
37 #define PARTID1_FAT16 0x0E
38 #define PARTID2_FAT16 0x06
39 #define PARTID_CPM 0x52
42 ; ------------------------------------------------ Start of Code Segment
45 ; ====================================================================
46 ; Function: Scans a Disk for CP/M Partions
47 ; ====================================================================
49 ; --------------------------------------------------------------------
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 ; --------------------------------------------------------------------
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 ; ====================================================================
66 sts ndisks,_0 ; Set Number of Disks to 0
68 ; Initialize partition table
70 ldi temp2,PARTENTRY_SIZE*MAXDISKS
76 ; Start mmc Card interaction
78 andi temp,MMCST_NOINIT | MMCST_NODISK
81 ;Load first sector from MMC (boot sector)
86 breq mgr_check_bootsektor
93 ;Pointer to first table entry
95 ldi temp3,0 ;temp3 holds number of found disks (paritions)
97 ;Test, if it has a valid MBR
99 lds temp,hostbuf+510 ;MBR signature (0xAA55) at and of sector?
101 lds temp,hostbuf+510+1
106 ;No MBR, no partition table ...
108 inc temp3 ;pretend we have one.
110 ldi temp,high((1<<16) * 128/512)
111 ldi temp2,dskType_CPM
113 std y+1,_0 ;start at beginning of card
117 std y+5,_0 ;max CP/M 2.2 disk size
121 rcall dpb_imgdata_get
125 ; Search for valid Partitions and ImageFiles
127 ldiw z,hostbuf+510-64 ;Point to first byte of partition table
134 ; Test for CP/M Partition
138 rcall cpm_add_partition
141 adiw y,PARTENTRY_SIZE
147 cpi zl,low(hostbuf+510) ;End of partition table reached?
152 ; Test for FAT16 Partition
153 ldiw z,hostbuf+510-64 ;Point to first byte of partition table
159 ; Test for FAT Partition Type 1
160 cpi temp,PARTID1_FAT16
163 ; Test for FAT Partition Type 2
164 cpi temp,PARTID2_FAT16
168 rcall fat_add_partition
169 rcall fat_scan_partition
170 rcall fat_reset_cache
171 rjmp mgr_pend ;Stop after first FAT16 partition found.
175 cpi zl,low(hostbuf+510)
185 rcall dpb_imgdata_get
190 lds temp,ndisks ;return # of "disks"
195 ; ====================================================================
196 ; Function: Print partition table info
197 ; ====================================================================
199 ; --------------------------------------------------------------------
201 ; Variables : [r] hostparttbl Table with Partitioninformations
202 ; [r] hostparttbltop Pointer to the Top of the Table
203 ; --------------------------------------------------------------------
205 ; ====================================================================
217 ldd temp ,z+1 ;Get partition start
222 cp temp,_0 ;If zero ...
226 breq mgr_prnop ;... no partition table at 0
228 ; Partitiontype examining
234 rcall mgr_prnt_diskname
235 rcall mgr_prnt_table_cpm
243 rcall mgr_prnt_diskname
244 rcall mgr_prnt_table_fat
248 #if 0 /* RAMDISK is not on SD card */
252 rcall mgr_prnt_diskname
253 rcall mgr_prnt_table_ram
258 rcall mgr_prnt_table_err
262 rcall mgr_prnt_diskname
267 printstring ", size: "
269 ldd temp ,z+5 ;Get partition size
279 adiw z,PARTENTRY_SIZE
300 printstring "CP/M partition at: "
304 printstring "FAT16 File-Image at: "
308 printstring "Ramdisk at: "
312 printstring "Unknown Entry at: "
316 printstring "Assuming CP/M image at: "