?? reports.asm
字號:
TITLE "REPORTS.ASM"
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; File: reports.asm
; Author: Steve Roberts 8/2/96
; Description: Comprised of three functions that are totally
; independent of each other (i.e. called independently)
; but all have to do with writing data reports to
; TXFIFO's.
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include 82930.inc
include donconst.inc
include externs.inc
public SEND_KBD_REPORT_EP2
public SEND_KBD_REPORT_EP0
public MOUSE_REPORT_GENERATOR
public SEND_MOUSE_REPORT
define KBD_REPORT_REQUEST,SPACE=CODE
segment KBD_REPORT_REQUEST
;-------------------------------------------------------------------
; Function: SEND_KBD_REPORT_EP2
; Description: Sends an eight byte kbd report to TXFIFO2.
; Called from within lite_frm.asm when a USB
; TXD2 interrupt is received. It is meant to fill
; the TXFIFO for the next IN-TOKEN request from the
; host.
; Regs Preserved: All used
;--------------------------------------------------------------------
SEND_KBD_REPORT_EP2:
push R0
push WR16
push R1
clr SBI.4 ; Clears the TXD2 interrupt bit
mov WR16, #KBD_BUFFER_START
CHECK_FIFO_VACANCY_EP2:
jnb TXFLG2.6, FIFO_AVAILABLE_EP2
jnb TXFLG2.7, FIFO_AVAILABLE_EP2
jmp EXIT_SEND_KBD_REPORT_EP2 ; Perhaps flushing the FIFO would
; be better, but this shouldn't
; happen anyways. If it does,
; something else is wrong.
FIFO_AVAILABLE_EP2:
mov R0, #1
cmp R0, ERROR_ROLLOVER_STATE
je SEND_ERROR_ROLLOVER_STATE_EP2
WRITE_KBD_DATA_EP2:
mov R0, @WR16
mov TXDAT2, R0
inc WR16, #1
cmp WR16, #KBD_BUFFER_END ; If not at end of buffer, keep filling
jle WRITE_KBD_DATA_EP2 ; otherwise, done writing dataset
mov TXCNT2, #08h
jmp EXIT_SEND_KBD_REPORT_EP2
SEND_ERROR_ROLLOVER_STATE_EP2:
mov R1, #03h
INITIAL_LOOP_EP2:
mov R0, @WR16 ; Still need to send ID, modifier, &
mov TXDAT2, R0 ; reserved byte
inc WR16, #1 ; All other bytes = 01
djnz R1,INITIAL_LOOP_EP2
mov R0, #01h
SEND_ERROR_ROLLOVER_STATE_LOOP_EP2:
mov TXDAT2, R0
inc WR16, #1
cmp WR16, #KBD_BUFFER_END ; If not at end of buffer, keep filling
jle SEND_ERROR_ROLLOVER_STATE_LOOP_EP2 ; otherwise, done writing dataset
mov TXCNT2, #08h
EXIT_SEND_KBD_REPORT_EP2:
mov R0, IDLE_MODE
cmp R0, #2 ; If in TIMED IDLE mode need to reset
jne RETURN_SEND_KBD_REPORT_EP2 ; timer value and restart timer
mov TH0, #0E0h ; Resets timer value
mov TL0, #0BFh
setb TCON.4 ; Restarts timer
RETURN_SEND_KBD_REPORT_EP2:
pop R1
pop WR16
pop R0
RET
;-------------------------------------------------------------------
; Function: SEND_KBD_REPORT_EP0
; Description: Sends an eight byte kbd report to TXFIFO0.
; Called from within lite_frm.asm when a USB
; GET_REPORT(Input) request is detected for EP2.
; Regs Preserved: All used
;--------------------------------------------------------------------
SEND_KBD_REPORT_EP0:
push R0
push WR16
push R1
mov WR16, #KBD_BUFFER_START
mov R0, #1
cmp R0, ERROR_ROLLOVER_STATE
je SEND_ERROR_ROLLOVER_STATE_EP0
WRITE_KBD_DATA_EP0: ; FIFO vacancy not checked since a
mov R0, @WR16 ; flush is done before calling this
mov TXDAT0, R0
inc WR16, #1
cmp WR16, #KBD_BUFFER_END ; If not at end of buffer, keep filling
jle WRITE_KBD_DATA_EP0 ; otherwise, done writing dataset
mov TXCNT0, #08h
jmp EXIT_SEND_KBD_REPORT_EP0
SEND_ERROR_ROLLOVER_STATE_EP0:
mov R1, #03h
INITIAL_LOOP_EP0:
mov R0, @WR16 ; Still need to send ID, modifier, &
mov TXDAT0, R0 ; reserved byte
inc WR16, #1 ; All other bytes = 01
djnz R1,INITIAL_LOOP_EP0
mov R0, #01h
SEND_ERROR_ROLLOVER_STATE_LOOP_EP0:
mov TXDAT0, R0
inc WR16, #1
cmp WR16, #KBD_BUFFER_END ; If not at end of buffer, keep filling
jle SEND_ERROR_ROLLOVER_STATE_LOOP_EP0 ; otherwise, done writing dataset mov TXCNT0, #08h
mov R0, #0
mov ERROR_ROLLOVER_STATE, R0
EXIT_SEND_KBD_REPORT_EP0:
pop R1
pop WR16
pop R0
RET
;-------------------------------------------------------------------
define MOUSE_REPORT_REQUEST,SPACE=CODE
segment MOUSE_REPORT_REQUEST
;-------------------------------------------------------------------
; Function: SEND_MOUSE_REPORT
; Description: Sends a three byte mouse report to TXFIFO3. It
; checks to be sure a FIFO is available & then
; checks for data availability. It sends only three
; bytes of data each time even if more are available.
; Called from IN-TOKEN and Report requests at
; "SEND_MOUSE_REPORT". Called from mouseisr.asm at
; " MOUSE_REPORT_GENERATOR".
; Regs Preserved: All used
;--------------------------------------------------------------------
SEND_MOUSE_REPORT:
push WR6
push WR30
push WR10
clr SBI.6 ; Clears the TXD interrupt in SBI
mov R10, MOUSE_DATA_COUNTH ; Need to make sure there are
mov R11, MOUSE_DATA_COUNTL ; at least 3 bytes in mouse buffer
cmp WR10, #MOUSE_DATA_LENGTH ; Otherwise, exit
jsge CALL_MOUSE_REPORT_GENERATOR
jmp EXIT_SEND_MOUSE_REPORT
CALL_MOUSE_REPORT_GENERATOR:
lcall MOUSE_REPORT_GENERATOR
EXIT_SEND_MOUSE_REPORT:
pop WR10
pop WR30
pop WR6
ret
MOUSE_REPORT_GENERATOR:
jnb TXFLG3.6, FIFO_AVAILABLE ; Makes sure a fifo is available
jmp EXIT_MOUSE_REPORT_GENERATOR ; If not,exit.
FIFO_AVAILABLE:
mov R6, MOUSE_DATA_COUNTH ; Puts data count in WR6
mov R7, MOUSE_DATA_COUNTL
cmp WR6, #MOUSE_DATA_LENGTH ; Is data count >= 03?
jsge WRITE_DATA ; If not, get out
ret
WRITE_DATA:
mov R10, MOUSE_BUFFER_ROFFSETH ; Get offset of first full location
mov R11, MOUSE_BUFFER_ROFFSETL ; in the endpoint buffer
mov WR30, #MOUSE_BUFFER ; Set WR30 back to buffer start
add WR30, WR10 ; Add offset to first full location
mov R0, @WR30
anl R0, #040h ; Gets bit 6
cmp R0, #040h ; Checks if it is set
je CONTINUE ; (bit 6 is always set in first
; byte of mouse data packet)
inc WR10, #01h
anl WR10, #RINGWORDMASK ; Rollover after buffer end hit
mov MOUSE_BUFFER_ROFFSETH, R10
mov MOUSE_BUFFER_ROFFSETL, R11
ENTER_CRITICAL_SECTION_A:
clr ES ; Disable serial interrupt as the
; SerialISR decs MOUSE_DATA_COUNT
mov R10, MOUSE_DATA_COUNTH
mov R11, MOUSE_DATA_COUNTL
dec WR10, #01h ; Get rid of this byte.
mov MOUSE_DATA_COUNTH, R10 ; dec. no. of bytes in the Mouse Buffer
mov MOUSE_DATA_COUNTL, R11
setb ES ; Enable serial interrupt
END_CRITICAL_SECTION_A:
jmp FIFO_AVAILABLE
CONTINUE: ; First byte now being processed
add WR10, #MOUSE_DATA_LENGTH
anl WR10, #RINGWORDMASK ; Rollover after buffer end hit
mov MOUSE_BUFFER_ROFFSETH, R10 ; Update Read Offset
mov MOUSE_BUFFER_ROFFSETL, R11
ENTER_CRITICAL_SECTION_B:
clr ES ; Disable serial interrupt
mov R10, MOUSE_DATA_COUNTH
mov R11, MOUSE_DATA_COUNTL
sub WR10, #MOUSE_DATA_LENGTH ; sub no. of bytes being Xmitted now.
mov MOUSE_DATA_COUNTH, R10 ; dec. no. of bytes in the Mouse Buffer
mov MOUSE_DATA_COUNTL, R11
setb ES ; Enable serial interrupt
END_CRITICAL_SECTION_B:
clr EPCON3.1
lcall PUT_REPORT_IN_FIFO ; Sets up the bits properly.
setb EPCON3.1
EXIT_MOUSE_REPORT_GENERATOR:
ret
;--------------------------------------------------------------------
;---------------------------------------------------------------------
;Function name : PUT_REPORT_IN_FIFO
;Description : Generates a report from the 3 bytes that the mouse
; sent back. The bytes are stored at location pointed
; to by WR30.
;--------------------------------------------------------------------
PUT_REPORT_IN_FIFO:
mov R10, @WR30
anl R10, #03Fh ; Makes sure top bits are 0
mov R11, R10 ; Save this value in R11
mov R7, #GET_MOUSE_BUTTONS
SHIFT_RIGHT:
srl R10 ; Puts mouse button data at LSBs
djnz R7, SHIFT_RIGHT
mov TXDAT3, #02h ; This is the Report ID
mov TXDAT3, R10 ; Put the modified value in the Fifo
inc WR30, #01h
anl WR30, #RINGBUFFMASK ; Rollover to 1000 after 7FF bytes
mov R10, @WR30 ; Get next byte (X value)
anl R10, #03Fh ; Makes sure top two bits = 0
mov R6, R11 ; Store the top byte in R6
mov R7, #GET_MOUSE_X_VALUE ; Shift the first byte 6 times
SHIFT_X_LEFT: ; to the left to get the top
sll R11 ; 2 bits of the X co-ordinate.
djnz R7, SHIFT_X_LEFT
orl R10, R11 ; OR the top two bits in and
mov TXDAT3, R10 ; place it in the fifo.
inc WR30, #01h
anl WR30, #RINGBUFFMASK ; Rollover to 1000 after 7FF bytes
mov R10, @WR30 ; Get next byte (Y value)
anl R10, #03Fh ; Makes sure top two bits = 0
mov R11, R6 ; Restore the top byte in R11
anl R11, #0FCh ; Get rid of the X values in the
; top byte.
mov R7, #GET_MOUSE_Y_VALUE ; Shift the first byte 4 times
SHIFT_Y_LEFT: ; to the left to get the top
sll R11 ; 2 bits of the Y co-ordinate.
djnz R7, SHIFT_Y_LEFT
orl R10, R11 ; OR the top two bits in and
mov TXDAT3, R10 ; store it back.
mov TXCNT3, #MOUSE_DATA_LENGTH+1 ; Write the transmit count
RETURN:
Ret
;-------------------------------------------------------------------
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -