⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 async.asm

📁 source code for visa card
💻 ASM
📖 第 1 页 / 共 2 页
字号:
	push    dx

	mov     ax, @data                       ; Address local data with ds
	mov     ds, ax

	mov     dx, [IIR]                       ; Check if data actually recieved
	in      al, dx
	and     al, 06h
	cmp     al, 04h
	je      AsyncISR_recieve
	cmp     al, 02h
	jne     AsyncISR_end

;----- Transmit A byte
AsyncISR_transmit:
	mov     bx, [TransTail]
	cmp     bx, [TransHead]
	jne     AsyncISR_1

	mov     dx, [IER]                       ; Buffer empty
	mov     al, 1
	out     dx, al                          ; Disable THR empty interrupt
	jmp     AsyncISR_end

AsyncISR_1:
	mov     al, [byte ptr bx]               ; Get Byte
	inc     [TransTail]                     ; Update buffer pointer
	cmp     [word ptr TransTail], offset TransBuffer + BufSize
	jb      AsyncISR_2
	mov     [TransTail], offset TransBuffer
AsyncISR_2:
	mov     dx, [THR]
	out     dx, al
	jmp     AsyncISR_end

;----- Recieve a byte
AsyncISR_recieve:
	mov     dx, [RDR]                       ; Get Byte
	in      al, dx
	mov     bx, [RecHead]                   ; Store Byte in buffer
	mov     [byte ptr bx], al
	inc     bx                              ; Update RecHead
	cmp     bx, offset RecBuffer + BufSize
	jb      AsyncISR_10
	mov     bx, offset RecBuffer
AsyncISR_10:
	cmp     bx, [RecTail]
	jne     AsyncISR_20
	mov     bx, [RecHead]                   ; Cancel Pointer advance on overflow
AsyncISR_20:
	mov     [RecHead], bx                   ; Store new pointer

AsyncISR_end:
	mov     al, EOI                         ; Signal end ot interrupt
	out     Ctrl8259_0, al

	; Disable and re-enable interrupts so that there
	; is an interrupt edge.

	mov     dx,[IER]                ; Point to Interrupt Enable Register.
	in      al,dx                   ; Read the current value.
	push    ax                      ; Save it.
	mov     al,0                    ; Disable the interrupts.
	out     dx,al
	pop     ax                      ; Restore original mask.
	out     dx,al                   ; Re-enable interrupts.

	pop     dx                      ; Restore saved registers.
	pop     ds
	pop     bx
	pop     ax

	iret

AsyncISR ENDP



;-----------------------------------------------------------------------------
;       AsyncIn                 Gets a byte from the input buffer
;-----------------------------------------------------------------------------
;       int     AsyncIn( void)
;-----------------------------------------------------------------------------
_AsyncIn PROC NEAR

	push    bp
	mov     bp, sp

	xor     ax, ax                          ; Pre-Set result to 0
	mov     bx, [RecTail]
	cmp     bx, [RecHead]
	je      _AsyncIn_return
	mov     al, [byte ptr bx]
	inc     [RecTail]
	cmp     [word ptr RecTail], offset RecBuffer + BufSize
	jb      _AsyncIn_return
	mov     [RecTail], offset RecBuffer

_AsyncIn_return:
	pop     bp
	ret
_AsyncIn ENDP



;-----------------------------------------------------------------------------
;       AsyncOut                Output a byte
;-----------------------------------------------------------------------------
;       void    AsyncOut( int c)
;-----------------------------------------------------------------------------
; spetial synchron send for use with season

_AsyncOut PROC NEAR
	push    bp
	mov     bp,sp
	mov     ax,[bp+4]               ; get argument
	mov     dx,[THR]                ; write direct to Transmitregister
	out     dx,al
	pop     bp
	ret


;_AsyncOut PROC NEAR
;	push    bp
;       mov     bp,sp
;	mov     ax,[bp+4]               ; get argument
;	mov     bx, [TransHead]
;	mov     cx, bx
;	inc     cx                              ; Compute NEW buffer position
;	cmp     cx, offset TransBuffer + BufSize
;	jb      _AsyncIn_1
;	mov     cx, offset TransBuffer
;_AsyncIn_1:
;	cmp     cx, [TransTail]                 ; Wait for space in buffer
;	je      _AsyncIn_1
;
;	mov     [byte ptr bx], al               ; Add byte to buffer
;	mov     [TransHead], cx                 ; Update pointer
;
;	mov     dx, [IER]                       ; Enable THR empty interrupt
;	mov     al, 3
;	out     dx, al
;
;	pop     bp
;	ret
_AsyncOut ENDP



;-----------------------------------------------------------------------------
;       AsyncSet                Set communication paramaters
;-----------------------------------------------------------------------------
;       void    AsyncSet( int Baud, int Control)
;
;       Baud = 150, 300, 600, 1200, 2400, 4800, 9600, 19200, 28800, 38400, 57600
;       Control = The valure to place in the LCR
;-----------------------------------------------------------------------------
_AsyncSet PROC NEAR
       Baud   equ  bp+4
       Control equ bp+6

	push    bp
	mov     bp, sp

	mov     bx, [Baud]
	cmp     bx, 0
	je      _AsyncSet_abort

	mov     ax, 0C200h              ; Baud rate divisor = 115200 / Baud
	mov     dx, 0001h               ; 115200 = 0001C200h
	div     bx
	mov     cx, ax

	cli
	mov     dx, [LCR]               ; Set Port Toggle to BRDL/BRDH registers
	mov     al, 0ffh
	out     dx, al

	mov     dx, [BRDL]              ; Set Baud Rate
	mov     al, cl
	out     dx, al
	mov     dx, [BRDH]
	mov     al, ch
	out     dx, al

	mov     dx, [LCR]               ; Set LCR and Port Toggle
	mov     ax, [Control]
	and     al, 07Fh
	out     dx, al

	sti
_AsyncSet_abort:
	pop     bp
	ret
_AsyncSet ENDP



;-----------------------------------------------------------------------------
;       AsyncInStat             Returns the # of characters in buffer
;-----------------------------------------------------------------------------
;       int     AsyncInStat( void)
;-----------------------------------------------------------------------------
_AsyncInStat PROC NEAR
	push    bp
	mov     bp, sp

	mov     ax,[RecHead]
	sub     ax, [RecTail]
	jge     _AsyncInStat_10
	add     ax, BufSize
_AsyncInStat_10:
	pop     bp
	ret
_AsyncInStat ENDP



;-----------------------------------------------------------------------------
;       AsyncOutStat            Returns the # of characters in buffer
;-----------------------------------------------------------------------------
;       int     AsyncOutStat( void)
;-----------------------------------------------------------------------------
_AsyncOutStat PROC NEAR
	push    bp
	mov     bp, sp

	mov     ax,[TransHead]
	sub     ax, [TransTail]
	jge     _AsyncOutStat_10
	add     ax, BufSize
_AsyncOutStat_10:

	pop     bp
	ret
_AsyncOutStat ENDP



;-----------------------------------------------------------------------------
;       AsyncHand               Sets various handshaking lines
;-----------------------------------------------------------------------------
;       void    AsyncHand( int Hand)
;-----------------------------------------------------------------------------
_AsyncHand PROC NEAR
       Hand  equ bp+4

	push    bp
	mov     bp, sp

	mov     dx, [MCR]
	mov     ax, [Hand]
	or      al, 08h                         ; Keep interrupt enable ON
	out     dx, al

	pop     bp
	ret
_AsyncHand ENDP


;-----------------------------------------------------------------------------
;       AsyncStat               Returns Async/Modem status
;-----------------------------------------------------------------------------
;       unsigned        AsyncStat( void)
;
;       MSR is returned in the high byte, LSR in the low byte
;-----------------------------------------------------------------------------
_AsyncStat PROC NEAR
	push    bp
	mov     bp, sp

	mov     dx, [MSR]
	in      al, dx
	mov     cl, al
	mov     dx, [LSR]
	in      al, dx                  ; LSR in low byte
	mov     ah, cl                  ; MSR in high byte

	pop     bp
	ret
_AsyncStat ENDP


	_TEXT ENDS

	END

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -