;[]-------------------------------------------------------------------------[]
;|	Program name: 3_1_4.ASM                                              |
;|	Image   file: None                                                   |
;|	Note        : Display the recorded data using INT 05H routine.       |
;|                    List new_int05 and its subroutines only.               |
;[]-------------------------------------------------------------------------[]


;------- Data area ---------------------

busy_05		db	0

count		dw	0
reg_buf		dw	800H dup (0FFFFH)

;------- INT 05H -----------------------

new_int05	proc	far

	cmp	cs:busy_05,1		; Test for INT 05H busy
	je	i05_done		; If busy then branch

	sti				; Enable interrupt
	mov	cs:busy_05,1		; Set INT 05H busy
	call	dis_buffer		; Display buffer
	mov	cs:busy_05,0		; Reset INT 05H idle

i05_done:
	iret				; Return calling program

new_int05	endp

;---------------------------------------
; Display buffer that saved register values
;---------------------------------------

dis_buffer	proc	near

	pushall				; Save all the register values

	mov	ax,cs			; Adjust DS, ES
	mov	ds,ax
	mov	es,ax

	mov	bx,offset reg_buf	; Get buffer start address
	mov	cx,0			; Let CX to be a counter

;---------------------------------------
; In the following routine, AX, BX, CX, DX are used for:
;	AX: displaying data
;	BX: point to buffer which to be displayed
;	CX: total displayed data, used for comparing with count
;	DX: control display format
;	    ( one block per line & insert one blank line per two blocks)
;---------------------------------------

n3:	mov	dx,0			; Reset DX counting
n2:	mov	ax,[bx]			; Get data
	call	dsword			; Display it
	dstr	<' ',' '>		; Display '  '
	add	bx,2			; BX point to next data
	add	dx,1			; Increase DX
	add	cx,2			; Increase CX
	cmp	dx,9			; Does one block have been displayed ?
	jne	n1			; If not, check another
	call	dreturn			; If yes, display return
	jmp	n2			; and go on displaying
n1:	cmp	dx,18			; Does two blocks have been displayed ?
	jne	n2			; If not, go on displaying
	call	dreturn			; If yes, display return
	call	dreturn			; and insert one blank line
	cmp	cx,count		; Does all data have been displayed?
	jbe	n3			; If not, go on displaying

	popall				; Restore all the register values

	ret				; Return

dis_buffer	endp

;------- INT 13H -----------------------
