; SUBROUTINES FOR RLIB global blank,clsfil,conin,conout,crlf global defdu,delfil,doftyp,error,makfil,opnfil global rec2wr,rdrec,renfil,retud,setdma global typlin,wrrec,x128 .xlist .in libdef .list ;===================================================== ;calculate number of sectors to write out ;CALL WITH: ; HL = length of block ;RETURN WITH: ; DE = remainder ; L = number of sectors, rounded up rec2wr: call d128 ld a,e or d ;remainder? ret z ;ret if not inc l ;round up if so ret ;========================================================= x128: ;multiply value in A by 128. ;return A in HL, A*128 in BC ;net effect is a 7 times rotate left circular ;in a 16 bit field. ld l,a ;for return ld c,a xor a ;reset cy, get 0 ld h,a ;for return rr c ;9 bit rotate right ld b,c ld c,h ;free 0 rr c ret ;================================================= d128: ;divide contents of HL by 128 ;return with hl=hl/128, de=remainder ;shift hl left circular 1 place after ;saving the 7 low bits (the remainder) ;and then swapping h&l. This is the same ;as a 7 bit right shift! ld a,l and 7fh ;remainder ld e,a ;..in de ld a,l ;get it again and 80h ;discard remainder rla ;high bit in cy rl h ;cy to low bit, high bit to cy ld l,h ;equiv to shift right 7! ld h,a ;free zero rl h ;saved bit into low bit ret ;================================================= crlf: ld a,cr call conout ld a,lf call conout ret ;========================================================= blank: ld a,' ' call conout djnz blank ret ;========================================================= ; CONSOLE INPUT conin: ld a,1 jp bdosin ;================================================= ; WRITE CONSOLE conout: push de ld e,a ld a,2 call bdosin ld a,e pop de ret ;================================================= ; PRINT STRING TERMINATED BY BINARY 0 typlin: ld a,(de) inc de or a ret z call conout jr typlin ret ;================================================= ; FILE ACCESS ROUTINES ;================================================= ; OPEN FILE ; Z SET IF FILE NOT FOUND ;CALL WITH ; DE -> FCB opnfil: call setusr ld a,15 call bdosin cp 255 ret ;================================================= ; CLOSE FILE ;CALL WITH ; DE -> FCB clsfil: call setusr ld a,16 call bdosin cp 255 ret nz ld de,closer jp error closer: dz 'close error' ;================================================= ; MAKE FILE ;CALL WITH ; DE -> FCB makfil: call setusr ld a,22 call bdosin cp 255 ret nz jp dirful ;================================================= ; Set Random Record Field ;CALL WITH ; DE -> FCB setrr: ld a,36 ;bdos function number jp bdosin ;================================================= ; DELETE FILE ;CALL WITH ; DE -> FCB delfil: call setusr ld a,19 jp bdosin ;================================================= ; READ RANDOM RECORD ;CALL WITH ; DE -> FCB rdrand: call setusr ld a,33 ;bdos random read fn. call bdosin or a ret ;================================================= ; RENAME FILE ;CALL WITH ; DE -> FCB renfil: call setusr ld a,23 call bdosin cp 255 ret nz ld de,rener jp error rener: dz cr,lf,'rename error!' ;================================================= ; READ NEXT RECORD ;CALL WITH ; DE -> FCB rdrec: call setusr ld a,20 call bdosin or a ret z cp 2 ;check for eof ret c ;.. and return if so ld de,reader jr rwerr reader: db cr,lf,'read error = ',0 ;================================================= ; WRITE NEXT RECORD ;CALL WITH ; DE -> FCB wrrec: call setusr ld a,21 call bdosin or a ret z cp 255 jp z,dirful ld de,writer rwerr: push af ;save error value call typlin pop af or 30h ;make ascii call conout rst 0 writer: db cr,lf,'write error = ',0 ;================================================= ; SET DMA ADDRESS setdma: ld a,26 jp bdosin ; ret ;================================================= ;install the default filetype located at FCB-3 in the ;fcb filetype field if it is currently filled with spaces. ;on entry, DE -> initialized FCB ; HL -> default file type ;on exit, DE is preserved. Others are munched. doftyp: push de ex de,hl ld bc,9 add hl,bc ld a,' ' cp a,(hl) ;first char of file type field blank? jr nz,fcbtyx ;return if not. User has supplied type ex de,hl ;de -> fcb+9, hl -> def type ld bc,3 ;3 char to move ldir ;move 'em fcbtyx: pop de ;fcb address ret ;========================================================= ;set the user number to that in the byte ;just preceding the FCB setusr: dec de ld a,(de) inc de cp 0ffh ;use default user? jr nz,sua ; jp resusr ;================================================= ;restore the default user number resusr: push af ld a,(defdu) call sua pop af ret ;================================================= ;Return the default Drive/User, and store in (defdu) retud: call getdr ld b,a ;A...P = 0...15 call gua ld c,a inc b ;cnvrt to 1...16 ld (defdu),bc ret defdu: dw 10h ;drive a,user 0 default ;A...P = 1...16 ;================================================= ;set user area sua: push de and 1fh ;remove 3 msb to avoid ld e,a ;illegal user number ld a,32 call bdosin pop de ret ;================================================= ;get user area in A gua: push de ld e,-1 ld a,32 call bdosin pop de ret ;================================================= ;get current drive in A getdr: ld a,25 ; jr bdosin ;================================================= ; BDOS ENTRY ROUTINE bdosin: push hl push de push bc push ix push iy ld c,a ;set the function call 5 ;call dos for service pop iy pop ix pop bc pop de pop hl ret ; DIRECTORY FULL ERROR ENTRY POINT dirful: ld de,direr jp error direr: dz 'directory full' end