All pastes #1454273 Raw Edit

Stuff

public text v1 · immutable
#1454273 ·published 2009-06-09 20:23 UTC
rendered paste body
;----------------------------------------
;Seiriaki Epikoinwnia - Apeftheias UART
;Askisi 3b
;################# ####### 
;----------------------------------------

TITLE 	serial_bios
DOSSEG
.MODEL 	SMALL
.STACK	100h
.DATA
	;Minimata interface
	i_msg1	db	10,13,"Sellect Serial 1 or 2: $"
	r_msg1	db	10,13,"overrun error, skipping",10,13,"$"
	r_msg2	db	10,13,"parity error, skipping",10,13,"$"
	r_msg3	db	10,13,"framing error, skipping",10,13,"$"
	endl	db	10,13,"$" ;Endline
	;Term Flag
	escf	db	00h
.CODE
	start:	mov	ax,@DATA	;Arxikopoiisi
		mov	ds,ax		;tou DS
		mov	ax,0040h	;Arxikopoiisi tou
		mov	es,ax		;ES gia evresi thirwn
		sub	ax,ax		;

		call	INPUT		;Input
		cmp	al,"1"		;
		jne	com2		;
		mov	al,00h		;
		jmp	cont
	com2:	mov	al,02h	
		
	cont:	mov	ah,00h		;
		mov	si,al		;Saving

		mov	cx,es:[si]	;Serial Port Address save 

		lea	dx,endl		;
		mov	ah,09h		;alazoume
		int	21h		;grammi

		call	INIT		;Arxikopoiisi thyras

	prlp:	call	SEND		;Sending proc
		cmp	escf,01h	;Check if ESC
		je	term		;
		call	RECIEVE		;Recieve proc
		cmp	escf,01h	;Check if ESC
		je	term		;
		jmp	prlp		;Loop
	
	term:	mov	ax,4C00h	;Termatismos
                int	21h		;

	;--------------------------------
	;Input Routine
	;--------------------------------
	INPUT	proc	near
		push	dx
		;------------------------
	i_ask:	lea	dx,i_msg1	;Printing
		mov	ah,09h		;message
		int	21h		;

		mov	ah,01h		;Reading
		int	21h		;

		cmp	al,"1"		;Check
		jb	i_ask		;Below 1 ask again
		cmp	al,"2"		;
		ja	i_ask		;Above 2 ask again

		;------------------------
		pop	dx
		retn
	INPUT	endp

	;--------------------------------
	;Initialise com
	;--------------------------------
	INIT	proc	near
		push	dx
		push	ax
		;------------------------
		mov	dx,cx		;Diefthinsi thiras
		add	dx,3h		;base+3 == kataxoristis elegxou gramis
		mov	al,10001111b
		out	dx,al		;1=DLAB (gia to baud rate)
					;0=Apenergopoiisi gramis metadosis (oxi)
					;0=bit isotimias 0
					;0=periti isotimia
					;1=energopoiisi isotimias
					;1=2 stop bits
					;1=}
					;1=}8 bytes char

		mov	dx,cx		;Diefthinsi thiras ==diefthinsi LSB
		mov	al,18h		;exoume DLAB = 1 apo prin
		out	dx,al		;4800 BaudRATE
		inc	dx		;+1 diefthinsi MSB
		mov	al,0h		;
		out	dx,al		;MSB = 0 gia 4800

		mov	dx,cx		;Diefthinsi thiras
		add	dx,3h		;base+3 == kataxoristis elegxou gramis
		mov	al,00001111b	;To idio me DLAB 0 gia apostoli/lipsi
		out	dx,al 		;
		;------------------------
		pop	ax
		pop	dx
		retn
	INIT	endp

	;--------------------------------
	;SEND Routine
	;--------------------------------
	SEND 	proc	near
		push	dx
		push	cx
		push	ax
		;------------------------

		mov	ah,01h		;Check if 
		int	16h		;key on buffer
		jz	s_skip		;if not, quit

		mov	ah,00h		;Read key 
		int	16h		;from buffer

		mov	escf,01h	;
		cmp	al,1bh		;ESC pressed
		je	s_exit		;An exoume ESC parakamptei
		mov	escf,00h	;to "midenismo" tis simeas

	s_exit:	push	ax		;
	s_wait:	mov	dx,cx		;Diefthinsi thiras
		add	dx,5h		;base+5 = kataxoritis katastasis gramis
		in	al,dx		;Anagnosi katastasis

		test	al,00100000b	;Koitame katastasi
		jz	s_wait		;perimenoume na einai 0 (clear to send)

		pop	ax		;Epanaferoume ax

		;========================

		mov	dx,cx		;Diefthinsi thiras
		out	dx,al		;al exei ton xaraktira apo prin

		;------------------------
	s_skip:	pop	ax
		pop	cx
		pop	dx
		retn
	SEND	endp

	;--------------------------------
	;RECIEVE Routine
	;--------------------------------
	RECIEVE proc	near
		push	dx
		push	cx
		push	ax
		;------------------------
		mov	dx,cx		;Diefthinsi thiras
		add	dx,5h		;base+5 = kataxoritis katastasis gramis
		in	al,dx		;Anagnosi katastasis

		mov	ah,al
		test	ah,00000001b	;Koitame katastasi an irthe tpt
		jz	r_skip		;an oxi vgenoume

		;Elegxxoume gia lathi
		;--------------------
		test	ah,00000010b	;overrun
		jz	r_parc		;proxorame se parity check
		
		lea	dx,r_msg1	;Tupoma minimatos
		mov	ah,09h		;kai
		int	21h		;eksodos apo
		jmp	r_skip		;routina

	r_parc:	test	ah,00000100b	;overrun
		jz	r_frac		;framing check

		lea	dx,r_msg2	;Tupoma minimatos
		mov	ah,09h		;kai
		int	21h		;eksodos apo
		jmp	r_skip		;routina

	r_frac:	test	ah,00001000b	;overrun
		jz	r_reci		;Recieve

		lea	dx,r_msg3	;Tupoma minimatos
		mov	ah,09h		;kai
		int	21h		;eksodos apo
		jmp	r_skip		;routina

	r_reci:	mov	dx,cx		;Diefthinsi thiras
		in	al,dx		;al exei ton xaraktira apo prin

		cmp	al,1bh		;Escape - exiting
		je	r_exit		;

		mov	dl,al		;Typoma 
		mov	ah,02h		;Xaraktira
		int	21h		;
		jmp	r_skip		;Apofigi tou r_exit

	r_exit:	mov	escf,01h
		;------------------------
	r_skip:	pop	ax
		pop	cx
		pop	dx
		retn
	RECIEVE endp

	END	start