From 2ccaac16ab91e647a42e4a558864751eeae63929 Mon Sep 17 00:00:00 2001 From: Leo Date: Sun, 14 Apr 2013 20:22:53 +0000 Subject: [PATCH] * avr/dsk_fsys.asm - Write to unallocated block bug now fixed. - Straightened up debug messages. git-svn-id: svn://cu.loc/avr-cpm/avrcpm/trunk@209 57430480-672e-4586-8877-bcf8adbbf3b7 --- avr/config.inc | 33 +++-- avr/dsk_cpm.asm | 14 +- avr/dsk_fat16.asm | 31 +--- avr/dsk_fsys.asm | 360 +++++++++++++++++++++------------------------- avr/init.asm | 7 +- avr/svnrev.inc | 12 +- 6 files changed, 207 insertions(+), 250 deletions(-) diff --git a/avr/config.inc b/avr/config.inc index 0618876..40bdaab 100644 --- a/avr/config.inc +++ b/avr/config.inc @@ -1,7 +1,7 @@ ; Configuration, hardware definition, ... ; ; Copyright (C) 2010 Sprite_tm -; Copyright (C) 2010 Leo C. +; Copyright (C) 2010,2012,2013 Leo C. ; ; This file is part of avrcpm. ; @@ -31,7 +31,7 @@ ; Supported MCUs are: atmega328P atmega168 atmega88 atmega8 ; Z80 emulation currently needs atmega328P, so this is the default. -;#define atmega328P +;#define atmega328p ; MCU frequency in Hz. ;#define F_CPU 20000000 @@ -62,6 +62,8 @@ ; Uncomment and set to 0, if you need to save flash. ;#define MMCBOOTLOADER 1 +; Uncomment to disable ADC support +;#define ADC_SUPPORT 0 ;----------------------------------------------------------------------- ;Debugging aids @@ -70,11 +72,11 @@ .equ MEMTEST = 1 .equ MEMFILL = 1 .equ MMC_DEBUG = 0 /* Increase for more debugging */ +.equ DSKSEL_DEBUG = 0 +.equ DISK_DEBUG = 0 /* 1 = BOOT/HOME debug, 2 = +R/W debug */ +.equ HOSTRW_DEBUG = 0 .equ FAT16_DEBUG = 0 -.equ FAT16_RWDEBUG = 0 .equ FAT16_DBG_FAT = 0 -.equ DISK_DEBUG = 0 /* Increase for more debugging */ -.equ HOSTRW_DEBUG = 0 .equ HEAP_DEBUG = 0 .equ PORT_DEBUG = 0 .equ INS_DEBUG = 0 @@ -85,6 +87,11 @@ ;----------------------------------------------------------------------- ; Z80/8080 Virtual Ports +#define READ_FUNC 7 +#define WRITE_FUNC 6 +#define BOOT_FUNC 5 +#define HOME_FUNC 4 + #define TIMERPORT 0x40 /* Base z80 port address for clock access */ #define TIMER_CTL TIMERPORT #define TIMER_MSECS TIMERPORT+1 @@ -110,8 +117,12 @@ #define I2CADRH 0x08 ; Simple ADC Interface -#define ADC80 0x17 -#define ADC81 0x18 +#define ADC80 0x17 /* Read Value from ADC6 Pin, 8 bit */ +#define ADC81 0x18 /* Read Value from ADC7 Pin, 8 bit */ +#define ADCTEMP 0x19 /* Read Value from Temp Sensor, 8 bit */ +#define ADCBGL 0x20 /* Read 1.1V Bandgap, 10 bit */ +#define ADCBGH 0x21 /* Read 1.1V Bandgap, 10 bit */ + ; Port-Expander PCF8574 #define PORT 0x80 @@ -163,15 +174,17 @@ #error "I2C_SUPPORT requires 8 bit DRAM (DRAM_8BIT=1)!" #endif #ifndef ADC_SUPPORT - #define ADC_SUPPORT 0 + #define ADC_SUPPORT 1 #endif #ifndef EM_Z80 #define EM_Z80 1 /* Emulate Z80 if true, else 8080 */ #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 FAT16 Partitions */ +#endif /* which may contain CP/M image files. */ + #ifndef RAMDISKCNT #define RAMDISKCNT 0 /* Number of RAM disks */ #endif diff --git a/avr/dsk_cpm.asm b/avr/dsk_cpm.asm index 0e7b274..4ef4af2 100644 --- a/avr/dsk_cpm.asm +++ b/avr/dsk_cpm.asm @@ -53,7 +53,6 @@ cpm_hostparam: mov temp,zl subi temp,-('A') lcall uartputc - printstring ": " .endif rcall dsk_getpartentry ; get partition entry @@ -62,7 +61,7 @@ cpm_hostparam: lds temp2,hostlba+1 .if HOSTRW_DEBUG - printstring "lba: " + printstring ": lba " push r15 push r14 clr r14 @@ -111,7 +110,7 @@ cpm_hp1: adc yh,_0 .if HOSTRW_DEBUG - printstring ", abs:" + printstring ", abs " push r15 push r14 push temp2 @@ -123,7 +122,6 @@ cpm_hp1: pop temp2 pop r14 pop r15 - printstring " " .endif ori temp,255 @@ -145,8 +143,7 @@ cpm_hpex: cpm_writehost: .if HOSTRW_DEBUG - printnewline - printstring "host write " + printstring ", hst WR " .endif rcall cpm_hostparam breq cpm_rdwr_err @@ -170,12 +167,11 @@ cpm_writehost: ; -------------------------------------------------------------------- ; Description: ; ==================================================================== + cpm_readhost: .if HOSTRW_DEBUG - printnewline - printstring "host read " + printstring ", hst RD " .endif - rcall cpm_hostparam breq cpm_rdwr_err diff --git a/avr/dsk_fat16.asm b/avr/dsk_fat16.asm index fd8715f..96ed44f 100644 --- a/avr/dsk_fat16.asm +++ b/avr/dsk_fat16.asm @@ -864,7 +864,6 @@ fat_hostparam: mov temp,zl subi temp,-('A') lcall uartputc - printstring ": " .endif rcall dsk_getpartentry ; get partition entry @@ -874,7 +873,7 @@ fat_hostparam: .if HOSTRW_DEBUG - printstring "lba: " + printstring ": lba " push r15 push r14 clr r14 @@ -892,7 +891,7 @@ fat_hostparam: brcs fat_hp1 .if HOSTRW_DEBUG - printstring ", max: " + printstring ", max " push r15 push r14 push temp2 @@ -1025,7 +1024,7 @@ fat_add_offset: .endif .if HOSTRW_DEBUG - printstring ", abs:" + printstring ", abs " push r15 push r14 push temp2 @@ -1037,7 +1036,6 @@ fat_add_offset: pop temp2 pop r14 pop r15 - printstring " " .endif ori temp,255 @@ -1058,8 +1056,7 @@ fat_hpex: fat_writehost: .if HOSTRW_DEBUG - printnewline - printstring "host write " + printstring ", hst WR " .endif rcall fat_hostparam breq fat_rdwr_err @@ -1109,30 +1106,12 @@ fat_rdwr_err: fat_readhost: .if HOSTRW_DEBUG - printnewline - printstring "host read " + printstring ", hst RD " .endif rcall fat_hostparam breq fat_rdwr_err - -.if FAT16_RWDEBUG > 0 - printstring "Read Image Sector:" - 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 - printnewline -.endif - lcall mmcReadSect tst temp breq fat_rdwr_ok diff --git a/avr/dsk_fsys.asm b/avr/dsk_fsys.asm index 228438f..ab792b9 100644 --- a/avr/dsk_fsys.asm +++ b/avr/dsk_fsys.asm @@ -20,7 +20,6 @@ ; $Id$ ; -.equ DSKSEL_DEBUG = 0 ; ---------------- Defines for the Filesystem Interface ------- @@ -64,11 +63,6 @@ .equ WRUAL = 2 ;write to unallocated .equ WRTMSK= 3 ;write type mask - .equ READ_FUNC = 7 - .equ WRITE_FUNC = 6 - .equ BOOT_FUNC = 5 - .equ HOME_FUNC = 4 - ;----------------------------------------------- Start of Data Segment .dseg @@ -91,14 +85,15 @@ seekdsk: .byte 1 ;seek disk number seektrk: .byte 2 ;seek track number seeksec: .byte 2 ;seek sector number dmaadr: .byte 2 ;last dma address +hostpart: .byte 1 ;part of hostbuf to transfer hdrsize: .byte 1 ;Image header size (offset) cpmspt: .byte 1 ;CP/M sectors per track secpblk: .byte 1 ;sectors per block (alloc size) unacnt: .byte 1 ;unalloc rec cnt unadsk: .byte 1 ;last unalloc disk -unatrk: .byte 2 ;last unalloc track -unasec: .byte 2 ;last unalloc sector +unalba: .byte 2 ;last unalloc disk block +unapart: .byte 1 ;last unalloc disk buffer part erflag: .byte 1 ;error reporting wrtype: .byte 1 ;write operation type @@ -128,12 +123,12 @@ dbg_prdrvtbl: lds xl,biosdrvtbl lds xh,biosdrvtbl+1 movw temp,x - rcall printhexw + lcall printhexw printstring "): " ldi temp3,16 dbg_pcpel: - rcall dram_readw_pp - rcall printhexw + lcall dram_readw_pp + lcall printhexw printstring " " dec temp3 brne dbg_pcpel @@ -148,19 +143,19 @@ dbg_print_biosd: printnewline lds temp,bcbadr lds temp2,bcbadr+1 - rcall printhexw + lcall printhexw printstring " " lds temp,biosdrvtbl lds temp2,biosdrvtbl+1 - rcall printhexw + lcall printhexw printstring " " lds temp,biosdirbuf lds temp2,biosdirbuf+1 - rcall printhexw + lcall printhexw printstring " " lds temp,biosenddat lds temp2,biosenddat+1 - rcall printhexw + lcall printhexw printstring " " ret .endif @@ -255,7 +250,7 @@ dskDiskCheck: .if DSKSEL_DEBUG printnewline printstring "DiskCheck: " - rcall printhexw + lcall printhexw .endif cpi temp,RAMDISKNR brsh dsk_dchrd ;maybe ramdisk @@ -299,7 +294,7 @@ dsk_dchpart1: .if DSKSEL_DEBUG printnewline printstring "Select: " - rcall printhex + lcall printhex .endif rcall dpb_drvtbl_entry_get or temp,temp2 ;if !0, drive is allready initialized @@ -315,7 +310,7 @@ dsk_dchend: rcall dpb_drvtbl_entry_get printstring ", " - rcall printhexw + lcall printhexw pop temp .endif @@ -927,7 +922,7 @@ dsk_setdrvparam: andi temp2,~dskType_MASK ;Lower nibble is image header size sts hdrsize,temp2 ldd temp2,z+PTAB_SPT - sts cpmspt,temp2 + sts cpmspt,temp2 ;CP/M sectors per track ldd temp2,z+PTAB_BSH swap temp2 andi temp2,0x0f @@ -937,7 +932,7 @@ dsk_sdrvpl: lsl _tmp0 dec temp2 brne dsk_sdrvpl - sts secpblk,_tmp0 + sts secpblk,_tmp0 ;Sectors per block ret @@ -946,58 +941,69 @@ dsk_sdrvpl: ; ==================================================================== ; Parameters ; -------------------------------------------------------------------- -; Registers : none -; Variables : [r] seeksec Sector to read -; [r] seektrk Track to read +; Registers : +; Variables : +; ; -------------------------------------------------------------------- ; Description: ; ==================================================================== + dskDoIt: .if DISK_DEBUG push temp + sbrc temp,HOME_FUNC + rjmp dskdbghome + sbrc temp,BOOT_FUNC + rjmp dskdbgboot +.if DISK_DEBUG > 1 sbrc temp,READ_FUNC - rjmp dskdbgr + rjmp dskdbgread sbrc temp,WRITE_FUNC - rjmp dskdbgw + rjmp dskdbgwrite +.endif rjmp dskdbge -dskdbgr: +dskdbgread: + printnewline + printstring "dsk RD: " + rjmp dskdbg1 +dskdbgwrite: + printnewline + printstring "dsk WR: " + rjmp dskdbg1 +dskdbghome: printnewline - printstring "Disk read: " + printstring " HOME: " rjmp dskdbg1 -dskdbgw: +dskdbgboot: printnewline - printstring "Disk write: " + printstring " BOOT: " dskdbg1: lds temp,seekdsk subi temp,-('A') rcall uartputc - printstring ": track " + printstring ": trk " lds temp2,seektrk+1 lds temp,seektrk lcall printhexw - printstring ", sector " + printstring ", sec " lds temp,seeksec lcall printhex - printstring ", dma-addr " + printstring ", dma " lds temp2,dmaadr+1 lds temp,dmaadr lcall printhexw - pop temp - push temp - sbrs temp,WRITE_FUNC - rjmp dskdbge - printstring " wrtype " - andi temp,3 - lcall printhex dskdbge: - pop temp + pop temp .endif + + sts erflag,_0 + ;See what has to be done. sbrc temp,READ_FUNC - rjmp dsk_read + rjmp dsk_readwrite sbrc temp,WRITE_FUNC - rjmp dsk_write + rjmp dsk_readwrite sbrc temp,HOME_FUNC rjmp dsk_home sbrc temp,BOOT_FUNC @@ -1021,117 +1027,120 @@ dsk_home: -; ==================================================================== -; Function: Does a Disk read operation -; ==================================================================== -; Parameters -; -------------------------------------------------------------------- -; Registers : in: temp -; Variables : [r] seekdsk Number of Disk to Read -; [r] seeksec Sector to read -; [r] seektrk Track to read -; -------------------------------------------------------------------- -; Description: -; ==================================================================== -dsk_read: - sts erflag,_0 - sbi flags,readop ; Set read operation flag - ;RAM disk? +dsk_readwrite: + +; RAM disk? + lds zl,seekdsk #if RAMDISKCNT cpi zl,RAMDISKNR - brlt PC+2 - rjmp rdsk_read + brlt dsk_rw_noramdisk + sbrc temp,WRITE_FUNC + rjmp rdsk_write + rjmp rdsk_read +dsk_rw_noramdisk: #endif - rcall dsk_getpartentry ; Get Paritiontableentry - ld temp,z ; Get Partitiontype - andi temp,dskType_MASK + rcall dsk_getpartentry ;Get Paritiontableentry + ld temp2,z ;Get Partitiontype + andi temp2,dskType_MASK ; Isn't it a Disk ? - cpi temp,dskType_None + + cpi temp2,dskType_None brne PC+2 - rjmp dsk_read_err + ret ;return error ; It must be a FAT16-Imagefile or CP/M Partition. - rcall dsk_setdrvparam ;todo: do this only if needed (disk change) + sbrc temp,WRITE_FUNC + rjmp dsk_write - sts unacnt,_0 + sbi flags,readop ;Set read operation flag sbi flags,rsflag ;must read data + sts unacnt,_0 ldi temp,WRUAL ;write type sts wrtype,temp ;treat as unalloc + rjmp dsk_rw - rjmp dsk_rwoper ;to perform the read - -dsk_read_err: - ret - -; ==================================================================== -; Function: Does a Disk write operation -; ==================================================================== -; Parameters -; -------------------------------------------------------------------- -; Registers : in: temp Write type -; Variables : [r] seekdsk Number of Disk to Read -; [r] seeksec Sector to read -; [r] seektrk Track to read -; -------------------------------------------------------------------- -; Description: -; ==================================================================== dsk_write: - ;write the selected sector - sts erflag,_0 - cbi flags,readop ; not a read operation - ;RAM disk? - lds zl,seekdsk -#if RAMDISKCNT - cpi zl,RAMDISKNR - brlt PC+2 - rjmp rdsk_write -#endif - rcall dsk_getpartentry ; Get Paritiontableentry - ld temp2,z ; Get Partitiontype - andi temp2,dskType_MASK + cbi flags,readop ;Not a read operation + andi temp,WRTMSK + sts wrtype,temp ;save write type +dsk_rw: + rcall dsk_setdrvparam ;todo: do this only if needed (disk change) -; Isn't it a Disk ? - cpi temp2,dskType_None - brne PC+2 - rjmp dsk_write_err +; Convert track/sector to an LBA address (in 128byte blocks) + lds xl,seeksec ; + ldi xh,0 ; + ldi temp3,0 ; + lds temp,hdrsize ;add image header size + add xl,temp ; + adc xh,_0 ; + lds temp2,cpmspt ; + lds temp,seektrk ; + mul temp,temp2 ; + add xl,r0 ; + adc xh,r1 ; + lds temp,seektrk+1 ; + mul temp,temp2 ; + add xh,r0 ;temp3:xh:xl := sec + trk * SectorsPerTrack + adc temp3,r1 ; + mov temp,xl + andi temp,SECMSK ;mask buffer number + sts hostpart,temp ;save for later -; It must be a FAT16-Imagefile or CP/M Partition. +; Convert from CP/M LBA blocks to host LBA blocks - rcall dsk_setdrvparam ;TODO: do this only if needed (disk change) + ldi temp,SECSHF +dsk_sh1: + lsr temp3 + ror xh + ror xl + dec temp + brne dsk_sh1 + ;todo: temp3 should be 0 here. + ;xh:xl = host block to seek +; + sbic flags,readop + rjmp dsk_rwoper ;to perform the read - andi temp,WRTMSK - sts wrtype,temp ;save write type +; Write operation + cbi flags,rsflag ;rsflag = 0 + lds temp,wrtype ; cpi temp,WRUAL ;write unallocated? brne dsk_chkuna ;check for unalloc ; write to unallocated, set parameters + lds temp,secpblk ;next unalloc recs (blocksize/128) + lds temp2,hostpart ; + sts unapart,temp2 ; + cpi temp2,0 ;cpm sector on phys. sector boundary? + breq dsk_una1 + sbi flags,rsflag ; no, rsflag = 1 subi temp,HOSTBLK ;don't write lds _tmp0,hdrsize ; in next bock add temp,_tmp0 ; if there is a header +dsk_una1: sts unacnt,temp lds temp,seekdsk ;disk to seek sts unadsk,temp ;unadsk = sekdsk - lds temp,seektrk - sts unatrk,temp ;unatrk = sectrk - lds temp,seektrk+1 - sts unatrk+1,temp ;unatrk = sectrk - lds temp,seeksec - sts unasec,temp ;unasec = seksec + sts unalba, xl ;unalba = seeklba (== hostlba) + sts unalba+1,xh + +; check for write to unallocated sector dsk_chkuna: - ;check for write to unallocated sector + lds temp,unacnt ;any unalloc remain? tst temp breq dsk_alloc ;skip if not ; more unallocated records remain + dec temp ;unacnt = unacnt-1 sts unacnt,temp lds temp,seekdsk ;same disk? @@ -1140,116 +1149,72 @@ dsk_chkuna: brne dsk_alloc ;skip if not ; disks are the same - lds temp,unatrk - lds temp2,unatrk+1 - lds _tmp0,seektrk - lds _tmp1,seektrk+1 - cp temp,_tmp0 ;seektrk = unatrk? - cpc temp2,_tmp1 + + lds temp,unalba + lds temp2,unalba+1 + cp temp,xl ;seeklba = unalba? + cpc temp2,xh brne dsk_alloc ;skip if not -; tracks are the same - lds temp,seeksec ;same sector? - lds temp2,unasec - cp temp,temp2 ;seeksec = unasec? +; block address is the same + + lds _tmp0,hostpart ;same part? + lds temp3,unapart + cp _tmp0,temp3 ;seekpart = unapart? brne dsk_alloc ;skip if not ; match, move to next sector for future ref - inc temp2 ;unasec = unasec+1 - sts unasec,temp2 - lds _tmp0,cpmspt - cp temp2,_tmp0 ;end of track? (count CP/M sectors) - brlo dsk_noovf ;skip if no overflow - -; overflow to next track - sts unasec,_0 ;unasec = 0 - lds temp,unatrk - lds temp2,unatrk+1 - subi temp, low(-1) ;unatrk = unatrk+1 + + inc temp3 ;next part + andi temp3,SECMSK + sts unapart,temp3 + brne dsk_noovf ;skip if no overflow + +; overflow to next block + + subi temp, low(-1) ;unalba = unalba+1 sbci temp2,high(-1) - sts unatrk,temp - sts unatrk+1,temp2 + sts unalba,temp + sts unalba+1,temp2 dsk_noovf: - cbi flags,rsflag ;rsflag = 0 rjmp dsk_rwoper ;to perform the write +; not an unallocated record, requires pre-read + dsk_alloc: - ;not an unallocated record, requires pre-read sts unacnt,_0 ;unacnt = 0 sbi flags,rsflag ;rsflag = 1 - rjmp dsk_rwoper -dsk_write_err: - ret -; ==================================================================== -; Function: Does a Disk read/write operation -; ==================================================================== -; Parameters -; -------------------------------------------------------------------- -; Registers : none -; Variables : [r] seekdsk Number of Disk to Read -; [r] seeksec Sector to read -; [r] seektrk Track to read -; -------------------------------------------------------------------- -; Description: -; ==================================================================== +; Enter here to perform the read/write + dsk_rwoper: - ;enter here to perform the read/write -.if DISK_DEBUG - printstring ", flags: " + +.if DISK_DEBUG > 1 + printstring ", flags|wtyp " in temp,flags + cbr temp,WRTMSK + lds _tmp0,wrtype + or temp,_tmp0 + lcall printhex + printstring ", buf " + lds temp,hostpart lcall printhex .endif -; Convert track/sector to an LBA address (in 128byte blocks) - - lds xl,seeksec ; - ldi xh,0 ; - ldi yl,0 ; - lds temp,hdrsize ;add image header size - add xl,temp ; - adc xh,_0 ; - lds temp,seektrk ; - lds temp2,seektrk+1 ; - lds temp3,cpmspt ; - mul temp,temp3 ; - add xl,r0 ; - adc xh,r1 ; - mul temp2,temp3 ; - add xh,r0 ;yl:xh:xl := sec + trk * SectorsPerTrack - adc yl,r1 ; - mov temp,xl - andi temp,SECMSK ;mask buffer number - push temp ;save for later - -; Convert from CP/M LBA blocks to host LBA blocks - ldi temp,SECSHF -dsk_sh1: - lsr yl - ror xh - ror xl - dec temp - brne dsk_sh1 - ;todo: yl should be 0 here. - ;xh:xl = host block to seek movw temp,x lds temp3,seekdsk rcall dsk_rw_hostbuf ; copy data to or from buffer + ldiw z,hostbuf - ldi temp,128 - pop temp2 ;get buffer number (which part of hostbuf) - mul temp2,temp + lds temp,hostpart ;get buffer number (which part of hostbuf) + ldi temp2,128 + mul temp,temp2 add zl,r0 ;offset in hostbuf adc zh,r1 -.if DISK_DEBUG > 2 - movw temp,r0 - printstring "; host buf adr: " - lcall printhexw -.endif lds xl,dmaadr lds xh,dmaadr+1 @@ -1304,11 +1269,12 @@ dsk_wdir1: ; -------------------------------------------------------------------- ; Description: ; ==================================================================== +; dsk_readhost_lba: -#if 0 +.if HOSTRW_DEBUG printnewline - printstring "readhst lba" -#endif + printstring "Readhost LBA" +.endif sbi flags,rsflag ;must read data rcall dsk_rw_hostbuf lds temp,erflag ;returns 0, if ok diff --git a/avr/init.asm b/avr/init.asm index 940b135..df1cfcd 100644 --- a/avr/init.asm +++ b/avr/init.asm @@ -253,7 +253,9 @@ boot_ipl2: printnewline printstring "Partinit done." - lcall dsk_inval_hostbuf ;init (de)blocking buffer +; Init (de)blocking buffer + + lcall dsk_inval_hostbuf ; Read first sector of first CP/M partition (ipl) @@ -269,7 +271,8 @@ boot_ipl2: ldiw x,IPLADDR stsw dmaadr,x - lcall dsk_read + ldi temp,1<