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?
100 lds temp2,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
128 ldi temp4,4 ;Partition table has 4 entries.
135 ; Test for CP/M Partition
139 rcall cpm_add_partition
142 adiw y,PARTENTRY_SIZE
153 ; Test for FAT16 Partition
154 ldiw z,hostbuf+510-64 ;Point to first byte of partition table
161 ; Test for FAT Partition Type 1
162 cpi temp,PARTID1_FAT16
165 ; Test for FAT Partition Type 2
166 cpi temp,PARTID2_FAT16
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.
187 rcall dpb_imgdata_get
193 lds temp,ndisks ;return # of "disks"
198 ; ====================================================================
199 ; Function: Print partition table info
200 ; ====================================================================
202 ; --------------------------------------------------------------------
204 ; Variables : [r] hostparttbl Table with Partitioninformations
205 ; [r] hostparttbltop Pointer to the Top of the Table
206 ; --------------------------------------------------------------------
208 ; ====================================================================
216 ldd temp ,z+1 ;Get partition start
223 cp temp,_0 ;If zero ...
227 breq mgr_prnop ;... no partition table at 0
229 ; Partitiontype examining
235 rcall mgr_prnt_diskname
236 rcall mgr_prnt_table_cpm
244 rcall mgr_prnt_diskname
245 rcall mgr_prnt_table_fat
249 #if 0 /* RAMDISK is not on SD card */
253 rcall mgr_prnt_diskname
254 rcall mgr_prnt_table_ram
259 rcall mgr_prnt_table_err
263 rcall mgr_prnt_diskname
268 printstring ", size: "
270 ldd temp ,z+5 ;Get partition size
283 adiw z,PARTENTRY_SIZE
302 printstring "CP/M partition at: "
306 printstring "FAT16 File-Image at: "
310 printstring "Ramdisk at: "
314 printstring "Unknown Entry at: "
318 printstring "Assuming CP/M image at: "