From ce520bff08cbc7d4ba629a68b585ff241dad8950 Mon Sep 17 00:00:00 2001 From: Leo Date: Tue, 16 Apr 2013 13:10:37 +0000 Subject: [PATCH] * New config option: CPMDSK_SUPPORT - System can now be built without CP/M partitions. (FAT-16 only) * avr/dsk_*.asm - refactored functions to remove commen code. git-svn-id: svn://cu.loc/avr-cpm/avrcpm/trunk@211 57430480-672e-4586-8877-bcf8adbbf3b7 --- avr/Makefile | 8 ++- avr/config.inc | 12 +++- avr/dsk_cpm.asm | 162 ++------------------------------------------ avr/dsk_fat16.asm | 162 ++------------------------------------------ avr/dsk_fsys.asm | 168 +++++++++++++++++++++++++++++++++++++--------- avr/dsk_mgr.asm | 67 ++++++++++++------ avr/svnrev.inc | 12 ++-- 7 files changed, 216 insertions(+), 375 deletions(-) diff --git a/avr/Makefile b/avr/Makefile index b4fdfdc..aadcb40 100644 --- a/avr/Makefile +++ b/avr/Makefile @@ -6,15 +6,16 @@ #Defining options here will override the defaults from the config file. #MCU = atmega88 -MCU = atmega328P +MCU = atmega328p #F_CPU = 20000000 #DRAM_8BIT = 0 #BAUD = 57600 #BAUD = 115200 -I2C_SUPPORT = 0 +#I2C_SUPPORT = 0 #ADC_SUPPORT = 0 #EM_Z80 = 0 #FAT16_SUPPORT = 0 +#CPMDSK_SUPPORT = 0 #MMCBOOTLOADER = 0 @@ -64,6 +65,9 @@ endif ifdef FAT16_SUPPORT CDEFS += -DFAT16_SUPPORT=$(FAT16_SUPPORT) endif +ifdef CPMDSK_SUPPORT + CDEFS += -DCPMDSK_SUPPORT=$(CPMDSK_SUPPORT) +endif ifdef MMCBOOTLOADER CDEFS += -DMMCBOOTLOADER=$(MMCBOOTLOADER) endif diff --git a/avr/config.inc b/avr/config.inc index 40bdaab..20dbf29 100644 --- a/avr/config.inc +++ b/avr/config.inc @@ -59,6 +59,10 @@ ; Uncomment and set to 0, if you need to save flash (ie. ATmega88). ;#define FAT16_SUPPORT 1 +; Uncomment and set to 0, if you don't want to use CP/M partitions. +; (Saves some bytes.) +;#define CPMDSK_SUPPORT 1 + ; Uncomment and set to 0, if you need to save flash. ;#define MMCBOOTLOADER 1 @@ -181,9 +185,13 @@ #define EM_Z80 1 /* Emulate Z80 if true, else 8080 */ #endif +#ifndef CPMDSK_SUPPORT + #define CPMDSK_SUPPORT 1 /* Include Support for CP/M partitions */ +#endif + #ifndef FAT16_SUPPORT - #define FAT16_SUPPORT 1 /* Include Support for FAT16 Partitions */ -#endif /* which may contain CP/M image files. */ + #define FAT16_SUPPORT 1 /* Include Support for a FAT16 partition */ +#endif /* which may contain CP/M image files. */ #ifndef RAMDISKCNT #define RAMDISKCNT 0 /* Number of RAM disks */ diff --git a/avr/dsk_cpm.asm b/avr/dsk_cpm.asm index 4ef4af2..91cd434 100644 --- a/avr/dsk_cpm.asm +++ b/avr/dsk_cpm.asm @@ -20,174 +20,24 @@ ; $Id$ ; -#ifndef CPMDSK_SUPPORT - #define CPMDSK_SUPPORT 1 -#endif - #if CPMDSK_SUPPORT -;----------------------------------------------- Start of Code Segment .cseg -; ==================================================================== -; Function: Does a Disk write operation -; ==================================================================== -; Parameters -; -------------------------------------------------------------------- -; Registers : none -; Variables : [r] seekdsk Number of Disk to Read -; [r] seeksec Sector to read -; [r] seektrk Track to read -; hostdsk = host disk #, (partition #) -; hostlba = host block #, relative to partition start -; Read/Write "hostsize" bytes to/from hostbuf -; -------------------------------------------------------------------- -; Description: -; ==================================================================== - -cpm_hostparam: - lds zl,hostdsk - -.if HOSTRW_DEBUG - mov temp,zl - subi temp,-('A') - lcall uartputc -.endif - - rcall dsk_getpartentry ; get partition entry - - lds temp,hostlba ; get sector to access - lds temp2,hostlba+1 - -.if HOSTRW_DEBUG - printstring ": lba " - push r15 - push r14 - clr r14 - clr r15 - lcall print_ultoa - pop r14 - pop r15 -.endif - - ldd xl,z+5 ; get disksize - ldd xh,z+6 - - cp temp,xl ; check given sector against disksize - cpc temp2,xh - brcs cpm_hp1 - -.if HOSTRW_DEBUG - printstring ", max: " - push r15 - push r14 - push temp2 - push temp - movw temp,x - clr r14 - clr r15 - lcall print_ultoa - pop temp - pop temp2 - pop r14 - pop r15 - printstring " " -.endif - - clr temp - ret - -cpm_hp1: - ldd xl,z+1 ; get startsector of partition - ldd xh,z+2 - ldd yl,z+3 - ldd yh,z+4 +cpm_lba_to_phys: + ldd temp ,z+PTAB_START+0 ; get startsector of partition + ldd temp2,z+PTAB_START+1 + ldd yl,z+PTAB_START+2 + ldd yh,z+PTAB_START+3 add xl,temp ; add offset to startsector adc xh,temp2 adc yl,_0 adc yh,_0 -.if HOSTRW_DEBUG - printstring ", abs " - push r15 - push r14 - push temp2 - push temp - movw temp,x - movw r14,y - lcall print_ultoa - pop temp - pop temp2 - pop r14 - pop r15 -.endif - - ori temp,255 -cpm_hpex: ret -; ==================================================================== -; Function: Does a Disk write operation -; ==================================================================== -; Parameters -; -------------------------------------------------------------------- -; Registers : none -; Variables : [r] seekdsk Number of Disk to Read -; [r] seeksec Sector to read -; [r] seektrk Track to read -; -------------------------------------------------------------------- -; Description: -; ==================================================================== - -cpm_writehost: -.if HOSTRW_DEBUG - printstring ", hst WR " -.endif - rcall cpm_hostparam - breq cpm_rdwr_err - - rcall mmcWriteSect - tst temp - brne cpm_rdwr_err - - rjmp cpm_rdwr_ok - - -; ==================================================================== -; Function: Does a Disk read operation -; ==================================================================== -; Parameters -; -------------------------------------------------------------------- -; Registers : none -; Variables : [r] seekdsk Number of Disk to Read -; [r] seeksec Sector to read -; [r] seektrk Track to read -; -------------------------------------------------------------------- -; Description: -; ==================================================================== - -cpm_readhost: -.if HOSTRW_DEBUG - printstring ", hst RD " -.endif - rcall cpm_hostparam - breq cpm_rdwr_err - - rcall mmcReadSect - tst temp - brne cpm_rdwr_err - -cpm_rdwr_ok: - sts erflag,_0 - ret - -cpm_rdwr_err: - sts erflag,_255 - ret - - ; ==================================================================== ; Function: Add's a CP/M Partition to the Partition table ; ==================================================================== @@ -232,7 +82,7 @@ cpm_add_prune: cpm_add_e: ret -#endif +#endif /* CPMDSK_SUPPORT */ ; vim:set ts=8 noet nowrap diff --git a/avr/dsk_fat16.asm b/avr/dsk_fat16.asm index 96ed44f..61f8165 100644 --- a/avr/dsk_fat16.asm +++ b/avr/dsk_fat16.asm @@ -857,64 +857,13 @@ fat_found_phsy_clust: ; sector. this gives the pointer to the sector to be read and or written. ; ============================================================================ -fat_hostparam: - lds zl,hostdsk - -.if HOSTRW_DEBUG - mov temp,zl - subi temp,-('A') - lcall uartputc -.endif - - rcall dsk_getpartentry ; get partition entry - - lds temp ,hostlba - lds temp2,hostlba+1 - - -.if HOSTRW_DEBUG - printstring ": lba " - push r15 - push r14 - clr r14 - clr r15 - lcall print_ultoa - pop r14 - pop r15 -.endif - ldd xl,z+5 ; get size of disk in sectors - ldd xh,z+6 - - cp temp,xl ; check given sector against disksize - cpc temp2,xh - brcs fat_hp1 - -.if HOSTRW_DEBUG - printstring ", max " - push r15 - push r14 - push temp2 - push temp - movw temp,x - clr r14 - clr r15 - lcall print_ultoa - pop temp - pop temp2 - pop r14 - pop r15 - printstring " " -.endif - - clr temp - ret +fat_lba_to_phys: -fat_hp1: ; ################# Get logical Number of Cluster within the imagefile ; printstring "calc log sector" -; Get logical Sectornumber from temp - movw x,temp +; Logical Sectornumber in x + movw temp,x mov yl,_0 mov yh,_0 ; Divide logical Sectornumber by size of Cluster in sectors @@ -1023,112 +972,9 @@ fat_add_offset: printnewline .endif -.if HOSTRW_DEBUG - printstring ", abs " - push r15 - push r14 - push temp2 - push temp - movw temp,x - movw r14,y - lcall print_ultoa - pop temp - pop temp2 - pop r14 - pop r15 -.endif - - ori temp,255 -fat_hpex: ret -; ============================================================================ -; Function: Does a Disk write operation -; ============================================================================ -; Registers: [out] temp Error-Variable ( 0= No Error) -; Variables: [in] hostdsk host disk #, (partition #) -; [in] hostlba host block #, relative to part.start -; [in] hostbuf Sector to be written -; ---------------------------------------------------------------------------- -; Description: -; This Routine writes a Sector to the Imagefile inside an FAT16 Partition. -; ============================================================================ - -fat_writehost: -.if HOSTRW_DEBUG - printstring ", hst WR " -.endif - rcall fat_hostparam - breq fat_rdwr_err - - lcall mmcWriteSect - tst temp - breq fat_rdwr_ok - - rjmp fat_rdwr_err ; skip disk change detection code - -; After a second thought, the following code doesn't make sense, because -; disk change (change of one or more disk images) can not reliably detected. -; At least with the existing code. - - - - rcall mgr_init_partitions - cbr temp,0x80 - breq fat_rdwr_err - - rcall fat_hostparam - breq fat_rdwr_err - lcall mmcWriteSect ; disabled till read is functioning - tst temp - brne fat_rdwr_err - rjmp fat_rdwr_ok - -fat_rdwr_ok: - sts erflag,_0 - ret - -fat_rdwr_err: - sts erflag,_255 - ret - -; ============================================================================ -; Function: Does a Disk read operation -; ============================================================================ -; Registers: none -; Variables: [in] hostdsk host disk #, (partition #) -; [in] hostlba host block #, relative to part.start -; [out] hostbuf Sector read by this routine -; ---------------------------------------------------------------------------- -; Description: -; This Routine reads a Sector from the Imagefile inside a FAT16 Partition. -; ============================================================================ - -fat_readhost: -.if HOSTRW_DEBUG - printstring ", hst RD " -.endif - - rcall fat_hostparam - breq fat_rdwr_err - - lcall mmcReadSect - tst temp - breq fat_rdwr_ok - - rjmp fat_rdwr_err ; skip disk change detection code - - rcall mgr_init_partitions - cbr temp,0x80 - breq fat_rdwr_err - - rcall fat_hostparam - breq fat_rdwr_err - lcall mmcReadSect - tst temp - brne fat_rdwr_err - -#endif +#endif /* FAT16_SUPPORT */ ; vim:set ts=8 noet nowrap diff --git a/avr/dsk_fsys.asm b/avr/dsk_fsys.asm index 12b2e7f..b9458ec 100644 --- a/avr/dsk_fsys.asm +++ b/avr/dsk_fsys.asm @@ -1370,24 +1370,26 @@ dsk_match: ; -------------------------------------------------------------------- ; Description: ; ==================================================================== + dsk_writehost: - lds zl,hostdsk - rcall dsk_getpartentry - ld temp,z - andi temp,dskType_MASK -#if FAT16_SUPPORT -; Is it a FAT16 Diskimage ? - cpi temp,dskType_FAT - brne PC+2 - rjmp fat_writehost -#endif +.if HOSTRW_DEBUG + printstring ", hst WR " +.endif -; Is it a CP/M Partition ? - cpi temp,dskType_CPM - brne PC+2 - rjmp cpm_writehost -; Disktype not supported -> Return + rcall dsk_hostparam + breq dsk_hstwr_err + + rcall mmcWriteSect + tst temp + brne dsk_hstwr_err + +dsk_hstwr_ok: + sts erflag,_0 + ret + +dsk_hstwr_err: + sts erflag,_255 ret ; ==================================================================== @@ -1402,36 +1404,140 @@ dsk_writehost: ; -------------------------------------------------------------------- ; Description: ; ==================================================================== + dsk_readhost: -#if 0 - printnewline - printstring "readhost" - ldiw z,biosdrvtbl - rcall dbg_hexdump_line - adiw z,16 - rcall dbg_hexdump_line -#endif - +.if HOSTRW_DEBUG + printstring ", hst RD " +.endif + + rcall dsk_hostparam + breq dsk_hstrd_err + + rcall mmcReadSect + tst temp + brne dsk_hstrd_err + +dsk_hstrd_ok: + sts erflag,_0 + ret + +dsk_hstrd_err: + sts erflag,_255 + ret + +; ==================================================================== +; Function: Does a Disk write operation +; ==================================================================== +; Parameters +; -------------------------------------------------------------------- +; Registers : none +; Variables : [r] seekdsk Number of Disk to Read +; [r] seeksec Sector to read +; [r] seektrk Track to read +; hostdsk = host disk #, (partition #) +; hostlba = host block #, relative to partition start +; Read/Write "hostsize" bytes to/from hostbuf +; -------------------------------------------------------------------- +; Description: +; ==================================================================== + +dsk_hostparam: + lds zl,hostdsk + +.if HOSTRW_DEBUG + mov temp,zl + subi temp,-('A') + lcall uartputc +.endif rcall dsk_getpartentry - ld temp,z + lds xl,hostlba ; get sector to access + lds xh,hostlba+1 + +.if HOSTRW_DEBUG + printstring ": lba " + push r15 + push r14 + clr r14 + clr r15 + movw temp,x + lcall print_ultoa + pop r14 + pop r15 +.endif + + ldd _tmp0,z+PTAB_SIZE ; get disksize + ldd _tmp1,z+PTAB_SIZE+1 + + cp xl,_tmp0 ; check given sector against disksize + cpc xh,_tmp1 + brcc dsk_hst_param_err + + ldd temp,z+PTAB_TYPE andi temp,dskType_MASK #if FAT16_SUPPORT ; Is it a FAT16 Diskimage ? cpi temp,dskType_FAT - brne PC+2 - rjmp fat_readhost + brne dsk_hstpar_nofat + rcall fat_lba_to_phys + rjmp dsk_hstpar_gotit +dsk_hstpar_nofat: #endif - +#if CPMDSK_SUPPORT ; Is it a CP/M Partition ? cpi temp,dskType_CPM - brne PC+2 - rjmp cpm_readhost -; Disktype not supported -> Return + brne dsk_hstpar_nocpm + rcall cpm_lba_to_phys + rjmp dsk_hstpar_gotit +dsk_hstpar_nocpm: +#endif +; Disktype not supported + rjmp dsk_hst_param_err + +dsk_hstpar_gotit: + +.if HOSTRW_DEBUG + printstring ", abs " + push r15 + push r14 + push temp2 + push temp + movw temp,x + movw r14,y + lcall print_ultoa + pop temp + pop temp2 + pop r14 + pop r15 +.endif + + ori temp,255 ret +dsk_hst_param_err: +.if HOSTRW_DEBUG + printstring ", max: " + push r15 + push r14 + push temp2 + push temp + movw temp,_tmp0 + clr r14 + clr r15 + lcall print_ultoa + pop temp + pop temp2 + pop r14 + pop r15 + printstring " " +.endif + + clr temp + ret + +; -------------------------------------------------------------------- ; vim:set ts=8 noet nowrap diff --git a/avr/dsk_mgr.asm b/avr/dsk_mgr.asm index f378da4..ca3013f 100644 --- a/avr/dsk_mgr.asm +++ b/avr/dsk_mgr.asm @@ -105,6 +105,8 @@ mgr_check_bootsektor: ;No MBR, no partition table ... +#if CPMDSK_SUPPORT + inc temp3 ;pretend we have one. sts ndisks,temp3 ldi temp,high((1<<16) * 128/512) @@ -120,10 +122,15 @@ mgr_check_bootsektor: ldi temp3,0 rcall dpb_imgdata_get +#endif /* CPMDSK_SUPPORT */ + rjmp mgr_pend -; Search for valid Partitions and ImageFiles mgr_search: + +#if CPMDSK_SUPPORT + +; Search for valid Partitions and ImageFiles ldiw z,hostbuf+510-64 ;Point to first byte of partition table mgr_ploop: @@ -146,6 +153,7 @@ mgr_nextp: adiw z,16 cpi zl,low(hostbuf+510) ;End of partition table reached? brne mgr_ploop +#endif /* CPMDSK_SUPPORT */ #if FAT16_SUPPORT @@ -174,7 +182,7 @@ mgr_nextp2: adiw zl,16 cpi zl,low(hostbuf+510) brne mgr_ploop2 -#endif +#endif /* FAT16_SUPPORT */ mgr_pend: clr temp3 @@ -205,12 +213,16 @@ mgr_pend2: ; ==================================================================== mgr_prnt_parttbl: + lds yl,ndisks + tst yl + brne ppr_doit + ret + +ppr_doit: push r15 push r14 ldiw z,hostparttbl - lds yl,ndisks ldi xh,'A' - pprl: printnewline @@ -219,23 +231,33 @@ pprl: ldd r14,z+3 ldd r15,z+4 +; Partitiontype examining + + ldd xl,z+0 + andi xl,dskType_MASK + +#if CPMDSK_SUPPORT + cp temp,_0 ;If zero ... cpc temp2,_0 cpc r14,_0 cpc r15,_0 - breq mgr_prnop ;... no partition table at 0 + brne mgr_prchkcpm ;... no partition table at 0 -; Partitiontype examining - ldd xl,z+0 - andi xl,dskType_MASK + rcall mgr_prnt_diskname + rcall mgr_prnt_image + rjmp mgr_prnt_size + +mgr_prchkcpm: ; CP/M ? cpi xl,dskType_CPM brne mgr_prtb_nocpm rcall mgr_prnt_diskname rcall mgr_prnt_table_cpm rjmp mgr_prnt_size - mgr_prtb_nocpm: +#endif + #if FAT16_SUPPORT ; FAT16 ? cpi xl,dskType_FAT @@ -245,22 +267,21 @@ mgr_prtb_nocpm: rjmp mgr_prnt_size mgr_prtb_nofat: #endif + #if 0 /* RAMDISK is not on SD card */ +#if RAMDISKCNT ; RAMDISK ? cpi xl,dskType_RAM - brne mgr_prnt_err + brne mgr_prnt_noramdisk rcall mgr_prnt_diskname rcall mgr_prnt_table_ram rjmp mgr_prnt_size +mgr_prnt_noramdisk: +#endif #endif -mgr_prnt_err: + ; Entry Error rcall mgr_prnt_table_err - rjmp mgr_prnt_size - -mgr_prnop: - rcall mgr_prnt_diskname - rcall mgr_prnt_image mgr_prnt_size: lcall print_ultoa @@ -295,10 +316,17 @@ mgr_prnt_diskname: pop temp ret +#if CPMDSK_SUPPORT mgr_prnt_table_cpm: printstring "CP/M partition at: " ret +mgr_prnt_image: + printstring "Assuming CP/M image at: " + ret +#endif + +#if FAT16_SUPPORT mgr_prnt_table_fat: printstring "FAT16 File-Image '" push temp @@ -308,17 +336,16 @@ mgr_prnt_table_fat: pop temp printstring "' at: " ret +#endif +#if RAMDISKCNT mgr_prnt_table_ram: printstring "Ramdisk at: " ret +#endif mgr_prnt_table_err: printstring "Unknown Entry at: " ret -mgr_prnt_image: - printstring "Assuming CP/M image at: " - ret - diff --git a/avr/svnrev.inc b/avr/svnrev.inc index e41b9a9..31be6d6 100644 --- a/avr/svnrev.inc +++ b/avr/svnrev.inc @@ -2,17 +2,17 @@ * (http://www.compuphase.com/svnrev.htm). * You should not modify it manually, as it may be re-generated. * - * $Revision: 208$ - * $Date: 2013-04-06$ + * $Revision: 210$ + * $Date: 2013-04-15$ */ #ifndef SVN_REV_H #define SVN_REV_H -#define SVN_REV 208 -#define SVN_REVSTR "208" -#define SVN_REVDATE "2013-04-06" -#define SVN_REVSTAMP 20130406L +#define SVN_REV 210 +#define SVN_REVSTR "210" +#define SVN_REVDATE "2013-04-15" +#define SVN_REVSTAMP 20130415L #define SVN_REVMODIFIED 0 #endif /* SVN_REV_H */ -- 2.39.2