#include "dos.h"

struct INTERRUPT

      {

            unsigned ax,bx,cx,dx,cs,ip,es,ds,bp,si,di,fl;

      };

void interrupt hdprot(struct INTERRUPT);

void interrupt (*prev)();

 

main()

{

//AIM : to write protect the hard disk

      unsigned long far *inthd;

      inthd=(unsigned long far*)(0x13*4);

      prev=(void (interrupt far*)())*inthd;

      *inthd=(unsigned long)hdprot;

      keep(0,500);

      return 0;

}

 

void interrupt hdprot(struct INTERRUPT r)

{

      if((_AH==3)|(_AH==5)|(_AH=0x0b))//if write, format, or long write

            {

                                    asm stc; //set carry , saying that write operation failed

                                    _FLAGS=r.fl;

                                //asm pushf;

                                    //asm pop r.fl;  // both thease to move flag into r.flag

                                    return;

            }

      _AX=r.ax;

      _BX=r.bx;

      _CX=r.cx;

      _DX=r.dx;

      _ES=r.es;

      (*prev)();

      //asm pushf;

      //asm pop r.fl;

      _FLAGS=r.fl;

      r.es=_ES;

      r.dx=_DX;

      r.cx=_CX;

      r.bx=_BX;

      r.ax=_AX;

}//void inturrept hdprot()