
TITLE RANREAD.COM -- Random block read of name file
cseg segment para 'code'
	assume cs:cseg, ds:cseg
	assume ss:cseg, es:cseg
	org    100h
begin:	jmp	main
;--------------------------------------------------
fcbrec	label byte	    ;FCB for disk file
fcbdriv	 db  0		    ;drive C
fcbname	 db  'namefile'	    ;file name
fcbext	 db  'dat'	    ;extension
fcbblk	 dw  0		    ;current block #
fcbrcsz	 dw  0		    ;record size
fcbflz	 dd  ?		    ;DOS file size
	 dw  ?		    ;DOS date
	 dt  ?		    ;DOS reserved
	 db  0		    ;current record #
fcbrnrc	 dd  0		    ;random record #

dskrecs	 db  1024 dup(?),'$' ;DTA for block rec.
endcode  db  0
norecs	 dw  25		     ;number of records

openmsg	 db  '*** open error ***',13,10,'$'
readmsg	 db  '*** read error ***',13,10,'$'
rowctr	 db  0
;--------------------------------------------------
main proc near
	mov	ax,cseg	
	mov	ds,ax	

	call	clrscn		;clear screen
	call	curs		;set cursor
	call	openb		;open file,set DTA
	cmp	endcode,0	;valid open?
	jnz	return		;no,exit
	call	readb		;read records
	call	dispb		;call display
return:	mov	ax,4c00h	;no,terminate
	int	21h
main endp
;	open disk file :
;--------------------------------------------------
openb proc near 
	mov	ah,0fh		;request open
	lea	dx,fcbrec
	int	21h
	cmp	al,0		;valid open ?
	jnz	b1		;no,error
	mov	fcbrcsz,20h	;record  size
	mov	ah,1ah
	lea	dx,dskrecs	;set address of DTA
	int	21h
	ret
b1:	lea	dx,openmsg
	call	errm
	ret
openb endp
;	read disk block :
;--------------------------------------------------
readb proc near
	mov	ah,27h		;random block read
	mov	cx,norecs	;number of record
	lea	dx,fcbrec
	int	21h
	mov	endcode,al	;save return condition
	ret
readb endp
;	display disk block :
;--------------------------------------------------
dispb proc near
	mov	ah,09		;request display
	lea	dx,dskrecs
	int	21h
	ret
dispb endp
;	clear screen routine :
;--------------------------------------------------
clrscn proc near
	mov	ax,0600h	;request scroll
	mov	bh,41h		;color(07 for BW)
	mov	cx,0
	mov	dx,184fh
	int	10h
	ret
clrscn endp
;	set cursor routine :
;--------------------------------------------------
curs proc near
	mov	ah,2		;request set
	mov	bh,0		;  cursor
	mov	dh,rowctr
	mov	dl,0
	int	10h
	inc	rowctr
	ret
curs endp
;	disk error routine :
;--------------------------------------------------
errm proc near
	mov	ah,09		;DX contains addr
	int	21h		;  of message
	mov	endcode,01
	ret
errm endp
;--------------------------------------------------
cseg ends
     end begin
