LUÂÄN VĂN TỐT NGHIỆP
1
Chương 7:
Chương trình nhận dữ
liệu ở Kit thực tập vi xử lý 8085.
;+++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++;Chuong trinh nhan
du lieu tu may tinh goi xuong Thiet bi thuc
tap
;vi xu li 8085.
;+++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++ Org 2500h
MVI A,99h ;khoi tao 8255, Mode 0: PortA
nhap du lieu, PortB xuat
OUT RegCNT ;trang thai, PortC nhan lenh
dieu khien.
MVI A,80h ;bao cho may tinh biet thiet
bi dang ban.
OUT PortB
MVI C,00h ;reset bien dem dia chi.
CALL READY ;xuat chu "READY" ra hien
thi tren 5 LED 7 doan.
WaitGO: CALL KEYBRD ;doi nhan phim.
CPI KeyGO ;chuong trinh chi thuc hien
tiep khi nhan dung
JNZ WaitGO ;phim "GO".
CALL SENDING ;nhan dung phim "GO" se
xuat hien "SENDING" tren 8 LED.
MVI A,00h ;bao cho may tinh biet thiet
bi da san sang tiep ;nhan
OUT PortB ;du lieu.
CkSTB1:IN PortC ;doc lenh dieu khien
STROBE tai PortC.
ANI 01h
CPI 01h
JNZ CkSTB1 ;neu STROBE # 1 thi doi tiep.
MVI A,80h ;bao BUSY\ = 0, ACK = 0.
LUAÂÄN VAÊN TOÁT NGHIEÄP
2
OUT PortB
IN PortA ;doc du lieu vao.
MOV B,A ;tam cat du lieu vao thanh ghi B.
MVI A,0C0h ;bao ACK = 1.
OUT PortB
ChkAF1: IN PortC ;doc lenh dieu khien AF.
ANI 02h
CPI 02h
JNZ ChkAF1 ;neu AF # 1 thi doi tiep.
MOV A,B ;hoan tra B lai cho A.
ANI 0F0h ;che nibble thap va reset bit
ERROR = 0.
OUT PortB ;xuat nibble cao va bao ERROR
= 0.
ChkAF0: IN PortC ;doc lenh dieu khien AF.
ANI 02h
CPI 00h
JNZ ChkAF0 ;neu AF # 0 thi doi tiep.
MOV A,B ;hoan tra B lai cho A.
RLC ;dich 4 bit thap thanh 4 bit cao
tuong ung.
RLC
RLC
RLC
ANI 0F0h ;che nua byte thap thap.
ORI 08h ;set bit ERROR = 1.
OUT PortB ;xuat nibble thap va bao
ERROR = 1.
ChkSTB0:IN PortC ;doc lenh dieu khien
STROBE.
ANI 01h
CPI 00h
JNZ ChkSTB0 ;neu STROBE # 0 thi doi tiep.
IN PortA ;doc du lieu.
CPI 0FFh ;FFh la ma bao du lieu dung.
JZ NoChk
CALL PROCESS
NoChk: MVI A,40h ;bao BUSY\ = 1.
OUT PortB
LUAÂÄN VAÊN TOÁT NGHIEÄP
3
JMP ChkSTB1 ;chuan bi nhan byte ke tiep.
;+++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++
;Chuong trinh con hien thi "READY" tren nam
LED 7 doan.
;+++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++
READY: PUSH PSW
MVI A,10h ;khoi tao 8279: hien thi 8 ki
tu,loi vao phai,
STA CntI79 ;quet ban phim co lap ma,
khoa ngoai 2 phim.
MVI A,3Eh ;lap trinh xung Clock = 100
KHz.
STA CntI79
MVI A,0C3h ;xoa hien thi va xoa FIFO.
STA CntI79
MVI A,01h ;tri hoan 0.1 ms > 160 us.
CALL DELAY
MVI A,90h ;bat dau ghi vao tai LED dau
tien ben phai, co
STA CntI79 ;tang dia chi tu dong.
MVI A,31h ;cho hien thi "R".
STA DataI79
MVI A,79h ;cho hien thi "E".
STA DataI79
MVI A,77h ;cho hien thi "A".
STA DataI79
MVI A,5Eh ;cho hien thi "D".
STA DataI79
MVI A,6Eh ;cho hien thi "Y".
STA DataI79
POP PSW
RET
;+++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++;Chuong trinh con
hien thi "SENDING" tren bay LED 7 doan.
;+++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++ SENDING:POP PSW
LUAÂÄN VAÊN TOÁT NGHIEÄP
4
MVI A,10h ;khoi tao 8279: hien thi 8 ki
tu,loi vao phai,
STA CntI79 ;quet ban phim co lap ma,
khoa ngoai 2 phim.
MVI A,3Eh ;lap trinh xung Clock = 100
KHz.
STA CntI79
MVI A,0C3h ;xoa hien thi va xoa FIFO.
STA CntI79
MVI A,01h ;tri hoan 0.1 ms > 160 us.
CALL DELAY
MVI A,90h ;bat dau ghi vao tai LED dau
tien ben phai, co
STA CntI79 ;tang dia chi tu dong.
MVI A,6Dh ;cho hien thi "S".
STA DataI79
MVI A,79h ;cho hien thi "E".
STA DataI79
MVI A,37h ;cho hien thi "N".
STA DataI79
MVI A,5Eh ;cho hien thi "D".
STA DataI79
MVI A,06h ;cho hien thi "I".
STA DataI79
MVI A,37h ;cho hien thi "N".
STA DataI79
MVI A,6Fh ;cho hien thi "G".
STA DataI79
POP PSW
RET
;+++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++;Chuong trinh con
xu li du lieu: Chuong trinh nay se nhan dia
chi bat
;dau va dia chi cham dut cua vung du lieu,
cac ma may cua chuong trinh
;tren may tinh do xuong se duoc dat trong
pham vi vung nay.
LUAÂÄN VAÊN TOÁT NGHIEÄP
5
;+++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++
PROCESS:MOV A,C ;kiem tra xem co phai day
la byte thu nhat
;khong ?
CPI 00h
JNZ A1
MOV H,B ;neu dung thi cat byte thu nhat
vao thanh ghi H.
INR C ;tang bien dem byte dia chi len 1
don vi.
RET
A1: MOV A,C ;kiem tra xem co phai day la byte
thu hai khong ?
CPI 01h
JNZ A2
MOV L,B ;neu dung thi cat byte thu hai
vao thanh ghi L.
INR C ;tang bien dem byte dia chi len 1
don vi.
RET
A2: MOV A,C ;kiem tra xem co phai day la byte
thu ba khong ?
CPI 02h
JNZ A3
MOV D,B ;neu dung thi cat byte thu ba vao
thanh ghi D.
INR C ;tang bien dem byte dia chi len 1
don vi.
RET
A3: MOV A,C ;kiem tra xem day co phai la byte
thu tu khong ?
CPI 03h
JNZ A4
MOV E,B ;neu dung thi cat byte thu tu vao
thanh ghi E.
INR C ;tang bien dem byte dia chi len 1
don vi.
RET
LUAÂÄN VAÊN TOÁT NGHIEÄP
6
A4: MOV M,B ;ke tu byte thu nam tro di se
duoc cat vao o nho co
INX H ;dia chi do cap thanh ghi HL quan
li.
MOV A,D
CPI H
RNZ
MOV A,E
CMP L
RNZ ;thoat neu HL tro den dia chi
cham dut nam trong DE.
CALL END ;cho hien thi "END." tren ba
LED 7 doan.
MVI A,40h ;bao BUSY\ = 1.
OUT PortB
HLT
;+++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++;Chuong trinh con
hien thi "END." tren ba LED 7 doan.
;+++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++ END: PUSH PSW
MVI A,10h ;khoi tao 8279: hien thi 8 ki
tu,loi vao phai,
STA CntI79 ;quet ban phim co lap ma,
khoa ngoai 2 phim.
MVI A,3Eh ;lap trinh xung Clock = 100
KHz.
STA CntI79
MVI A,0C3h ;xoa hien thi va xoa FIFO.
STA CntI79
MVI A,01h ;tri hoan 0.1 ms > 160 us.
CALL DELAY
MVI A,90h ;bat dau ghi vao tai LED dau
tien ben phai, co
STA CntI79 ;tang dia chi tu dong.
MVI A,79h ;cho hien thi "E".
STA DataI79
MVI A,54h ;cho hien thi "N".
STA DataI79
LUAÂÄN VAÊN TOÁT NGHIEÄP
7
MVI A,0DEh ;cho hien thi "D.".
STA DataI79
POP PSW
RET
;+++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++;Hai chuong trinh
con sau day da co san trong thiet bi thuc
tap Vi xu ;li 8085
;nen nguoi thuc hien de tai nay thay khong
can thiet phai viet lai va ;trinh bay
;ra. Do la 2 chuong trinh:
;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
8
B.Module Demo.cpp
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <graphics.h>
#include <string.h>
#include <dos.h>
#include <math.h>
#include <complex.h>
#include <time.h>
#include <dir.h>
#include <ctype.h>
#include "screen.h"
#include "mouse.h"
#include "button.hpp"
#include "textbox.hpp"
#include "list.hpp"
#include "disklist.hpp"
#include "send.hpp"
#define NumBox 2
#define NumBut 2
LPEVENT lpEvent; //bien chua cac bien co
chuot
char szMessage[128];
BUTTON But[NumBut],NutKiem;
TEXTBOX Box[NumBox],Port;
char DiskName[27],DName;
char ftype[15]="*.prn";
char inter_Path[100]="";
char RequF[100];
unsigned int St_address,End_address=0;
char Sta_hex[5],End_hex[5];
//------------------------------------------
---------------
LUAÂÄN VAÊN TOÁT NGHIEÄP
9
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();
}
//------------------------------------------
---------------
void MainProgram()
{
char Name[20],buffer[MAXPATH];
unsigned attrib,Attribp;
SEND Send;
LIST L;
LUAÂÄN VAÊN TOÁT NGHIEÄP
10
But[0].InitButton(200,380,250,400,LIGHTGRAY,
"Send");
But[1].InitButton(400,380,450,400,LIGHTGRAY,
"Exit");
Box[0].InitTextBox(50,70,477,90,GREEN,LIGHTG
REEN,"Open File");
Port.InitTextBox(50,270,250,290,GREEN,LIGHTG
REEN,"Out port");
Port.GetS_in("LPT1");
L.InitList(480,70,500,90,LIGHTGRAY);
But[0].OutButton();//xuat nut lenh
But[1].OutButton();//xuat nut lenh
Box[0].OutTextBox();//xuat hop nhap text
Port.OutTextBox();
L.Show();
setcolor(BLACK);
line(50,150,250,150);
line(50,150,50,215);
setcolor(WHITE);
line(50,215,250,215);
line(250,150,250,215);
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
{
LUAÂÄN VAÊN TOÁT NGHIEÄP
11
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(End_address!=0)
{
if(OutError("Are you sure ?"))
{
OutMessage("Sending... Press Esc
to stop if time is over.");
Send.CatFile(Sta_hex,End_hex,inter_Path);
Send.Out();
HideMouse();
if(Send.Out()!=-1)
{
HideMouse();
OutMessage("");
OutError("Task is complete.");
LUAÂÄN VAÊN TOÁT NGHIEÄP
12
OutMessage("Click mouse to
choose action");
}
else
{
HideMouse();
OutMessage("Click mouse to
choose action");
}
}
}
}
}//if(TestPressedButton
if(TestPressList(L,lpEvent,Name,&attrib,ftyp
e)==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;
LUAÂÄN VAÊN TOÁT NGHIEÄP
13
}//end switch
}//if(TestPressList(
//chon Cancel
TestPressTexbox(NumBox,lpEvent,inter_Path,&A
ttribp);//Path lay ra duong dan cho file
nhap vao
//ShowMouse();
if(kbhit())
{
kkkk=getch();
if(kkkk==0)kkkk=getch();
}
Box[0].GetS(RequF);
{
int n=strlen(RequF);
if(n>5)//?.???
if(RequF[n-1]!='\\')
{
while(n>0&&RequF[n-1]!='\\')
{
n--;
}
char *strtemp=RequF;
for(int m=0;m<n;m++)
strtemp++;
if(strcmp(RequestFile,strtemp))//neu
file chon co thay doi
{
setfillstyle(SOLID_FILL,CYAN);
bar(155,155,245,210);
strcpy(RequestFile,strtemp);
strtemp+=strlen(strtemp)-4;
if(!strcmp(strtemp,".prn"))//neu
dung file prn
{
FILE *f;
if ((f = fopen(RequF,"rb")) ==
NULL)
LUAÂÄN VAÊN TOÁT NGHIEÄP
14
{
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;
fseek(f,-5,SEEK_CUR);
fread(address,10,1,f);
address[4]='\0';
strcpy(Sta_hex,address);
LUAÂÄN VAÊN TOÁT NGHIEÄP
15
HideMouse();
strcat(address," Hex");
outtextxy(170,158,address);
for
(FindPos=3;FindPos>=0;FindPos--)
for(FindValue=0;FindValue<22;FindValue++
)
if(address[FindPos]==KyTu_Hex[FindValue])
Value1+=pow(16,(3-
FindPos))*Gtri_Dec[FindValue];
St_address=(unsigned
int)Value1;
ShowMouse();
thoat=1;
start = clock();
do
{
do
{
fread(&c,1,1,f);
end = clock();
}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);
LUAÂÄN VAÊN TOÁT NGHIEÄP
16
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
{
dem++;
fread(&c,1,1,f);
if(c=='\n')
dem=20;
fseek(f,-2,SEEK_CUR);
end = clock();
}while(dem<10&&(period=(end -
start) / CLK_TCK)<15);
if(period>=15) goto Error;
end = clock();
}while(dem!=20&&(period=(end -
start) / CLK_TCK)<15);
if(period>=15) goto Error;
fseek(f,2,SEEK_CUR);
start = clock();
do
{
fread(&c,1,1,f);
end = clock();
LUAÂÄN VAÊN TOÁT NGHIEÄP
17
}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);
LUAÂÄN VAÊN TOÁT NGHIEÄP
18
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()<= lpEvent-
>Posx&&But[i].Top()<=lpEvent-
>Posy&&But[i].Right()>=lpEvent-
>Posx&&But[i].Bottom()>=lpEvent->Posy)
{
HideMouse();
But[i].PressButton();
delay(100);
But[i].OutButton();
if(i==1)
LUAÂÄN VAÊN TOÁT NGHIEÄP
19
{
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()<= 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);
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
LUAÂÄN VAÊN TOÁT NGHIEÄP
20
//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);
LUAÂÄN VAÊN TOÁT NGHIEÄP
21
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;
}
LUAÂÄN VAÊN TOÁT NGHIEÄP
22
//------------------------------------------
---------------
int TestPressList(LIST L,LPEVENT
lpEvent,char s[],unsigned *attrib,char *typ)
{
int k=0;
if(lpEvent->Msg==1)
if(L.Left()<= lpEvent-
>Posx&&L.Top()<=lpEvent-
>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,t
yp);
}
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;}
LUAÂÄN VAÊN TOÁT NGHIEÄP
23
int Right() {return r;}
int Top() {return t;}
int Bottom() {return b;}
};
#endif
III.MODULE BUTTON.CPP
#include <graphics.h>
#include <string.h>
#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);
}
LUAÂÄN VAÊN TOÁT NGHIEÄP
24
//------------------------------------------
---------------
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 <dir.h>
#include <alloc.h>
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <graphics.h>
#include <bios.h>
#include <PROCESS.H>
// <PROCESS.H, STDLIB.H>
LUAÂÄN VAÊN TOÁT NGHIEÄP
25
#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
{