Tải bản đầy đủ (.doc) (8 trang)

Tài liệu Báo cáo tiểu luận môn Hệ Điều Hành ppt

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (83.99 KB, 8 trang )

Báo cáo tiểu luận môn Hệ Điều Hành
Sinh viên : Nguyễn Đức Đài
06119009
GVHD: Thầy Khoan.
Gới thiệu đề tài:
Trong quá trình học trên lớp ,tìm hiểu và tham khảo kiến thức về môn Hệ Điều
Hành,em thấy mảng đề tài về MOUSE là khá hay. Vì vậy với những kiến thức có
được,em đưa ra đề tài gồm nội dung sau:
• Hiển thị biểu tượng MOUSE trong MS DOS.
• Hiển thị vị trí của MOUSE trong khi di chuyển.
• Khi click MOUSE trái sẽ hiển thị ra vị trí đã click.
• Khi click MOUSE phải sẽ thoát khỏi chương trình.
Cách làm: int 33h
Công cụ: Borland c++3.1
Chương trình:
Chương trình này kiểm tra xem co mouse kết nối với PC chưa.( tìm driver của mouse)
#include <dos.h>#include<stdio.h>#include<conio.h>
void main()
{
union REGS i,o;
i.x.ax=0;
int86(0x33,&i,&o);
if(o.x.ax==0)
printf("No Mouse Available ");
else
printf("Mouse Available "); getch();
}MOUSE1.EXE
Chương trình trên đưa ra 2 giá trị của loại union REGS trong dos.h,bao gồm 2
structs (struct WORDREGS x, struct BYTEREGS h). Hai structures này chứa một
vài giá trị 1-byte long và 2-byte long đại diện cho thanh ghi của CPU. Đưa giá trị
0 (hàm con) vào thanh ghi AX và gọi chuột bằng interrupt(33h),chúng ta có thể


kiêm tra chuột có kết nối hay chưa. Ta dùng hàm int86() để gọi interrupt. Hàm
int86() chứa 3 đối số: interrupt 33h và 2 kiểu giá trị union REGS. Nếu ko có
chuột,nó returns 0 vào thanh ghi AX. Mọi giá trị trả về được dung truy cập vào 'o'
. Điều đó giải thích vì sao ta có câu lệnh o.x.ax==0.
2) Program to show the mouse pointer
Chương trình đầu chỉ hiển thị có driver cua mouse hay chưa,nếu có thì chúng ta
vẫn chưa thấy. Để hiện thị,chúng ta sử dụng i.x.ax=1
#include <dos.h>#include<stdio.h>#include<conio.h>#include<stdlib.h>
void main()
{
union REGS i,o;
i.x.ax=0;
int86(0x33,&i,&o);
if(o.x.ax==0)
{
printf("No Mouse Available ");
exit(1);
}
i.x.ax=1; //show mouse!!!!!!!!!
int86(0x33,&i,&o);
getch();
}MOUSE2.EXE
3) Program to hide the mouse pointer
#include <dos.h>#include<stdio.h>#include<conio.h>#include<stdlib.h>
void main()
{
union REGS i,o;

clrscr();


i.x.ax=0;
int86(0x33,&i,&o);

if(o.x.ax==0)
{
printf("No Mouse Available ");
exit(1);
}
i.x.ax=1;
int86(0x33,&i,&o);
gotoxy(24,23);
printf("Press any key to hide mouse cursor ");
getch();

i.x.ax=2; //hide mouse!!!!!
int86(0x33,&i,&o);

gotoxy(10,23);
printf("Mouse cursor is hidden !! Press any key to terminate the program ");
getch();
}MOUSE3.EXE
Chương trình trên dùng hàm con 2 và gọi ngắt để giấu con trỏ chuột.
5) Program to print which mouse button is pressed
#include <dos.h>#include<stdio.h>#include<conio.h>#include<stdlib.h>
void main()
{
union REGS i,o;
int button;

clrscr();


i.x.ax=0;
int86(0x33,&i,&o);

if(o.x.ax==0)
{
printf("No mouse available ");
exit(1);
}

i.x.ax=1;
int86(0x33,&i,&o);

gotoxy(24,23);
printf("Press any key to exit ");

while(!kbhit())
{
i.x.ax=3;
int86(0x33,&i,&o);

button=o.x.bx&7;

gotoxy(23,11);
switch(button)
{
case 1:
printf("Left button pressed ");
break;


case 2:
printf("Right button pressed ");
break;

case 4:
printf("Middle button pressed ");
break;

case 3:
printf("Left and Right buttons pressed ");
break;

case 5:
printf("Left and Middle buttons pressed ");
break;

case 6:
printf("Right and Middle buttons pressed ");
break;

case 7:
printf("All the three buttons pressed ");
break;

default:
printf("No button pressed ");
}
}

i.x.ax=2;

int86(0x33,&i,&o);
getch();
}MOUSE5.EXE
Chương trình trên có thêm 1 vòng lặp phụ. Trong đó ta dùng lệnh i.x.ax=3 và gọi
ngắt. trong đó ta đã dung 3 hàm con giống nhau và gọi ngắt chuột. Hàm này trả về
thong tin nut nhấn vào BX. Toàn bộ thong tin về nut nhấn chúa trong 3 bit đầu của
BX. Sau đó chúng ta AND BX với 7 to separate the first 3 bits và chứa giá trị vào
button.
Nếu giá trị của bit đầu là 1,nut trái nhấn,0 la không nhấn ,giá trị bit 2 là 1 là phải
nhấn,0 là không nhấn. Nếu bit cuối là 1 là nút giữa nhấn,0 là ko nhấn.
7) Hiển thị chuột dưới dạng đồ họa
#include <graphics.h>#include <dos.h>#include<stdio.h>#include<conio.h>#include<stdlib.h>
void main()
{
int gd=DETECT,gm;
union REGS i,o;

initgraph(&gd,&gm,"d:\\borlandc\\bgi"); //hiển thị đồ họa

i.x.ax=0;
int86(0x33,&i,&o);

if(o.x.ax==0)
{
printf("No Mouse Avaialable ");
restorecrtmode();
exit(1);
}

i.x.ax=1;

int86(0x33,&i,&o);

outtextxy(100,400,"Mouse Pointer in graphics mode!!Press any key to exit");
getch();

i.x.ax=2;
int86(0x33,&i,&o);

restorecrtmode(); }
MOUSE7.EXE
ở chương trình này ,ta dung thư viện chuẩn là hàm initgraph() của hệ thống đò
họa. hàm này có 3 đối số: graphics driver(công cụ đồ họa), graphics mode(chế độ
đồ họa ),đường dẫn vào thư mục. By using DETECT,ta nói hàm chọn công
cụ(driver) phù hợp cho nó. Khi dùng DETECT ,không cần chọn bất kỳ graphics
mode nào.
9) Free-hand drawing//tham khảo
#include <graphics.h>#include
<dos.h>#include<stdio.h>#include<conio.h>#include<stdlib.h>
union REGS i,o;

void main()
{

int gd=DETECT,gm,button,x1,y1,x2,y2;

initgraph(&gd,&gm," d:\\borlandc\\bgi ");

i.x.ax=0;
int86(0x33,&i,&o);


if(o.x.ax==0)
{
printf("No Mouse is available ");
exit();
restorecrtmode();
}

outtextxy(230,400,"Press any key to exit ");

while(!kbhit())
{
show_mouse();
get_mouse_pos(&x1,&y1,&button);

x2=x1;
y2=y1;

while(button==1)
{
hide_mouse();
line(x1,y1,x2,y2);

x1=x2;
y1=y2;

get_mouse_pos(&x2,&y2,&button);
}
}
restorecrtmode();
}


void show_mouse()
{
i.x.ax=1;
int86(0x33,&i,&o);
}

void hide_mouse()
{
i.x.ax=2;
int86(0x33,&i,&o);
}

void get_mouse_pos(int *x,int *y,int *button)
{
i.x.ax=3;
int86(0x33,&i,&o);

*x=o.x.cx;
*y=o.x.dx;
*button=o.x.bx&1;
}MOUSE9.EXE
10/ Chương trình hiện tọa độ chuột trên màn hình
#include <dos.h>#include <stdio.h>#include <conio.h>#include <string.h>#include <stdlib.h>
char * Str_Pos_Mouse = "00:00";
char * Str_Menu = "Quit ";
char Colum_Menu = 76;
char Row_Menu = 1;
const char Left_Click = 1;
int MouseX, MouseY, MouseClick;

char Num_Mouse_Button;
void WriteXY(char x,char y, char * Msg);
void Show_Menu(char On_Menu);
void Clear_Screen();
void Setup_Mouse();
void Get_Pos_Mouse(int * MP_x,int * MP_y,int * St_Button);
void Change_Str_Pos_Mouse(int x,int y);
int ShowFile(char * StrFileName);
void Event_Left_Click(char _Is_OnMenu);
int Is_OnMenu(int x, int y);
void Event_Mouse(int MouseX,int MouseY,int MouseClick);
void main()
{
Clear_Screen();
Setup_Mouse();
do
{
Get_Pos_Mouse(&MouseX, &MouseY,&MouseClick);
Change_Str_Pos_Mouse(MouseX, MouseY);
Event_Mouse(MouseX, MouseY, MouseClick);
Show_Menu(Is_OnMenu(MouseX, MouseY));
} while (1);
}
void Clear_Screen()
{
textcolor(15);
textbackground(0);
clrscr();
}
void WriteXY(char x,char y,char * Msg)

{
gotoxy(x,y);
cprintf("%s",Msg);
}
void Show_Menu(char On_Menu)
{
WriteXY(Colum_Menu,Row_Menu,Str_Pos_Mouse);
WriteXY(Colum_Menu,Row_Menu+1,Str_Menu);
}
int Is_OnMenu(int x, int y)
{
int result;
result=0;
if ((x+1 >= Colum_Menu) && (x+1 <= Colum_Menu + 4)
&& ( y+1 >= Row_Menu + 1) && (y+1 <= Row_Menu+ 3 ))
result = y - Row_Menu +1;
return(result);
}
void Setup_Mouse()
{
union REGS _regs;
_regs.x.ax = 0x0000;
int86(0x33, &_regs, &_regs);
Num_Mouse_Button = _regs.h.bl;
_regs.x.ax = 0x0001;
int86(0x33, &_regs, &_regs);
}
void Get_Pos_Mouse(int * MP_x,int * MP_y,int * St_Button)
{
union REGS _regs;

_regs.x.ax = 0x0003;
int86(0x33,&_regs,&_regs);
*MP_x = _regs.x.cx / 8;
*MP_y = _regs.x.dx / 8;
*St_Button= _regs.x.bx;
}
void Change_Str_Pos_Mouse(int x,int y)
{
Str_Pos_Mouse[0]=(x/10 + 0x30);
Str_Pos_Mouse[1]=(x%10 + 0x30);
Str_Pos_Mouse[3]=(y/10 + 0x30);
Str_Pos_Mouse[4]=(y%10 + 0x30);
}
void Event_Left_Click(char _Is_OnMenu)
{
switch (_Is_OnMenu)
{
case 1 : exit(0); break;
}
}
void Event_Mouse(int MouseX,int MouseY,int MouseClick)
{
char _Is_OnMenu ;
_Is_OnMenu = Is_OnMenu(MouseX, MouseY);
if ( _Is_OnMenu != 0)
switch (MouseClick)
{
case 1 : Event_Left_Click(_Is_OnMenu); break;
}
}MOU.EXE

×