home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0010 - 0019 / ibm0010-0019 / ibm0010.tar / ibm0010 / REFLECT.ZIP / API.DOC < prev    next >
Encoding:
Text File  |  1989-10-17  |  106.6 KB  |  4,252 lines

  1.              Reflection API Support Disk
  2.  
  3. This diskette contains support files and utility (demo) programs for
  4. Reflection's API (Application Program Interface) feature.  All Reflection
  5. emulators for the IBM PC family version 3.40 and above have API support
  6. included.  This diskette containing special files and libraries is included
  7. with PLUS versions of Reflection only.
  8.  
  9.  
  10.            API Support Disk Files
  11.  
  12.  
  13.     API.DOC     This document
  14.  
  15.  
  16. <APIDEMO> Directory    Utility programs which use API feature
  17.  
  18.     HPCMD.EXE    Run HP commands at the DOS prompt and see
  19.             the results displayed on the PC screen
  20.  
  21.     HPCMD.C     Source for HPCMD.EXE
  22.  
  23.     DOAPI.EXE    Send a command to Reflection in background
  24.             to transfer a file or run a command script
  25.  
  26.     DOAPI.C     Source for DOAPI.EXE
  27.  
  28.     $.EXE        Run VAX commands from the DOS prompt with
  29.             results displayed on PC screen
  30.  
  31.     HP.BAT        Sample DOS batch file which demonstrates
  32.             how HPCMD.EXE (named LISTF.EXE) can be used
  33.             to check for a file on the HP3000 from DOS
  34.  
  35.     APIDEMO.DOC    Documentation on the above files
  36.  
  37.  
  38. <Pascal> Directory    Turbo Pascal Library support for API
  39.  
  40.     APIUNIT.PAS    Source of API UNIT file
  41.  
  42.     APIUNIT.TPU    TPU Unit file - created by compiling APIUNIT.PAS:
  43.             Code can be included into your Pascal program via the
  44.             'uses' statement
  45.  
  46.     P_APILIB.OBJ    API library in OBJ format. Used to create new
  47.             APIUNIT.TPU.  You may customize APIUNIT.PAS as needed
  48.             and recompile via the TPC command.
  49.  
  50.     SAMPLE.PAS    Sample Pascal program which does API calls
  51.  
  52.     SAMPLE.EXE    Compiled version of SAMPLE.PAS
  53.  
  54.  
  55. <BASIC> Directory    Microsoft QuickBASIC library support for API
  56.  
  57.     API.INC     Include file listing all function
  58.             declarations.    Use the $INCLUDE metacommand
  59.             to include this file in your BASIC source.
  60.  
  61.     SAMPLE.BAS    Sample BASIC program using API calls
  62.  
  63.     SAMPLE.EXE    Compiled version of SAMPLE.BAS
  64.  
  65.     B_APILIB.QLB    QuickBASIC Library with API calls.
  66.             Use with QuickBASIC environment.
  67.  
  68.     B_APILIB.LIB    Standard API LIB for use with command
  69.             line BC compiler and linker
  70.  
  71.     BAS_API.DOC    List of API function declarations
  72.  
  73.  
  74. <C> Directory        C Library support for API
  75.  
  76.     API.H        Include file with API structure definitions
  77.  
  78.     SAMPLE.C    Sample program which uses API calls
  79.  
  80.     SAMPLE.EXE    Compiled version of SAMPLE.C
  81.  
  82.     C_SAPI.LIB    Small model API library
  83.  
  84.     C_CAPI.LIB    Compact model API library
  85.  
  86.     C_MAPI.LIB    Medium model API library
  87.  
  88.     C_LAPI.LIB    Large model API library
  89.  
  90.  
  91.           THE REFLECTION APPLICATION PROGRAM INTERFACE (API)
  92.  
  93.  
  94. Reflection terminal emulation products with the BACKGROUND multitasking feature
  95. have provided the ability to run two programs simultaneously on your PC.  You
  96. can run a program in foreground - say a word processor - and at the same time
  97. be transferring files from the PC to a host computer in the background.
  98.  
  99. With the arrival of the background multitasking feature, it made sense to
  100. provide a way for foreground programs to 'hook' into Reflection so that they
  101. could initiate file transfers, log on to a host computer, dial a modem or
  102. perform some other communication function.  Reflection API provides that
  103. service, allowing DOS programs to control a background copy of Reflection and
  104. make the background copy do anything that a user could do.  Now your programs
  105. can simulate a user typing on the keyboard, issuing commands, filling in data
  106. entry screens, even hitting the hot-key which would pop Reflection into the
  107. foreground.
  108.  
  109. All standard versions of Reflection will be shipped with API support starting
  110. with version 3.40.  The code will not be loaded into memory, however, unless
  111. the user invokes Reflection with the /W switch from the DOS command line.  API
  112. support requires approximately 4000 additional bytes of memory.  While API
  113. support will be present in all versions of Reflection for the IBM PC, software
  114. developers will need the PLUS versions of Reflection 1, 2, 4, or 7 to avail
  115. themselves of software libraries for C, Turbo Pascal and Microsoft QuickBASIC.
  116.  
  117.  
  118. API functions fall into several groups:
  119.  
  120. Status calls
  121.  
  122.     api_rcheck        see if Reflection installed
  123.     api_instchk        see if API present
  124.     api_getinfo        get static information
  125.     api_getstatus        get dynamic information
  126.  
  127. Command Language
  128.  
  129.     Group I  - synchronous (Do while-you-wait commands)
  130.  
  131.     api_startcommands    start a command sequence
  132.     api_docommand        do a command
  133.     api_getvar        return a command language variable
  134.     api_setvar        set a command language variable
  135.     api_found        return value of the FOUND boolean
  136.     api_endcommands     end a command sequence
  137.  
  138.     Group 2  - queued/asynchronous (Do in background commands)
  139.  
  140.     api_cmdstatus        how much free space is in the API queue
  141.     api_qcmd        queue a new command
  142.     api_clrcmdq        flush the queue of commands
  143.  
  144. Keyboard support
  145.  
  146.     api_keystatus        how much free space is in the API queue
  147.     api_qkeys        queue some keystrokes
  148.     api_clrkeybd        flush the keyboard queue
  149.     api_getfkey        get a function key
  150.     api_setfkey        set a function key
  151.  
  152. Screen    support
  153.  
  154.     api_screenread        read the text screen (minus function keys)
  155.     api_atrbscreen        read screen with character attributes
  156.     api_searchscreen    search the screen for a string
  157.  
  158.  
  159. Datacomm support
  160.  
  161.     api_rdchar        read a character from com port    (may be lan)
  162.     api_writeasync        write character to com port (may be lan)
  163.     api_xmitstatus        check status of transmit buffer
  164.     api_releasedc        release the datacomm port
  165.     api_assertdc        re assert control over the datacomm port
  166.  
  167. Session support
  168.  
  169.     api_open        start an API session
  170.     api_close        end an API session
  171.     api_wait        wait until Reflection is free
  172.     api_block        give Reflection some CPU time
  173.     api_popup        pop up Reflection
  174.  
  175. Miscellaneous
  176.  
  177.     api_reset        do a hard reset of Reflection
  178.     api_offerbuf        provide buffers for queuing keys/commands
  179.     api_cancelbuf        cancel use of buffer
  180.  
  181.  
  182. Queued versus Synchronous commands
  183.  
  184. You will notice that some of the functions are QUEUED (asynchronous) and some
  185. of the commands are synchronous.  A queued function posts a request for
  186. Reflection to do something as time permits.  The request is processed when
  187. Reflection gets to it in the queue, and there's no guarantee exactly when it
  188. will be done.  The advantage is that the function call returns to the client
  189. program immediately (as soon as the request is queued) and the client program
  190. can go about its business while Reflection works on the queued request.
  191.  
  192. Suppose that a client program creates a file that it wants Reflection to
  193. transfer to a VAX.  The program can queue the request and then let Reflection
  194. worry about transferring the file.  Meanwhile the client program can be busy
  195. interacting with the user.  Asynchronous commands capitalize on the
  196. multitasking capability of Reflection.
  197.  
  198. More frequently used are synchronous functions, where you must wait for the
  199. function to be completed before proceeding.  This will be familiar to most
  200. programmers.  You want to transfer a file to the VAX.  You call the function,
  201. the file transfers, and when it's all done the function returns with an error
  202. code (hopefully 0).  Synchronous commands can have their limitations if you're
  203. simultaneously trying to interact with a user since, unlike most system calls
  204. (write to file, read character from keyboard), a file transfer can take a long
  205. time.  Your user may wonder what's happening and will get no visual
  206. feedback.  Your PC will act like it is hung and there is no way to break out
  207. except by using Ctrl-Alt-Del.  See the tip on Synchronous File Transfers
  208. below to get around this.
  209.  
  210. It can be dangerous, too.  If you forget and send Reflection a command like
  211. "WAIT FOR 'Password:  '", you had better be sure that the text 'Password:'
  212. is going to come down from the host computer SOON, otherwise the function call
  213. will NEVER return!  Your computer is hung waiting for the required message to
  214. come from the VAX or HP3000.  Rather than risk this, you will want to make sure
  215. that all commands have a timeout period:
  216.  
  217.         'WAIT 0:0:2 for "Password: "'
  218.  
  219. This command will only wait up to 2 seconds for the string.  If the string has
  220. already arrived or arrives in .05 seconds, the call will return quickly to your
  221. program.  Another function lets you find out if the string was actually found.
  222.  
  223. Note that API is only active if Reflection is in background.  If Reflection is
  224. popped into the foreground, the API client program (like any other foreground
  225. program) freezes until Reflection is popped back into the background.
  226.  
  227.  
  228.  
  229.               The API Function Calls
  230.               ----------------------
  231.  
  232.  
  233. The following section consists of a description of each of the function calls
  234. with short examples in C and assembler, Pascal and QuickBASIC.    Function
  235. calls 28, 29, and 30 are reserved for future use.
  236.  
  237.     Assembly Language Interface
  238.  
  239.     AH = 0DE52H
  240.     DX = 0
  241.     CH = 0        (reserved for future use)
  242.     CL = API function code
  243.     ES   Used to pass parameters
  244.     BX   Used to pass parameters
  245.     SI   Used to pass parameters
  246.     DI   Used to pass parameters
  247.  
  248.     INT    21H    Use MS-DOS Interrupt 21H to access API
  249.  
  250.  
  251. -----------------------------------------------------------------------------
  252.     api_rcheck        # - N/A
  253. -----------------------------------------------------------------------------
  254.     Purpose:    See if a copy of Reflection is present in the
  255.             background.
  256.  
  257.     INPUT    AX = 0DE57H
  258.  
  259.     OUTPUT    AX = "RQ"        - implies Reflection present
  260.         AX = other value - implies Reflection not present
  261.  
  262.        *This function has existed in all versions of Reflection
  263.     from 2.00 on.    Departs from the standard API call format
  264.     (AX = DE57H instead of DE52H.  CX N/A.
  265.  
  266.     This function may be used to detect the presence of any
  267.     version of Reflection including those prior to version 3.4.
  268.     It does not imply that the API code is present, only that
  269.     a copy of Reflection is present in background.    This will
  270.     enable you to tell a user that while Reflection may be
  271.     installed, either the /W switch was not used or it is
  272.     a pre-3.40 version.
  273.  
  274. Assembler Example:
  275. ------------------
  276.     mov    ah,0DE57H
  277.     int    21h
  278.     cmp    ax, "RQ"                ;  Does AX have correct signature?
  279.     jz    Reflection_present    ;  Yes - Reflection is present
  280.     mov    ah,9            ;  No  - print error message and exit
  281.     mov    dx,offset error_message
  282.     int    21h
  283.     mov    ah,4ch
  284.     int    21h
  285. error_message    db    "Reflection not installed",0dh,0ah,"$"
  286.  
  287.  
  288. C Function Definition:
  289. ----------------------
  290. int api_rcheck()    returns 0 if Reflection is present
  291.  
  292.  
  293. C Programming Example:
  294. ----------------------
  295. main()
  296. {
  297.     /* See if Reflection is in background */
  298.  
  299.     if (api_rcheck())
  300.         printf("Reflection not installed\n");
  301.     else
  302.         printf("Reflection in background\n");
  303. }
  304.  
  305.  
  306.  
  307.  
  308. BASIC Function Definition
  309. -------------------------
  310.  
  311. DECLARE FUNCTION api.rcheck% CDECL ()
  312.  
  313.  
  314. BASIC example    - see if Reflection installed
  315. -------------
  316.  
  317. ' $INCLUDE: 'API.INC'
  318.  
  319. if api.rcheck <> 0 then
  320.     print "Reflection not installed"
  321. else
  322.     print "Reflection in background"
  323. end if
  324.  
  325. TURBO Function Definition
  326. -------------------------
  327.  
  328. function api_rcheck : integer;
  329.  
  330.  
  331. TURBO Pascal example    - see if Reflection installed
  332. --------------------
  333. uses    apiunit;
  334. var
  335.  
  336. begin
  337.     if api_rcheck <> 0 then
  338.         writeln('Reflection not installed')
  339.     else
  340.         writeln('Reflection in background');
  341.  
  342.  
  343.  
  344. -----------------------------------------------------------------------------
  345.     api_instchk            0
  346. -----------------------------------------------------------------------------
  347.     Purpose:  See if the API support code has been loaded via
  348.           the /W switch.  Determines Reflection product,
  349.           version, and serial numbers.
  350.  
  351.     The remaining 17 bytes of the buffer are reserved for future
  352.     use.
  353.  
  354.     INPUT:    CX = 0
  355.         AX = DE52H
  356.         DX = 0
  357.         ES:BX point to 32 byte buffer to receive serial number
  358.  
  359.  
  360.     OUTPUT:
  361.        No error:
  362.         AX =  0
  363.         Null-terminated Reflection 14-byte serial number
  364.         copied to buffer.
  365.         See Command Language manual for serial number format.
  366.        Error:
  367.         AX <> 0
  368.  
  369.  
  370. Assembler Example:
  371. ------------------
  372.     mov    ax,0DE52H
  373.     xor    dx,dx
  374.     mov    cx,0
  375.     push    ds
  376.     pop    es
  377.     ASSUME ES:DATA
  378.     mov    bx,offset serialno_buffer   ;ES:BX -> buffer
  379.     int    21h
  380.     or    ax,ax
  381.     jnz    not_installed    ; Error if AX not zero
  382.  
  383.  
  384. serialno_buffer db    32 dup (0)
  385.  
  386. C Function Definition:
  387. ----------------------
  388.  
  389. int api_instchk(serialbuf)    returns 0 if Reflection present
  390. char    *serialbuf;        serialbuf points to 32 byte buffer
  391.  
  392.  
  393. C Programming Example:
  394. ----------------------
  395.  
  396. char    serialbuf[32];
  397.     if ( api_instchk( serialbuf )) {
  398.         printf( "API support not present restart with /W switch\n");
  399.         exit();
  400.     }
  401.     else
  402.         printf( "Reflection serial number %s\n", serialbuf );
  403.  
  404.  
  405. BASIC Function Definition
  406. -------------------------
  407.  
  408. DECLARE FUNCTION api.instchk% CDECL (SEG serno$)
  409. set serno$ to spaces prior to call
  410. serno$= spaces$(32)
  411.  
  412. Basic Example    - Get Reflection serial number if API present
  413. -------------
  414. ' $INCLUDE: 'API.INC'
  415.  
  416.     serno$ = space$(32)
  417.     if api.rcheck%(serno$) <> 0 then
  418.          print "API support not present, restart with /W switch")
  419.     end if
  420.  
  421. TURBO Function Definition
  422. -------------------------
  423.  
  424. function api_InstChk( var s: string ) :integer;
  425.  
  426. TURBO Pascal example
  427. --------------------
  428.  
  429. uses    apiunit;
  430. var    serno    : string[32];
  431.  
  432. begin
  433.     if api_instchk( serno ) > 0  then exit;
  434.     writeln( 'serial number is ', serno )
  435. end.
  436.  
  437. -----------------------------------------------------------------------------
  438.         api_open               1
  439. -----------------------------------------------------------------------------
  440.     Purpose: Initialize Reflection for a series of API function
  441.          calls.
  442.  
  443.     Make this call prior to making any others, except for
  444.     api_instchk (function 0) or api_rcheck.
  445.  
  446.     Make this call once prior to using Reflection API
  447.     and make the api_close call when API use is
  448.     complete.
  449.  
  450.  
  451.     INPUT:    CX = 1
  452.         AX = DE52H
  453.         DX = 0
  454.  
  455.  
  456.     OUTPUT:
  457.        No error:
  458.         AX =  0
  459.  
  460.        Error:
  461.         AX = error code
  462.         Should not return error if Reflection present
  463.  
  464. Assembler Example:
  465. ------------------
  466.     mov    ax,0DE52H
  467.     xor    dx,dx
  468.     mov    cx,1
  469.     int    21h
  470.     or    ax,ax
  471.     jz    api_started
  472.     mov    ah,4ch
  473.     int    21h
  474.  
  475. C Function Definition:
  476. ----------------------
  477. int api_open();
  478.  
  479.  
  480. C Programming Example:
  481. ----------------------
  482.  
  483. main()
  484. {
  485.     /* Start API services */
  486.  
  487.     if(!api_open())
  488.         printf( "Reflection API initialized\n");
  489.     else
  490.         printf( "Reflection API not found\n");
  491.     api_close();
  492. }
  493.  
  494.  
  495. BASIC Function Definition
  496. -------------------------
  497.  
  498. DECLARE FUNCTION api.open% CDECL ()
  499.  
  500. BASIC Example    - open API services
  501. -------------
  502. ' $INCLUDE: 'API.INC'
  503.     i% = api.open%
  504.  
  505. TURBO Function Definition
  506. -------------------------
  507.  
  508. function api_Open :integer;
  509.  
  510.  
  511. TURBO Pascal example
  512. --------------------
  513.  
  514.     uses    apiunit;
  515.     var
  516.         i : integer;
  517.     begin
  518.         i := api_open;
  519.     end.
  520. -----------------------------------------------------------------------------
  521.     api_close              2
  522. -----------------------------------------------------------------------------
  523.     Purpose: Closes API services, clears buffers and
  524.          returns Reflection to pre-start state.
  525.  
  526.     Do not make this call until API use is complete.  You may wish to
  527.     queue several commands and terminate your program without issuing an
  528.     api_close command to allow Reflection to process the commands in
  529.     background.  Don't issue the close command until the commands have
  530.     been completed since this call will clear the command queues.
  531.  
  532.  
  533.     INPUT:    CX = 2
  534.         AX = DE52H
  535.         DX = 0
  536.  
  537.     OUTPUT:
  538.        No error:
  539.         AX =  0
  540.        Error:
  541.         Should not return an error if installed
  542.  
  543.  
  544. Assembler Example:
  545. ------------------
  546.     mov    ax,0DE52H
  547.     xor    dx,dx
  548.     mov    cx,2
  549.     int    21h
  550.     or    ax,ax
  551.     ret
  552.  
  553. C Function Definition:
  554. ----------------------
  555. int api_close();
  556.  
  557.  
  558. C Programming Example:
  559. ----------------------
  560.     api_close();
  561.  
  562.  
  563. BASIC Function Definition
  564. -------------------------
  565.  
  566. DECLARE FUNCTION api.close% CDECL ()
  567.  
  568.  
  569. BASIC Example    - close API services
  570. -------------
  571. ' $INCLUDE: 'API.INC'
  572.     i% = api.close%
  573.  
  574.  
  575. TURBO Function Definition
  576. -------------------------
  577.  
  578. function api_Close :integer;
  579.  
  580. TURBO Pascal example
  581. --------------------
  582.     uses    apiunit;
  583.     var
  584.         i : integer;
  585.     begin
  586.         i := api_close;
  587.     end.
  588.  
  589. -----------------------------------------------------------------------------
  590.     api_getinfo        3
  591. -----------------------------------------------------------------------------
  592.     Purpose: Get information from Reflection.  This call returns
  593.          information of a relatively non-volatile nature,
  594.          i.e. information what should not change on a second
  595.          by second basis.
  596.  
  597.     INPUT:    CX = 3
  598.         AX = DE52H
  599.         DX = 0
  600.         ES:BX points to user buffer
  601.         SI = # of words of information to be written to user
  602.         buffer. If SI exceeds structure size (25) remaining space
  603.         is zeroed.
  604.  
  605.     OUTPUT:
  606.        No error:
  607.         AX =  0
  608.         Buffer initialized
  609.  
  610.        Error:
  611.         AX = error code
  612.         Should not return error if Reflection present
  613.  
  614.  
  615.  
  616. struct api_infostruc {
  617.     int          apiinfo_apiversion;
  618.     int          apiinfo_function_key_mode;
  619.     int          apiinfo_local_echo;
  620.     int          apiinfo_remote_mode;
  621.     int          apiinfo_caps_lock;
  622.     int          apiinfo_display_functions;
  623.     int          apiinfo_auto_linefeed;
  624.     int          apiinfo_right_margin;
  625.     int          apiinfo_phys_screen_width;
  626.     int          apiinfo_memory_response;         /* HP */
  627.     int          apiinfo_xmit_functions;         /* HP */
  628.     int          apiinfo_spow_strap;         /* HP */
  629.     int          apiinfo_inheolwrp;         /* HP */
  630.     int          apiinfo_line_page_mode;         /* HP */
  631.     int          apiinfo_inhhndshk;         /* HP */
  632.     int          apiinfo_inhdc2;             /* HP */
  633.     int          apiinfo_block_mode;         /* HP */
  634.     int          apiinfo_format_mode;         /* HP */
  635.     int          apiinfo_memory_lock;         /* HP */
  636.     int          apiinfo_type_ahead;         /* HP */
  637.     int          apiinfo_normal_cursor_key_mode;/* DEC */
  638.     int          apiinfo_numeric_keypad_mode;   /* DEC */
  639.     int          apiinfo_multipage_mode;         /* DEC */
  640.     int          apiinfo_user_features_locked;  /* DEC */
  641.     int          apiinfo_udks_locked;         /* DEC */
  642. }
  643.  
  644.         Structure Definitions
  645.         ---------------------
  646.  
  647. apiinfo_apiversion           Version number of API.  High byte = major
  648.                    version.  Low byte is minor version.
  649.  
  650. apiinfo_function_key_mode      Number identifying current set of
  651.                    function keys displayed at bottom of
  652.                    Reflection Screen
  653.  
  654.     R2 R4 Keys            R1, R7, R1V, R7V Keys
  655.  
  656.   MAINMENU       =      0      MODESKEYS       =      0
  657.   SOFTKEYS       =      1      USERKEYS       =      1
  658.   VT102KEYS       =      2      SYSTEMKEYS       =      2
  659.   NOKEYS       =      3      CONFIGKEYS       =      3
  660.   CONFIGKEYS       =      4      MARGINTABKEYS    =      4
  661.   DEVICECTLKEYS    =      5      ENHANCEKEYS       =      5
  662.   DEVICEMODESKEYS  =      6      DEVICECTLKEYS    =      6
  663.   TODEVICEKEYS       =      7      DEVICEMODESKEYS  =      7
  664.   FILEXFERKEYS       =      8      USERMENUKEYS       =      8
  665.   TABKEYS       =      9      FILEXFERKEYS       =      9
  666.   TERMINALKEYS       =      10      TODEVICEKEYS       =      10
  667.   GRAPHICSKEYS       =      11      VT102KEYS       =      11    R1V/R7V
  668.                   VMODESKEYS       =      12    R1V/R7V
  669.                   VMAINMENU       =      13    R1V/R7V
  670.                   VTABKEYS       =      14    R1V/R7V
  671.  
  672. apiinfo_local_echo           0 = OFF           1 = ON
  673. apiinfo_remote_mode           0 = OFF           1 = ON
  674. apiinfo_caps_lock           0 = OFF           1 = ON
  675. apiinfo_display_functions      0 = OFF           1 = ON
  676. apiinfo_auto_linefeed           0 = OFF           1 = ON
  677. apiinfo_right_margin           logical right hand margin of screen (0 relative)
  678. apiinfo_phys_screen_width      actual physical width of screen (1 relative)
  679. apiinfo_memory_response
  680.                 0 = 4K
  681.                 1 = 8K
  682.                 2 = 12K
  683.                 3 = 15K
  684.  
  685. apiinfo_xmit_functions           0 = OFF           1 = ON
  686. apiinfo_spow_strap           0 = OFF           1 = ON
  687. apiinfo_inheolwrp           0 = OFF           1 = ON
  688. apiinfo_line_page_mode           0 = LINE        1 = PAGE
  689. apiinfo_inhhndshk           0 = OFF           1 = ON
  690. apiinfo_inhdc2               0 = OFF           1 = ON
  691. apiinfo_block_mode           0 = OFF           1 = ON
  692. apiinfo_format_mode           0 = OFF           1 = ON
  693. apiinfo_memory_lock           0 = OFF           1 = ON
  694. apiinfo_type_ahead           0 = OFF           1 = ON
  695. apiinfo_normal_cursor_key_mode 0 = APPL        1 = NORMAL
  696. apiinfo_numeric_keypad_mode    0 = APPL        1 = NORMAL
  697. apiinfo_multipage_mode           0 = OFF           1 = ON
  698. apiinfo_user_features_locked   0 = UNLOCKED    1 = LOCKED
  699. apiinfo_udks_locked           0 = UNLOCKED    1 = LOCKED
  700.  
  701. Assembler Example:
  702. ------------------
  703.     mov    ax,0DE52H
  704.     xor    dx,dx
  705.     push    ds
  706.     pop    es
  707.     ASSUME    ES:DATA
  708.     mov    bx,offset infostructure
  709.     mov    cx,3
  710.     int    21h
  711.     or    ax,ax
  712.     jnz    info_error
  713.  
  714. C Function Definition:
  715. ----------------------
  716.  
  717. int api_getinfo( infobuffer, count );
  718. struct api_infostruc *infobuffer;    infobuffer points to structure
  719.                     defined above
  720. int    count;                infobuffer size in words
  721.  
  722. C Programming Example:
  723. ----------------------
  724.  
  725. main()
  726. {
  727.  
  728.     /* find the physical screen width */
  729.  
  730.     struct  api_infostruc infobuffer;
  731.     struct  api_infostruc *sptr;
  732.     api_open();
  733.     sptr    = &infobuffer;
  734.     api_getinfo( sptr , 25);
  735.     printf( "Physical Screen Width = %d\n",sptr->apiinfo_phys_screen_width);
  736.     api_close();
  737. }
  738.  
  739. BASIC Function Definition
  740. -------------------------
  741.  
  742. DECLARE FUNCTION api.getinfo% CDECL (SEG buffer AS RINFO, BYVAL rvarlen%)
  743. see api.inc for RINFO user-defined type definition
  744. rvarlen% = size of buffer
  745.  
  746. BASIC Example    - get Reflection physical screen width
  747. -------------
  748.  
  749. ' $include: 'api.inc'
  750. '
  751. '       See API.INC for description of user-defined type RINFO
  752. '
  753. COMMON X AS RINFO
  754.  
  755. i% = api.getinfo( X, 25%)
  756. print "Reflection screen width is "; x.rphysscreenwidth
  757. end
  758.  
  759.  
  760.  
  761.  
  762. TURBO Function Definition
  763. -------------------------
  764.  
  765. function api_GetInfo(i:integer; var x:info_array ) :integer;
  766.  
  767. i = size of info_array buffer
  768. see apiunit.pas for info_array type declaration
  769.  
  770. TURBO Pascal example    - get screen width
  771. --------------------
  772. uses  apiunit;
  773. var
  774.     info    : info_array;
  775.     i    : integer;
  776.  
  777. begin
  778.     if api_getinfo( 25, info )  > 0 then exit;
  779.     writeln( 'screen width is ', info[8] );
  780. end.
  781. -----------------------------------------------------------------------------
  782.     api_getstatus        4
  783. -----------------------------------------------------------------------------
  784.     Purpose: Return status of volatile information from Reflection.
  785.          This information is time critical.
  786.  
  787.     INPUT:    CX = 4
  788.         AX = DE52H
  789.         DX = 0
  790.         ES:BX point to    structure
  791.         SI   specifies number of words (12) to be returned to user
  792.              buffer.  If SI greater than structure size, excess
  793.              buffer area will be zeroed.
  794.     OUTPUT:
  795.        No error:
  796.         AX =  0
  797.  
  798.  
  799.        Error:
  800.         AX = error code
  801.         Should not return error if Reflection present
  802.  
  803. struct api_statstruc    {
  804.    int          apistat_pagetop_row;
  805.    int          apistat_cursor_row;
  806.    int          apistat_cursor_col;
  807.    int          apistat_left_border;
  808.    int          apistat_cursor_physrow;
  809.    int          apistat_cursor_physcol;
  810.    int          apistat_kb_lock_sw;
  811.    int          apistat_batch_flag;
  812.    int          apistat_datacomm_error_flag;    /* HP */
  813.    int          apistat_host_prompt_received;    /* HP */
  814.    int          apistat_xfer_pending_sw;        /* HP */
  815. };
  816.  
  817.         Structure Definitions
  818.         ---------------------
  819.  
  820. apistat_pagetop_row        0 relative row number of display memory
  821.                 for top of screen, i.e. if 100 lines
  822.                 of text have scrolled off the top of
  823.                 the screen (and are still in display
  824.                 memory), the top of the screen would
  825.                 display row 101 or pagetop_row 100.
  826.  
  827. apistat_cursor_row        logical 0 relative cursor row from
  828.                 beginning of display memory
  829.  
  830. apistat_cursor_col        logical 0 relative cursor column from
  831.                 left hand margin of screen
  832.  
  833. apistat_left_border        column position of left border of screen
  834.                 (true left margin may have been scrolled
  835.                 off of screen)
  836.  
  837. apistat_cursor_physrow        actual physical row where cursor is located
  838.                 (0 relative)
  839.  
  840. apistat_cursor_physcol        actual physical column where cursor is
  841.                 located (0 relative)
  842.  
  843. apistat_kb_lock_sw        keyboard lock status
  844.                 0 = No Lock    <>0 = Keyboard Locked
  845.  
  846.  
  847. apistat_batch_flag        0 = Reflection IDLE, <>0 BUSY
  848.  
  849. apistat_datacomm_error_flag    1 = DATCOMM ERROR has occurred since last
  850.                     primary status request.
  851.  
  852. apistat_host_prompt_received    1 = Host prompt has been received
  853.                 0 = Waiting for host prompt.
  854.  
  855. apistat_xfer_pending_sw     <>0 = Transfer of data has been requested
  856.                       from host.  Waiting to receive prompt
  857.                       before starting transfer.
  858.  
  859.                 0   No transfer pending
  860.  
  861.  
  862.  
  863. Assembler Example:
  864. ------------------
  865.     mov    ax,0DE52H
  866.     xor    dx,dx
  867.     push    ds
  868.     pop    es
  869.     ASSUME    ES:DATA
  870.     mov    bx,offset status_struc
  871.     mov    cx,4
  872.     int    21h
  873.     or    ax,ax
  874.     jnz    info_error
  875.  
  876. status_struc    dw    22 dup (?)    ; 44 byte buffer to receive data
  877.  
  878. C Function Definition:
  879. ----------------------
  880.  
  881. int api_getstatus(  statusbuf, siz )
  882. struct api_statstruc *statusbuf;    statusbuf is pointer to structure
  883. int    siz;
  884.  
  885. C Programming Example:
  886. ----------------------
  887. main()
  888. {
  889.  
  890.     /* find which row the cursor is on */
  891.  
  892.     struct    api_statstruc    buffer;
  893.     struct    api_statstruc    *sptr;
  894.     api_open();
  895.     sptr = &buffer;
  896.     api_getstatus(sptr, 11);    /* returns 11 words of status info */
  897.     printf( "cursor row = %d",sptr->apistat_cursor_row);
  898.     api_close();
  899. }
  900.  
  901. BASIC Function Definition
  902. -------------------------
  903.  
  904. DECLARE FUNCTION api.getstatus% CDECL (SEG buffer AS RSTAT, BYVAL rvarlen%)
  905. see api.inc for RSTAT user-defined type definition
  906. rvarlen% = size of buffer
  907.  
  908.  
  909. BASIC Example    - get physical cursor and row position.
  910. -------------
  911.  
  912. ' $include: 'api.inc'
  913. '
  914. '       See API.INC for description of user-defined type RSTAT
  915. '
  916. COMMON Y AS RSTAT
  917.  
  918. i% = api.getstatus( Y, 11%)
  919. print "Cursor at ROW ";y.Rcursorphysrow ;" COL ";y.Rcursorphyscol
  920. end
  921.  
  922. TURBO Function Definition
  923. -------------------------
  924.  
  925. function api_getstatus(i:integer; var x:stat_array ) :integer;
  926. i = size of stat_array buffer
  927. see apiunit.pas for stat_array type declaration
  928.  
  929. TURBO Pascal example
  930. --------------------
  931. uses    apiunit;
  932. var    status    : stat_array;
  933.  
  934. begin
  935.     if api_getstatus(11, status )  > 0 then exit;
  936.     writeln ( 'cursor row is ', status[1] , ' column ' ,status[2] );
  937. end.
  938.  
  939.  
  940. -----------------------------------------------------------------------------
  941.     api_startcommands    5
  942. -----------------------------------------------------------------------------
  943.     Purpose: Prepares Reflection for series of synchronous commands.
  944.          This call will return an error if Reflection is busy,
  945.          i.e. if it is already performing a command or
  946.          file transfer.  If successful, this call turns off
  947.          incoming (characters remain in receive buffer) unless
  948.          a docommand() is actually being processed.
  949.  
  950.     After the api_startcommands function has been issued, Reflection
  951.     will no longer read incoming datacomm out of the receive buffer
  952.     unless a Reflection command is actually being executed.  In most
  953.     cases, startcommands should not be issued until you are ready to
  954.     start processing commands.  Depending on the type of receive
  955.     pacing, you may run the risk of overflowing the receive buffer.
  956.     Note that datacomm is turned back on while Reflection is
  957.     in foreground.    Upon return to background, datacomm is turned back
  958.     off unless a command is active.
  959.  
  960.     INPUT:    CX = 5
  961.         AX = DE52H
  962.         DX = 0
  963.  
  964.     OUTPUT:
  965.        No error:
  966.         AX =  0
  967.        Error:
  968.         AX = 100H  Not available (busy)
  969.  
  970. Assembler Example:
  971. ------------------
  972.     mov    ax,0DE52H
  973.     xor    dx,dx
  974.     mov    cx,5
  975.     int    21h
  976.     or    ax,ax
  977.     jnz    Reflection_Busy
  978.  
  979. C Function Definition:
  980. ----------------------
  981. int api_startcommands();    returns non-zero if error or busy
  982.  
  983. C Programming Example:
  984. ----------------------
  985.     if(api_startcommands())
  986.         printf( "Reflection Busy\n");
  987.  
  988. BASIC Function Definition
  989. -------------------------
  990.  
  991. DECLARE FUNCTION api.startcommands% CDECL ()
  992.  
  993. BASIC example    - see if we can start docommand sequence
  994. -------------
  995.  
  996. ' $include: 'api.inc'
  997.  
  998. if api.startcommands% > 0 then print "Reflection busy"
  999. end
  1000.  
  1001. TURBO Function Definition
  1002. -------------------------
  1003.  
  1004. function api_startcommands :integer;
  1005.  
  1006. TURBO Pascal example
  1007. --------------------
  1008.     uses    apiunit;
  1009.     var
  1010.         i : integer;
  1011.     begin
  1012.         if api_startcommands <> 0 then
  1013.             writeln ( 'Reflection busy' );
  1014.     end.
  1015.  
  1016. -----------------------------------------------------------------------------
  1017.     api_docommand        6
  1018. -----------------------------------------------------------------------------
  1019.     Purpose: Perform a Reflection command synchronously.  The
  1020.          call does not return to the calling caller until the
  1021.          command has been completed or an error is encountered.
  1022.  
  1023.       During the wait for a Reflection command to complete, you can
  1024.       not use the HOT-KEY.  Reflection will just beep at you.
  1025.       "ALERT" messages will not blink on and off as normal.
  1026.       The calling program will be frozen until the command completes.
  1027.       Make sure that all commands issued will time out after
  1028.       a while otherwise your API program can crash waiting for
  1029.       a condition that may never be met.  See note on
  1030.       Synchronous File Transfers.
  1031.  
  1032.         i.e.  use:
  1033.             WAIT 0:0:10 FOR "^Q"
  1034.               rather than
  1035.             WAIT FOR "^Q"
  1036.  
  1037.     INPUT:    CX = 6
  1038.         AX = DE52H
  1039.         DX = 0
  1040.         ES:BX points to buffer containing null-terminated
  1041.         command string.
  1042.  
  1043.     OUTPUT:
  1044.        No error:
  1045.         AX =  0 Command performed satisfactorily
  1046.  
  1047.  
  1048.        Error:
  1049.         AX =  Standard Reflection error code for command
  1050.               language.
  1051.         AX =  102H Service not open - need api_startcommands()
  1052.  
  1053. Assembler Example:
  1054. ------------------
  1055.     mov    ax,0DE52H
  1056.     xor    dx,dx
  1057.     mov    cx,6            ; Function call 6
  1058.     push    ds
  1059.     pop    es
  1060.     ASSUME    ES:DATA
  1061.     mov    bx,offset Reflection_command
  1062.     int    21h
  1063.     or    ax,ax
  1064.     jnz    command_error
  1065.  
  1066.  
  1067. Reflection_command db "SEND ABC TO XYZ  ASCII REC=80",0
  1068.  
  1069. C Function Definition:
  1070. ----------------------
  1071. int api_docommand( command_string )    returns error code / 0 if no error
  1072.  
  1073.  
  1074. char    *command_string;    command_string points to null-terminated
  1075.                 Reflection command
  1076.  
  1077. C Programming Example:
  1078. ----------------------
  1079. main()
  1080. {
  1081.     /* do a synch file transfer - print error code if failed */
  1082.  
  1083.     int     error;
  1084.     char    *command_string = "SEND ABC TO XYZ ASCII REC=80";
  1085.     api_open();
  1086.     api_startcommands();
  1087.     if (error = api_docommand(command_string))
  1088.            printf( "File transfer failed, error code = %d\n",error);
  1089.     api_endcommands();
  1090.     api_close ();
  1091. }
  1092.  
  1093. BASIC Function Definition
  1094. -------------------------
  1095.  
  1096. DECLARE FUNCTION api.docommand% CDECL (SEG rcommand$)
  1097.  
  1098. BASIC example:    - transfer a file
  1099. --------------
  1100. ' $include: 'api.inc'
  1101.  
  1102. i% = api.startcommands%
  1103. cm$ = "SEND ABC TO XYZ ASCII REC=80"
  1104. error% = api.docommand%(cm$)
  1105. if error% > 0 then print "File transfer failed, error code = ";error%
  1106. i% = api.endcommands%
  1107. end
  1108.  
  1109. TURBO Function Definition
  1110. -------------------------
  1111.  
  1112. function api_DoCommand( var x: string ) :integer;
  1113.  
  1114. TURBO Pascal example    - send a file
  1115. --------------------
  1116.     {$V-}
  1117.     uses    apiunit;
  1118.     var
  1119.         i  : integer;
  1120.         cm : string[80];
  1121.     begin
  1122.         cm := 'SEND ABC TO XYZ ASCII REC=80';
  1123.         if api_startcommands <> 0 then
  1124.             writeln ( 'Reflection busy' );
  1125.         if api_docommand( cm ) <> 0 then
  1126.             writeln ( 'error transferring file' );
  1127.         i := api_endcommands;
  1128.     end.
  1129.  
  1130.  
  1131.  
  1132. -----------------------------------------------------------------------------
  1133.     api_getvar        7
  1134. -----------------------------------------------------------------------------
  1135.     Purpose: Return contents of variable to user buffer.
  1136.          Note that a Reflection variable may contain characters
  1137.          of any value including nulls.
  1138.  
  1139.     This command should only be executed as part of a synchronous
  1140.     command sequence otherwise it can return random values.
  1141.     i.e. It may interrupt Reflection's changing of one variable
  1142.     to another so a false result could occur.
  1143.  
  1144.     *Variables can not always be null-terminated in this way
  1145.     since it is possible for them to contain nulls themselves.
  1146.  
  1147.     INPUT:    CX = 7
  1148.         AX = DE52H
  1149.         DX = 0
  1150.         ES:BX points to 80 byte buffer
  1151.         SI = variable number
  1152.  
  1153.     OUTPUT:
  1154.        No error:
  1155.         AX =  0
  1156.         SI = # length of variable
  1157.        Error:
  1158.         AX = 10AH bad variable no
  1159.  
  1160.  
  1161.  
  1162. Assembler Example:    Get variable V8 and null-terminate
  1163. ------------------
  1164.     mov    ax,0DE52H
  1165.     xor    dx,dx
  1166.     mov    cx,7            ; Function GetVar
  1167.     mov    si,8            ; get variable V8
  1168.     push    ds
  1169.     pop    es
  1170.     ASSUME    ES:DATA
  1171.     mov    bx,offset Variable_Buffer
  1172.     int    21h
  1173.                     ; SI is length of variable V8
  1174.                     ; put NULL at end of string
  1175.     mov    byte ptr [variable_length+SI],0
  1176.     or    ax,ax            ; was there an error
  1177.     jnz    Bad_variable_number    ; yes.
  1178.  
  1179.  
  1180. Variable_Buffer db 80 dup (?)
  1181.  
  1182. C Function Definition:
  1183. ----------------------
  1184.  
  1185. int api_getvar( var_buffer, varno, varlength )
  1186.                 returns non-zero if error
  1187.                 returns length of variable
  1188.  
  1189. char    *var_buffer;        buffer for 80 byte variable
  1190. int    varno;            variable number 0 - 799
  1191. int    &varlength;        returned length of variable
  1192.  
  1193. C Programming Example:
  1194. ----------------------
  1195. main()
  1196. {
  1197.  
  1198.     /*   Find out if a file is present on the HP3000 */
  1199.  
  1200.     int    length;
  1201.     char    varbuf[80];
  1202.     api_open();
  1203.     api_startcommands();
  1204.     printf("Enter filename :");
  1205.     gets(varbuf);
  1206.     length = strlen( varbuf );
  1207.     api_setvar(varbuf,1, length);
  1208.     api_docommand("transmit 'listf $1^m'");
  1209.     api_docommand("readhost 0:0:5 v2");
  1210.     api_docommand("readhost 0:0:5 v2");   /* get HP response */
  1211.     api_docommand("wait 0:0:8 for '^q'");
  1212.     api_getvar( varbuf, 2, &length );     /* get v2 */
  1213.     varbuf[length] = '\0';                /* null-terminate v2 */
  1214.     if (strstr( varbuf, "CIERR" ))
  1215.         printf( "File Not Found on Host\n");
  1216.     api_endcommands();
  1217.     api_close();
  1218. }
  1219.  
  1220. BASIC Function Definition
  1221. -------------------------
  1222.  
  1223. DECLARE FUNCTION api.getvar% CDECL (SEG var$, BYVAL varnumber%, SEG rvarlen%)
  1224. var$ = string first initialized to at least 80 characters in size
  1225.        - for receiving variable data
  1226. varnumber% = variable number
  1227. rvarlen% = length of variable
  1228.  
  1229. BASIC example    - find out if a file is present on a VAX
  1230. -------------
  1231.  
  1232. ' $INCLUDE: 'api.inc'
  1233. LINE INPUT "Enter vax filename"; f$
  1234. if f$< "!" then end
  1235. i% = api.startcommands
  1236. j$ = "transmit 'dir " + f$ + CHR$(13) + "'"
  1237. i% = api.docommand(j$)
  1238. i% = api.docommand("readhost 0:0:5 v2")
  1239. i% = api.docommand("readhost 0:0:5 v2")
  1240. i% = api.docommand("readhost 0:0:5 v2")
  1241. i% = api.docommand("wait 0:0:8 for '^m$'")
  1242. varbuf$ = SPACE$(80)
  1243. i% = api.getvar( varbuf$, 2, l% )
  1244. varbuf$ = MID$( varbuf$, 1, l% )
  1245. IF INSTR(varbuf$, "%DIRECT-W-NOFILES") > 0 THEN
  1246.      PRINT "File "; x$; "not found on vax"
  1247. ELSE
  1248.      PRINT "File "; x$; " on VAX"
  1249. END IF
  1250. i% = api.endcommands
  1251. END
  1252.  
  1253. TURBO Function Definition
  1254. -------------------------
  1255.  
  1256. function api_getvar( i :integer; var x: string ) :integer;
  1257.  
  1258. i = variable number
  1259. x = string variable to return data to
  1260.  
  1261. TURBO Pascal example    - find out if a file is present on a VAX
  1262. --------------------
  1263. uses apiunit;
  1264. {$V-}
  1265. var    fname    : string[80];
  1266.     cm    : string[80];
  1267.     i    : integer;
  1268.     vlen    : integer;
  1269. begin
  1270.     write ( 'Enter vax filename' );
  1271.     readln( fname );
  1272.     if fname < '!' then exit;
  1273.     i := api_startcommands;
  1274.     cm := 'transmit "dir ' + fname + '^m"';
  1275.     i := api_docommand(cm);
  1276.     cm := 'readhost 0:0:5 v2';
  1277.     i := api_docommand( cm );
  1278.     i := api_docommand( cm );
  1279.     i := api_docommand( cm );
  1280.     cm := 'wait 0:0:8 for "^m$"';
  1281.     i := api_docommand( cm );
  1282.     i := api_getvar( 2, cm );
  1283.     if pos( '%DIRECT-W-NOFILES', cm ) <> 0 then
  1284.         writeln ('File ', fname, ' not found on VAX' )
  1285.     else
  1286.         writeln ('File ', fname, ' on VAX' );
  1287. end.
  1288.  
  1289. -----------------------------------------------------------------------------
  1290.     api_setvar        8
  1291. -----------------------------------------------------------------------------
  1292.     Purpose:  Load ascii string into Reflection variable.
  1293.           Reflection variables are limited in length to
  1294.           80 characters.  The default # of variables is
  1295.           10 but can be increased via a SET command to 800.
  1296.  
  1297.     This command should only be executed as part of a synchronous
  1298.     command sequence, otherwise it can return bogus values,
  1299.     i.e. it may interrupt Reflection changing one variable
  1300.     to another so a false result could occur.
  1301.  
  1302.     Variables can not always be null-terminated in this way
  1303.     since it is possible for them to contain nulls themselves.
  1304.  
  1305.     INPUT:    CX = 8
  1306.         AX = DE52H
  1307.         DX = 0
  1308.         ES:BX points to 80 byte buffer
  1309.         SI = variable #
  1310.         DI = length of variable
  1311.     OUTPUT:
  1312.        No error:
  1313.         AX =  0
  1314.        Error:
  1315.         AX = 10AH bad variable no
  1316.              106H bad length
  1317.  
  1318.  
  1319.  
  1320.  
  1321. Assembler Example:    Set variable V2 to value below
  1322. ------------------
  1323.     mov    ax,0DE52H
  1324.     xor    dx,dx
  1325.     mov    cx,8
  1326.     mov    si,2
  1327.     mov    di,VARLENGTH
  1328.     push    ds
  1329.     pop    es
  1330.     ASSUME    ES:DATA
  1331.     mov    bx,offset Variable_Buffer
  1332.     int    21h
  1333.  
  1334.  
  1335.     mov    byte ptr [variable_length+SI],0
  1336.     or    ax,ax            ; was there an error
  1337.     jnz    Bad_variable_number    ; yes.
  1338.  
  1339.  
  1340. Variable_Buffer db "Enter this string in V2"
  1341. VARLENGTH    EQU    $ - Variable_Buffer
  1342.  
  1343. C Function Definition:
  1344. ----------------------
  1345.  
  1346. int    api_setvar( var_buffer, varno, varlength );
  1347.                 returns non-zero if error
  1348.  
  1349.  
  1350. char    *var_buffer;
  1351. int    varno;            /* variable number 0-799 */
  1352. int    varlength;
  1353.  
  1354. C Programming Example:
  1355. ----------------------
  1356. see api_getvar example above
  1357.  
  1358.  
  1359. BASIC Function Definition
  1360. -------------------------
  1361.  
  1362. DECLARE FUNCTION api.setvar% CDECL (SEG var$, BYVAL varnumber%)
  1363. var$ = string containing data to load into variable
  1364. varnumber$ = variable number
  1365.  
  1366. BASIC example    - set a command language variable
  1367. -------------
  1368.  
  1369. ' $INCLUDE: 'API.INC'
  1370.     a$ = "abc" + chr$(0) + "def" ' a$ contains a null
  1371.     i%=api.setvar(a$, 3 )     ' set V3 to a variable which contains a null
  1372.  
  1373. TURBO Function Definition
  1374. -------------------------
  1375.  
  1376. function api_setvar( i :integer; var x: string ) :integer;
  1377. i = variable number
  1378. x = string data to load into Reflection variable
  1379.  
  1380. TURBO Pascal example    - set a command language variable
  1381. --------------------
  1382. {$V-}
  1383. uses apiunit;
  1384. var    cmdvar    : string[80];
  1385.     retvar    : string[80];
  1386.     i    : integer;
  1387. begin
  1388.     cmdvar := 'Load this string in V3';
  1389.     i := api_setvar( 3, cmdvar );
  1390.     i := api_getvar( 3, retvar );
  1391.     writeln ( retvar );
  1392. end.
  1393.  
  1394.  
  1395.  
  1396. -----------------------------------------------------------------------------
  1397.     api_found        9
  1398. -----------------------------------------------------------------------------
  1399.     Purpose: Return the value of the command language FOUND boolean.
  1400.  
  1401.     INPUT:    CX = 9
  1402.         AX = DE52H
  1403.         DX = 0
  1404.  
  1405.     OUTPUT:
  1406.         AX = value of FOUND boolean
  1407.         AX =  0     Not found
  1408.         AX <> 0     Found
  1409.  
  1410.  
  1411. Assembler Example:
  1412. ------------------
  1413.  
  1414.     mov    ax,0DE52H
  1415.     xor    dx,dx
  1416.     mov    cx,9
  1417.     int    21h            ; call API
  1418.     or    ax,ax
  1419.     jz    String_Not_Found
  1420.  
  1421. C Function Definition:
  1422. ----------------------
  1423. int api_found();        Returns value of FOUND boolean
  1424.  
  1425. C Programming Example:
  1426. ----------------------
  1427.  
  1428. main()
  1429. {
  1430.       /* return the state of the found boolean */
  1431.  
  1432.       api_open();
  1433.       api_startcommands();
  1434.       api_docommand("transmit  'john^m'");         /* send username */
  1435.       api_docommand("wait 0:0:8 for 'Password:'"); /* wait 8 sec for password */
  1436.       if (!api_found()) {
  1437.           printf("Timed out waiting for password\n");
  1438.           printf("Try again ?:");
  1439.       }
  1440.       api_endcommands();
  1441.       api_close();
  1442. }
  1443.  
  1444. BASIC Function Definition
  1445. -------------------------
  1446.  
  1447. DECLARE FUNCTION api.found% CDECL ()
  1448.  
  1449. BASIC example    - print a message if successful connect to remote modem
  1450. -------------
  1451. ' $INCLUDE: 'api.inc'
  1452. i% = api.startcommands
  1453. i% = api.docommand("transmit 'ATDT 555-1212^m'")
  1454. i% = api.docommand("WAIT 0:0:45 for 'CONNECT'")
  1455. if api.found then print "Connected to REMOTE MODEM"
  1456. i% = api.endcommands
  1457. end
  1458.  
  1459. TURBO Function Definition
  1460. -------------------------
  1461.  
  1462. function api_Found :integer;
  1463.  
  1464. TURBO Pascal example    - print a message if successful connect to remote modem
  1465. --------------------
  1466. {$V-}
  1467. uses    apiunit;
  1468. var    cm    : string[80];
  1469.     i    : integer;
  1470. begin
  1471.     i  := api_startcommands;
  1472.     cm := 'transmit "ATDT 555-1212^m"';
  1473.     i  := api_docommand( cm );
  1474.     cm := 'WAIT 0:0:30 for "CONNECT"';
  1475.     i  := api_docommand( cm );
  1476.     if api_found <> 0 then
  1477.         writeln ( 'Connected to REMOTE MODEM' )
  1478.     else
  1479.         writeln ( 'No connection' );
  1480.     i  := api_endcommands;
  1481. end.
  1482.  
  1483. -----------------------------------------------------------------------------
  1484.     api_endcommands     10
  1485. -----------------------------------------------------------------------------
  1486.     Purpose: Stop series of synchronous commands.  Turn datacomm
  1487.          back on. Should not return an error
  1488.  
  1489.  
  1490.     INPUT:    CX = 10
  1491.         AX = DE52H
  1492.         DX = 0
  1493.  
  1494.     OUTPUT:
  1495.        No error:
  1496.         AX =  0
  1497.        Error:
  1498.         AX = error code
  1499.         Should not return error
  1500.  
  1501. Assembler Example:
  1502. ------------------
  1503.  
  1504.     mov    ax,0DE52H
  1505.     xor    dx,dx
  1506.     mov    cx,10
  1507.     int    21h
  1508.     or    ax,ax
  1509.     jnz    Serious_error
  1510.  
  1511.  
  1512. C Function Definition:
  1513. ----------------------
  1514.  
  1515. int api_endcommands();
  1516.  
  1517. C Programming Example:
  1518. ----------------------
  1519.  
  1520.     see    api_startcommands
  1521.  
  1522. BASIC Function Definition
  1523. -------------------------
  1524.  
  1525. DECLARE FUNCTION api.endcommands% CDECL ()
  1526.  
  1527. BASIC example
  1528. -------------
  1529.  
  1530.     see    api_startcommands
  1531.  
  1532. TURBO Function Definition
  1533. -------------------------
  1534.  
  1535. function api_EndCommands :integer;
  1536.  
  1537. TURBO Pascal example
  1538. --------------------
  1539.  
  1540.     see    api_startcommands
  1541.  
  1542. -----------------------------------------------------------------------------
  1543.     api_screenread        11
  1544. -----------------------------------------------------------------------------
  1545.  
  1546.     Purpose: Read text from the Reflection screen in background.
  1547.  
  1548.     Screen reads do not extend to function key area.  Returns
  1549.     an error if the screen is in graphics mode.
  1550.  
  1551.  
  1552.     INPUT:    CX = 11
  1553.         AX = DE52H
  1554.         DX = 0
  1555.         BH = ROW    0 relative
  1556.         BL = COL    0 relative
  1557.         ES:DI        points to buffer to contain screen text
  1558.         SI = number of bytes to read
  1559.  
  1560.     OUTPUT:
  1561.        No error:
  1562.         AX =  0
  1563.  
  1564.        Error:
  1565.         AX = 106H asked for read off of screen
  1566.              103H Screen in graphics mode
  1567.  
  1568.  
  1569. Assembler Example:
  1570. ------------------
  1571.     mov    ax,0DE52H
  1572.     xor    dx,dx
  1573.     mov    bh,[start_row]
  1574.     mov    bl,[start_column]
  1575.     mov    si,[bytes_to_read]
  1576.     push    ds
  1577.     pop    es
  1578.     ASSUME    ES:DATA
  1579.     mov    di,offset screen_buffer
  1580.     mov    cx,11
  1581.     int    21h
  1582.     or    ax,ax
  1583.     jnz    screen_read_error
  1584.  
  1585. C Function Definition:
  1586. ----------------------
  1587. int    api_screenread( buffer, row, col, length );
  1588.             returns non-zero if error
  1589. char    *buffer;
  1590. int    row;
  1591. int    col;
  1592. int    length;
  1593.  
  1594. C Programming Example:
  1595. ----------------------
  1596. main()
  1597. {
  1598.  
  1599.     /* read a string off of the screen */
  1600.  
  1601.     char    screen_buffer[30];
  1602.     api_open();
  1603.     api_startcommands();
  1604.  
  1605.     /*    Home cursor, clear screen go down 4 and right 6   */
  1606.     /*    NOTE - THESE ARE HP ESCAPE SEQUENCES - !!!!!! */
  1607.  
  1608.     api_docommand("display '^[H^[J^[B^[B^[B^[B^[C^[C^[C^[C^[C^[C'");
  1609.  
  1610.     /*    display sample text */
  1611.  
  1612.     api_docommand("display 'line at row 4 column 6'");
  1613.  
  1614.     /*    read 22 bytes off of screen at row 4 column 6  */
  1615.  
  1616.     api_screenread(screen_buffer, 4, 6, 22 );
  1617.  
  1618.     screen_buffer[22]='\0';
  1619.     if (strcmp(screen_buffer,"line at row 4 column 6"))
  1620.         printf("returned string doesn't compare\n");
  1621.     else
  1622.         printf("Found [%s]\n",screen_buffer);
  1623.     api_endcommands();
  1624.     api_close();
  1625. }
  1626.  
  1627.  
  1628. BASIC Function Definition
  1629. -------------------------
  1630.  
  1631. DECLARE FUNCTION api.screenread% CDECL (SEG scrbuffer$, BYVAL row%,
  1632.          BYVAL col%, BYVAL rvarlen%)
  1633.  
  1634. scrbuffer$ =  buffer to receive screen data - scrbuffer$  must be first
  1635.           initialized to size sufficient to contain data
  1636. row% = row to start read
  1637. col% = column to start read
  1638. rvarlen% = number of bytes to read
  1639.  
  1640. BASIC example    - print Reflection screen (characters only - no color)
  1641. -------------
  1642. ' Print the Reflection screen.
  1643. ' $INCLUDE: 'api.inc'
  1644. scbuf$ = space$(80*24)
  1645. i% = api.screenread( scbuf$, 0%, 0%, 80%*24% )
  1646. cls
  1647. print scbuf$
  1648. end
  1649.  
  1650. TURBO Function Definition
  1651. -------------------------
  1652.  
  1653. function api_ScreenRead( length ,column, row:integer; var x: buffer ) :integer;
  1654. length = number of bytes to read
  1655. column = column to start read
  1656. row    = row to start read
  1657. x      = buffer to receive data - see apiunit.pas for declaration
  1658.  
  1659. TURBO Pascal example    - read and print 80 columns from Reflection screen
  1660. --------------------
  1661. {$V-}
  1662. uses  apiunit;
  1663. var    scrbuf    : buffer ;
  1664.     j, row, col, k, i  : integer;
  1665.     scrtext        : string[255];
  1666. begin
  1667.      write( 'enter row and column to start screen read :');
  1668.      readln( row, col );
  1669.      j := 80;
  1670.      if api_screenread( j, col, row , scrbuf ) <> 0 then exit;
  1671.      k := 1;
  1672.      scrtext[0] := chr(j);
  1673.      while k <= j do
  1674.        begin
  1675.         scrtext[k] := scrbuf[k-1];
  1676.         k := k+1;
  1677.        end;
  1678.      writeln( scrtext );
  1679. end.
  1680.  
  1681.  
  1682. -----------------------------------------------------------------------------
  1683.     api_keystatus        12
  1684. -----------------------------------------------------------------------------
  1685.     Purpose: Returns amount of free space left in keyboard queue
  1686.          in keys.  Each key actually takes two bytes of space in
  1687.          the queue.
  1688.  
  1689.     INPUT:    CX = 12
  1690.         AX = DE52H
  1691.         DX = 0
  1692.  
  1693.     OUTPUT:
  1694.        AX = amount of free space in units of keys
  1695.  
  1696. Assembler Example:
  1697. ------------------
  1698.     mov    ax,0DE52H
  1699.     xor    dx,dx
  1700.     mov    cx,12
  1701.     int    21h
  1702.     or    ax,ax
  1703.     jz    No_free_space_remaining
  1704.  
  1705.  
  1706. C Function Definition:
  1707. ----------------------
  1708.  
  1709. int    api_keystatus();    returns free space in key units
  1710.  
  1711.  
  1712.  
  1713. C Programming Example:
  1714. ----------------------
  1715.  
  1716. main()
  1717. {
  1718.     if (!api_keystatus)
  1719.         printf( "API Key buffer full\n");
  1720.  
  1721. }
  1722. BASIC Function Definition
  1723. -------------------------
  1724.  
  1725. DECLARE FUNCTION api.keystatus% CDECL ()
  1726.  
  1727. BASIC example    - see if any room left to queue keys
  1728. -------------
  1729. ' $INCLUDE: 'api.inc'
  1730. if api.keystatus = 0 then print "API key buffer full"
  1731.  
  1732.  
  1733. TURBO Function Definition
  1734. -------------------------
  1735.  
  1736. function api_KeyStatus :integer;
  1737.  
  1738.  
  1739. TURBO Pascal example
  1740. --------------------
  1741. uses    apiunit;
  1742. var    i : integer;
  1743. begin
  1744.     if api_keystatus <> 0 then
  1745.         writeln( 'key buffer full');
  1746. end.
  1747.  
  1748. -----------------------------------------------------------------------------
  1749.     api_qkeys           13
  1750. -----------------------------------------------------------------------------
  1751.     Purpose: Queue Reflection keystrokes.  This function call queues
  1752.          keys and returns immediately to the caller.  Since
  1753.          this is an asynchronous (queued) call, the caller will
  1754.          not know when the keys are sent.  The keys are entered
  1755.          into Reflection's keyboard buffer exactly as though
  1756.          they had been typed, except no remapping takes place.
  1757.  
  1758.     There are two kinds of keys on your keyboard, those which
  1759.     cause standard ascii characters to be transmitted and those
  1760.     which perform control functions like resetting an internal modem,
  1761.     bringing up a configuration screen, or switching sets of
  1762.     softkeys.  The api_qkeys function differentiates between
  1763.     these sets of keys.  Keys which cause ascii values to be
  1764.     transmitted or entered are passed by enclosing the string
  1765.     of keys in quotes - either single or double.
  1766.  
  1767.         "read mail"
  1768.         "don't exit"
  1769.         'he said "wait for me!" '
  1770.  
  1771.     C uses quotes to delimit strings, but the quotes are not
  1772.     part of the string.  For this reason, you may have to use
  1773.     single quotes within C string constants such as:
  1774.  
  1775.         char    *keyentry = "'find employee miller'"
  1776.  
  1777.     Control keys such as RETURN and VT-ENTER are keywords
  1778.     and must be passed to the api function unquoted.  These
  1779.     keyword definitions are the same as those used in Reflection's
  1780.     keyboard mapping utility (Keymap or Keycomp).  Here's an
  1781.     example of entering a string of keys followed by a carriage return:
  1782.  
  1783.         api_qkeys( "'MyPassword'  RETURN ");
  1784.  
  1785.     Notice that the password (MyPassword) is a quoted string, but
  1786.     the keyword RETURN is not quoted.  The keynames are documented
  1787.     in the Reflection Technical Reference manual in the keyboard remapping
  1788.     section.
  1789.  
  1790.     INPUT:    CX = 13
  1791.         AX = DE52H
  1792.         DX = 0
  1793.  
  1794.     OUTPUT:
  1795.        No error:
  1796.         AX =  0
  1797.  
  1798.        Error:
  1799.         AX = 104H Queue full
  1800.         AX = 105H Bad Key
  1801.  
  1802.  
  1803. Assembler Example:
  1804. ------------------
  1805.     mov    ax,0DE52H
  1806.     xor    dx,dx
  1807.     push    ds
  1808.     pop    es
  1809.     mov    bx,offset key_buffer
  1810.     mov    cx,13
  1811.     int    21h
  1812.     or    ax,ax
  1813.     jnz    key_queue_error
  1814.  
  1815.  
  1816. key_buffer    db     "'Hello user.acct' return",0
  1817.  
  1818.  
  1819. C Function Definition:
  1820. ----------------------
  1821.  
  1822. int    api_qkeys( keybuffer );     returns non-zero if error
  1823. char    *keybuffer;
  1824.  
  1825.  
  1826. C Programming Example:
  1827. ----------------------
  1828.  
  1829. main()
  1830. {
  1831.  
  1832.     /* Queue some keys if there is room in the key queue */
  1833.  
  1834. char    *keybuffer = "'Hello user.acct' return";
  1835.  
  1836.     api_open();
  1837.     if ( strlen( keybuffer ) <= api_keystatus())
  1838.         api_qkeys( keybuffer );
  1839.     else
  1840.         printf("No room in Reflection Key Queue.\n");
  1841.     while(!api_block())
  1842.         if (kbhit())
  1843.             break;
  1844.     /* don't call api_close     since it will clear the queue */
  1845. }
  1846.  
  1847. BASIC Function Definition
  1848. -------------------------
  1849.  
  1850. DECLARE FUNCTION api.qkeys% CDECL (SEG keys$)
  1851. key$ = string containing keystrokes to queue
  1852.  
  1853. BASIC example    - queue keys to log on to an HP3000
  1854. -------------
  1855. ' $INCLUDE: 'api.inc'
  1856. i% = api.qkeys( "'hello user.acct' return")
  1857.  
  1858. TURBO Function Definition
  1859. -------------------------
  1860.  
  1861. function api_QKeys( var keys: string ) :integer;
  1862.  
  1863. keys = string containing keystrokes
  1864.  
  1865. TURBO Pascal example
  1866. --------------------
  1867. {$V-}
  1868. uses    apiunit;
  1869. var    keys    : string[80];
  1870.     i    : integer;
  1871. begin
  1872.     keys := '"hello user.acct" return';
  1873.     i := api_qkeys( keys );
  1874. end.
  1875.  
  1876. -----------------------------------------------------------------------------
  1877.     api_clrkeybd           14
  1878. -----------------------------------------------------------------------------
  1879.     Purpose: Clear any remaining unprocessed keys out of the keyboard
  1880.          buffer.
  1881.  
  1882.  
  1883.     INPUT:    CX = 14
  1884.         AX = DE52H
  1885.         DX = 0
  1886.  
  1887.     OUTPUT:
  1888.        No error:
  1889.         AX =  0
  1890.  
  1891.        Error:
  1892.         AX = error code
  1893.  
  1894.        Should not return an error.
  1895.  
  1896. Assembler Example:
  1897. ------------------
  1898.     mov    ax,0DE52H
  1899.     xor    dx,dx
  1900.     mov    cx,14
  1901.     int    21h
  1902.  
  1903.  
  1904. C Function Definition:
  1905. ----------------------
  1906.  
  1907. int    api_clrkeybd ();
  1908.  
  1909.  
  1910. C Programming Example:
  1911. ----------------------
  1912.  
  1913. api_clrkeybd ();
  1914.  
  1915. BASIC Function Definition
  1916. -------------------------
  1917.  
  1918. DECLARE FUNCTION api.clrkeybd% CDECL ()
  1919.  
  1920. BASIC example    - clear the keyboard buffer
  1921. -------------
  1922. ' $INCLUDE: 'API.INC'
  1923. i% = api.clrkeybd
  1924.  
  1925.  
  1926. TURBO Function Definition
  1927. -------------------------
  1928.  
  1929. function api_ClrKeybd :integer;
  1930.  
  1931. TURBO Pascal example
  1932. --------------------
  1933. uses    apiunit;
  1934. var    i : integer;
  1935. begin
  1936.     i := api_clrkeybd
  1937. end.
  1938.  
  1939. -----------------------------------------------------------------------------
  1940.     api_cmdstatus        15
  1941. -----------------------------------------------------------------------------
  1942.     Purpose: Returns amount of free space available in command queue
  1943.          buffer.
  1944.  
  1945.     INPUT:    CX = 15
  1946.         AX = DE52H
  1947.         DX = 0
  1948.  
  1949.     OUTPUT:
  1950.         AX = amount of free space  in bytes
  1951.  
  1952. Assembler Example:
  1953. ------------------
  1954.     mov    ax,0DE52H
  1955.     xor    dx,dx
  1956.     mov    cx,15
  1957.     int    21h
  1958.     or    ax,ax
  1959.     jz    No_free_space
  1960.  
  1961. C Function Definition:
  1962. ----------------------
  1963.  
  1964. int    api_cmdstatus();    returns free space in command queue
  1965.  
  1966.  
  1967.  
  1968.  
  1969. C Programming Example:
  1970. ----------------------
  1971.  
  1972. main()
  1973. {
  1974.     /* Queue a command if there is room in the buffer */
  1975.  
  1976.     char    *send_command = "SEND ABC TO XYZ ASCII DELETE";
  1977.     api_open();
  1978.     if (api_cmdstatus() >= strlen( send_command ) ) {
  1979.         api_qcmd( send_command );
  1980.         printf("Command Queued\n");
  1981.     }
  1982.     else
  1983.         printf("Queue full\n");
  1984.     /* no api_close     here - allow command to be processed */
  1985. }
  1986.  
  1987. BASIC Function Definition
  1988. -------------------------
  1989.  
  1990. DECLARE FUNCTION api.cmdstatus% CDECL ()
  1991.  
  1992. BASIC example    - Queue a command if there is room in the buffer
  1993. -------------
  1994.  
  1995. ' $INCLUDE: 'api.inc'
  1996.  
  1997.     cm$= "SEND ABC TO XYZ ASCII DELETE";
  1998.     i%=api.open
  1999.     if (api.cmdstatus > len(cm$)) then     ' if there is room then
  2000.         api.qcmd( cm$ )            ' queue the command
  2001.         print "Command Queued"
  2002.     else
  2003.         print "Queue full"
  2004.     end if
  2005.  
  2006. TURBO Function Definition
  2007. -------------------------
  2008.  
  2009. function api_CmdStatus :integer;
  2010.  
  2011. TURBO Pascal example
  2012. --------------------
  2013. uses    apiunit;
  2014. var    i : integer;
  2015. begin
  2016.     i := api_cmdstatus;
  2017.     writeln ( 'bytes free in command buffer = ', i );
  2018. end.
  2019.  
  2020. -----------------------------------------------------------------------------
  2021.     api_qcmd        16
  2022. -----------------------------------------------------------------------------
  2023.     Purpose: Queue a new command in the command queue.  This call
  2024.          returns immediately to the caller and the command is
  2025.          processed asynchronously via background multitasking.
  2026.  
  2027.     INPUT:    CX = 16
  2028.         AX = DE52H
  2029.         DX = 0
  2030.         ES:BX point to null-terminated command
  2031.  
  2032.     OUTPUT:
  2033.        No error:
  2034.         AX =  0
  2035.  
  2036.        Error:
  2037.         AX = 104H Queue full
  2038.            = 106H Bad Length
  2039.  
  2040. Assembler Example:
  2041. ------------------
  2042.     mov    ax,0DE52H
  2043.     xor    dx,dx
  2044.     mov    cx,16
  2045.     push    ds
  2046.     pop    es
  2047.     ASSUME    ES:DATA
  2048.     mov    bx,offset command_string
  2049.     int    21h
  2050.     or    ax,ax
  2051.     jnz    Command_Queue_error
  2052.  
  2053.  
  2054. Command_string    db    "Send ABC to XYZ ASCII DELETE",0
  2055.  
  2056.  
  2057. C Function Definition:
  2058. ----------------------
  2059.  
  2060. int    api_qcmd( command_string );        returns error-code
  2061. char    *command_string;
  2062.  
  2063.  
  2064. C Programming Example:
  2065. ----------------------
  2066. See api_cmdstatus example
  2067.  
  2068.  
  2069. BASIC Function Definition
  2070. -------------------------
  2071.  
  2072. DECLARE FUNCTION api.qcmd% CDECL (SEG rcommand$)
  2073.  
  2074. BASIC example    -  Queue a command - report if there was an error
  2075. -------------
  2076.  
  2077. ' $INCLUDE: 'API.INC'
  2078.  
  2079. cm$ = "SEND ABC TO DEF ASCII REC = 256"
  2080. if api.qcmd( cm$ ) then print "Error queuing command"
  2081.  
  2082. TURBO Function Definition
  2083. -------------------------
  2084.  
  2085. function api_QCmd( var cmd : string ) :integer;
  2086. cmd = string containing command
  2087.  
  2088. TURBO Pascal example    -  Queue a command - report if there was an error
  2089. --------------------
  2090. uses    apiunit;
  2091. var    cm : string[80];
  2092.     i  : integer;
  2093. begin
  2094.     cm := 'SEND ABC TO DEF ASCII REC = 256';
  2095.     if api_qcmd( cm ) <> 0 then
  2096.         writeln( 'error occurred while queuing command');
  2097. end.
  2098.  
  2099. -----------------------------------------------------------------------------
  2100.     api_clrcmdq          17
  2101. -----------------------------------------------------------------------------
  2102.     Purpose: Clear the command queue
  2103.  
  2104.     INPUT:    CX = 17
  2105.         AX = DE52H
  2106.         DX = 0
  2107.  
  2108.     OUTPUT:
  2109.        AX = 0
  2110.        Should not encounter an error
  2111.  
  2112.  
  2113. Assembler Example:
  2114. ------------------
  2115.     mov    ax,0DE52H
  2116.     xor    dx,dx
  2117.     mov    cx,17
  2118.     int    21h
  2119.  
  2120. C Function Definition:
  2121. ----------------------
  2122.  
  2123. int api_clrcmdq();
  2124.  
  2125.  
  2126. C Programming Example:
  2127. ----------------------
  2128.  
  2129.     api_clrcmdq();
  2130.  
  2131. BASIC Function Definition
  2132. -------------------------
  2133.  
  2134. DECLARE FUNCTION api.clrcmdq% CDECL ()
  2135.  
  2136. BASIC example    - clear the command queue
  2137. -------------
  2138. ' $INCLUDE: 'API.INC'
  2139.  
  2140. i% = api.clrcmdq
  2141.  
  2142. TURBO Function Definition
  2143. -------------------------
  2144.  
  2145. function api_ClrCmdQ :integer;
  2146.  
  2147. TURBO Pascal example    - clear the command queue
  2148. --------------------
  2149. uses    apiunit;
  2150. var    i : integer;
  2151. begin
  2152.     i := api_clrcmdq;
  2153. end.
  2154.  
  2155. -----------------------------------------------------------------------------
  2156.     api_releasedc        18
  2157. -----------------------------------------------------------------------------
  2158.     Purpose: Stop stealing datacomm hardware away from foreground
  2159.          process. Normally if Reflection is running a command
  2160.          file or processing a command, it will steal the
  2161.          datacomm hardware (COM1, COM2, etc.) away from a
  2162.          foreground process that may have grabbed it.
  2163.          This call allows a foreground task to initialize
  2164.          the datacomm hardware and do direct datacomm I/O
  2165.          without interference from Reflection in background.
  2166.          Reflection will not be able to do datacomm.
  2167.  
  2168.        This call will not restore datacomm to the foreground program
  2169.        if it has already been taken away.  The foreground program will
  2170.        have to re-initialize the datacomm hardware.  ReleaseDC should
  2171.        only be required when the hardware serial ports are being used
  2172.        by both Reflection and a foreground program.
  2173.  
  2174.     INPUT:    CX = 18
  2175.         AX = DE52H
  2176.         DX = 0
  2177.  
  2178.     OUTPUT:
  2179.         Should not return an error
  2180.  
  2181.  
  2182.  
  2183. Assembler Example:
  2184. ------------------
  2185.     mov    ax,0DE52H
  2186.     xor    dx,dx
  2187.     mov    cx,18
  2188.     int    21h
  2189.  
  2190. C Function Definition:
  2191. ----------------------
  2192. int    api_releasedc();
  2193.  
  2194.  
  2195. C Programming Example:
  2196. ----------------------
  2197.  
  2198.     api_releasedc();
  2199.  
  2200. BASIC Function Definition
  2201. -------------------------
  2202.  
  2203. DECLARE FUNCTION api.releasedc% CDECL ()
  2204.  
  2205. BASIC example    - release datacomm
  2206. -------------
  2207. ' $INCLUDE: 'API.INC'
  2208. i% = api.releasedc
  2209.  
  2210. TURBO Function Definition
  2211. -------------------------
  2212.  
  2213. function api_ReleaseDC :integer;
  2214.  
  2215. TURBO Pascal example
  2216. --------------------
  2217. ....
  2218. i := api_releasedc
  2219. ....
  2220.  
  2221. -----------------------------------------------------------------------------
  2222.     api_assertdc        19
  2223. -----------------------------------------------------------------------------
  2224.     Purpose: Tells Reflection to re-grab the serial hardware
  2225.          away from a foreground task that may have taken it.
  2226.          Reflection re-initializes datacomm back to its
  2227.          normal baud rate, parity, etc.   Reflection will
  2228.          continually re-grab the hardware from another program
  2229.          if necessary.
  2230.  
  2231.     INPUT:    CX = 19
  2232.         AX = DE52H
  2233.         DX = 0
  2234.  
  2235.     OUTPUT:
  2236.        Should not return an error.
  2237.  
  2238.  
  2239. Assembler Example:
  2240. ------------------
  2241.     mov    ax,0DE52H
  2242.     xor    dx,dx
  2243.     mov    cx,19
  2244.     int    21h
  2245.  
  2246. BASIC, C, Pascal examples
  2247. ----------------------
  2248.  
  2249. Note:    See ReleaseDC()
  2250.  
  2251.  
  2252. -----------------------------------------------------------------------------
  2253.     api_popup        20
  2254. -----------------------------------------------------------------------------
  2255.     Purpose: Pop Reflection into the foreground.  API client
  2256.          application will be frozen until user hits hot-key
  2257.          or a queued "BACKGROUND" command is processed.
  2258.  
  2259.     INPUT:    CX = 20
  2260.         AX = DE52H
  2261.         DX = 0
  2262.  
  2263.  
  2264.     OUTPUT:
  2265.        Should not return an error
  2266.  
  2267. Assembler Example:
  2268. ------------------
  2269.     mov    ax,0DE52H
  2270.     xor    dx,dx
  2271.     mov    cx,20
  2272.     int    21h    ; This call freezes API Client program
  2273.  
  2274. C Function Definition:
  2275. ----------------------
  2276. int    api_popup();
  2277.  
  2278.  
  2279.  
  2280. C Programming Example:
  2281. ----------------------
  2282.  
  2283.     api_popup();
  2284.     printf("Back from POP COMMAND\n");
  2285.  
  2286. BASIC Function Definition
  2287. -------------------------
  2288.  
  2289. DECLARE FUNCTION api.popup% CDECL ()
  2290.  
  2291. BASIC example    - pop up Reflection
  2292. -------------
  2293. ' $INCLUDE: 'API.INC'
  2294. i% = api.popup
  2295. print "BACK from Reflection"
  2296.  
  2297. TURBO Function Definition
  2298. -------------------------
  2299.  
  2300. function api_PopUP :integer;
  2301.  
  2302. TURBO Pascal example    - pop up Reflection;
  2303. --------------------
  2304. uses    apiunit;
  2305. var    i : integer;
  2306. begin
  2307.     i := api_popup;
  2308. end.
  2309. -----------------------------------------------------------------------------
  2310.     api_reset        21
  2311. -----------------------------------------------------------------------------
  2312.     Purpose: Sends Reflection a hard reset.  Check the technical
  2313.          reference manual for the description of the hard
  2314.          reset process.  In addition, api_reset performs
  2315.          api_flushcmd(), api_clrkeybd (), and api_endcommands().
  2316.          To prevent the host from performing a hard-reset,
  2317.          issue the command "SET EXITS-DISABLED YES"
  2318.  
  2319.     INPUT:    CX = 21
  2320.         AX = DE52H
  2321.         DX = 0
  2322.  
  2323.     OUTPUT:
  2324.        Should not return an error
  2325.  
  2326. Assembler Example:
  2327. ------------------
  2328.     mov    ax,0DE52H
  2329.     xor    dx,dx
  2330.     mov    cx,21
  2331.     int    21h
  2332.  
  2333.  
  2334. C Function Definition:
  2335. ----------------------
  2336.  
  2337. int    api_reset();
  2338.  
  2339. C Programming Example:
  2340. ----------------------
  2341.  
  2342.     api_reset();
  2343.  
  2344. BASIC Function Definition
  2345. -------------------------
  2346.  
  2347. DECLARE FUNCTION api.reset% CDECL ()
  2348.  
  2349. BASIC example    - Hard reset Reflection
  2350. -------------
  2351. ' $INCLUDE: 'API.INC'
  2352.  
  2353. i% = api.reset
  2354.  
  2355. TURBO Function Definition
  2356. -------------------------
  2357.  
  2358. function api_Reset :integer;
  2359.  
  2360. TURBO Pascal example    - Hard reset Reflection
  2361. --------------------
  2362. uses    apiunit;
  2363. var    i : integer;
  2364. begin
  2365.     i := api_reset;
  2366. end.
  2367.  
  2368. -----------------------------------------------------------------------------
  2369.     api_getfkey        22
  2370. -----------------------------------------------------------------------------
  2371.     Purpose: Return the current setting of a Reflection softkey
  2372.          to calling program.   This function returns value of
  2373.          R2 and R4 softkeys,  R2 and R4 user-defined keys (UDKs)
  2374.          and R1 and R7 HP userkeys.
  2375.  
  2376.     INPUT:    CX = 22
  2377.         AX = DE52H
  2378.         DX = 0
  2379.         ES:BX point to buffer to return key.
  2380.         SI = Key number (1 relative)
  2381.              To return R2/R4 user-defined keys    (UDKs)
  2382.             UDK # 6  = keynumber 17
  2383.             ...       ...
  2384.             UDK # 20 = keynumber 34
  2385.  
  2386.     OUTPUT:
  2387.        No error
  2388.        AX = 0
  2389.         key record copied to buffer
  2390.  
  2391.        Error:
  2392.         AX = 105H Badkey
  2393.  
  2394.  
  2395. HP Userkey label structure    R1/R7
  2396.  
  2397. struct    ukey    {
  2398.     char    unsigned   ukey_attr;   /* 0=normal, 1=local only, 2=transmit only*/
  2399.     char    unsigned   ukey_lablen; /* length of the label  */
  2400.     char    unsigned   ukey_deflen; /* length of the definition string */
  2401.     int            ukey_reserved;
  2402.     char        ukey_text[160]; /*label string followed by definition*/
  2403. }
  2404.  
  2405. DEC Softkey structure      R2/R4
  2406.  
  2407. struct softkey    {
  2408.     char    unsigned   action;    /* 0 = normal, 1 = local only */
  2409.     char    unsigned   label_length;
  2410.     char    label_text[8];
  2411.     char    unsigned   defn_length;
  2412.     char    defn_text[80];
  2413. }
  2414.  
  2415.  
  2416. DEC UDK structure   R2 / R4
  2417.  
  2418. struct udk {
  2419.     char    unsigned    udk_length;
  2420.     char            udk_text[255];
  2421. }
  2422.  
  2423. Assembler Example:            ; Get HP softkey # 3
  2424. ------------------
  2425.     mov    ax,0DE52H
  2426.     xor    dx,dx
  2427.     push    ds
  2428.     pop    es
  2429.     mov    si,3            ; User key # 3
  2430.     assume    es:data
  2431.     mov    bx,offset ukey_buffer    ; where to put the ukey info
  2432.     mov    cx,22            ; get user key
  2433.     int    21h
  2434.     or    ax,ax            ; Error?
  2435.     jnz    getkey_error        ;  YES
  2436.  
  2437.  
  2438. key_buffer label byte
  2439. ukey_attr    db    ?    ; 0 = normal, 1 = local, 2 = transmit only
  2440. ukey_lablen    db    ?    ; length of label text
  2441. ukey_deflen    db    ?    ; length of definition string
  2442. reserved    dw    ?
  2443. ukey_text    db    160 dup (0)    ; label text and definition start
  2444.  
  2445.  
  2446.  
  2447. C Function Definition:
  2448. ----------------------
  2449. int    api_getfkey( key_buffer, keynumber );
  2450. struct    ukey   *key_buffer;
  2451. int    keynumber;
  2452.  
  2453. C Programming Example:
  2454. ----------------------
  2455. main()
  2456.  
  2457.     /* Retrieve a function key and print the label */
  2458.  
  2459.  
  2460. {
  2461. struct    ukey   key_buffer;
  2462.  
  2463. int    i;
  2464. int    keynumber=3;
  2465. struct    ukey  *kptr;
  2466.     kptr = &key_buffer;
  2467.     api_open();
  2468.     api_getfkey( kptr, keynumber );
  2469.     i = kptr->ukey_lablen;
  2470.     kptr->ukey_text[i]='\0';    /* null-terminate after label */
  2471.     printf("key %d label '%s'\n", keynumber, kptr->ukey_text );
  2472.     api_close();
  2473. }
  2474.  
  2475. BASIC Function Definition
  2476. -------------------------
  2477.  
  2478. DECLARE FUNCTION api.getfkey% CDECL (SEG keybuff AS ukeytype, BYVAL keyno%)
  2479.  
  2480. BASIC example    - Print the definition part of HP function key #3
  2481. -------------
  2482.  
  2483. ' $INCLUDE: 'api.inc'
  2484.  
  2485. COMMON x AS ukeytype
  2486.     i% = api.getfkey(x, 3)
  2487.     y$ = x.ukeytext
  2488.     PRINT MID$(y$, ASC(x.ukeylablen) + 1)
  2489.     END
  2490.  
  2491. TURBO Function Definition
  2492. -------------------------
  2493.  
  2494. function api_GetFkey( k : integer; var fkey: ukeytype ) :integer;
  2495.  
  2496. k = function key number
  2497. fkey = user key record - see apiunit.pas for declaration
  2498.  
  2499. TURBO Pascal example - Print the definition part of HP function key #3
  2500. --------------------
  2501. uses    apiunit;
  2502. var    x : ukeytype;            (* function key record *)
  2503.     i : integer;
  2504.     n : integer;            (* label length *)
  2505.     keydefn  : string[80];
  2506. begin
  2507.     i := api_getfkey( 3, x );
  2508.     n := ord( x.ukeylablen );
  2509.     i := 0;
  2510.     keydefn[0] := x.ukeydeflen;    (* definition length *)
  2511.     while i < ord( x.ukeydeflen ) do
  2512.         begin
  2513.          keydefn[i+1] := x.ukeytext[n + i ];
  2514.          i := i + 1;
  2515.         end;
  2516.     writeln ( 'definition of function key 3 = ',keydefn );
  2517. end.
  2518.  
  2519.  
  2520.  
  2521.  
  2522. -----------------------------------------------------------------------------
  2523.     api_setfkey        23
  2524. -----------------------------------------------------------------------------
  2525.     Purpose: Directly set an R1/R7 HP userkey or an R2/R4 softkey.
  2526.          DEC UDK's may only be set via the display command
  2527.          displaying the appropriate escape sequence.
  2528.  
  2529.     INPUT:    CX = 23
  2530.         AX = DE52H
  2531.         DX = 0
  2532.         ES:BX point to    ukey/softkey structure
  2533.         SI = key number
  2534.  
  2535.     OUTPUT:
  2536.        No error:
  2537.         AX =  0
  2538.        Error:
  2539.         AX = 105H bad key
  2540.  
  2541.  
  2542. Assembler Example:
  2543. ------------------
  2544.     mov    ax,0DE52H
  2545.     xor    dx,dx
  2546.     push    ds
  2547.     pop    es
  2548.     assume    es:data
  2549.     mov    bx,offset key_structure
  2550.     mov    si,3            ; set user key 3
  2551.     mov    cx,23
  2552.     int    21h
  2553.     or    ax,ax
  2554.     jnz    key_error
  2555.  
  2556.  
  2557. key_structure label byte
  2558. ukey_attr    db    0    ; normal (as if typed at keyboard)
  2559. ukey_lablen    db    16    ; length of label text    (2 rows )
  2560. ukey_deflen    db    23    ; length of definition string
  2561. reserved    dw    ?
  2562. ukey_text    db    '  LOGON ','   HP   ','HELLO George,mgr.sales',0dh
  2563.  
  2564.  
  2565.  
  2566. C Function Definition:
  2567. ----------------------
  2568. int api_setfkey( key_buffer, keynumber);
  2569. struct    ukey   *key_buffer;
  2570. int    keynumber;
  2571.  
  2572.  
  2573. C Programming Example:
  2574. ----------------------
  2575. main()
  2576. {
  2577.  
  2578.     /* change function key 3 to LOCAL */
  2579.  
  2580.     int    keynumber = 3;
  2581.     struct    ukey  key_buffer;
  2582.     struct    ukey  *sptr;
  2583.     sptr = &key_buffer;
  2584.     api_open();
  2585.     api_getfkey( sptr, keynumber );
  2586.     sptr->ukey_attr = 1;          /* 1 = local */
  2587.     api_setfkey( sptr, keynumber );
  2588.     printf("Userkey 3 set to LOCAL  [L]  \n");
  2589.     api_close();
  2590. }
  2591.  
  2592. BASIC Function Definition
  2593. -------------------------
  2594.  
  2595. see api_getfkey
  2596.  
  2597. BASIC example
  2598. -------------
  2599.  
  2600. see api_getfkey
  2601.  
  2602. TURBO Function Definition
  2603. -------------------------
  2604.  
  2605. see api_getfkey
  2606.  
  2607. TURBO Pascal example
  2608. --------------------
  2609.  
  2610. see api_getfkey
  2611.  
  2612. -----------------------------------------------------------------------------
  2613.     api_offerbuf         24
  2614. -----------------------------------------------------------------------------
  2615.     Purpose: To provide larger buffers for command or keyboard queues
  2616.          than the default API buffers.    Default buffer size is
  2617.          approximately 190 bytes for the command buffer and 32 keys
  2618.          for the keyboard buffer.
  2619.  
  2620.     Make sure that the current queue is empty before offering
  2621.     a new buffer, otherwise any queued keys or commands will be lost.
  2622.     Each offer cancels the previous one.  Do not modify the offered
  2623.     buffer space until it has been canceled (see below).  Note that the
  2624.     pointer passed to API is a far pointer (32 bit address)!
  2625.  
  2626.     INPUT:    CX = 24
  2627.         AX = DE52H
  2628.         DX = 0
  2629.         ES:BX points to buffer
  2630.         SI    size of buffer
  2631.         DI    buffer type
  2632.             0 = keyboard buffer
  2633.             1 = command queue buffer
  2634.  
  2635.     OUTPUT:
  2636.        No error:
  2637.         AX =  0
  2638.  
  2639.        Error:
  2640.         AX = 103H  Bad buffer type
  2641.  
  2642. Assembler Example:
  2643. ------------------
  2644.     mov    ax,0DE52H
  2645.     xor    dx,dx
  2646.     push    ds
  2647.     pop    es
  2648.     ASSUME    ES:DATA
  2649.     mov    bx,offset command_buffer
  2650.     mov    di,1            ; 1 <==> buffer for command queue
  2651.     mov    si,CBUFFER_LEN        ; length of buffer
  2652.     mov    cx,24
  2653.     int    21h
  2654.  
  2655. command_buffer    db    2000 dup (0)
  2656. CBUFFER_LEN    EQU    $ - command_buffer
  2657.  
  2658.  
  2659.  
  2660. C Function Definition:
  2661. ----------------------
  2662.  
  2663. int api_offerbuf( command_queue, bufsize, type );
  2664. char far *command_queue;
  2665. int    bufsize;
  2666. int    type;
  2667.  
  2668.  
  2669. C Programming Example:            Offer a 2000 byte command buffer
  2670. ----------------------
  2671.  
  2672. #define BUFSIZE  2000
  2673. #define COMMAND_TYPE    1
  2674. char far command_queue[BUFSIZE];
  2675.  
  2676. api_offerbuf(command_queue, BUFSIZE, COMMAND_TYPE );
  2677.  
  2678.  
  2679. BASIC Function Definition
  2680. -------------------------
  2681.  
  2682. DECLARE FUNCTION api.offerbuf% CDECL (SEG buffer AS bufftype, BYVAL rvarlen%,
  2683.          BYVAL typ%)
  2684.  
  2685. buffer = buffer to be used for queuing keys or commands - see api.inc for
  2686.      user-defined type definition.
  2687. rvarlen% = size of buffer
  2688.  
  2689. BASIC example    - Setup 512 byte command buffer within BASIC's data
  2690. -------------      segment and queue some commands.
  2691.  
  2692. ' $include: 'api.inc'
  2693.  
  2694. COMMON cmdbuf as bufftype    ' see api.inc for bufftype declaration
  2695. i% = api.offerbuf( cmdbuf, 512, 1% )
  2696. i% = api.qcmd("dir *.*")
  2697. i% = api.qcmd("display '^g'")
  2698. i% = api.qcmd("wait 0:0:10")
  2699. i% = api.wait
  2700. i% = api.cancelbuf
  2701. end
  2702.  
  2703. TURBO Function Definition
  2704. -------------------------
  2705.  
  2706. function api_OfferBuf(typ,buflen:integer;var x : buffer):integer;
  2707. type = 0 or 1    for keys or commands
  2708. buflen = size of buffer
  2709. x = buffer see apiunit.pas for declaration
  2710.  
  2711. TURBO Pascal example    - Offer a Keyboard Queue buffer from Pascal's
  2712. --------------------      data space.
  2713. {$V-}
  2714. uses  apiunit, crt;
  2715. const     maxlength = 256;
  2716. var    keys  : string[250];
  2717.     i     : integer;
  2718.     keybuf     : buffer;
  2719. begin
  2720.      i := api_offerbuf( 0, 256, keybuf );
  2721.      keys := '"enter these keys and hit return" return ';
  2722.      i := api_qkeys( keys );
  2723.      repeat
  2724.      until keypressed or (api_block = 0);
  2725.      i := api_cancelbuf;    (* cancel buffer before terminating program *)
  2726. end.
  2727.  
  2728. -----------------------------------------------------------------------------
  2729.     api_cancelbufs        25
  2730. -----------------------------------------------------------------------------
  2731.     Purpose: Reflection will return to use of default keyboard
  2732.          and command buffers.  Original buffer is
  2733.          reclaimed by API client program.  Issue this
  2734.          call prior to terminating.
  2735.  
  2736.     INPUT:    CX = 25
  2737.         AX = DE52H
  2738.         DX = 0
  2739.  
  2740.     OUTPUT:
  2741.        Should not return an error
  2742.  
  2743.  
  2744. Assembler Example:
  2745. ------------------
  2746.  
  2747.     mov    ax,0DE52H
  2748.     xor    dx,dx
  2749.     mov    cx,25
  2750.     int    21h
  2751.  
  2752.  
  2753.  
  2754. C Function Definition:
  2755. ----------------------
  2756.  
  2757. int    api_cancelbuf();
  2758.  
  2759. C Programming Example:
  2760. ----------------------
  2761.  
  2762. api_cancelbuf();
  2763.  
  2764. BASIC Function Definition
  2765. -------------------------
  2766.  
  2767. DECLARE FUNCTION api.cancelbuf% CDECL ()
  2768.  
  2769. BASIC example
  2770. -------------
  2771.  
  2772. see api.offerbuf
  2773.  
  2774. TURBO Function Definition
  2775. -------------------------
  2776.  
  2777. function api_CancelBuf :integer;
  2778.  
  2779. TURBO Pascal example
  2780. --------------------
  2781.  
  2782. see api_offerbuf
  2783.  
  2784. -----------------------------------------------------------------------------
  2785.     api_wait        26
  2786. -----------------------------------------------------------------------------
  2787.     Purpose: Wait for Reflection to empty command and/or keyboard
  2788.          queues.  Does not return until Reflection is idle.
  2789.          When a series of commands are queued, but the API
  2790.          client program can not continue until the commands
  2791.          have been completed, this call could be used.
  2792.          Handle with care.  Keyboard lock could cause system
  2793.          hang.
  2794.  
  2795.     INPUT:    CX = 26
  2796.         AX = DE52H
  2797.         DX = 0
  2798.  
  2799.     OUTPUT:
  2800.        Should not return an error.
  2801.  
  2802.  
  2803. Assembler Example:
  2804. ------------------
  2805.  
  2806.     mov    ax,0DE52H
  2807.     xor    dx,dx
  2808.     mov    cx,26
  2809.     int    21h
  2810.  
  2811.  
  2812. C Function Definition:
  2813. ----------------------
  2814.  
  2815. int    api_wait();
  2816.  
  2817. C Programming Example:
  2818. ----------------------
  2819.  
  2820. main()
  2821. {
  2822.  
  2823.     /* Queue commands and WAIT till complete */
  2824.  
  2825.     api_open();
  2826.     api_qcmd("wait 0:0:5");
  2827.     api_qcmd("display '^g'");
  2828.     api_wait();
  2829.     api_close();
  2830. }
  2831.  
  2832. BASIC Function Definition
  2833. -------------------------
  2834.  
  2835. DECLARE FUNCTION api.wait% CDECL ()
  2836.  
  2837. BASIC example    -  Queue commands and WAIT until complete
  2838. -------------
  2839.  
  2840. ' $INCLUDE: 'api.inc'
  2841. i% = api.qcmd("WAIT 0:0:5")
  2842. i% = api.qcmd("display '^g'")
  2843. i% = api.wait
  2844.  
  2845. TURBO Function Definition
  2846. -------------------------
  2847.  
  2848. function api_Wait :integer;
  2849.  
  2850. TURBO Pascal example
  2851. --------------------
  2852. uses apiunit;
  2853. var i : integer;
  2854. var cm : string[80];
  2855. begin
  2856.     cm := 'SEND ABC TO XYZ';
  2857.     i  := api_qcmd( cm );
  2858.     i  := api_wait        (* wait until command completed       *)
  2859. end.                (* note: may cause program to hang if *)
  2860.                 (* command can't complete             *)
  2861.  
  2862. -----------------------------------------------------------------------------
  2863.     api_block        27
  2864. -----------------------------------------------------------------------------
  2865.     Purpose: Give Reflection some CPU time.  This should be
  2866.          done if the API client program is waiting for
  2867.          Reflection to complete some queued commands or
  2868.          keystrokes but wants to maintain CPU control
  2869.          (api_block returns quickly).
  2870.  
  2871.     INPUT:    CX = 27
  2872.         AX = DE52H
  2873.         DX = 0
  2874.  
  2875.     OUTPUT:
  2876.        AX  = 0   implies Reflection idle.  Command or key
  2877.              queues have been completed.
  2878.  
  2879.        AX <> 0   implies Reflection is busy processing
  2880.              commands or queued keys.
  2881.  
  2882.  
  2883. Assembler Example:            Give Reflection CPU time while
  2884. ------------------            waiting for user input.
  2885.  
  2886.  
  2887. Idle_Loop:
  2888.     mov    ah,1            ; Check keyboard status
  2889.     int    16h            ; BIOS keyboard interrupt
  2890.     jnz    Key_waiting        ; Exit if user has typed key
  2891.     mov    ax,0DE52H
  2892.     xor    dx,dx
  2893.     mov    cx,27            ; Do api_block
  2894.     int    21h
  2895.     or    ax,ax            ; Is Reflection finished?
  2896.     jnz    idle_loop        ; No.  See if keyboard input
  2897.  
  2898.  
  2899.  
  2900. C Function Definition:
  2901. ----------------------
  2902. int    api_block();
  2903.  
  2904.  
  2905. C Programming Example:
  2906. ----------------------
  2907. main()
  2908. {
  2909.     /* queue two commands and block until complete */
  2910.  
  2911.     api_open();
  2912.     api_qcmd("wait 0:0:3");
  2913.     api_qcmd("display '^g'");
  2914.     while (api_block())
  2915.         if (kbhit())    /* If key has been pressed */
  2916.             break;    /* stop waiting */
  2917.     api_close();
  2918. }
  2919.  
  2920.  
  2921. BASIC Function Definition
  2922. -------------------------
  2923.  
  2924. DECLARE FUNCTION api.block% CDECL ()
  2925.  
  2926. BASIC example    - Give Reflection CPU time until file transfer completes
  2927. -------------      or user hits a key.
  2928.  
  2929. ' $INCLUDE: 'api.inc'
  2930. i% = api.qcmd("send bigfile to xyz")
  2931. DO
  2932. LOOP WHILE  inkey$="" and api.block <> 0
  2933.  
  2934. TURBO Function Definition
  2935. -------------------------
  2936.  
  2937. function api_Block :integer;
  2938.  
  2939. TURBO Pascal example
  2940. --------------------
  2941.  
  2942. see    api_offerbuf example
  2943.  
  2944. -----------------------------------------------------------------------------
  2945.     api_atrbscreen          31
  2946. -----------------------------------------------------------------------------
  2947.     Purpose: Read text and color attributes from Reflection's
  2948.          background screen. Read can extend to function key display.
  2949.          Color attributes are IBM PC attribute bytes.  Client
  2950.          program may read Reflection screen and re-display with
  2951.          same color attributes.
  2952.  
  2953.     INPUT:    CX = 31
  2954.         AX = DE52H
  2955.         DX = 0
  2956.         BH = ROW    0 relative
  2957.         BL = COL    0 relative
  2958.         ES:DI        points to buffer to contain screen text
  2959.         SI = number of characters to read.  Note that each
  2960.              character is 2 bytes with this function.  For each
  2961.              character, the first byte is the character from
  2962.              the IBM character set and the second byte is
  2963.              the attribute which determines how the byte is
  2964.              displayed.
  2965.  
  2966.     OUTPUT:
  2967.        No error:
  2968.         AX =  0
  2969.  
  2970.        Error:
  2971.         AX = 103H  read extends off of screen
  2972.  
  2973.  
  2974. Assembler Example:
  2975. ------------------
  2976.     See example for api_screenread
  2977.  
  2978. C Function Definition:
  2979. ----------------------
  2980.     See api_screenread
  2981.  
  2982. C Programming Example:
  2983. ----------------------
  2984.     See example for api_screenread
  2985.  
  2986.  
  2987. BASIC Function Definition
  2988. -------------------------
  2989.     See api_screenread
  2990.  
  2991.  
  2992. BASIC example    - Read the Reflection screen and print characters with correct
  2993. -------------      color attributes.
  2994.  
  2995. ' $INCLUDE: 'api.inc'
  2996. ' Allocate space for reading 80 columns by 25 rows by two bytes per char.
  2997. x$ = SPACE$(80 * 25 * 2)
  2998. '
  2999. ' Ask for 80*25 characters starting at row 0, column 0
  3000. '
  3001. i% = api.atrbscreen%(x$, 0, 0, 80 * 25)
  3002. '
  3003. ' Make default segment the segment of the video display (use B000 for mono)
  3004. '
  3005. DEF SEG = &HB800
  3006. FOR i = 1 TO 80 * 25 * 2
  3007. POKE i-1, ASC(MID$(x$, i, 1))
  3008. NEXT i
  3009. END
  3010.  
  3011.  
  3012. TURBO Function Definition
  3013. -------------------------
  3014.  
  3015. function api_AtrbScreen(length,col,row:integer;var x:buffer):integer;
  3016.  
  3017. see api_screenread above
  3018.  
  3019. TURBO Pascal example   - Read 100 characters off of screen and put ascii
  3020. --------------------     bytes only into string variable.  Read starting
  3021.              row 10 column 1.
  3022.  
  3023. program ReadScrnAttr (input,output);
  3024. {$V-}
  3025. uses  apiunit;
  3026. var
  3027.     scrn    : buffer;
  3028.     row    : integer;
  3029.     col    : integer;
  3030.     i     : integer;
  3031.     scrtext  : string[100];
  3032. begin
  3033.      row := 10;
  3034.      col := 1;
  3035.      i     := api_atrbscreen (100, col, row, scrn );
  3036.      i     := 0;
  3037.      while i < 100 do
  3038.          begin
  3039.           scrtext[i+1] := scrn[ i*2 ];
  3040.           i := i+1;
  3041.          end;
  3042.      scrtext[0] := chr(100);
  3043.      writeln( scrtext );
  3044. end.
  3045.  
  3046.  
  3047.  
  3048.  
  3049. -----------------------------------------------------------------------------
  3050.     api_searchscreen    32
  3051. -----------------------------------------------------------------------------
  3052.     Purpose: Search the Reflection screen for a string.  If found,
  3053.          return row and column location
  3054.  
  3055.  
  3056.     INPUT:    CX =    32
  3057.         AX = DE52H
  3058.         DX = 0
  3059.         BH =    Column    (0 relative) where to start search
  3060.         BL =    Row    (0 relative)
  3061.         ES:DI = buffer containing null-terminated string
  3062.             to search for
  3063.     Output:
  3064.         No Error:
  3065.         AX = 0    found string
  3066.         BH =    Column    (0 relative)
  3067.         BL =    Row    (0 relative)
  3068.         Error:
  3069.         AX <> 0 String not found
  3070.  
  3071.  
  3072.  
  3073. Assembler Example:
  3074. ------------------
  3075.     mov    ax,0DE52H
  3076.     xor    dx,dx
  3077.     push    ds
  3078.     pop    es
  3079.     ASSUME    ES:DATA
  3080.     mov    bl,[row]
  3081.     mov    bh,[column]
  3082.     mov    di,offset search_string ; string to search for
  3083.     mov    cx,32
  3084.     int    21h
  3085.     or    ax,ax
  3086.     jnz    string_not_found
  3087.     mov    [row],bl        ; store location where found
  3088.     mov    [column],bh
  3089.  
  3090. column        db    20
  3091. row        db    2
  3092. search_string    db    "Enter Password:"
  3093.  
  3094. C Function Definition:
  3095. ----------------------
  3096.  
  3097. int    api_searchscreen( search_string, row, col );
  3098.                 returns NZ if not found
  3099. int    &row;
  3100. int    &col;
  3101. char    *search_string;
  3102.  
  3103. C Programming Example:    - Search screen for field. If found, print contents
  3104. ----------------------
  3105. main()
  3106. {
  3107.  
  3108.     /* Search screen for a prompt */
  3109.  
  3110.     int    row, col;
  3111.     char    *string = "Employee Name:";
  3112.     char    employee[30];
  3113.     col = 0;
  3114.     row = 0;
  3115.     api_open();
  3116.     if (api_searchscreen( string, &row, &col ))
  3117.         printf("Can't find employee field\n");
  3118.     else    {
  3119.         col = col + 15;    /* skip 'Employee Name:' */
  3120.         api_screenread( employee, row, col, 30 );
  3121.         employee[30] = '\0';
  3122.         printf("Employee (%s)\n",employee);
  3123.     }
  3124.     api_close();
  3125. }
  3126.  
  3127. BASIC Function Definition
  3128. -------------------------
  3129.  
  3130. DECLARE FUNCTION api.searchscreen% CDECL (SEG srchstrng$, SEG row%, SEG col%)
  3131. srchstrng$ = string being searched for
  3132. row% = row where search is to begin -
  3133. col% = column where search is to begin
  3134. if found, row% and col% are set to the location of string
  3135.  
  3136. BASIC example  - Search screen for field. If found, print contents
  3137. -------------
  3138. ' $INCLUDE: 'api.inc'
  3139. srchtext$ = "Employee Name:"
  3140. namevar$ = SPACE$(40)        ' allow 40 spaces for name variable
  3141. column% = 0
  3142. row% = 0
  3143. IF api.searchscreen(srchtext$, row%, column%) <> 0 THEN
  3144.     PRINT "Can't find employee field"
  3145. ELSE
  3146.     PRINT "found", row%, column%
  3147.     column% = column% + 15
  3148.     i = api.screenread(namevar$, row%, column%, 40)
  3149.     PRINT "Employee name : "; namevar$
  3150. END IF
  3151. END
  3152.  
  3153. TURBO Function Definition
  3154. -------------------------
  3155.  
  3156. function api_SearchScreen(var col, row :integer;var x:string ):integer;
  3157. col = starting column
  3158. row = starting row
  3159. x = string to search for.
  3160. if string is found, col and row contain string position on screen
  3161.  
  3162. TURBO Pascal example  - Search screen for field. If found, print contents
  3163. --------------------
  3164. {$V-}
  3165. uses  apiunit;
  3166. var    searchtxt    : string[30];
  3167.     row    : integer;
  3168.     col    : integer;
  3169.     i    : integer;
  3170.     namvar    : string[40];
  3171.     scrtext : buffer;
  3172. begin
  3173.      row := 0;
  3174.      col := 0;
  3175.      searchtxt := 'Employee Name:';
  3176.      if api_searchscreen(col, row, searchtxt) <> 0 then
  3177.         writeln( 'employee field not found')
  3178.      else
  3179.      begin
  3180.           col := col + 15;
  3181.           i := api_screenread( 40, col, row, scrtext);
  3182.           i := 0;
  3183.           repeat
  3184.             namvar[i+1] := scrtext[i];
  3185.             i := i + 1;
  3186.           until i = 40;
  3187.           namvar[0] := chr(40);
  3188.           writeln( 'Employee name : ', namvar );
  3189.      end;
  3190. end.
  3191.  
  3192. -----------------------------------------------------------------------------
  3193.     api_rdchar          33
  3194. -----------------------------------------------------------------------------
  3195.     Purpose: Directly read async datacomm from Reflection's receive
  3196.          buffer.  Reflection will not read the characters.
  3197.          api_startcommands() must be invoked first to
  3198.          stop Reflection from reading its incoming datacomm.
  3199.  
  3200.       It is the API client program's responsibility to keep up with
  3201.       the incoming data.  Make sure that the appropriate flow control
  3202.       is set.  Recommend SET RECEIVE-PACING XON/XOFF in most cases.
  3203.       Character translation takes place from the host character set
  3204.       to the PC character set unless SET DISABLE-TRANSLATION YES
  3205.       is in force.
  3206.  
  3207.     INPUT:    CX = 33
  3208.         AX = DE52H
  3209.         DX = 0
  3210.         ES:BX points to  2 byte buffer for storing character.
  3211.         (Null is second byte)
  3212.  
  3213.     OUTPUT:
  3214.        No error:
  3215.         AX =  0  character read
  3216.        Error:
  3217.         AX <> 0  no characters available
  3218.  
  3219.  
  3220. Assembler Example:
  3221. ------------------
  3222.     mov    ax,0DE52H
  3223.     xor    dx,dx
  3224.     push    ds
  3225.     pop    es
  3226.     ASSUME    ES:DATA
  3227.     mov    bx,offset receive_buf
  3228.     mov    cx,33
  3229.     int    21h
  3230.     or    ax,ax
  3231.     jz    received_a_character
  3232.  
  3233.  
  3234. receive_buf    db    ?,0
  3235.  
  3236.  
  3237. C Function Definition:
  3238. ----------------------
  3239. int    api_rdchar( string )  read character and store in *string
  3240. char    *string;         returns NZ if character not available
  3241.  
  3242.  
  3243. C Programming Example:
  3244. ----------------------
  3245. main()
  3246. {
  3247.  
  3248.     /* transmit some characters and read their echo */
  3249.  
  3250.     char    one_byte[2];
  3251.     char    temp[33];
  3252.     int    k;
  3253.     api_open();
  3254.     if (api_startcommands())   {        /* tell Reflect not to read */
  3255.         printf("can't start\n");        /* incoming data */
  3256.         exit();
  3257.     }
  3258.     k=0;
  3259.     api_docommand("transmit 'Read echo from these characters^m'");
  3260.     while(k < 33 )    {
  3261.         if (kbhit())
  3262.             break;
  3263.         if (!api_rdchar(one_byte))
  3264.             temp[k++]=*one_byte;
  3265.     }
  3266.     temp[k]='\0';
  3267.     printf("%s\n",temp);
  3268.     api_endcommands();
  3269.     api_close();
  3270. }
  3271.  
  3272.  
  3273. BASIC Function Definition
  3274. -------------------------
  3275.  
  3276. DECLARE FUNCTION api.rdchar% CDECL (SEG char$)
  3277. char$ = must be initialized to a length of 1 prior to call.
  3278.     if found, char$ will contain character that has been read.
  3279.     and api.rdchar% = 0
  3280.  
  3281. BASIC example    - send a character and then read the echo coming back
  3282. -------------
  3283.  
  3284. ' $INCLUDE: 'api.inc'
  3285. ch$ = space$(1)
  3286. i% = api.startcommands
  3287. '
  3288. '       send a character - depending on host, will probably be echoed back
  3289. '
  3290. i% = api.writeasync( asc("a"))
  3291. '
  3292. '       rdloop waiting for character to come back or user to hit key
  3293. '
  3294. do
  3295. loop while api.rdchar( ch$ ) <>0 and inkey$=""
  3296. if ch$ = "a" then print "Successfully transmitted and received character"
  3297. i% = api.endcommands
  3298. end
  3299.  
  3300. TURBO Function Definition
  3301. -------------------------
  3302.  
  3303. function api_Rdchar(var x:integer) :integer;
  3304. x = integer which will contain character after successful read
  3305.     (api_rdchar returns 0)
  3306.  
  3307. TURBO Pascal example - write a string and read back the echo and print it
  3308. --------------------   out.  Requires connection to full duplex host with
  3309.                local echo off.
  3310. {$V-}
  3311. uses  apiunit;
  3312. var
  3313.     j    : integer;
  3314.     k    : integer;
  3315.     i     : integer;
  3316.     srctext  : string[255];
  3317.     destext  : string[255];
  3318.     c     : integer;
  3319. begin
  3320.      srctext := 'send this string';
  3321.      destext := '';
  3322.      i := api_startcommands;
  3323.      k := 0;
  3324.      while k < length( srctext ) do
  3325.     begin
  3326.         if api_xmitstatus > 0  then
  3327.             begin
  3328.             j := api_writeasync( ord( srctext[k+1] ));
  3329.             k := succ(k);
  3330.             end;
  3331.     end;
  3332.      k := 0;
  3333.      while k < length( srctext ) do
  3334.     if api_Rdchar    (c) = 0  then
  3335.        begin
  3336.        destext[k+1] := chr(c);
  3337.        k := succ(k);
  3338.        end;
  3339.     destext[0] := chr(k);
  3340.     j := api_endcommands;
  3341.     writeln( 'received data = ', destext );
  3342. end.
  3343.  
  3344.  
  3345. -----------------------------------------------------------------------------
  3346.     api_writeasync        34
  3347. -----------------------------------------------------------------------------
  3348.     Purpose: Write a single character to the Reflection transmit
  3349.          buffer for transmission to the host.
  3350.  
  3351.     INPUT:    CX = 34
  3352.         AX = DE52H
  3353.         DX = 0
  3354.         SI = character
  3355.  
  3356.     OUTPUT:
  3357.        No error:
  3358.         AX =  0
  3359.  
  3360.        Error:
  3361.         AX <> 0 buffer full
  3362.  
  3363. Assembler Example:
  3364. ------------------
  3365.     mov    ax,0DE52H
  3366.     xor    dx,dx
  3367.     mov    cx,34
  3368.     mov    si,'a'
  3369.     int    21h
  3370.     or    ax,ax
  3371.     jnz    buffer_full
  3372.  
  3373. C Function Definition:
  3374. ----------------------
  3375.  
  3376. int    api_writeasync( c );        write character c. return NZ
  3377.                     if xmit buffer full
  3378. int    unsigned    c;
  3379.  
  3380. C Programming Example:
  3381. ----------------------            transmit the contents of the string
  3382. main()
  3383. {
  3384.  
  3385.     /* write a string */
  3386.  
  3387. int    c;
  3388. char    *xmit_string   = "Send this string";
  3389.     api_open();
  3390.     while (( c =*xmit_string++)  != '\0' )  {
  3391.         while(!api_xmitstatus())
  3392.             if (kbhit())
  3393.                 break;
  3394.         api_writeasync( c );
  3395.     }
  3396.     api_close();
  3397. }
  3398.  
  3399. BASIC Function Definition
  3400. -------------------------
  3401.  
  3402. DECLARE FUNCTION api.writeasync% CDECL (BYVAL c%)
  3403. c% = is the ordinal value of the character within the ASCII character
  3404.      set.  This can be derived via the ASC function.  c% = asc( c$  )
  3405.  
  3406.  
  3407. BASIC example
  3408. -------------
  3409.  
  3410. See    api.rdchar above
  3411.  
  3412. TURBO Function Definition
  3413. -------------------------
  3414.  
  3415. function api_writeasync(c :integer ) :integer;
  3416.  
  3417. c = integer containing character to be transmitted
  3418.  
  3419. TURBO Pascal example
  3420. --------------------
  3421. See    api_rdchar above
  3422.  
  3423. -----------------------------------------------------------------------------
  3424.     api_xmitstatus        35
  3425. -----------------------------------------------------------------------------
  3426.     Purpose: Return the amount of free space in the transmit buffer.
  3427.          Should be used before api_writeasync to prevent
  3428.          accidental overrun of the transmit buffer and loss of data.
  3429.  
  3430.     INPUT:    CX = 35
  3431.         AX = DE52H
  3432.         DX = 0
  3433.  
  3434.     OUTPUT:
  3435.         AX = amount of free space
  3436.  
  3437.  
  3438.  
  3439. Assembler Example:
  3440. ------------------
  3441.  
  3442.     mov    ax,0DE52H
  3443.     xor    dx,dx
  3444.     mov    cx,35
  3445.     int    21h
  3446.     or    ax,ax            ; is there any free space
  3447.     jz    buffer_full        ;  NO
  3448.  
  3449. C Function Definition:
  3450. ----------------------
  3451.  
  3452. int    api_xmitstatus();        ; returns # bytes of free space
  3453.                     ; in xmit buffer
  3454. C Programming Example:
  3455. ----------------------
  3456.  
  3457. see api_writeasync above.
  3458.  
  3459.  
  3460. BASIC Function Definition
  3461. -------------------------
  3462.  
  3463. DECLARE FUNCTION api.xmitstatus% CDECL ()
  3464.  
  3465.  
  3466. BASIC example    - send an ASCII file out the datacomm port without
  3467. -------------      flow control
  3468.  
  3469. ' $INCLUDE: 'api.inc'
  3470.     open "filename" for input as #1
  3471. readloop:
  3472.     if eof(1) then goto endit
  3473.     line input #1, x$
  3474.     for charpos = 1 to len(x$)
  3475.     do                 ' delay until transmitter ready
  3476.     loop while api.xmitstatus = 0
  3477.     i%=api.writeasync( asc( mid$(x$,charpos, 1) ))
  3478.     next charpos
  3479.  
  3480.     do                    ' delay until transmitter ready
  3481.     loop while api.xmitstatus = 0
  3482.     i%=api.writeasync( 13% )        ' send a carriage return
  3483.     for j% = 1 to 100 : next j%     ' delay after carriage return
  3484.     goto readloop
  3485. endit:
  3486.     close (1)
  3487.     end
  3488.  
  3489.  
  3490. TURBO Function Definition
  3491. -------------------------
  3492.  
  3493. function api_Xmitstatus :integer;
  3494.  
  3495. TURBO Pascal Example
  3496. --------------------
  3497.  
  3498. See    api_rdchar above
  3499.  
  3500.  
  3501.  
  3502.  
  3503.  
  3504.               An API Primer
  3505.       Converting an existing command file to  C
  3506.       -----------------------------------------
  3507.  
  3508. It is assumed that you are already familiar with Reflection and have
  3509. written Reflection command language programs.    If you haven't, that
  3510. is probably the best and easiest place to start.
  3511.  
  3512. If you have a supply of command files that you have written in the
  3513. past, a good way to get started with API is to convert one or more of
  3514. these files to an API program.    An example in C is shown.
  3515.  
  3516. The api_docommand function is shown since it is the easiest function
  3517. to use.
  3518.  
  3519. One of the principal differences you'll notice when using the
  3520. api_docommand() function is that the IF, ELSE, ENDIF, GOTO, and GOSUB
  3521. commands are not supported.  Flow of control must be handled by the
  3522. client program.
  3523.  
  3524.     A command language IF clause which reads...
  3525.  
  3526.         CONTINUE
  3527.         SEND "ABC TO XYZ"
  3528.         IF ERROR
  3529.             DISPLAY "ERROR TRANSFERRING FILE^m^j"
  3530.         ENDIF
  3531.  
  3532.     would be converted to C as follows
  3533.  
  3534.         (CONTINUE is on automatically)
  3535.  
  3536.         if (api_docommand( "SEND ABC TO XYZ"))
  3537.             printf("Error transferring file\n");
  3538.  
  3539.         api_docommand() returns 0 if no error or the
  3540.         error code if an error occurred.  This is then
  3541.         tested by C and a branch can be taken.
  3542.  
  3543.     a QuickBASIC version of the same thing would be
  3544.  
  3545.         if api.docommand( "SEND ABC TO XYZ") > 0 then
  3546.             print "Error transferring file"
  3547.  
  3548.  
  3549.     Another example:  Get  V1 from Reflection, test for a substring
  3550.  
  3551.  
  3552.     Command Language Version
  3553.  
  3554.         TRANSMIT "LISTF FOO^m"
  3555.         READHOST    V1
  3556.         READHOST    V1
  3557.         WAIT 0:0:8 FOR "^q"
  3558.         IF FIND("CIERR",v1) > 0
  3559.             DISPLAY "File FOO Not Found on Host^m^j"
  3560.         ENDIF
  3561.  
  3562.     C Version:
  3563.         int    length;
  3564.         char    varbuf[81];
  3565.         ....
  3566.         api_docommand("transmit 'listf foo^m'");
  3567.         api_docommand("readhost 0:0:5 v1);
  3568.         api_docommand("readhost 0:0:5 v1);
  3569.         api_docommand("wait 0:0:8 for '^q'");
  3570.         api_getvar( varbuf, 1, &length ); /* get v1 */
  3571.         varbuf[length] = '\0';               /* null-terminate */
  3572.         if (strstr( varbuf, "CIERR" ))
  3573.             printf( "File FOO Not Found on Host\n");
  3574.         ....
  3575.  
  3576.         *strstr() is the C counterpart of Reflection FIND()
  3577.  
  3578.  
  3579.  
  3580.  
  3581.     Handling Special Problems
  3582.  
  3583.  
  3584. Keyboard Reads
  3585.  
  3586. You will probably want to avoid  api_docommand( "accept v1").  ACCEPT
  3587. is the verb which reads input from the keyboard.  Since Reflection is
  3588. in background, the user won't be able to type anything (unless you
  3589. have queued keys) and your program will hang.
  3590.  
  3591. Most likely you'd normally be using the C gets command or some other
  3592. variant for reading keyboard input into your C program.
  3593.  
  3594. Unfortunately many Microsoft C and Turbo Pascal keyboard reads use
  3595. DOS calls like function 3FH (read file handle). This call has a side
  3596. effect of preventing Reflection from getting any CPU time until the
  3597. user enters the line and hits carriage return.
  3598.  
  3599. No multitasking takes place!  This can halt a file transfer and
  3600. cause a host or local timeout.    To avoid this problem, you will
  3601. need to use different calls to read from the keyboard.    The included
  3602. libraries for C and Turbo Pascal each support a keyboard read which
  3603. does not freeze Reflection.  BASIC does not use this call and
  3604. therefore encounters no problems.
  3605.  
  3606. C function available in the C_[X]API.LIB's   X = S,C,M,L
  3607.  
  3608.     char    *rgets( s, i )
  3609.     char    *s;    /*    buffer for string   */
  3610.     int    i;    /*    size of buffer        */
  3611.  
  3612.     Be sure to allocate a buffer which is one byte larger than
  3613.     its size parameter.  This call uses DOS function 0AH,
  3614.     (read string).
  3615.  
  3616.  
  3617. Pascal procedure available in APIUNIT.TPU and APIUNIT.PAS
  3618.  
  3619. procedure rfreadkeybd( length : integer; var x: string );
  3620.  
  3621.     Specify a length which is one less than the
  3622.     declared string size.
  3623.  
  3624.     Example - prompt for a queued command and then
  3625.     call API to queue it.
  3626.  
  3627.     program quecmd (input,output);
  3628.     {$V-}
  3629.     (*  include the API UNIT *)
  3630.     uses  apiunit;
  3631.     var    command  : string[80];
  3632.         i     : integer;
  3633.     begin
  3634.          write ( 'enter command : ');
  3635.          rfreadkeybd ( 79, command );
  3636.          while command >= ' ' do
  3637.            begin
  3638.         i := api_qcmd( command );
  3639.         write ( 'enter command : ');
  3640.         rfreadkeybd ( 79, command )
  3641.            end;
  3642.     end.
  3643.  
  3644.  
  3645.  
  3646. Timeouts
  3647.  
  3648. As previously mentioned, if you are using synchronous calls
  3649. (api_docommand) where your program has to wait for the call
  3650. to complete,  make sure that you specify a timeout on any
  3651. WAIT, HOLD, READHOST, or other command.  Otherwise your
  3652. application may hang waiting for a response that may never
  3653. arrive.
  3654.  
  3655. Conflicting Commands
  3656.  
  3657. Reflection is constantly accepting commands from both the host
  3658. computer and the user.    From time to time, however, these commands
  3659. may conflict with each other.  For instance, the host may lock the
  3660. keyboard while the user wants to type data for the next screen.  The
  3661. host also has the capability to invoke the Reflection command
  3662. facility by prefixing Reflection commands with the escape sequence
  3663. "<esc>&oC".  Some host programs use this facility.  Reflection may
  3664. then encounter a command file running on the PC which starts and
  3665. tries to run a host application which sends commands via the escape
  3666. sequence.  Since Reflection can't process two commands at once, the
  3667. host commands fail.  The results, however, are usually disastrous since
  3668. the host program isn't behaving the same way it was when you ran it
  3669. from the keyboard.  api_startcommands turns off host initiated
  3670. commands, i.e. if any commands come from the host, they will fail, but
  3671. this will certainly abort or seriously affect the host application.
  3672. There's no solution to problems of this kind except awareness.  It is
  3673. frequently helpful to turn on display functions or display controls
  3674. to see what the host is actually doing.  You will then see any host
  3675. commands, status requests, etc. that you'll have to program around.
  3676.  
  3677. Preventing User Exits
  3678.  
  3679. An unguarded API application can be unintentionally sabotaged by the
  3680. user. If the user pops up Reflection and hardexits (ALT-X), your
  3681. application will have nothing to interface with.  The only way that
  3682. your application can detect this is by looking at return codes.  If
  3683. AX returns with AH = DEH, this is precisely what has happened.
  3684. Reflection has been un-installed.  You'll want to make sure that the
  3685. user doesn't even have a chance to screw things up.  You can control
  3686. the user as much as you want by issuing the appropriate Reflection
  3687. set commands.
  3688.  
  3689.      SET HOT-KEY NONE
  3690.  
  3691.      Will prevent the user from popping up Reflection
  3692.  
  3693.      SET EXITS-DISABLED YES
  3694.  
  3695.      Will prevent the user from exiting via ALT-X or
  3696.      interfering by pressing hard-reset
  3697.  
  3698.      SET DISABLE-INTERRUPT
  3699.  
  3700.      Will prevent the user from stopping a command via
  3701.      Ctrl-Y
  3702.  
  3703. Of course all of these settings will make it much more
  3704. difficult for you to debug your program, so you shouldn't set
  3705. them until everything is working correctly.
  3706.  
  3707. Datacomm Disabling in docommand sequence
  3708.  
  3709. Once the api_startcommands function is performed, datacomm is turned
  3710. off except during the actual execution of an api_docommand.  This is
  3711. essential to allow your application to maintain synchronization with
  3712. the host program.  What we mean when we say datacomm is turned off is
  3713. that Reflection will not read any incoming characters from its
  3714. receive buffer unless you are actually processing a command.  The
  3715. characters will still be received, of course, but they will remain in
  3716. the buffer and Reflection will be ignorant of them.  This means that
  3717. you can pause and prompt the user for something without missing any
  3718. incoming characters.  If you were logging a user onto a DEC VAX and
  3719. had to stop and prompt for a password, you wouldn't have to worry
  3720. that the password prompt might have slipped in while you weren't
  3721. looking. The password prompt would still be in Reflection's receive
  3722. buffer waiting to be read by your next command.  If you then issued
  3723. the command
  3724.  
  3725.      api_docommand("WAIT 0:0:30 for 'Password:'");
  3726.  
  3727. the command would return immediately (since the prompt was
  3728. already in the receive buffer).
  3729.  
  3730. If, instead, Reflection were always reading datacomm and you
  3731. issued the above wait command, the WAIT would time out in 30
  3732. seconds without finding the 'Password:' prompt, since it
  3733. would have already been received. Your application would
  3734. likely assume that there was some kind of problem
  3735. communicating with the VAX and take incorrect action.
  3736.  
  3737. To prevent Reflection's receive buffer from being overrun by
  3738. the host during delays by your application, you must
  3739. set the appropriate type of flow control.  For both HP and
  3740. DEC, this will in most cases be XON/XOFF receive pacing.
  3741.  
  3742. When you issue a WAIT FOR command, you will
  3743. probably want to follow it with a api_found() command, which
  3744. will tell your application whether the wait command actually
  3745. found the string you were looking for, or it timed out
  3746. empty-handed.
  3747.  
  3748.     api_docommand("wait 0:0:30 for 'HP3000'");
  3749.     if (api_found())
  3750.         printf("Logged on Successfully\n");
  3751.     else
  3752.         .....
  3753.  
  3754. Configuration Issues
  3755.  
  3756. The api_getinfo command returns a structure of configuration
  3757. items, but they are pretty obscure.  These are items
  3758. which appear on config screens but have no corresponding SET
  3759. command.  The VALUE command can be relied upon to get more
  3760. common configuration items such as BAUD rate, PARITY, etc.
  3761. For instance, to find the baud rate execute the following
  3762. sequence:
  3763.  
  3764.      api_docommand( "set v3=value(BAUD)" );
  3765.      api_getvar( baudvalue, 3, length );
  3766.      baudvalue[length]='\0';
  3767.      printf( "Reflection BAUD RATE = %s\n",baudvalue);
  3768.  
  3769.      SET commands can be issued to change most configuration
  3770.      items.  Some items cannot be changed except via SET
  3771.      commands or display commands using escape sequences.
  3772.  
  3773.  
  3774. Configuring Reflection to use less memory
  3775.  
  3776. Since Reflection must be loaded in background to provide API services
  3777. to a client program, memory is at a premium.  There must be enough
  3778. for any resident device drivers plus Reflection, as well as your
  3779. application.  You can configure Reflection to use less memory by
  3780. setting display memory to 8K instead of 20K, using the standard IBM
  3781. font (/I switch), and by using expanded memory if available (/E
  3782. switch).
  3783.  
  3784.     R1 /Q /W /B /I /E
  3785.  
  3786. This command loads Reflection /Quickly /With API /Background immediately
  3787. with /IBM font using /Expanded memory.    Using a configuration file which
  3788. specifies 8K of display memory and no print buffers will also save
  3789. memory.
  3790.  
  3791.  
  3792. Queued File Transfers
  3793.  
  3794. When an API client queues a file transfer, the file transfer usually
  3795. will not start immediately.  Consequently, if you immediately test
  3796. apistat_batch_flag to see if the transfer is complete (== 0), you
  3797. will probably be testing it before Reflection has had a chance to
  3798. turn it on.  The best way to determine Reflection's status, and see
  3799. whether the file transfer is complete, is by testing the return code
  3800. from api_block.  If api_block returns 0, then Reflection has
  3801. exhausted all queues.  Api_block also gives Reflection a little CPU
  3802. time.
  3803.  
  3804. Synchronous File Transfers
  3805.  
  3806. One problem in performing a synchronous file transfer is that control
  3807. will not return to your PC until the file is transferred.  Since the
  3808. user will not receive any feedback as the file is being transferred,
  3809. it tends to look as though the machine is hung.  By using queued
  3810. commands, you can get around this problem and pop up the file
  3811. transfer screen during the transfer so the user will at least know
  3812. that something is happening. The following code fragment demonstrates
  3813. this.  It queues 3 commands: a command to perform the file transfer,
  3814. a command to get the error code into a variable, and a command to
  3815. switch back to background.  It then issues the pop_up command so the
  3816. user can view the file transfer.  As soon as the file transfer
  3817. completes, the error code is fetched and Reflection flips back to
  3818. background.  While these commands are queued, the effect is
  3819. synchronous since the file transfer is performed in the foreground.
  3820. It is important to capture the error code since it is possible for
  3821. the user to stop the transfer via the STOP TRANSFER key.  In this
  3822. case, you can detect why the xfer failed.
  3823.  
  3824.  
  3825.  
  3826.    char   error_text[81];
  3827.    int      length;
  3828.    api_qcmd( "send testall.c to data1 ascii delete");
  3829.    api_qcmd( "let v9=error-code" );
  3830.    api_qcmd( "background");
  3831.    api_popup();
  3832.    api_getvar( error_text, 9 , &length);
  3833.    error_text[length]='\0';
  3834.    printf( "File transfer Completed\n");
  3835.    printf( "Error code %s",error_text );
  3836.    exit();
  3837.  
  3838.  
  3839.  
  3840.  
  3841. Un-installing Reflection
  3842.  
  3843. If you need to un-install Reflection to free up some memory,
  3844. the correct method is to use api_qcmd as follows:
  3845.  
  3846.     api_qcmd("HARDEXIT");
  3847.  
  3848. Other methods may leave your PC in an unstable state.
  3849.  
  3850.  
  3851. Debugging API applications
  3852.  
  3853. Most programmers have their favorite debugger.    Microsoft C
  3854. developers usually use CodeView, and Turbo Pascal or QuickBASIC
  3855. programmers may use the built-in debug capabilities of those
  3856. environments.    Memory limitations, however, may also determine
  3857. which debugger is used.  Periscope has low memory requirements and
  3858. is useful for debugging memory-resident applications.
  3859.  
  3860.  
  3861.     COMMAND LANGUAGE PROGRAM -> API PROGRAM
  3862.         SAMPLE CONVERSIONS
  3863.  
  3864.  
  3865. Here's a fairly standard command file which dials a modem and
  3866. attempts to log on to an HP 3000 computer.  Following it is the exact
  3867. same function in a C program using API calls.
  3868.  
  3869.     COMMAND LANGUAGE VERSION
  3870.  
  3871.  
  3872. set datacomm-port com1
  3873. set baud 2400
  3874. set character-delay 80
  3875. ;
  3876. ; need to set big delays and long waits when talking to modems
  3877. ;
  3878. ; initialize retry_count
  3879. let v1 = 0
  3880. display 'Initializing Modem...^m^j'
  3881. wait 0:0:1
  3882. transmit '+++'
  3883. wait 0:0:2 for 'OK'
  3884. wait 0:0:.5
  3885. transmit 'ATH^m'
  3886. wait 0:0:2 for 'OK'
  3887. if NOT FOUND
  3888.     let v4 =   "No Response from modem^m^j"
  3889.     goto fail
  3890. endif
  3891. wait 0:0:1
  3892. display 'Dialing Modem...^m^j'
  3893. transmit 'ATDT 1234567^m'
  3894. wait 0:0:45 for 'CONNECT'
  3895. if NOT FOUND
  3896.     let v4 = "Did not receive CONNECT Message^m^j"
  3897.     goto fail
  3898. endif
  3899. display 'Connected to Remote Modem^m^j'
  3900. ;
  3901. ; Modem says we're connected - see if we can log on
  3902. ;
  3903. :tryagain
  3904. if v1 < 6
  3905.     let v1 = v1 + 1
  3906.     transmit '^m'
  3907.     wait 0:0:1 for '^q'
  3908.     if NOT FOUND
  3909.     display 'Try $1 Failed^m^j'
  3910.     goto tryagain
  3911.     else
  3912.     goto logon
  3913.     endif
  3914. else
  3915.     let v4 = "Never Got Host Prompt^m^j"
  3916.     goto fail
  3917. endif
  3918. display 'Entering login and password^m^j'
  3919. transmit 'hello sazle,mgr.express/joshua^m'
  3920. wait 0:0:30 for 'HP3000'
  3921. if NOT FOUND
  3922.     display 'Login rejected - hangup modem^m^j'
  3923.     wait 0:0:2
  3924.     transmit '+++'
  3925.     wait 0:0:3 for 'OK'
  3926.     wait 0:0:1
  3927.     transmit 'ATH^m'
  3928.     wait 0:0:2 for 'OK'
  3929.     if NOT_FOUND
  3930.     let v4 = "Hangup Complete^m^j"
  3931.     goto fail
  3932.     else
  3933.     let v4 = "Hangup failed^m^j"
  3934.     goto fail
  3935.     endif
  3936. endif
  3937. wait 0:0:30 for ':^q'
  3938. set character-delay 0
  3939. display 'Successful Logon^m^j'
  3940. stop
  3941. ;
  3942. ;    Fail 'subroutine'
  3943. ;
  3944. :fail
  3945. display  v4
  3946. stop
  3947.  
  3948.  
  3949.     C LANGUAGE VERSION of the same command file using Synchronous
  3950.     (Do while you wait) Commands.  Notice that we use C's if
  3951.     and for statements to control program execution.
  3952.  
  3953. main()
  3954. {
  3955.     int  retry_count;
  3956.     char    serbuf[32];
  3957.     if (api_instchk(serbuf)) {
  3958.         printf("API not present\n");
  3959.         exit();
  3960.     }
  3961.     api_open();
  3962.     if (api_startcommands()) {
  3963.         printf("API busy\n");
  3964.         exit();
  3965.     }
  3966.  
  3967.     api_docommand("alert 'API - AUTODIAL - LOGON'");
  3968.     api_docommand("set datacomm-port com1");
  3969.     api_docommand("set baud 2400");
  3970.     api_docommand("set character-delay 80");
  3971.  
  3972.     /* need to set big delays and long waits when talking to modems */
  3973.  
  3974.     retry_count = 0;
  3975.     printf("Initializing Modem...\n");
  3976.     api_docommand("wait 0:0:1");
  3977.     api_docommand("transmit '+++'");
  3978.     api_docommand("wait 0:0:2 for 'OK'");
  3979.     api_docommand("wait 0:0:.5");
  3980.     api_docommand("transmit 'ATH^m'");
  3981.     api_docommand("wait 0:0:2 for 'OK'");
  3982.     if (!api_found())
  3983.          fail("No Response from modem\n");
  3984.  
  3985.     api_docommand("wait 0:0:1");
  3986.     printf("Dialing Modem...\n");
  3987.     api_docommand("transmit 'ATDT 1234567^m'");
  3988.     api_docommand("wait 0:0:45 for 'CONNECT'");
  3989.     if (!api_found())
  3990.        fail("Did not receive CONNECT Message\n");
  3991.  
  3992.     printf("Connected to Remote Modem\n");
  3993.  
  3994.     /* Modem says we're connected - see if we can log on */
  3995.  
  3996.     for ( retry_count = 0 ; retry_count < 6 ; retry_count++) {
  3997.          api_docommand("transmit '^m'");
  3998.          api_docommand("wait 0:0:1 for '^q'");
  3999.          if (!api_found())
  4000.           printf("Try %d Failed\n",retry_count);
  4001.          else
  4002.           break;
  4003.     }
  4004.     if ( retry_count >= 6)
  4005.         fail("Never got host prompt\n");
  4006.     else
  4007.         printf("Entering login and password\n");
  4008.  
  4009.     api_docommand("transmit 'hello sazle,mgr.express/joshua^m'");
  4010.     api_docommand("wait 0:0:30 for 'HP3000'");
  4011.     if (!api_found())  {
  4012.          printf("Login rejected - hangup modem\n");
  4013.          api_docommand("wait 0:0:2");
  4014.          api_docommand("transmit '+++'");
  4015.          api_docommand("wait 0:0:3 for 'OK'");
  4016.          api_docommand("wait 0:0:1");
  4017.          api_docommand("transmit 'ATH^m'");
  4018.          api_docommand("wait 0:0:2 for 'OK'");
  4019.          if (!api_found())
  4020.         fail("Hangup Complete\n");
  4021.          else
  4022.         fail("Hangup failed\n");
  4023.     }
  4024.     api_docommand("wait 0:0:30 for ':^q'");
  4025.     api_docommand("set character-delay 0");
  4026.     printf("Successful Logon\n");
  4027.     api_endcommands();
  4028.     api_close();
  4029. }
  4030.  
  4031. fail(s)
  4032. char    *s;
  4033. {
  4034.     printf("%s",s);
  4035.     api_endcommands();
  4036.     api_close();
  4037.     exit();
  4038. }
  4039.  
  4040.  
  4041.  
  4042.  
  4043.        Using the api_qkeys() function.
  4044.  
  4045.  
  4046. You'll need to mind your single and double quotes when using this
  4047. function.  When passing keystrokes via the api_qkeys function, keys
  4048. with normal ASCII values such as "abcd12345%&*@" are passed between
  4049. single or double quotes.  Note that even control characters may be
  4050. passed in this way.  Keys with special functions such as the HP or VT
  4051. ENTER key, F1, PF1, or the ERROR-RECAP key which brings up the
  4052. summary of datacomm errors are not treated in this way.  Keys
  4053. providing special functions are passed as KEYWORDS and are not
  4054. quoted. A list of these keywords is found in the Keyboard
  4055. Remapping section of the Technical Reference Manual.  These are
  4056. keywords such as HARD-RESET, HOST-BREAK, RETURN, F1, F2, SYSTEM-KEYS,
  4057. ENTER, etc.
  4058.  
  4059. Be careful to observe the difference between:
  4060.  
  4061.         api_qkeys("'return'");
  4062.  
  4063.         which passes the keys r - e - t - u - r - n
  4064.         as a quoted string 'return' and...
  4065.  
  4066.         api_qkeys("return");
  4067.  
  4068.         which passes the keyword RETURN as a NON-quoted
  4069.         string to API - this refers to the carriage
  4070.         return key.
  4071.  
  4072.  
  4073.  
  4074.  
  4075. API SPECIFIC ERROR CODES returned to functions
  4076. ------------------------
  4077.  hex   dec
  4078.  
  4079.   0    0    No Error         No error encountered
  4080.  
  4081.  
  4082. 100h   256   Not_Available - Attempt to do api_startcommands when Reflection
  4083.                  busy or a config screen/help screen/file xfer
  4084.                  screen is present.
  4085.                  Attempt to do api_docommand when screen is up.
  4086.  
  4087. 101H   257   OpenforSynch    Attempt to do api_qcmd when opened for Docommands
  4088.                  Issue an api_endcommands function first.
  4089.  
  4090.  
  4091. 102H   258   ServiceNotOpen  Attempt to do an api_docommand before first
  4092.                  issuing an api_startcommands.  Also an
  4093.                  attempt to do an api_rdchar without doing
  4094.                  an api_startcommands (to turn off datacomm).
  4095.  
  4096. 103H   259   IllegalFncCall  Call parameters are incorrect, i.e. a screen
  4097.                  read is requested which goes off of the screen
  4098.  
  4099. 104H   260   QueueFull         Keyboard or Command queue is full
  4100.  
  4101. 105H   261   BadKey         An attempt was made to queue a keyname that
  4102.                  could not be recognized
  4103.  
  4104. 106H   262   BadLength         Attempt made to set a variable with length
  4105.                  greater than 80 or a command with greater
  4106.                  than 159
  4107.  
  4108. 109H   265   NotFound         Searchscreen failed character not found
  4109.                  on api_rdchar
  4110.  
  4111. 10AH   266   BadVarno         The variable number used exceeded the
  4112.                  current highest legal variable number
  4113.  
  4114. 0FFFFH    -1   Uninstalled     Reflection was un-installed.  Also AH=DEH
  4115.                  for assembler
  4116.  
  4117. other codes             Api_docommand returns standard Reflection
  4118.                  error codes.  These codes are below 256.
  4119.                  See the Command Language manual for a
  4120.                  listing of these error codes.
  4121.  
  4122.  
  4123.  
  4124. Compiling and Linking with API Libraries
  4125. ----------------------------------------
  4126.  
  4127.  
  4128. Building API applications with Borland Turbo Pascal
  4129. ---------------------------------------------------
  4130.  
  4131.     Version 5.0 or greater of Turbo Pascal is required.
  4132.  
  4133.  
  4134.  
  4135. Sample session using TURBO integrated environment:
  4136.  
  4137.     1. Load Reflection in background using a minimum memory
  4138.        configuration
  4139.  
  4140.     2. Load SAMPLE.PAS file using pull-down menus
  4141.  
  4142.     3. Run SAMPLE.PAS - it will prompt for Reflection
  4143.        command language commands.  Use commands like
  4144.        'dir', 'display "^g"' to beep the bell, or
  4145.        'foreground' to pop Reflection up.
  4146.  
  4147. Sample session using DOS command line:
  4148.  
  4149.     1. Invoke Turbo Pascal compiler via TPC command
  4150.  
  4151.         TPC  sample   /GD
  4152.  
  4153.        (GD switch produces a detailed map which can be
  4154.          used for debugging)
  4155.  
  4156.        This will create a SAMPLE.EXE file
  4157.  
  4158.     Turbo Pascal will 'link' in APIUNIT.TPU to create
  4159.     SAMPLE.EXE
  4160.  
  4161.  
  4162.  
  4163.  
  4164.  
  4165.  
  4166. Building API applications using Microsoft QuickBASIC
  4167. ----------------------------------------------------
  4168.  
  4169.     Version 4.5 or greater of Microsoft QuickBASIC
  4170.     required.
  4171.  
  4172.  
  4173. Special considerations for BASIC string variables:
  4174.  
  4175.     The size of a BASIC string variable cannot be
  4176.     modified by a called subroutine such as api.getvar.
  4177.     Any attempt to modify the length of a BASIC string
  4178.     variable results in a "String Space Corrupt" message
  4179.     and immediate termination of the program.  For this
  4180.     reason, if you need to get a Reflection variable into
  4181.     a BASIC string, you must first initialize the string
  4182.     to the correct length in BASIC and then pass the string
  4183.     to Reflection as shown:
  4184.  
  4185.         varbuf$ = SPACE$(80)
  4186.         i% = api.getvar( varbuf$, 2, l% )
  4187.         varbuf$ = MID$( varbuf$, 1, l% )
  4188.  
  4189.  
  4190.  
  4191.  
  4192.     Using the QuickBASIC environment:
  4193.  
  4194.     1. From DOS prompt load R1 or R2 using minimum memory
  4195.        configuration and requesting API support.  You must
  4196.        be using Reflection version 3.40 or above.    Reflection
  4197.        should immediately go into background if there is a
  4198.        configuration file.
  4199.  
  4200.         R1 /W /B /I /Q
  4201.  
  4202.         (for switch definitions, type  R1 /?)
  4203.  
  4204.     2. From DOS prompt, start QB environment by typing:
  4205.  
  4206.         QB  /L    B_APILIB.QLB
  4207.  
  4208.     3. The QuickBASIC environment will start up with the API
  4209.        support present.
  4210.  
  4211.     4. Load the SAMPLE.BAS program using the FILES pull-down
  4212.        menu.
  4213.  
  4214.     5. Run the program.  SAMPLE.BAS will first print the
  4215.        Reflection serial number and will then pop-up after
  4216.        you hit a key.  Hit hot-key (Alt-right Shift) to return
  4217.        to the BASIC program.
  4218.  
  4219.    Using the DOS command line:
  4220.  
  4221.  
  4222.     1. Invoke the QuickBASIC compiler
  4223.  
  4224.         BC    SAMPLE;
  4225.  
  4226.     2. Invoke the Microsoft Linker, linking in the
  4227.        B_APILIB.LIB library.
  4228.  
  4229.         LINK    SAMPLE,,,B_APILIB;
  4230.  
  4231.     Note that there are a number of command line options
  4232.     for producing stand alone .EXE versions and providing
  4233.     debug capabilities.  These options are documented in
  4234.     the QuickBASIC manuals.
  4235.  
  4236.  
  4237.  
  4238.  
  4239.  
  4240. Building API applications using  Microsoft C
  4241. ---------------------------------------------
  4242.  
  4243.     Microsoft C version 5.0 or greater required
  4244.  
  4245. Sample Compile and Link of a small model API application.
  4246.  
  4247.         cl    sample.c  /link  c_sapi.lib
  4248.  
  4249. Sample Compile and Link of a medium model API application.
  4250.  
  4251.         cl /AM    sample.c  /link  c_mapi.lib
  4252.