DataPort = 378h
ControlPort= DataPort+2 
StatusPort = 379h
print	macro	buffer
	mov	ah,09h
	lea	dx,buffer
	int	21h
	endm
any_key	macro
	mov	ah,06h
	mov	dl,0ffh
	int	21h
	endm

get_string	macro buffer
	mov	ax,@data
	mov	ds,ax
	
	mov	dx,offset buffer
	mov	ah,0ah
	int	21h
	
	;asc_to_hex

	endm
delay	macro	
	local	retry,_end,ah_retry,_end_ah,bl_retry,bl_end,bh_retry,bh_end

	mov	al,0
	mov	al,01h
retry:	
	cmp	al,0
	jz	_end

	mov	ah,10h
ah_retry:
	cmp	ah,0
	jz	_end_ah

	mov	bl,0ffh
bl_retry:
	cmp	bl,0
	jz	bl_end

	mov	bh,0ffh
bh_retry:
	cmp	bh,0
	jz	bh_end
	dec	bh
	jmp	bh_retry

bh_end:
	dec	bl
	jmp	bl_retry
bl_end:

	dec	ah
	jmp	ah_retry
_end_ah:
	dec	al
	jmp	retry

_end:

		endm
delay2	macro	
	local	retry,_end,ah_retry,_end_ah,bl_retry,bl_end,bh_retry,bh_end

	mov	al,0
	mov	al,01h
retry:	
	cmp	al,0
	jz	_end

	mov	ah,01h
ah_retry:
	cmp	ah,0
	jz	_end_ah

	mov	bl,0ffh
bl_retry:
	cmp	bl,0
	jz	bl_end

	mov	bh,0ffh
bh_retry:
	cmp	bh,0
	jz	bh_end
	dec	bh
	jmp	bh_retry

bh_end:
	dec	bl
	jmp	bl_retry
bl_end:

	dec	ah
	jmp	ah_retry
_end_ah:
	dec	al
	jmp	retry

_end:

		endm


check_status    macro
	mov	dx,StatusPort
	in	al,dx		;al=press key status
	endm

.model	small
.386
.stack	200h
.data
	Message5		db	'LCM(20*2) and Panel test program 1 .......By Lanner Inc.(2002/05/15)',0dh,0ah,'$'
	Message		db	'Turning the display OFF.............Press any key to exit!!',0dh,0ah,'$'
;	Message		db	'Please input IO Space........................................'
	Message0		db	'Press Upper Key.........................Press Upper Key................'
	Message1		db	'Press Lower Key.........................Press Lower Key................'
	Message2		db	'Press ESC Key...........................Press ESC Key................'
	Message3		db	'Press Enter Key.........................Press Enter Key................'
	NumTable	db	'0123456789ABCDEF'
	Bus		db	'IO Space=','$'
	Device		db	'Device#','$'
	Function	db	'Func#','$'
	bus_		db	3,4 DUP (0)
	dev_		db	3,4 DUP (0)
	func_		db	3,4 DUP (0)
	CR_LF		db	0ah,0dh,'$'
	space		db	'      ','$'
	   
.code
main:
	mov	ax,@data
	mov	ds,ax
	print   message5
	print	message
_loop:
;	check_status
;	push	ax
;	delay2
;	delay2
;	delay2
;	delay2
;	delay
;	pop	ax
;	mov	ah,06h
;	mov	dl,al
;	int	21h
;	test	al,40h
;	jz	test_key
;	test	al,08h
;	jz	ESC_Enter	;ESC or Enter key
;	test	al,20h
;	jz	upper
;	jmp	lower
;ESC_Enter:
;	test	al,20h
;	jz	_esc
;	jmp	_enter
;	cmp	al,8eh		;Upper key
;	je	upper	
;	cmp	al,0aeh		;Lower key
;	je	lower	
;	cmp	al,86h
;	je	_esc		;ESC key
;	cmp	al,0a6h
;	je	_enter		;Enter key
;	jmp	_exit

upper:
;	mov	dx,ControlPort
;	in	al,dx
	mov	dx,ControlPort
	mov	al,0c8h
	out	dx,al
	delay
;
	mov	dx,DataPort
	mov	al,38h			;set function
	out	dx,al	
	delay
	mov	dx,ControlPort
	mov	al,0cah
	out	dx,al
	delay
	mov	dx,ControlPort
	mov	al,0c8h
	out	dx,al
	delay
;
	mov	dx,DataPort		;display on
	mov	al,0ch
	out	dx,al
	delay
	mov	dx,ControlPort
	mov	al,0cah
	out	dx,al
	delay
	mov	dx,ControlPort
	mov	al,0c8h
	out	dx,al
	delay
;
	mov	dx,DataPort	       ;clear display
	mov	al,01h
	out	dx,al
	delay
	mov	dx,ControlPort
	mov	al,0cah
	out	dx,al
	delay
	mov	dx,ControlPort
	mov	al,0c8h
	out	dx,al
	delay
	delay
;
	mov	dx,ControlPort		;write data
	mov	al,0c1h
	out	dx,al
;
;	mov	cx,0
	delay
	delay
;	delay
;show:	
;	mov	bx,cx
;	mov	dx,DataPort	       
;	mov	al,message0[bx]
;	out	dx,al
;	delay
;	mov	dx,ControlPort
;	mov	al,0c2h
;	out	dx,al
;	delay
;	mov	dx,ControlPort
;	mov	al,0c0h
;	out	dx,al
;	delay
;	inc	cx
;	cmp	cx,79
;	jbe	show

;For STB ( backlight)
	mov	dx,ControlPort
	mov	al,0c1h
	out	dx,al
	delay

;	jmp	test_key
;end of upper


;test_key:
;	mov	al,0
;	any_key
;	push	ax
;	push	dx
;	mov	ah,06h
;	mov	al,00h
;	mov	dl,0ffh
;	int	21h
	mov	ah,01h
	int	21h
;	cmp	al,0
;	pop	dx
;	pop	ax
;	jne	_exit
;	jmp	_loop

_exit:
	mov	ah,4ch
	int	21h
	
end	main
