home *** CD-ROM | disk | FTP | other *** search
/ Turbo Toolbox / Turbo_Toolbox.iso / sharew / exoten / rec / rec5.hlp < prev    next >
Encoding:
Text File  |  1990-10-30  |  28.9 KB  |  682 lines

  1. Chapter 5, Part I.  Variables ($).
  2. Chapter 5, Part II.  The Compiling Operator (C).
  3. Chapter 5, Part III.  The OS Interface (_, K, k, `).
  4. :        Chapter 5.  Variables, the Compiling Operator
  5.                 and the CP/M Interface
  6.  
  7.     Variables in REC consist of an array of two-byte words (four-byte 
  8. words in MC68000 REC) which the programmer may use to store data or addresses 
  9. of data.  A single operator gives access to this array, as well as to the 
  10. array of subroutine names; we now describe this operator.
  11.  
  12.      Operator            Function performed
  13.  
  14.     $    Takes a one- or two-byte argument from the PDL, whose value 
  15.         lies between 0 and 127, and replaces it with the address 
  16.         belonging to that number in the variable and subroutine name 
  17.         table.  Values between 0 and 32 and the value 127 are used as 
  18.         variables, as they correspond to control characters in the 
  19.         ASCII alphabet and thus are not used as subroutine names; 
  20.         values from 33 to 126 correspond to the  ASCII printing 
  21.         characters, which may be used as subroutine names (except @ 
  22.         and }).
  23.  
  24.  
  25.  
  26.  
  27.     Operator $ is almost always used together with operators S and r, 
  28. which allow the program to store and retrieve data (c.f. Chapter 3), 
  29. respectively.  For instance, 'FA'25$S leaves the pair of ASCII characters FA 
  30. in the table cell corresponding to variable 25; 'm'$r leaves on the PDL, in 
  31. place of the letter m, the address at which subroutine m starts (so that 
  32. 'm'$r@@ has the same effect as 'm'@@ or @m).
  33.  
  34.     If one wants to put aside a datum whose length is other than two 
  35. bytes, the PDL may be used to hold it and a variable may contain its PDL 
  36. address.  For example, an address may be used to keep the address of a File 
  37. Control Block (FCB) created as shown in Chapter 3.  We reproduce here the 
  38. corresponding subroutines with slight modifications, together with a new 
  39. subroutine which calls the previous two subroutines and stores in variables 
  40. 30 and 31 the addresses of two blocks corresponding to the command line tail 
  41. filenames appearing at locations 005CH and 006CH.
  42.  
  43.     [creates an FCB for the file whose name starts at the given address]
  44.     (m 33 c pG n 12G &S;) M
  45.     [clears the upper 21 bytes of an FCB]
  46.     (pG 12+ 21 w 0% (f:;) w;) C
  47.     [makes FCBs for the filenames at 5C and 6C]
  48.     ('05C'H@M@C 30$S '06C'H@M@C 31$S;) F
  49.  
  50.     It can be seen that subroutine M has been generalized so that it 
  51. receives in the PDL the address from which it is to obtain the name of the 
  52. file whose FCB it makes, instead of using a fixed address; also, it no longer 
  53. types the address of the created block. Subroutine C uses the workspace 
  54. operators w and f to fill with zeros the upper 21 bytes of the FCB.  Once 
  55. subroutine F has been called, and as long as the blocks are not lifted from 
  56. the PDL, 30$r and 31$r may be used to retrieve the addresses of the FCBs and 
  57. thus have access to them, no matter how many more arguments have been piled 
  58. up on the PDL.  These subroutines may be improved so that blocks are not made 
  59. for files whose names are entirely blank; this is easily accomplished by the 
  60. tests '05D'H1G" "= and '06D'H1G" "=, since if the first character of the 
  61. filename is a blank, it is certain that the rest of the name is also blank.
  62.  
  63.     The PDL complement may also be used to store data.  In this case, the 
  64. combination ml20$s, for example, stores in variable 20 the value of pz where 
  65. the datum sent to the PDL complement by m starts.  As long as n is not used 
  66. to remove this datum, we can use, in this example, the combination 20$ryG to 
  67. put on the normal end of the PDL a copy of the stored datum without 
  68. disturbing the PDL complement's contents.
  69.  
  70.  
  71.  
  72.  
  73.     We now extend the parsing program given towards the end of Chapter 4 
  74. so that it evaluates the parsed expression, if the parse succeeds.  
  75. Evaluation will require that in all exponentiations the exponent be an 
  76. integer.  The program also establishes precedence and associativity rules for 
  77. operators, as follows:
  78.  
  79.     (a)    Expressions enclosed in parentheses are evaluated 
  80.         first.
  81.  
  82.     (b)    ** and ^ are evaluated before * and /; * and / are 
  83.         evaluated before + and -.
  84.  
  85.     (c)    ** and ^ associate from right to left; e.g., 2^3^2 is 
  86.         evaluated as 2^(3^2), whose is different from that of 
  87.         (2^3)^2
  88.  
  89.     (d)    * and / associate from left to right; e.g., 4*5/6 is 
  90.         evaluated as (4*5)/6, whose value is different to 
  91.         that of 4*(5/6)
  92.  
  93.     (e)    + and - associate from left to right.
  94.  
  95.  
  96.     The complete program is the following:
  97.  
  98.     [Algebraic notation arithmetic expression evaluator]
  99.     {("0""9"Mz;) d                [digit]
  100.      (@d:;) D                [0 o more digits]
  101.      (qL('E'Ez;'D'Ez;)(@a;;) @d@D L;Yj;) E    [power of 10 factor]
  102.      (Z< (@d@D'.'Ez; J'.'Ez@d; J@d; Jj>)
  103.          >@D@E;) q            [number]
  104.      ('+'Ez; '-'Ez;) a            [additive operator]
  105.      ('*'Ez; '/'Ez;) m            [mult. operator]
  106.      ('**'Ez; '^'Ez;) i            [exp. operator]
  107.      (@i; @m; @a;) o            [operator]
  108.      (@q; '('Ez @e ')'Ez;) p        [operand]
  109.      (Z<(@p;J@a@p;J>)>
  110.         (qL@o@pL:Y;);) e        [expression]
  111.  
  112.      (                    [final adjustment]
  113.       J('+'ED; '-'Ej'0'I;;)            [initial +, -]
  114.       J('(+'FAD:;) J('(-'FAj'0'I:;)        [other unary +, -]
  115.       J('**'FD'^'I:;)            [all ** to ^]
  116.       J 0,127$S 0m ;) A            [initialize]
  117.  
  118.  
  119.      (                    [evaluate the formula]
  120.       ('(' ED @(:                [nest down]
  121.        ')' ED @):                [nest up]
  122.        Z<@q JQDO>: >            [number to the PDL]
  123.        @i 4 @c:                [operator ^]
  124.        @m 2 @c:                [operator * o /]
  125.        @a 1 @c: ;)                [operator + o -]
  126.       (n0=; Ln @@:) ;) f            [evaluate pending]
  127.  
  128.      (127$r5+,127$S;) (            [nest down]
  129.      (127$r5-,127$S;) )            [nest up]
  130.  
  131.      (                    [compute or push]
  132.       127$r+                [add nest weight]
  133.       (pG lyG N                [compare weights]
  134.        I                     [new smaller, store]
  135.        nL                    [lift previous weight]
  136.        n @@                    [evaluate previous]
  137.        QD:                    [get weight, repeat]
  138.        ;)
  139.       5/ 5* & (4= 3;;) +            [reduce ^ weight]
  140.       BQD mm;) c
  141.  
  142.      (+;) +   (-;) -   (*;) *        [addn, subt, prod]
  143.  
  144.      (/                    [division]
  145.       p&L4N                    [integer?]
  146.       &L;                    [yes, lift residue]
  147.       ;) /                    [no, exit]
  148.  
  149.      (                    [a^b]
  150.       p4(N)                    [integer expt.?]
  151.        "Error in exponent "TLL%:        [no, reduce to int]
  152.       L                    [yes, go on]
  153.       ((p&L 2=                [exponent sign]
  154.         pG32767;LpG00&;)            [2 or more bytes?]
  155.         N;                    [positivo: exit]
  156.         ~m                    [no, check base]
  157.         (d^) "0**x, x<0" T_;        [base 0, abort]
  158.         1&@/n;)                [not 0, reciprocal]
  159.       1m                    [initial factor]
  160.       (d^)                    [expt. = 0?]
  161.        (d                    [yes; base = 0?]
  162.         ^ Ln;                [no, result=base]
  163.         "0**0"T_;);                [0**0, abandon]
  164.  
  165. [^ cont.]  (dd^^                    [expt. = 1?]
  166.        2/ &                    [no, divide]
  167.        (d                    [residue 1?]
  168.         L &pGn * m;                [yes, multiply]
  169.         &;)                    [no]
  170.        pG * &:                [square]
  171.        n*;)                    [last product]
  172.      ;) ^                    [end of subroutine ^]
  173.  
  174.      (R 13%=""; T@J|;) J            [get line]
  175.      (2573TL '> 'TL @J ""=;
  176.       JZD I @e (A) @A @f '='TL#TL: ": no" TL:)}  [main]
  177.  
  178.     This program is intended to be compiled and run with REC80F, REC86F 
  179. or REC87, the REC versions with floating point arithmetic.  It could be run 
  180. with REC80 or REC86, whose arithmetic operators recognize only (integer) 
  181. operands up to 2 bytes in length.  In any case, the division subroutine / may 
  182. give apparently strange results when its operands are two-byte integers, 
  183. since, as it was explained in Chapter 3, division of operands of this type 
  184. considers them to be unsigned quantities, so that the expression 4/(-1), to 
  185. give an example, causes the program to return 0 as the result, because the 
  186. operation carried out in effect is 4/65535.
  187.  
  188.     The operation of the program shown above is the following:  Once 
  189. subroutine e has succeeded in parsing an arithmetic expression, the main 
  190. program calls subroutine A to eliminate all unary +'s, convert all unary -'s 
  191. to binary operators by inserting zeros and change all **'s to ^'s.  When this 
  192. is done, subroutine f is called to evaluate the expression, which is done by 
  193. reading it left to right.  
  194.  
  195.     The precedence rules we stated before are implemented by assigning 
  196. weights to the operands, so that + and - have weight 1, * and / are assigned 
  197. a weight of 2, and ^ gets a weight of 4 (the larger the weight, the greater 
  198. the precedence of evaluation); variable 127 is used to keep track of how 
  199. deeply parentheses have been nested, in the form of a multiple of 5, which is 
  200. added to the weight of operators found at that parenthesis level; this 
  201. guarantees that all of the operators contained within a given parenthesis 
  202. level have higher precedence than operators at an outer level.  Associativity 
  203. is dictated by the evaluation algorithm contained in subroutine c, which 
  204. stacks operators on the PDL complement or executes them (by using predicate 
  205. @@) depending on the relation between the weight of the operator submitted to 
  206. it by subroutine b and that of the top operator on the PDL complement (which 
  207. contains 0 initially); the associativity rule for ^ demands that its weight 
  208. be reduced when a comparison requires this operator to become stacked.
  209.  
  210. :         Ch. 5, Part II.  The Compiling Operator.
  211.  
  212.     Before going on to describe the compiling operator C, it is 
  213. convenient to mention some features of the compiling area.  This area has 
  214. associated with it three pointers: c0, c1 and c2, which point to the physical 
  215. lower bound, the next available address and the physical upper bound of the 
  216. compiling area, respectively.  Once REC has compiled a program (as a result 
  217. of its own execution, not that of operator C), the value of c1 is preserved 
  218. throughout the execution of the compiled program, which occupies memory 
  219. bracketed by c0 and c1; c1 is stored during execution of C and is restored 
  220. once C has performed its function.  We proceed now to the description.
  221.  
  222.      Operator            Function performed
  223.  
  224.     C    Compiles a REC program, consulting the PDL for data on the 
  225.         program's source and the address at which the compiled 
  226.         program is to reside; besides leaving the compiled program at 
  227.         the desired location, C leaves two addresses on the PDL, the 
  228.         starting address of the object (as top argument) and the 
  229.         address following the object's last one (usually the next 
  230.         available address in the compiling area) as the PDL's lower 
  231.         argument.
  232.         
  233.   C (cont.)    The argument indicating tha address at which the object is to 
  234.         start must be the top one on the PDL and may have either of 
  235.         two forms: the null string or an address (in two bytes); the 
  236.         null string indicates that the program compiled by C must 
  237.         start following the program initially compiled by REC and an 
  238.         address indicates the actual address where the compiled 
  239.         program is to begin.  In general, the address provided in the 
  240.         latter alternative should be one of those returned by a 
  241.         previous use of C.  The lower argument, which indicates the 
  242.         source of the REC program, may have one of three forms:  the 
  243.         null string, indicating the source is the console keyboard, a 
  244.         one-byte argument indicating the source is a disk file 
  245.         residing in the disk unit designated by that byte, or a 
  246.         two-byte argument representing a length and indicating that 
  247.         the source program is in memory.  The last two options imply 
  248.         that still one more argument must be on the PDL with one 
  249.         exception noted below; in the first case it should be a 
  250.         string of up to 11 characters giving the name and extension 
  251.         of the disk file (the extension is assumed to be REC if not 
  252.         included explicitly); in the second case the additional 
  253.         argument is the starting address of the source program and 
  254.         must be a two-byte argument (four bytes are also allowed in 
  255.         the 8086 version).
  256.   C (concl.)    The exception occurs when a two-byte argument representing a 
  257.         length is zero, in which case no more arguments are sought 
  258.         and, instead of compiling, C leaves on the PDL an address c1' 
  259.         and a length c2-c1', where c1' is the address determined by 
  260.         the destination argument given to C.  In the 8086 version c1' 
  261.         is four bytes long; the upper word contains the value of the 
  262.         code segment base.
  263.  
  264.     If C is given an address lower than c1 for the object program's 
  265. start, the compiled program will be written over the original program, the 
  266. most likely result being a processor "hang", i.e., that the computer ceases 
  267. to respond.  Because of this, some care should be exercised in choosing the 
  268. argument indicating the address and should normally be the null string 
  269. (implyimg the use of the fixed value of c1) or one of the addresses left by C 
  270. on the PDL. 
  271.  
  272.     When REC or the operator C compile a program whose last address 
  273. exceeds c2, the error message "Cp ovfl" is issued to the console, program 
  274. execution is abandoned and control returns immediately to CP/M.
  275.  
  276.  
  277.  
  278.  
  279. Some examples of program fragments invoking C:
  280.  
  281.     """"C        Reads a REC program from the keyboard; the 
  282.             compiled program starts at c1, the value of 
  283.             c1 is left as top argument and the address 
  284.             of the next available byte in the compiling 
  285.             area is left as lower PDL argument. 
  286.  
  287.     "ABC""B"""C    Compiles the program contained in file 
  288.             B:ABC.REC; the compiled program starts at c1 
  289.             and the PDL is left with arguments as 
  290.             described in the previous example.
  291.  
  292.     "FILENAMEEXT"
  293.     "@"""C        Searches the currently logged disk for the 
  294.             file FILENAME.EXT, to compile the REC program 
  295.             it contains.  The result on the PDL is the 
  296.             same as above.
  297.  
  298.     q""C        In this case, C is being directed to find the 
  299.             source program between pointers p1 and p2 in 
  300.             the workspace. 
  301.  
  302.     p""C        Analogous to the last example, but the source 
  303.             is now on the PDL (and must be the argument 
  304.             to which p is applied in this example).
  305.  
  306.     0""C        Replaces its arguments on the PDL with the
  307.             values of c1 (as the lower argument) and
  308.             c2-c1 (as the top).
  309.  
  310.     Operator C causes an error message "Rd ovfl" to be issued and 
  311. execution to be terminated if the program being compiled contains syntax 
  312. errors, which may be due to insufficient right parentheses or braces, lack of 
  313. a main program in a subroutine group enclosed in braces or unbalanced 
  314. quotation marks.  All of these circumstances cause an attempt to continue the 
  315. compilation beyond the end of the file or memory area containing the source 
  316. program, this is why they are grouped under the generic message "Rd ovfl".
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.     C can be used in combination with operator $ to compile programs 
  326. contained in separate files, which can then be called as subroutines.  For 
  327. instance, 
  328.  
  329.     ('SUB1'"A"""C '1'$S m 'SUB2'"A" nC '2'$S 0$S;)
  330.  
  331. compiles the programs contained in files A:SUB1.REC and A:SUB2.REC.  The 
  332. starting address (c1) of the first one is saved under subroutine name "1" 
  333. ['1'$S] and may be called by @1; the second program's starting address (which 
  334. is the first following the first subroutine; note the use of m and n) is 
  335. stored in the subroutine name table under the name "2", its execution is 
  336. accomplished by the predicate @2.  Finally, the address of the next available 
  337. byte in the compilation area is saved in variable 0 [0$S], foreseeing the 
  338. possibility of compiling still another program without destroying subroutines 
  339. 1 and 2. A use of C which allows executing programs whose length exceed the 
  340. size of the compilation area is that of overlay construction.  Consider the 
  341. example in the following panel:
  342.  
  343.  
  344.  
  345.  
  346.  
  347.  
  348.     {[compiles and executes the program whose source and
  349.       destination are on the PDL]
  350.      (C &0$S @@;) X
  351.  
  352.      [main program: alternates executions of B:PROG1.REC 
  353.       and B:PROG2.REC, until either of them becomes false]
  354.      ("PROG1" 'B' ""@X "PROG2" 'B' ""@X:;)}
  355.  
  356. Subroutine X compiles the program whose source is indicated by the 
  357. argument(s) it receives on the PDL, places the object in memory starting at 
  358. c1 (when the top argument is the null string), stores the final address in 
  359. variable 0 [&0$S] and executes the compiled program [@@]; the main program 
  360. calls @X alternating executions of PROG1 and PROG2; the compilation of each 
  361. of these programs overwrites the previous one's object program; PROG1 and 
  362. PROG2 can communicate data through the PDL or the workspace.  Notice that 
  363. PROG1 and PROG2 may in turn contain calls to X of the form 
  364. "PROG3"'A'0$rpGm@Xn0$S, where the initial address for the object is now given 
  365. by variable 0 and is the next available address in the compilation area, 
  366. relative to the program containing the predicate @X, and the PDL complement 
  367. is used to stack a copy of the current value of variable 0 (since it will be 
  368. changed by subroutine X); this way overlay trees may be built.
  369.  
  370. :        Ch. 5, Part III. The OS Interface.
  371.  
  372.     We end this chapter with a discussion of the operators which provide 
  373. the user with an interface to the operating system:
  374.  
  375.      Operator            Function performed
  376.  
  377.     _    (Underscore.)  Returns immediately to the OS.
  378.  
  379.     K    Calls the operating system to execute the function whose 
  380.         number is given by the top PDL argument (which should be two 
  381.         bytes long) with the lower argument copied to register DE (DX 
  382.         on the 8086).  The lower argument remains on the PDL after K 
  383.         is executed, and the top argument is replaced by the 
  384.         resulting value of register A (AL on the 8086) extended to a 
  385.         two-byte value by adjoining a zero upper byte; this value 
  386.         usually indicates success or failure in the execution of the 
  387.         BDOS function requested.
  388.  
  389.     k    Identical to K, but lifts both arguments and leaves no A value
  390.         behind; it is mainly used to request functions for which it is
  391.         not necessary to check the value of A returned by the BDOS.
  392.  
  393.     `    Predicate.  It is true if there is a character waiting to be 
  394.         read from the console keyboard, false otherwise.  If true, 
  395.         the character may be read by operator R.
  396.  
  397.     A warning on predicate `.  In MS-DOS, ctrl-S will suspend the 
  398. execution of the program and ctrl-C will terminate it if either is the next 
  399. character waiting to be read from the keyboard at the time ` is executed. An 
  400. R following ` will NOT read either ctrl-S nor ctrl-C, because these are 
  401. intercepted in the BIOS.  Thus a subroutine to check the keyboard status and 
  402. suspend or terminate would take the following forms, for CP/M and MS-DOS, 
  403. respectively:
  404.  
  405.     [keyboard check, CP/M]    ((`);R3%=_;19%=RL;L;) K
  406.  
  407.     [keyboard check, MS-DOS]  (`;;) K
  408.  
  409.     3 and 19 are the ASCII codes for ctrl-C and ctrl-S, respectively;
  410. % is used to restrict the values to one byte.  After ctrl-S suspends program
  411. execution, typing any character will resume it.
  412.  
  413.  
  414.  
  415.  
  416.     When the 8086 processor is used, the lower argument of K or k may be 
  417. four bytes long, representing an address and a memory segment base; in this 
  418. case the DS register value is saved, the segment base portion of the argument 
  419. is transferred to DS, the function is executed and the previous value of DS 
  420. is restored.  If the function requested is function number 26 (set DMA 
  421. address), CP/M is called first to perform function 51 (set DMA segment base) 
  422. with the segment base indicated by the lower argument (the data segment if 
  423. this argument is two bytes long, the explicit base given if the length is 
  424. four) and then the call to CP/M for function 26 is carried out.
  425.  
  426.     Not all CP/M functions require a value in DE (or DX); for those 
  427. functions not needing it the PDL must still contain the corresponding 
  428. two-byte argument in its place, 0 is recommended. 
  429.  
  430.     The use of operators K and k requires a thorough knowledge of the 
  431. operation of CP/M function calls (for example, CP/M must be requested to open 
  432. a file before reading from it, or to close a file used for writing in order 
  433. to update the disk's directory and hence be able to access the data later, 
  434. etc.), however, the discussion of all possible variants is beyond the scope 
  435. of these notes, so we refer the reader to the bibliography given at the end.  
  436. We limit ourselves here to giving a list of possible functions and 
  437. illustrating the use of the more important ones.
  438.  
  439.     In the following table, applicable to CP/M, "Num" is the value which 
  440. the top argument must have, "DE" is the kind of datum the lower argument 
  441. should be and "Value" is the value K returns as top argument.  A dash in 
  442. column "DE" indicates that the argument is not used (although both K and k 
  443. require something in its place, usually a zero) and a dash in the "Value" 
  444. column indicates that no specific value is returned in A (or AL) and hence 
  445. the value left by K has no significance.
  446.  
  447.     As regards the abbreviations used in the table, "char" represents a 
  448. character (to be written, if under "DE"; read if under "Value"), "FCB" 
  449. represents the address of a file control block which can be created as shown 
  450. in Chapter 3 or at the beginning of this chapter, "stat" indicates the datum 
  451. contains a byte with the status referred to by the corresponding function, 
  452. "buf" is the address of a buffer to be used for data transfer, "DMA" is the 
  453. address of a 128-byte buffer to be used in operations to be subsequently 
  454. performed on disk files, "id" is a disk identifier (0 for disk A, 1 for disk 
  455. B, etc.) and "ind" means the returned value indicates the success or failure 
  456. of the function.  The number 80 or 86 next to the function number means that 
  457. line is applicable to the version of CP/M for the 8080 or 8086, respectively.
  458.  
  459.  
  460.  
  461.  
  462. ==========================CP/M BDOS functions========================
  463.  Num            Function         DE           Value
  464. =====================================================================
  465.   0        System reset             -         -
  466.   1        Read from console         -        char
  467.   2        Write to console        char         -
  468.   3        Read from reader         -        char
  469.   4        Write to punch            char         -
  470.   5        Write to printer        char         -
  471.   6 (80)    Read direct from console    255         char or 0
  472.   6 (80)    Write direct to console        char         -
  473.   6 (86)    Read direct from console    255        char
  474.   6 (86)    Read console status        254        stat
  475.   6 (86)    Write direct to console        char         -
  476.   7        Read I/O byte             -        stat
  477.   8        Write I/O byte            stat         -
  478.   9        Write string to console        buf         -
  479.  10        Read string from console    buf         -
  480.  11        Read console status         -        stat
  481.  12        Read version number         -        ind
  482.  13        Reset disk system         -         -
  483.  14        Select disk            id         -
  484.  15        Open file            FCB        ind
  485.  16        Close file            FCB        ind
  486.  17        Search for first instance    FCB        ind
  487.  18        Search for next instance     -        ind
  488.  19        Delete file            FCB        ind
  489.  20        Read a sector sequentially    FCB        ind
  490.  21        Write a sector sequentially    FCB        ind
  491.  22        Make file            FCB        ind
  492.  23        Rename file            FCB        ind
  493.  24        Read logged disk vector         -        stat
  494.  25        Read logged in disk id         -        id
  495.  26        Set DMA address            DMA         -
  496.  28        Write protect disk         -         -
  497.  30        Set file attributes        FCB        ind
  498.  32        Get user code            255        ind
  499.  32        Set user code               0 to 15         -
  500.  33        Read random            FCB        ind
  501.  34        Write random            FCB        ind
  502.  35        Compute file size        FCB         -
  503.  36        Set random record        FCB         -
  504.  37 (86)    Reset selected disks        stat         -
  505.  40 (86)    Write random with zero fill    FCB        ind
  506.  50 (86)    Direct BIOS call        buf        ind
  507. =====================================================================
  508.     Communication with MS-DOS is only slightly different:  more than two 
  509. arguments may be required, depending on the function call and "n" is the 
  510. MS-DOS function number.
  511.  
  512.     Each argument contains values for one or two registers; up to four 
  513. registers may be assigned values. Since some functions require an argument in 
  514. AL, this is taken from the HIGH order byte of "n".  For most functions the 
  515. value returned ("code") is the value of AX.  Functions which will take two 
  516. arguments from the PDL are 27H, 29H, 3CH, 3EH and all others above 3EH. 
  517. Functions beyond 3EH not actually requiring the second argument will 
  518. nevertheless lift an extra argument; loading an extra 0 will do.
  519.  
  520.     If a two byte argument XX is given where two registers R1:R2 are 
  521. expected (R1 being the high order word), R1 will be assigned the value of DS 
  522. and XX will be loaded into R2. With the exception of functions 2BH and 2DH, 
  523. where arg1 is read as CX:DX, if arg1 is WW:XX and arg2 is YY:ZZ, XX will be 
  524. loaded into DX and SI, ZZ will be loaded into BX and DI, YY (or DS if YY is 
  525. absent) will be loaded into ES, and WW will be loaded into DS (unless WW is 
  526. absent, in which case DS does not change) In the list below "fcb" and 
  527. "buffer" represent the addresses of a file control block and a buffer, 
  528. respectively. 
  529.  
  530.  
  531.     Some functions return additional values besides AX. These are 
  532. indicated in the list; each PDL argument produced by K is separated by a 
  533. slash. Addr4 means a 4 byte address (seg:offset). An asterisk indicates that 
  534. an extra value -1 (on error, in which case the remaining AX value is the 
  535. error code) or an extra copy of AX (if no error) is returned.
  536.  
  537. =======================MS-DOS BDOS functions=========================
  538. num    function            "arg1"    "arg2"    "code"
  539. =====================================================================
  540. 0    program terminate        0    -    -
  541. 1    keyboard input            0    -    char
  542. 2    video output            char    -    AX
  543. 3    aux input            0    -    char
  544. 4    aux output            char    -    AX
  545. 5    printer output            char    -    AX
  546. 6    direct console I/O        DX    -    AX
  547. 7    dir console input, no echo    0    -    AX
  548. 8    console input, no echo        0    -    AX
  549. 9    print string            buffer    -    AX
  550. 10    buffered keyboard input        buffer    -    AX
  551. 11    keyboard status            0    -    stat
  552. 12    character input w/buffer flush    DX    -    AX
  553.  
  554. 13    disk reset            0    -    AX
  555. 14    select disk            disk    -    AX
  556. 15    open file            fcb    -    code
  557. 16    close file            fcb    -    code
  558. 17    search once            fcb    -    code
  559. 18    search again            fcb    -    code
  560. 19    delete file            fcb    -    code
  561. 20    sequential read            fcb    -    code
  562. 21    write one record        fcb    -    code
  563. 22    create file            fcb    -    code
  564. 23    rename file            fcb    -    code
  565. 25    current disk            0    -    disk
  566. 26    set DMA address            dma    -    AX
  567. 27    allocation table address    not implemented
  568. 33    random read            fcb    -    code
  569. 34    random write            fcb    -    code
  570. 35    file size            fcb    -    code
  571. 36    set random record field        fcb    -    AX
  572. 37    set vector            addr    -    AX
  573. 38    create new program segment    seg    -    AX
  574. 39    random block read        fcb    CX    AX
  575. 40    random block write        fcb    CX    AX
  576.  
  577. 41    parse file name            DS:SI    ES:DI    AX
  578. 42    get date            0    -    CX:DX/AX
  579. 43    set date            CX:DX    -    AX
  580. 44    get time            0    -    CX:DX/AX
  581. 45    set time            CX:DX    -    AX
  582. 46    set/reset verify flag        0    -    AX
  583. 47    get DMA address            0    -    addr4/AX
  584. 48    get DOS version No.        0    -    AX
  585. 49    terminate and stay resident    DX    -    -
  586. 51    ctrl-break check        DX    -    DX
  587. 53    get vector            0    -    addr4
  588. 54    get disk free space        disk    -  ax:cx/dx:bx/code
  589. 56    return country-dependent info    addr    -    AX/*
  590. 57    create subdirectory        addr    -    AX/*
  591. 58    remove directory entry        addr    -    AX/*
  592. 59    change current directory    addr    -    AX/*
  593. 60    create a file            addr    attrib    AX/*
  594. 61    open a file            addr    -    AX/*
  595. 62    close a file            0    handle    AX/*
  596. 63    read file/device        buffer    No:Hdl    AX/*
  597. 64    write file/device        buffer    No:Hdl    AX/*
  598. 65    delete file            addr    0    AX/*
  599.  
  600. 66    move file pointer        DX    CX:Hdl    dx:ax/ax/*
  601. 67    change file mode        addr    0    CX/AX/*
  602. 68    IOCTL                0    handle    dx/ax/*
  603. 69    duplicate a handle        0    handle    AX/*
  604. 70    force duplicate of handle    0    CX:BX    AX/*
  605. 71    get current directory        disk    buffer    AX/*
  606. 72    allocate memory            0    BX    AX/*
  607. 73    free allocated memory        0    ES:0    AX/*
  608. 74    modify allocated mem blocks    0    ES:BX    BX/AX/*
  609. 75    load or execute a program    DS:DX    ES:BX    AX/*
  610. 76    terminate a process        0    0    -
  611. 77    get return code            0    0    AX/*
  612. 78    find first            addr    attrib    AX/*
  613. 79    find next            0    0    AX/*
  614. 84    get verify state        0    0    AX/*
  615. 86    rename a file            DS:DX    ES:DI    AX/*
  616. 87    get/set file date/time        DX    CX:BX    AX/*
  617. =====================================================================
  618.  
  619.  
  620.  
  621.  
  622.  
  623.     As an example of K and k usage, assume FCBs have been created by 
  624. means of subroutines M, C and F shown earlier in this chapter.  Then, the 
  625. following subroutines can be used to open, close, make, read and write the 
  626. files described by the FCBs.
  627.  
  628.     [set DMA buffer at absolute address 128]
  629.     ('080'H 26k;) h
  630.  
  631.     [delete file if present]
  632.     (@h $r 19k;) g
  633.  
  634.     [open file or create it]
  635.     (@h $r 15K (255= 22K 255= "Directory full"T_;;) LL;) e
  636.  
  637.     [open file or report absence]
  638.     (@h $r 15K (255= ^11G T ": Not found"T_;;) LL;) f
  639.  
  640.     [open for reading file denoted by variable 30,
  641.      open for writing file denoted by variable 31]
  642.     (30@f 31@g 31@e;) G
  643.  
  644.  
  645.  
  646.     [write 128  workspace bytes to the output file [var. 31],
  647.      false if less then 128 bytes in workspace]
  648.     (Jj 26%EZD 0; 128a qL 26k 31$r
  649.         21K(0= L;
  650.             1= "Directory full"T_;
  651.                "Disk full"T_)
  652.         D'.'T;) p
  653.  
  654.     [write workspace from p0 to p1 to the output file]
  655.     (jJ < (@p '.'=: 0=: L;) Zz>;) P
  656.  
  657.     [append a sector from the input file [var. 30], 
  658.      false when there is no more data to read]
  659.     (128(e) "WS full"T_; qL 26k 30$r 20K 0=L; DLL) y
  660.  
  661.     [empty workspace to the output file, copying what is
  662.      left of the input file, and close the output file]
  663.     (@p '.'=: L@y: (@p '.': 0=; e 26%(f:;) @p L; L;)
  664.      31 $r 16k;) H
  665.  
  666.  
  667.  
  668.  
  669.     These subroutines could be a part of some program that reads from the 
  670. input file to the workspace with @y and writes the processed data to the 
  671. output file with @P; a call to subroutine H at the end would ensure that the 
  672. output file is properly closed; the one byte value 26 [26%] used by H to fill 
  673. the last sector of the output file is the ASCII character control-Z used by 
  674. CP/M to signal the end of data in an ASCII text file.
  675.  
  676.     The above examples assume a CP/M model of file handling; CONVERT.REC 
  677. and CNVLIB.REC for MS-DOS contain file-handling subroutines using the BDOS 
  678. functions allowing for files in arbitrary subdirectories.
  679.  
  680. :[REC5.HLP]
  681. [(c) G. Cisneros, 1985, 1990]
  682.