; ; Shows available space on disk/area (A) (in range 'A'..'P'). ; Print the free space remaining for the received file ; a,f,b,c,d,e,h,l kshow: sui 'A'; make numeric (0,1,2,etc.) push psw call dskset; find the proper allocation vector mvi c,curdpb call bdos; Get ^DPB in hl inx h inx h mov a,m; Get block shift sta blkshf inx h; Bump to block mask mov a,m inx h inx h mov e,m; Get max block # inx h mov d,m xchg shld blkmax; Save it ; " " ; Calculate # of K free on selected drive now pop psw; get drive back mov b,a; save mvi a,cpmver; Get CP/M version number call dos cpi 30h; 3.0? jc free20; Use old method if not mov e,b; Use new Compute Free Space BDOS call mvi a,getfre call dos mvi c,3; Answer is a 24-bit integer fre3l1: lxi h,tbuf+2; in 1st 3 bytes of DMA adr mvi b,3; Convert it from sectors to K ora a; By dividing by 8 fre3l2: mov a,m rar mov m,a dcx h dcr b jnz fre3l2; Loop for 3 bytes dcr c jnz fre3l1; Shift 3 times lhld tbuf; Now get result in K jmp savfre; Go store it ; ; Find free space available free20: mvi c,galloc; Get address of allocation vector call bdos xchg lhld blkmax; Get its length inx h lxi b,0; Init block count to 0 dcx d push d free2a: pop d inx d push d; Save alloc address ldax d mov d,a mvi e,8; Set to process 8 blocks free2b: mov a,d; Restore bits dcr e; Count down 8 bits jm free2a ral; Test bit jc free2c; block in use inx b free2c: mov d,a; Save bits dcx h; Count down blocks mov a,l ora h jnz free2b; more blocks pop d; Clear stack of allocation vector ptr. mov l,c; Copy block to HL mov h,b lda blkshf; Get block shift factor sui 3; Convert from sectors to K jz savfre; Skip shifts if 1K blocks... free2d: dad h; Multiply blocks by K/BLK dcr a jnz free2d ; " " ; Print the amount of free space remaining on the selected drive savfre: call decout call ilprt db 'k free space is available',0 ret ; ; -------------------------------