LUAÂÄN VAÊN TOÁT NGHIEÄP
56
;KeyKRB : Chuong trinh con quet ban phim. Ma cua phim an duoc cat
;trong thanh
; ghi A.
;DELAY : Chuong trinh con tri hoan theo thoi hang 0.1 ms. He so tri
;hoan duoc
; nap vao thanh ghi A.
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++
;#####################################################################
;Khai bao cac nhan duoc su dung.
;#####################################################################
RegCNT equ 03h
PortA equ 00h
PortB equ 01h
PortC equ 02h
CntI79 equ 0A001h
DataI79 equ 0A000h
KEYBRD equ 0216h
DELAY equ 0310h
KeyGO equ 17h
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
End
LUAÂÄN VAÊN TOÁT NGHIEÄP
57
B.Module Demo.cpp
char inter_Path[100]="";
char RequF[100];
unsigned int St_address,End_address=0;
char Sta_hex[5],End_hex[5];
//
int TestPressedButton(int x,LPEVENT lpEvent);
int TestPressTexbox(int x,LPEVENT lpEvent,char layra[],unsigned
*attribp);
void MainProgram();
int TestPressList(LIST L,LPEVENT lpEvent,char s[],unsigned
*attrib,char *typ);//nhap bang liet ke
int SendFile();
//
void main(void)
{
InitGraphics();
InitValues("Download Program.");
InitScreen();
if (!InitMouse(&MainWindow.rViewPort))
{
OutMessage("Mouse driver not found. Init mouse and return");
getch();
closegraph();
exit(1);
}
ShowMouse();
MainProgram();
closegraph();
outtextxy(50,130,"Free memory request");
outtextxy(55,158,"Start ad :");
outtextxy(55,178,"End ad :");
outtextxy(55,198,"Total :");
OutMessage("Click mouse to chose action");
int kkkk;
char RequestFile[15]="";
do//kiem tra nhap chuot chon cong viec
{
ShowMouse();
lpEvent = GetEvent();//lay bien co chuot
if(TestPressedButton(2,lpEvent)==0)//kiem tra xem da click vao
nut nao
//0:nhan OK
{
char InName[100],OutName[100];
Box[0].GetS(InName);
if(InName[strlen(InName)-1]=='\\')
InName[strlen(InName)-1]='\0';
_dos_getfileattr(InName,&attrib);
if(attrib==16)
{
OutMessage("");
OutError("Please enter a file name");
OutMessage("Click mouse to chose action");
}
else//la file
if(TestPressList(L,lpEvent,Name,&attrib,ftype)==1)
//chon OK
{
switch (attrib)
{
case 16:chdir(Name);
getcwd(buffer, MAXPATH);//lay duong dan hien thoi vao
buffer
strcpy(inter_Path,buffer);
Box[0].GetS_in(inter_Path);
Box[0].OutTextBox();
break;
default:
getcwd(buffer, MAXPATH);//lay duong dan hien thoi vao
buffer
strcpy(inter_Path,buffer);
if(inter_Path[strlen(inter_Path)-1]!='\\')
strcat(inter_Path,"\\");
strcat(inter_Path,Name);
Box[0].GetS_in(inter_Path);
Box[0].DuongDan(inter_Path);
Box[0].OutTextBox();
break;
}//end switch
}//if(TestPressList(
//chon Cancel
TestPressTexbox(NumBox,lpEvent,inter_Path,&Attribp);//Path lay
ra duong dan cho file nhap vao
//ShowMouse();
if(kbhit())
if ((f = fopen(RequF,"rb")) == NULL)
{
fprintf(stderr, "Cannot open input file.\n");
return ;
}
else//neu mo duoc file
{
clock_t start, end;
int period=0;
char c,address[7],buf[8];
int thoat;
int dem;
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};
double Value1=0,Value2=0;
char Total[10];
int FindPos,FindValue;
start = clock();
do
{
fread(&c,1,1,f);
end = clock();
}while(c!='\''&&(period=(end - start) / CLK_TCK)<10);
if(period>=2) goto Error;
}while(c!='m'&&c!='M'&&(period=(end - start) /
CLK_TCK)<10);
if(period>=10) goto Error;
fseek(f,-1,SEEK_CUR);
fread(buf,7,1,f);
buf[7]='\0';
end = clock();
if(!strcmp(buf,"Macros:")||!strcmp(buf,"MACROS:")||!strcmp(buf,"
macros:"))
thoat=0;
}while(thoat&&(period=(end - start) / CLK_TCK)<15);
if(period>=15) goto Error;
fseek(f,-1,SEEK_CUR);
start = clock();
do
{
dem=0;
do
{
fread(&c,1,1,f);
if(c=='\n')
fseek(f,-3,SEEK_CUR);
else
fseek(f,-2,SEEK_CUR);
end = clock();
}while(c!='\''&&(period=(end - start) /
CLK_TCK)<10);
if(period>=10) goto Error;
do
62
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
if(OutError("Do you want to quit ?")==0)
return -1;
closegraph();
exit(1);
}
ShowMouse();
LUAÂÄN VAÊN TOÁT NGHIEÄP
63
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()<= lpEvent->Posx&&Box[i].Top()<=lpEvent-
>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);
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]);
LUAÂÄN VAÊN TOÁT NGHIEÄP
64
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;
//
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
LUAÂÄN VAÊN TOÁT NGHIEÄP
65
III.MODULE BUTTON.CPP
#include <graphics.h>
#include <string.h>
#include "button.hpp"
//
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 <dir.h>
#include <alloc.h>
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <graphics.h>
LUAÂÄN VAÊN TOÁT NGHIEÄP
66
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);