;[]-------------------------------------------------------------------------[]
;|	Program name: 3_2_1.ASM                                              |
;|	Image   file: None                                                   |
;|	Note        : Write register value to 'REGISTER.DAT' file.           |
;|                    List save and load subroutines only.                   |
;[]-------------------------------------------------------------------------[]


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

count		dw	0
reg_buf		dw	800H dup (0FFFFH)
reg_file	db	'REGISTER.DAT',0
handle		dw	0

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

;---------------------------------------
; Save buffer data to 'REGISTER.DAT'.
;---------------------------------------

save_reg	proc	near

	pushall				; Save all the register values

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

	h_creat	reg_file,0		; Creat 'REGISTER.DAT' file
	mov	cx,count		; Get count value
	add	cx,2			; Write count+2 bytes
	h_write	handle,count,cx		; from count to file
	h_close	handle			; Close 'REGISTER.DAT'

	popall				; Restore all the register values

	ret				; Return

save_reg	endp

;---------------------------------------
; Load buffer data from 'REGISTER.DAT'.
;---------------------------------------

load_reg	proc	near

	pushall				; Save all the register values

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

	h_open	reg_file,RDWR		; Open 'REGISTER.DAT'
	jc	l1			; If error then branch
	h_read	handle,count,1002H	; Read 1008H bytes to count
	h_close	handle			; Close 'REGISTER.DAT'

l1:	popall				; Restore all the register values

	ret				; Return

load_reg	endp

;---------------------------------------
