Thursday, January 3, 2008

System Side Programming in Turbo C

/* 1.INTERRUPT TO READ BASE MEMORY SIZE */
int baseMemory()
{
int memsize;
asm int 18h
asm mov memsize,ax
return(640);
/* return (memsize); */
}

/* 2.INTERRUPT TO READ CURSOR POSITION */
void setCursorPos()
{
i.h.ah=2;
i.h.dh=20;
i.h.dl=6;
int86(0x16,&i,&o);
}

/* 3.INTERRUPT TO READ CURSOR POSITION */
void readCursorPos(unsigned char *page_no,unsigned char *start_line,unsigned char *end_line,unsigned char *row,unsigned char *coloumn)
{
unsigned char val,sl,el,r,c;
val=*page_no;
asm mov ah,0x03
asm mov bh,val
asm int 10h
asm mov sl,ch
asm mov el,cl
asm mov r,dh
asm mov c,dl
*start_line=sl;
*end_line=el;
*row=r;
*coloumn=c;
}


/* 4.INTERRUPT TO SET VIDEO MODE */
void setVideoMode(unsigned char videomode)
{
asm mov ah,0h
asm mov al,videomode
asm int 10h
}

/* 5.INTERRUPT TO SET CURSOR SIZE */
void setCursorSize(unsigned char start_scan_line,unsigned char end_scan_line)
{
asm mov ah,0x01
asm mov ch,start_scan_line
asm mov cl,end_scan_line
asm int 10h
}


/* 6.INTERRUPT TO SCROLL WINDOW UP */
void scrollWindowUp(unsigned char no_lines,unsigned char filler,unsigned char upper_row,unsigned char left_coloumn,unsigned char lower_row,unsigned char right_coloumn)
{
asm mov ah,0x06
asm mov al,no_lines
asm mov bh,filler
asm mov ch,upper_row
asm mov cl,left_coloumn
asm mov dh,lower_row
asm mov dl,right_coloumn
asm int 10h
}


/* 7.INTERRUPT TO SCROLL WINDOW DOWN */
void scrollWindowDown(unsigned char no_lines,unsigned char filler,unsigned char upper_row,unsigned char left_coloumn,unsigned char lower_row,unsigned char right_coloumn)
{
asm mov ah,0x07
asm mov al,no_lines
asm mov bh,filler
asm mov ch,upper_row
asm mov cl,left_coloumn
asm mov dh,lower_row
asm mov dl,right_coloumn
asm int 10h
}

/* 8.INTERRUPT TO PRINT SCREEN */
void printScreen()
{
asm int 5h
}


/* 9.INTERRUPT TO WRITE PIXEL */
void writePixel(pixel_value,pixel_row,pixel_col,page)
unsigned char pixel_value,page;
unsigned int pixel_row,pixel_col;
{
asm mov ah,0x0c
asm mov al,pixel_value
asm mov cx,pixel_col
asm mov dx,pixel_row
asm mov bh,page
asm int 10h
}


/* 10.INTERRUPT TO READ PIXEL */
void readPixel(unsigned char *pixel_value,unsigned int pixel_row,unsigned int pixel_col,unsigned char page)
{
unsigned char val;
asm mov ah,0x0d
asm mov cx,pixel_col
asm mov dx,pixel_row
asm mov bh,page
asm int 10h
asm mov val,al
*pixel_value=val;
}


/* 11.INTERRUPT TO GET PERIPHERAL EQUIPMENT LIST */
int getPeripheralEquipList()
{
int k;
asm int 11h
asm mov k,ax
return(k);
}



/* 12.INTERRUPT TO GET DOS VERSION */
int getDosVersion()
{
asm mov ah,0x30
asm int 21h
return(5);
/* return _AH; */
}


/* 13.INTERRUPT TO SET CTRL BREAK OFF */
int set_CTRL_BREAK_OFF()
{
asm mov ah,0x33
asm mov al,1
asm mov dl,0
asm int 21h
if(_DL==0)
return 1;
else
return 0;
}


/* 14.INTERRUPT TO SET CTRL BREAK ON */
int set_CTRL_BREAK_ON()
{
asm mov ah,0x33
asm mov al,1
asm mov dl,1
asm int 21h
if(_DL==1)
return 1;
else
return 0;
}


/* 15.INTERRUPT TO REBOOT */
void reBoot()
{
asm int 0x19;
}

/*void reStart()
{
void far (*p)();
p=0xffff0000;
(*p)();
} */

/* 16.INTERRUPT TO GET EXTENDED MEMORY SIZE */
void get_Extended_Memory_Size()
{
asm mov ah,0x88
asm int 15h
}


/* 17.INTERRUPT TO READ SCAN ASCII CODE */
void readScanAscii(unsigned char *scan,unsigned char *ascii)
{
unsigned char sc,as;
asm mov ah,0x00
asm int 0x16
asm mov sc,ah
asm mov as,al
*scan=sc;
*ascii=as;
}


/* 18.INTERRUPT TO MAKE DIRECTORY */
int makeDirectory(char *dname)
{
struct SREGS s;
union REGS i,o;
i.h.ah=0x39;
s.ds=FP_SEG(dname);
i.x.dx=FP_OFF(dname);
int86x(0x21,&i,&o,&s);
if (o.x.cflag==0)
return 1;
else
return 0;

}


/* 19.INTERRUPT TO REMOVE DIRECTORY */
int removeDirectory(char *dname)
{
struct SREGS s;
union REGS i,o;
i.h.ah=0x3a;
s.ds=FP_SEG(dname);
i.x.dx=FP_OFF(dname);
int86x(0x21,&i,&o,&s);
if (o.x.cflag==0)
return 1;
else
return 0;
}


/* 20.INTERRUPT TO DELETE FILE */
int deleteFile(char *fname)
{
union REGS i,o;
struct SREGS s;

i.h.ah=0x41;
s.ds=FP_SEG(fname);
i.x.dx=FP_OFF(fname);
int86x(0x21,&i,&o,&s);
if(o.x.cflag==0)
return 1;
else
return 0;
}


/* 21.INTERRUPT TO GET FILE ATTRIBUTE */
int getFileAttribute(char *fname)
{
union REGS i,o;
struct SREGS s;
i.h.ah=0x43;
i.h.al=0;
s.ds=FP_SEG(fname);
i.x.dx=FP_OFF(fname);
int86x(0x21,&i,&o,&s);
if(o.x.cflag==0)
return o.x.cx;
else
return 0;
}


/* 22.INTERRUPT TO SET FILE ATTRIBUTE */
int setFileAttribute(char *fname,int attr)
{
union REGS i,o;
struct SREGS s;
i.h.ah=0x43;
i.h.al=1;
i.x.cx=attr;
s.ds=FP_SEG(fname);
i.x.dx=FP_OFF(fname);
int86x(0x21,&i,&o,&s);

if(o.x.cflag==0)
return o.x.cx;
else
return 0;
}


/* 23.INTERRUPT TO GET CURRENT DIRECTORY */
int getCurrentDirectory(char *dname)
{
union REGS i,o;
struct SREGS s;

i.h.ah=0x47;
i.h.dl=0x4;
s.ds=FP_SEG(dname);
i.x.dx=FP_OFF(dname);
int86x(0x21,&i,&o,&s);
if(o.x.cflag==0)
return 1;
else
return o.x.ax;
}


/* 24.INTERRUPT TO CREATE BUTTON */
void rectbox(int x1,int y1,int x2,int y2,int color)
{
setfillstyle(SOLID_FILL,color);
bar(x1,y1,x2,y1+2);
bar(x1,y1,x1+2,y2);
bar(x2,y1,x2+2,y2);
bar(x1,y2,x2+2,y2+2);
}


/* 25.INTERRUPT TO PRESS A BUTTON */
void pressedButton(int x1,int y1,int x2,int y2,int bcolor,int fillstyle)
{
setfillstyle(SOLID_FILL,fillstyle);
bar(x1,y1,x2,y2);
setcolor(bcolor);
line(x2,y2,x2,y1);
line(x2+1,y2,x2+1,y1);
line(x2,y2,x1,y2);
line(x2,y2+1,x1,y2+1);
}


/* 26.INTERRUPT TO DEPRESSED BUTTON */
void depressedButton(int x1,int y1,int x2,int y2,int bcolor,int fillstyle)
{
setfillstyle(SOLID_FILL,fillstyle);
bar(x1,y1,x2,y2);
setcolor(bcolor);
line(x1,y1,x1,y2);
line(x1+1,y1,x1+1,y2);
line(x1,y1,x2,y1);
line(x1,y1+1,x2,y1+1);
}


/* 27.MOUSE INTERRUPT */
void initMouse()
{
_AX=0;
geninterrupt(0x33);
}


/* 28.INTERRUPT TO SHOW MOUSE POINTER */
void showMousePtr()
{
_AX=1;
geninterrupt(0x33);
}


/* 29.INTERRUPT TO GET MOUSE POINTER */
void getMousePos(int *x,int *y,int *b)
{
union REGS i,o;
i.x.ax=3;
int86(0x33,&i,&o);
*x=o.x.cx;
*y=o.x.dx;
*b=o.x.bx;
}


/* 30.INTERRUPT TO HIDE MOUSE POINTER */
void hideMousePtr()
{
_AX=2;
geninterrupt(0x33);
}


/* 31.INTERRUPT TO SET MOUSE POINTER */
void setMousePtrPos(int x,int y)
{
_AX=4;
_CX=x;
_DX=y;
geninterrupt(0x33);
}


/* 32.INTERRUPT TO RESTRICT MOUSE POINTER */
void restrictMousePtr(int x1,int y1,int x2,int y2)
{
union REGS i,o;
i.x.ax=7;
i.x.cx=x1;
i.x.dx=y1;
int86(0x33,&i,&o);
i.x.ax=8;
i.x.cx=x2;
i.x.dx=y2;
int86(0x33,&i,&o);
}

void setMousePos(int x,int y)
{
_AX=4;
_CX=x;
_DX=y;
geninterrupt(0x33);
}

No comments: