From 6421790873fa5bdb8e1d525cac42764faf0f0af3 Mon Sep 17 00:00:00 2001 From: Frank Zoll Date: Sat, 2 Oct 2010 21:30:51 +0000 Subject: [PATCH 1/1] * avr/dsk_fat16.asm More than one disk image (Up to max # of CP/M disks). git-svn-id: svn://cu.loc/avr-cpm/trunk/avrcpm/avr@113 57430480-672e-4586-8877-bcf8adbbf3b7 --- Makefile | 35 +++++++--- config.inc | 4 +- dsk_fat16.asm | 178 ++++++++++++++++++++++++++++++++++++++++++-------- dsk_fsys.asm | 2 +- dsk_mgr.asm | 51 ++++++++++----- 5 files changed, 215 insertions(+), 55 deletions(-) diff --git a/Makefile b/Makefile index 9fa980f..c6f2b35 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,18 @@ BAUD = 57600 DRAM_8BIT = 1 TARGET = avrcpm -ASRC = avrcpm.asm +ASRC = avrcpm.asm + +ASRC += config.inc macros.inc init.asm dram-refresh.asm timer.asm utils.asm +ASRC += mmc.asm mmc-old.asm virt_ports.asm +ASRC += dsk_cpm.asm dsk_fat16.asm dsk_fsys.asm dsk_mgr.asm dsk_ram.asm +ASRC += 8080int.asm 8080int-jmp.asm 8080int-t3.asm 8080int-t3-jmp.asm + +ifneq ($(DRAM_8BIT),0) + ASRC += dram-8bit.inc dram-8bit.asm sw-uart.asm +else + ASRC += dram-4bit.inc dram-4bit.asm hw-uart.asm +endif # Place -D or -U options here CDEFS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -D$(MCU) -DDRAM_8BIT=$(DRAM_8BIT) @@ -55,19 +66,21 @@ MV = mv -f # Define all listing files. -LST = $(ASRC:.asm=.lst) +#LST = $(ASRC:.asm=.lst) # Combine all necessary flags and optional flags. # Add target processor to flags. ALL_ASFLAGS = $(ASFLAGS) +.PHONY: all hex eep lst map program flash eeprom tags clean + # Default target. all: hex lst -hex: $(TARGET).hex -eep: $(TARGET).eep -lst: $(TARGET).lst -map: $(TARGET).map +hex: $(TARGET).hex $(ASRC) +eep: $(TARGET).eep $(ASRC) +lst: $(TARGET).lst $(ASRC) +map: $(TARGET).map $(ASRC) # Program the device. @@ -81,8 +94,13 @@ eeprom: $(TARGET).hex $(TARGET).eep $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_EEPROM) +$(TARGET).hex: $(ASRC) +$(TARGET).eep: $(ASRC) +$(TARGET).lst: $(ASRC) +$(TARGET).map: $(ASRC) -.SUFFIXES: .hex .eep .lst +#.SUFFIXES: .hex .eep .lst +.SUFFIXES: %.hex: %.asm $(AS) $(ALL_ASFLAGS) -fI -o $@ $< @@ -102,6 +120,3 @@ tags: $(SRC) $(ASRC) clean: $(REMOVE) $(TARGET).hex $(TARGET).eep $(TARGET).obj $(TARGET).map $(TARGET).lst - -.PHONY: all hex eep lst map program flash eeprom tags clean - diff --git a/config.inc b/config.inc index 7035a43..1331f5b 100644 --- a/config.inc +++ b/config.inc @@ -63,9 +63,9 @@ .equ BOOT_DEBUG = 0 .equ MMC_DEBUG = 0 /* Increase for more debugging */ -.equ FAT16_DEBUG = 1 +.equ FAT16_DEBUG = 0 .equ FAT16_RWDEBUG = 0 -.equ FAT16_DBG_FAT = 1 +.equ FAT16_DBG_FAT = 0 .equ INS_DEBUG = 0 .equ MEMTEST = 1 .equ BOOTWAIT = 1 diff --git a/dsk_fat16.asm b/dsk_fat16.asm index a0c648d..ac4b2e8 100644 --- a/dsk_fat16.asm +++ b/dsk_fat16.asm @@ -40,6 +40,8 @@ #define FAT16_BSO_SECPERFAT 0x16 ; BootSectorOffset to Number of Sectors per Fat #define FAT16_BSO_NUMFATCP 0x10 ; BootSectorOffset to Ammount of FAT Copys #define FAT16_BSO_NUMDIRENT 0x11 ; BootSectorOffset to Max. Root Dir. Entrys +#define FAT16_FIRST_IMAGENAME 'A' +#define FAT16_LAST_IMAGENAME 'Z' ;-------------------------------- Start of Data Segment @@ -89,10 +91,27 @@ fat_init_partitiontable: st y+,_0 st y+,_0 st y+,_0 + ret + +; ==================================================================== +; Function: Resets the Cache +; ==================================================================== +; Parameters +; -------------------------------------------------------------------- +; Registers : none +; Variables : [r] seekdsk Number of Disk to Read +; [r] seeksec Sector to read +; [r] seektrk Track to read +; -------------------------------------------------------------------- +; Description: +; ==================================================================== +fat_reset_cache: + push yl ldi yl,0xFF sts fat_log_clust ,yl sts fat_log_clust+1,yl sts fat_last_dsk ,yl + pop yl ret ; ==================================================================== @@ -429,12 +448,38 @@ fat_calc_dp_lend: ; Here Starts the Scann of the Directory for valid image Files. +; Init Image-Namecounter + ldi temp,FAT16_FIRST_IMAGENAME + sts fat_last_dsk,temp + +fat_scan_for_next_image: + +; Init Offset into Directory-Sectors + ldi temp,0 + sts fat_clust_offset,temp + +; Init counter for number of entry left to scan + lds temp,fat_numdirentrys + sts fat_log_clust ,temp + + lds temp,fat_numdirentrys+1 + sts fat_log_clust+1,temp + +fat_next_sector_loop: +; Get a Pointer to the first Directory sector lds xl,fat_ptr2dir lds xh,fat_ptr2dir+1 lds yl,fat_ptr2dir+2 lds yh,fat_ptr2dir+3 -; Load first sector from Directory +; Add actual offset + lds temp,fat_clust_offset + add xl,temp + adc xh,_0 + adc yl,_0 + adc yh,_0 + +; Load sector from Directory call mmcReadSect tst temp breq fat_look_for_images @@ -478,6 +523,10 @@ fat_look_for_loop: cpi temp,'_' brne fat_look_not_ok + lds temp3,fat_last_dsk ; Get actual Diskname (A to Z) + ldd temp,z+7 + cp temp,temp3 + brne fat_look_not_ok ldd temp,z+8 cpi temp,'I' brne fat_look_not_ok @@ -490,12 +539,29 @@ fat_look_for_loop: cpi temp,'G' brne fat_look_not_ok + sts fat_clust_ptr ,zl + sts fat_clust_ptr+1,zh + sts fat_clust_ptr+2,temp2 jmp fat_store_new_entry +fat_scan_for_more: + + +.if FAT16_DEBUG > 1 + printstring "At:Scann for more ",0 + printnewline +.endif + + lds zl ,fat_clust_ptr + lds zh ,fat_clust_ptr+1 + lds temp2,fat_clust_ptr+2 fat_look_not_ok: - //ldi temp,32 - addiw z,32 +.if FAT16_DEBUG > 1 + printstring "+",0 +.endif + + adiw z,32 inc temp2 cpi temp2,16 ; max entrys/sector @@ -504,7 +570,50 @@ fat_look_not_ok: fat_scan_next_sector: - ret +.if FAT16_DEBUG > 1 + printstring "At:Scan next Sector",0 + printnewline +.endif + + lds temp3, fat_log_clust + lds temp4, fat_log_clust+1 + + sub temp3,temp2 + sbc temp4,_0 + + sts fat_log_clust,temp3 + sts fat_log_clust+1,temp4 + + cp temp3,_0 + cpc temp4,_0 + breq fat_scan_at_end + + lds temp,fat_clust_offset + inc temp + sts fat_clust_offset,temp + + rjmp fat_next_sector_loop + +fat_scan_at_end: + +.if FAT16_DEBUG > 1 + printstring "At:Scan at end",0 + printnewline +.endif + + lds temp,fat_last_dsk + inc temp + sts fat_last_dsk,temp + + ldi temp2,FAT16_LAST_IMAGENAME + cp temp,temp2 + brge fat_scaned_last_disk + + rjmp fat_scan_for_next_image + +fat_scaned_last_disk: + + rjmp fat_scan_end ; Create new Partition Entry @@ -512,7 +621,10 @@ fat_store_new_entry: ; Found a valid image .if FAT16_DEBUG > 1 - printstring "Found a valid Image ! ",0 + printstring "Found a valid Image ! Z=",0 + mov temp ,zl + mov temp2,zh + rcall printhexw printnewline .endif @@ -532,16 +644,28 @@ fat_look_store: ldi temp,dskType_FAT st y+,temp +.if FAT16_DEBUG > 1 + printstring "ClusterID",0 +.endif ; Offset to Startcluster + 2 ldd temp,z+0x1A st y+,temp +.if FAT16_DEBUG > 1 + rcall printhex +.endif ldd temp,z+0x1B st y+,temp +.if FAT16_DEBUG > 1 + rcall printhex +.endif ldi temp,0 st y+,temp st y+,temp +.if FAT16_DEBUG > 1 + printnewline +.endif -; Filesize in Bytes - 2,4,8,16,32,64,128,256,512 +; Filesize in Bytes ; ldd temp,z+0x1C ; st y+,temp ; ldd temp,z+0x1D @@ -569,33 +693,35 @@ fat_look_store: st y+,zl st y+,zh +.if FAT16_DEBUG > 1 +; Test finding of the first sector + + ldd xl,z+0x1A + ldd xh,z+0x1B + + rcall fat_gethostsec + + printstring "Begin of Image at: ",0 + mov temp ,yl + mov temp2,yh + rcall printhexw + mov temp ,xl + mov temp2,xh + rcall printhexw + printnewline + +.endif ; Check for another free entry in partition table lds temp,ndisks inc temp sts ndisks,temp + cpi temp,MAXDISKS + breq fat_scan_end -; Test finding of the first sector - ldd xl,z+0x1A - ldd xh,z+0x1B - ldi zl,0 - - rcall fat_gethostsec - -.if FAT16_DEBUG > 1 - printstring "Begin of Image at: ",0 - mov temp ,yl - mov temp2,yh - rcall printhexw - mov temp ,xl - mov temp2,xh - rcall printhexw - printnewline + jmp fat_scan_for_more -.endif - -; cp temp,MAXDISKS -; brne fat_scan_for_more +fat_scan_end: ret diff --git a/dsk_fsys.asm b/dsk_fsys.asm index 018aeba..6f2da7a 100644 --- a/dsk_fsys.asm +++ b/dsk_fsys.asm @@ -35,7 +35,7 @@ ;***************************************************** ;* CP/M to host disk constants * ;***************************************************** - .equ MAXDISKS = 4 ;Max number of Disks (partitions) + .equ MAXDISKS = 6 ;Max number of Disks (partitions) .equ PARTENTRY_SIZE = 9 ;Size of a Partitiontableentry .equ blksize = 1024 ;CP/M allocation size .equ hostsize = 512 ;host disk sector size diff --git a/dsk_mgr.asm b/dsk_mgr.asm index 8086d2f..38901cd 100644 --- a/dsk_mgr.asm +++ b/dsk_mgr.asm @@ -194,6 +194,7 @@ mgr_pcpl: #if FAT16_SUPPORT rcall fat_scan_partition + rcall fat_reset_cache #endif lds temp,ndisks sbr temp,0x80 @@ -217,19 +218,29 @@ mgr_pcpe: mgr_prnt_parttbl: ldiw z,hostparttbl -pprl: -; Partitiontype examining + lds yl,ndisks + ldi xh,'A' - ldd xl,z+0 -; Empty slot? - cpi xl,dskType_None - breq mgr_goto_next_part +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_diskname rcall mgr_prnt_table_cpm rjmp mgr_prnt_size @@ -237,12 +248,14 @@ pprl: mgr_prtb_nocpm: cpi xl,dskType_FAT brne mgr_prtb_nofat + 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_diskname rcall mgr_prnt_table_ram rjmp mgr_prnt_size ; Entry Error @@ -251,14 +264,11 @@ mgr_prnt_err: rjmp mgr_prnt_size mgr_prnop: + rcall mgr_prnt_diskname rcall mgr_prnt_image mgr_prnt_size: - ldd temp ,z+1 ;Get partition start - ldd temp2,z+2 - ldd temp3,z+3 - ldd temp4,z+4 - lcall print_ultoa + call print_ultoa printstring ", size: " ldd temp ,z+5 ;Get partition size @@ -270,15 +280,15 @@ mgr_prnt_size: ror temp3 ror temp2 ror temp - lcall print_ultoa + 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 + inc xh + dec yl + tst yl + brne pprl mgr_pppre: ret @@ -298,6 +308,15 @@ mgr_prnt_fatsize: 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_cpm: printstring "CP/M partition at: " ret -- 2.39.2