Giao tiếp máy tính với vi xử lý 8085

Sơ đồ khối trên hình 5. trình bày hai cổng 8 bit (A và B) và hai cổng 4 bit (CU và CL) bộ điện tuyến dữ liệu, và logic điều khiển. Hình 5.9 (b) trình bày một sơ đồ đơn giản hóa nhưng mở rộng của cấu trúc bên trong, chứa một thanh ghi điểu khiển. Sơ đồ khối này chứa tất cả các phần tử của một thiết bị lập trình; cổng C thực hiện chức năng tương tự chức năng của thanh ghi trạng

doc96 trang | Chia sẻ: Dung Lona | Lượt xem: 1494 | Lượt tải: 0download
Bạn đang xem trước 20 trang tài liệu Giao tiếp máy tính với vi xử lý 8085, để xem tài liệu hoàn chỉnh bạn click vào nút DOWNLOAD ở trên
start = clock(); do { fread(&c,1,1,f); end = clock(); }while(c!='\''&&(period=(end - start) / CLK_TCK)<10); if(period>=10) goto Error; fseek(f,-5,SEEK_CUR); fread(buf,4,1,f); buf[4]='\0'; HideMouse(); strcpy(End_hex,buf); strcat(buf," Hex"); outtextxy(170,178,buf); for (FindPos=3;FindPos>=0;FindPos--) for(FindValue=0;FindValue<22;FindValue++) if(buf[FindPos]==KyTu_Hex[FindValue]) Value2+=pow(16,(3-FindPos))*Gtri_Dec[FindValue]; End_address=(unsigned int)Value2; Value1=Value2-Value1+1; sprintf(Total,"%0.0f bytes",Value1); outtextxy(160,198,Total); outtextxy(260,250,buf); ShowMouse(); while(0) { Error: strcpy(buf,"error"); setfillstyle(SOLID_FILL,CYAN); HideMouse(); bar(155,155,245,210); outtextxy(200,158,buf); outtextxy(200,178,buf); outtextxy(200,198,buf); ShowMouse(); } fcloseall(); } } else { OutMessage(""); } } } } if(kkkk==27) { HideMouse(); if(!OutError("Do you want to quit ?")) kkkk=0; ShowMouse(); } }while(kkkk!=27); } //--------------------------------------------------------- int TestPressedButton(int x,LPEVENT lpEvent)//kiem tra cac nut { if(lpEvent->Msg==1) { for(int i=0;i<x;i++) if(But[i].Left()Posx&&But[i].Top()Posy&&But[i].Right()>=lpEvent->Posx&&But[i].Bottom()>=lpEvent->Posy) { HideMouse(); But[i].PressButton(); delay(100); But[i].OutButton(); if(i==1) { if(OutError("Do you want to quit ?")==0) return -1; closegraph(); exit(1); } ShowMouse(); return i; } } return -1; } //--------------------------------------------------------- int TestPressTexbox(int x,LPEVENT lpEvent,char layra[],unsigned *attribp) { *attribp=0; if(lpEvent->Msg==1) { for(int i=0;i<x;i++) if(Box[i].Left()Posx&&Box[i].Top()Posy&&Box[i].Right()>=lpEvent->Posx&&Box[i].Bottom()>=lpEvent->Posy) { HideMouse();//giau chuot de khong bi vet lem mau o vi tri chuot char LastName[100]; Box[i].GetS(LastName); OutMessage("Enter a file name. Press Enter to finish, Esc to ignore."); Box[i].Path();//lay Path vao bien S cua TEXTBOX Box[i].OutTextBox(); Box[i].GetS(layra);//lay ra text da nhap vao //tao chuan cho chuoi Path if(layra[strlen(layra)-1]=='>')//gat bo dau \> sau thu muc nhung van giu lai doi voi o dia if(layra[strlen(layra)-2]=='\\') if(layra[strlen(layra)-3]==':')//dang a:\> layra[strlen(layra)-1]='\0';//ra a:\ else //dang a:\fname\> layra[strlen(layra)-2]='\0';//ra dang a:\fname else layra[strlen(layra)-1]='\0';//bo dau > if(layra[strlen(layra)-1]=='\\')//gat bo dau \ sau thu muc nhung van giu lai doi voi o dia if(layra[strlen(layra)-2]!=':')//dang a:\fname\ layra[strlen(layra)-1]='\0'; if(layra[strlen(layra)-1]==':') if(strlen(layra)==2)//dang a: strcat(layra,"\\");//ra a:\ int NotExist=_dos_getfileattr(layra, attribp); int m=strlen(layra)-1; while(layra[m]!='\\')//dem so ky tu thuoc ve phan Path m--; for(int n=0;n<m;n++)//doi thanh chu hoa duong dan if(layra[n]>='a'&&layra[n]<='z') layra[n]=toupper(layra[n]); Box[i].GetS_in(layra); if(i==0)//chon Open file { if(*attribp==16) { m=strlen(layra); while(layra[--m]!='\\')//doi sang chu hoa ten cua thu muc layra[m]=toupper(layra[m]); if(layra[1]==':'&&layra[0]!=LastName[0]) setdisk(toupper(layra[0])-'A'); chdir(layra);//vao them mot cap thu muc if(layra[strlen(layra)-1]!='\\') strcat(layra,"\\"); Box[0].GetS_in(layra); Box[0].OutTextBox(); OutMessage("Click mouse to chose action"); return 0; } if (NotExist == 0) { return 0; } else { OutMessage("File does not exist."); Box[0].GetS_in(LastName); Box[0].OutTextBox(); return 1; } }//end if Open } } return -1; } //--------------------------------------------------------- int TestPressList(LIST L,LPEVENT lpEvent,char s[],unsigned *attrib,char *typ) { int k=0; if(lpEvent->Msg==1) if(L.Left()Posx&&L.Top()Posy&&L.Right()>=lpEvent->Posx&&L.Bottom()>=lpEvent->Posy) { OutMessage("Open File Name"); delay(100);//neu khong thi khong the putimage, khong thoat khoi bang list duoc k=L.Press(s,&Box[0],attrib,DiskName,&DName,typ); } return k; } //--------------------------------------------------------- II.CLASS BUTTON.HPP #if !defined __BUTTON__ #define __BUTTON__ class BUTTON { private: int l,t,r,b;//toa do box int Color; char S[100]; public: void InitButton(int x1,int y1,int x2,int y2,int color,char s[]); void OutButton(); void PressButton(); int Left() {return l;} int Right() {return r;} int Top() {return t;} int Bottom() {return b;} }; #endif III.MODULE BUTTON.CPP #include #include #include "button.hpp" //--------------------------------------------------------- void BUTTON::InitButton(int x1,int y1,int x2,int y2,int color,char s[]) { l=x1; t=y1; r=x2; b=y2; Color=color; strcpy(S,s); } //--------------------------------------------------------- void BUTTON::OutButton() { setfillstyle(SOLID_FILL,Color); bar(l,t,r,b); setcolor(WHITE); line(l,t,r,t); line(l,t,l,b); setcolor(BLACK); line(r,t,r,b); line(l,b,r,b); setcolor(BLUE); int x=l+(r-l-textwidth(S))/2,y=t+(b-t-textheight(S))/2; outtextxy(x,y,S); } //--------------------------------------------------------- void BUTTON::PressButton() { setcolor(BLACK); line(l,t,r,t); line(l,t,l,b); setcolor(WHITE); line(r,t,r,b); line(l,b,r,b); } //--------------------------------------------------------- IV. CLASS DISKLIST.HPP #include "textbox.hpp" #include "mouse.h" #if !defined __DISKLIST__ #define __DISLIST__ extern char Disk(char *s); extern int ChosenDisk(char *s,/*TEXTBOX *Box,*/char PreDisk,char CurDisk); extern LPEVENT CheckChooseDisk(char *DiskName,char *DName,LPEVENT lpEvent,int x,int y); extern char *FileType(TEXTBOX *b); #endif V.MODULE DISKLIST.CPP #include #include #include #include #include #include #include #include // #include "disklist.hpp" char Disk(char *s)//kiem tra co bao nhieu o dia trong may, luu ten cac o dia vao chuoi s, tra ve ten o dia hien hanh { int save,disk, disks; int equip_check; char c[4]; s[0]='\0'; save = getdisk(); equip_check = biosequip(); equip_check >>= 6; equip_check = (equip_check & 3) + 1;//dem so o dia mem for (disk = 0;disk < 26;++disk) { setdisk(disk); if (disk == getdisk()) { sprintf(c,"%c",disk +'A'); strcat(s,c); } } setdisk(save); if(equip_check==1&&s[1]=='B')//neu chi co ot o dia mem for(int i=1;i<strlen(s);i++)//thi khong co ten o dia B s[i]=s[i+1];//loai ky tu B ra khoi chuoi luu ten o dia } //--------------------------------------------------------- int ChosenDisk(char *s,/*TEXTBOX *Box,*/char PreDisk,char CurDisk) //tra ve ten o dia { int i; if(PreDisk!=CurDisk) { for(i=0;i<strlen(s);i++) if((CurDisk)==s[i])//hien thi cho dia moi { setdisk(s[i]-'A'); char buffer[MAXPATH],*iem; if((iem=getcwd(buffer, MAXPATH))==NULL) { OutMessage("Driver is not ready."); i=0; ShowMouse(); return s[i]; } } return s[i]; } //--------------------------------------------------------- LPEVENT CheckChooseDisk(char *DiskName,char *DName,LPEVENT lpEvent,int x,int y) { int NumDisk=strlen(DiskName); int x1=x-30,y1=y+NumDisk*14+12; void far *buf;//con tro chi vung luu tru man hinh unsigned int size = imagesize(x1,y,x,y1); if ((buf = farmalloc(size)) == NULL) { OutMessage("Error: not enough heap space in save_screen()."); getch(); closegraph(); exit(1); } else { getimage(x1,y,x,y1,buf); OutMessage("Click a drive name in the list"); } setfillstyle(SOLID_FILL,WHITE); bar(x1,y,x,y1); setcolor(BLACK); rectangle(x,y,x1,y1); setcolor(LIGHTGRAY); line(x-1,y+1,x-1,y1-1); line(x1+1,y1-1,x-1,y1-1); setcolor(BLACK); char Temp[3]; for(int i=0;i<NumDisk;i++) { sprintf(Temp,"%c:",DiskName[i]); outtextxy(x1+10,y+10+i*14,Temp); } for(i=0;i<NumDisk;i++) if(*DName==DiskName[i]) break; setfillstyle(SOLID_FILL,BLUE); bar(x1+1,y+7+14*i,x-1,y+7+14+14*i); setcolor(YELLOW); sprintf(Temp,"%c:",DiskName[i]); outtextxy(x1+10,y+10+i*14,Temp); LPEVENT LpEvent; do { ShowMouse(); delay(50); LpEvent=GetEvent(); HideMouse(); if(LpEvent->Msg==1) for(i=0;i<NumDisk;i++) if(LpEvent->Posx>=x1+1&&LpEvent->PosxPosy>=y+7+i*14&&LpEvent->Posy<=y+7+14+i*14) { bar(x1+1,y+7+14*i,x-1,y+7+14+14*i); *DName=DiskName[i]; setdisk((int)*DName-65); } }while(LpEvent->Msg!=1); putimage(x1,y,buf,COPY_PUT); farfree(buf); return LpEvent; } //--------------------------------------------------------- char *FileType(TEXTBOX *b) { char s[15]; b->Path(); b->OutTextBox(); b->GetS(s); return s; } VI.CLASS LIST.HPP #include "textbox.hpp" #include "disklist.hpp" #if !defined __LIST__ #define __LIST__ class LIST { private: int l,t,r,b; int Color; public: void InitList(int x1,int y1,int x2,int y2,int Color); void Show(); int Press(char s[],TEXTBOX *Box,unsigned *attrib,char *DiskName,char *DName,char *ftype); int GetList(char s[],TEXTBOX *Box,unsigned *attrib,char *DiskName,char *DName,TEXTBOX *Box2,char *ftype); int Left(){return l;}; int Right(){return r;}; int Top(){return t;}; int Bottom(){return b;}; }; #endif VII.MODULE LIST.CPP #include #include #include #include #include #include #include #include #include #include "mouse.h" #include "list.hpp" //--------------------------------------------------------- void LIST::InitList(int x1,int y1,int x2,int y2,int col) { Color=col; l=x1;t=y1;r=x2;b=y2; } //--------------------------------------------------------- void LIST::Show() { setfillstyle(SOLID_FILL,Color); bar(l,t,r,b); int hor=(r-l)/3,ver=(b-t)/3; int x1=l+hor,x2=r-hor,x3=l+(r-l)/2,y1=t+ver,y2=t+ver,y3=b-ver; setcolor(WHITE); line(x1,y1,x2,y2); line(x2,y2,x3,y3); line(x1,y1,x3,y3); setfillstyle(SOLID_FILL,WHITE); floodfill(x1+(x2-x1)/2,y1+(y3-y2)/2,WHITE); setfillstyle(SOLID_FILL,Color); setcolor(BLACK); line(l,b,r,b); line(r,t,r,b); setcolor(WHITE); line(l,t,r,t); line(l,t,l,b); } //--------------------------------------------------------- int LIST::Press(char s[],TEXTBOX *Box,unsigned *attrib,char *DiskName,char *DName,char *ftype) //tra ve 0:nhan Cancel //tra ve 1:nhan OK { TEXTBOX Box2; HideMouse(); int hor=(r-l)/3,ver=(b-t)/3; int x1=l+hor,x2=r-hor,x3=l+(r-l)/2,y1=t+ver,y2=t+ver,y3=b-ver; setcolor(BLACK); line(x1,y1,x2,y2); line(x2,y2,x3,y3); line(x1,y1,x3,y3); setfillstyle(SOLID_FILL,BLACK); floodfill(x1+(x2-x1)/2,y1+(y3-y2)/2,BLACK); setfillstyle(SOLID_FILL,Color); setcolor(WHITE);//vien cho nut bi nhan line(l,b,r,b); line(r,t,r,b); setcolor(BLACK);//vien cho nut bi nhan line(l,t,r,t); line(l,t,l,b); int k=0; *DName=Disk(DiskName); do { char buffer[MAXPATH]; k=GetList(s,Box,attrib,DiskName,DName,&Box2,ftype); getcwd(buffer, MAXPATH); Box->GetS_in(buffer); Box->OutTextBox(); }while(k==2); ShowMouse(); return k;//k=0: nhan Cancel, k=1:nhan OK } //--------------------------------------------------------- int LIST::GetList(char s[],TEXTBOX *Box,unsigned *attrib,char *DiskName,char *DName,TEXTBOX *Box2,char *ftype) { int x11=l-300,y11=b,x12=r+100,y12=b+300;//toa do bang ngoai //600 x 300 la kich thuoc bang ngoai int Kiemtra=0;//bien de kiem tra truong hop chon OK truoc khi chon file LPEVENT lpEvent;//kiem tra bang thu muc void far *buf;//con tro chi vung luu tru man hinh unsigned int size = imagesize(x11,y11,x12,y12); if ((buf = farmalloc(size)) == NULL) { OutMessage("Error: not enough heap space in save_screen()."); getch(); closegraph(); exit(1); } else { getimage(x11,y11,x12,y12, buf); OutMessage("Choose a file name then click OK to accept or click Cancel to ignore"); } setfillstyle(SOLID_FILL,LIGHTGRAY);//GREEN); bar(x11,y11,x12,y12);//ve bang ngoai int x21=x11+5,y21=y11+5,x22=x12-120,y22=y12-77;//75;//toa do bang liet ke setfillstyle(SOLID_FILL,WHITE);//MAGENTA); bar(x21,y21,x22,y22);//ve bang liet ke int x31=x22+30,y31=y21+50,x32=x31+60,y32=y31+20;//toa do nut OK int x41=x31,y41=y31+100,x42=x32,y42=y32+100; setcolor(WHITE); line(x11,y11,x12,y11); line(x11,y11,x11,y12); line(x22+2,y21-2,x22+2,y22+2);//vien cho bang liet ke line(x21-1,y22+2,x22+2,y22+2);//vien cho bang liet ke line(x31,y31,x32,y31);//vien cho nut OK line(x31,y31,x31,y32);//vien cho nut OK line(x41,y41,x42,y41);//vien nut Cancel line(x41,y41,x41,y42);//vien nut Cancel setcolor(BLACK); line(x12,y11,x12,y12); line(x11,y12,x12,y12); line(x21,y21,x22,y21);//vien cho bang liet ke line(x21,y21,x21,y22);//vien cho bang liet ke line(x32,y31,x32,y32);//vien cho nut OK line(x31,y32,x32,y32);//vien cho nut OK line(x42,y41,x42,y42);//vien nut Cancel line(x41,y42,x42,y42);//vien nut Cancel setcolor(DARKGRAY); line(x21-1,y21-1,x22+1,y21-1);//vien cho bang liet ke line(x21-1,y21-1,x21-1,y22+1);//vien cho bang liet ke setcolor(BLUE); char S3[]="OK",S4[]="Cancel"; int x33=x31+(x32-x31-textwidth(S3))/2; int y33=y31+(y32-y31-textheight(S3))/2; outtextxy(x33,y33,S3); int x44=x41+(x42-x41-textwidth(S4))/2; int y44=y41+(y42-y41-textheight(S4))/2; outtextxy(x44,y44,S4); struct ffblk FF; struct ffblk Lis[200]; char path[100]; getcurdir(0, path); int done; int x51=x21,x52=x51+130,y51=y22+28,y52=y51+20; int x61=x21,x62=x12-5,y61=y12-25,y62=y12-5; Box2->InitTextBox(x51,y51,x52,y52,WHITE,LIGHTBLUE,"Type of file"); Box2->GetS_in(ftype); Box2->OutTextBox(); setcolor(BLACK); line(x51+1,y51+1,x52-1,y51+1); line(x51+1,y51+1,x51+1,y52-1); setcolor(LIGHTGRAY); line(x51+1,y52-1,x52-1,y52-1); line(x52-1,y51+1,x52-1,y52-1); setfillstyle(SOLID_FILL,WHITE); bar(x61,y61,x62,y62); setcolor(BLACK); line(x61,y61,x62,y61); line(x61,y61,x61,y62); line(x61+1,y61+1,x62-1,y61+1); line(x61+1,y61+1,x61+1,y62-1); setcolor(LIGHTGRAY); line(x62-1,y61+1,x62-1,y62-1); line(x61+1,y62-1,x62-1,y62-1); //DiskBox int x71=x52+30,x72=x22,y71=y51,y72=y52;//toa do DiskBox char DNameTemp[4]; sprintf(DNameTemp,"%c:",*DName); TEXTBOX DiskBox; DiskBox.InitTextBox(x71,y71,x72,y72,WHITE,LIGHTBLUE,"Driver name"); DiskBox.GetS_in(DNameTemp); DiskBox.OutTextBox(); setcolor(BLACK); line(x71+1,y71+1,x72-1,y71+1); line(x71+1,y71+1,x71+1,y72-1); setcolor(LIGHTGRAY); line(x71+1,y72-1,x72-1,y72-1); line(x72-1,y71+1,x72-1,y72-1); LIST DriList;//nut nhan chon o dia int x81=x72-19,y81=y71+2,x82=x72-2,y82=y72-2; DriList.InitList(x81,y81,x82,y82,LIGHTGRAY); DriList.Show(); done=findfirst("*",&FF,FA_DIREC); Lis[0]=FF; int dem=0;//cho vong while tim file, la so files + thu muc tim duoc if((int)Lis[0].ff_attrib!=16) dem-=1; while (!done)//nhap ten file vao mang cau truc FF { dem++; done = findnext(&FF); if(!done) Lis[dem]=FF; if((int)Lis[dem].ff_attrib!=16) dem-=1; } dem+=1; int NumDir=dem; done=findfirst(ftype,&FF,FA_RDONLY|FA_HIDDEN|FA_SYSTEM|FA_ARCH); for(int j=0;j<strlen(FF.ff_name)+1;j++) Lis[dem].ff_name[j]=tolower(FF.ff_name[j]); while (!done)//nhap ten file vao mang cau truc FF { dem++; done = findnext(&FF); for(int j=0;j<strlen(FF.ff_name)+1;j++) Lis[dem].ff_name[j]=tolower(FF.ff_name[j]); } int NumFile=dem-NumDir; char Note[50];//[30]; setcolor(BLACK); sprintf(Note,"%d files and %d directories found",NumFile,NumDir); outtextxy(x61+5,y61+(y62-y61-textheight(Note))/2,Note); int temp=y11,Dem=0,i; if(dem==0)//truong hop dia hoan toan trong, neu la mot thu muc rong thi khong thuoc truong hop nay strcpy(Lis[0].ff_name,""); int tempx1=x21+1,tempx2=x22,tempy1=y11+14-3,tempy2=y11+14+8+3; setcolor(BLACK);//LIGHTGREEN); for(i=0;i<15&&i<dem;i++)//hien thi ten file outtextxy(x21+8,temp+=14,Lis[i].ff_name); setfillstyle(SOLID_FILL,BLUE); bar(tempx1,tempy1,tempx2,tempy2); setcolor(YELLOW); outtextxy(x21+8,y11+14,Lis[0].ff_name);//vach sang tai vi tri dau tien int oldx1=tempx1,oldy1=tempy1,oldx2=tempx2,oldy2=tempy2; int over=0; int ppp=0; do//while(1); { ShowMouse(); lpEvent = GetEvent();//lay bien co chuot int j,nhanphim; if(kbhit())//kiem tra co nhan phim { nhanphim=getch(); if(nhanphim==0) nhanphim=getch(); } { switch(nhanphim) { case 81://page down if(ppp++ >12)//17) ppp=0; else goto MouseDown; case 80: // mui ten xuong nhanphim=1; MouseDown: HideMouse(); if(Dem<14/*9*/&&Dem<dem-1)j=Dem+1;//&&Dem<dem-1 else { over++; if((over)>=(dem-14))//9)) { over--; goto End; } j=Dem; setcolor(WHITE);//MAGENTA); temp=y11; for(i=over-1;(i<15+over-1)&&i<dem;i++)//xoa ten file outtextxy(x21+8,temp+=14,Lis[i].ff_name); setcolor(BLACK);//LIGHTGREEN); temp=y11; for(i=over;(i<14+over)&&i<dem;i++) outtextxy(x21+8,temp+=14,Lis[i].ff_name); } goto Arrowkey;//break; case 73://page up if(ppp++ >12) ppp=0; else goto MouseUp; case 72: // len nhanphim=1; MouseUp: HideMouse(); if(Dem>0) j=Dem-1; else { over--; if((over)<=-1) { over++; goto End; } j=Dem; setcolor(WHITE);//MAGENTA); temp=y11; for(i=over+1;i<15+over+1;i++)//xoa ten file outtextxy(x21+8,temp+=14,Lis[i].ff_name); setcolor(BLACK);//LIGHTGREEN); temp=y11; for(i=over;i<15+over;i++) outtextxy(x21+8,temp+=14,Lis[i].ff_name); } goto Arrowkey;//break; case 13://Enter nhanphim=1; goto nutOK; case 27://Esc nhanphim=1; goto nutCancel; } }//if(kbhit()) /////////////////////////////////// xet mouse if(lpEvent->Msg==1)//neu nhan phim trai chuot { if(lpEvent->Posx>=x51&&lpEvent->PosxPosy>=y51&&lpEvent->Posy<=y52) {//get type of file HideMouse(); OutMessage("Enter type of file then press Enter to accept or Esc to ignore."); Box2->Path();//lay Path vao bien S cua TEXTBOX Box2->GetS(ftype); putimage(x11,y11,buf,COPY_PUT); farfree(buf); ShowMouse(); return 2; } if(lpEvent->Posx>=x71&&lpEvent->PosxPosy>=y71&&lpEvent->Posy<=y72) {//change disk trong diskbox int ExistDisk; char OldDisk=toupper(*DName); OutMessage("Enter name of drive"); do { HideMouse(); DiskBox.Path();//lay Path vao bien S cua TEXTBOX DiskBox.GetS(DNameTemp); DNameTemp[0]=toupper(DNameTemp[0]); *DName=DNameTemp[0]; ExistDisk=0; for(int k=0;k<strlen(DiskName);k++) if(*DName==DiskName[k]) ExistDisk=1; if(ExistDisk!=1) { OutMessage("Press Enter to do the action again or Esc to ignore"); if(OutError("Disk not exist")==0) { *DName=OldDisk; break; } } ShowMouse(); }while(!ExistDisk); if(OldDisk!=*DName) //truong hop chon dia bang nut pulldown nhung lai chon kieu go ky tu vao textbox setdisk(*DName-'A'); HideMouse(); putimage(x11,y11,buf,COPY_PUT); farfree(buf); ShowMouse(); return 2; } if(lpEvent->Posx>=x81&&lpEvent->PosxPosy>=y81&&lpEvent->Posy<=y82) {//choose disk HideMouse(); setcolor(BLACK); line(x81,y81,x82,y81); line(x81,y81,x81,y82); line(x81+1,y81-1,x81+1,y82-1); char OldDName=*DName; CheckChooseDisk(DiskName,DName,lpEvent,x82,y82); if(OldDName!=*DName) { putimage(x11,y11,buf,COPY_PUT); farfree(buf); return 2; } setcolor(WHITE); line(x81,y81,x82,y81); line(x81,y81,x81,y82); line(x81+1,y81-1,x81+1,y82-1); ShowMouse(); } for(j=0;jMsg==1;j++)//kiem tra file chon neu co chon if(tempx1Posx&&tempx2>=lpEvent->Posx) if((tempy1+j*14)Posy&&(tempy2+j*14)>=lpEvent->Posy) { Arrowkey: HideMouse(); setfillstyle(SOLID_FILL,WHITE);//MAGENTA); bar(oldx1,oldy1,oldx2,oldy2); setcolor(BLACK);//LIGHTGREEN); outtextxy(x21+8,oldy1+3,Lis[Dem+over].ff_name); setfillstyle(SOLID_FILL,BLUE); oldx1=tempx1, oldy1=tempy1+j*14,oldx2=tempx2,oldy2=tempy2+j*14; bar(oldx1,oldy1,oldx2,oldy2); setcolor(YELLOW); outtextxy(x21+8,oldy1+3,Lis[j+over].ff_name); _dos_getfileattr(Lis[j+over].ff_name,attrib); strcpy(s,Lis[j+over].ff_name); if(strcmp(s,".")==0) strcpy(s,"\\"); Dem=j; End: Kiemtra=1;//bao hieu co nhan vao list } if(lpEvent->Msg==1&&(j==15)&&tempx1Posx&&tempx2>=lpEvent->Posx&&(tempy1+j*14)Posy&&(tempy2+j*14)>=lpEvent->Posy) //truong hop vet tro file o cuoi bang list va nhap chuot ngay ben duoi vet tro { lpEvent->Posx=x11; lpEvent->Posy=y11; delay(50); goto MouseDown; } if(lpEvent->Msg==1&&(j==15)&&tempx1Posx&&tempx2>=lpEvent->Posx&&(tempy1-14)Posy&&(tempy2-14)>=lpEvent->Posy) //truong hop vet tro file o dau bang list va nhap chuot ngay ben tren vet tro { lpEvent->Posx=x11; lpEvent->Posy=y11; delay(50); goto MouseUp; } if(lpEvent->Msg==1&&x31Posx&&y31Posy&&x32>=lpEvent->Posx&&y32>=lpEvent->Posy) nutOK: { HideMouse(); putimage(x11,y11,buf,COPY_PUT); farfree(buf); if(Kiemtra!=1) strcpy(s,Lis[0].ff_name); if(strcmp(s,".")==0) { strcpy(s,"\\"); *attrib=16; } if(*attrib==16) { chdir(s); return 2; } Show(); ShowMouse(); OutMessage("Click OK to send file."); return 1 ;//bao da co chon file } if(lpEvent->Msg==1&&x41Posx&&y41Posy&&x42>=lpEvent->Posx&&y42>=lpEvent->Posy) nutCancel: { HideMouse(); putimage(x11,y11,buf,COPY_PUT); farfree(buf); Cancel: Show(); ShowMouse(); OutMessage("Click mouse to chose action"); return 0; } } if(lpEvent->Msg==2) { delay(100); goto nutOK; } }while(1); } //--------------------------------------------------------- VIII. CLASS MOUSE.H #if !defined(__MOUSE_H__) #define __MOUSE_H__ #include #include "screen.h" #define INT_MOUSE 0x33 #define M_LEFT 0x01 /* set if LEFT press */ #define M_RIGHT 0x02 /* set if RIGHT press */ #define M_CENTER 0x04 /* set if CENTER press */ #define M_CHANGE 0x08 /* set if mouse status is changed */ /* -- Keyboard coding bits -- */ #define KEY_NULL 0x0 #define ESC 0x1B #define ENTER 0x0D #define TAB '\t' #define INS 0xD2 #define DEL 0xD3 #define BACKSPACE 0x8 #define HOME 0xC7 #define END 0xCF #define PAGE_UP 0xC9 #define PAGE_DOWN 0xD1 /* -- Function's keys -- */ #define F1 0xBB #define F2 0xBC #define F3 0xBD #define F4 0xBE #define F5 0xBF #define F6 0xC0 #define F7 0xC1 #define F8 0xC2 #define F9 0xC3 #define F10 0xC4 #define PLUS 0x2B #define MINUS 0x2D #define SPACEBAR 0x20 #define SHIFT_TAB 0x8F #define CTRL_C 0x3 //struct time; typedef struct tagEVENT{ int Msg; int Posx, Posy; // toa do xay ra bien co chuot struct time *t; } EVENT; typedef EVENT far *LPEVENT; // Khai bao cac ham toan cuc extern void SetMouseRange(LPRECT);//LPRECT: xem SCREEN.H extern int InitMouse(LPRECT); extern void ShowMouse(void); extern void HideMouse(void); extern void MouseRead(LPEVENT); extern LPEVENT GetEvent(void); extern void DeviceRelease(int); //extern void ButtonPressed(int, LPEVENT); extern void ResetEvent(LPEVENT); //extern void MoveMouse(int x,int y);//tri extern void MouseText(int x,int y,int color1, int color2);//,char s[]); //extern int GetKey(void); extern int GetMtx(); extern int GetMty(); //extern EVENT OldEvent(); extern int Double(LPEVENT); #endif // End of MOUSE.H IX.MODULE MOUSE.CPP #include #include //#include #include #include "mouse.h" void SetMouseRange(LPRECT lpRect) // Dat vung di chuyen cho chuot { _AX = 0x07;//ham 07 cua ngat 33 de dinh gioi han di chuyen ngang _CX = lpRect->left; _DX = lpRect->right; geninterrupt(INT_MOUSE);//INT_MOUSE=0x33:ngat 33 _AX = 0x08;//ham 08 cua ngat 33 dinh gioi han di chuyen doc cho con tro _CX = lpRect->top; _DX = lpRect->bottom; geninterrupt(INT_MOUSE); } //--------------------------------------------------------- int InitMouse(LPRECT lpRect) // Khoi dong chuot { int ax; _AX = 0; geninterrupt(INT_MOUSE); ax = _AX; if (ax == 0) return FALSE; SetMouseRange(lpRect); return TRUE; } //--------------------------------------------------------- void ShowMouse(void) // Hien thi chuot { _AX = 1; geninterrupt(INT_MOUSE); } //--------------------------------------------------------- void HideMouse(void) // Dau chuot { _AX = 2; geninterrupt(INT_MOUSE); } //--------------------------------------------------------- #include #include void MouseRead(LPEVENT lpEvent) // Tra ve bien co nhan duoc tu chuot : Nut trai hay phai duoc an { int bx; _AX = 3; geninterrupt(INT_MOUSE); bx = _BX; //cx = _CX; //dx = _DX; lpEvent->Msg = bx; lpEvent->Posx = _CX; lpEvent->Posy = _DX; gettime(lpEvent->t); } //--------------------------------------------------------- void ResetEvent(LPEVENT lpEvent) { lpEvent->Msg = 0; lpEvent->Posx = lpEvent->Posy = 0; } //--------------------------------------------------------- EVENT PrevEvent, CurEvent; //--------------------------------------------------------- LPEVENT GetEvent(void) { ResetEvent(&CurEvent); MouseRead(&CurEvent); // chuyen sang toa do ViewPort CurEvent.Posx = CurEvent.Posx-MainWindow.rViewPort.left; CurEvent.Posy = CurEvent.Posy-MainWindow.rViewPort.top; // xet trang thai chuot co thay doi hay khong if((CurEvent.Posx!=PrevEvent.Posx)&&(CurEvent.Posy!=PrevEvent.Posy)) CurEvent.Msg |= M_CHANGE; PrevEvent = CurEvent; // delay(50); return (&CurEvent); } //--------------------------------------------------------- void DeviceRelease(int Msg) { while(GetEvent()->Msg&Msg); } //--------------------------------------------------------- int Double(LPEVENT lpEvent) { if(lpEvent->Msg==1) { delay(100); ResetEvent(lpEvent); lpEvent=GetEvent(); if(lpEvent->Msg==1) //if((abs(CurEvent.Posx-oldEvent.Posx))<=10&&abs(CurEvent.Posy-oldEvent.Posy)<=10) { { return 1; } } else return 0; } else return 0; } //--------------------------------------------------------- void MouseText(int x,int y,int color1,int color2)//,char s[])//gia dau nhay con tro { HideMouse(); // int h=textheight(s); int w=5; int color=getcolor(); do { for(int i=0;i<10&&(!kbhit());i++) { setcolor(color2);//WHITE); line(x,y,x+w,y); line(x,y+1,x+w,y+1); delay(10); setcolor(color); } setcolor(color1);//GREEN); line(x,y,x+w,y); line(x,y+1,x+w,y+1); setcolor(color); for(i=0;i<10&&(!kbhit());i++) { setcolor(color1);//GREEN); line(x,y,x+w,y); line(x,y+1,x+w,y+1); delay(10); setcolor(color); } }while(!kbhit()); } //--------------------------------------------------------- int GetMtx() { return getx(); } //--------------------------------------------------------- int GetMty() { return gety(); } //--------------------------------------------------------- // End of MOUSE.CPP X.CLASS SCREEN.H #if !defined(__SCREEN_H__) #define __SCREEN_H__ #define BORDERSIZE 3 #define TRUE 1 #define FALSE 0 #define DEMODELAY 0 // Dinh nghia cac kieu du lieu typedef struct tagRECT{ int left, top, right, bottom ; }RECT; typedef RECT far *LPRECT; typedef struct tagWINDOW { char sCaption[80]; /*Window's caption*/ RECT rWinRect; /*Rectangle in which window is located*/ RECT rSys; /*System area of window*/ RECT rTitleBar; /*Caption area of window*/ RECT rMenuBar; /*Rectangle in which window's menu is located*/ RECT rMessage; /* Rectangle in which messages is display }WINDOWS; // Dinh nghia cac ham va bien dung toan cuc extern int Xc, Yc; // Goc toa do extern int LineColor; extern int VP_WIDTH; extern int VP_HEIGHT; extern WINDOWS MainWindow; extern void InitGraphics(void); extern void OutMessage(char *Msg); extern void InitScreen(void); extern void InitValues(char *lpCaption); extern int OutError(char *s); #endif // End of SCREEN.H XI.MODULE SCREEN.CPP #include #include #include #include #include #include "screen.h" #include "mouse.h" int T_SIZE, W_SIZE, H_SIZE, W_CHAR, H_CHAR, MSG_SIZE; int COLOR_WINDOW; int COLOR_BUTTON; int COLOR_BORDER; int COLOR_CAPTION; int COLOR_TEXT; int VP_WIDTH; int VP_HEIGHT; int Maxx, Maxy; // Maxx - Maxy of screen WINDOWS MainWindow; //int Xc, Yc; // Goc toa do //int LineColor = MAGENTA; // Mau cua duong thang can ve - Dung trong thu tuc SetPixel //--------------------------------------------------------- void InitGraphics(void) // Khoi tao che do do hoa { int grDrv=DETECT, grMode; int ErrCode; initgraph(&grDrv, &grMode, ""); ErrCode = graphresult(); if(ErrCode!= grOk) { printf("Graphics error: %s\n", grapherrormsg(ErrCode)); printf("Press any key to halt..."); getch(); exit(1); /* return with error code */ } Maxx = getmaxx(); Maxy = getmaxy(); } //--------------------------------------------------------- void InitValues(char *lpCaption) // Khoi tao cac gia tri cho bien Windows de ve cua so man hinh { int WinWidth, WinHeight; W_CHAR = 8; H_CHAR = 8; // Chieu rong va chieu cao cua mot ki tu W_SIZE = 8; H_SIZE = 20; T_SIZE = 18; MSG_SIZE = 20; COLOR_WINDOW = CYAN; COLOR_BUTTON = LIGHTGRAY; COLOR_BORDER = LIGHTGRAY; COLOR_CAPTION = BLUE; COLOR_TEXT = BLUE; strcpy(MainWindow.sCaption, lpCaption); // Gan gia tri cho WinRect - H.C.nhat chua cua so MainWindow.rWinRect.left = 0; MainWindow.rWinRect.top = 0; MainWindow.rWinRect.right = Maxx; MainWindow.rWinRect.bottom= Maxy; WinWidth = MainWindow.rWinRect.right-MainWindow.rWinRect.left+1; WinHeight= MainWindow.rWinRect.bottom-MainWindow.rWinRect.top+1; // Gan gia tri cho rSys - H.C.nhat chua SystemMenu MainWindow.rSys.left = BORDERSIZE; MainWindow.rSys.top = BORDERSIZE; MainWindow.rSys.right = MainWindow.rSys.left+T_SIZE; MainWindow.rSys.bottom= MainWindow.rSys.top+T_SIZE; // Gan gia tri cho rTitleBar - H.C.nhat chua thong tin thanh tieu de MainWindow.rTitleBar.left = BORDERSIZE+1;//MainWindow.rSys.right+1; MainWindow.rTitleBar.top = BORDERSIZE+1; MainWindow.rTitleBar.right = WinWidth-BORDERSIZE-1; MainWindow.rTitleBar.bottom= MainWindow.rSys.top+T_SIZE; // Gan gia tri cho rMenuBar - H.C.nhat chua thong tin menu // Gan gia tri cho rMessage - H.C.nhat chua thong tin cua cac //thong bao MainWindow.rMessage.left = BORDERSIZE+1; MainWindow.rMessage.right = WinWidth-BORDERSIZE-2; MainWindow.rMessage.top = WinHeight-(BORDERSIZE+2)-MSG_SIZE; MainWindow.rMessage.bottom= MainWindow.rMessage.top+MSG_SIZE; // Gan gia tri cho rViewPort - H.C.nhat chua thong tin ve vung lam viec // thuc su cua cua so MainWindow.rViewPort.left = BORDERSIZE+1; MainWindow.rViewPort.top = MainWindow.rTitleBar.bottom+2;//MainWindow.rMenuBar.bottom+2; MainWindow.rViewPort.right = WinWidth-BORDERSIZE-2; MainWindow.rViewPort.bottom= MainWindow.rMessage.top-2; VP_WIDTH = MainWindow.rViewPort.right-MainWindow.rViewPort.left; VP_HEIGHT = MainWindow.rViewPort.bottom-MainWindow.rViewPort.top; } //--------------------------------------------------------- void OutMessage(char *Msg) // Ghi thong bao Msg ra cua so rMessage { struct fillsettingstype FillInfo; int OldColor; struct viewporttype vp; // luu thong tin cu getfillsettings(&FillInfo); OldColor = getcolor(); getviewsettings(&vp); // xoa thong bao cu setviewport(MainWindow.rWinRect.left, MainWindow.rWinRect.top, MainWindow.rWinRect.right, MainWindow.rWinRect.bottom, 1); setfillstyle(SOLID_FILL, COLOR_BUTTON); setcolor(COLOR_TEXT); bar(MainWindow.rMessage.left, MainWindow.rMessage.top, MainWindow.rMessage.right, MainWindow.rMessage.bottom); // in thong bao moi ra outtextxy(MainWindow.rMessage.left+W_CHAR, MainWindow.rMessage.bottom-H_CHAR-5, Msg); // tra ve trang thai cu setfillstyle(FillInfo.pattern, FillInfo.color); setcolor(OldColor); setviewport(vp.left,vp.top, vp.right, vp.bottom, 1); } //--------------------------------------------------------- void DrawScreenBorder(int left, int top, int right, int bottom) // Ve duong vien cho mot hinh chu nhat co toa do (left, top), (right, bottom) { setfillstyle(SOLID_FILL, COLOR_BORDER); bar(left, top, right, top+BORDERSIZE); bar(left, bottom, right, bottom-BORDERSIZE); bar(left, top, left+BORDERSIZE, bottom); bar(right-BORDERSIZE, top, right, bottom); setcolor(BLACK); rectangle(left, top, right, bottom); rectangle(left+BORDERSIZE, top+BORDERSIZE, right-BORDERSIZE, bottom-BORDERSIZE); } //--------------------------------------------------------- #include void InitScreen(void) // Ve cac thanh phan cua cua so { int x, y; int WinWidth, WinHeight; struct viewporttype vp; getviewsettings(&vp); setviewport(MainWindow.rWinRect.left, MainWindow.rWinRect.top, MainWindow.rWinRect.right, MainWindow.rWinRect.bottom, 1); WinWidth = MainWindow.rWinRect.right-MainWindow.rWinRect.left+1; WinHeight= MainWindow.rWinRect.bottom-MainWindow.rWinRect.top+1; x = (WinWidth-W_CHAR*strlen(MainWindow.sCaption))/2+1; y = BORDERSIZE+(T_SIZE-H_CHAR)/2+1; // Ve duong vien cua hinh chu nhat DrawScreenBorder(0, 0, WinWidth-1, WinHeight-1); delay(DEMODELAY); // Ve thanh tieu de setfillstyle(SOLID_FILL, COLOR_CAPTION); bar(MainWindow.rTitleBar.left, MainWindow.rTitleBar.top, MainWindow.rTitleBar.right, MainWindow.rTitleBar.bottom); setcolor(WHITE); outtextxy(x, y, MainWindow.sCaption); delay(DEMODELAY); // Ve SystemMenu setfillstyle(SOLID_FILL, COLOR_BUTTON); /* bar(MainWindow.rSys.left+1, MainWindow.rSys.top+1, MainWindow.rSys.right-1, MainWindow.rSys.bottom-1); setcolor(BLACK); rectangle((MainWindow.rSys.left+MainWindow.rSys.right)/2-5, (MainWindow.rSys.top+MainWindow.rSys.bottom)/2-1, (MainWindow.rSys.left+MainWindow.rSys.right)/2+5, (MainWindow.rSys.top+MainWindow.rSys.bottom)/2+1); delay(DEMODELAY); */ // Ve Menu // bar(MainWindow.rMenuBar.left, MainWindow.rMenuBar.top, // MainWindow.rMenuBar.right, MainWindow.rMenuBar.bottom); // outtextxy(MainWindow.rMenuBar.left+8, MainWindow.rMenuBar.bottom-13, // "Menu of Program is here"); // delay(DEMODELAY); // Ve thanh chua thong bao bar(MainWindow.rMessage.left, MainWindow.rMessage.top, MainWindow.rMessage.right, MainWindow.rMessage.bottom); OutMessage("Welcome to Demo Window Program"); delay(DEMODELAY); // Ve vung lam viec setfillstyle(SOLID_FILL, COLOR_WINDOW); bar(MainWindow.rViewPort.left, MainWindow.rViewPort.top, MainWindow.rViewPort.right, MainWindow.rViewPort.bottom); setcolor(BLACK); rectangle(MainWindow.rViewPort.left-1, MainWindow.rViewPort.top, MainWindow.rViewPort.right+1, MainWindow.rViewPort.bottom); delay(DEMODELAY); // Dat lai viewport la rViewPort setviewport(MainWindow.rViewPort.left, MainWindow.rViewPort.top, MainWindow.rViewPort.right, MainWindow.rViewPort.bottom, 1); } //--------------------------------------------------------- /*void DrawSysCoordinates(void) // Ve he truc toa do { Xc = VP_WIDTH/2; Yc = VP_HEIGHT/2; setcolor(COLOR_TEXT); // ve hai truc toa do line(0, Yc, VP_WIDTH, Yc); line(Xc, 0, Xc, VP_HEIGHT); // ve hai mui ten line(Xc, 0, Xc-5, 5); line(Xc, 0, Xc+5, 5); line(VP_WIDTH, Yc, VP_WIDTH-5, Yc-5); line(VP_WIDTH, Yc, VP_WIDTH-5, Yc+5); // Ve goc toa do outtextxy(Xc-8, Yc+8, "O"); } //--------------------------------------------------------- void SetLineColor(int C) { LineColor = C; } //--------------------------------------------------------- void SetPixel(int x, int y) { putpixel(Xc+x, Yc-y, LineColor); } //--------------------------------------------------------- void Set2Pixel(int Ox, int Oy, int x, int y) { putpixel(Ox+x, Oy-y, LineColor); putpixel(Ox-x, Oy-y, LineColor); } //--------------------------------------------------------- void Set2PixelHor(int Ox, int Oy, int x, int y) { putpixel(Ox+x, Oy-y, LineColor); putpixel(Ox+x, Oy+y, LineColor); } //--------------------------------------------------------- void ClearViewPort(void) { struct fillsettingstype FillInfo; // luu thong tin cu getfillsettings(&FillInfo); setfillstyle(SOLID_FILL, COLOR_WINDOW); bar(0, 0, VP_WIDTH, VP_HEIGHT); setfillstyle(FillInfo.pattern, FillInfo.color); DrawSysCoordinates(); } */ // End of SCREEN.C //--------------------------------------------------------- #include int OutError(char *s) { void far *buf;//con tro chi vung luu tru man hinh unsigned int size = imagesize(200,150,470,240); LPEVENT lpEvent; int Cx1=280,Cy1=203,Cx2=337,Cy2=223; int Ox1=350,Oy1=203,Ox2=405,Oy2=223; if ((buf = farmalloc(size)) == NULL) { return -1; } else { getimage(200,150,470,240,buf); } setfillstyle(SOLID_FILL,BLUE); HideMouse(); bar(200,150,470,240); setcolor(WHITE); rectangle(200,150,470,240); outtextxy(200+(270-8*strlen(s))/2,170,s); setfillstyle(SOLID_FILL,LIGHTBLUE); bar(Cx1,Cy1,Cx2,Cy2);//280,203,337,223); int OK=0; outtextxy(285,210,"Cancel"); outtextxy(365,210,"OK"); int event; do { lpEvent=GetEvent(); if(kbhit()) { if((event=getch())==13) { CompleteOk: HideMouse(); putimage(200,150,buf,COPY_PUT); ShowMouse(); farfree(buf); return OK; } if(event==27) { CompleteCancel: HideMouse(); putimage(200,150,buf,COPY_PUT); ShowMouse(); farfree(buf); return 0; } if(event==9) { OK=!OK; Cancel: if(OK==0) { HideMouse(); setfillstyle(SOLID_FILL,BLUE); bar(Ox1,Oy1,Ox2,Oy2);//350,203,405,223); outtextxy(365,210,"OK"); setfillstyle(SOLID_FILL,LIGHTBLUE); bar(Cx1,Cy1,Cx2,Cy2);//280,203,337,223); outtextxy(285,210,"Cancel"); ShowMouse(); } Ok: if(OK==1) { HideMouse(); setfillstyle(SOLID_FILL,BLUE); bar(Cx1,Cy1,Cx2,Cy2);//280,203,337,223); outtextxy(285,210,"Cancel"); setfillstyle(SOLID_FILL,LIGHTBLUE); bar(Ox1,Oy1,Ox2,Oy2);//350,203,405,223); outtextxy(365,210,"OK"); ShowMouse(); } } if(event==0) { event=getch(); if(event==75) { OK=0; goto Cancel; } if(event==77) { OK=1; goto Ok; } } else flushall(); } if(lpEvent->Msg==1) { if(lpEvent->Posx>=Cx1&&lpEvent->PosxPosy>=Cy1&&lpEvent->Posy<=Cy2) { OK=0; goto CompleteCancel; } if(lpEvent->Posx>=Ox1&&lpEvent->PosxPosy>=Oy1&&lpEvent->Posy<=Oy2) { OK=1; goto CompleteOk; } } ShowMouse(); }while(1); } XII. CLASS SEND.HPP #include #include #include #include #include #include #include #if !defined __SEND__ #define __SEND__ class SEND { private: char OutFile[100]; public: char *CatFile(char St_add[],char End_add[],char InFile[]); int Out(); int DeleteFile();//se del OutFile }; #endif extern int Esc(); XIII. MODULE SEND.CPP #include "screen.h" #include "send.hpp" #define data 0x378 #define sta 0x379 #define ctr 0x37a char *SEND::CatFile(char St_add[],char End_add[],char InFile[]) { char KyTu_Hex[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','a','b','c','d','e','f'}; int Gtri_Dec[]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,10,11,12,13,14,15}; unsigned int i,DemSpace; unsigned int Value1=0,Value2=0; char FindPos,FindValue; int Thoigian=0; FILE *f,*f1; char t,t1,t2,t3,t4; // char St_add[]="0000 Hex",End_add[]="000F Hex"; int end_line; strcpy(OutFile,InFile); i=strlen(OutFile); do { OutFile[i]='\0'; }while(OutFile[--i]!='.'); strcat(OutFile,"tmp");//dat ten cho file se tao ra for (FindPos=3;FindPos>=0;FindPos--) for(FindValue=0;FindValue<22;FindValue++) if(St_add[FindPos]==KyTu_Hex[FindValue]) Value1+=pow(16,(3-FindPos))*Gtri_Dec[FindValue]; for (FindPos=3;FindPos>=0;FindPos--) for(FindValue=0;FindValue<22;FindValue++) if(End_add[FindPos]==KyTu_Hex[FindValue]) Value2+=pow(16,(3-FindPos))*Gtri_Dec[FindValue]; f=fopen(InFile,"rt"); f1=fopen(OutFile,"w+t"); fwrite(St_add,4,1,f1); fwrite(End_add,4,1,f1); do { do { fread(&t1,1,1,f); }while(t1!='\'');//ngay sau dia chi cua lenh do { fread(&t1,1,1,f); }while(t1==' ');//den lenh end_line=0; do { fread(&t2,1,1,f); Value1++; DemSpace=0; do { fread(&t,1,1,f); DemSpace++; }while(t==' '&&DemSpace<3);//con la lenh hoac dia chi hay da cham dut mot lenh if(DemSpace>=2)//la ma lenh hoac da ket thuc mot dong lenh { fwrite(&t1,1,1,f1); fwrite(&t2,1,1,f1); t1=t; } if(DemSpace==1) { t3=t; fread(&t4,1,1,f); Value1++; fwrite(&t3,1,1,f1); fwrite(&t4,1,1,f1); fwrite(&t1,1,1,f1); fwrite(&t2,1,1,f1); DemSpace=0; do { fread(&t,1,1,f); if(t==' ') DemSpace++; }while((t=='\''||t==' ')&&DemSpace<3);//con la lenh hoac dia chi hay da cham dut mot lenh if(DemSpace==2) t1=t; } if(DemSpace>2) { end_line=1; } }while(end_line==0); }while(Value1<=Value2); fcloseall(); return OutFile; } //--------------------------------------------------------- int SEND::Out() { int result,Temp; FILE *f; char value; int n,dem=0; int Stop=0; char KyTu_Hex[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','a','b','c','d','e','f'}; int Gtri_Dec[]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,10,11,12,13,14,15}; if ( (f = fopen(OutFile,"rt")) == NULL) { OutError("Cannot open input file."); return dem; } while(!feof(f)) { do { result=inportb(sta); result=result & 0x80; Stop=Esc(); }while(result !=0x80&&Stop!=1);//doc busy cho toi khi !busy = 1 if(Stop==1) return -1; n=fread(&value,1,1,f); if(n==0) return dem; for(int z=0;z<22;z++)//doi ky tu ra gia tri Dec de goi di if(value==KyTu_Hex[z])//nible cao { Temp=Gtri_Dec[z]*16; z=22; } fread(&value,1,1,f); for(z=0;z<22;z++)//nible thap if(value==KyTu_Hex[z]) { Temp=Gtri_Dec[z]+Temp; z=22; } outportb(data,Temp);//pow(2,i));//xuat du lieu ra thanh ghi du lieu outportb(ctr,0x00);// cho strobe = 1 de bao cho phan thu biet da goi du lieu ra thanh ghi du lieu dem++; do { result=inportb(sta); result=result & 0xC0; Stop=Esc(); }while(result!=0x40&&Stop!=1);//doc ack cho den khi ack = 1 if(Stop==1) return -1; outportb(ctr,0x01);// cho strobe = 0 de bao cho phan thu biet da goi xong mot byte du lieu ra thanh ghi du lieu } return 0; } //--------------------------------------------------------- int SEND::DeleteFile() { return remove(OutFile); } //--------------------------------------------------------- int Esc() { if(kbhit())//nhan Esc de thoat { if(getch()==27) { OutError("Task is not complete !!!"); } else flushall(); return 1; } return 0; } XIV.CLASS TEXTBOX.HPP #include #if !defined __TEXTBOX__ #define __TEXTBOX__ class TEXTBOX { private: int l,t,r,b; int Color,Color1; char S[100],S1[100]; char Dri[100],Path_var[100],Name[100],TenFile[100],SubFile[100]; int chiso; public: TEXTBOX() {S[0]='\0';}//S1="Duong dan";} void InitTextBox(int x1,int y1,int x2,int y2,int color,int color1,char s[]); void Path(); void PressTextBox(); void OutTextBox(); int Left(){return l;} int Top(){return t;} int Right(){return r;} int Bottom(){return b;} void DelChar(int length);//,int xoa);//de xoa ky tu khi gap phim del tai texbox void InsertChar(char c); void GetS(char s[]){strcpy(s,S);}; void GetS_in(char s[]){strcpy(S,s);} int DuongDan(char s[]); void Get_path(char s[]){strcpy(s,Path_var);}; void Get_name(); }; #endif XV.MODULE TEXTBOX.CPP #include #include #include #include #include #include #include #include "textbox.hpp" #include "mouse.h" //--------------------------------------------------------- void TEXTBOX::InitTextBox(int x1,int y1,int x2,int y2,int color,int color1,char s[]) { char buffer[MAXPATH]; l=x1;t=y1;r=x2;b=y2; Color=color; Color1=color1; strcpy(S1,s); getcwd(buffer, MAXPATH); strcpy(S,buffer); strcat(S,"\\"); } //--------------------------------------------------------- void TEXTBOX::OutTextBox() { setfillstyle(SOLID_FILL,Color); bar(l,t,r,b); setcolor(WHITE); line(l,b,r,b); line(r,t,r,b); setcolor(BLACK); line(l,t,r,t); line(l,t,l,b); setcolor(WHITE); if(Color==WHITE) setcolor(BLACK); outtextxy(l,t+(b-t-textheight(S))/2-b+t-3,S1); outtextxy(l+5,t+(b-t-textheight(S))/2,S); } //--------------------------------------------------------- /* void TEXTBOX::PressTextBox() { setcolor(BLACK); line(l,t,r,t); line(l,t,l,b); setcolor(WHITE); line(l,b,r,b); line(r,t,r,b); } */ //--------------------------------------------------------- void TEXTBOX::Path()//lay duong dan nhap vao vao bien S cua TEXTBOX { char a; int C1=Color1;//C1 la mau cua text trong textbox o che do nhap ten file setcolor(C1); outtextxy(l+5,t+(b-t-textheight(S))/2,S); chiso=0; MouseText(l+textwidth(S)+4,t+(b-t+textheight(S))/2,Color,C1);//,S);//gia dau nhac chuot char stemp[128]; strcpy(stemp,S); while((a=getch())!=13)//&&a!=27)//kiem tra phim Enter { switch(a)//kiem tra ky tu nhap vao { case 0:switch(a=getch()) { case 71://home MouseText(l+6,t+(b-t+textheight(S))/2,Color,C1);//,S); chiso=-strlen(S); break; case 72:break; case 73:break; case 75://left arrow int f=textwidth(S); int xt=l+6+f+(--chiso)*8; int yt=t+(b-t+textheight(S))/2; if(xt<l+6) xt=l+6+f+((++chiso))*8; MouseText(xt,yt,Color,C1);//,S);//so 8 la be ngang 1 ky tu break; case 77://right arrow if(chiso==0)break; f=textwidth(S); MouseText(l+f+6+((++chiso))*8,t+(b-t+textheight(S))/2,Color,C1);//,S);//so 8 la be ngang 1 ky tu break; case 79://end f=textwidth(S); MouseText(l+f+6,t+(b-t+textheight(S))/2,Color,C1);//,S); chiso=0; break; case 80: case 81: case 82:break; case 83://del setcolor(GREEN); outtextxy(l+5,t+(b-t-textheight(S))/2,S); DelChar(strlen(S));//,chiso); f=textwidth(S); setcolor(YELLOW); outtextxy(l+5,t+(b-t-textheight(S))/2,S); MouseText(l+f+6+chiso*8,t+(b-t+textheight(S))/2,Color,C1);//,S);//so 8 la be ngang 1 ky tu break; }break; case 8://backspace setcolor(Color); outtextxy(l+5,t+(b-t-textheight(S))/2,S); chiso--; DelChar(strlen(S)); setcolor(C1); outtextxy(l+5,t+(b-t-textheight(S))/2,S); MouseText(l+textwidth(S)+6+chiso*8,t+(b-t+textheight(S))/2,Color,C1);//,S); break; case 27://Esc strcpy(S,stemp);return; default: if(a>=32&&a<=126) { if((strlen(S)+2)*8>(r-l))break; setcolor(GREEN); outtextxy(l+5,t+(b-t-textheight(S))/2,S); InsertChar(a); setcolor(C1); outtextxy(l+5,t+(b-t-textheight(S))/2,S); MouseText(l+textwidth(S)+6+chiso*8,t+(b-t+textheight(S))/2,Color,C1);//,S);//so 8 la be ngang 1 ky tu } } MouseText(l+textwidth(S)+6,t+(b-t+textheight(S))/2,Color,C1);//,S);//truong hop phim khong co nhiem vu nao dac biet }; if (S[0]=='\0') strcpy(S,stemp); } //--------------------------------------------------------- void TEXTBOX::DelChar(int length)//xoa ky tu tai vi tri con tro { int vitri=length+chiso; for(int i=vitri;i<length-1;i++) S[i]=S[i+1]; if(chiso<0) { S[length-1]='\0'; chiso++; } } //--------------------------------------------------------- void TEXTBOX::InsertChar(char c) { int length=strlen(S); for(int i=length;i>length+chiso;i--) S[i]=S[i-1]; S[length+1]='\0'; S[i]=c; } //--------------------------------------------------------- int TEXTBOX::DuongDan(char s[]) { int l=strlen(s),dem,dr; char s1[200]="",s2[200]=""; dem=l-1; if(s[1]==':') switch(toupper(s[0])) { case 'A':dr=1;break; case 'B':dr=2;break; case 'C':dr=3;break; case 'D':dr=4;break; case 'E':dr=5;break; } else dr=_getdrive(); for(int i=l-1;i>0;i--) { if(s[i]=='\\') { dem=i+1; i=0; } else dem=0; } strcat(s2,&s[dem]); if(dem!=0) dem-=1; strncpy(s1,s,dem); strcpy(Path_var,s1); strcpy(Name,s2); return dr; } //--------------------------------------------------------- void TEXTBOX::Get_name() { int n=strlen(Name); int phan_ten=1; for(int i=0;i<=n&&phan_ten;i++) { if(Name[i]=='.'&&i<n) { for(int j=n;j>i;j--) Name[j]=Name[j-1]; Name[j]='1'; Name[n+1]='\0'; phan_ten=0; } if(i==n) { Name[i]='1'; Name[i+1]='\0'; } } S[0]='\0'; strcat(S,Path_var); strcat(S,"\\"); strcat(S,Name); } C. SỬ DỤNG CHƯƠNG TRÌNH DOWNLOAD. Để sử dụng chương trình DowLoad, trước tiên phải về màn hình Dos (vì chương trình được viết trong môi trương Dos, không quản lý được các chương trình điều khiển thiết bị sẳn có trong máy, thoát về Dos để tránh những xung đột chương trình). Gọi tên Demo.exe, lúc đó màn hình sẽ hiện lên như sau: Để chọn file bằng cách gõ phím, click chuột vào ô Open File. Ô nhập text Nút pulldown Nếu nhắp nút pulldown thì sẽ chọn file theo kiểu click chuột. (hình sau). Chọn ổ đĩa, chọn loại file, chọn tên file và click OK để chọn file. Sau khi chọn xong file thì trong bảng “Free memory request” xuất hiện các địa chỉ đầu cuối, và dung lượng bộ nhớ sẽ sử dụng. Sau đó click Send để gởi dữ liệu đi. Khi quá trình truyền file kết thúc thì xuất hiện thông báo “Task is complete.”

Các file đính kèm theo tài liệu này:

  • docDO57.DOC