/*--------------------------------------------------------------------------*/
/*	Program name: 4_3_4.C                                               */
/*	Compile mode: Tiny                                                  */
/*	Image   file: None                                                  */
/*	Note        : List NewInt13() procedure and its subroutines only.   */
/*--------------------------------------------------------------------------*/


/*----------------- Data area ----------------------------------------------*/

struct	Reg_buf	{	unsigned	ax_1,bx_1,cx_1,dx_1;
			unsigned	ax_2,bx_2,cx_2,dx_2;
			unsigned	flag_2,bytes,names;
		}	reg_buf[100];
char	name_buf[0x1000];
int	reg_count;

/*----------------- Utilities ----------------------------------------------*/

void	Dump_msg(void)
{	int		i,j,len;
	unsigned	*ptr;

	Printf("\n\r");
	Printf(" AX   BX   CX   DX   AX   BX   CX   DX  FLAG BYTE NAME\n\r");
	for(i=0,ptr=(unsigned *)reg_buf;i<reg_count;i++)
	{	for(j=0;j<11;j++,ptr++)	Printf("%04X ",*ptr);
		Printf("\n\r");
	}


	Printf("\n\r");
	for(i=0;(len=strlen(name_buf+i))!=0;i+=len+1)
		Printf("%s\n\r",name_buf+i);
}

/*----------------- NewInt13 -----------------------------------------------*/

void	interrupt	NewInt13( unsigned BP,unsigned DI,unsigned SI,
				  unsigned DS,unsigned ES,unsigned DX,
				  unsigned CX,unsigned BX,unsigned AX,
				  unsigned IP,unsigned CS,unsigned FLAGS )
{	static	union	REGS	regs;
	static	struct	SREGS	sregs;


	if ((DX%256!=0)||(AX/256==0)||(*InDos)||(Busy))	goto	i13_done;

	Busy=1;

	regs.x.ax=AX;
	regs.x.bx=BX;
	regs.x.cx=CX;
	regs.x.dx=DX;
	regs.x.si=SI;
	regs.x.di=DI;
	regs.x.flags=FLAGS;
	sregs.es=ES;
	sregs.ds=DS;

	OLD_SS=_SS;
	OLD_SP=_SP;

	disable();
	_SS=TSR_SS;
	_SP=TSR_SP;
	enable();



	reg_buf[reg_count].ax_1=regs.x.ax;
	reg_buf[reg_count].bx_1=regs.x.bx;
	reg_buf[reg_count].cx_1=regs.x.cx;
	reg_buf[reg_count].dx_1=regs.x.dx;
	int86x(0x13,&regs,&regs,&sregs);
	reg_buf[reg_count].ax_2=regs.x.ax;
	reg_buf[reg_count].bx_2=regs.x.bx;
	reg_buf[reg_count].cx_2=regs.x.cx;
	reg_buf[reg_count].dx_2=regs.x.dx;
	reg_buf[reg_count].flag_2=regs.x.flags;
	if (reg_count<99)	reg_count++;



	disable();
	_SS=OLD_SS;
	_SP=OLD_SP;
	enable();

	AX=regs.x.ax;
	BX=regs.x.bx;
	CX=regs.x.cx;
	DX=regs.x.dx;
	SI=regs.x.si;
	DI=regs.x.di;
	FLAGS=regs.x.flags;
	ES=sregs.es;
	DS=sregs.ds;

	Busy=0;

	return;




i13_done:
	_SP=_SP-6;
	_BP=_BP-6;
	BP=DS;
	DI=ES;
	SI=DX;
	DS=CX;
	ES=BX;
	DX=AX;
	CX=IP;
	BX=CS;
	AX=FLAGS;
	_BP=_BP+6;
	CX=(unsigned int)OldInt13;
	BX=(unsigned long)OldInt13 / 65536;
	AX=FLAGS;
	_BP=_BP-6;
}

