A TSR program (often memory-resident program in German-speaking countries ) is a DOS program that remains in memory after execution and can be called up again if necessary.
The abbreviation TSR comes from the DOS environment and stands for "Terminate and Stay Resident". The concept of memory residency was developed as a forerunner to later multitasking applications so that certain tasks (clock, drivers, system services) can run permanently as a background process, or simply to expand or replace the functionality of the operating system.
Development concepts for background processes
This became possible and effective at the end of the 1970s mainly through the development of powerful 16-bit processors and the interrupt architecture, with the help of which a large number of devices on a computer can be addressed at regular intervals, relatively independently of the operating system. Since communication between these devices and the processor cannot take place without suitable "management programs" (device drivers), this offered a new way of writing programs independently of hardware components that remain in the memory and are repeatedly called in the background by the interrupts .
Forerunner in home computers
The interrupt control is not absolutely necessary. Most operating systems were already based on 8-bit processors such as the Zilog Z80 with modular processes, e.g. B. equipped for memory and image management. Since these are processed at regular intervals via jump addresses , there are basically two options for other applications to participate in this concept (simplified description):
- In operating systems with changeable jump addresses in the RAM memory (not a matter of course at that time), resident programs redirect them to themselves, only then does the jump to the system process take place, the address of which is known from the jump address stored in RAM before redirection, which is the resident one Program notices. So you switch between an application program and the system process.
- The same option can also be used with some home computers, the entire operating system of which, as was quite common at the time, is housed in read- only memory ( ROM ) (like the system's firmware today ). If the operating system writes jump variables to the RAM when the system is started, these jump addresses can be changed as described above.
- If these jump addresses are called directly from the ROM, the application must completely replace the actual operating system when it starts and call the system-relevant background processes in the ROM itself in order to keep itself and the system viable. A vivid example of this is a stopwatch in the chess program of the Sinclair ZX-Spectrum. If the player stops the assembler part during a move in order to temporarily store the score under a basic program, the interpreter regularly returns control to the chess clock, which then continues to run.
The TSR programs under DOS
A TSR program is loaded and, for the time being, processed like any normal program. Normally, a DOS program ended by calling the DOS operating system function (part of the software - interrupt 21h) interrupt 21h, function 4Ch or just interrupt 20h. DOS then releases the memory and other resources used by the program. With TSR programs, the "normal" (transient) execution section is also terminated in memory (sometimes even the memory is released), but a different DOS function is called for this; this is either interrupt 27h or interrupt 21h, function 31h. The “special” (resident) TSR part, a small control center, then remains active in the memory so that it can be called up again if necessary.
So-called interrupt bending takes place so that this TSR service can remain active. The jump address to the original code is obtained from the interrupt vector table of the system (on DOS computers always in the first KB of the memory), stored in the new interrupt vector, and finally the table entry for the interrupt is rewritten to its own vector. When the interrupt is called (possibly a software interrupt ), the address of the part of the TSR that has remained resident is read from the interrupt vector table and this is executed. Depending on the type of TSR (and, in the case of software interrupts, depending on the function called), the resident part can then also execute the previous interrupt vector.
A very popular example is the timer interrupt (Interrupt 1Ch Timer) for a resident clock. This happens almost exactly as described above for home computers, but with the help of hardware-controlled interrupts and thus more independent of software weaknesses. This makes TSR programs much more stable. Probably the most frequently "bent" software interrupt under DOS is the DOS function interrupt (interrupt 21h DOS), which contains most of the DOS operating system functions for other programs. TSR programs can, for example, monitor, record, prohibit certain functions or add functions that are not actually present in the loaded DOS.
Device drivers are another application example for TSR programs. Simple examples of this are DOS mouse drivers (hardware interrupt 14h - serial interface, as well as software interrupt 33h - mouse functions for DOS programs), as well as keyboard and EGA drivers, drivers for the extended memory, etc. When setting up a computer, you should be aware of The special behavior of TSR programs, which can only be loaded into conventional memory, basically load larger TSR programs before smaller ones, as the gaps that their transient parts leave behind can possibly be filled by the smaller TSR programs - vice versa it happens that the larger ones no longer fit into the memory, because the “gaps” that the transient parts of the smaller ones leave behind are no longer sufficient for the larger ones. Some TSRs avoid the occurrence of memory gaps by cleverly shifting the interrupt vectors to be installed.
A widespread utility program that worked according to the TSR principle was SideKick , which made it possible to bring printouts onto paper in landscape format, even if neither the respective application program nor its printer driver offered this option.
- Interrupts and DOS system programming (English; Memento on archive.org)