X-Git-Url: http://cloudbase.mooo.com/gitweb/avrcpm.git/blobdiff_plain/8b13b36c6542ac4fac3a69ae45f7e296f7754bdb..18938d0cc783a503ea04cdd0d804a87ebf178d33:/dsk_mgr.asm diff --git a/dsk_mgr.asm b/dsk_mgr.asm index ac9b0d4..e48052c 100644 --- a/dsk_mgr.asm +++ b/dsk_mgr.asm @@ -1,47 +1,50 @@ ; Various Management functions for the Interaction with the File- -; systems -; -; Copyright (C) 2010 Frank Zoll -; -; This file is part of avrcpm. -; -; avrcpm is free software: you can redistribute it and/or modify it -; under the terms of the GNU General Public License as published by -; the Free Software Foundation, either version 3 of the License, or -; (at your option) any later version. -; -; avrcpm is distributed in the hope that it will be useful, -; but WITHOUT ANY WARRANTY; without even the implied warranty of -; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -; GNU General Public License for more details. -; -; You should have received a copy of the GNU General Public License -; along with avrcpm. If not, see . -; -; $Id$ +; systems +; +; Copyright (C) 2010 Frank Zoll +; +; This file is part of avrcpm. +; +; avrcpm is free software: you can redistribute it and/or modify it +; under the terms of the GNU General Public License as published by +; the Free Software Foundation, either version 3 of the License, or +; (at your option) any later version. +; +; avrcpm is distributed in the hope that it will be useful, +; but WITHOUT ANY WARRANTY; without even the implied warranty of +; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +; GNU General Public License for more details. +; +; You should have received a copy of the GNU General Public License +; along with avrcpm. If not, see . +; +; $Id$ ; -; ------------------------- Defines for the disk management Structures +;-------------------------- Defines for the disk management Structures + +;----------------------------------------------- Start of Data Segment -;----------------------------------------------- Start of Data Segment - .dseg +; Partition table offsets: +tmp_tbl: + .byte PARTENTRY_SIZE*MAXDISKS -; ------------------------------- Start of Code Segment +; ------------------------------- Start of Code Segment .cseg ; ==================================================================== -; Function: Scans a Disk for CP/M Partions +; Function: Scans a Disk for CP/M Partions ; ==================================================================== ; Parameters ; -------------------------------------------------------------------- -; Registers : none -; Variables : [w] temp Status of Operation -; (0x80 - Operation Failure ) -; (others - Operation Suceded) +; +; 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. @@ -51,156 +54,180 @@ ; 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: sts ndisks,_0 ; Set Number of Disks to 0 ; Initialize temp partition table - ldiw y,tmp_tbl - ldi temp2,PARTENTRY_SIZE*MAXDISKS -mgr_picl: - st y+,_0 - dec temp2 + ldiw y,tmp_tbl + ldi temp2,PARTENTRY_SIZE*MAXDISKS +mgr_picl: + st y+,_0 + dec temp2 brne mgr_picl -; Start mmc Card interaction - call 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 - breq mgr_check_bootsektor - -mgr_pierr: - clr temp +; Start mmc Card interaction + 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 + lcall mmcReadSect + tst temp + breq mgr_check_bootsektor + +mgr_pierr: + clr temp ret mgr_check_bootsektor: ;Pointer to first temp table entry - ldiw y,tmp_tbl -;Test, if it has a valid MBR - - ldiw z,hostbuf+510-1 ;Point to last byte of partition table - - 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 - breq mgr_search - -;No MBR, no partition table ... - inc temp3 ;pretend we have one. + ldiw y,tmp_tbl +;Test, if it has a valid MBR + + ldiw z,hostbuf+510-1 ;Point to last byte of partition table + + 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 + breq mgr_search + +;No MBR, no partition table ... + inc temp3 ;pretend we have one. 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 + 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: - sbiw z,63 ;Now at first byte of partition table - ldi temp4,high(hostbuf+510) + sbiw z,63 ;Now at first byte of partition table + ldi temp4,high(hostbuf+510) -mgr_ploop: +mgr_ploop: ; Get Partitiontype - ldd temp,z+PART_TYPE + ldd temp,z+PART_TYPE ; Test for CP/M Partition - cpi temp,PARTID_CPM - brne mgr_nextp - - rcall cpm_add_partition + cpi temp,PARTID_CPM + brne mgr_nextp + + rcall cpm_add_partition - inc temp3 - cpi temp3,MAXDISKS + inc temp3 + cpi temp3,MAXDISKS breq mgr_pend - rjmp mgr_nextp - -mgr_nextp: - adiw zl,16 - cpi zl,low(hostbuf+510) - cpc zh,temp4 + +mgr_nextp: + adiw zl,16 + cpi zl,low(hostbuf+510) + cpc zh,temp4 brlo mgr_ploop +#if FAT16_SUPPORT + ; Test for FAT16 Partition - ldiw z,hostbuf+510-1-63 ;Point to first byte of partition table - ldi temp4,high(hostbuf+510) + ldiw z,hostbuf+510-1-63 ;Point to first byte of partition table + ldi temp4,high(hostbuf+510) -mgr_ploop2: +mgr_ploop2: ; Get Partitiontype - ldd temp,z+PART_TYPE - -; Test for FAT Partition - cpi temp,PARTID_FAT16 - brne mgr_nextp2 - - rcall fat_add_partition - + ldd temp,z+PART_TYPE + +; Test for FAT Partition Type 1 + cpi temp,PARTID1_FAT16 + brne mgr_nextp1 + + rcall fat_add_partition rjmp mgr_pend - -mgr_nextp2: - adiw zl,16 - cpi zl,low(hostbuf+510) - cpc zh,temp4 + +; Test for FAT Partition Type 2 +mgr_nextp1: + cpi temp,PARTID2_FAT16 + brne mgr_nextp2 + + rcall fat_add_partition + rjmp mgr_pend + +mgr_nextp2: + adiw zl,16 + cpi zl,low(hostbuf+510) + cpc zh,temp4 brlo mgr_ploop2 +#endif mgr_pend: +#if 0 /* ToDo: ramdisks are not in sd-card partitions */ ; Initialize RAM-Disks rcall rdsk_add_partition +#endif + +; Save ammount of found CP/M Partitions + sts ndisks,temp3 + tst temp3 + breq mgr_fat -;Store new partitions and check if the SD card has been changed. - - ldiw y,tmp_tbl - ldiw z,hostparttbl - ldi temp4,PARTENTRY_SIZE*MAXDISKS +;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 - -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. + +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 + +; SD card changed. + + tst temp + breq mgr_pcpe + +mgr_fat: +#if FAT16_SUPPORT rcall fat_scan_partition + rcall fat_reset_cache +#endif lds temp,ndisks - sbr temp,0x80 - + sbr temp,0x80 + mgr_pcpe: - + + + tst temp ret ; ==================================================================== -; Function: Print partition table info +; Function: Print partition table info ; ==================================================================== ; Parameters ; -------------------------------------------------------------------- @@ -210,108 +237,126 @@ mgr_pcpe: ; -------------------------------------------------------------------- ; Description: ; ==================================================================== - -mgr_prnt_parttbl: - ldiw z,hostparttbl -pprl: - 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 - breq mgr_prnop ;... no partition table at 0 + +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 + + printnewline + + cp temp,_0 ;If zero ... + cpc temp2,_0 + cpc temp3,_0 + cpc temp4,_0 + breq mgr_prnop ;... no partition table at 0 ; Partitiontype examining ldd xl,z+0 ; CP/M ? cpi xl,dskType_CPM brne mgr_prtb_nocpm - rcall mgr_prnt_table_cpm + rcall mgr_prnt_diskname + rcall mgr_prnt_table_cpm rjmp mgr_prnt_size ; FAT16 ? -mgr_prtb_nocpm: +mgr_prtb_nocpm: cpi xl,dskType_FAT brne mgr_prtb_nofat - rcall mgr_prnt_table_fat - rjmp mgr_prnt_size + rcall mgr_prnt_diskname + rcall mgr_prnt_table_fat + rjmp mgr_prnt_size ; RAMDISK ? mgr_prtb_nofat: cpi xl,dskType_RAM brne mgr_prnt_err - rcall mgr_prnt_table_ram + rcall mgr_prnt_diskname + rcall mgr_prnt_table_ram rjmp mgr_prnt_size ; Entry Error mgr_prnt_err: - rcall mgr_prnt_table_err + rcall mgr_prnt_table_err rjmp mgr_prnt_size -mgr_prnop: - rcall mgr_prnt_image +mgr_prnop: + rcall mgr_prnt_diskname + rcall mgr_prnt_image mgr_prnt_size: - rcall print_ultoa - printstring ", size: " - - 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 + call print_ultoa + printstring ", size: " + + 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 + call 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 - -mgr_pppre: - ret + +mgr_goto_next_part: + adiw z,PARTENTRY_SIZE + inc xh + dec yl + tst yl + brne pprl + +mgr_pppre: + ret -mgr_prnt_fatsize: - rcall print_ultoa - printstring ", size: " +mgr_prnt_fatsize: + lcall print_ultoa + printstring ", size: " - 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 - - rcall print_ultoa - printstring "BYTE." - - jmp mgr_goto_next_part - -mgr_prnt_table_cpm: - printstring "CP/M partition at: " + 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 + + lcall print_ultoa + printstring "BYTE." + + rjmp mgr_goto_next_part + +mgr_prnt_diskname: + push temp + mov temp,xh + call uartputc + ldi temp,':' + call uartputc + pop temp ret -mgr_prnt_table_fat: - printstring "FAT16 File-Image at: " +mgr_prnt_table_cpm: + printstring "CP/M partition at: " ret -mgr_prnt_table_ram: - printstring "Ramdisk at: " +mgr_prnt_table_fat: + printstring "FAT16 File-Image at: " ret -mgr_prnt_table_err: - printstring "Unknown Entry at: " +mgr_prnt_table_ram: + printstring "Ramdisk at: " ret - -mgr_prnt_image: - printstring "Assuming CP/M image at: " + +mgr_prnt_table_err: + printstring "Unknown Entry at: " ret - + +mgr_prnt_image: + printstring "Assuming CP/M image at: " + ret +