/* PSP.C */

#include <stdlib.h>
#include <dos.h>
#include "tsr.h"

#define GET_PSP_DOS2   0x51
#define GET_PSP_DOS3   0x62
#define SET_PSP        0x50

static union  REGS regs;

/*****
Function: GetPSP - returns current PSP
*****/ 
unsigned GetPSP(void)
{
    if (_osmajor == 2)
    {   
        if (! crit_err_ptr) /* must not have called InitInDos */
            return 0;

        *crit_err_ptr = 0xFF;   /* force use of proper stack */ 
        regs.h.ah = GET_PSP_DOS2; 
        intdos(&regs,&regs);
        *crit_err_ptr = 0;
    }
    else
    {
        regs.h.ah = GET_PSP_DOS3;
        intdos(&regs,&regs);
    }
    
    return regs.x.bx;
}

/*****
Function: SetPSP - sets current PSP
*****/ 
void SetPSP(unsigned segPSP)
{
    if (!crit_err_ptr)           /* must not have called InitInDos */
        return;

    *crit_err_ptr = 0xFF;        /* force use of correct stack    */
    regs.h.ah = SET_PSP;      
    regs.x.bx = segPSP;          /* pass segment value to set     */

    intdos(&regs,&regs);
    *crit_err_ptr = 0;
}

