home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / TURBOPAS / TP003.ZIP / READTHIS.NOW < prev    next >
Encoding:
Text File  |  1985-06-28  |  24.6 KB  |  479 lines

  1.                           T U R B O   W H E E L S
  2.                                version 1.00
  3.                     Copyright 1984 by Neil J. Rubenking
  4.  
  5.         This disk contains quite a few procedures and functions that make
  6.     TURBO Pascal easier to use.  Why re-invent the wheel when you can get
  7.     TURBO WHEELS?  I am releasing it for distribution in the User Group/
  8.     Bulletin Board network subject to the following stipulations:
  9.  
  10.         1)  Anyone may get a copy of these files for examination, either
  11.             through their local Users Group or Bulletin Board, or by
  12.             sending me a blank, DOUBLE-sided diskette and a prepaid,
  13.             self-addressed diskette mailer.  Regardless of how the disk
  14.             is obtained, anyone who actually finds the contents USEFUL
  15.             should send me $10, so I can continue writing and releasing
  16.             software in this User-Supported fashion.  Send $10 to:
  17.  
  18.                             Neil J. Rubenking
  19.                             300 Page St.
  20.                             San Francisco, CA  94102
  21.  
  22.         2)  I retain all rights to the SOURCE code.  Recipients of the
  23.             procedures may freely $INCLUDE them in compiled programs,
  24.             but may not release the SOURCE.
  25.  
  26.         3)  Clubs may freely copy and distribute the disk for a nominal
  27.             fee, not to exceed $8.
  28.  
  29.         With the legalities aside, I hope you find these procedures useful
  30.     in your programs.  Each has at least one "driver" program, to illustrate
  31.     its actual use.  If you are new to the concept of $INCLUDEing pre-written
  32.     code in your TURBO Pascal programs, study the drivers.  There are also
  33.     several minor applications/utilities constructed using 8 or 10 of the
  34.     handy procedures.  A listing and description of the procedures follows.
  35.  
  36.         A keen observer might correctly deduce the following from the type of
  37.     files I have put on this disk.
  38.  
  39.         1)  I don't have a Color/Graphics display,
  40.         2)  I don't do much in math and scientific programming,
  41.         3)  I do write programs that involve creating and manipulating
  42.             disk files,
  43.         4)  I do like my programs to look and sound good.
  44.  
  45.         You may have noticed other disks of TURBO files on the market.  One
  46.     that I have found useful is just called "Procedures and Functions for
  47.     TURBO Pascal", from:
  48.  
  49.                               The Success Press
  50.                               P.O. Box 2795
  51.                               Des Plaines, IL  60018
  52.  
  53.         Send Bill Todd $20 to receive these procedures.  A list of them is
  54.     on this disk as "SUCCESS.DOC".
  55.  
  56.                                                 TURBO WHEELS   page 2
  57.  
  58.             *** SETTING UP THE DISK ***
  59.  
  60.         Format a blank diskette with the /S option, to make it a "bootable"
  61.     DOS disk.  Copy COMMAND.COM onto it, too.  Copy all the files from this
  62.     diskette onto the new diskette, and finally copy the files TURBO.COM and
  63.     TURBO.MSG from the TURBO Pascal disk.  Now your TURBO is a more powerful
  64.     development tool -- it has WHEELS!
  65.  
  66.     NOTE: If you're pressed for room, you only need the *.COM, *.LIB, *.TYP,
  67.           *.DAT and the *.PAS files.  The latter are handy but not necessary.
  68.           This would leave about 68K left on the disk for ASTCLOCK.COM,
  69.           ANSI.SYS, etc.  -- C.T. Wiebe, PDSE reviewer.
  70.  
  71.             *** FILES ON THIS DISK ***
  72.  
  73.         The file "README.###" is a list of all the files, with a one-line
  74.     description of each for quick reference.  The files for INCLUsion in your
  75.     programs have the extension .LIB or .TYP.  Almost every .LIB file has a
  76.     short program to illustrate its action (often called a "driver").  The
  77.     drivers have the same name as their .LIB file, but the extension is .PAS.
  78.     There are several utility application programs that use 8 or 10 .LIB files,
  79.     and a few data files (extension .DAT).  Now on to the descriptions of the
  80.     individual files.
  81.  
  82.  
  83.             *** TYPE DECLARATION FILES ***
  84.  
  85.         Most of the files on this disk use variables of type REGPACK (for
  86.     REGister PACK) or FILENAME_TYPE.  The description at the top of the INCLUDE
  87.     file will indicate if these or any other files need to also be present.
  88.     The reason to NOT write these type declarations directly into the files
  89.     that require them is that TURBO objects to multiple descriptions of the
  90.     same TYPE.
  91.  
  92.     FILENAME.TYP contains the definition of "filename_type" as a string
  93.         of up to 64 characters.
  94.  
  95.     REGPACK.TYP describes the type of variable required as input by TURBO's
  96.         procedures INTR and MSDOS.  You do not need to understand these to
  97.         use them! (But if you DO, you can do a lot!)
  98.  
  99.     SCREENS.TYP is the declaration of variable type SCREEN, which is exactly
  100.         the same "shape" as the (text) video display memory.  Using variables
  101.         of this TYPE, you can easily do direct screen manipulation.
  102.  
  103.     ERRMESSG.LIB is another file that is required by quite a few others.
  104.         It contains the function MESSAGE which receives as input a one-byte
  105.         error code (output of a DOS function) and returns the "translation"
  106.         of that code, as specified in the DOS 2.0 manual.
  107.  
  108.  
  109.  
  110.  
  111.                                                 TURBO WHEELS   page 3
  112.  
  113.             *** DOS 2.0 FILE HANDLING ***
  114.  
  115.         TURBO's file handling procedures do NOT work with subdirectories, as
  116.     you may have found out.  The following procedures are implementations of
  117.     the DOS 2.0 procedures--all the ordinary ones and some new ones, too.
  118.  
  119.     EXTENDIO.DAT is an exact description of the parameters passed to and
  120.         from these new IO functions.  Until you are used to using them,
  121.         you may want to actually insert this document into your source for
  122.         reference (or refer to it using SIDEKICK!).
  123.  
  124.     EXTENDIO.LIB, for EXTENDed Input/Output, contains 2.0 versions of Reset,
  125.         Rewrite, Close, Read, Write, Seek, and Erase.  Each new procedure
  126.         has the same name as the one it replaces, preceded by an X (Xreset,
  127.         Xclose, etc.).  Any time you use these Extended IO procedures, you
  128.         will also have to $INCLUDE the TYPE files REGPACK.TYP and
  129.         FILENAME.TYP, and the file ERRMESSG.LIB--all of these procedures
  130.         return a one-byte error code if anything goes wrong, and ERRMESSG.LIB
  131.         lets you interpret the error by saying "writeLn(message(error))".
  132.             In the DOS 2.0 mode, instead of a File Variable (a variable of
  133.         TYPE "file of something") you will use an INTEGER File Handle.
  134.         XReset and XRewrite receive a full-path filename (up to 64 char-
  135.         acters) and return the file handle, which you will use for all
  136.         further references to the file.  XClose receives just the file
  137.         handle (any open file has a handle), and XErase receives just the
  138.         path/filename.
  139.             Since DOS 2.0 files are effectively just files of bytes, the
  140.         XRead and XWrite operations work rather differently from their
  141.         forebears.  You pass the File Handle, the variable to/from which
  142.         data is to be read/written, and the SIZE of that variable (easily
  143.         obtained with TURBO's SizeOf function).  If the variable is a 1K
  144.         array, then 1K will be read into it (or written from it).  The
  145.         Size-passing is necessary.  Without it, you would have to write a
  146.         new XRead and XWrite for each type of variable!
  147.             XSeek is a bit complicated.  You pass the File Handle (as usual),
  148.         the Size of the records in your file, and the point from which you
  149.         want to start your XSeek (Beginning, End, or Current position), and
  150.         you get back the new current position.  Even if you don't want the
  151.         new current position (e.g., you just wanted to set the file pointer
  152.         back to the beginning, or all the way to the end for APPEND), you
  153.         still have to provide a dummy variable for it.
  154.             For very detailed descriptions of the parameters to pass to and
  155.         from these EXTENDed Input Output operations, see EXTENDIO.DAT.
  156.  
  157.     MOVEFILE.LIB might well be called "XRename", because it does serve to
  158.         rename files on any path.  However, the Renaming extends to the full
  159.         path -- you can MOVE a file to a different subdirectory simply by
  160.         changing its path.  You pass the old path and the new path, and
  161.         receive the usual one-byte error code if anything goes wrong.
  162.  
  163.  
  164.  
  165.  
  166.                                                 TURBO WHEELS   page 4
  167.  
  168.     GETFILE.LIB contains two procedures, Find_First and Find_Next.
  169.         Find_First serves to find the first occurrence of a file matching
  170.         the template you supply (using the standard DOS wildcard characters,
  171.         ? for any character and * for anything at all, AND using full-path
  172.         filenames).  You also specify the File Attribute--you can GET files
  173.         that are Read-Only, Hidden, System, Volume label, or Directory.
  174.         Find_First sets the DTA (Disk Transfer Area) to a buffer supplied by
  175.         you and either puts information about the file in the buffer, or
  176.         returns an error code.  Once you have Found the First occurrence,
  177.         you repeat Find_Next until you don't find any more.
  178.  
  179.     ALLFILES.LIB is a very handy procedure to include in any program that
  180.         makes use of other files (e.g., a word processor, picture editor,
  181.         music maker, etc.).  You pass the top left and bottom right coor-
  182.         dinates of an available screen area, and a template for the files
  183.         you want, and ALLFILES takes over.  It opens and frames a window at
  184.         the coordinates and displays all matching files.  The user positions
  185.         a pointer at the required file and presses <return> to select it.
  186.         If there are more files than will fit in the window, the user has
  187.         he choice of selecting a visible file or going on to another window
  188.         full.  Once a file is selected, ALLFILES erases its window and returns
  189.         the filename.  Note that your program will not have to test for
  190.         existence of the file before trying to open it--you KNOW it exists.
  191.             For an extremely classy use of ALLFILES, you may want to use the
  192.         technique described in SCREENS.LIB to save whatever is on the screen
  193.         before calling ALLFILES and pop it right back when ALLFILES is done.
  194.  
  195.     MKRMDIR.LIB brings the DOS MKDIR and RMDIR (MaKe DIRectory and ReMove
  196.         DIRectory) into TURBO.  If you want to do it, you can.
  197.  
  198.     FILEATTR.LIB lets you change the File Attribute byte (Read-Only, Hidden,
  199.         System, Archive) of a file on any path.
  200.  
  201.     GTSETDIR.LIB lets you GET or SET the current subDIRectory.  It may well
  202.         be used in conjunction with GETSTDD below.
  203.  
  204.  
  205.             *** DOS 1 OR 2 FILE HANDLING ***
  206.  
  207.     GETSETDD.LIB uses DOS function calls to GET or SET the Default Drive.
  208.  
  209.     EXISTFIL.LIB checks for the existence of a file.  You pass it the
  210.         "old-fashioned" filename (no subdirectory!) and it returns true
  211.         or false.  (The EXTENDed I/O operations do not directly crash your
  212.         program if the file requested does not exist, so they don't need a
  213.         corresponding 2.0 function.)
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.                                                 TURBO WHEELS   page 5
  222.  
  223.             *** DISK READ/WRITE PROCEDURES ***
  224.  
  225.     DISKTYP.LIB checks the type of disk (single/double sided, 8/9 sectors
  226.         per track).  You pass the drive letter, and it returns the number
  227.         of K of disk space (an integer, 160, 180, 320, or 360), 0 if an
  228.         invalid drive was specified, or 1 for a non-standard format.
  229.  
  230.     GETSECTR.LIB conducts I/O between a specific sector on the disk and a
  231.         buffer variable declared by you.  You specify [R]ead or [W]rite and
  232.         the side, sector, and track, and the buffer variable is either read
  233.         from or written to the disk.  As usual, a one-byte error code is
  234.         returned.  On the advice of the DOS Manual, GetSector makes three
  235.         tries at reading the sector before it gives up and returns an error
  236.         code.
  237.             The buffer variable must be 512 bytes, but you can choose to
  238.         arrange these bytes in convenient ways.  For example, in the
  239.         application LABEL.PAS, the buffer is an array[1..16] of type
  240.         directory_entry, and reading a directory sector gives you instant
  241.         access to its 16 entries.  NOTE that, unlike most of the procedures
  242.         on this disk, GETSECTR does not have a driver with the same name.
  243.         The sample programs that use GETSECTR are LABEL and DISKMOD.
  244.  
  245.     LABEL.PAS uses DISKTYP.LIB, GETSECTR.LIB, and several other files to
  246.         read and write the volume label.  It first seeks an existing label
  247.         in the directory (NOTE:  the volume label is just a special kind
  248.         of directory entry.)  If found, you may change it.  If not found,
  249.         the first directory slot that is either never-used or erased is
  250.         converted to a label of your choice.  The current date and time are
  251.         properly included with your volume label, but the bit-manipulation
  252.         that does that is horrifying!
  253.  
  254.     DISKMOD.PAS is a working Disk Sector Viewing and Modifying program,
  255.         based on DISKMODF.BAS by John VanderGrift.  You select a sector
  256.         and get it displayed both in (filtered) ASCII and hex.  You can
  257.         modify the displayed sector by simply typing in new values, but
  258.         you must specifically ask to record the modifications.  Pressing
  259.         PgDn and PgUp move to the next or previous sectors -- the procedures
  260.         "increment" and "decrement" embody the DOS sector numbering scheme.
  261.  
  262.  
  263.             *** VIDEO DISPLAY PROCEDURES ***
  264.  
  265.     CURSOR.LIB contains the procedure Cursor_Control.  You set the top and
  266.         bottom "scan lines" for the cursor.  You'll want to $INCLUDE the
  267.         file MONITOR.LIB and ask to CheckColor before you change the cursor
  268.         around, because the Monochrome cursor has 14 scan lines (numbered
  269.         0 at the top to 13 at the bottom) while the Color cursor is only
  270.         7 high (0 to 6).  The normal cursor is 12,13 in Mono and 6,7 in color.
  271.         In Monochrome, you can get a two-part cursor by setting the top line
  272.         below the bottom.  NOTE that you can "kill" the cursor by setting the
  273.         top line to 48, bottom to 0.
  274.  
  275.  
  276.                                                 TURBO WHEELS   page 6
  277.  
  278.     MONITOR.LIB sets the values of the variables COLOR (boolean) and
  279.         ScreenSeg (integer) for use by other procedures.  Besides
  280.         $INCLUDEing it, you must invoke CheckColor at the beginning
  281.         of your program.
  282.  
  283.     SCREEN.LIB contains procedures to read and write the character and
  284.         screen attribute (i.e., COLOR) at any location on the screen IN
  285.         TEXT MODE.  The driver, SCREEN.PAS, is a little video game showing
  286.         how handy these procedures can be.
  287.  
  288.     POPSCREN.LIB is a slightly frivolous use of the SCREEN data type,
  289.         declared in SCREENS.TYP.  Several SCREEN variables are created
  290.         and rapidly switched to the display.  A pop-up menu example is
  291.         included.
  292.  
  293.     POPSCREN.DAT is a screen file used by POPSCREN.LIB.
  294.  
  295.     GRFXTABL.LIB defines a table of ROMEntries "on top" of the ROM
  296.         graphics table, giving us (read-only) access to the dot patterns
  297.         used to create the monochrome characters.
  298.  
  299.     TITLES.LIB contains the procedure MakeTitle.  Given a title up to ten
  300.         characters and a starting row, it makes a big title on the screen
  301.         by using the character patterns from GRFXTABL.
  302.  
  303.     WINDOWS.LIB offers another approach to using windows.  The variable
  304.         type "corners" is declared to be an array[1..4] of byte.  Windows
  305.         that your program will use are set at the beginning of the program
  306.         by declaring CONSTants of type "corners".  The procedures DoWindow
  307.         and DoFrame operate on input of type "corners".  If, later in the
  308.         development of your program, you want to move the windows around,
  309.         you just change the CONSTant declaration at the top.
  310.  
  311.  
  312.             *** KEYBOARD PROCEDURES ***
  313.  
  314.     GETKEYS.LIB is one of my favorites.  The line "GetKeys(C,D)" causes
  315.         your program to wait for a keystroke and, if it is an "ordinary"
  316.         keystroke, returns the character in C and chr(0) in D.  If, however,
  317.         it was a "special" keystroke (arrow key, function key), it returns
  318.         chr(27) in C and a code character in D.  The file KEYCHART.DAT
  319.         tabulates these special codes.
  320.  
  321.     KEYBOARD.LIB is another approach to trapping keystrokes.  It uses the
  322.         keyboard BIOS interrupt $16 to get the scan code and ASCII code of
  323.         any key pressed.  The file SCANCODE.DAT is a chart of keyboard
  324.         codes, along with a table of "extended" scan codes.
  325.  
  326.     FANCYKEY.LIB goes KEYBOARD one better.  It returns a phrase describing
  327.         the key pressed, such as "Alt-A", "Shift-F1", "Back Tab", etc.
  328.  
  329.  
  330.  
  331.                                                 TURBO WHEELS   page 7
  332.  
  333.     NEWINT9.LIB is an ambitious procedure.  The keyboard's output is
  334.         generally handled by Interrupt $9, which is called BY THE KEYBOARD
  335.         whenever a key is struck.  This interrupt checks for shift states,
  336.         filters out key release codes, and produces the "typematic" effect,
  337.         whereby a key held down repeats.  Certain applications might be
  338.         better off WITHOUT the typematic and WITH access to the key release
  339.         codes -- my own PIANO MAN program comes to mind.  I required a note
  340.         to sound ONCE when a key was pressed and stop when that key was
  341.         released.  Games might requires this feature.  If you do use it,
  342.         your program should:
  343.  
  344.             1)  invoke procedure SetUpInt, which creates the new interrupt.
  345.             2)  invoke NewInt, which saves the normal interrupt vector and
  346.                 replaces it with directions to the new one.
  347.             3)  MOST IMPORTANT, before the program ends, invoke OldInt to
  348.                 restore the normal interrupt.  If you don't do this, or if
  349.                 your program crashes before it can do it, you cannot
  350.                 communicate through your keyboard, and you have to turn
  351.                 the PC off and on again.
  352.  
  353.         Used with care, NEWINT9 can satisfy a real need.
  354.  
  355.  
  356.             *** GRAPHICS ***
  357.  
  358.     (Let me note that I myself do not have a Color/Graphics adapter, so I
  359.     haven't had much opportunity to write for one.  However, the mighty
  360.     BORLAND has a Graphics tool set for their usual price of $50.)
  361.  
  362.     CIRCLE.LIB draws a circle on your screen.  You specify six parameters:
  363.         H, K and R are the X and Y coordinates of the circle's center and
  364.         its radius.  "Res" is the resolution -- the number of dots used to
  365.         draw the circle is proportional to Res, as is the time required to
  366.         draw it.  "Aspect" is a real value that describes the circle's
  367.         "roundness" -- adjust to a perfect circle, or change it to get an
  368.         ellipse.
  369.             Finally,  "color" can be 1, 2, or 3 if you are in the Graphics
  370.         mode that supports four colors.  (See the description of graphics
  371.         modes in the TURBO 2.0 manual).
  372.  
  373.     RECTANGL.LIB naturally draws a rectangle on the screen.  You tell it
  374.         the X and Y coordinates of the upper left and lower right corners,
  375.         the color (1, 2, or 3 if appropriate), and 1 for a filled rectangle,
  376.         0 for hollow.
  377.  
  378.  
  379.  
  380.  
  381.  
  382.  
  383.  
  384.  
  385.  
  386.                                                 TURBO WHEELS   page 8
  387.  
  388.             *** MISCELLANEOUS ROUTINES ***
  389.  
  390.     EQUIPMNT.LIB uses Interrupt $11 to check the equipment attached to
  391.         your PC.  It reports on number of printers, RS232 ports, game
  392.         ports, and diskette drives, the initial video mode, or the amount
  393.         of RAM on the motherboard.
  394.  
  395.     GETINTGR.LIB is intended to save you the embarrassment of having your
  396.         program crash because someone made an invalid entry for an integer.
  397.         At the same time, it makes sure that the entry is within a ranges
  398.         you specify.  Non-numeric keystrokes are ignored, BackSpace works,
  399.         and the function does not give up until a valid integer is entered.
  400.  
  401.     GETFREE.LIB is another face-saver.  It gets the amount of free space on
  402.         the current disk.  That way, your programs can check for space and
  403.         give alternatives if there's not enough, rather than ignominiously
  404.         crashing.
  405.  
  406.     HEXFUNCT.LIB contains the procedure HEX which receives an integer and
  407.         returns a 5-character hex string (e.g., $BF00).  The hex string
  408.         always refers to a positive number -- TURBO's integer variable type
  409.         uses its highest bit to indicate sign, thus restricting the integer
  410.         range to -32,768 to +32,767.  Hex equivalents are calculated by
  411.         considering negative integers as offsets down from $10000 (decimal
  412.         65,536).  Thus, HEX(-1) = $FFFF.  (NOTE:  the TURBO manual says
  413.         that the integer range is as stated above, but in my experience,
  414.         it is not possible to enter -32,768.)
  415.  
  416.     KAVAIL.LIB returns the number of KiloBytes of memory available.  It
  417.         takes into account the MemAvail function's quirk of reporting
  418.         amounts greater than 32,767 as negative numbers.
  419.  
  420.     NOSOUND.PAS does nothing but shut off the sound, if one of your
  421.         programs crashes with sound on.  When you need it, you NEED it!
  422.  
  423.     PARAMETR.LIB contains the function GetParameter, which returns a string
  424.         of up to 80 characters consisting of whatever was entered on the
  425.         command line after the name of the program.  This O N L Y works in
  426.         COMPILED programs.
  427.     QUEUE.LIB is a generic Queue data structure.  One of Pascal's great
  428.         advantages over BASIC is its implementation of Pointer^ variables
  429.         and dynamic lists.  By keeping your data in a linked list instead
  430.         of an array, you can dedicate only as much memory as you need, up
  431.         to all the memory the system has.  If you test for memory available
  432.         with KAVAIL before you add each item to the list, you can safely
  433.         expand to the maximum memory of different systems without crashing
  434.         for lack of memory.
  435.  
  436.  
  437.  
  438.  
  439.  
  440.  
  441.                                                 TURBO WHEELS   page 9
  442.  
  443.     REBOOT.LIB does just what it says.  The "warm" reboot produced by
  444.         Interrupt $19 does NOT clear the RAM, so, for example, SIDEKICK
  445.         will stay resident.  The programs LESSRAM and NUMDISKS use REBOOT
  446.         to cause the PC to act as if its internal DIP switches had been
  447.         reset to indicate a different number of disk drives or different
  448.         amount of RAM.  One note of caution -- There seems to be some
  449.         interference in this reboot process from certain device drivers
  450.         in the CONFIG.SYS file.  The symptom is that the driver (e.g.,
  451.         your hard disk driver, or a RAMdisk) installs itself and then the
  452.         A: drive spins . . . and spins . . . and that's it.  To avoid this
  453.         problem, you could always rename CONFIG.SYS to something else
  454.         temporarily.  IF you can figure out why this happens and how to
  455.         get around it, PLEASE let me know!
  456.  
  457.     LESSRAM.COM is handy if you always write your programs on your
  458.         souped-up 640K SuperPC and want to test whether it will actually
  459.         run on a lesser machine with, say 96K.  You COULD open the box and
  460.         change the switches, but it's a lot easier just to go back to DOS
  461.         and type LESSRAM 96.
  462.  
  463.     NUMDISKS.COM's raison d'etre is the current confusion of method among
  464.         RAMdisks.  Some require that the internal switches be set to the
  465.         total number of physical drives and RAMdisks, while others insist
  466.         that the switches show physical drives only.  If you need to switch
  467.         around, you can enter NUMDISKS <number>.  If you put NUMDISKS in a
  468.         batch file, be sure to add an "n" (or "N") to the number so the
  469.         program won't pause for a keypress before rebooting.
  470.  
  471.     SAFEWRIT.LIB is one way to get around the fact that you cannot WRITE
  472.         certain characters to the screen -- they get interpreted as Control
  473.         Characters and warp your display.  Procedure SafeWrite catches these
  474.         characters and replaces them with a related character in Low Video.
  475.         Note that another approach would be to use the procedures in
  476.         SCREEN.LIB to send characters directly to the screen memory.
  477.         Using this latter method, you can put ANY character on the screen.
  478.  
  479.