Dec 052017
Memory Resident PopUp Routines Version 1.6 for Turbo Pascal Version 4.0. TPU's only.
File TPPOP16.ZIP from The Programmer’s Corner in
Category Pascal Source Code
Memory Resident PopUp Routines Version 1.6 for Turbo Pascal Version 4.0. TPU’s only.
File Name File Size Zip Size Zip Type
-READ.ME 1132 493 deflated
DICE.PAS 9325 2793 deflated
DICE.TPU 8336 3508 deflated
NODICE.BAT 871 398 deflated
NODICE.PAS 1187 483 deflated
POPDICE.PAS 2272 984 deflated
POPUP.DOC 14324 5610 deflated
POPUP.PAS 4950 1425 deflated
POPUP.TPU 3008 1632 deflated
REMOVE.PAS 702 361 deflated
TPOP.ASM 19572 4589 deflated
TPOP.OBJ 909 662 deflated
UNHOOK.PAS 3973 1233 deflated
UNHOOK.TPU 1760 833 deflated
UPPRCASE.ASM 775 290 deflated
UPPRCASE.OBJ 115 115 stored
WINDOWS.PAS 7122 1985 deflated
WINDOWS.TPU 4000 1904 deflated

Download File TPPOP16.ZIP Here

Contents of the POPUP.DOC file


Memory Resident PopUp Routines Version 1.6
for Turbo Pascal Version 4.0

Copyright (c)1988
Ross Neilson Wentworth

Custom software at reasonable prices!


All Rights Reserved


This software is provided without
warranty, expressed or implied.

The Turbo Pascal Units contained in this package will enable you to
quickly and easily create popup programs. Also included is a very simple
windowing package.

All source code is included so that you may modify it to your hearts
desire. Do NOT release modified versions of this package under any

Turbo Pascal Version 4.0 is required to use this package. MASM 5.1
is required to to re-assemble the low-level modules.

If you find this code useful, please send $10 to the address below or
make a $10 donation to the "The Historic Oaks Foundation", located in
Agoura Hills and Novato, California. Let me know if you make the
donation and you will receive full credit for registration (receipt or
copy of cancelled check required).

If you use this code in any commerical program this payment is required.
Shareware is considered commercial upon receipt of first registration.

Ross Neilson Wentworth
Serendipity Software
1422 Elkgrove Circle, #3
Venice, CA 90291

Features of This Package

o Easily create memory resident popup programs (SideKick-like).
o Automatic program detection to prevent multiple loading. (new!)
o Allows TSR's with conflicting hot-keys (new!)
o Simple program removal (new!)
o Uses proven TSR techniques.
o All DOS functions allowed from within resident program (except
I/O redirection), you can safely access the disk!
o No load-order limitations (except those imposed by other TSR's).
o Low code overhead, slightly over 1k EXE size increase to standard

One of the problems with writing popup programs is DOS is not reentrant.
That is, if you popup while DOS is busy you are very likely to crash the
system. This package does all the necessary checking and will only popup
when it is safe. This allows your program to do virtually anything including
file access. The one limitation is that it can not allocate additional memory.
You can still use heap memory, just don't use the DOS function to allocate or
modify a current memory block.

To guarantee a safe pop-up program it is necessary to grab hold of several
interrupt vectors. When the program is first initialized the following
vectors are intercepted:

09h keyboard
13h disk i/o
1Ch timer
28h backprocess
2Fh multiplex

When the program is popped up, two additional vectors are also intercepted:

23h control-break
24h critical error

In addition, a couple of other internal values are changed while the
program is active:

The Disk-Transfer-Area is saved and the popup's installed
The BREAK status is saved then turned off

These four items are restored when the TSR relinquishes control.

A sample program is provided that shows how to implement a popup program.

Contents of POPUP:

Function ReadKey : Char;

Use this function instead of the one provided in the CRT unit. Using
this routine will for keyboard entry will prevent other resident programs
from being "locked" out. To guarantee that the correct READKEY is being
used, precede it with it's unit name, i.e., CH := POPUP.READKEY

Function Installed(OurID : Byte) : Byte;

Given a unique program ID number, this function returns zero (0) if
the program has not already been installed. A nonzero value indicates
it has been installed or an error has occured:

1 : PRINT.COM detected. The TSR must be loaded before PRINT.COM.
2 : The program is already installed.
3 : Internal error, can't install.

Error 3 is usually caused by a poorly designed TSR program that has
already been loaded into memory. Try loading your program before any
others. Experimenting with the order of loading should point out the
bad TSR.

Procedure StayResident(OurID : Byte;ProgramAdress : Pointer;HotKey: Word);

HOTKEY is your key combination that will activate your program. It is of
type WORD where the low byte is the scan code and the high byte is the
shift status (ALT, CTRL, SHIFT, etc. See below). ProgramAddress is a
pointer to your popup procedure that you want called. Precede the
program name with an '@' to pass a pointer.

StayResident($69,@NotePad,Alt+LeftShift + $20); (ALT-LeftShift-D);

The shift status values are documented below.

OurID is a unique number for your resident program. Each different
TSR that you write should have a different ID number. For maximum
compatibility, you should allow the user to change the ID number,
perhaps by using a 'command-line' option, i.e. /I=155. MS-DOS reserves
ID numbers 0 to 80h for internal use.

Procedure ReleaseBlock(Segment : Word);

This inline macro releases the block of memory given a segment number.

Procedure ReleaseEnvironment;

Releases the block of memory holding the program's environment. It keeps
track of whether it has already been called so that multiple calls will
not be harmful.

Contents of UNHOOK:

Function Installed(MultID : Byte) : Boolean;

Returns TRUE if the resident program is in memory.

Function OKToUnload(MultID : Byte) : Boolean;

Returns TRUE if it is safe to unload the resident program from memory.

Procedure RemoveProgram(MultID : Byte);

Releases the memory and restores the interrupt vectors used by the
resident program.

Contents of WINDOWS:

Procedure MakeWindow(X1,Y1,X2,Y2,Foreground,Background : Word;Border : BorderType);

This procedure saves the current screen memory and creates a bordered
window. X1, Y1, X2, and Y2 are the same values used by Turbo's WINDOW
procedure. Foreground and Background are the color attributes of the
border. Border is the type of border desired. Possible border types

NONE - no border
SINGLE - single line
DOUBLE - double line
DOUBLETOP - double top lines, single side lines
DOUBLESIDE - double side lines, single top lines
SOLID - solid block (space character)

Example useage:


Procedure DrawBox(X1,Y1,X2,Y2,Forground,Background : Word;Border : BorderType);

Works just like MakeWindow but doesn't save the underlying screen and
doesn't use a matching RemoveWindow.

Procedure RemoveWindow;

Removes the current top window, does nothing if there isn't any windows
defined with the MakeWindow procedure.

Procedure SetCursor(Cursor : Word);

Sets the cursor shape. Some software packages turn off the cursor
so this is provided so you can set your prefered cursor shape. The
windowing package saves the cursor shape of the underlying screen so
there is no need to restore it.

Var VideoMode : Word;

A DOS variable that holds the current video mode. Use this to test
for and avoid popping in graphics modes.


POPDICE is a fully functional sample pop-up program. After loading, pressing
ALT-LeftShift-D will pop-up a fancy dice rolling program designed for war
games and roll-playing games.

NODICE will remove POPDICE from memory if it is safe to do safe. Alternately,
a second program, REMOVE, can be used to unload ANY resident program written
with this package. A companion batch file, NODICE.BAT, is used to drive the
universal program and to display the proper messages. REMOVE accepts a single
I.D. number on the command line. This is the same as the program's signature.

You must delete or rename NODICE.EXE for NODICE.BAT to work since DOS will
execute an EXE before a BAT file of the same name.


You MUST handle all possible errors. If at any time the program halts
due to a runtime, I/O, or critical error the system will probably crash.
Before the resident program is entered, Turbo's critical error handle
is restored so that you can query IOResult for errors.

Use the $M directive to reduce memory requirements. Slightly more than 4000
bytes are required for each window created by MakeWindow (to save the under-
lying screen). Make a high guess of memory requirements for your program
then double or triple it. Compile and run the program to make sure it runs.
If it doesn't increase memory. If it does run decrease it. Keep decreasing
the memory until the program crashes then increase memory and add a little
extra for slop.

You should test the video mode when your routine is first run. The windows
unit can not properly save graphics screens so you might want to beep and
exit. You could, of course, write your own windowing package that can save
graphics screens. This could be a problem with some of the new video modes
that have tremendous memory requirements.

Shift Keys

RightShift $01
LeftShift $02
Control $04
ALT $08

ScrollLock $10 { these four are not supported in this version }
NumLock $20 { " " " " " " " " }
CapLock $40 { " " " " " " " " }
Insert $80 { " " " " " " " " }

The shift status values are defined in the interface portion of the PopUp
unit. The values are already shifted to the left 8 bits to save you the
trouble. Simple add the different shift keys you want to the scan code
and pass that value to StayResident. For example, for a program to popup
when both shift keys are pressed as well as the period you would issue
the command:

StayResident(@MyPopUp,RightShift + LeftShift + $34);

The coding of the popup routines makes undefined keys possible, thus
reducing the chance of keyboard confict. For example the numeric pad
'5' (the center key) is undefined for most combinations. This allows
you to use combinations such as (Control + LeftShift + $4C) with a
high degree of certainty that it won't conflict with other programs.

Keyboard Scan Codes

0 $0B 6 $07 C $2E I $17 O $18 U $16
1 $02 7 $08 D $20 J $24 P $19 V $2F
2 $03 8 $09 E $12 K $25 Q $10 W $11
3 $04 9 $0A F $21 L $26 R $13 X $2D
4 $05 A $1E G $22 M $32 S $1F Y $15
5 $06 B $30 H $23 N $31 T $14 Z $2C

BS $0E
ESC $01

- $0C ` $29
= $0D \ $2B
[ $1A , $33
] $1B . $34
; $27 / $35
' $28

LeftShift $2A
RightShift $36
ALT $38
Space $39
CapLock $3A

F1 $3B F2 $3C F3 $3D F4 $3E F5 $3F
F6 $40 F7 $41 F8 $42 F9 $43 F10 $44

NumLock $45 ScrollLock $46 Home $47
UpArrow $48 PageUp $49 grey - $4A
RightArrow $4B Center $4C LeftArrow $4D
grey + $4E End $4F DownArrow $50
PageDown $51 Ins $52 Del $53

Version History

1.6 1 October 1988

Added experimental unload procedure. Minor cosmetic changes.
Improved support for conflicting hot-keys. Removed RestoreVectors
and placed in a separate unit.

1.5 20 September 1988

Code added to detect programs that have already been loaded, thus
preventing multiple loading of the same TSR. Minor bug fix.
Documentation corrections.

1.4 31 August 1988

All source code now included in the archive.
Removed the FREE unit due to problems. Use Mark/Release instead.

1.2 21 March 1988

Minor correction in the low-level popup code - not all of the
registers were being saved.

1.1 13 March 1988

Changed popup code so the user procedure is declared as FAR rather
than as INTERRUPT.

1.0 Original version


Advanced MS-DOS, Ray Duncan, Microsoft Press

The MS-DOS Encyclopedia, Microsoft Press

Magazine articles too numerous to list.


I wish to thank the many programmers who pioneered the development of
Terminate-and-Stay-Resident programs, on whom's shoulders I am standing.

Other Turbo Pascal units by Ross Neilson Wentworth
(## indicates a two digit version number)

TPENV## Easily access the environment. Includes a routine to automatically
search the PATH for a specified file. Other nice features.

VOLUME Add, read, change, delete the DOS volume label.

TEXT## Adds three new procedures for TEXT files, TEXTFILEPOS, TEXTFILESIZE
TEXTSEEK. Makes moving around in a text file possible.


Sidekick and Turbo Pascal are Trademarks or Registered Trademarks
of Borland International, Inc.

 December 5, 2017  Add comments

Leave a Reply