From 02d57479e7411595d7b8b9507e63034d81091ad1 Mon Sep 17 00:00:00 2001 From: Leo Date: Fri, 19 Apr 2013 20:08:31 +0000 Subject: [PATCH] * FAT buffer on ATmega328 * avr/dsk_fsys.asm - Temporary buffer eliminated. (16 byte RAM saved) git-svn-id: svn://cu.loc/avr-cpm/avrcpm/trunk@212 57430480-672e-4586-8877-bcf8adbbf3b7 --- avr/config.inc | 1 + avr/dsk_fat16.asm | 62 +++++++++++++++++--- avr/dsk_fsys.asm | 141 ++++++++++++++++++++++++---------------------- avr/dsk_mgr.asm | 1 + avr/init.asm | 2 +- avr/mmc.asm | 11 ++-- 6 files changed, 140 insertions(+), 78 deletions(-) diff --git a/avr/config.inc b/avr/config.inc index 20dbf29..5e1304c 100644 --- a/avr/config.inc +++ b/avr/config.inc @@ -76,6 +76,7 @@ .equ MEMTEST = 1 .equ MEMFILL = 1 .equ MMC_DEBUG = 0 /* Increase for more debugging */ +.equ MMC_DEBUG_RDW = 0 .equ DSKSEL_DEBUG = 0 .equ DISK_DEBUG = 0 /* 1 = BOOT/HOME debug, 2 = +R/W debug */ .equ HOSTRW_DEBUG = 0 diff --git a/avr/dsk_fat16.asm b/avr/dsk_fat16.asm index 61f8165..d8ecd6f 100644 --- a/avr/dsk_fat16.asm +++ b/avr/dsk_fat16.asm @@ -84,6 +84,14 @@ fat_clust_ptr: .byte 4 ; sector of last real cluster .equ o_fat_clust_offset= 17 .equ o_fat_clust_ptr = 18 +.if SRAM_SIZE > 1024 + +fat_last_fatsect: .byte 1 + .equ o_fat_last_fatsect = 22 + +fat_buf: .byte 512 + +.endif ; ############################################################################ ; Start of Code Segment @@ -137,6 +145,10 @@ fat_reset_cache: std y+o_fat_log_clust ,_255 std y+o_fat_log_clust+1,_255 std y+o_fat_last_dsk ,_255 +.if SRAM_SIZE > 1024 + std y+o_fat_last_fatsect,_255 +.endif + ret ; ============================================================================ @@ -225,6 +237,7 @@ fat_scan_partition: ldd xh,z+1 ldd yl,z+2 ldd yh,z+3 + ldiw z,hostbuf ; Load first sector from Partition rcall mmcReadSect @@ -426,6 +439,7 @@ fat_next_sector_loop: sbc yh,_0 ; Load sector from Directory + ldiw z,hostbuf lcall mmcReadSect tst temp breq fat_look_for_images @@ -784,28 +798,62 @@ fat_next_phsy_clust: push xl push xh -; Create FAT Offset Value +; Create FAT Offset Value + clr zh mov zl,yl lsl zl rol zh -; Get FAT Start mov temp,yh - lds xl,fat_ptr2fat + +.if SRAM_SIZE > 1024 + +; Check, if required fat sector allready in buffer + + lds temp2,fat_last_fatsect + sts fat_last_fatsect,temp + cp temp,temp2 + breq fat_phys_1 + +; Not in buffer, get fat sector + + lds xl,fat_ptr2fat ;get FAT start lds xh,fat_ptr2fat+1 lds yl,fat_ptr2fat+2 lds yh,fat_ptr2fat+3 -; Add Cluster offset within sector - add xl,temp + add xl,temp ;add cluster offset within sector + adc xh,_0 + adc yl,_0 + adc yh,_0 + push zl + push zh + ldiw z,fat_buf + lcall mmcReadSect + pop zh + pop zl + +fat_phys_1: + ldiw y,fat_buf + add zl,yl + adc zh,yh + ldd yl,z+0 + ldd yh,z+1 +.else + + lds xl,fat_ptr2fat ;get FAT start + lds xh,fat_ptr2fat+1 + lds yl,fat_ptr2fat+2 + lds yh,fat_ptr2fat+3 + add xl,temp ;add cluster offset within sector adc xh,_0 adc yl,_0 adc yh,_0 lcall mmcReadWord - + movw y,z +.endif pop xh pop xl - movw y,z ; Check next logical Cluster diff --git a/avr/dsk_fsys.asm b/avr/dsk_fsys.asm index b9458ec..d298019 100644 --- a/avr/dsk_fsys.asm +++ b/avr/dsk_fsys.asm @@ -371,10 +371,6 @@ dskErrorRet: ; ==================================================================== - .dseg -tmpdpb: .byte 16 - - .cseg str_CPM_Disk: .db 10,"",0 @@ -434,34 +430,6 @@ dpbdat_simhd: ; #endif -; Copy the dpb data from flash memory, pointed to by Z, to temp ram. - -dpb_copy_p: - push yh - push yl - ldi temp2,16 - ldiw y,tmpdpb -cpydpb_pl: - lpm temp,z+ - st y+,temp - dec temp2 - brne cpydpb_pl - pop yl - pop yh - ret - -; Copy the dpb data, pointed to by Z to temp ram. - -dpb_copy: - st y+,temp - ldi temp2,15 -cpydpb_l: - ld temp,z+ - st y+,temp - dec temp2 - brne cpydpb_l - ret - ; ==================================================================== ; Function: get drive table entry pointer for drive # in temp @@ -598,10 +566,10 @@ dsk_tst_yaze: lcall strncmp_p brne dsk_tyze_not - ldiw z,hostbuf+32 - ldiw y,tmpdpb + ldiw z,hostbuf+31 + clt ;dpb in RAM ldi temp,1 ;1 sector header size - rcall dpb_copy + st z,temp ori temp,0xff ret @@ -643,6 +611,8 @@ dsk_tmyz80_loop: dec temp2 brne dsk_tmyz80_loop + ldiw z,dpbdat_myz80*2 + set ori temp,0xff ret @@ -693,6 +663,8 @@ dsk_tsimhd_loop: brne dsk_tsimhd_loop dsk_tsimhd_found: + ldiw z,dpbdat_simhd*2 + set ori temp,0xff ret @@ -732,22 +704,19 @@ dsk_format_get: ; Test for simhd format. rcall dsk_tst_simhd - ldiw z,dpbdat_simhd*2 - brne dsk_imgt_fixed + brne dsk_imgt_done ; Test for MyZ80 format. rcall dsk_tst_myz80 - ldiw z,dpbdat_myz80*2 - brne dsk_imgt_fixed + brne dsk_imgt_done ; No special image found. Use avrcpm. ldiw z,dpbdat_avrcpm*2 - -dsk_imgt_fixed: - rcall dpb_copy_p + set ori temp,0xff + dsk_imgt_done: ret @@ -769,30 +738,38 @@ dpb_imgdata_get: rcall dsk_format_get breq dpb_imgd_err ;no known format detected -; +dpb_imgd_0: + brtc dpb_imgd_variable +dpb_imgd_fixed: + lpm temp, z+ ;image header + lpm yl,z+ ;low(SPT) + lpm yh,z+ ;high(SPT) + lpm temp2,z+ ;BSH + rjmp dpb_imgd_common + +dpb_imgd_variable: + ld temp, z+ ;image header + ld yl,z+ ;low(SPT) + ld yh,z+ ;high(SPT) + ld temp2,z+ ;BSH + +dpb_imgd_common: mov zl,temp3 rcall dsk_getpartentry ;get partition entry - ldiw y,tmpdpb - -; std y+12,_0 ;Test: set check size to 0 -; std y+13,_0 + std z+PTAB_SPT,yl + tst yh ;more then 256 sectors per track? + brne dsk_imgprp_err ;todo: support 16 bit sector numbers + + andi temp2,0x0f + swap temp2 + std z+PTAB_BSH,temp2 - ldd temp,y+0 andi temp,~dskType_MASK ldd temp2,z+PTAB_TYPE andi temp2,dskType_MASK or temp,temp2 std z+PTAB_TYPE,temp - ldd temp,y+1 - std z+PTAB_SPT,temp - ldd temp,y+2 - tst temp ;more then 256 sectors per track? - brne dsk_imgprp_err ;todo: support 16 bit sector numbers - ldd temp2,y+3 - andi temp2,0x0f - swap temp2 - std z+PTAB_BSH,temp2 - + ori temp,255 ret @@ -866,22 +843,43 @@ dpb_di_1: breq dpb_di_err_p1 movw x,temp - ldiw z,tmpdpb+1 ;skip sector offset byte + adiw z,1 ;skip sector offset byte + push temp3 + ldi temp3,15 dpb_dicpl: - ld temp,z+ + brtc PC+2 ; + lpm temp,z+ + brts PC+2 ; + ld temp,z+ rcall dram_write_pp - cpi zl,low(tmpdpb + 16) + dec temp3 brne dpb_dicpl + pop temp3 sbiw x,15 + sbiw z,15 movw temp,x movw x,y adiw x,10 rcall dram_writew_pp ;DPB - + + brtc dpb_dicks_variable +dpb_dicks_fixed: + adiw z,5 + lpm _tmp0,z+ ;dsm + lpm _tmp1,z+ + adiw z,11-5-2 + lpm temp,z+ ;cks + lpm temp2,z+ + rjmp dpb_dicks_common +dpb_dicks_variable: + ldd _tmp0,z+5 ;dsm + ldd _tmp1,z+5+1 + ldd temp,z+11 ;cks + ldd temp2,z+11+1 + ; get mem for dir check vector - lds temp,tmpdpb+12 ;cks - lds temp2,tmpdpb+12+1 +dpb_dicks_common: cp temp,_0 cpc temp2,_0 breq dpb_dicks0 @@ -892,8 +890,7 @@ dpb_dicks0: ; get mem for alloc vector - lds temp,tmpdpb+6 ;dsm - lds temp2,tmpdpb+6+1 + movw temp,_tmp0 subi temp, low (-8) sbci temp2,high(-8) lsr temp2 @@ -1374,12 +1371,18 @@ dsk_match: dsk_writehost: .if HOSTRW_DEBUG +.if DISK_DEBUG == 0 + printnewline + printstring "Host write: " +.else printstring ", hst WR " +.endif .endif rcall dsk_hostparam breq dsk_hstwr_err + ldiw z,hostbuf rcall mmcWriteSect tst temp brne dsk_hstwr_err @@ -1408,12 +1411,18 @@ dsk_hstwr_err: dsk_readhost: .if HOSTRW_DEBUG +.if DISK_DEBUG == 0 + printnewline + printstring "Host read: " +.else printstring ", hst RD " +.endif .endif rcall dsk_hostparam breq dsk_hstrd_err + ldiw z,hostbuf rcall mmcReadSect tst temp brne dsk_hstrd_err diff --git a/avr/dsk_mgr.asm b/avr/dsk_mgr.asm index ca3013f..c9ff9e0 100644 --- a/avr/dsk_mgr.asm +++ b/avr/dsk_mgr.asm @@ -81,6 +81,7 @@ mgr_picl: ;Load first sector from MMC (boot sector) ldiw y,0 ; Sector 0 movw x,y + ldiw z,hostbuf lcall mmcReadSect tst temp breq mgr_check_bootsektor diff --git a/avr/init.asm b/avr/init.asm index df1cfcd..2d35ff5 100644 --- a/avr/init.asm +++ b/avr/init.asm @@ -220,8 +220,8 @@ ramtestend: .if MEMFILL ldiw x,0 + ldi temp,MEMFILL_VAL ramfillw: - ldi temp,MEMFILL_VAL rcall dram_write_pp brcc ramfillw .endif diff --git a/avr/mmc.asm b/avr/mmc.asm index 52134c3..3254046 100644 --- a/avr/mmc.asm +++ b/avr/mmc.asm @@ -539,7 +539,7 @@ mmcReadSect: mmcReadWord: -.if MMC_DEBUG > 1 +.if (MMC_DEBUG > 1) || (MMC_DEBUG_RDW > 0) printnewline printstring "mmcRdWord " .endif @@ -576,9 +576,6 @@ mmc_rw_common: rjmp mmc_rwexit_error mmc_rw_1: - ldiw y,hostbuf ;aarrrgh - sbrs temp3,MMC_RDWORD - movw z,y ldiw y,512 sbrs temp3,MMC_RDOP rjmp mmc_wroper @@ -649,6 +646,12 @@ mmc_rcvw_sto: out SPDR,_255 mov zh,temp +.if MMC_DEBUG_RDW > 0 + movw temp,z + lcall printhexw + printstring " " +.endif + ; discard the rest mmc_rcvw_rl2: -- 2.39.2