IoBase dw 0

_EOI macro
        mov  al, 20h
        out  20h, al
        endm

;============================================================================
sio_in proc far
; DX = uart port 
; BL = offset
; Output : AL = byte
;============================================================================
       mov ax, dx
       xor bh, bh
       add ax, bx
       mov dx, ax 
       in  al, dx      
       ret
sio_in endp

_sio_in macro _sio_port, _sio_ofs
        mov  dx, _sio_port
        mov  bl, _sio_ofs
        call sio_in
        endm

_sio_in_w macro _sio_iport, _sio_iofs, _sio_iword
        mov  dx, _sio_iport
        mov  bl, _sio_iofs
        call sio_in
        mov  ch, al
        mov  dx, _sio_iport
        mov  bl, _sio_iofs
        call sio_in
        mov  cl, al
        mov  ax, cx         ; DING! 
        endm

inb  macro port
     mov dx, cs:IoBase
     add dx, port
     in  al, dx
     Endm

inw		Macro port
        mov dx,cs:IoBase
	add dx,port
	in al,dx
	inc dx
	mov ah,al
	in al,dx
	xchg al,ah
		Endm

;=========================================================================================
sio_out proc far
; DX = uart port 
; CL = byte to send
; BL = offset
;=========================================================================================
       mov  ax, dx
       xor  bh, bh
       add  ax, bx
       mov  dx, ax
       mov  al, cl
       out  dx, al
       ret
sio_out endp

_sio_out macro _sio_oport, _sio_oofs, _sio_obyte
        mov  dx, _sio_oport
        mov  bl, _sio_oofs
        mov  cl, _sio_obyte
        call sio_out
        endm

_sio_out_w macro _sio_oport, _sio_oofs, _sio_oword
        mov  dx, _sio_oport
        mov  bl, _sio_oofs
        mov  cx, _sio_oword
        and  cx, 0f0h      ; network byte order from little endian
        mov  cl, ch
        xor  ch, ch
        call sio_out
        mov  dx, _sio_oport
        mov  bl, _sio_oofs
        mov  cx, _sio_oword
        and  cx, 0fh
        call sio_out
        endm

outb	Macro port, val
        mov  dx, cs:IoBase
        add  dx, port
        mov  al, val
        out  dx, al
        jmp  short $+2
        Endm

outw	Macro port, val
        mov dx,cs:IoBase
	add dx,port
	mov ax,val
	out dx,al
	inc dx
	mov al,ah
	out dx,al
		Endm

