home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / rxportio.zip / RXPORTIO.CMD < prev    next >
OS/2 REXX Batch file  |  1998-06-22  |  4KB  |  122 lines

  1. /* RXPORTIO.CMD */
  2. /* Sample REXX Program to access I/O ports using TESTCFG.SYS */
  3.  
  4. /*
  5.  To run this program, the file RXPORTIO.DLL must be in
  6.  the same directory as this file or in a directory
  7.  listed in your LIBPATH.
  8.  
  9. Prerequisites for RXPORTIO to work properly:
  10.  
  11. The following statements must be in your CONFIG.SYS
  12.  
  13. IOPL=YES,FXPRINT  (or just IOPL=YES)
  14. DEVICE=D:\OS2\BOOT\TESTCFG.SYS
  15.  
  16. These statements are added by default by Warp 3 and Warp 4.
  17.  
  18. Note: If the port_Address is not returned as the same value, then there was an error in reading or writing to the port.
  19.       The data_value will return the error code from the DosOpen or DosDevIOCtl call.
  20.  
  21.       The port_Address can have the following values in an error condition:
  22.  
  23.       port_Address = 10 if DOSOpen during init was unsuccessful.
  24.                      11 if I/O read unsuccessful.
  25.                      12 if I/O write unsuccessful.
  26.  
  27.       In an error condition, data will return the return code (rc) of the DOSDevIOCtl or DosOpen commands.
  28.       See the IBM VisualAge C/C++ documantation on Control Program or rxPortIO.INF for error code explanation.
  29.   
  30. */
  31.  
  32.  
  33. /* Load RXPORTIO.DLL    */
  34.  
  35. CALL RXFuncAdd 'PIOLoadFuncs', 'RXPORTIO', 'PIOLoadFuncs'
  36. CALL PIOLoadFuncs
  37.  
  38. SAY ''
  39. SAY '--- Sample REXX Program to access I/O ports using TESTCFG.SYS.---'
  40. SAY ''
  41.  
  42. SAY 'CAUTION: This program is capable of writing to I/O directly.'
  43. SAY '         Make sure the port_Address is set to a value'
  44. SAY '         that will not cause harm to your system.'
  45. SAY '         Port_Address is set to 768 (300hex) by default.'
  46. SAY ''
  47.  
  48. port_Address = X2D('300')                         /* Port_address is converted from hex to decimal */
  49. data_value = 0                                    /* initialize I/O data_value to zero */
  50. SAY 'Address is set to ' || port_Address || ' decimal.'
  51.  
  52. keyhit = ""
  53. DO FOREVER
  54.    SAY ""
  55.    SAY "Press w to write 0x55, r to Read; d for 0.5 sec delay;"
  56.    SAY "b for bit manipulation; x for eXit..."
  57.    SAY ""
  58.    PARSE PULL keyhit
  59.    SELECT
  60.       when keyhit = "r" | keyhit = "R" then    /* read */
  61.         do
  62.          return_data = PIORead( port_Address )
  63.          SAY 'Read returned ' || return_data
  64.          PARSE VAR return_data . ': ' port1 . ': ' data1
  65.  
  66.          IF port1 <> port_Address then
  67.            SAY 'error reading port: ' || port_Address || '  rc = ' || data1
  68.          ELSE
  69.            SAY "READ. Address: " || D2X(port1) || "h   Data: " || D2X(data1) || "h = " || X2B(D2X(data1)) || " bin"
  70.  
  71.          keyhit = ""
  72.         end
  73.       
  74.       when keyhit = "w" | keyhit = "W" then    /* write  */
  75.         do
  76.           data_value = X2D('55')  /* data to write */
  77.           return_data = PIOWrite( port_Address, data_value )
  78.           SAY 'Write returned ' || return_data
  79.           PARSE VAR return_data . ': ' port1 . ': ' data1
  80.           SAY "WRITE. Address: " || D2X(port1) || "h   Data: " || D2X(data1) || "h = " || X2B(D2X(data1)) || " bin"
  81.           keyhit = ""
  82.         end
  83.  
  84.       when keyhit = "d" | keyhit = "D" then    /* delay  */
  85.         do
  86.           delay_value = 500                                    /* delay 1 to 1000 msec max. */
  87.           SAY 'Start delay of ' || delay_value || ' msec...'
  88.           delay = TIME('R')                                    /* delay verification only */
  89.           return_data = PIODelay( delay_value )
  90.           delay = TIME('E')
  91.           SAY "... End Delay (0 = successfull, 322 = error).  rc = " || return_data
  92.           SAY 'elapsed time = ' || delay
  93.           keyhit = ""
  94.         end
  95.  
  96.       when keyhit = "b" | keyhit = "B" then    /* bit manipulations */
  97.         do
  98.           value = X2D('FF')  /* init value to 255 (FFhex) */
  99.           SAY 'BitPick. Bit 0 of ' || value || ' is ' || PIOBitPick(value, '0')
  100.           SAY 'BitClear. Bit 1 cleared of ' || value || ' is ' || PIOBitClear(value, '1')
  101.           SAY 'BitClear. Bit 8 cleared of 257 is ' || PIOBitClear('257', '8')
  102.           SAY 'BitSet. Bit 15 set of 0 is ' || PIOBitSet('0', '15')
  103.           keyhit = ""
  104.         end
  105.  
  106.    otherwise
  107.      DO
  108.        IF keyhit = "x" | keyhit = "X" THEN
  109.          DO
  110.             CALL PIODropFuncs
  111.             SAY 'RXPORTIO dropped.'
  112.             EXIT
  113.          END
  114.        ELSE
  115.          SAY "Invalid Input"
  116.      END
  117.    end  /* select */
  118. end /* do */
  119.  
  120. EXIT
  121.  
  122.