-; Various Management functions for the Interaction with the File-\r
+; Various Management functions for the Interaction with the File-
; systems
;
; Copyright (C) 2010 Frank Zoll
; along with avrcpm. If not, see <http://www.gnu.org/licenses/>.
;
; $Id$
-;\r
-\r
-\r
-; ------------------------- Defines for the disk management Structures
-\r
+;
+
+
+;-------------------------- Defines for the disk management Structures
+
;----------------------------------------------- Start of Data Segment
- .dseg\r
-\r
-\r
-\r
+ .dseg
+
; ------------------------------- Start of Code Segment
- .cseg\r
-\r
-; ====================================================================\r
+ .cseg
+
+; ====================================================================
; Function: Scans a Disk for CP/M Partions
-; ====================================================================\r
-; Parameters\r
-; --------------------------------------------------------------------\r
-; Registers : none\r
-; Variables : [w] temp Status of Operation\r
-; (0x80 - Operation Failure )\r
-; (others - Operation Suceded)\r
-; --------------------------------------------------------------------\r
-; Description:\r
-; This Function scans an SD-Cards Boot-Sector for valid Partitions.\r
-; First all original CP/M Partitions will be usesed as Drives for\r
-; the CPM-System. Wenn all CP/M Partitions are found, a second\r
-; scann will be made. In the second Scan, the first FAT16 Partition\r
-; on the Disk will be used for a detailed analyses. If there\r
-; are any Files like "cpm_x.img" are found, these Files will be\r
-; used as Disks by the CP/M- System. ( x must be in the Range A to D )\r
+; ====================================================================
+; Parameters
+; --------------------------------------------------------------------
+;
+; Registers : [w] temp Number of disk images (raw and fat16) found.
+; + 0x80 if sd card changes. (not used, doesn't work)
+; SREG : Z according to temp
+; --------------------------------------------------------------------
+; Description:
+; This Function scans an SD-Cards Boot-Sector for valid Partitions.
+; First all original CP/M Partitions will be usesed as Drives for
+; the CPM-System. Wenn all CP/M Partitions are found, a second
+; scann will be made. In the second Scan, the first FAT16 Partition
+; on the Disk will be used for a detailed analyses. If there
+; are any Files like "cpm_x.img" are found, these Files will be
+; used as Disks by the CP/M- System. ( x must be in the Range A to D )
; ====================================================================
-mgr_init_partitions:\r
-\r
- sts ndisks,_0 ; Set Number of Disks to 0\r
-\r
-; Initialize temp partition table\r
- ldiw y,tmp_tbl
- ldi temp2,PARTENTRY_SIZE*MAXDISKS
+mgr_init_partitions:
+
+ sts ndisks,_0 ; Set Number of Disks to 0
+
+; Initialize partition table
+ ldiw y,hostparttbl
+ ldi temp2,PARTENTRY_SIZE*MAXDISKS
mgr_picl:
- st y+,_0
- dec temp2
- brne mgr_picl\r
-\r
+ st y+,_0
+ dec temp2
+ brne mgr_picl
+
; Start mmc Card interaction
- call mmcInit
+ lcall mmcInit
andi temp,MMCST_NOINIT & MMCST_NODISK
brne mgr_pierr
;Load first sector from MMC (boot sector)
ldiw y,0 ; Sector 0
movw x,y
- call mmcReadSect
- tst temp
+ lcall mmcReadSect
+ tst temp
breq mgr_check_bootsektor
mgr_pierr:
clr temp
- ret\r
-\r
-mgr_check_bootsektor:\r
-;Pointer to first temp table entry\r
- ldiw y,tmp_tbl
-;Test, if it has a valid MBR
+ ret
- ldiw z,hostbuf+510-1 ;Point to last byte of partition table
+mgr_check_bootsektor:
+;Pointer to first table entry
+ ldiw y,hostparttbl
+ ldi temp3,0 ;temp3 holds number of found disks (paritions)
- ldi temp3,0 ;temp3 holds number of found disks (paritions)
- ldd temp,z+1 ;MBR signature (0xAA55) at and of sector?
- ldd temp2,z+2
- ldi temp4,0xAA
- cpi temp,0x55
- cpc temp2,temp4
+;Test, if it has a valid MBR
+
+ lds temp,hostbuf+510 ;MBR signature (0xAA55) at and of sector?
+ lds temp2,hostbuf+510+1
+ ldi temp4,0xAA
+ cpi temp,0x55
+ cpc temp2,temp4
breq mgr_search
;No MBR, no partition table ...
- inc temp3 ;pretend we have one.
- ldi temp,high((1<<16) * 128/512)\r
- ldi temp2,dskType_CPM\r
- std y+0,temp2
- std y+1,_0 ;start at beginning of card
- std y+2,_0
- std y+3,_0
- std y+4,_0
- std y+5,_0 ;max CP/M 2.2 disk size
- std y+6,temp ;
- std y+7,_0
- std y+8,_0
- rjmp mgr_pend\r
-\r
-; Search for valid Partitions and ImageFiles \r
-mgr_search:\r
- sbiw z,63 ;Now at first byte of partition table
- ldi temp4,high(hostbuf+510)
-\r
+
+ inc temp3 ;pretend we have one.
+ sts ndisks,temp3
+ ldi temp,high((1<<16) * 128/512)
+ ldi temp2,dskType_CPM
+ std y+0,temp2
+ std y+1,_0 ;start at beginning of card
+ std y+2,_0
+ std y+3,_0
+ std y+4,_0
+ std y+5,_0 ;max CP/M 2.2 disk size
+ std y+6,temp ;
+ std y+7,_0
+ std y+8,_0
+ rjmp mgr_pend
+
+; Search for valid Partitions and ImageFiles
+mgr_search:
+ ldiw z,hostbuf+510-64 ;Point to first byte of partition table
+ ldi temp4,4 ;Partition table has 4 entries.
+
mgr_ploop:
-\r
-; Get Partitiontype\r
- ldd temp,z+PART_TYPE
-\r
-; Test for CP/M Partition\r
- cpi temp,PARTID_CPM
+
+; Get Partitiontype
+ ldd temp,z+PART_TYPE
+
+; Test for CP/M Partition
+ cpi temp,PARTID_CPM
brne mgr_nextp
rcall cpm_add_partition
-\r
- inc temp3
- cpi temp3,MAXDISKS
- breq mgr_pend\r
- rjmp mgr_nextp\r
+
+ inc temp3
+ sts ndisks,temp3
+ cpi temp3,MAXDISKS
+ breq mgr_pend
mgr_nextp:
adiw zl,16
- cpi zl,low(hostbuf+510)
- cpc zh,temp4
- brlo mgr_ploop\r
-\r
-; Test for FAT16 Partition\r
- ldiw z,hostbuf+510-1-63 ;Point to first byte of partition table
- ldi temp4,high(hostbuf+510)
-\r
+ dec temp4
+ brne mgr_ploop
+
+#if FAT16_SUPPORT
+
+; Test for FAT16 Partition
+ ldiw z,hostbuf+510-64 ;Point to first byte of partition table
+ ldi temp4,4
+
mgr_ploop2:
-\r
-; Get Partitiontype\r
- ldd temp,z+PART_TYPE
-\r
-; Test for FAT Partition\r
- cpi temp,PARTID_FAT16
+; Get Partitiontype
+ ldd temp,z+PART_TYPE
+
+; Test for FAT Partition Type 1
+ cpi temp,PARTID1_FAT16
+ breq mgr_fatfound
+
+; Test for FAT Partition Type 2
+ cpi temp,PARTID2_FAT16
brne mgr_nextp2
-
- rcall fat_add_partition
- rjmp mgr_pend\r
-
+mgr_fatfound:
+ rcall fat_add_partition
+ rcall fat_scan_partition
+ rcall fat_reset_cache
+ rjmp mgr_pend ;Stop after first FAT16 partition found.
+
mgr_nextp2:
adiw zl,16
- cpi zl,low(hostbuf+510)
- cpc zh,temp4
- brlo mgr_ploop2\r
-\r
-mgr_pend:\r
-\r
-; Initialize RAM-Disks\r
- rcall rdsk_add_partition\r
-\r
-;Store new partitions and check if the SD card has been changed.
-
- ldiw y,tmp_tbl
- ldiw z,hostparttbl
- ldi temp4,PARTENTRY_SIZE*MAXDISKS
- clt\r
-
-mgr_pcpl:
- ld temp,y+
- ld temp2,z
- st z+,temp
- cpse temp,temp2
- set
- dec temp4
- brne mgr_pcpl
-
- mov temp,temp3
- sts ndisks,temp
- brtc mgr_pcpe
-
- tst temp
- breq mgr_pcpe
-
-; SD card not changed.
- rcall fat_scan_partition\r
-\r
- lds temp,ndisks\r
- sbr temp,0x80
-
-mgr_pcpe:\r
-
- ret\r
-\r
-\r
-; ====================================================================\r
+ dec temp4
+ brne mgr_ploop2
+#endif
+
+mgr_pend:
+ lds temp,ndisks ;return # of "disks"
+ tst temp
+ ret
+
+
+; ====================================================================
; Function: Print partition table info
-; ====================================================================\r
-; Parameters\r
-; --------------------------------------------------------------------\r
-; Registers : none\r
-; Variables : [r] hostparttbl Table with Partitioninformations\r
-; [r] hostparttbltop Pointer to the Top of the Table\r
-; --------------------------------------------------------------------\r
-; Description:\r
-; ====================================================================\r
+; ====================================================================
+; Parameters
+; --------------------------------------------------------------------
+; Registers : none
+; Variables : [r] hostparttbl Table with Partitioninformations
+; [r] hostparttbltop Pointer to the Top of the Table
+; --------------------------------------------------------------------
+; Description:
+; ====================================================================
mgr_prnt_parttbl:
ldiw z,hostparttbl
+ lds yl,ndisks
+ ldi xh,'A'
+
pprl:
- ldd temp ,z+1 ;Get partition start
- ldd temp2,z+2
- ldd temp3,z+3
- ldd temp4,z+4
+ ldd temp ,z+1 ;Get partition start
+ ldd temp2,z+2
+ ldd temp3,z+3
+ ldd temp4,z+4
+
printnewline
- cp temp,_0 ;If zero ...
- cpc temp2,_0
- cpc temp3,_0
- cpc temp4,_0
+
+ cp temp,_0 ;If zero ...
+ cpc temp2,_0
+ cpc temp3,_0
+ cpc temp4,_0
breq mgr_prnop ;... no partition table at 0
-\r
-; Partitiontype examining\r
- ldd xl,z+0\r
-; CP/M ?\r
- cpi xl,dskType_CPM\r
- brne mgr_prtb_nocpm\r
+
+; Partitiontype examining
+ ldd xl,z+0
+; CP/M ?
+ cpi xl,dskType_CPM
+ brne mgr_prtb_nocpm
+ rcall mgr_prnt_diskname
rcall mgr_prnt_table_cpm
- rjmp mgr_prnt_size\r
-\r
-; FAT16 ?\r
+ rjmp mgr_prnt_size
+
mgr_prtb_nocpm:
- cpi xl,dskType_FAT\r
- brne mgr_prtb_nofat\r
+#if FAT16_SUPPORT
+; FAT16 ?
+ cpi xl,dskType_FAT
+ brne mgr_prtb_nofat
+ rcall mgr_prnt_diskname
rcall mgr_prnt_table_fat
rjmp mgr_prnt_size
-; RAMDISK ?\r
-mgr_prtb_nofat:\r
- cpi xl,dskType_RAM\r
- brne mgr_prnt_err\r
+mgr_prtb_nofat:
+#endif
+#if 0 /* RAMDISK is not on SD card */
+; RAMDISK ?
+ cpi xl,dskType_RAM
+ brne mgr_prnt_err
+ rcall mgr_prnt_diskname
rcall mgr_prnt_table_ram
- rjmp mgr_prnt_size\r
-; Entry Error\r
-mgr_prnt_err: \r
+ rjmp mgr_prnt_size
+#endif
+mgr_prnt_err:
+; Entry Error
rcall mgr_prnt_table_err
- rjmp mgr_prnt_size\r
-\r
+ rjmp mgr_prnt_size
+
mgr_prnop:
+ rcall mgr_prnt_diskname
rcall mgr_prnt_image
-\r
-mgr_prnt_size:\r
- rcall print_ultoa
+
+mgr_prnt_size:
+ lcall print_ultoa
printstring ", size: "
-\r
- ldd temp ,z+5 ;Get partition size
- ldd temp2,z+6 ;Get partition size
- ldd temp3,z+7 ;Get partition size
- ldd temp4,z+8 ;Get partition size
-
- lsr temp4
- ror temp3
- ror temp2
- ror temp
- rcall print_ultoa
- printstring "KB."\r
+
+ ldd temp ,z+5 ;Get partition size
+ ldd temp2,z+6
+ ldd temp3,z+7
+ ldd temp4,z+8
+
+ lsr temp4
+ ror temp3
+ ror temp2
+ ror temp
+ lcall print_ultoa
+ printstring "KB."
mgr_goto_next_part:
adiw z,PARTENTRY_SIZE
- ldi temp,high(hostparttbltop)
- cpi zl, low (hostparttbltop)
- cpc zh,temp
- brlo pprl
-\r
+ inc xh
+ dec yl
+ brne pprl
+
mgr_pppre:
ret
- \r
-\r
+
+
mgr_prnt_fatsize:
- rcall print_ultoa
+ lcall print_ultoa
printstring ", size: "
- \r
- ldd temp ,z+5 ;Get partition size
- ldd temp2,z+6 ;Get partition size
- ldd temp3,z+7 ;Get partition size
- ldd temp4,z+8 ;Get partition size
+
+ ldd temp ,z+5 ;Get partition size
+ ldd temp2,z+6
+ ldd temp3,z+7
+ ldd temp4,z+8
- rcall print_ultoa
+ lcall print_ultoa
printstring "BYTE."
- jmp mgr_goto_next_part\r
+ rjmp mgr_goto_next_part
+
+mgr_prnt_diskname:
+ push temp
+ mov temp,xh
+ lcall uartputc
+ ldi temp,':'
+ lcall uartputc
+ pop temp
+ ret
mgr_prnt_table_cpm:
printstring "CP/M partition at: "
- ret\r
-\r
+ ret
+
mgr_prnt_table_fat:
printstring "FAT16 File-Image at: "
- ret\r
-\r
+ ret
+
mgr_prnt_table_ram:
printstring "Ramdisk at: "
- ret\r
-\r
+ ret
+
mgr_prnt_table_err:
printstring "Unknown Entry at: "
- ret\r
+ ret
mgr_prnt_image:
printstring "Assuming CP/M image at: "
- ret\r
+ ret
+
-\r