Dec 232017
Turbo Pascal TSR library. TSR management, hotkeys, etc. Excellent.
File TPPOP18C.ZIP from The Programmer’s Corner in
Category Pascal Source Code
Turbo Pascal TSR library. TSR management, hotkeys, etc. Excellent.
File Name File Size Zip Size Zip Type
-READ.ME 2136 769 deflated
CATALOG.LST 1844 909 deflated
CRIT.ASM 586 247 deflated
CRIT.OBJ 284 258 deflated
CURSOR.ASM 406 206 deflated
CURSOR.OBJ 190 175 deflated
DICE.PAS 9305 2787 deflated
DICE.TPU 8896 3822 deflated
FASTPUT.ASM 2027 562 deflated
FASTPUT.OBJ 365 316 deflated
NODICE.PAS 1174 513 deflated
POPDICE.PAS 2292 1001 deflated
POPUP.ASM 21346 5001 deflated
POPUP.DOC 14268 5524 deflated
POPUP.OBJ 1087 832 deflated
POPUP.PAS 4687 1424 deflated
POPUP.TPU 3408 1877 deflated
REMOVE.PAS 806 393 deflated
UNHOOK.PAS 4948 1451 deflated
UNHOOK.TPU 1888 970 deflated
UPPRCASE.ASM 486 226 deflated
UPPRCASE.OBJ 224 194 deflated
WINDOWS.PAS 12778 3300 deflated
WINDOWS.TPU 9792 4482 deflated

Download File TPPOP18C.ZIP Here

Contents of the POPUP.DOC file


Memory Resident PopUp Routines Version 1.8c
for Turbo Pascal Version 5.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 5.0 is required to use this package. TASM 1.0
or MASM 5.1 is required to to re-assemble the low-level modules.

If you find this code useful, please send $20 to the address below or
make a $20 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.
o Allows TSR's with conflicting hot-keys
o Simple program removal
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:

08h timer
09h keyboard
13h disk i/o
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 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 already been installed or an error has occured:

1 : PRINT.COM detected. Under DOS 2.x, 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
window. 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 activating 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. REMOVE accepts a single I.D. number on the command line.
This is the same as the program's signature.



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, POPUP.TPU's critical error handle
is restored so that you can query IOResult for errors.

Use the $M directive to reduce memory requirements. 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.8c 22 January 1989

Minor bug in the window package was corrected that would cause
window types of NONE not to be set properly.

1.8b 30 December 1988

Faster box drawing in the WINDOWS unit by using assembler routine.
When archive was updated several necessary files were inadvertantly
left out.

1.8 3 November 1988

Improved detection of unsafe unload conditions. Minor bug fixed
on saving and restoring the cursor shape. Made changes to source
so that it will assemble using Turbo Assembler.

1.7 16 October 1988

Removed the READKEY procedure. Instead, interrupt 16h is grabbed
to prevent resident program lock-outs. Changed to using interrupt
08h instead of 1Ch. For some reason, using the later with some
programs would cause the system to lock up.

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 Ported from Turbo Pascal 3.0, changed name, and restarted version

Previously: Used a lot of INLINE code under Turbo Pascal 3.x.


Advanced MS-DOS, Ray Duncan, Microsoft Press

The MS-DOS Encyclopedia, Microsoft Press

Magazine articles too numerous to list.

Tidbits of knowledge gained from the Fido/Opus Network.


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


Legal Stuff

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

 December 23, 2017  Add comments

Leave a Reply