19.5.3 Preserving Existing Data

A TSR requires its own disk transfer area (DTA) if it calls DOS functions that access the DTA. These include file control block functions, as well as Functions 11h, 12h, 4Eh, and 4Fh. The TSR must switch to a new DTA to avoid overwriting the one belonging to the interrupted process. On becoming active, the TSR calls Function 2Fh to obtain the address of the current DTA. The TSR stores the address and then calls Function 1Ah to establish a new DTA. Before returning, the TSR again calls Function 1Ah to restore the address of the original DTA.

DOS versions 3.1 and later allow a TSR to preserve extended error information. This prevents the TSR from destroying the original information if it commits a DOS error.

The TSR retrieves the current extended error data by calling DOS Function 59h. It then copies registers AX, BX, CX, DX, SI, DI, DS, and ES to an 11-word data structure in the order given. DOS reserves the last three words of the structure, which should each be set to zero. Before returning, the TSR calls Function 5Dh, with AL equalling 0Ah and DS:DX pointing to the data structure. This call restores the extended error data to their original state.