home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ACDI.ZIP / ACDI / ACDI_M / ACDIMRCV.ASM < prev    next >
Assembly Source File  |  1991-11-05  |  43KB  |  971 lines

  1. .286P
  2.  
  3. ;*************************************************************************
  4. ;*                                                                       *
  5. ;*   MODULE NAME: ACDIMRCV.ASM                                           *
  6. ;*                                                                       *
  7. ;*   DESCRIPTIVE NAME: ACDI MASM SAMPLE RECEIVE PROGRAM                  *
  8. ;*                     OS/2 EXTENDED SERVICES                            *
  9. ;*                                                                       *
  10. ;*   COPYRIGHT:  (C) COPYRIGHT IBM CORP. 1988, 1990                      *
  11. ;*               LICENSED MATERIAL - PROGRAM PROPERTY OF IBM             *
  12. ;*               ALL RIGHTS RESERVED                                     *
  13. ;*                                                                       *
  14. ;*   STATUS:   LPP Release 1.0 Modification 0                            *
  15. ;*                                                                       *
  16. ;*   FUNCTION: The sample program will use the ACDI interface to echo    *
  17. ;*             line by line screen image from the first Personal         *
  18. ;*             Computer on the second Personal Computer connected        *
  19. ;*             through asynchronous line.                                *
  20. ;*             The RECEIVE PROGRAM, is executed in the second Personal   *
  21. ;*             Computer.                                                 *
  22. ;*                                                                       *
  23. ;*             Uses the following ACDI Verbs:                            *
  24. ;*                                                                       *
  25. ;*                COMOPEN                                                *
  26. ;*                COMDEFOUTPUTBUFF                                       *
  27. ;*                COMDEFINPUT                                            *
  28. ;*                COMSETBITRATE                                          *
  29. ;*                COMSETLINECTRL                                         *
  30. ;*                COMCONNECT                                             *
  31. ;*                COMSETTIMEOUTS                                         *
  32. ;*                COMREADEVENT                                           *
  33. ;*                COMREADCHARSTRING                                      *
  34. ;*                COMDISCONNECT                                          *
  35. ;*                COMCLOSE                                               *
  36. ;*                                                                       *
  37. ;*   NOTE:     The asynchronous device name to be used in this           *
  38. ;*             program is COM1. If this is to be changed it must         *
  39. ;*             be changed in the main header.                            *
  40. ;*                                                                       *
  41. ;*             This program is designed to run with connect type 4       *
  42. ;*             only.                                                     *
  43. ;*                                                                       *
  44. ;*   MODULE TYPE = IBM Personal Computer Macro Assembler/2 Version 1.00  *
  45. ;*                                                                       *
  46. ;*   PREREQS = Requires Message file "ACX.MSG" at runtime.               *
  47. ;*                                                                       *
  48. ;*************************************************************************
  49.  
  50.            IF1
  51.             INCLUDE ACDI_A.INC              ;acdi include file
  52.             INCLUDE DOSCALLS.INC            ;other dos files
  53.             INCLUDE SUBCALLS.INC
  54.            ENDIF
  55.  
  56. @MOVW      MACRO     DESTINATION,SOURCE
  57.            MOV       AX,SOURCE
  58.            MOV       DESTINATION,AX
  59.            ENDM
  60.  
  61. @MOVB      MACRO     DESTINATION,SOURCE
  62.            MOV       AL,SOURCE
  63.            MOV       DESTINATION,AL
  64.            ENDM
  65.  
  66. @ACDI      MACRO     VCB                    ;a macro to define and call acdi
  67.            @DEFINE   ACDI
  68.            PUSH      DS
  69.            PUSH      OFFSET DGROUP:VCB
  70.            CALL      FAR PTR ACDI
  71.            ENDM
  72.  
  73.  
  74. DGROUP           GROUP      DATA
  75.  
  76. ;*****************************************************************************
  77. ;The thread process stack segment
  78.  
  79. THRD_STK   SEGMENT WORD STACK 'STACK1'
  80.            DW      4096 DUP (?)
  81. THRD_STK_END EQU   $
  82. THRD_STK   ENDS                             ;end of thread proc stack segment
  83.  
  84. ;*****************************************************************************
  85. ;The main program stack segment
  86.  
  87. STACK      SEGMENT STACK 'STACK'
  88.            DW      4096 DUP (?)
  89. STACK      ENDS                             ;end of main program stack segment
  90.  
  91. ;*****************************************************************************
  92.  
  93. DATA       SEGMENT WORD PUBLIC 'DATA'       ;Data segment.
  94.  
  95. SYS_ERR        DB       0                   ;system error flag
  96. HANDLE         DW       0                   ;com device handle
  97. DEV_NAME       DB       'COM1\0',0          ;name of com device to be used
  98.  
  99. OUT_BUFF_LEN   EQU      82                  ;length of output buffer
  100. IN_BUFF_LEN    EQU      82                  ;length of input buffer
  101.  
  102. INTEG          DB       0
  103.  
  104. I_ANBPTR_SEL   DW       0                   ;selector returned by DOSALLOCSEG
  105.                                             ;for input buffer
  106. O_ANBPTR_SEL   DW       0                   ;selector returned by DOSALLOCSEG
  107.                                             ;for output buffer
  108.  
  109. CONCTTIMEOUT1  EQU      0                   ;timeout values for the
  110. CONCTTIMEOUT2  EQU      30                  ;comconnect verb
  111.  
  112. INF_RDBLKTMOUT EQU      0                   ;timeout parameters for the
  113. RDCHRTMOUT     EQU      01H                 ;verb -
  114. INF_WRTTMOUT   EQU      0                   ;comsettimeouts
  115.  
  116. INITWAIT       DW       0                   ;parameters for comreadcharstring
  117. BYTESFREED     DW       0                   ;verb
  118. BYTESNEEDED    DW       0
  119.  
  120. ;*****************************************************************************
  121.  
  122. NULL           DB       20H                 ;null character
  123. RET_CODE       DW       0                   ;area for function and return
  124. FUNC_CODE      DB       0                   ;codes from acdi
  125.  
  126. R_C_HX         DB       '    ',0DH,0AH      ;return code in printable hex
  127. R_C_HX_LEN     EQU      $-R_C_HX            ;length of printable return code
  128.  
  129. F_C_HX         DB       '  ',0DH,0AH        ;function code in printable hex
  130. F_C_HX_LEN     EQU      $-F_C_HX            ;length of printable function code
  131.  
  132. GETMSERR       DB       'Unable to process message file - ACX.MSG',0DH,0AH
  133. GETMSERR_LEN   EQU      $-GETMSERR          ;message to be printed in case of
  134.                                             ;an error in DOSGETMESSAGE
  135.  
  136. DOS_RC         DW       0                   ;return code from dos calls
  137. DOS_RC_HX      DB       '    ',0DH,0AH      ;dos return codes in printable hex
  138. DOS_RC_HX_LEN  EQU      $-DOS_RC_HX         ;and its length
  139.  
  140. VIO_RC         DW       0                   ;return code from vio calls
  141. VIO_RC_HX      DB       '    ',0DH,0AH      ;vio return codes in printable hex
  142. VIO_RC_HX_LEN  EQU      $-VIO_RC_HX         ;and its length
  143.  
  144. ZERO           DD       0
  145. MSG_FILE       DB       'ACX.MSG',0         ;file containing messages
  146. MSG_BUFF       DB       100 DUP  (?)        ;buffer for messages
  147. MSG_NO         DW       0                   ;message to load and display
  148. MSG_LEN        DW       0                   ;length of message
  149.  
  150. HEXTAB         DB       '0123456789ABCDEF'  ;table for hex conversion
  151.  
  152. ;*****************************************************************************
  153.  
  154. ACTION         EQU      1
  155. RESULT_CODE    DW       0
  156.  
  157. ;*****************************************************************************
  158.  
  159. RECVD_CHAR     DB       0                   ;character received
  160. EVENTFLAG      DB       0                   ;variable for communication
  161.                                             ;between to asynchronously running
  162.                                             ;processes-main and thread
  163.  
  164. ROW            DW       0                   ;row and column numbers used in
  165. COL            DW       0                   ;screen displays
  166. CH_ATR         DW       720H
  167.  
  168. CAR_RET        EQU      0DH                 ;carriage return
  169.  
  170. ;*****************************************************************************
  171.  
  172. THRD_PGM_ADR   DD       EVENT               ;selector returned by DOSALLOCSEG
  173. THRD_STK_ADR   DD       THRD_STK_END        ;address of stack
  174. THRD_ID        DW       0                   ;thread identifier
  175. SEMAPHOR       DD       0                   ;ram semaphore used in thread
  176. SEMHANDLE      DD       SEMAPHOR            ;semaphore handle (address)
  177. SEMTIMOUT_INF  DD      -1                   ;infinite wait time for DOSSEMWAIT
  178.  
  179. ;*****************************************************************************
  180. ;   VERB CONTROL BLOCK (VCB)
  181. ;*****************************************************************************
  182.  
  183. OPN            COMOPEN_CB               <>  ;use same VCB with structs
  184.                ORG              OPN         ;defined over same storage
  185. DFOTBFF        COMDEFOUTPUTBUFF_CB      <>
  186.                ORG              OPN
  187. DFINBFF        COMDEFINPUT_CB           <>
  188.                ORG              OPN
  189. BITRT          COMSETBITRATE_CB         <>
  190.                ORG              OPN
  191. LINCTRL        COMSETLINECTRL_CB        <>
  192.                ORG              OPN
  193. CONCT          COMCONNECT_CB            <>
  194.                ORG              OPN
  195. TIMOUTS        COMSETTIMEOUTS_CB        <>
  196.                ORG              OPN
  197. RDCHRSTR       COMREADCHARSTRING_CB     <>
  198.                ORG              OPN
  199. DSCONCT        COMDISCONNECT_CB         <>
  200.                ORG              OPN
  201. CLOS           COMCLOSE_CB              <>
  202.                ORG              OPN
  203. VCB            DB               300 DUP (0)
  204. VCB_LEN        EQU              $-VCB       ;size of VCB
  205.  
  206. ;*****************************************************************************
  207. ;   VERB CONTROL BLOCK - FOR THE THREAD PROCESS
  208. ;*****************************************************************************
  209.  
  210. RDEVNT         COMREADEVENT_CB          <>   ;VCB for the thread process
  211.                ORG              RDEVNT
  212. VCB_THRD       DB               200 DUP (0)  ;size of VCB for thread
  213. VCB_THRD_LEN   EQU              $-VCB_THRD
  214.  
  215. MASK           MASKS                    <>
  216. EVENTSTRUCT    EVENT_STRUCT             <>
  217.  
  218. DATA           ENDS
  219.  
  220. ;*****************************************************************************
  221.  
  222. CSEG       SEGMENT WORD PUBLIC 'CODE'
  223.            ASSUME   CS:CSEG, DS:DGROUP, SS:STACK
  224.  
  225. EVENT      PROC         FAR
  226.  
  227. ;  This is the thread process. It will set the EVENTFLAG to zero to enable
  228. ;  receiving characters by the main process, then set the semaphore; issue
  229. ;  comreadevent verb, and wait for the semaphore to be cleared by async
  230. ;  subsystem - which will happen when any one of three events specified -
  231. ;  break signal, disconnect or a stop is received. When this occurs it
  232. ;  will set the EVENTFLAG to signal end of session.
  233. ;  This process runs asynchronously with the main process so that receiving
  234. ;  message, and watching for the break signal can be done simultaneously
  235.  
  236.            MOV          EVENTFLAG,0         ;set flag to session active
  237.  
  238.            @DOSSEMSET   SEMHANDLE           ;doscall to set semaphore
  239.            CMP          AX,0                ;check for a good return code
  240.            JE           SUCC1               ;if good return code - go on
  241.            MOV          DOS_RC,AX           ;otherwise show dos error and
  242.            CALL         SHOW_DOS_ERR        ;jump to end
  243.            MOV          SYS_ERR,1
  244.            JMP          EVNT_ENDD
  245. SUCC1:
  246.            CALL         READEVENT           ;call subroutine to issue
  247.                                             ;comreadevent verb
  248.            CMP          SYS_ERR,0           ;check system error
  249.            JNE          EVNT_ENDD
  250.            @DOSSEMWAIT  SEMHANDLE,SEMTIMOUT_INF
  251.                                             ;doscall to wait for semaphore
  252.                                             ;to be cleared by async subsys
  253.            CMP          AX,0                ;check return code
  254.            JE           SUCC2               ;handle any error
  255.            MOV          DOS_RC,AX
  256.            CALL         SHOW_DOS_ERR
  257.            JMP          EVNT_ENDD
  258.            MOV          SYS_ERR,1
  259. SUCC2:
  260.            MOV          EVENTFLAG,0FFH      ;set flag to session ended
  261. EVNT_ENDD:
  262.            @DOSEXIT     ACTION,RESULT_CODE
  263.  
  264. EVENT      ENDP
  265.  
  266.  
  267. READEVENT  PROC         NEAR
  268.  
  269. ;  This subroutine will issue comreadevent verb so that the calling process
  270. ;  can wait on the semaphore to be cleared.
  271.  
  272.            PUSHA                            ;push work registers
  273.  
  274.            MOV          AX,DS
  275.            MOV          ES,AX
  276.            MOV          BYTE PTR ES:MASK.EVENT_MASK_1,0
  277.            MOV          BYTE PTR ES:MASK.EVENT_MASK_1+2,AA_BREAK_RECEIVED
  278.            MOV          BYTE PTR ES:MASK.EVENT_MASK_1+3,AA_STOP_ISSUED
  279.            MOV          BYTE PTR ES:MASK.EVENT_MASK_1+4,0
  280.                                             ;set up event masks for the events
  281.                                             ;we want to be notified of
  282.            MOV          RDEVNT.FUNCTION_CODE,COM_READ_EVENT
  283.                                             ;insert function code
  284.            @MOVW        RDEVNT.COM_DEV_HANDLE,HANDLE
  285.                                             ;com. device handle
  286.            MOV          WORD PTR RDEVNT.SEM_HANDLE+2,DS
  287.            LEA          AX,SEMAPHOR
  288.            MOV          WORD PTR RDEVNT.SEM_HANDLE,AX
  289.                                             ;seg. & offset values of SEMAPHOR
  290.            MOV          WORD PTR RDEVNT.BUFFER_ADDRESS+2,DS
  291.            MOV          AX,OFFSET EVENTSTRUCT.EVENT_TYPE_1
  292.            MOV          WORD PTR RDEVNT.BUFFER_ADDRESS,AX
  293.                                             ;seg. & offset of EVENT_STRUCT
  294.            MOV          WORD PTR RDEVNT.EVENT_MASKS+2,DS
  295.            MOV          AX,OFFSET MASK.EVENT_MASK_1
  296.            MOV          WORD PTR RDEVNT.EVENT_MASKS,AX
  297.                                             ;seg. & offset of MASKS
  298.            @ACDI        RDEVNT.FUNCTION_CODE
  299.                                             ;call acdi to issue the verb
  300.            MOV          AX,RDEVNT.RETURN_CODE
  301.            CMP          AX,0
  302.            JE           RETT_EVNT           ;jump to end if good ret_code
  303.            MOV          RET_CODE,AX         ;otherwise copy ret and func codes
  304.            @MOVB        FUNC_CODE,RDEVNT.FUNCTION_CODE
  305.            CALL         SHOW_ERR            ;show error
  306.            MOV          SYS_ERR,1           ;set system error
  307. RETT_EVNT:
  308.            POPA                             ;pop work registers
  309.            RET
  310.  
  311. READEVENT  ENDP
  312.  
  313.  
  314. RECV       PROC       FAR
  315.  
  316. ;This is the main process, which calls subroutines one by one to issue
  317. ;acdi verbs, starts the thread process and then calls READLINES to read
  318. ;the message from the other PC
  319.  
  320.            MOV          MSG_NO,7            ;msg_no 7 is "ACDI sample
  321.            CALL         SHOW_MSG            ;receiver program"
  322.  
  323.            CMP          SYS_ERR,0           ;check system error; if zero (no
  324.            JE           STEP2               ;error) jump to next step; else
  325.            JMP          ENDD                ;end the program
  326. STEP2:
  327.            CALL         OPEN                ;issue comopen
  328.  
  329.            CMP          SYS_ERR,0           ;check system error; if zero (no
  330.            JE           STEP3               ;error) jump to next step; else
  331.            JMP          ENDD                ;end the program
  332. STEP3:
  333.            @DOSALLOCSEG OUT_BUFF_LEN,O_ANBPTR_SEL,0
  334.                                             ;Doscall to get an output buffer.
  335.            CMP          AX,0
  336.            JE           STEP4               ;if successful jump to next step
  337.            MOV          DOS_RC,AX           ;otherwise copy the return code,
  338.            CALL         SHOW_DOS_ERR        ;show the error, set system error
  339.            MOV          SYS_ERR,1           ;end the program
  340.            JMP          ENDD
  341. STEP4:
  342.            CALL         DEFOUTBUFF          ;issue comdefoutputbuff
  343.  
  344.            CMP          SYS_ERR,0           ;check system error; if zero (no
  345.            JE           STEP5               ;error) jump to next step; else
  346.            JMP          ENDD                ;end the program
  347. STEP5:
  348.            @DOSALLOCSEG IN_BUFF_LEN,I_ANBPTR_SEL,0
  349.                                             ;Doscall to get the input buffer.
  350.            CMP          AX,0
  351.            JE           STEP6               ;if successful jump to next step
  352.            MOV          DOS_RC,AX           ;otherwise copy the return code,
  353.            CALL         SHOW_DOS_ERR        ;show the error, set system error
  354.            MOV          SYS_ERR,1           ;and end the program
  355.            JMP          ENDD
  356. STEP6:
  357.            CALL         DEFINBUFF           ;issue comdefinput
  358.  
  359.            CMP          SYS_ERR,0           ;check system error; if zero (no
  360.            JE           STEP7               ;error) jump to next step; else
  361.            JMP          ENDD                ;end the program
  362. STEP7:
  363.            CALL         SETBITRTE           ;issue comsetbitrate
  364.  
  365.            CMP          SYS_ERR,0           ;check system error; if zero (no
  366.            JE           STEP8               ;error) jump to next step; else
  367.            JMP          ENDD                ;end the program
  368. STEP8:
  369.            CALL         SETLINCTRL          ;issue comsetlinectrl
  370.  
  371.            CMP          SYS_ERR,0           ;check system error; if zero (no
  372.            JE           STEP9               ;error) jump to next step; else
  373.            JMP          ENDD                ;end the program
  374. STEP9:
  375.            CALL         SETTIMOUTS          ;issue comsettimouts
  376.  
  377.            CMP          SYS_ERR,0           ;check system error; if zero (no
  378.            JE           STEP10              ;error) jump to next step; else
  379.            JMP          ENDD                ;end the program
  380. STEP10:
  381.            CALL         CONNECT             ;issue comconnect
  382.  
  383.            CMP          SYS_ERR,0           ;check system error; if zero (no
  384.            JE           STEP11              ;error) jump to next step; else
  385.            JMP          ENDD                ;end the program
  386. STEP11:
  387.            @DOSCREATETHREAD  THRD_PGM_ADR,THRD_ID,THRD_STK_ADR
  388.                                             ;Doscall to start thread proc.
  389.            CMP          AX,0
  390.            JE           STEP12              ;if successful jump to next step
  391.            MOV          DOS_RC,AX           ;otherwise copy the return code,
  392.            CALL         SHOW_DOS_ERR        ;show the error, set system error
  393.            MOV          SYS_ERR,1           ;and end the program
  394.            JMP          ENDD
  395. STEP12:
  396.  
  397.            CALL         READLINES           ;call subr. to read message
  398.  
  399.            CMP          SYS_ERR,0           ;check system error; if zero (no
  400.            JE           STEP13              ;error) jump to next step; else
  401.            JMP          ENDD                ;end the program
  402. STEP13:
  403.            CALL         DISCONNECT          ;issue comdisconnect
  404.  
  405.            CMP          SYS_ERR,0           ;check system error; if zero (no
  406.            JE           STEP14              ;error) jump to next step; else
  407.            JMP          ENDD                ;end the program
  408. STEP14:
  409.            CALL         CLOSE               ;issue comclose
  410. ENDD:
  411.            @DOSEXIT     ACTION,RESULT_CODE
  412. RECV       ENDP
  413.  
  414.  
  415. READLINES  PROC         NEAR
  416.  
  417. ;  This subroutine will clear the screen in preparation for receiving the
  418. ;  message, issue com_read_char_string verb as long as EVENTFLAG is on,
  419. ;  read the message character by character, display it on the screen. It
  420. ;  will quit when the flag is set to session ended.
  421.  
  422.            PUSHA                            ;push work registers
  423.            CALL         CLR_SCRN            ;call subr. to clear screen
  424.  
  425. LOOP1:
  426.            CMP          SYS_ERR,0           ;check system error; if zero (no
  427.            JE           READSTEP1           ;error) jump to next step; else
  428.            JMP          RETT                ;end the program
  429. READSTEP1:
  430.            CALL         SET_CRSR_POS        ;set cursor on row, col
  431.            CMP          SYS_ERR,0           ;check system error; if zero (no
  432.            JE           LOOP2               ;error) jump to next step; else
  433.            JMP          RETT                ;end the program
  434. LOOP2:
  435.            CMP          EVENTFLAG,0H        ;check the flag
  436.            JE           READSTEP2
  437.            JMP          RETT
  438. READSTEP2:
  439.            MOV          BYTESNEEDED,1
  440.            CALL         READCHARSTR         ;issue comreadcharstring
  441.  
  442.            CMP          SYS_ERR,0           ;check system error; if zero (no
  443.            JE           READSTEP3           ;error) jump to next step; else
  444.            JMP          RETT                ;end the program
  445. READSTEP3:
  446.            CMP          RET_CODE,0          ;check return code-if zero
  447.            JE           CHAR_RECVD          ;a character is received
  448.            MOV          BYTESFREED,0        ;set bytesfreed to 0
  449.            JMP          LOOP2               ;issue comreadcharstring again
  450. CHAR_RECVD:
  451.            MOV          ES,WORD PTR RDCHRSTR.NEXT_AVAIL_READ_PTR+2
  452.                                             ;ES = seg of next_avail_read_ptr
  453.            MOV          SI,WORD PTR RDCHRSTR.NEXT_AVAIL_READ_PTR
  454.                                             ;SI = off of next_avail_read_ptr
  455.            MOV          AL,ES:[SI]          ;mov to AL the received char.
  456.            CMP          AL,CAR_RET          ;if received character is carriage
  457.            JE           NXT_LIN             ;return jump to NXT_LIN
  458.            MOV          RECVD_CHAR,AL       ;else copy received character in
  459.                                             ;RECVD_CHAR and call vio
  460.                                             ;function to write it on screen
  461.            @VIOWRTNCHAR  RECVD_CHAR,1,ROW,COL,0
  462.            MOV          BYTESFREED,1        ;set bytesfreed to 1
  463.            INC          COL                 ;increment column
  464.            CMP          COL,80              ;79 is the last column on screen
  465.            JE           SET_COL_ZERO        ;so if column 79 is reached -
  466.            JMP          LOOP1
  467. SET_COL_ZERO:
  468.            MOV          COL,0               ;set it back to zero
  469.            JMP          LOOP1               ;repeat again to get the next
  470.                                             ;character
  471. NXT_LIN:
  472.            MOV          BYTESFREED,1        ;set bytesfreed to 1
  473.            INC          ROW                 ;increment row
  474.            CMP          ROW,24              ;if row is 24
  475.            JE           SCROLL              ;jump to scroll
  476.            MOV          COL,0               ;else set col to 0
  477.            JMP          LOOP1               ;repeat again, get next character
  478. SCROLL:
  479.            CALL         SCROL_SCRN          ;subr. to scroll screen by 1 row
  480.            MOV          ROW,23              ;set row to 23
  481.            MOV          COL,0               ;set column to 0
  482.            JMP          LOOP1               ;repeat again,get next character
  483. RETT:
  484.            POPA
  485.            RET                              ;pop work registers
  486. READLINES  ENDP
  487.  
  488.  
  489. ;*****************************************************************************
  490. ;   UTILITY PROC'S
  491. ;*****************************************************************************
  492.  
  493. CLEAR_VCB    PROC       NEAR
  494.  
  495. ;Writes 0's in the control block. This is done before the control block is
  496. ;built for each acdi verb because the same memory area is used for control
  497. ;blocks for every acdi verb.
  498.  
  499.            PUSHA
  500.            XOR          DI,DI
  501. LOOP_CB:   MOV          BYTE PTR VCB[DI],0
  502.            INC          DI
  503.            CMP          DI,VCB_LEN
  504.            JL           LOOP_CB
  505.            POPA
  506.            RET
  507. CLEAR_VCB    ENDP
  508.  
  509. SHOW_ERR     PROC       NEAR
  510. ;  This function shows errors relating to ACDI verbs.
  511.  
  512.            PUSHA
  513.            MOV          MSG_NO,2            ;msg number 2 is "ACDI verb in
  514.                                             ;error - function code =    "
  515.            CALL         SHOW_MSG            ; call proc to show msg_no 2
  516.            MOV          AH,0
  517.            MOV          AL,FUNC_CODE        ;set parameters for CVHEX proc
  518.            LEA          DI,F_C_HX
  519.            CALL         CVHEX               ;proc to convert hex data into
  520.                                             ;printable hex
  521.            @VIOWRTTTY F_C_HX,F_C_HX_LEN,0   ;vio call to write on screen
  522.  
  523.            MOV          MSG_NO,3            ;msg number 3 is "return code =  "
  524.            CALL         SHOW_MSG
  525.            MOV          AX,RET_CODE
  526.            LEA          DI,R_C_HX
  527.            CALL         CVHEX
  528.            @VIOWRTTTY R_C_HX,R_C_HX_LEN,0
  529.            POPA
  530.            RET
  531. SHOW_ERR     ENDP
  532.  
  533. SHOW_DOS_ERR  PROC
  534. ;  This function shows errors relating to DOS function calls.
  535.  
  536.            PUSHA
  537.            MOV          MSG_NO,4            ;msg number 4 is "DOSCALL
  538.                                             ;in error - return code =    "
  539.            CALL         SHOW_MSG            ;call proc to show msg no 3
  540.            LEA          DI,DOS_RC_HX        ;set parameters for cvhex proc
  541.            CALL         CVHEX               ;proc to convert hex data into
  542.                                             ;printable hex
  543.            @VIOWRTTTY DOS_RC_HX,DOS_RC_HX_LEN,0
  544.                                             ;vio call to write on screen
  545.            POPA
  546.            RET
  547. SHOW_DOS_ERR  ENDP
  548.  
  549. SHOW_VIO_ERR  PROC
  550. ;  This function shows errors relating to Vio function calls.
  551.  
  552.            PUSHA
  553.            MOV          MSG_NO,5            ;msg number 5 is "VIOCALL
  554.                                             ;in error - return code =    "
  555.            CALL         SHOW_MSG            ;call proc to show msg no 5
  556.            LEA          DI,VIO_RC_HX        ;set parameters for cvhex proc
  557.            CALL         CVHEX               ;the convert proc
  558.            @VIOWRTTTY VIO_RC_HX,VIO_RC_HX_LEN,0
  559.                                             ;vio call to write on screen
  560.            POPA
  561.            RET
  562. SHOW_VIO_ERR  ENDP
  563.  
  564. SHOW_MSG     PROC       NEAR
  565. ;  This function displays error messages using argument MSGNO ( message
  566. ;  number) from the message file "ACX.MSG"
  567.  
  568.            PUSHA
  569.            @DOSGETMESSAGE ZERO,0,MSG_BUFF,100,MSG_NO,MSG_FILE,MSG_LEN
  570.                                             ;doscall to get mes from msg file
  571.            CMP          AX,0                ;check return code
  572.            JNE          JUMP                ;show DOSGETMESSAGE in error
  573.                                             ;message if not zero
  574.            @VIOWRTTTY MSG_BUFF,MSG_LEN,0    ;otherwise display message from
  575.                                             ;the message buffer
  576.            JMP          RETT7
  577. JUMP:
  578.            @VIOWRTTTY GETMSERR,GETMSERR_LEN,0
  579. RETT7:
  580.            POPA
  581.            RET
  582. SHOW_MSG     ENDP
  583.  
  584. CVHEX        PROC       NEAR
  585. ;This proc. converts function codes and return codes into printable hex form
  586.  
  587.            PUSH         BX                  ;save work regs
  588.            PUSH         CX
  589.            MOV          BX,AX               ;get hex data
  590.            AND          BX,000FH            ;cleanup to get just 1st nibble
  591.            MOV          CL,HEXTAB[BX]       ;lookup the ASCII representation
  592.            MOV          [DI]+3,CL           ;put it into the output area
  593.            MOV          BX,AX               ;get the original data again
  594.            AND          BX,00F0H            ;cleanup to get the 2nd nibble
  595.            MOV          CL,04               ;shift it over for lookup index
  596.            SHR          BX,CL
  597.            MOV          CL,HEXTAB[BX]       ;lookup the ASCII representation
  598.            MOV          [DI]+2,CL           ;put it into the result
  599.            MOV          BX,AX               ;get the original data again
  600.            AND          BX,0F00H            ;3rd nibble
  601.            MOV          CL,08               ;shift it
  602.            SHR          BX,CL
  603.            MOV          CL,HEXTAB[BX]       ;lookup the ASCII rep.
  604.            MOV          [DI]+1,CL           ;into result
  605.            MOV          BX,AX
  606.            AND          BX,0F000H           ;4th nibble
  607.            MOV          CL,12               ;shift
  608.            SHR          BX,CL
  609.            MOV          CL,HEXTAB[BX]       ;lookup
  610.            MOV          [DI],CL             ;save result
  611.            POP          CX                  ;restore regs & exit
  612.            POP          BX
  613.            RET
  614. CVHEX        ENDP
  615.  
  616. ;*****************************************************************************
  617. ;   ACDI RELATED PROC'S
  618. ;*****************************************************************************
  619.  
  620. ;To issue an acdi verb the program has to build the control block structure
  621. ;with the parameters and pass the pointer to the control block to the
  622. ;acdi subsystem. Each of the following subroutines, when called, will build
  623. ;the control block structure and then call acdi. When the acdi subsystem
  624. ;returns the subroutine will check the return code, call SHOW_ERR process
  625. ;if the return code is bad, otherwise return to the calling process.
  626.  
  627. OPEN       PROC         NEAR
  628. ; This proceduere issue com_open verb to open the specified device for
  629. ; communication.
  630.  
  631.            PUSHA
  632.            CALL         CLEAR_VCB           ;zero out the control block
  633.  
  634.            MOV          OPN.FUNCTION_CODE,COM_OPEN
  635.                                             ;verb - com_open
  636.            LEA          SI,DEV_NAME         ;copy device name in control blk.
  637.            LEA          DI,OPN.COM_DEV_NAME
  638.            MOV          AX,DS
  639.            MOV          ES,AX
  640.            CLD
  641.            MOV          CX,4
  642. LOOP_COM:
  643.            MOVSB
  644.            LOOP         LOOP_COM
  645.  
  646.            @ACDI        VCB                 ;issue the verb
  647.  
  648.            @MOVW        HANDLE,OPN.COM_DEV_HANDLE
  649.                                             ;copy device handle returned by
  650.                                             ;acdi for use in other verbs
  651.            CMP          OPN.RETURN_CODE,0   ;check if return code is zero
  652.            JE           RETT8               ;return if it is; if not,.....
  653.            @MOVW        RET_CODE,OPN.RETURN_CODE
  654.            @MOVB        FUNC_CODE,OPN.FUNCTION_CODE
  655.            CALL         SHOW_ERR            ;copy ret and func codes, show
  656.            MOV          SYS_ERR,1H          ;error, and set system err flag
  657. RETT8:
  658.            POPA
  659.            RET
  660. OPEN       ENDP
  661.  
  662. DEFOUTBUFF PROC         NEAR
  663. ; This subroutine will issue com_def_output_buff to define output buffer.
  664.  
  665.            PUSHA
  666.            CALL         CLEAR_VCB           ;zero out the control block
  667.  
  668.            @MOVW        DFOTBFF.COM_DEV_HANDLE,HANDLE
  669.            MOV          DFOTBFF.FUNCTION_CODE,COM_DEF_OUTPUT_BUFF
  670.            MOV          AX,O_ANBPTR_SEL
  671.            MOV          WORD PTR DFOTBFF.OUTPUT_BUFF+2,AX
  672.            SUB          AX,AX
  673.            MOV          WORD PTR DFOTBFF.OUTPUT_BUFF,AX
  674.            @MOVW        DFOTBFF.OUT_BUFF_LENGTH,OUT_BUFF_LEN
  675.                                             ;fill in the control block with
  676.                                             ;function code and parameters
  677.            @ACDI        VCB                 ;issue the verb
  678.  
  679.            MOV          AX,DFOTBFF.RETURN_CODE
  680.            CMP          AX,0
  681.            JZ           RETT9
  682.            MOV          RET_CODE,AX
  683.            @MOVB        FUNC_CODE,DFOTBFF.FUNCTION_CODE
  684.            CALL         SHOW_ERR            ;check return code and handle
  685.            MOV          SYS_ERR,1H          ;any errors
  686. RETT9:
  687.            POPA
  688.            RET
  689. DEFOUTBUFF ENDP
  690.  
  691. DEFINBUFF  PROC         NEAR
  692. ; This subroutine will issue com_def_input verb to define input buffer.
  693.  
  694.            PUSHA
  695.            CALL         CLEAR_VCB           ;zero out the control block
  696.  
  697.            @MOVW        DFINBFF.COM_DEV_HANDLE,HANDLE
  698.            MOV          DFINBFF.FUNCTION_CODE,COM_DEF_INPUT
  699.            MOV          AX,I_ANBPTR_SEL
  700.            MOV          WORD PTR DFINBFF.INPUT_BUFF+2,AX
  701.            SUB          AX,AX
  702.            MOV          WORD PTR DFINBFF.INPUT_BUFF,AX
  703.            @MOVW        DFINBFF.IN_BUFF_LENGTH,IN_BUFF_LEN
  704.            MOV          DFINBFF.INPUT_MODE,AA_CHAR_MODE
  705.                                             ;fill in the control block with
  706.                                             ;function code and parameters
  707.            @ACDI        VCB                 ;issue the verb
  708.  
  709.            MOV          AX,DFINBFF.RETURN_CODE
  710.            CMP          AX,0
  711.            JZ           RETTA
  712.            MOV          RET_CODE,AX
  713.            @MOVB        FUNC_CODE,DFINBFF.FUNCTION_CODE
  714.            CALL         SHOW_ERR            ;check return code and handle
  715.            MOV          SYS_ERR,1H          ;any errors
  716. RETTA:
  717.            POPA
  718.            RET
  719. DEFINBUFF  ENDP
  720.  
  721. SETBITRTE  PROC         NEAR
  722. ; This subroutine will issue com_set_bit_rate verb to set up the line
  723. ; data rates (bps).
  724.  
  725.            PUSHA
  726.            CALL         CLEAR_VCB           ;zero out the control block
  727.  
  728.            @MOVW        BITRT.COM_DEV_HANDLE,HANDLE
  729.            MOV          BITRT.FUNCTION_CODE,COM_SET_BIT_RATE
  730.            @MOVW        BITRT.BIT_RATE_RCV,AA_300_BPS
  731.            @MOVW        BITRT.BIT_RATE_SEND,AA_300_BPS
  732.                                             ;fill in the control block with
  733.                                             ;function code and parameters
  734.            @ACDI        VCB                 ;issue the verb
  735.  
  736.            MOV          AX,BITRT.RETURN_CODE
  737.            CMP          AX,0
  738.            JZ           RETTB
  739.            MOV          RET_CODE,AX
  740.            @MOVB        FUNC_CODE,BITRT.FUNCTION_CODE
  741.            CALL         SHOW_ERR            ;check return code and handle
  742.            MOV          SYS_ERR,1H          ;any errors
  743. RETTB:
  744.            POPA
  745.            RET
  746. SETBITRTE  ENDP
  747.  
  748. SETLINCTRL PROC         NEAR
  749. ; This subroutine will issue com_set_line_ctrl to set up line control
  750. ; values.
  751.  
  752.            PUSHA
  753.            CALL         CLEAR_VCB           ;zero out the control block
  754.  
  755.            @MOVW        LINCTRL.COM_DEV_HANDLE,HANDLE
  756.            MOV          LINCTRL.FUNCTION_CODE,COM_SET_LINE_CTRL
  757.            MOV          AX,0
  758.            MOV          LINCTRL.STOP_BITS,AA_1_STOP_BIT
  759.            MOV          LINCTRL.PARITY,AA_EVEN_PARITY
  760.            MOV          LINCTRL.DATA_BITS,AA_7_DATA_BITS
  761.                                             ;fill in the control block with
  762.                                             ;function code and parameters
  763.            @ACDI        VCB                 ;issue the verb
  764.  
  765.            MOV          AX,LINCTRL.RETURN_CODE
  766.            CMP          AX,0
  767.            JZ           RETTC
  768.            @MOVB        FUNC_CODE,LINCTRL.FUNCTION_CODE
  769.            CALL         SHOW_ERR            ;check return code and handle
  770.            MOV          SYS_ERR,1H          ;any errors
  771. RETTC:
  772.            POPA
  773.            RET
  774. SETLINCTRL ENDP
  775.  
  776. CONNECT    PROC         NEAR
  777. ; This subroutine will issue com_connect to establish connection.
  778.  
  779.            PUSHA
  780.            CALL         CLEAR_VCB           ;zero out the control block
  781.  
  782.            @MOVW       CONCT.COM_DEV_HANDLE,HANDLE
  783.            MOV         CONCT.FUNCTION_CODE,COM_CONNECT
  784.            MOV         CONCT.CONNECT_TYPE,AA_CONNECT_TYPE_4
  785.            MOV         CONCT.CONNECT_TIMEOUT_1,CONCTTIMEOUT1
  786.            MOV         CONCT.CONNECT_TIMEOUT_2,CONCTTIMEOUT2
  787.                                             ;fill in the control block with
  788.                                             ;function code and parameters
  789.            @ACDI        VCB                 ;issue the verb
  790.  
  791.            MOV         AX,CONCT.RETURN_CODE
  792.            CMP         AX,0
  793.            JE          RETTD
  794.            MOV         RET_CODE,AX
  795.            @MOVB       FUNC_CODE,CONCT.FUNCTION_CODE
  796.            CALL         SHOW_ERR            ;check return code and handle
  797.            MOV          SYS_ERR,1H          ;any errors
  798. RETTD:
  799.            POPA
  800.            RET
  801. CONNECT    ENDP
  802.  
  803. SETTIMOUTS PROC         NEAR
  804. ; This subroutine will issue com_set_timeouts to set the timeout values
  805. ; for read and write.
  806.  
  807.            PUSHA
  808.            CALL         CLEAR_VCB           ;zero out the control block
  809.  
  810.            @MOVW        TIMOUTS.COM_DEV_HANDLE,HANDLE
  811.            MOV          TIMOUTS.FUNCTION_CODE,COM_SET_TIMEOUTS
  812.            MOV          TIMOUTS.READ_TIMEOUT_BLOCK,INF_RDBLKTMOUT
  813.            MOV          TIMOUTS.READ_TIMEOUT_CHAR,RDCHRTMOUT
  814.            MOV          TIMOUTS.WRITE_TIMEOUT,INF_WRTTMOUT
  815.                                             ;fill in the control block with
  816.                                             ;function code and parameters
  817.            @ACDI        VCB                 ;issue the verb
  818.  
  819.            MOV          AX,TIMOUTS.RETURN_CODE
  820.            CMP          AX,0
  821.            JE           RETTE
  822.            MOV          RET_CODE,AX
  823.            @MOVB        FUNC_CODE,TIMOUTS.FUNCTION_CODE
  824.            CALL         SHOW_ERR            ;check return code and handle
  825.            MOV          SYS_ERR,1H          ;any errors
  826. RETTE:
  827.            POPA
  828.            RET
  829. SETTIMOUTS ENDP
  830.  
  831. READCHARSTR   PROC   NEAR
  832.  
  833.            PUSHA
  834.            CALL         CLEAR_VCB           ;zero out the control block
  835.  
  836.            @MOVW        RDCHRSTR.COM_DEV_HANDLE,HANDLE
  837.            MOV          RDCHRSTR.FUNCTION_CODE,COM_READ_CHAR_STRING
  838.            @MOVW        RDCHRSTR.BYTES_FREED,BYTESFREED
  839.            @MOVW        RDCHRSTR.READ_BYTES_NEEDED,BYTESNEEDED
  840.            @MOVW        RDCHRSTR.INITIAL_WAIT,INITWAIT
  841.                                             ;fill in the control block with
  842.                                             ;function code and parameters
  843.            @ACDI        VCB                 ;issue the verb
  844.  
  845.            MOV          AX,RDCHRSTR.RETURN_CODE
  846.            MOV          RET_CODE,AX         ;copy return code(AX) in RET_CODE
  847.            CMP          AX,0                ;if return code is zero, return
  848.            JE           RETTF
  849.            CMP          AX,0054H            ;otherwise, if ret. code is 54H -
  850.                                             ;means timeout occured - which is
  851.            JE           RETTF               ;ok, so just return
  852.                                             ;if we reach here - error occured
  853.            @MOVB        FUNC_CODE,RDCHRSTR.FUNCTION_CODE
  854.            CALL         SHOW_ERR            ;so show error
  855.            MOV          SYS_ERR,1H          ;set system error to true & ret.
  856. RETTF:
  857.            POPA
  858.            RET
  859. READCHARSTR   ENDP
  860.  
  861. DISCONNECT    PROC      NEAR
  862. ; This subroutine will issue com_disconnect to break the connection.
  863.  
  864.            PUSHA
  865.            CALL         CLEAR_VCB           ;zero out the control block
  866.  
  867.            @MOVW        DSCONCT.COM_DEV_HANDLE,HANDLE
  868.            MOV          DSCONCT.FUNCTION_CODE,COM_DISCONNECT
  869.                                             ;fill in the control block with
  870.                                             ;function code and parameters
  871.            @ACDI        VCB                 ;issue the verb
  872.  
  873.            MOV          AX,DSCONCT.RETURN_CODE
  874.            CMP          AX,0
  875.            JE           RETTI
  876.            MOV          RET_CODE,AX
  877.            @MOVB        FUNC_CODE,DSCONCT.FUNCTION_CODE
  878.            CALL         SHOW_ERR            ;check return code and handle
  879.            MOV          SYS_ERR,1H          ;any errors
  880. RETTI:
  881.            POPA
  882.            RET
  883. DISCONNECT    ENDP
  884.  
  885. CLOSE      PROC         NEAR
  886. ; This subroutine will issue com_close to close the communication device.
  887.  
  888.            PUSHA
  889.            CALL         CLEAR_VCB           ;zero out the control block
  890.  
  891.            @MOVW        CLOS.COM_DEV_HANDLE,HANDLE
  892.            MOV          CLOS.FUNCTION_CODE,COM_CLOSE
  893.                                             ;fill in the control block with
  894.                                             ;function code and parameters
  895.            @ACDI        VCB                 ;issue the verb
  896.  
  897.            MOV          AX,CLOS.RETURN_CODE
  898.            CMP          AX,0
  899.            JE           RETTJ
  900.            MOV          RET_CODE,AX
  901.            @MOVB        FUNC_CODE,CLOS.FUNCTION_CODE
  902.            CALL         SHOW_ERR            ;check return code and handle
  903.            MOV          SYS_ERR,1H          ;any errors
  904. RETTJ:
  905.            POPA
  906.            RET
  907. CLOSE      ENDP
  908.  
  909. ;*****************************************************************************
  910. ;   OS/2 RELATED FUNCTIONS
  911. ;*****************************************************************************
  912.  
  913. CLR_SCRN   PROC         NEAR
  914.  
  915. ;  This function clears the screen to prepare to display message received.
  916. ;  Writes null on the whole screen
  917.  
  918.            PUSHA
  919.  
  920.            @VIOWRTNCHAR NULL,2000,0,0,0
  921.                                             ;doscall to write a character
  922.                                             ;(null) on the screen.
  923.            CMP          AX,0                ;check for good return
  924.            JE           RETT2               ;if good, return; otherwise
  925.            CALL         SHOW_VIO_ERR        ;handle the error
  926.            MOV          SYS_ERR,1H
  927. RETT2:
  928.            POPA
  929.            RET
  930. CLR_SCRN   ENDP
  931.  
  932. SET_CRSR_POS  PROC
  933.  
  934. ;  This function sets the cursor position at the specified row and column.
  935.  
  936.            PUSHA
  937.  
  938.            @VIOSETCURPOS ROW,COL,0
  939.                                             ;doscall to set crsr pos on screen
  940.            CMP          AX,0                ;check for good return
  941.            JE           RETT3               ;if good, return; otherwise
  942.            CALL         SHOW_VIO_ERR        ;handle the error
  943.            MOV          SYS_ERR,1H
  944. RETT3:
  945.            POPA
  946.            RET
  947. SET_CRSR_POS  ENDP
  948.  
  949. SCROL_SCRN  PROC
  950.  
  951. ;This position scrolls the screen by one line
  952.  
  953.            PUSHA
  954.  
  955.            @VIOSCROLLUP 0,0,24,79,1,CH_ATR,0
  956.                                             ;doscall to scroll the screen.
  957.            CMP          AX,0                ;check for good return
  958.            JE           RETT6               ;if good, return; otherwise
  959.            CALL         SHOW_VIO_ERR        ;handle the error
  960.            MOV          SYS_ERR,1H
  961. RETT6:
  962.            POPA
  963.            RET
  964. SCROL_SCRN  ENDP
  965.  
  966. ;*****************************************************************************
  967. CSEG       ENDS
  968. ;*****************************************************************************
  969. ;end of program
  970.            END          RECV
  971.