TITLE BIOREAD.COM -- Read disk sectors via BIOS
cseg segment para 'code'
	assume cs:cseg,ds:cseg,ss:cseg,es:cseg
	org	100h
begin:	jmp	main
;--------------------------------------------------
recdin	db  512 dup(' ')   ;input area
endcde	db  0
curadr	dw  0304h	   ;beginning track/sector
endadr	dw  0501h	   ;ending track/sector
readmsg	db  '*** read error ***$'
side	db  0
;--------------------------------------------------
main proc near
	mov	ax,cseg
	mov	ds,ax
	mov	es,ax
	mov	ax,0600h       ;request scroll
rept:	call	scren	       ;clear screen
	call	curs	       ;set cursor
	call	addrs	       ;calculate disk addr.
	mov	cx,curadr
	mov	dx,endadr
	cmp	cx,dx	       ;at end sector ?
	je	exit	       ;yes,exit
	call	reads	       ;read disk record
	cmp	endcde,0       ;normal read ?
	jnz	exit	       ;no,exit
	call	disps	       ;display sector
	jmp	rept	       ;repeat
exit:	mov	ax,4c00h       ;terminate
	int	21h
main endp
;	calculate next disk address
;--------------------------------------------------
addrs proc near
	mov	cx,curadr      ;get track/sector
	cmp	cl,10	       ;past last sector?
	jne	return	       ;no,exit
	cmp	side,0	       ;bypass if side 0
	je	chs
	inc	ch	       ;increment track
chs:	xor	side,01	       ;change side
	mov	cl,01	       ;set sector to 1
	mov	curadr,cx
return:	ret
addrs endp
;	read disk sector
;--------------------------------------------------
reads proc near
	mov	al,01	       ;No. of sector
	mov	ah,02	       ;request read
	lea	bx,recdin      ;addr of buffer
	mov	cx,curadr      ;track/sector
	mov	dh,side	       ;side
	mov	dl,01	       ;drive B
	int	13h
	cmp	ah,0	       ;normal read ?
	jz	incrt	       ;yes,exit
	mov	endcde,01      ;no
	call	errm	       ;invalid read
incrt:	inc	curadr	       ;increment sector
	ret
reads endp
;	display sector
;--------------------------------------------------
disps proc near
	mov	ah,40h	       ;request display
	mov	bx,01	       ;handle
	mov	cx,512	       ;length
	lea	dx,recdin
	int	21h
	ret
disps	endp
;	clear screen
;--------------------------------------------------
scren proc near
	mov	ax,0600h       ;full screen
	mov	bh,1eh	       ;set color
	mov	cx,0	       ;request scroll
	mov	dx,184fh
	int	10h
	ret
scren endp
;	set cursor
;--------------------------------------------------
curs proc near
	mov	ah,02	       ;request set cursor
	mov	bh,0
	mov	dx,0
	int	10h
	ret
curs endp
;	disk error routine
;--------------------------------------------------
errm proc near
	mov	ah,40h	       ;request display
	mov	bx,01	       ;handle
	mov	cx,18	       ;length of message
	lea	dx,readmsg
	int	21h
	ret
errm	endp
;--------------------------------------------------
cseg    ends
        end    begin


