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

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