home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / DECODEBA.ZIP / DECODE88.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1980-01-01  |  2.1 KB  |  63 lines

  1. --------------------------------------------------------------------------
  2.                        F i l e    I n f o r m a t i o n
  3.  
  4. * DESCRIPTION
  5. DECODE88.PAS will not work with TURBO-87 or TURBOCD.
  6. Requires: Turbo Pascal 2.0, 3.0. Author: Rick Solomon. Version T1.0
  7.  
  8. * ASSOCIATED FILES
  9. DECODE.PAS
  10. DECODE88.PAS
  11. DECODE.TXT
  12. ==========================================================================
  13. }
  14. {.PL65}
  15. {The following function (DECODE) converts REAL numbers stored
  16.  by a BASIC program in a random access file (i.e. in ASCII
  17.  format) and read by a Pascal program into a number which
  18.  can be used by Pascal. BASIC stores a REAL (single precision)
  19.  number as a four byte vector starting with the least
  20.  significant byte in the first position to the most significant
  21.  byte in third position with the exponent in fourth. TURBO
  22.  Pascal uses a six byte format starting with the exponent in
  23.  position 0 then least to most significant bytes in positions
  24.  one through five respectively.
  25.  
  26.  The function takes advantage of TURBO's absolute addressing
  27.  capabilities to declare a real number and a six byte array
  28.  in the same six bytes of memory. Since BASIC and TURBO use
  29.  similar encoding schemes, it is possible to read the four
  30.  byte BASIC format and to place the individual byte values into
  31.  the proper locations in the Pascal representation. The array
  32.  is then read as a number which Pascal can understand.
  33.  
  34.  This function WILL NOT WORK with TURBO-87 or TURBOBCD which use
  35.  eight or ten byte REALs respectively with different encoding
  36.  schemes.
  37.  
  38.  A global TYPE SHORT_VECTOR = ARRAY[1..4] OF BYTE must be
  39.  declared in the calling routine and used to pass the values
  40.  to the function.}
  41.  
  42.  
  43. FUNCTION DECODE (BASIC_REAL : SHORT_VECTOR) : REAL;
  44.  
  45. TYPE
  46.     LONG_VECTOR = ARRAY[0..5] OF BYTE;
  47.  
  48. VAR
  49.    NUMBER   :  REAL;
  50.    DECODER  :  LONG_VECTOR ABSOLUTE NUMBER;
  51.  
  52. BEGIN
  53.      DECODER[0] :=   BASIC_REAL[4];
  54.      DECODER[1] :=   0;
  55.      DECODER[2] :=   0;
  56.      DECODER[3] :=   BASIC_REAL[1];
  57.      DECODER[4] :=   BASIC_REAL[2];
  58.      DECODER[5] :=   BASIC_REAL[3];
  59.  
  60.      DECODE     :=   NUMBER;
  61.  
  62. END; {FUNCTION DECODE}
  63.