From 5482d75ffeb537629e1fe0a82c3eb22986dcbbc5 Mon Sep 17 00:00:00 2001 From: Leo Date: Sat, 9 Apr 2011 21:26:38 +0000 Subject: [PATCH] * cpm/ipl.mac - Load logical sectors ignoring track numbers. * cpm/bios.mac -Dynamic disk parameters for drives A - H. * avr/utils.asm, avr/init.asm, avr/virt_ports.asm, avr/dsk_cpm.asm, avr/dsk_fat16.asm, avr/dsk_mgr.asm - minor changes * avr/dsk_fsys.asm reorganization git-svn-id: svn://cu.loc/avr-cpm/avrcpm/trunk@162 57430480-672e-4586-8877-bcf8adbbf3b7 --- avr/dsk_cpm.asm | 7 +- avr/dsk_fat16.asm | 10 +- avr/dsk_fsys.asm | 311 ++++++++++++++++++++++++++------------------- avr/dsk_mgr.asm | 24 +++- avr/init.asm | 3 - avr/utils.asm | 20 +-- avr/virt_ports.asm | 6 +- cpm/bios.mac | 11 +- cpm/ipl.mac | 32 ++--- 9 files changed, 241 insertions(+), 183 deletions(-) diff --git a/avr/dsk_cpm.asm b/avr/dsk_cpm.asm index e154e4b..0999b79 100644 --- a/avr/dsk_cpm.asm +++ b/avr/dsk_cpm.asm @@ -87,7 +87,7 @@ cpm_hostparam: ; mov temp3,yl clr temp3 clr temp4 - rcall print_ultoa + lcall print_ultoa pop temp pop temp2 pop temp3 @@ -118,7 +118,7 @@ cpm_hp1: push temp movw temp,x movw temp3,y - rcall print_ultoa + lcall print_ultoa pop temp pop temp2 pop temp3 @@ -237,3 +237,6 @@ cpm_add_e: ret #endif + +; vim:set ts=8 noet nowrap + diff --git a/avr/dsk_fat16.asm b/avr/dsk_fat16.asm index 6a73bc4..f5516df 100644 --- a/avr/dsk_fat16.asm +++ b/avr/dsk_fat16.asm @@ -590,14 +590,14 @@ fat_store_new_entry: .endif ldiw y,hostparttbl - lds temp,ndisks + lds temp3,ndisks fat_look_store_loop: - cp temp,_0 + cp temp3,_0 breq fat_look_store adiw y,PARTENTRY_SIZE - dec temp + dec temp3 rjmp fat_look_store_loop fat_look_store: @@ -881,7 +881,7 @@ fat_hostparam: fat_hostlend: lds temp ,hostlba lds temp2,hostlba+1 - lds temp3,hostlba+2 +; lds temp3,hostlba+2 ldd xl,z+5 ; get size of disk in sectors @@ -1128,3 +1128,5 @@ fat_readhost: #endif +; vim:set ts=8 noet nowrap + diff --git a/avr/dsk_fsys.asm b/avr/dsk_fsys.asm index 2bf9d80..46389d2 100644 --- a/avr/dsk_fsys.asm +++ b/avr/dsk_fsys.asm @@ -98,13 +98,13 @@ 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 1 ;last unalloc sector +unasec: .byte 2 ;last unalloc sector erflag: .byte 1 ;error reporting wrtype: .byte 1 ;write operation type hostdsk: .byte 1 ;host disk number -hostlba: .byte 3 ;host sector number (relative to partition start) +hostlba: .byte 2 ;host sector number (relative to partition start) hostparttbl: .byte PARTENTRY_SIZE*MAXDISKS ;host partition table (type, start sector, sector count) hostparttbltop: hostbuf: .byte HOSTSIZE ;host buffer (from/to SD-card) @@ -165,6 +165,7 @@ dbg_print_biosd: ret .endif +; ==================================================================== ; ==================================================================== ; Function: Get a Pointer to a Partitiontable entry ; ==================================================================== @@ -186,6 +187,7 @@ dsk_getpartentry: add zh,_tmp1 ret +; ==================================================================== ; ==================================================================== ; Function: Virtual Port Interface ; ==================================================================== @@ -204,18 +206,14 @@ dsk_param_getadr: adc zh,_0 ret -dsk_param_wr: +dsk_param_set: rcall dsk_param_getadr st z,temp - cpi temp3,bcbadr+1-seektrk - brne dsk_param_wr1 - std z+1,_0 -dsk_param_wr1: cpi temp3,bcbadr+1-biospar_base breq SetBCB ret -dsk_param_rd: +dsk_param_get: cpi temp3,seekdsk-biospar_base breq dskDiskCheck rcall dsk_param_getadr @@ -234,7 +232,7 @@ sbcb_l: brne sbcb_l ; rcall dbg_print_biosd - rcall dpb_drvtblinit + rcall dpb_drvtblclear ; rcall dbg_prdrvtbl ret @@ -262,25 +260,38 @@ dskDiskCheck: cpi temp,RAMDISKNR brsh dsk_dchrd ;maybe ramdisk -; Check if selected disk # is less then # of disks. - - lds temp2,ndisks tst temp2 ;0 disks? brne dsk_dchpart1 ; No disks yet, need to init + rcall dpb_drvtblclear +.if 0 + ldi temp2,0x40 + ldi temp,1 + lcall clockput +.endif rcall mgr_init_partitions ;disk chanched? + push temp +.if 0 + ldi temp2,0x40 + ldi temp,2 + lcall clockput ; sbrs temp,7 ; rjmp dsk_dchpart0 - push temp - rcall dpb_drvtblinit + + lcall mgr_prnt_parttbl + printnewline +.endif + ; rcall dbg_prdrvtbl pop temp2 dsk_dchpart0: cbr temp2,0x80 lds temp,seekdsk +; Check if selected disk # is less then # of disks. + dsk_dchpart1: cp temp,temp2 brsh dsk_dch_err @@ -293,10 +304,11 @@ dsk_dchpart1: rcall dpb_drvtbl_entry_get or temp,temp2 ;if !0, drive is allready initialized brne dsk_dchend - lds temp,seekdsk - rcall dpb_diskinit - + lds temp3,seekdsk + mov temp,temp3 + rcall dpb_biosdph_get dsk_dchend: + .if DSKSEL_DEBUG push temp lds temp,seekdsk @@ -343,7 +355,8 @@ dskErrorRet: ret -; ------------------------------------------------------------------- +; ==================================================================== +; ==================================================================== .dseg @@ -406,7 +419,7 @@ dpbdat_simhd: ; #endif -; Copy the dpb data in flash memory, pointed to by Z to temp ram. +; Copy the dpb data from flash memory, pointed to by Z, to temp ram. dpb_copy_p: push yh @@ -520,36 +533,44 @@ dpb_drvtbl_entry_get: ; -dpb_drvtblinit: +dpb_drvtblclear: ldsw x,biosdrvtbl -; adiw x,2 + sbiw x,0 + breq dpb_drvi_ex + +dpb_drvi_1: ldi temp3,8 -dpb_drvi_l: +dpb_drvi_lp: ldi temp,0 ldi temp2,0 rcall dram_writew_pp dec temp3 - brne dpb_drvi_l + brne dpb_drvi_lp lds temp,biosenddat lds temp2,biosenddat+1 + cp temp,_0 + cpc temp2,_0 + breq dpb_drvi_ex + rcall heap_init +dpb_drvi_ex: clr temp ret ; ==================================================================== -; Function: +; Function: Test disk format: avrcpmhd ; ==================================================================== ; Parameters ; -------------------------------------------------------------------- ; Registers : temp drive # ; ; -------------------------------------------------------------------- -; Description: +; Description: Not implemented yet. ; ==================================================================== dsk_tst_avrcpmhd: - ori temp,0xff ; Test, return 'not found' for now. + clr temp ; Test, return 'not found' for now. ret @@ -603,11 +624,11 @@ dsk_tst_yaze: ldi temp,1 ;1 sector header size rcall dpb_copy - clr temp + ori temp,0xff ret dsk_tyze_not: - ori temp,0xff ;Not a YAZE disk image. + clr temp ;Not a YAZE disk image. ret ; ==================================================================== @@ -642,11 +663,11 @@ dsk_tmyz80_loop: dec temp2 brne dsk_tmyz80_loop - clr temp + ori temp,0xff ret dsk_tmyz80_not: - ori temp,0xff ;Not a MyZ80 hard disk image. + clr temp ;Not a MyZ80 hard disk image. ret ; ==================================================================== @@ -686,11 +707,11 @@ dsk_tsimhd_loop: dec temp2 brne dsk_tsimhd_loop - clr temp + ori temp,0xff ret dsk_tsimhd_not: - ori temp,0xff ;Not a simhd hard disk image. + clr temp ;Not a simhd hard disk image. ret ; ==================================================================== @@ -698,60 +719,73 @@ dsk_tsimhd_not: ; ==================================================================== ; Parameters ; -------------------------------------------------------------------- -; Registers : temp drive # +; Registers : temp3 drive # ; ; -------------------------------------------------------------------- ; Description: ; ==================================================================== -dsk_img_type: - -; todo: flush hostbuf! -; todo: flush hostbuf! +dsk_format_get: ; Get first sector (512 byte) of current drive into hostbuf. - push temp3 - mov temp3,temp + push temp3 ldi temp,0 ldi temp2,0 ; rcall dsk_readhost_lba - pop temp3 - push temp3 - ; Test for variable format avrcpmhd. rcall dsk_tst_avrcpmhd - breq dsk_img_prep + brne dsk_imgt_done ; Test for YAZE formats. rcall dsk_tst_yaze - breq dsk_img_prep + brne dsk_imgt_done ; Test for simhd format. rcall dsk_tst_simhd ldiw z,dpbdat_simhd*2 - breq dsk_img_fix + brne dsk_imgt_fixed ; Test for MyZ80 format. rcall dsk_tst_myz80 ldiw z,dpbdat_myz80*2 - breq dsk_img_fix + brne dsk_imgt_fixed ; No special image found. Use avrcpm. ldiw z,dpbdat_avrcpm*2 -dsk_img_fix: +dsk_imgt_fixed: rcall dpb_copy_p - -dsk_img_prep: + ori temp,0xff +dsk_imgt_done: + pop temp3 + ret - pop temp3 +; ==================================================================== +; Function: Add CP/M image format data to partition table data +; ==================================================================== +; Parameters +; -------------------------------------------------------------------- +; Registers : temp3 drive # +; +; -------------------------------------------------------------------- +; Description: +; ==================================================================== + +dpb_imgdata_get: + +; Test for known CP/M formats + + rcall dsk_format_get + breq dpb_imgd_err ;no known format detected + +; mov zl,temp3 rcall dsk_getpartentry ;get partition entry ldiw y,tmpdpb @@ -786,35 +820,47 @@ dsk_imgprp_err: printstring ": Format not supported: Too much sectors per track! " printnewline +dpb_imgd_err: clr temp ret -; ---------------------------------------------------------------------- -; Init CP/M data structures -; temp = drive # +; ==================================================================== +; Function: +; ==================================================================== +; Parameters +; -------------------------------------------------------------------- +; Registers : temp drive # +; +; return !0 if ok +; 0 on error +; -------------------------------------------------------------------- +; Description: Init CP/M data structures ; -; return !0 if ok -; 0 on error - +; ----------------------------------------------------------------- +; DPH: | XLT | | | |DIRBUF | DPB | CSV | ALV | +; ----------------------------------------------------------------- +;offset: 0 2 4 6 8 10 12 14 +; +; ------------------------------------------------------------- +; DPB: | SPT |BSH|BLM|EXM| DSM | DRM |AL0|AL1| CKS | OFF | +; ------------------------------------------------------------- +;offset: 0 5 7 11 13 +; ==================================================================== -dpb_diskinit: +dpb_biosdph_get: mov temp3,temp ;save disk # - rcall dsk_img_type + rcall dsk_format_get brne dpb_di_0 rjmp dpb_di_err dpb_di_0: ; get mem for DPH -; ----------------------------------------------------------------- -; DPH: | XLT | | | |DIRBUF | DPB | CSV | ALV | -; ----------------------------------------------------------------- -;(offset) 0 2 4 6 8 10 12 14 ldi temp, low (16) ldi temp2,high(16) - rcall heap_get + rcall heap_get ;returns ptr to dph mem brne dpb_di_1 rjmp dpb_di_err ; dpb_di_1: @@ -829,10 +875,6 @@ dpb_di_1: rcall dram_writew_pp ;DIRBUF ; get mem for DPB -; ------------------------------------------------------------- -; DPB: | SPT |BSH|BLM|EXM| DSM | DRM |AL0|AL1| CKS | OFF | -; ------------------------------------------------------------- -; 0 5 7 11 13 ldi temp, low (15) ldi temp2,high(15) @@ -1079,7 +1121,7 @@ dsk_write: #endif rcall dsk_getpartentry ; Get Paritiontableentry ld temp2,z ; Get Partitiontype - andi temp,dskType_MASK + andi temp2,dskType_MASK ; Isn't it a Disk ? cpi temp2,dskType_None @@ -1091,8 +1133,6 @@ dsk_write: rcall dsk_setdrvparam ;todo: do this only if needed (disk change) - cbi flags,readop ;not a read operation - andi temp,WRTMSK sts wrtype,temp ;save write type @@ -1188,8 +1228,6 @@ dsk_rwoper: in temp,flags rcall printhex .endif - sts erflag,_0 ;no errors (yet) - ;Convert track/sector to an LBA address (in 128byte blocks) lds xl,seeksec ; @@ -1220,53 +1258,11 @@ dsk_sh1: ror xl dec temp brne dsk_sh1 - ;yl:xh:xl = host block to seek -; active host sector? - in _tmp0,flags ;host active flag - sbi flags,hostact ;always becomes 1 - sbrs _tmp0,hostact ;was it already? - rjmp dsk_filhst ;fill host if not - -; host buffer active, same as seek buffer? - lds temp,seekdsk - lds temp2,hostdsk ;same disk? - cp temp,temp2 ;seekdsk = hostdsk? - brne dsk_nomatch - -; same disk, same block? - lds temp,hostlba - lds temp2,hostlba+1 - lds temp3,hostlba+2 - cp xl,temp - cpc xh,temp2 - cpc yl,temp3 - breq dsk_match -; -dsk_nomatch: - ;proper disk, but not correct sector - 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 - lds temp,seekdsk - sts hostdsk,temp - sts hostlba,xl - sts hostlba+1,xh - sts hostlba+2,yl - - sbic flags,rsflag ;need to read? - rcall dsk_readhost ;yes, if 1 - cbi flags,hostwrt ;no pending write - -dsk_match: + ;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 @@ -1277,11 +1273,8 @@ dsk_match: adc zh,r1 .if DISK_DEBUG > 2 - push r0 - push r1 + movw temp,r0 printstring "; host buf adr: " - pop temp2 - pop temp rcall printhexw .endif @@ -1336,16 +1329,73 @@ dsk_wdir1: ; Description: ; ==================================================================== dsk_readhost_lba: - sts hostlba+0,temp - sts hostlba+1,temp2 - sts hostlba+2,_0 - sts hostdsk,temp3 -#if 0 +#if 0 printnewline printstring "readhst lba" #endif - rjmp dsk_readhost ;returns 0, if ok + sbi flags,rsflag ;must read data + rcall dsk_rw_hostbuf + lds temp,erflag ;returns 0, if ok + tst temp + ret +; ==================================================================== +; Function: Get physical disk sector in hostbuf. +; ==================================================================== +; Parameters +; -------------------------------------------------------------------- +; Registers : temp2:temp host block to read/write (lba) +; temp3 disk # +; +; -------------------------------------------------------------------- +; Description: +; ==================================================================== +dsk_rw_hostbuf: + ;xh:xl = host block to seek + sts erflag,_0 ;no errors (yet) + +; active host sector? + in _tmp0,flags ;host active flag + sbi flags,hostact ;always becomes 1 + sbrs _tmp0,hostact ;was it already? + rjmp dsk_filhst ;fill host if not + +; host buffer active, same as seek buffer? + lds _tmp0,hostdsk ;same disk? + cp temp3,_tmp0 ;seekdsk = hostdsk? + brne dsk_nomatch + +; same disk, same block? + lds _tmp0,hostlba + lds _tmp1,hostlba+1 + cp temp,_tmp0 + cpc temp2,_tmp1 + breq dsk_match + +dsk_nomatch: + ;proper disk, but not correct sector + sbis flags,hostwrt ;host written? + rjmp dsk_filhst + push temp3 + push temp2 + push temp + rcall dsk_writehost ;clear host buff + pop temp + pop temp2 + pop temp3 + +dsk_filhst: + ;may have to fill the host buffer + sts hostlba,temp + sts hostlba+1,temp2 + sts hostdsk,temp3 + + sbic flags,rsflag ;need to read? + rcall dsk_readhost ;yes, if 1 + cbi flags,hostwrt ;no pending write + +dsk_match: + ret ; ==================================================================== ; Function: Does a Disk write operation @@ -1421,3 +1471,6 @@ dsk_readhost: ; Disktype not supported -> Return ret + +; vim:set ts=8 noet nowrap + diff --git a/avr/dsk_mgr.asm b/avr/dsk_mgr.asm index eefee45..f0a5702 100644 --- a/avr/dsk_mgr.asm +++ b/avr/dsk_mgr.asm @@ -116,8 +116,10 @@ mgr_check_bootsektor: std y+4,_0 std y+5,_0 ;max CP/M 2.2 disk size std y+6,temp ; -; std y+7,_0 -; std y+8,_0 + + ldi temp3,0 + rcall dpb_imgdata_get + rjmp mgr_pend ; Search for valid Partitions and ImageFiles @@ -134,8 +136,7 @@ mgr_ploop: cpi temp,PARTID_CPM brne mgr_nextp - rcall cpm_add_partition - + rcall cpm_add_partition inc temp3 sts ndisks,temp3 adiw y,PARTENTRY_SIZE @@ -143,7 +144,7 @@ mgr_ploop: breq mgr_pend mgr_nextp: - adiw zl,16 + adiw z,16 dec temp4 brne mgr_ploop @@ -178,7 +179,18 @@ mgr_nextp2: #endif mgr_pend: - lds temp,ndisks ;return # of "disks" + lds temp4,ndisks + clr temp3 +mgr_imgd_lp: + tst temp4 + breq mgr_pend2 + rcall dpb_imgdata_get + inc temp3 + dec temp4 + rjmp mgr_imgd_lp + +mgr_pend2: + lds temp,ndisks ;return # of "disks" tst temp ret diff --git a/avr/init.asm b/avr/init.asm index a1b80ac..e0b860a 100644 --- a/avr/init.asm +++ b/avr/init.asm @@ -223,9 +223,6 @@ boot_ipl2: printnewline printstring "Partinit done." - ldi temp,0 - rcall dsk_img_type ;parameter for boot disk image. - lcall dsk_inval_hostbuf ;init (de)blocking buffer ; Read first sector of first CP/M partition (ipl) diff --git a/avr/utils.asm b/avr/utils.asm index 4d8122a..0e7e0c3 100644 --- a/avr/utils.asm +++ b/avr/utils.asm @@ -165,17 +165,17 @@ dbg_hdp: ;Prints the zero-terminated string following the call statement. printstr: - push zh - push zl - push yh - push yl - push temp + push zh ;SP+5 + push zl ; 4 + push yh ; 3 + push yl ; 2 + push temp ; 1 in yh,sph in yl,spl - ldd zl,y+7 - ldd zh,y+6 + ldd zl,y+7 ;SP+7 == "return adr." == String adr. + ldd zh,y+6 ;SP+6 - lsl zl + lsl zl ;word to byte conv. rol zh printstr_loop: lpm temp,z+ @@ -189,8 +189,8 @@ printstr_loop: rjmp printstr_loop printstr_end: - adiw zl,1 ;rounding - lsr zh + adiw zl,1 ;rounding up + lsr zh ;byte to word conv. ror zl std y+7,zl diff --git a/avr/virt_ports.asm b/avr/virt_ports.asm index bffb78f..022d5d4 100644 --- a/avr/virt_ports.asm +++ b/avr/virt_ports.asm @@ -53,7 +53,7 @@ ;16 22 in - Result of last read/write operation. ; 0x00 = ok, 0xff = error (--> Bad Sector) ; -;40 64-71 in/out - Timer/Clock controll. +;40 64-71 in/out - Timer/Clock control. ;46 @@ -77,8 +77,8 @@ vport_tbl: .dw uartout .db 13,9 ; Port 13-21, (lenth 9) - .dw dsk_param_rd - .dw dsk_param_wr + .dw dsk_param_get + .dw dsk_param_set .db 22,1 .dw dskErrorRet .dw dskDoIt diff --git a/cpm/bios.mac b/cpm/bios.mac index 24d88ac..c477f56 100644 --- a/cpm/bios.mac +++ b/cpm/bios.mac @@ -50,18 +50,19 @@ wboote: ;Drive A B C D E F G H I J K L ;drvtbl: dtbl -drvtbl: dtbl +;drvtbl: dtbl +drvtbl: dtbl < , , , , , , , ,dphi,dphj,dphk,dphl> ; Name spt bls dks dir cks off - dpb dpb243, 26, 1024, 243, 64, 64, 2 - dpb dp8192s,32, 4096,2046, 512, 512, 2 - dpb dp8192, 32, 4096,2046,1024,1024, 2 +; dpb dpb243, 26, 1024, 243, 64, 64, 2 +; dpb dp8192s,32, 4096,2046, 512, 512, 2 +; dpb dp8192, 32, 4096,2046,1024,1024, 2 ; dpb dpbrd, 32, 1024, 56, 32, 0, 2 dpb rd1016, 32, 2048, 508, 192, 0, 2 dpb rd1024, 32, 2048, 512, 192, 0, 0 dpb rd0960, 32, 2048, 480, 192, 0, 0 -dpha: dph dpb243 +;dpha: dph dpb243 ;dphb: dph dpb243 ;dphc: dph dpb243 ;dphd: dph dpb243 diff --git a/cpm/ipl.mac b/cpm/ipl.mac index 93ab6b4..d3e631d 100644 --- a/cpm/ipl.mac +++ b/cpm/ipl.mac @@ -18,8 +18,8 @@ ; $Id$ ; -; IPL for the CP/M-emu in an AVR. Loads CPM from the 'disk' from -; track 0 sector 2 to track 1 sector 26. +; IPL for the CP/M-emu in an AVR. Loads CPM (CCP+BDOS+BIOS) from the 'disk'. +; Loads nsects (51) locical CPM sectors, starting from track 0 sector 2. maclib CFGACPM.LIB @@ -34,13 +34,15 @@ nsects equ 26*2 - 1 ;cold start sector count ld hl,msgipl call prmsg - ld b,nsects - ld de,0001h ;track 0, sector 1 ld hl,ccp + ld de,128 + ld c,1 ;sector 1 + ld b,nsects + xor a + out (16),a ;track 0 + out (17),a ; loadloop: - ld a,d ;track - out (16),a - ld a,e ;sector (base-0) + ld a,c ;sector (base-0) out (18),a ld a,l ;dma L out (20),a @@ -49,20 +51,8 @@ loadloop: ld a,1 shl READ_FUNC out (22),a - push bc - ld bc,128 - add hl,bc - pop bc - - inc e - ld a,e - cp 26 - jp nz,noNextTrack - - inc d - ld e,0 - -noNextTrack: + add hl,de + inc c dec b jp nz,loadloop -- 2.39.2