home *** CD-ROM | disk | FTP | other *** search
- A. Introduction
- The following is the documentation for the subprogram
- library PASLIB01.INC which is now placed in the public
- domain.
-
- CAVEAT: much of this library is IBM and PC DOS specific.
- It has been tested on both an IBM PC-1 and an IBM PC/AT with
- monochrome, CGA, EGA, and Hercules boards but there are no
- guarantees for any other machines.
-
- Any comments or suggestions will be appreciated.
-
- Robert B. Wooster
- (203) 227-5588
- (212) 310-5222
- CIS: 72415,1602
-
- Version 1 released 22 May 1986
-
- B. Global Declarations
- 1. Constants
- a) IsColor
- a boolean set by InitMonitor depending upon whether the
- machines switches are set for monochrome or color.
- Also used in SwapMonitors, q.v.
- b) MaxRow, MaxCol should be self-evident
- c) Video attributes:
- LO_V: low video, HI_V high (or normal) video,
- RE_V: reverse video
- d) Special key scan codes
- for the use of these constants see the functions ugetc
- and NextField
- 1) cursor control keys
- SK_HM: Home SK_UP: up SK_PU: PgUp
- SK_LE: left SK_RI: right
- SK_EN: End SK_DN: down SK_PD: PgDn
- SK_IN: Ins SK_DE: Del
- 2) function keys
- SK_F1 to SK_F0
- 3) the Esc key : E_S_C
- 2. Types
- a) chrset
- b) string80: used as standard string type in most of the
- routines
- c) bigstring: for use when string80 isn't enough
- d) regtype: fairly standard register declaration for use in
- DOS function calls
- e) datetype: a standard date type to handle dates from 1/2/60
- to 12/31/2050
- f) timetype: a standard type for handling times
- g) scrntype & scrnptr: used in SaveScrn and RestoreScrn
- 3. Variables
- a) EquipFlag: the location of the equipment flag set by POST on
- IBM PCs
- b) MonoScrn & ColorScrn: the addresses of the monochrome and CGA
- screens
- c) KeyStat: the key status byte used by the keyboard routines
- d) SavedScrn: used by SaveScrn & RestoreScrn, q.v.
- e) SplKey: a flag used by the keyboard input routines, q.v.
- f) sdt: the current date according to the machine's clock;
- initialized in InitSys
- g) out: used by WhereOut, q.v.
- h) To_LST: see WhereOut
- i) EscFlag: see ugetc
- C. Hardware control functions
- 1. InitMonitor procedure
- a) function: sets IsColor flag according to the switch
- setting at EquipFlag
- b) syntax: InitMonitor;
- c) returns: nothing
- d) side effects: sets IsColor flag
- e) notes: EquipFlag is set during boot according to the
- hardware switch settings. In a two monitor
- system this means that the monochrome monitor
- will come up. EquipFlag can, however, be
- reset by some external programs such as Bob
- Starr's UTIL.EXE.
- 2. SwapMonitors procedure
- a) function: this is to allow two monitor systems to move
- back and forth between the monochrome and
- color monitors.
- b) Syntax: SwapMonitors;
- c) returns: nothing
- d) side effects: resets EquipFlag, and IsColor to their
- opposite monitor settings
- e) notes: if you return to the Turbo editor after
- switching monitors an odd number of times,
- the results can be unpredictable, i.e. your
- machine will more or less hang.
- 3. SaveScrn procedure
- a) function: saves current screen
- b) syntax: SaveScrn
- c) returns: nothing
- d) side effects: moves screen contents to savedscrn
- e) notes: used with restorescrn
- f) calls: nothing
- 4. RestoreScrn procedure
- a) function: restores saved screen
- b) syntax: RestoreScrn
- c) returns: nothing
- d) side effects: moves saved screen to current screen
- e) notes: used with savescrn
- f) calls: nothing
- 5. InitSystem procedure
- a) function: initialize system to standard
- setup
- b) syntax: InitSystem;
- c) returns: nothing
- d) side effects: IsColor flag and sdt are set and the standard
- window configuration (Sec. G) is initialized
- e) notes: See TEMPLATE.PAS for an example of its use
- f) calls: InitMonitor, InitWindows, SysDate
- D. Low-level Screen I/O
- 1. ugetc character function
- a) function: get a character from the keyboard without
- echo but with several side effects
- b) syntax c := ugetc;
- c) returns the character typed
- d) side effects
- 1) if Control-C is typed the program halts
- 2) if a special key, i.e. a function or cursor control key, is
- typed, a null character is returned and the global variable
- SplKey is set to that key's scan code
- e) notes: this is the workhorse of the input functions
- discussed in section D
- 2. putc procedure
- a) function: put a character on the screen with a
- specified attribute at the current cursor
- position
- b) syntax putc(c,b) where c is a character and b is an
- attribute byte.
- c) returns nothing
- d) side effects none, but note that the cursor is not moved
- e) notes: uses direct screen addressing
- 3. aputc procedure
- a) function: put a character c on the screen with
- attribute b at column x and row y
- b) syntax aputc(c,b,x,y)
- c) returns nothing
- d) side effects none, but note that the cursor is not moved
- e) notes: uses direct screen addressing
- E. Data I/O
- 1. GetUC character function
- a) function: get an upper case character from the
- keyboard if it is in OKSet, otherwise ring
- bell until a character in OKSet is typed
- b) syntax c := GetUC(default, OKSet)
- c) returns an upper case character
- d) side effects same as ugetc
- e) notes: useful for menu selections
- f) calls: ugetc
- 2. PutString procedure
- a) function: put a string on the CRT at the indicated
- position
- b) syntax PutString(s,x,y)
- c) returns nothing
- d) side effects none
- e) notes: writes a string80 but $V- parameter permits
- sending any string
- 3. GetString procedure
- a) function: get a string from the keyboard
- b) syntax: GetString(s1,len,x,y,s2)
- where s1 is the string returned as a
- side effect
- len is the maximum length of the string
- x,y are the screen coordinates
- s2 is the default string or ''
- c) returns: nothing
- d) side effects: If a string has been typed it is returned in
- s1. If no string typed before a special
- function key or <Enter> is typed s2 is
- returned as s1. If a special function key is
- pressed the global variables are set.
-
- e) notes: The function terminates after len characters
- have been entered.
- <Esc> clears an unfinished entry and lets you
- start over
- f) calls: ugetc, PutString
- 4. PutInteger procedure
- a) function: put an integer on the screen at x,y
- b) syntax: PutInteger(i,x,y,len)
- c) returns: nothing
- d) side effects: none
- e) notes:
- f) calls: PutString
- 5. GetInteger procedure
- a) function: get an integer from the keyboard
- b) syntax: GetInteger(i1,x,y,len,min,max,i2)
- where i1 is the integer returned
- x,y are the screen coordinates
- len is the maximum length
- min is the minimum acceptable value
- max is the maximum acceptable value
- i2 is the default value
- c) returns: nothing
- d) side effects: the entered value in i2 plus the same other
- side effects as GetString
- e) notes: the NumLock is set upon entering this
- function and released upon exit
- f) calls: GetString, PutInteger
- 6. Format string function
- a) function: format a number with parentheses and commas
- b) syntax: s := Format(r,i,j)
- c) returns: s as a string of length i representing a
- number to j decimal places with imbedded
- commas and parens if negative.
- d) side effects: none
- e) notes: use for pretty-printing output
- f) calls:
- 7. PutNumber procedure
- a) function: put a real number on CRT at x,y with length i
- and j decimal places
- b) syntax: PutNumber(r,i,j,x,y)
- c) returns: nothing
- d) side effects: none
- e) notes: results are unpredictable if number has more
- than i digits
- f) calls: nothing
- 8. GetNumber procedure
- a) function: get a real number from the keyboard
- b) syntax: GetInteger(r1,x,y,i,j,min,max,r2)
- where r1 is the integer returned
- x,y are the screen coordinates
- i is the maximum length
- j is the # of decimals
- min is the minimum acceptable value
- max is the maximum acceptable value
- r2 is the default value
- c) returns: nothing
- d) side effects: the entered value in r1 plus the same other
- side effects as GetString
- e) notes: the NumLock is set upon entering this
- function and released upon exit
- f) calls: GetString, PutNumber
- 9. PutDate procedure
- a) function: put a date on the CRT in the form mm/dd/yy
- b) syntax: PutDate(date,x,y);
- c) returns: nothing
- d) side effects: none
- e) notes:
- f) calls:
- 10. GetDate procedure
- a) function: get a legal date form the keyboard
- b) syntax: GetDate(date1,x,y,date2)
- where: date1 is the date returned
- x,y are the screen coordinates
- date2 is the default date
- c) returns: nothing
- d) side effects: date entered in date1
- e) notes: NumLock is set upon entering this procedure
- and cleared upon exit.
- ANY character may be used as a delimiter
- If no year is given the current year is
- assumed
- Dates must be between 1/1/1960 and
- 12/31/2059, the appropriate century is
- assumed.
- f) calls: GetString
- 11. Heading procedure
- a) function: put a string on the heading line
- b) syntax: Heading(string)
- c) returns: nothing
- d) side effects: prints a message centered on line 1
- e) notes: see above
- f) calls: MainWdo, aputc
- 12. Wait procedure
- a) function: wait for any key to be pressed
- b) syntax: Wait;
- c) returns: nothing
- d) side effects: none
- e) notes: prints "Press any key to continue" on the
- message line and waits for it. An
- improvement over REPEAT UNTIL KeyPressed
- because it throws away the key that was
- pressed.
- f) calls: HelpWdo, MainWdo
- 13. ShowHelp procedure
- a) function: Display a message on the message
- line
- b) syntax: ShowHelp(string)
- c) returns: nothing
- d) side effects: none
- e) notes: Use for explanatory messages
- f) calls: HelpWdo, MAinWdo
- 14. Prompt character function
- a) function: a variation on the UCSD standard prompt such
- as "C)ompile, E)dit, F)ile, R)un ?"
- b) syntax: c := Prompt(string, default);
- c) returns: character c
- d) side effects: none
- e) notes: any capitalized character in string is a
- valid response.
- f) calls: HelpWdo, MainWdo, GetUC
- F. Date Manipulation
- 1. Jul integer function
- a) function: calculate pseudo-Julian number from date
- b) syntax: i := Jul(date)
- c) returns: returns pseudo-Julian as an integer
- d) side effects: none
- e) notes: the algorithm first calculates the true
- Julian number as a real and then subtracts
- the Julian number for 1/1/60. This insures
- that the number will be an integer over the
- range of datetype. Based on a FORTRAN
- one-liner fount in the HP-41 user library.
- f) calls: None.
- 2. JtoD procedure
- a) function: convert a pseudo-Julian number to a datetype
- b) syntax: JtoD(i, date);
- c) returns: nothing
- d) side effects: returns date as a side effect
- e) notes: See Jul; this just reverses the process
- f) calls: none
- 3. J30 integer function
- a) function: Does the equivalent of Jul except following
- a 30-day month convention.
- b) syntax: i := J30(date)
- c) returns: a 30-day equivalent pseudo-Julian number
- d) side effects: none
- e) notes: See Jul.
- f) calls: nothing
- 4. LegalDate procedure
- a) function: checks to see if a date is a legal
- date, i.e., not June 31, and if it
- is, fixes it
- b) syntax: LegalDate(date);
- c) returns: nothing
- d) side effects: if date is corrected, the corrected date
- is returned, else the original date is
- returned
- e) notes: can be used for some input checking
- f) calls: nothing
- 5. mmdd string function
- a) function: converts a date to a string of the
- form "mm/dd"
- b) syntax: s := mmdd(date);
- c) returns: string of date in the form "mm/dd"
- d) side effects: none
- e) notes: useful for printing dates
- f) calls: nothing
- 6. mmddyy string function
- a) function: converts a date to a string of the
- form "mm/dd/yy"
- b) syntax: s := mmddyy(date);
- c) returns: string of date in the form "mm/dd/yy"
- d) side effects: none
- e) notes: useful for printing dates
- f) calls: nothing
- 7. DayofWeek integer function
- a) function: find the day of the week from a date
- b) syntax: i := DayOfWeek(date);
- c) returns: an integer with 0 representing Monday and 6
- representing Sunday
- d) side effects: none
- e) notes: used by NextBDay
- f) calls: Jul
- 8. NextBDay procedure
- a) function: find the next weekday after a date
- b) syntax: NextBDay(date1,date2)
- c) returns: nothing
- d) side effects: date2 is the next business or week day after
- date1
- e) notes: used for some investment calculations
- f) calls: DayofWeek, JtoD, jul
- 9. AddMonths procedure
- a) function: add n months to a date
- b) syntax: AddMonths(date1,n,date2)
- c) returns: nothing
- d) side effects: date2 is n months from date1
- e) notes: very useful for bond calculations but
- admittedly a little kludgey
- f) calls: nothing
- 10. DayCount integer function
- a) function: return days between two dates
- b) syntax: i := DayCount(date1, date2)
- c) returns: number of days between two dates
- d) side effects: none
- e) notes: I was doing this so often in programs I
- decided to make it a function. The order of
- the dates is irrelevant; the absolute value
- of the dates is returned.
- f) calls: Jul
- 11. DatesEqual boolean function
- a) function: test for the equality of two dates
- b) syntax: Boolean := DatesEqual(date1, date2);
- c) returns: TRUE if date1 equals Date2, false otherwise
- d) side effects: none
- e) notes: why can't Pascal test for equality of
- records?
- f) calls: nothing
- 12. NullDate procedure
- a) function: sets a date to 1/1/60
- b) syntax: NullDate(date)
- c) returns: nothing
- d) side effects: date is set to 1/1/60, which may be used as a
- null
- e) notes: used to test if a date record is initialized;
- may also be used to force no default in
- GetDate
- f) calls: nothing
- G. Window Support
- My standard display uses the first line as a header and
- the last line as a message line. The active window then
- becomes rows 2 through 24. Both the header and the message
- line are in reverse video. The procedures InitWindows,
- MainWdo, and HelpWdo manage this
- 1. InitWindows procedure
- a) function: set up standard windows
- b) syntax: InitWindows
- c) returns: nothing
- d) side effects: CRT lines 1 and 25 are set to reverse video
- and the active window is set to 1,2;80,24
- e) notes: see above
- f) calls: MainWdo, aputc
- 2. MainWdo procedure
- a) function: set the active window to 1,2;80,24
- b) syntax: MainWdo
- c) returns: nothing
- d) side effects: sets the active window to 1,2;80,24
- e) notes: see above
- f) calls: nothing
- 3. HelpWdo procedure
- a) function: set the active window to the message
- line
- b) syntax: HelpWdo
- c) returns: nothing
- d) side effects: sets the active window to 1,1;80,25
- e) notes: sets the cursor at 1,25
- f) calls: nothing
- 4. UseWdo procedure
- a) function: creates a window for i/o
- b) syntax: UseWdo(x,y,col,row,string);
- c) returns: nothing
- d) side effects: see notes
- e) notes: creates a window with the upper left corner
- at x,y, col wide and row high. If possible,
- draws a box around the window. String is
- inserted in the row above the window. The
- window is cleared.
- f) calls: aputc
- 5. CloseWdo procedure
- a) function: restores MainWdo after a call to UseWdo
- b) syntax: CloseWdo;
- c) returns: nothing
- d) side effects: none
- e) notes: used to cancel effect of UseWdo. It does
- not, however, clear the screen. To do that
- use the window save and restore functions.
- f) calls: MainWdo
- H. System Services
- 1. SysDate procedure
- a) function: gets the date from the system clock
- b) syntax: SysDate(date);
- c) returns: nothing
- d) side effects: date is initialized to whatever date the
- computer's clock says it is
- e) notes:
- f) calls:
- 2. SysTime procedure
- a) function: gets the time from the system
- clock
- b) syntax: SysTime(time)
- c) returns: nothing
- d) side effects: time is initialized to whatever time the
- computer's clock says it is
- e) notes:
- f) calls:
- 3. TimeStamp string function
- a) function: returns a string with the current date and
- time
- b) syntax: s := TimeStamp
- c) returns: s initialized to a string of the form
- "mm/dd/yy hh:mm am"
- d) side effects: none
- e) notes: useful for including in a write statement.
- The value returned is based on the computer's
- clock.
- f) calls: SysTime, SysDate,TimeStamp
- I. Miscellaneous
- 1. MakeBox
- a) function: draws a box using reverse video on the
- CRT
- b) syntax: DrawBox(x1,y1,x2,y2)
- c) returns: nothing
- d) side effects: none
- e) notes: draws a box from x1,y1 to x2,y2
- f) calls: aputc
- 2. WhereOut
- a) function: permits user to select between CRT and
- printer output.
- b) syntax: WhereOut
- c) returns: nothing
- d) side effects: opens "out" as either LST: or CON: depending
- on user response
- e) notes: file out should be closed when finished.
- f) calls: HelpWdo, MainWdo
- 3. Page
- a) function: if printer selected as output sends a form
- feed as per standard procedure, does a Wait
- if CRT selected.
- b) syntax: Page;
- c) returns: nothing
- d) side effects: form feed or wait
- e) notes: Tests To_LST flag
- f) calls: wait