em không viết được thường trú (test thường trú là treo máy ảo), chỉ viết được bằng ngôn ngữ c (asm cực quá chuyển c viết).
Code:
#include"conio.h"
#include"stdio.h"
#include"dos.h"
#include"time.h"
#include"string.h"
#include"stdlib.h"
char screen[]="Sreen Saver";
void Luu_KT_Man_Hinh(char buf[]);
void Phuc_Hoi_Man_Hinh(char buf[]);
void Sreen_Saver(char buf[]);
unsigned long tg_giay(void)
{
static struct time ti;
unsigned long t;
gettime(&ti);
t=(ti.ti_hour+60+ti.ti_min)*60+ti.ti_sec;
return t;
}
char Doc_KT(int dong,int cot)
{
char kt;
int off=(80*dong+cot)*2;
kt=peekb(0xb800,off);
return kt;
}
void IN_KT(char kt,int dong,int cot)
{
int off=(80*dong+cot)*2;
pokeb(0xb800,off,kt);
}
void Phuc_Hoi_Man_Hinh(char buf[])
{
int dong;
int cot;
int i=0;
int off;
for(dong=0;dong<25;dong++)
for(cot=0;cot<80;cot++)
{
off=(80*dong+cot)*2;
pokeb(0xb800,off,buf[i]);
i++;
}
}
void Luu_KT_Man_Hinh(char buf[])
{
int dong;
int cot;
int i=0;
int off;
for(dong=0;dong<25;dong++)
for(cot=0;cot<80;cot++)
{
off=(80*dong+cot)*2;
buf[i]=peekb(0xb800,off);
i++;
}
}
void Chu_Roi(char buf[])
{
int dong;
int cot;
char doc_kt;
char kt;
Luu_KT_Man_Hinh(buf);
while(1)
{
for(dong=0;dong<25;dong++)
for(cot=0;cot<80;cot++)
{
doc_kt=Doc_KT(dong,cot);
if(dong<24)
{
for(int i=dong+1;i<25;i++)
{
if(kbhit())
goto phuchoi;
kt=Doc_KT(i,cot);
delay(1);
if(doc_kt==32)
break;
IN_KT(doc_kt,i,cot);
delay(100);
IN_KT(' ',dong,cot);
delay(100);
IN_KT(kt,i,cot);
}
}
}
if(dong==25)
{
for(cot=0;cot<80;cot++)
IN_KT(' ',dong-1,cot);
dong=12;
int len=strlen(screen);
for(cot=1;cot<=80;cot++)
{
if(kbhit())
goto phuchoi;
gotoxy(cot,dong);
int tam;
tam=80-cot;
if(tam==len)
{
for(cot=cot;cot>=1;cot--)
{
if(kbhit())
goto phuchoi;
gotoxy(cot,dong);
delay(100);
puts(screen);
delay(100);
clrscr();
}
}
else
{
if(kbhit())
goto phuchoi;
puts(screen);
delay(100);
gotoxy(cot,dong);
delay(100);
putch(32);
}
}
}
}
phuchoi:
Phuc_Hoi_Man_Hinh(buf);
}
void Screen_Saver(char buf[])
{
int tg_doi=30;
unsigned long t_bd,t_ht;
t_bd=tg_giay();
while(1)
{
t_ht=tg_giay();
if(t_ht-t_bd>=tg_doi)
{
Chu_Roi(buf);
break;
}
}
}
void main()
{
clrscr();
char buf[2000];
// du liêu de test
printf("vo thanh long");
printf("\nabc de");
printf("\nfgh i");
printf("\nvo thanh long");
printf("\ncd a");
printf("vo thanh long");
printf("vo thanh long");
printf("vo thanh long");
printf("vo thanh long");
printf("vo thanh long");
//test dong cuoi
gotoxy(1,25);
printf("vo thanh long");
Screen_Saver(buf);
getch();
getch();
}
Chương trình chưa tốt lắm.