home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / TURBOPAS / BOOSTDOC.ZIP / BOREF1.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1985-11-17  |  42.5 KB  |  1,250 lines

  1. .R:
  2. .R:
  3. .XT:4
  4. .X:8
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.                       Boosters Users Guide
  18.                        by George F. Smith
  19.  
  20.  
  21.                       609 Candlewick Lane
  22.                        Lilburn, GA 30247
  23.                         (404) 923-6879
  24.  
  25.  
  26.                          November, 1985
  27.                           Version 1.0
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.              (C) Copyright 1985 by George F. Smith
  42.                       All Rights Reserved
  43. 
  44. .F:
  45. .F:
  46. .F:Boosters Users Guide...Page $$$...
  47.                       BOOSTERS USERS GUIDE
  48.  
  49.                        Table of Contents
  50.  
  51.      Introduction 
  52.         What is Boosters? .............................  3
  53.         Speed Without Snow ............................  5
  54.  
  55.      Section 1  Getting Started
  56.         What's On the Distribution Disk ...............  6
  57.         What to Do First--BACKUP ......................  7
  58.  
  59.      Section 2  Ground Rules
  60.         Some Notes On Video ...........................  8
  61.         Heap I/O ...................................... 10
  62.  
  63.      Section 3 Descriptions of Boosters Routines ...... 12
  64.         BoDecl declares ............................... 13
  65.         BoxUL procedure ............................... 14
  66.         Calendar procedure ............................ 16
  67.         Center function ............................... 17
  68.         Copies function ............................... 18
  69.         CopyBlk procedure ............................. 19
  70.         CopyStr function .............................. 21
  71.         Cursor procedures ............................. 22
  72.         Dows function ................................. 23
  73.         Exec procedure ................................ 24
  74.         FillHeap procedure ............................ 26
  75.         FindStr procedure ............................. 27
  76.         GetStr procedure .............................. 29
  77.         Left function ................................. 30
  78.         MoveBg procedure .............................. 31
  79.         MoveBlk procedure ............................. 33
  80.         NsOrbit procedure ............................. 34
  81.         OverStr function .............................. 35
  82.         PutStr procedure .............................. 36
  83.         RemBlk procedure .............................. 37
  84.         RestoreScreen procedure ....................... 40
  85.         Right function ................................ 38
  86.         Rword function ................................ 39
  87.         SaveScreen procedure .......................... 40
  88.         SetAtt procedure .............................. 41
  89.         Space function ................................ 42
  90.         Stime procedure ............................... 45
  91.         Strip function ................................ 43
  92.         Timer function ................................ 44
  93.         TimeXY procedure .............................. 45
  94.         Upper function ................................ 47
  95.         Wait procedure ................................ 48
  96.         Word function ................................. 49
  97.         WordInd function .............................. 50
  98.         Words function ................................ 51
  99.                             INTRODUCTION
  100.  
  101.  
  102.  
  103. This book is a reference guide for Turbo Pascal (tm) programmers ì
  104. using the Boosters Utilities (C) in their work.  It provides ì
  105. formats, descriptions, and tested coding examples for each Booster 
  106. routine.  
  107.  
  108. Boosters is intended for students, software developers, hobbyists, ì
  109. or consultants who have at least a working knowledge of Turbo 
  110. Pascal and who are targeting their products for IBM PC/compatible ì
  111. systems that run under MS-DOS 2.0 or higher.  All Boosters 
  112. routines will run under Turbo Pascal version 2.0 or 3.0, except 
  113. the Exec procedure, which requires version 3.0.  
  114.  
  115.  
  116.  
  117. WHAT IS BOOSTERS?
  118.  
  119. Boosters is a family of Turbo Pascal utilities tuned for speed of 
  120. execution and ease of use.  Their evolution is as follows: 
  121.  
  122. While developing a large program with Turbo Pascal, I found it ì
  123. convenient to write some string functions that had proved ì
  124. indispensible in my work with other languages.  These are ì
  125. functions familiar to most programmers--routines to center or ì
  126. justify text, for example.  Turbo Pascal's features made it ì
  127. extremely easy to write them in source code.  As an example, the ì
  128. function Copies, which generates a string of length N of character ì
  129. C, can be expressed as: ì
  130. ì
  131.           Function COPIES ( C : Char; 
  132.                             N : LenType        (* 1..255  *)ì
  133.                                 ) : AnyString  (* string[255]  *)
  134.           var
  135.              S : AnyString;  ì
  136.              L : Integer absolute S;
  137.           beginì
  138.              L := N;ì
  139.              FillChar ( S[1], N, C );ì
  140.              Copies := Copy ( S, 1, N );ì
  141.           end; ì
  142. ì
  143. With the function thus defined, you can wring a great deal of ì
  144. work from it, such as marking the length of a user input field ì
  145. with a particular character and attribute:
  146. ì
  147.           GoToXY ( Xval, Yval );   (* Cursor at field beginning  *)ì
  148.           TextColor ( Yellow );    (* Brighten field  *)
  149.           Write ( Copies ( '_', Length(field) );  (* Mark field  *)ì
  150. The preceding example works fine, but lacks the convenience and ì
  151. speed desired when used repeatedly.  Seeking to combine the ì
  152. operations of those three procedures into one, and add a few ì
  153. enhancements, I wrote a routine called PutStr ("Put String") which 
  154. has the following declaration: ì
  155.  
  156.           Procedure PUTSTR ( D : Char;         (* Direction  *) 
  157.                              S : AnyString;    (* string[255]  *)
  158.                              X : ColumnType;   (* 1..80  *)
  159.                              Y : RowType;      (* 1..25  *)
  160.                              A : Integer ); ì
  161. ì
  162. PutStr writes string S directly to video memory beginning at ì
  163. location X,Y for length Length(S) with display attribute A.  The ì
  164. value of 'D' tells PutStr whether to proceed horizontally or
  165. vertically.
  166. ì
  167. Since S is defined as a value parameter, it allows for the direct ì
  168. placement of function calls in the PutStr procedure statement.    ì
  169.  
  170. Applying PutStr to the last example, we get:
  171.  
  172.           PutStr ( h, Copie≤ ('_', length(field), Xval, Yval, 14);ì
  173. ì
  174. Because PutStr bypasses DOS and BIOS video I/O services and goes ì
  175. directly to screen memory, PutStr is faster than the standard ì
  176. procedure Write.  ì
  177.  
  178. Copies and PutStr became part of a growing collection of routines ì
  179. that performed frequently used string and video operations.  For ì
  180. casual use, they were more than adequate in their source-level ì
  181. form.  But for large programming efforts, especially ones that ì
  182. employed time-critical operations, I felt compelled to tighten ì
  183. every routine to its limit.  Using the existing collection as ì
  184. prototypes, I began rewriting them in 8088 assembly language.  ì
  185.  
  186. The finished product--a collection of about 12 routines--was the 
  187. original Boosters.  
  188. 
  189. SPEED WITHOUT SNOW 
  190.  
  191. From long association with the winters of Buffalo, New York, I ì
  192. have concluded that snow has very limited appeal.  Unfortunately, ì
  193. on systems running with the IBM Color Graphics Adapter (tm), ì
  194. direct accesses to video memory will produce quick bursts of 
  195. "snow."  The IBM Technical Reference Manual (2.02) describes it 
  196. this way: 
  197.  
  198.         The processor and the display control unit have 
  199.         equal access to the display buffer during all the 
  200.         operating modes, except the high-resolution 
  201.         alphanumeric mode.  During this mode, the processor 
  202.         should access the display buffer during the vertical 
  203.         retrace time.  If it does not, the display will be 
  204.         affected with random patterns . . . (p 1-146) 
  205.  
  206. Programs that do direct video I/O only during vertical retrace 
  207. will indeed avoid all snow affects.  They will also avoid much of 
  208. the speed gained from using the direct I/O technique, unless the 
  209. amount of text written is slight.  When reading or writing a full 
  210. screen's worth of text, the loss of speed is painfully noticable 
  211. if programs wait for vertical retrace before performing I/O 
  212. operations.  ì
  213.  
  214. All is not grim, however.  Boosters makes it easy for Turbo 
  215. Pascal programmers to build screens on the heap, then display 
  216. them almost instantly, without snow, on a color display (or, of 
  217. course, a monochrome display).  Please see the section on Heap I/O 
  218. for details.  
  219.  
  220. The Boosters demo program, BoDemo, uses Heap I/O techniques to 
  221. move large amounts of data to and from the screen.  
  222.  
  223.  
  224. BOOSTERS PRODUCTION RELEASE
  225.  
  226. Heap I/O support is a major component of Boosters' Special-
  227. Purpose section.  Other notable members of this group include 
  228. Exec, which allows programs to call other programs as if they 
  229. were procedures, and Timer, which can add time-controlled 
  230. processing to your programs.  
  231.  
  232. The addition of the special-purpose routines to the original 
  233. string and video group make up the production release of 
  234. Boosters--43 routines in all.  
  235.  
  236. As a supplement to the technical descriptions of Section 3, 
  237. please refer to the Boosters demo program, BoDemo, and to the 
  238. individual example programs included on the distribution 
  239. diskette.  
  240.                       SECTION 1 - GETTING STARTED
  241.  
  242.  
  243.  
  244. WHAT'S ON THE DISTRIBUTION DISKETTE
  245.  
  246. The diskette you received with your Boosters order contains ì
  247. files that are classified as follows:ì
  248. ì
  249.      (A)  The complete collection of the Boosters routines, ì
  250.           contained in a file named Boosters.pas.
  251.  
  252.      (B)  The above collection split into files for each 
  253.           Booster function and procedure.  The Exec 
  254.           procedure, for example, resides on a file named
  255.           Exec.pas; the Upper function can be found on
  256.           Upper.pas--and so on.
  257. ì
  258.      (C)  A file of variable, type, and constant declarations
  259.           that Boosters needs to run--named BoDecl.pas.
  260.  
  261.      (D)  .COM files needed for the external procedures.
  262. ì
  263.      (E)  A program that demonstrates Boosters, BoDemo.pas and
  264.           BoDemo.com.  These programs perform the same exceptì
  265.           for the Exec procedure, which will only run from 
  266.           BoDemo.com under Turbo Pascal Version 3.0.  (The Exec
  267.           call is commented out in the .pas version.)
  268.  
  269.      (F)  Small programs illustrating how each Boosters routine
  270.           works.  All were tested, saved, then copied directly
  271.           to the appropriate example sections of this Users Guide
  272.           to ensure reproduction integrity.
  273.  
  274.      (G)  Source files for the Boosters assembler routines.  
  275.           Due to directory space limitations, the assembler
  276.           source files are stored in a subdirectory named
  277.           BoAsm.
  278.  
  279. There are over 115 files on the distribution diskette.
  280. 
  281.                       SECTION 1 - GETTING STARTED    
  282.  
  283.  
  284. WHAT TO DO FIRST--BACKUP
  285.  
  286. The distribution diskette is not copy-protected, so either ì
  287. DiskCopy or Copy will work fine.  Copy the original diskette and ì
  288. put it safely away.  ì
  289.  
  290. You will probably find it most convenient to keep Boosters right ì
  291. with Turbo Pascal--on the same diskette or subdirectory.  At a 
  292. minimum, copy Boosters.pas, BoDecl.pas, and the Boosters .com 
  293. files.  If there is sufficient disk space for the individual ì
  294. routines (category B above), we recommend you transfer those as 
  295. well.  ì
  296.  
  297. ì
  298.      Note: The Exec procedure requires that a copy of ì
  299.            Command.com (version 2.0 or higher) be present on ì
  300.            the default disk drive.  The Command processor ì
  301.            loads and passes control to the program you 
  302.            choose to execute.  ì
  303.  
  304. ì
  305. Having backed up your distribution diskette and copied Boosters to ì
  306. a convenient working location, fire up the demo program, ì
  307. BoDemo.com, and let it run for awhile.  Working examples are a 
  308. great benefit to understanding.  You may find it convenient to 
  309. clone parts of BoDemo.pas for your own programs.  
  310. 
  311.                        SECTION 2 - GROUND RULES
  312.  
  313.  
  314.  
  315. SOME NOTES ON VIDEO
  316.  
  317. Since Boosters addresses video memory frequently, it might be ì
  318. helpful to cover a few basics about the display area.  
  319.  
  320. 1.  Boosters video operations assumes a screen size of 80 columns ì
  321. by 25 rows (80x25).  In keeping with standard notational ì
  322. conventions, (1,1) refers to the upper left corner of the screen ì
  323. or current window, while (80,25) references the lower right.  The 
  324. variable X refers to the column, Y to the row, so that for X = 30   ì
  325. and Y = 10, for instance, we mean column 30, row 10 (30,10). 
  326.  
  327. 2.  Boosters will run with the IBM Color/Graphics Adapter, theì
  328. the IBM Monochrome Adapter, the IBM Enhanced Graphics Adapter, and
  329. on most compatibles.  It was developed on a 256K Compaq.
  330.  
  331. 3.  Each character in video memory has an attribute byte, located ì
  332. at the next higher address, that controls how the character will ì
  333. be displayed.  For the Color/Graphics Adapter and compatibles, ì
  334. this attribute byte can blink, color, or intensify the character, 
  335. and can color the character background.  
  336.  
  337. Blinking and intensity are available on the Monochrome Adapter, ì
  338. but color is interpreted as shown below:
  339.  
  340.         Attribute Byte Setting          Monochrome Shows
  341.            white-on-black                  normal
  342.            black-on-white                  reverse video
  343.            blue-on-black                   underlining
  344.            black-on-black                  nothing
  345.  
  346.  
  347. The format of the attribute byte is presented below.  A bit value ì
  348. of 1 activates a feature, while 0 turns it off.
  349.  
  350.                Bit Number
  351.                     7         Blinking foreground
  352.                     6         Red background
  353.                     5         Green background
  354.                     4         Blue background
  355.                     3         Intensity foreground
  356.                     2         Red foreground
  357.                     1         Green foreground
  358.                     0         Blue foreground
  359. 
  360. A frequently used attribute setting is 14 (hex 0E), which ì
  361. produces an intensified yellow over a black background.  Turbo ì
  362. Pascal includes a set of 16 predefined constants for designating ì
  363. colors, which you may find helpful.  See page 161 of the version ì
  364. 3.0 manual for details.  
  365.  
  366. Boosters' Set Attribute (SetAtt) procedure gives you easy control ì
  367. over the character attributes.  With SetAtt, you can set attributes ì
  368. in blocks as small as a single character or as large as the entire 
  369. screen.  
  370. 
  371.                        SECTION 2 - GROUND RULES
  372.  
  373.  
  374.  
  375. HEAP I/O
  376.  
  377. Heap I/O describes a programming technique that consists of building 
  378. or modifying screen displays on a page of the heap, then copying the 
  379. page to video memory.  For programs targeted to both monochrome and 
  380. color monitor systems, this technique provides a common approach to 
  381. fast screen output.  The steps involved are:
  382.  
  383.         STEP                            TURBO/BOOSTERS EXAMPLE
  384.                                              
  385.         1.  Mark current top            Mark ( HeapTop );
  386.   
  387.         2.  Allocate pages              For i := 1 to Npage do
  388.                                            New ( Page[i] );
  389.  
  390.         3.  Build screens               
  391.             a.  Initially               FillHeap ( page[1], ... ); 
  392.                                         BoxHeap  ( page[1], ... );
  393.                                         (*  and so on  *)
  394.  
  395.             b.  Modify existing         SaveScreen ( page[1] );
  396.                 screen                  MblkHeap   ( page[1], ... );
  397.                                         (*  perhaps more  *)
  398.  
  399.   
  400.         4.  Display any page            RestoreScreen ( page[1] );
  401.   
  402.         5.  Release heap memory         Release ( HeapTop );
  403.             when finished
  404.  
  405. Boosters has a number of routines that assist programmers in 
  406. developing sophisticated screen displays on the heap.  With one 
  407. exception, each heap routine is a clone of some other Boosters 
  408. routine.  
  409.  
  410. For example, procedure Calendar, which generates and displays a 
  411. calendar for any month and year, has a corresponding heap routine 
  412. called CalHeap.  Both routines are identical except for the address of 
  413. their output.  Calendar sends its results to video memory, while 
  414. CalHeap places its output on a specified page of the heap.  
  415. 
  416.         NOTE: All heap routines have as their first argument
  417.               the page of the heap to which output is sent. 
  418.               The remaining arguments match those of their     
  419.               corresponding video routine one-for-one.
  420.  
  421.               Thus, in the case of Calendar and CalHeap, their
  422.               statements might appear as:
  423.  
  424.               Calendar ( 11, 1985, 30, 10 );
  425.               CalHeap  ( page[1], 11, 1985, 30, 10 );
  426.  
  427. To view the results of CalHeap, of course, we must eventually copy 
  428. page[1] to video memory, an operation which RestoreScreen performs 
  429. almost instantly.
  430.  
  431. The one heap routine that has no Boosters clone is FillHeap, which is 
  432. useful for initializing a page of heap memory quickly.  FillHeap is 
  433. similar to Turbo Pascal's FillChar but differs in that it treats the 
  434. heap as having the character/attribute nature of video memory.  Please
  435. see section 3 for details on FillHeap.
  436.  
  437. The following table pairs Boosters video routines with their 
  438. corresponding heap routines.  Please remember that heap memory must 
  439. first be allocated (via New) before it can be used.
  440.  
  441.              Video              Heap            Purpose
  442.  
  443.              CopyBlk            CblkHeap        Copies a video block
  444.              MoveBlk            MblkHeap        Moves  a video block
  445.              SetAtt             HeapAt          Set block attributes
  446.              PutStr             PutHeap         Writes a string
  447.              GetStr             GetHeap         Reads a string
  448.              Calendar           CalHeap         Creates a calendar
  449.              Boxul              BoxHeap         Draws a box
  450.              FindStr            FstrHeap        Finds a string
  451. 
  452.  
  453.                                SECTION 3
  454.  
  455.                    DESCRIPTIONS OF BOOSTERS ROUTINES
  456.  
  457.  
  458.  
  459.  
  460. The examples in this section can be found on the Boosters 
  461. distribution diskette.  The file names begin with an X.  The 
  462. routine for PutStr, for instance, is named XPutStr.  
  463.  
  464.  
  465.  
  466. A SUGGESTION
  467.  
  468. If you are new to Boosters, you might find it helpful to run 
  469. the example programs as you read about them.  Make sure 
  470. BoDecl.pas and all the Boosters .pas files (PutStr.pas, 
  471. GetStr.pas, etc.) are on the default drive and directory when 
  472. you run the examples.  Because the examples are generally 
  473. simple, the routines they implement are easy to understand.  
  474.  
  475. Please pay particular attention to the uses of Heap I/O 
  476. ( XBoxUl.pas, XFillHep.pas ).  
  477. 
  478. .E
  479.                                  BODECL
  480.  
  481.  
  482. Purpose:     Declarations for Boosters Utilities.
  483.  
  484. Const
  485.    H  = 'H';                  (*  Code for horizontal PutStr & GetStr *)
  486.    V  = 'V';                  (*  "    "   vertical   "      " "      *)
  487.    StartElapsed : Boolean = FALSE;
  488.                               (*  Initial value for timer function    *)
  489.    Npage = 2;                 (*  Number of heap pages                *)
  490.  
  491. Type
  492.    AnyString   =  string[255];
  493.    HeapBuf     = ^AnyBuf;
  494.    AnyBuf      =  Record
  495.                      Screen : array[1..4000] of byte;
  496.                   end;
  497.    ColumnType  =  1..80;      (* With $R directive active, *)
  498.    RowType     =  1..25;      (* keeps video routines in line *)
  499.    result      =  Record
  500.                      AX,BX,CX,DX,BP,SI,DI,DS,ES,Flags : Integer;
  501.                   end;
  502.  
  503. Var
  504.    TimeElapsed,               (* Used by Timer . . . *)
  505.    SaveElapsed,               (* "    "  "           *)
  506.    Ecode,                     (* "    "  Exec for error return *)
  507.    I                          (* the ubiquitous index variable  *)
  508.                      : Integer;
  509.    SaveX                      (*  handy for saving WhereX result *)
  510.                      : ColumnType;
  511.    SaveY                      (*  "     "   "      WhereY "      *)
  512.                      : RowType;
  513.    Xheap             : ColumnType;
  514.    Yheap             : RowType;
  515.    HeapTop           : ^Integer;  (*  for marking current top of heap *)
  516.  
  517.    Ch                         (*  as in read(Kbd,ch) after KeyPressed *)
  518.                      : Char;
  519.    Page                       (*  screens for Heap I/O                *)
  520.                      : array[1..Npage] of HeapBuf;
  521.  
  522.    VideoStatus       : byte   absolute $0000:$0449;
  523.    MonoBuffer        : AnyBuf absolute $B000:0000;
  524.    GraphicsBuffer    : AnyBuf absolute $B800:0000;
  525.    Regs              : Result;
  526.  
  527.    S,                         (*  general string array *)
  528.    FileDesc,                  (*  File name and extension for EXEC *)
  529.    ComLine                    (*  Command Line setting for EXEC    *)
  530.                      : AnyString;
  531. .E
  532. 
  533.  
  534.                                  BOXUL
  535.  
  536.  
  537. Declaration: Procedure BoxUL ( X1 : ColumnType;
  538.                                Y1 : RowType;
  539.                                X2 : ColumnType;
  540.                                Y2 : RowType; 
  541.                                Style,
  542.                                Attribute : Integer); 
  543.  
  544. Purpose:     Draws a box (rectangle) in a given style with sides
  545.              in specified attribute.
  546.  
  547.              Notes:
  548.              1.  X1,Y1 and X2,Y2 designate the coordinates of the ì
  549.                  upper left and lower right corners, ì
  550.                  respectively, of the box to be drawn.
  551. ì
  552.              2.  Style is a value from 1 to 4 that controls   ì
  553.                  which set of box drawing characters to use.
  554.                     
  555.                  Style = 1 for single lines on all sides.
  556.                  Style = 2 for double lines on all sides.
  557.                  Style = 3 for double-lined vertical sides
  558.                            and single-lined horizontal sides.
  559.                  Style = 4 for single-lined vertical sides
  560.                            and double-lined horizontal sides.
  561.  
  562.              3.  The area enclosed by the box is not ì
  563.                  initialized.
  564.  
  565.              4.  A box must have at least 3 columns and 3 rows.
  566.  
  567.  
  568. Example:     Draw concentric boxes with Boxul then with Heap I/O.
  569.  
  570.              (*$IBoDecl   *)
  571.              (*$IPutStr   *)
  572.              (*$ICopies   *)
  573.              (*$IFillHeap *)
  574.              (*$IPutHeap  *)
  575.              (*$IRestores *)
  576.              (*$IBoxHeap  *)
  577.              (*$IBoxul    *)
  578. .E
  579.              BEGIN
  580.  
  581.                 ClrScr;
  582.                 PutStr ( h, 'USING BOXUL', 35, 12, 14 );
  583.                 for i := 0 to 8 do
  584.                    boxul ( 5 + (3*i), 2+i, 75 - (3*i), 23-i ,
  585.                            Random(4)+1, Yellow );
  586.                 ClrScr;
  587.                 Mark ( HeapTop );
  588.                 New ( Page[1] );
  589.                 FillHeap ( Page[1], 1,1,80,25,#32,14 );
  590.                 for i := 0 to 8 do
  591.                    boxHeap ( page[1], 5 + (3*i), 2+i, 75 - (3*i), 23-i ,
  592.                              Random(4)+1, Yellow );
  593.                 RestoreScreen ( page[1] );
  594.                 PutStr ( h, 'USED BOXHEAP', 35, 12, 14 );
  595.                 Release ( HeapTop );
  596.  
  597.              END (* XBoxul *) .
  598. .E
  599. 
  600.                                  CALENDAR
  601.  
  602.  
  603. Declaration: Procedure Calendar ( MM, CCYY, X, Y : Integer ); 
  604.  
  605. Purpose:     Generates a calendar for month MM of year CCYY,
  606.              then displays it with upper-left coordinates X,Y.
  607.  
  608.              Notes:
  609.              1.  The calendar size is 22 columns, 15 rows.
  610.  
  611.              2.  The calendar display includes trailing days from ì
  612.                  the previous month and the first days of the ì
  613.                  following month.
  614.  
  615.              3.  CALHEAP generates calendars on a page of the 
  616.                  heap.ì
  617.  
  618. Example:     Display the U.S.A. Bicentennial month.  
  619.  
  620.  
  621.              (*$IBodecl   *)
  622.              (*$IPutStr   *)
  623.              (*$IStrip    *)
  624.              (*$ICopies   *)
  625.              (*$IBoxul    *)
  626.              (*$IDows     *)
  627.              (*$ICenter   *)
  628.              (*$ICalendar *)
  629.  
  630.              BEGIN
  631.  
  632.                ClrScr;
  633.                Calendar ( 7, 1976, 29, 5 );
  634.  
  635.              END (* XCalenda *) .
  636. 
  637.                                   CENTER
  638.  
  639.  
  640. Declaration: Function Center ( S : AnyString; 
  641.                                N : Integer;
  642.                              Pad : Char ) : AnyString;
  643.  
  644. Purpose:     Returns a string of length N with S centered in it.
  645.              Pad is added as necessary to fill out length.
  646.  
  647.  
  648.              Notes:
  649.              1.  AnyString is Type string[255].
  650.                                                        
  651.              2.  If length(S) > N, then the first N characters ì
  652.                  are returned.
  653.  
  654. Example:     Center numbers 1 through 8 within 10-byte fields 
  655.              on first line of screen.
  656.  
  657.              (*$IBoDecl *)
  658.              (*$ICenter *)
  659.              (*$IPutStr *)
  660.  
  661.              BEGIN
  662.  
  663.                 for i := 1 to 8 do
  664.                 begin
  665.                    str ( i, S );
  666.                    PutStr ( h, Center ( S, 10, ' '),
  667.                                1 + (i-1) * 10, 1, 112 );
  668.                 end;
  669.                 read;
  670.  
  671.              END (* XCenter *) .
  672.  
  673. 
  674.                                   COPIES
  675.  
  676.  
  677. Declaration: Function Copies ( C : Char;
  678.                                N : Integer ) : AnyString;
  679.  
  680. Purpose:     Returns N concatenated copies of C.
  681.  
  682.              Notes:
  683.              1.  AnyString is Type string[255].
  684.              2.  See CopyStr for concatenating strings.
  685.  
  686. Example:     Add vertical columns to the Center example.
  687.  
  688.              (*$IBoDecl *)
  689.              (*$ICenter *)
  690.              (*$IPutStr *)
  691.              (*$ICopies *)
  692.  
  693.              BEGIN
  694.                 ClrScr;
  695.                 for i := 1 to 8 do
  696.                 begin
  697.                    str ( i, S );
  698.                    PutStr ( h, Center ( S, 10, ' '), 
  699.                             1 + (i-1) * 10, 1, 112 );
  700.  
  701.                    PutStr ( v, Copies ( #179,24),
  702.                             1 + (i-1) * 10, 2, 14 );
  703.                 end;
  704.                 read;
  705.  
  706.              END (* XCenter *) .
  707. 
  708.                                  COPYBLK
  709.  
  710.  
  711. Declaration: Procedure CopyBlk ( X1 : ColumnType;
  712.                                  Y1 : RowType;
  713.                                  X2 : ColumnType;
  714.                                  Y2 : RowType;
  715.                                  X3 : ColumnType;
  716.                                  Y3 : RowType ) ;
  717.  
  718. Purpose:     Copies block at screen location X1,Y1 (upper left)               ì
  719.              and X2,Y2 (lower right) to screen location beginning
  720.              at upper left coordinates X3,Y3.
  721.  
  722.  
  723. Example:     Create a box and copy it, first with CopyBlk, then 
  724.              with Heap I/O. 
  725.  
  726.              (*$IBoDecl   *)
  727.              (*$IPutStr   *)
  728.              (*$ICopies   *)
  729.              (*$IBoxul    *)
  730.              (*$ICopyBlk  *)
  731.              (*$ICblkHeap *)
  732.              (*$ISaves    *)
  733.              (*$IRestores *)
  734.  
  735.              BEGIN
  736.  
  737.                 Mark ( HeapTop );
  738.                 New ( page[1] );
  739.  
  740.                 ClrScr;
  741.                 Boxul   ( 1, 1, 18, 10, 1, Yellow );
  742.                 CopyBlk ( 1, 1, 18, 10, 1, 12 );
  743.                 SaveScreen ( page[1] );
  744.                 read;
  745.                 for i := 1 to 3 do
  746.                 begin
  747.                    CopyBlk ( 1, 1, 18, 10, 21+(i-1)*20, 1 );
  748.                    CopyBlk ( 1, 1, 18, 10, 21+(i-1)*20, 12 );
  749.                 end;
  750.                 read;
  751.                 ClrScr;
  752.                 read;
  753. .E
  754.                 for i := 1 to 3 do
  755.                 begin
  756.                    CblkHeap ( page[1], 1, 1, 18, 10, 21+(i-1)*20, 1 );
  757.                    CblkHeap ( page[1], 1, 1, 18, 10, 21+(i-1)*20, 12 );
  758.                 end;
  759.                 RestoreScreen ( page[1] );
  760.                 Release ( HeapTop );
  761.  
  762.              END (* XCopyBlk *) .
  763. .E
  764. 
  765.                                  COPYSTR
  766.  
  767.  
  768. Declaration: Function CopyStr ( S : AnyString;
  769.                                 N : Integer ) : AnyString;
  770.  
  771. Purpose:     Returns N concatenated copies of S.
  772.  
  773.              Notes:
  774.              1.  AnyString is Type string[255]. 
  775.              2.  See Copies for concatenating characters.
  776.  
  777. Example:     Section the screen.
  778.  
  779.              (*$IBoDecl  *)
  780.              (*$IPutStr  *)
  781.              (*$ICopies  *)
  782.              (*$ICopyStr *)
  783.  
  784.              Procedure BoCells ( y : RowType );
  785.              var
  786.                 Spacer : AnyString;
  787.                 N      : Integer;
  788.              begin
  789.                 S := Copies(#196,9)+#197;
  790.                 PutStr ( h, CopyStr ( S,8 ), 1, y, 14 );
  791.                 Spacer :=   CopyStr ( '         '+#179, 8);
  792.                 for  n := 1 to 5 do
  793.                    PutStr ( h, Spacer, 1, y+n, 14 );
  794.              end;
  795.  
  796.              BEGIN
  797.  
  798.                 ClrScr;
  799.                 BoCells ( 1 );
  800.                 BoCells ( 6 );
  801.                 BoCells ( 11 );
  802.                 BoCells ( 16 );
  803.                 BoCells ( 21 );
  804.                 Read;
  805.  
  806.              END (* XCopyStr *) .
  807. 
  808.  
  809.                              CURSOR ROUTINES
  810.  
  811.  
  812. Declaration: Procedure CursorOff;
  813.              Procedure CursorOn;
  814.                     ì
  815.  
  816. Purpose:     CursorOff hides the cursor, CursorOn makes it ì
  817.              visible.           ì
  818.  
  819. Example:     Turn the cursor off, then turn it on when user   ì
  820.              strikes the Enter key.
  821.  
  822.              (*$IBoDecl *)
  823.              (*$ICursor *)
  824.              (*$IPutStr *)
  825.              (*$ICopies *)
  826.              (*$IBoxul  *)
  827.  
  828.              BEGIN
  829.  
  830.                 ClrScr;
  831.                 CursorOff;
  832.                 Boxul (30,8,50,16,3,14);
  833.                 PutStr (h, 'Press RETURN',34,10,14);
  834.                 PutStr (h, 'to get cursor',33,12,14);
  835.                 PutStr (h, 'BACK',38,14,14);
  836.                 read;
  837.                 CursorOn;
  838.  
  839.              END (* XCursor *) .
  840.  
  841. 
  842.                                    DOWS
  843.  
  844.  
  845. Declaration: Function Dows ( MM, DD, CCYY : Integer) : AnyString;
  846.                     ì
  847.  
  848. Purpose:     Returns day of the week (Sunday, Monday, etc.) forì
  849.              any valid date.    ì
  850.  
  851.              Notes:
  852.              1.  MM and DD must be within usual ranges for month ì
  853.                  and day.  CCYY is 4-digit year (e.g., 1980, not ì
  854.                  80).
  855.  
  856. Example:     Compute day of the week for user input.  Pressing ì
  857.              return at the prompt ends session.
  858.  
  859.              (*$IBoDecl *)
  860.              (*$IDows   *)
  861.              (*$IPutStr *)
  862.              (*$IStrip  *)
  863.  
  864.              var
  865.                 mm, dd, ccyy, len : integer;
  866.  
  867.              BEGIN
  868.  
  869.                 ClrScr;
  870.                 Repeat
  871.                    PutStr (h,'Enter the numeric value for any '+
  872.                       'month, day and year',1,1,14);
  873.                    PutStr (h,'separated by spaces: ',1,2,14);
  874.                    ClrEol;
  875.                    read ( s );
  876.                    if length(s) > 0 then
  877.                    begin
  878.                       s   := strip ( S, ' ');
  879.                       len := pos(' ',S) - 1;
  880.                       val (copy (s,1,len),mm,ecode);
  881.                       s := copy (s,len+2,50);
  882.                       len := pos(' ',s) - 1 ;
  883.                       val (copy (S,1,len),dd,ecode);
  884.                       len := length(s) - pos(' ',s);
  885.                       val (copy (S,length(s)-len+1,len),ccyy,ecode);
  886.                       if ccyy < 100 then
  887.                          ccyy := ccyy + 1900;
  888.                       PutStr (h,'Day of the week is '+
  889.                                  dows(mm,dd,ccyy),1,4,14); 
  890.                    end;
  891.                 until length(s) = 0;
  892.  
  893.              END (* XDows *) .
  894. 
  895.                                    EXEC
  896.  
  897.  
  898. Declaration: Procedure Exec ( FileDescription,
  899.                               CommandLine : AnyString;
  900.                               Ecode       : Integer); 
  901.  
  902. Purpose:     Loads another program into memory and executes it,
  903.              then returns control to the invoking program.
  904.  
  905.              Notes:
  906.              1.  This is only available when issued from
  907.                  a .COM file under Turbo Pascal release 3.0.
  908.  
  909.              2.  FileDesc contains the drive, directory, file
  910.                  name and extension of the program to
  911.                  execute.
  912.  
  913.              3.  CommandLine specifies the DOS command line
  914.                  that Exec will pass to the command processor
  915.                  for execution.
  916.  
  917.              4.  Ecode = 0, execution was successful.
  918.                  Ecode = 1, improper parameters.
  919.  
  920.  
  921. Example 1:   Format a disk on the B: drive
  922.  
  923.              (*$IBoDecl *)
  924.              (*$IExec   *)
  925.  
  926.              BEGIN
  927.                 FileDesc := 'COMMAND.COM';
  928.                 ComLine  := 'COMMAND /C FORMAT B:';
  929.  
  930.                 Exec (FileDesc, CommandLine, Ecode);
  931.              END.
  932.  
  933.  
  934. Example 2:   Execute the Norton Utilities' DiskLook (C). 
  935.  
  936.              (*$IBoDecl *)
  937.              (*$IExec   *)
  938.  
  939.              BEGIN
  940.                 Filedesc := 'command.com';
  941.                 ComLine := 'command /c DL B:';
  942.  
  943.                 Exec (FileDesc, ComLine, Ecode);
  944.  
  945.                 Write(' Hello from Boosters');
  946.              END.
  947. 
  948. Example 3:   Execute Turbo Pascal (C).
  949.  
  950.              (*$IBoDecl *)
  951.              (*$IExec   *)
  952.  
  953.              BEGIN
  954.  
  955.                 Filedesc := 'B:TURBO.COM';
  956.                 Exec (FileDesc, ComLine, Ecode);
  957.                 Write(' Hello from Boosters');
  958.  
  959.              END (* XExec *) .
  960. 
  961.                               FILLHEAP
  962.  
  963.  
  964.  
  965. Declaration: Procedure FillHeap ( Page : HeapBuf;
  966.                                     X1 : ColumnType;
  967.                                     Y1 : RowType;
  968.                                     X2 : ColumnType;
  969.                                     Y2 : RowType;
  970.                                      C : Char;
  971.                                      A : Integer);
  972.  
  973. Purpose:     Generates characters C with video attribute A on Page 
  974.              of the heap, from (X1,Y1) to (X2,Y2).
  975.  
  976.              Notes:
  977.              1.  FillHeap is useful for initializing a page on the heap.
  978.  
  979. Example:     Generate and display alphabet screens A - Z.
  980.  
  981.              (*$IBoDecl   *)
  982.              (*$IRestores *)
  983.              (*$IFillHeap *)
  984.  
  985.              BEGIN
  986.  
  987.                 Mark ( HeapTop );
  988.                 New ( Page[1] );
  989.                 for i := 1 to 26 do
  990.                 begin
  991.                    FillHeap ( Page[1], 1, 1, 80, 25,
  992.                               Chr(64+i), 7 );
  993.                    RestoreScreen ( Page[1] );
  994.                    delay(150);
  995.                 end;
  996.                 Release ( HeapTop );
  997.  
  998.              END (* XFillHep *) .
  999. 
  1000.                                FINDSTR
  1001.  
  1002.  
  1003. Declaration: Procedure FindStr (  X : ColumnType;
  1004.                                   Y : RowType;
  1005.                               VAR S : AnyString;
  1006.                                   N ,
  1007.                               Ecode : Integer);  
  1008.  
  1009. Purpose:     Search for S in video memory, beginning at (X,Y).
  1010.              If S found, cursor is placed at offset N from S and 
  1011.              Ecode is set to zero.  Ecode is one when S is not 
  1012.              found.
  1013.  
  1014.              Notes:
  1015.              1.  For N > 0, offset is calculated from end of S.
  1016.                  Cursor will be positioned at length(S) + N.
  1017.                  For instance, for N = 1, the cursor will be 
  1018.                  placed at S[length(S)+1].
  1019.  
  1020.              2.  For N = 0, the cursor is placed at S[1].
  1021.  
  1022.              3.  For N < 0, offset is calculated from beginning
  1023.                  of S.  Cursor will be placed at S[1] + (-N).
  1024.                  Given N = -1, the cursor will be positioned at
  1025.                  the display coordinate immediately preceding ì
  1026.                  S[1].
  1027.  
  1028.              4.  If the value of N is such that it would place the ì
  1029.                  cursor offscreen, FindStr places the cursor at ì
  1030.                  either the beginning of the display screen or at ì
  1031.                  the end, whichever is closer to S.
  1032.  
  1033.              5.  FindStr's heap clone is FstrHeap.  
  1034.                  
  1035.                  Procedure FstrHeap ( Page : HeapBuf;
  1036.                                      VAR S : AnyString;
  1037.                                  VAR Xheap : ColumnType;
  1038.                                  VAR Yheap : RowType;
  1039.                                          N , 
  1040.                                      Ecode : Integer); 
  1041.                                      external 'FstrHeap.com';
  1042.                  
  1043.                  With FstrHeap, the search always begins at (1,1)
  1044.                  on the heap.  If S is found, Xheap and Yheap are
  1045.                  set and ecode = 0.  For S not found, ecode = 1.
  1046.                  See BoDemo.pas for uses of FstrHeap.
  1047. 
  1048. Example:     Demonstrate string find capability.
  1049.  
  1050.  
  1051.              (*$IBoDecl  *)
  1052.              (*$IFindStr *)
  1053.              (*$IGetStr  *)
  1054.              (*$IPutStr  *)
  1055.  
  1056.              BEGIN
  1057.  
  1058.                 Randomize;
  1059.                 ClrScr;
  1060.                 PutStr (v,'I AM VERTICAL',Random(80)+1,1,7);
  1061.                 FindStr (1,1,'I',0,Ecode);
  1062.                 GetStr (v,S,0,0,13);
  1063.                 read;                                          
  1064.                 insert ('NO LONGER ',S,6);
  1065.                 PutStr (h,S,1,15,14);
  1066.  
  1067.              END (* XFindStr *) . 
  1068. 
  1069.  
  1070.                                   GETSTR
  1071.  
  1072.  
  1073. Declaration: Procedure GetStr (  HV : Char;
  1074.                               VAR S : AnyString;
  1075.                                   X : ColumnType;
  1076.                                   Y : RowType;
  1077.                                 LEN : Integer);
  1078.  
  1079. Purpose:     Loads contents of video memory into S, beginning 
  1080.              at coordinates X,Y for length LEN.
  1081.  
  1082.              Notes:
  1083.              1.  Direction of read operation is set by HV, which 
  1084.                  will be horizontal when HV = 'H', vertical when 
  1085.                  HV = 'V'.  Constants H and V are set in
  1086.                  Boosters Declaration File (BoDecl). 
  1087.  
  1088.              2.  If X and Y are both zero, read operation begins 
  1089.                  at current position.
  1090.  
  1091.              3.  GETHEAP is the Heap I/O clone of GetStr.  With
  1092.                  GetHeap, X and Y cannot be zero, nor is there any
  1093.                  positioning of the cursor.
  1094.  
  1095.  
  1096. Example:     Write and read a column of vertical text.
  1097.  
  1098.              (*$IBoDecl *)
  1099.              (*$IGetStr *)
  1100.              (*$IPutStr *)
  1101.  
  1102.              BEGIN
  1103.  
  1104.                 ClrScr;
  1105.                 PutStr (v,'I AM VERTICAL',1,1,7);
  1106.                 GetStr (v,S,1,1,13);
  1107.                 read;
  1108.                 insert ('NO LONGER ',S,6);
  1109.                 PutStr (h,S,1,15,14);
  1110.  
  1111.              END (* XGetStr *) .  
  1112. 
  1113.                                LEFT
  1114.  
  1115.  
  1116. Declaration: Function Left ( S : AnyString;
  1117.                            LEN : Integer;
  1118.                            PAD : Char) : AnyString;
  1119.  
  1120.  
  1121. Purpose:     Left-justifies and pads (if necessary) S in theì
  1122.              result. ì
  1123.  
  1124.  
  1125. Example:     Create a sample input form.
  1126.  
  1127.              (*$IBoDecl *)
  1128.              (*$ILeft   *)
  1129.              (*$IPutStr *)
  1130.  
  1131.              BEGIN
  1132.  
  1133.                 ClrScr;
  1134.                 PutStr (h,left('Name ',60,'_'),5,1,14);
  1135.                 PutStr (h,left('Street ',60,'_'),5,2,14);
  1136.                 PutStr (h,left('City, State, and Zip ',60,'_'),
  1137.                         5,3,14);
  1138.                 read;
  1139.  
  1140.              END (* XLeft *) .
  1141. 
  1142.                               MOVEBG
  1143.  
  1144.  
  1145. Declaration: Procedure MoveBg (  Page  :  HeapBuf;
  1146.                                    X1  :  ColumnType;
  1147.                                    Y1  :  RowType;
  1148.                                    X2  :  ColumnType;
  1149.                                    Y2  :  RowType;
  1150.                                    X3  :  ColumnType;
  1151.                                    Y3  :  RowType);
  1152.  
  1153.  
  1154. Purpose:     Moves the block at X1,Y1 (upper left) and
  1155.              X2,Y2 (lower right) of the current screen
  1156.              to block beginning at X3,Y3 (upper left) on
  1157.              page.                  
  1158.                                       
  1159.              Notes:
  1160.              1.  When MoveBg is called, the block at X1,Y1,X2,Y2
  1161.                  is saved on the stack, the screen defined by ì
  1162.                  page is copied to video memory, then the block ì
  1163.                  on the stack is written to the screen.
  1164.  
  1165. Example:     Overlay some boxes, then move one from the other
  1166.              incrementally.
  1167.  
  1168.              (*$IBoDecl *)
  1169.              (*$IScreen *)
  1170.              (*$IPutStr *)
  1171.              (*$ICopies *)
  1172.              (*$IBoxul  *)
  1173.              (*$ISetAtt *)
  1174.              (*$IMoveBg *)
  1175.  
  1176.              BEGIN
  1177.  
  1178.                 Mark ( HeapTop );
  1179.                 New ( page[1] );
  1180.                 ClrScr;
  1181.                 Boxul ( 20, 8, 37, 16, 1, 14);
  1182.                 for i := 9 to 15 do
  1183.                    PutStr ( h, Copies ( '▓',16),21, i, 14);
  1184.                 SetAtt ( 38, 9, 40, 17, 30);
  1185.                 SetAtt ( 21, 17, 40, 17, 30);
  1186.                 Read;
  1187.                 SaveScreen ( page[1] );
  1188.                 Boxul ( 20, 8, 37, 16, 1, 14);
  1189.                 for i := 9 to 15 do
  1190.                    PutStr ( h, Copies('▒',16),21, i, 7);
  1191.                 Read;
  1192. .E
  1193.                 for i := 1 to 16 do
  1194.                 begin
  1195.                    Movebg ( page[1], 20+(i-1)*2, 8, 40+(i-1)*2, 17, 
  1196.                             22+(i-1)*2, 8 );
  1197.                    delay(04);
  1198.                 end;
  1199.                 Release( HeapTop );
  1200.    
  1201.              END (* XMoveBg *) .
  1202. .E
  1203. 
  1204.                                MOVEBLK
  1205.  
  1206.  
  1207. Declaration: Procedure MoveBlk ( X1  :  ColumnType;
  1208.                                  Y1  :  RowType;
  1209.                                  X2  :  ColumnType;
  1210.                                  Y2  :  RowType;
  1211.                                  X3  :  ColumnType;
  1212.                                  Y3  :  RowType);
  1213.  
  1214.  
  1215. Purpose:     Moves the block defined by X1,Y1,X2,Y2 (upper-
  1216.              left and lower-right coordinates) to location
  1217.              X3,Y3 (upper-left).
  1218.  
  1219.              
  1220.              Notes:
  1221.              1.  The original block (X1,Y1,X2,Y2) is saved onì
  1222.                  the stack, erased from video memory, then copied 
  1223.                  to (X3,Y3).  By contrast, see CopyBlk description. 
  1224.              2.  To move blocks on the heap, use MblkHeap.
  1225.  
  1226. Example:     Relocate three boxes.
  1227.  
  1228.              (*$IBoDecl  *)
  1229.              (*$IMoveBlk *)
  1230.              (*$IPutStr  *)
  1231.              (*$ICopies  *)
  1232.              (*$IBoxul   *)
  1233.  
  1234.              BEGIN
  1235.  
  1236.                 ClrScr;
  1237.                 BoxUl ( 1,1, 8, 7,3,14);
  1238.                 BoxUl ( 10,1,17, 7,3,14);
  1239.                 BoxUl ( 19,1,26, 7,3,14);
  1240.                 PutStr (h,'Press enter to move boxes',1,9,14);
  1241.                 read;
  1242.                 MoveBlk (1,1,26,7,1,12);
  1243.  
  1244.              END (* XMoveBlk *) .
  1245. 
  1246. .T:B:BoRef2.pas
  1247.