From 291049934bd3c4bf5defee60237aac3e17ce2049 Mon Sep 17 00:00:00 2001 From: Leo Date: Thu, 5 Aug 2010 09:32:02 +0000 Subject: [PATCH 1/1] * avr/z80.asm: - Save partition sizes and check if sector to be read or written is in partition range. - read/write functions return error code to Z80 bios. - Some bugfixes and cleanups in (de)blocking code. - DRAM refresh interupt does nothing, if read or write cycle is in progress. - print_ultoa saves all used registers. git-svn-id: svn://cu.loc/avr-cpm/trunk/avrcpm/avr@64 57430480-672e-4586-8877-bcf8adbbf3b7 --- Makefile | 7 +- z80.asm | 403 +++++++++++++++++++++++++++++++++---------------------- 2 files changed, 250 insertions(+), 160 deletions(-) diff --git a/Makefile b/Makefile index 1d0d5c3..cc3eaf1 100644 --- a/Makefile +++ b/Makefile @@ -6,14 +6,15 @@ MCU = atmega328P #F_CPU = 24576000 F_CPU = 20000000 -BAUD = 115200 -DRAM_DQ_ORDER = 1 +#BAUD = 19200 +BAUD = 57600 +#BAUD = 115200 TARGET = z80 ASRC = z80.asm # Place -D or -U options here -CDEFS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -D$(MCU) -DDRAM_DQ_ORDER=$(DRAM_DQ_ORDER) +CDEFS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -D$(MCU) WINEPATH = C:/Programme/Atmel/AVR\ Tools/AvrAssembler2 DEFS = $(WINEPATH)/Appnotes diff --git a/z80.asm b/z80.asm index 64f0786..3aca645 100644 --- a/z80.asm +++ b/z80.asm @@ -70,6 +70,7 @@ .equ BOOTWAIT = 1 .equ PORT_DEBUG = 0 .equ DISK_DEBUG = 0 +.equ HOSTRW_DEBUG= 0 .equ MEMFILL_CB = 1 .equ STACK_DBG = 0 .equ PRINT_PC = 0 @@ -461,8 +462,7 @@ ramfillw: boot_again: ldi yh,0 ldi yl,0 - ldi xh,0 - ldi xl,0 + movw x,y rcall mmcReadSect ;Test, if it has a valid MBR @@ -472,26 +472,27 @@ boot_again: ldi temp4,0xAA cpi temp,0x55 cpc temp2,temp4 + ldi opl,0 ;opl holds number of found disks (paritions) breq boot_part ;No MBR, no partition table ... - ldi opl,1 - sts ndisks,opl + inc opl ;pretend we have one. rjmp boot_ipl ;Search Partition Table for CP/M partitions boot_part: ldi zl,low(hostbuf+510-64) ldi zh,high(hostbuf+510-64) - ldi yl,low(hostdstart) - ldi yh,high(hostdstart) - ldi opl,0 + ldi yl,low(hostparttbl) + ldi yh,high(hostparttbl) ldi oph,high(hostbuf+510) boot_ploop: ldd temp,z+PART_TYPE cpi temp,PARTID brne boot_nextp +; Found a CP/M partition + ldd temp,z+PART_START st y+,temp ldd temp2,z+PART_START+1 @@ -507,9 +508,13 @@ boot_ploop: rcall printstr .db ", size: ",0,0 ldd temp,z+PART_SIZE + st y+,temp ldd temp2,z+PART_SIZE+1 + st y+,temp2 ldd temp3,z+PART_SIZE+2 + st y+,temp3 ldd temp4,z+PART_SIZE+3 + st y+,temp4 lsr temp4 ror temp3 ror temp2 @@ -519,7 +524,7 @@ boot_ploop: .db "KB.",13,0,0 inc opl - cpi temp2,MAXDISKS + cpi opl,MAXDISKS breq boot_pend boot_nextp: adiw zl,16 @@ -528,18 +533,17 @@ boot_nextp: brsh boot_pend rjmp boot_ploop boot_pend: - sts ndisks,opl ; Read first sector of first CP/M partition - lds xl,hostdstart - lds xh,hostdstart+1 - lds yl,hostdstart+2 - lds yh,hostdstart+3 + lds xl,hostparttbl + lds xh,hostparttbl+1 + lds yl,hostparttbl+2 + lds yh,hostparttbl+3 rcall mmcReadSect boot_ipl: - lds opl,ndisks + sts ndisks,opl tst opl brne boot_ipl2 rcall printstr @@ -600,13 +604,14 @@ notraceon: brsh noprintpc rcall printstr - .db "PC=",0 + .db 13,"PC=",0 mov temp,z_pch rcall printhex mov temp,z_pcl rcall printhex - ldi temp,10 - rcall uartputc + ldi temp,' ' +; ldi temp,10 +; rcall uartputc noprintpc: .endif @@ -793,9 +798,9 @@ seekdsk: .byte 1 ;seek disk number seektrk: .byte 2 ;seek track number seeksec: .byte 1 ;seek sector number +hostparttbl: .byte 8*MAXDISKS ; host partition table (start sector, sector count) hostdsk: .byte 1 ;host disk number hostlba: .byte 3 ;host sector number (relative to partition start) -hostdstart: .byte 4*MAXDISKS ; host disks start sector (partition) unacnt: .byte 1 ;unalloc rec cnt unadsk: .byte 1 ;last unalloc disk @@ -819,6 +824,8 @@ portRead: cpi temp2,15 breq dskDiskCheck + cpi temp2,22 + breq dskErrorRet cpi temp2,TIMER_MSECS brlo pr_noclock @@ -894,6 +901,14 @@ dskDiskCheck: brlt PC+2 ldi temp,0xff ;error return ret + +dsk_dchend: + ldi temp,0 + ret + +dskErrorRet: + lds temp,erflag + ret dskDiskSel: sts seekdsk,temp @@ -921,6 +936,52 @@ dskDmah: ret dskDoIt: +.if DISK_DEBUG + push temp + sbrc temp,READ_FUNC + rjmp dskdbgr + sbrc temp,WRITE_FUNC + rjmp dskdbgw + rjmp dskdbge + +dskdbgr: + rcall printstr + .db 13,"Disk read: ",0 + rjmp dskdbg1 +dskdbgw: + rcall printstr + .db 13,"Disk write: ",0 +dskdbg1: + lds temp,seekdsk + subi temp,-('A') + rcall uartputc + rcall printstr + .db ": track ",0,0 + lds temp,seektrk+1 + rcall printhex + lds temp,seektrk + rcall printhex + rcall printstr + .db " sector ",0,0 + lds temp,seeksec + rcall printhex + rcall printstr + .db " dma-addr ",0,0 + lds temp,dmaadr+1 + rcall printhex + lds temp,dmaadr + rcall printhex + pop temp + push temp + sbrs temp,WRITE_FUNC + rjmp dskdbge + rcall printstr + .db " wrtype ",0,0 + andi temp,3 + rcall printhex +dskdbge: + pop temp +.endif ;See what has to be done. sbrc temp,READ_FUNC rjmp dsk_read @@ -949,38 +1010,14 @@ dsk_home: dsk_read: -.if 0 - rcall timer_quit - rcall printstr - .db " In",0 -.endif + sbi flags,readop ;read operation + ;RAM disk? + lds temp2,seekdsk +; cpi temp2,RAMDISKNR +; brlt PC+2 +; rjmp rdskDoIt -.if DISK_DEBUG - push temp - rcall printstr - .db 13,0 - rcall printstr - .db "Disk read: track ",0 - lds temp,seektrk+1 - rcall printhex - lds temp,seektrk - rcall printhex - rcall printstr - .db " sector ",0,0 - lds temp,seeksec - rcall printhex - rcall printstr - .db " dma-addr ",0,0 - lds temp,dmaadr+1 - rcall printhex - lds temp,dmaadr - rcall printhex -; rcall printstr -; .db ".",13,0,0 - pop temp -.endif sts unacnt,_0 - sbi flags,readop ;read operation sbi flags,rsflag ;must read data ldi temp,WRUAL ;write type sts wrtype,temp ;treat as unalloc @@ -990,38 +1027,15 @@ dsk_read: dsk_write: ;write the selected CP/M sector - andi temp,WRTMSK - sts wrtype,temp ;save write type cbi flags,readop ;not a read operation -.if DISK_DEBUG - push temp - rcall printstr - .db 13,0 - rcall printstr - .db "Disk write: track ",0,0 - lds temp,seektrk+1 - rcall printhex - lds temp,seektrk - rcall printhex - rcall printstr - .db " sector ",0,0 - lds temp,seeksec - rcall printhex - rcall printstr - .db " dma-addr ",0,0 - lds temp,dmaadr+1 - rcall printhex - lds temp,dmaadr - rcall printhex - rcall printstr - .db " wrtype ",0,0 - lds temp,wrtype - rcall printhex -; rcall printstr -; .db ".",13,0,0 - pop temp -.endif + ;RAM disk? + lds temp2,seekdsk +; cpi temp2,RAMDISKNR +; brlt PC+2 +; rjmp rdskDoIt + andi temp,WRTMSK + sts wrtype,temp ;save write type cpi temp,WRUAL ;write unallocated? brne dsk_chkuna ;check for unalloc @@ -1097,6 +1111,12 @@ dsk_alloc: dsk_rwoper: ;enter here to perform the read/write +.if DISK_DEBUG + rcall printstr + .db ", flags: ",0 + in temp,flags + rcall printhex +.endif sts erflag,_0 ;no errors (yet) ;Convert track/sector to an LBA address (in 128byte blocks) @@ -1111,7 +1131,7 @@ dsk_rwoper: add xl,r0 ; adc xh,r1 ; mul temp4,temp ; - add xh,r0 ;xh:xl := sec + trk * SectorsPerTrack + add xh,r0 ;yl:xh:xl := sec + trk * SectorsPerTrack adc yl,r1 ; clr _0 @@ -1122,14 +1142,16 @@ dsk_rwoper: ;Convert from CP/M LBA blocks to host LBA blocks ldi temp,SECSHF dsk_sh1: - lsr xh + lsr yl + ror xh ror xl - ror yl dec temp brne dsk_sh1 ;yl:xh:xl = host block to seek ; active host sector? - sbis flags,hostact ;host active? + in _tmp,flags ;host active flag + sbi flags,hostact ;always becomes 1 + sbrs _tmp,hostact ;was it already? rjmp dsk_filhst ;fill host if not ; host buffer active, same as seek buffer? @@ -1149,8 +1171,15 @@ dsk_sh1: ; dsk_nomatch: ;proper disk, but not correct sector - sbic flags,hostwrt ;host written? + sbis flags,hostwrt ;host written? + rjmp dsk_filhst + push xl + push xh + push yl rcall dsk_writehost ;clear host buff + pop yl + pop xh + pop xl dsk_filhst: ;may have to fill the host buffer @@ -1165,7 +1194,6 @@ dsk_filhst: cbi flags,hostwrt ;no pending write dsk_match: - sbi flags,hostact ;host buffer active now ;copy data to or from buffer ldi zl,low(hostbuf) @@ -1175,7 +1203,7 @@ dsk_match: mul temp2,temp add zl,r0 ;offset in hostbuf adc zh,r1 -.if DISK_DEBUG +.if 0 ; DISK_DEBUG push r0 push r1 clr _0 @@ -1215,12 +1243,6 @@ dsk_rwmfin: lds temp,wrtype ;write type cpi temp,WRDIR ;to directory? breq dsk_wdir - lds temp,erflag -.if 0 - rcall timer_quit - rcall printstr - .db " Out",0 -.endif ret ;no further processing dsk_wdir: ; clear host buffer for directory write @@ -1231,86 +1253,142 @@ dsk_wdir: dsk_wdir1: rcall dsk_writehost ;clear host buff cbi flags,hostwrt ;buffer written - lds temp,erflag ret - -;***************************************************** -;* WRITEhost performs the physical write to * -;* the host disk, READhost reads the physical * -;* disk. * ;***************************************************** -dsk_writehost: - ;hostdsk = host disk #, hostlba = host block #. - ;Write "hostsize" bytes from hostbuf and return - ;error flag in erflag. - ;Return erflag non-zero if error +; hostdsk = host disk #, (partition #) +; hostlba = host block #, relative to partition start +; Read/Write "hostsize" bytes to/from hostbuf - push yh - push yl - push xh - push xl - ldi zl,low(hostdstart) - ldi zh,high(hostdstart) + +dsk_hostparam: + ldi zl,low(hostparttbl) + ldi zh,high(hostparttbl) lds temp,hostdsk - lsl temp - lsl temp - add zl,temp - adc zh,_0 +.if HOSTRW_DEBUG + push temp + subi temp,-('A') + rcall uartputc + rcall printstr + .db ": ",0,0 + pop temp +.endif + + lsl temp + lsl temp + lsl temp + add zl,temp + adc zh,_0 + + lds temp,hostlba + lds temp2,hostlba+1 + lds temp3,hostlba+2 + +.if HOSTRW_DEBUG + rcall printstr + .db "lba: ",0 + clr temp4 + rcall print_ultoa +.endif + + ldd xl,z+4 + ldd xh,z+5 + ldd yl,z+6 + + cp temp,xl + cpc temp2,xh + cpc temp3,yl + brcs dsk_hp1 + +.if HOSTRW_DEBUG + rcall printstr + .db ", max: ",0 + push temp4 + push temp3 + push temp2 + push temp + movw temp,x + mov temp3,yl + clr temp4 + rcall print_ultoa + pop temp + pop temp2 + pop temp3 + pop temp4 + rcall printstr + .db " ",0 +.endif + clr temp + ret + +dsk_hp1: ldd xl,z+0 ldd xh,z+1 ldd yl,z+2 ldd yh,z+3 - lds temp,hostlba + add xl,temp - lds temp,hostlba+1 - adc xh,temp - lds temp,hostlba+2 - adc zl,temp + adc xh,temp2 + adc zl,temp3 adc zh,_0 +.if HOSTRW_DEBUG + rcall printstr + .db ", abs:",0,0 + push temp4 + push temp3 + push temp2 + push temp + movw temp,x + movw temp3,y + rcall print_ultoa + pop temp + pop temp2 + pop temp3 + pop temp4 + rcall printstr + .db " ",0 +.endif + ori temp,255 +dsk_hpex: + ret + +;***************************************************** +;* WRITEhost performs the physical write to * +;* the host disk, READhost reads the physical * +;* disk. * +;***************************************************** + +dsk_writehost: +.if HOSTRW_DEBUG + rcall printstr + .db 13,"host write ",0,0 +.endif + rcall dsk_hostparam + brne dsk_wr1 + ldi temp,255 + sts erflag,temp + ret + +dsk_wr1: rcall mmcWriteSect - pop xl - pop xh - pop yl - pop yh sts erflag,_0 ret dsk_readhost: - ;hostdsk = host disk #, hostlba = host block #. - ;Read "hostsiz" bytes into hostbuf and return - ;error flag in erflag. - - push yh - push yl - push xh - push xl - ldi zl,low(hostdstart) - ldi zh,high(hostdstart) - lds temp,hostdsk - lsl temp - lsl temp - add zl,temp - adc zh,_0 - - ldd xl,z+0 - ldd xh,z+1 - ldd yl,z+2 - ldd yh,z+3 - lds temp,hostlba - add xl,temp - lds temp,hostlba+1 - adc xh,temp - lds temp,hostlba+2 - adc zl,temp - adc zh,_0 +.if HOSTRW_DEBUG + rcall printstr + .db 13,"host read ",0,0 +.endif + rcall dsk_hostparam + brne dsk_rd1 + ldi temp,255 + sts erflag,temp + ret + +dsk_rd1: rcall mmcReadSect - pop xl - pop xh - pop yl - pop yh sts erflag,_0 ret @@ -1821,8 +1899,11 @@ dram_write_w1: ; **************************************************************************** ; refresh interupt; exec 2 cbr cycles -refrint: - ;4 CAS RAS +refrint: ;4 + + sbis P_RAS,ram_ras ;2 + reti + ; CAS RAS cbi P_CAS,ram_cas ;2 1| 1| ; 1| 1| cbi P_RAS,ram_ras ;2 |0 1| @@ -2134,6 +2215,10 @@ print_ultoa: push yh push yl push z_flags + push temp4 + push temp3 + push temp2 + push temp clr yl ;yl = stack level @@ -2172,6 +2257,10 @@ ultoa6: pop temp ;Flush stacked digits dec yl brne ultoa6 + pop temp + pop temp2 + pop temp3 + pop temp4 pop z_flags pop yl pop yh @@ -2210,8 +2299,8 @@ printstr: push yh push yl push temp - in r29,sph - in r28,spl + in yh,sph + in yl,spl ldd zl,y+7 ldd zh,y+6 @@ -2317,7 +2406,7 @@ rxi_ov: ;endif uartgetc: lds temp,rxcount ; Number of characters in buffer tst temp - breq uartgetc + breq uartgetc ;Wait for char push zh push zl -- 2.39.2