home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / jsage / zsus / z3help / t.lbr / TP2.HZP / TP2.HLP
Encoding:
Text File  |  1991-11-18  |  20.4 KB  |  445 lines

  1. ;
  2.                        Help for Turbo Pascal (v3.0)                           
  3.  
  4.   / Introduction                       C- Logical Devices   
  5.   | Basic data types                   D- Standard file I/O
  6.   | Constants                          E- Pointers
  7.   | Type conversion                    F- Including files
  8.   | Predefined variables               G- Overlays
  9.   | Operators                          H- Chain and Execute
  10. A-| Compiler directives                I- Assembly routines
  11.   | Procedures and Functions           J- Internal representation of basic
  12.   | (including forward declarations)         data types
  13.   | Identifiers and Types              K- The heap and the stacks
  14.   \ String related routines            L- Interrupt Routines in Turbo Pascal
  15.  B- Reserved Words                     M- Run-time and I/O errors
  16. :A :TP
  17. :B :TP3
  18. :C
  19.                             Logical Devices - 1/2                             
  20.  
  21.  
  22.      These Devices are used in the Read,  Readln,  Write and Writeln routines. 
  23. Unlike  standard  files,  each  of  these is defined as  EOF  if  the  current 
  24. character is a ^Z, and EOLN if the current character is a ^M or ^Z.  (Standard 
  25. files look one character ahead to determine this.)
  26.  
  27.      Buffered input editing includes the following commands:
  28. ______________________________________________________________________________
  29. <BS>,<DEL>     Remove a character from input stream
  30. <ESC>,<^X>     Remove entire line from input stream
  31. <^D>           Recall a character from last input line (fwd space)
  32. <^R>           Recall (retype) entire last input line
  33. <^M>,<Return>  Process and save entire input line
  34. <^Z>           Simulate end of file.
  35. ______________________________________________________________________________
  36.  
  37.                             Logical Devices - 2/2                             
  38.  
  39.  
  40. Name             I/O Notes
  41. ______________________________________________________________________________
  42. CON: (console)   I/O Buffered input, echo on, edit facility
  43. TRM: (terminal)     I/O Unbuffered input, echo on, no edit
  44. KBD: (keyboard)  I   Unbuffered input, echo off, no edit
  45. LST: (list)      O   Output to Aux port (printer)
  46. AUX: (auxillary) I/O Unbuffered, no echo, I/O to Main port (modem)
  47. USR: (user)      I/O User defined handler (see User written I/O drivers)
  48. ______________________________________________________________________________
  49. :D
  50.                             Standard File I/O - 1/4                           
  51.  
  52.      For input and output to logical devices, see Logical Devices, (QQV).
  53.      IOResult  reports  the result of all file transactions.  If IOresult =  0 
  54. then  no error was generated,  otherwize,  the value will indicate the  error. 
  55. IOresult can only be read once, then it is reset.
  56.  
  57. Predefined files:
  58.      Assign, Reset, Rewrite, Close are illegal on these files.
  59. The  variable BufLen,  may be assigned a value to limit the maximum input line 
  60. length.
  61. Name      device    Notes
  62. Input     CON:      (TRM: if option B- is used; acts like standard pascal)
  63. Output    CON:      (TRM: as with Input)
  64. Con       CON:      (see Logical Devices)
  65. Trm       TRM:           "
  66. Kbd       KBD:           "
  67. Lst       LST:           "    
  68. Aux       AUX:           "
  69. Usr       USR:           "
  70.                             Standard FIle I/O - 2/4                           
  71.  
  72. User opened files:
  73.  
  74. Typed files: (files of type something eg:)
  75. VAR
  76.      Fil: File of User_Defined_Array_of_Bannanas;
  77. Seek(Filvar,n)
  78.      Find the Nth block of data in a non text file.
  79. Flush(Filvar)
  80.      Empty  the  file buffer associated with Filvar.  Force next  read  to  be 
  81.      physical.  Filvar cannot be a TEXT
  82. FilePos(Filvar)
  83.      Function  returns  current  position  of the file pointer  for  the  file 
  84.      Filvar.  Filvar cannot be a TEXT
  85. FileSize(Filvar)
  86.      Returns  the  number of records in the file Filvar.  Filvar cannot  be  a 
  87.      TEXT.
  88. Assign(Filvar,Name)
  89.      Assign should never be used with files which are already in  use.  Filvar 
  90.      is associated with a disk file of name Name.
  91.                             Standard File I/O - 3/4                           
  92.  
  93. Untyped Files: (files of type nothing) 
  94.      These  are  low level files which can only be communicated with  via  128 
  95. byte  records.  Untyped files are simply delared with the reserved  word  file 
  96. eg:
  97. VAR
  98.      Fil : FILE;
  99.      Read,  Write  and  Flush  are not allowed with  untyped  files.  Instead, 
  100. Blockread and BlockWrite are provided:
  101.  
  102. BlockRead(Filvar, Var, Recs {, Result})
  103.      Read  Recs  records  from file Filvar into the buffer  provided  by  Var. 
  104. Result  will  contain the number of records which were  actually  successfully 
  105. transferred.  This  is  the  only way to read non ascii files which  were  not 
  106. created under Turbo Pascal protocol.
  107. BlockWrite(Filvar, Var, Recs {,Result})
  108.      Similar  in  all  respects  except  direction  of  information  flow   to 
  109. BlockRead.
  110.      FilePos,  EOF, FileSize, and Seek all work as per normal, with the record 
  111. size set to 128 bytes.
  112.                             Standard File I/O - 4/4                           
  113.  
  114.  
  115. User written I/O drivers:
  116.      Rewrite  an  input/output driver by assigning one of the pointers  listed 
  117. below to the address of a newly created routine. (see Addr function)
  118.  
  119. Function        BDOS call Pointer    Use
  120. ______________________________________________________________________________
  121. ConSt:boolean   11        ConStPtr   Console status (Keypressed)
  122. ConIn:char      8         ConInPtr   Get console character (CON:,TRM:,KBD:)
  123. ConOut(c:Char)  2         ConOutPtr  Output char to console (CON:,TRM:)
  124. LstOut(c:Char)  5         LstOutPtr  Output char to printer (LST:)
  125. AuxOut(c:Char)  4         AuxOutPtr  Output to modem (AUX:)
  126. AuxIn:char      3         AuxInPtr   Input from modem (AUX:)
  127. UsrOut(c:Char)  2         UsrOutPtr  Same as ConOut unless redefined (USR:)
  128. UsrIn:char      8         UsrInPtr   Same as ConIn unless redefined (USR:)
  129. ______________________________________________________________________________
  130. :E
  131.                                  Pointers                                     
  132.  
  133.      No range checking is ever done on Pointers.  The routines which are
  134. designed  to work together on the Heap,  are:  New & Dispose,  Mark & Release, 
  135. GetMem & FreeMem
  136.      New and Dispose are used with any except variant records
  137.      Mark and Release are primitive, and deallocate the entire heap below
  138. a certain point.
  139.      GetMem  and  FreeMem  are arbitrary versions of  New  and  Dispose.  They 
  140. require  that  the programmer give the size of the chunk to  be  allocated  or 
  141. deallocated from the Heap.  This is neccessary for variant records since Turbo 
  142. will  otherwize  be  unable to determine the correct amount of heap  space  to 
  143. allocate.
  144. :F
  145.                               Including Files                                 
  146.  
  147.  
  148.      Use the $I compiler directive to include files.  Include files may not be 
  149. nested, however; the directive does permit the easy use of libraries.
  150.      Include  files can have their own VAR,  TYPE and other  segments  without 
  151. disturbing  the structure of the main turbo program.   In Turbo Pascal,  it is 
  152. possible to duplicate these segments as many times,  and in any order that the 
  153. programmer finds pleasing.  This is very different from the Pascal standard.
  154. :G
  155.                                  Overlays                                     
  156.  
  157.      Overlays  are defined  automatically  by  grouping  all of the procedures
  158. to  be  in  a  single overlay segment in a group  surrounded  by  non  overlay 
  159. routines and identifying them as overlay routines with the word OVERLAY.  
  160. EG:
  161.      program yaya;
  162.      overlay procedure o1; begin; end;
  163.      overlay procedure o2; begin; end;
  164.      procedure always_in_mem;
  165.      begin; end;
  166.      overlay function of1; begin; end;
  167. Puts  o1 and o2 into the same memory segment.  Only one can be in memory at  a 
  168. time.  Memory  is allocated by the length of the longest of the routines in an 
  169. overlay segment.  "of1" is in an entirely different segment.  Overlays in  the 
  170. same segment must not call one another.
  171.      Overlays  cannot  be forward declared,  or  recursive,  however,  calling 
  172. procedures may be either forward, or recursive or both. 
  173.      Run-time  errors in overlays may be very difficult  to  identify.  Always 
  174. debug overlays thoroughly before making them into overlays.
  175.      Overlays may themselves contain overlays, ad-infinitum. The overlay drive 
  176. default may be changed via the procedure OvrDrive. 
  177. :H
  178.                               Chain and Execute                               
  179.  
  180.   
  181.      Chain  and Execute,  like overlays,  change the area of control to a  new 
  182. process.  These  however,  are at the mercy of the new program,  and may  well 
  183. never return. All of the old program may well be over-written. Both are called 
  184. with an Assign'ed file variable.
  185. Chain(FilVar)
  186.      Chain transfers control to a special .CHN file compiled from turbo. These 
  187. files  do  not  need to load in the entire Turbo library and therefor  can  be 
  188. faster  and  smaller  than a call to execute.  Both the  chained  and  calling 
  189. program must use the same start address!
  190. Execute(FilVar)
  191.      Like Chain,  control is moved to a new program.  Unlike Chain, the Pascal 
  192. Library is trashed.
  193.      The only possible return is via an I/O error, if the file is not found.
  194. :I
  195.                             Assembly Routines - 1/4                           
  196.  
  197.      Two methods are available for avoiding using compiled Pascal code.  These 
  198. options are the "inline" command, and the "external" definition.
  199.  
  200.      External references:
  201.      Use  the reserved word external to declare a routine which will be loaded 
  202. into memory at compile time from an executable file and inserted in the  code. 
  203. The syntax is:
  204.                 Function Yaya:Integer; external $EC00;
  205.  
  206.      The  argument  following the external statement is the memory address  of 
  207. the  external  code.  Parameters for external subprograms must be  dealt  with 
  208. carefully by the program.
  209.  
  210.      All parameters are transferred via the Z-80 stack.  The top of the  stack 
  211. contains the return address (1 word), followed by the data to be passed.
  212. Var Parameters: The address of the variable is pushed (1 word)
  213. Value Parameters: Data transferred depends on the data type as per below:
  214. Scalars:  Integers,  Booleans, Chars and declared types are transferred to the 
  215. stack as a word. Bytes are stored with the MSB zeroed.
  216.                             Assembly Routines - 2/4                           
  217.  
  218. Reals:     Six  bytes of data are pushed for a real.  Typically they should be 
  219. removed  with  a sequence like POP HL,  POP DE,  POP BC.  L will  contain  the 
  220. exponent,  H  the least significant byte,  E the fourth,  D the third,  C  the 
  221. second and B the MSB.
  222.  
  223. Strings:   SP will point to the string length.  Following the length will be N 
  224. bytes  which contain the actual string.  The following code will transfer  the 
  225. data on the stack to StrBuf:
  226.      LD   DE,StrBuf
  227.      LD   HL,0
  228.      LD   B,H
  229.      ADD  HL,SP
  230.      LD   C,(HL)
  231.      INC  BC
  232.      LDIR
  233.      LD   SP,HL
  234.                             Assembly Routines - 3/4                           
  235.  
  236. Sets:      A set always occupies 32 bytes on the stack.  The following routine 
  237. will transfer the set from the stack to SetBuf:
  238.      LD   DE,SetBuf
  239.      LD   HL,0
  240.      ADD  HL,SP
  241.      LD   BC,32
  242.      LDIR
  243.      LD   SP,HL
  244.      Storing the LSB of the set at the lowest address in SetBuf.
  245.  
  246. Pointers:  The word at the top of the stack will be the value of the  pointer. 
  247. NIL is represented by the value 0.
  248. Arrays  and Records:  The address of the array or record is always transferred 
  249. to the stack,  and it is the duty of the subprogram to copy the array to a new 
  250. location if it is a VAR parameter.
  251.                             Assembly Routines - 4/4                           
  252.  
  253. Function results: should be returned as follows
  254.      Scalars: return their value in HL
  255.      Reals: return their value in BC, DE, and HL (as per POP)
  256.      Strings: return pushed into the stack (as per POP)
  257.      Pointer: return in the HL pair
  258. *** For more information see Internal Representation of Data Types ***
  259. Inline:   Inline code should be relocatable. However, an operator is available 
  260. for  writing  fixed code based on the current PC.  The operator  is  "*".  "*" 
  261. procedure   identifiers,   function  identifiers,   variable  identifiers  and 
  262. constants  can  be  added or subtracted.   Identifiers are all  addresses  (or 
  263. offsets) of the identifier in question. "*" is the address of the next byte of 
  264. code to be generated.  Bytes are only created and stored if they are  composed 
  265. entirely  of constants and results in a value in 0..255.  Otherwize a word  is 
  266. stored  in  normal  byte  reversed order.  Byte selection  can  be  forced  by 
  267. surrounding the expression in angle brackets.   Expressions are separated with 
  268. slashes. Eg:
  269.                inline(<$4321/>23/*+2/count+99);
  270.  
  271. Severe errors may result if SP is changed and not restored in the routine.
  272. :J
  273.               Internal Representation of Basic Data Types - 1/5               
  274.  
  275. Scalars: 
  276.      One byte iff ;
  277.           Integer subrange within 0..255
  278.           Char
  279.           Booleans
  280.           User Defined Types with fewer than 256 members
  281.      Two bytes iff (2's complement LSB first);
  282.           Integer
  283.           Integer subrange outside 0..255;
  284.           User Defined Types with more than 256 members
  285. Reals:
  286.      6 bytes;
  287.           Exponent (binary offset $80; 0 => REAL IS ZERO)
  288.           LSB
  289.           ...
  290.           MSB mantissa (normalized, radix 2, unsigned, MSBit represents 
  291.                     sign, actual MSBit is always 1 (ie normalized))
  292.               Internal Representation of Basic Data Types - 2/5               
  293.  
  294. Strings:
  295.      Max+1 bytes;
  296.           Current Length
  297.           First used char
  298.           ...
  299.           Last used char
  300.           ... (unused)
  301. Sets:
  302.      (Max div 8) - (Min div 8) +1 bytes (Max, Min= upper and lower bounds of 
  303.      base type of set);
  304.           Addr_of_byte_of_E = @+(E div 8)-(Min div 8)
  305.           Addr_of_bit_of_E = E mod 8
  306.               Internal Representation of Basic Data Types - 3/5               
  307.  
  308. File interface Blocks:
  309.      176 Bytes;
  310.      @        Flags (
  311.                  Bit 0..3 : file type 0:disk; 1:Con; 2:Kbd; 3:Lst; 4:Aux; 5:Usr)
  312.                  Bit 4 : read semaphore (set if buffer undefined)
  313.                  Bit 5 : write semaphore (set if data is in data buffer)
  314.                  Bit 6 : Output flag (output allowed)
  315.                  Bit 7 : Input flag (input allowed)
  316.                  )
  317.      @+1      Character buffer
  318.      @+2      Sector buffer pointer LSB; MSB
  319.      @+4      Number of records LSB; MSB
  320.      @+6      Record length LSB;MSB
  321.      @+8      Current record LSB;MSB
  322.      @+10     Unused
  323.               Unused
  324.      @+12     CP/M FCB byte 1
  325.               ...
  326.      @+47     Last CP/M FCB byte
  327.               Internal Representation of Basic Data Types - 4/5               
  328.  
  329.      @+48     First sector buffer byte
  330.               ...
  331.      @+175    Last sector buffer byte
  332.  
  333. Pointers:
  334.      2 bytes (unsigned);
  335.      @       LSB
  336.      @+1     MSB
  337. Arrays:
  338.      eg:
  339.      Table: array [1..10,1..10] of type;
  340.           @                   Board[1,1]
  341.           @+sizeof(type)      Board[1,2]
  342.                ...
  343.           @+9*sizeof(type)    Board[1,8]
  344.           @+10*sizeof(type)   Board[2,1]
  345.                ...
  346.           @+99*sizeof(type)   Board[10,10]
  347.               Internal Representation of Basic Data Types - 5/5               
  348.  
  349. Records:
  350.      Memory is allocated field by field, starting at the lowest address.
  351.      Variants occupy the length of the longest variant. Each variant starts at 
  352. the same address.
  353.  
  354. Disk Files:
  355.      Random access files:
  356.           Sec 0 Byte 0: No of records (LSB)
  357.           Sec 0 Byte 1:               (MSB)
  358.           Sec 0 Byte 2: Record length (LSB)
  359.           Sec 0 Byte 3:               (MSB)
  360.           Sec 0 Byte 4: First byte of data
  361.           ...
  362.      Text files:
  363.           Lines of characters delimited by ^Z or ^M^J sequences.
  364. :K
  365.                            The Heap and the Stacks                            
  366.  
  367.      The  Heap  is used to store dynamic variables and is controlled  by  New, 
  368. Mark and Release. Initially, the Heap is set to the first free byte of memory.
  369.      The  recursion stack is only used by recursive routines {$A-}.  Typically 
  370. it is located at $400 below the CPU stack pointer (1k). Upon a recursive call, 
  371. the  process copies its workspace onto the Recursion  stack.  On  exiting,  it 
  372. releases  the allocated memory.  Because of the method,  variables local to  a 
  373. subprogram must never be used as VAR parameters in a recursive call.  (Ie: all 
  374. parameters in a recursive call must be global)
  375.      The  CPU stack is used to store intermediate results during evaluation of 
  376. expressions and to transfer parameters to procedures and functions.  An active 
  377. for  statement  also uses the stack and occupies one word.  The CPU  stack  is 
  378. normally set to the top of free memory.
  379.      The  values  of  each  may be  controlled  with  the  variables  HeapPtr, 
  380. RecurPtr, and StackPtr.  It is neccessary that HeapPtr < RecurPtr < StackPtr.
  381.      A  runtime  error  will  be produced if the  Heap  and  Recursion  Stacks 
  382. overlap. The CPU stack is not checked for overflow, but is relatively unlikely 
  383. since  there  would need to be in excess of 300 active calls on the  stack  to 
  384. cause such problems.   In any event, the Recursion pointer can be relocated if 
  385. such dangers become emminent.
  386. :L
  387.                        Interrupt Routines in Turbo Pascal                     
  388.  
  389.      All  registers  should  be  saved by the routine.  PUSH and  POP  can  be 
  390. performed  at the beginning and end of the routine through inline  statements. 
  391. Also  the routine should end with EI (enable further interrupts).  It  may  be 
  392. neccessary if interrupts are daisy chained, to use an RETI instruction (inline 
  393. again) rather than the normal RET statment created by the compiler.
  394.      General rules of registers are that Integer ops only use AF,  BC,  DE and 
  395. HL.  Others  may use IX and IY,  and real ops will use the alternate  register 
  396. pairs.
  397.      Standard  I/O procedures must not be called since they are not reentrant. 
  398. All interrupt routines must be compiled with the $A option active {$A+}.  Many 
  399. BDOS and occasionally BIOS calls may be non-reentrant as well.
  400.      All interrupt proccessing is the responsibility of the programmer.
  401. :M
  402.                           Run-Time and I/O Errors - 1/3                       
  403.  
  404. Runtime:
  405.  
  406.      01   Floating overflow
  407.      02   Division by zero
  408.      03   Sqrt argument negative
  409.      04   Ln argument negative or zero
  410.      10   String length error
  411.           1.   Concat results in more than 255 character string
  412.           2.   Only strings of length 1 can be converted to char
  413.      11   Invalid string index (param of Copy, Delete, Insert not in [1..255]
  414.      90   Index out of range of array
  415.      91   Scalar or subrange out of range
  416.      92   Out of integer range (trunc, round not in [-32768,32767]
  417.      F0   Overlay file not found
  418.      FF   Heap/Stack collision
  419.                           Run-Time and I/O Errors - 2/3                       
  420.  
  421. I/O errors:
  422.      01   File does not exist
  423.      02   File not open for input
  424.      03   File not open for output
  425.      04   File not open (BlockRead, BlockWrite)
  426.      10   Error in numeric format (non convertible number)
  427.      20   Operation not allowed on a logical device
  428.      21   Not allowed in direct mode (Chain, Execute not allowed when run from 
  429.           memory)
  430.      22   Assign to std files not allowed
  431.      90   Record length mismatch
  432.      91   Seek past end-of-file
  433.      99   Unexpected end-of-file
  434.           1.   Physical EOF found before ^Z
  435.           2.   Read beyond EOF
  436.           3    Read or BlockRead unable to read next sector
  437.                           Run-Time and I/O Errors - 3/3                       
  438.  
  439.      F0   Disk write error (disk full, can also be caused by a read, since
  440.           these flush the write buffer before continuing)
  441.      F1   Directory is full
  442.      F2   File size overflow (write beyond record 65535)
  443.      F3   Too many open files
  444.      FF   File disappeared (close attempted on non-existant file)
  445.