📄 box.c
字号:
#include <dos.h>
#include <stdio.h>
#include <conio.h>
#include <alloc.h>
#include <time.h>
#include <ctype.h>
#include <string.h>
#define BORDER 1
#define ESC 27
#define TAB 9
#define REV_VID 0x70
#define NORM_VID 7
#define PORT_8259 0x21
#define PORT_8259_I 0x20
void save_video(),restore_video();
void goto_xy(),cls(),write_video();
void display_menu(),draw_border();
void show();
void waitibe(void);
void waitobf(void);
void Cmd81h(void);
void Cmd82h(void);
void Cmd83h(void);
void Cmd84h(void);
void Cmd85h(void);
void Cmd86h(void);
void Cmd87h_0(void);
void Cmd87h_1(void);
void Cmd88h(void);
void Cmd89h(void);
void Cmd8Ah(void);
void Cmd8Bh(void);
void Cmd8Ch(void);
void Cmd8Dh(void);
void Cmd8Eh(void);
void Cmd8Fh(void);
void CmdCDh(void);
void KBCOFF(void);
void KBCON(void);
void Thermal(void);
int IMR_8259A;
char *start[] ={
" 0 = 81h - Read FAN 0 Speed ",
" 1 = 82h - Read Thermal ",
" 2 = 83h - Protect Flash ROM ",
" 3 = 84h - Unprtotect Flash ROM ",
" 4 = 85h - Read RNG ",
" 5 = 86h - Enable Periodic Event ",
" 6 = 87h-00h - Read Time-Stamp Timer 0 ",
" 7 = 87h-01h - Read Time-Stamp Timer 1 ",
// " 3 = 88h - S-ROM Block Select ",
// " 4 = 89h - Read S-RAM low index ",
// " 5 = 8Ah - Write S-RAM low index ",
// " 6 = 8Bh - Read S-RAM high index ",
// " 7 = 8Ch - Write S-RAM high index ",
// " 8 = 8Dh - Copy S-ROM data to S-RAM",
// " 9 = 8Eh - Verify S-ROM with S-RAM ",
// " A = 8Fh - Copy S-RAM data to S-ROM",
" 8 = CDh - Read Event ID ",
};
void main(void)
{
int y=0;
long tt=0;
cls();
while(y != -1)
{
y=task1();
// tt++;
// if(tt>=1000000)
// Thermal();
// tt=0;
}
}
void Thermal()
{
unsigned int Tempr0;
KBCOFF();
cls();
goto_xy(05,30);
waitibe();
outportb(0x64,0xC4);
waitibe();
outportb(0x60,0x00);
waitobf();
Tempr0=inportb(0x60);
printf("The CPU temprature is %0d'C\n",Tempr0);
KBCON();
}
int task1()
{
int x=popup(start, "012345678",9,0,0,BORDER);
// int x=popup(start, "0123456789AB",12,0,0,BORDER);
switch (x)
{
case 0 : Cmd81h();
break;
case 1 : Cmd82h();
break;
case 2 : Cmd83h();
break;
case 3 : Cmd84h();
break;
case 4 : Cmd85h();
break;
case 5 : Cmd86h();
break;
case 6 : Cmd87h_0();
break;
case 7 : Cmd87h_1();
break;
// case 3 : Cmd88h();
// break;
//
// case 4 : Cmd89h();
// break;
//
// case 5 : Cmd8Ah();
// break;
//
// case 6 : Cmd8Bh();
// break;
//
// case 7 : Cmd8Ch();
// break;
//
// case 8 : Cmd8Dh();
// break;
//
// case 9 : Cmd8Eh();
// break;
//
// case 10 : Cmd8Fh();
// break;
//
case 8 : CmdCDh();
break;
case -1 : cls();
exit(-1);
defult :
break;
}
}
void Cmd81h()
{
unsigned int Tempr1;
unsigned int Tempr2;
unsigned int Tempr3;
unsigned int Tempr4;
KBCOFF();
cls();
goto_xy(20,0);
waitibe();
outportb(0x64,0x81);
waitobf();
Tempr1=inportb(0x60);
waitobf();
Tempr2=inportb(0x60);
Tempr1=Tempr1+Tempr2*0x100;
if(Tempr1!=0)
Tempr1=22500000/Tempr1;
printf("The FAN 0 SPEED is %04d RPM \n",Tempr1);
KBCON();
}
void Cmd82h()
{
int Tempr1;
int Tempr2;
int Tempr3;
int Tempr4;
KBCOFF();
cls();
// goto_xy(20,0);
waitibe();
outportb(0x64,0xC4);
waitibe();
outportb(0x60,0x00);
waitobf();
Tempr1=inportb(0x60);
waitibe();
outportb(0x64,0xC4);
waitibe();
outportb(0x60,0x01);
waitobf();
Tempr2=inportb(0x60);
waitibe();
outportb(0x64,0xC4);
waitibe();
outportb(0x60,0x02);
waitobf();
Tempr3=inportb(0x60);
Tempr3=256/Tempr3*1.5;
waitibe();
outportb(0x64,0xC4);
waitibe();
outportb(0x60,0x03);
waitobf();
Tempr4=inportb(0x60);
Tempr4=256/Tempr4*1.5;
goto_xy(20,0);
printf("The CPU Temperature is %02d C \n",Tempr1);
goto_xy(21,0);
printf("The SYS Temperature is %02d C \n",Tempr2);
goto_xy(22,0);
printf("The 3V Voltage is %02d V \n",Tempr3);
goto_xy(23,0);
printf("The Vcore Voltage is %02d V \n",Tempr4);
KBCON();
}
void Cmd85h()
{
unsigned int Tempr1;
unsigned int Tempr2;
unsigned int Tempr3;
unsigned int Tempr4;
KBCOFF();
cls();
goto_xy(20,0);
waitibe();
outportb(0x64,0x85);
waitobf();
Tempr1=inportb(0x60);
waitobf();
Tempr2=inportb(0x60);
waitobf();
Tempr3=inportb(0x60);
waitobf();
Tempr4=inportb(0x60);
printf("The RNG is %02x%02x%02x%02x\n",Tempr1,Tempr2,Tempr3,Tempr4);
KBCON();
}
void Cmd86h(void)
{
// KBCOFF();
waitibe();
outportb(0x64,0x86);
// KBCON();
}
void Cmd87h_0(void)
{
unsigned int Tempr1;
unsigned int Tempr2;
unsigned int Tempr3;
unsigned int Tempr4;
unsigned int Tempr5;
unsigned int Tempr6;
KBCOFF();
cls();
goto_xy(20,0);
waitibe();
outportb(0x64,0x87);
waitibe();
outportb(0x60,0x00);
waitobf();
Tempr1=inportb(0x60);
waitobf();
Tempr2=inportb(0x60);
waitobf();
Tempr3=inportb(0x60);
waitobf();
Tempr4=inportb(0x60);
waitobf();
Tempr5=inportb(0x60);
waitobf();
Tempr6=inportb(0x60);
printf("The Stmp-Timer0 is %02x%02x%02x%02x%02x%02x\n",Tempr1,Tempr2,Tempr3,Tempr4,Tempr5,Tempr6);
KBCON();
}
void Cmd87h_1(void)
{
unsigned int Tempr1;
unsigned int Tempr2;
unsigned int Tempr3;
unsigned int Tempr4;
unsigned int Tempr5;
unsigned int Tempr6;
KBCOFF();
cls();
goto_xy(20,0);
waitibe();
outportb(0x64,0x87);
waitibe();
outportb(0x60,0x01);
waitobf();
Tempr1=inportb(0x60);
waitobf();
Tempr2=inportb(0x60);
waitobf();
Tempr3=inportb(0x60);
waitobf();
Tempr4=inportb(0x60);
waitobf();
Tempr5=inportb(0x60);
waitobf();
Tempr6=inportb(0x60);
printf("The Stmp-Timer1 is %02x%02x%02x%02x%02x%02x\n",Tempr1,Tempr2,Tempr3,Tempr4,Tempr5,Tempr6);
KBCON();
}
void Cmd83h(void)
{
waitibe();
outportb(0x64,0x83);
goto_xy(20,0);
printf("The FLASH ROM is in protection mode");
}
void Cmd84h(void)
{
waitibe();
outportb(0x64,0x84);
goto_xy(20,0);
printf("The FLASH ROM is in un-protection mode");
}
void Cmd88h(void)
{
}
void Cmd89h(void)
{
}
void Cmd8Ah(void)
{
}
void Cmd8Bh(void)
{
}
void Cmd8Ch(void)
{
}
void Cmd8Dh(void)
{
}
void Cmd8Eh(void)
{
}
void Cmd8Fh(void)
{
}
void CmdCDh(void)
{
unsigned int Tempr1;
KBCOFF();
waitibe();
outportb(0x64,0xCD);
waitobf();
Tempr1=inportb(0x60);
cls();
goto_xy(20,0);
printf("The Event number %02x\n",Tempr1);
KBCON();
}
void KBCOFF(void)
{
IMR_8259A = inport(PORT_8259);
outport(PORT_8259, 0xFE); // Disable keyboard interrupts
waitibe();
outport(0x64, 0x60); // Disable keyboard interface
waitibe();
outport(0x60, 0x74); // Disable keyboard interface
}
void KBCON(void)
{
outport(PORT_8259, IMR_8259A); // Re- enable keyboard interrupts
waitibe();
outport(0x64, 0xAD); // Disable keyboard interface
waitibe();
outport(0x64, 0x60); // Disable keyboard interface
waitibe();
outport(0x60, 0x47); // Enable keyboard interface
}
int popup(menu,keys,count,x,y,border)
char *menu[];
char *keys;
char count;
int border;
{
register int i,len;
int endx,endy,choice;
unsigned int *p;
if((x>24) || (x<0) || (y>79) || (y<0))
{ printf("range error");
return -2;
}
len = 0;
for(i=0;i<count;i++)
if(strlen(menu[i]) > len)
len = strlen(menu[i]);
endy = len + 2 + y;
endx = count + 1 + x;
if((endx+1>24) || (endy+1>79))
{
printf("menu won't fit");
return -2;
}
p=(unsigned int *) malloc((endx-x+x+1) * (endy-y+1));
if(!p) exit(1);
/* save_video(x,endx+1,y,endy+1,p); */
if(border) draw_border(x,y,endx,endy);
display_menu(menu,x+1,y+1,count);
choice = get_resp(x+1,y,count,menu,keys);
/* restore_video(x,endx+1,y,endy+1,(char *) p); */
free(p);
return choice;
}
void display_menu(menu,x,y,count)
char *menu[];
int x,y,count;
{
register int i;
for(i=0;i<count;i++,x++)
{
goto_xy(x,y);
printf(menu[i]);
}
}
void draw_border(startx,starty,endx,endy)
int startx,starty,endx,endy;
{
register int i;
for(i=startx+1;i<endx;i++)
{ goto_xy(i,starty);
putchar(179);
goto_xy(i,endy);
putchar(179);
}
for(i=starty+1;i<endy;i++)
{
goto_xy(startx,i);
putchar(196);
goto_xy(endx,i);
putchar(196);
}
goto_xy(startx,starty);putchar(218);
goto_xy(startx,endy);putchar(191);
goto_xy(endx,starty);putchar(192);
goto_xy(endx,endy);putchar(217);
}
get_resp(x,y,count,menu,keys)
int x,y,count;
char *menu[];
char *keys;
{
union inkey
{
char ch[2];
int i;
} c;
int arrow_choice=0,key_choice;
y++;
goto_xy(x,y);
write_video(x,y,menu[0],REV_VID);
for(;;)
{
while (!bioskey(1));
c.i=bioskey(0);
goto_xy(x+arrow_choice,y);
write_video(x+arrow_choice,y,menu[arrow_choice],NORM_VID);
if(c.ch[0])
{
key_choice=is_in(keys,tolower(c.ch[0]));
if(key_choice) return key_choice-1;
switch(c.ch[0])
{
case '\r':return arrow_choice;
case ' ' :arrow_choice++;
break;
case ESC : return -1;
case TAB : return -5;
}
}
else {
switch(c.ch[1]) {
case 72 : arrow_choice--;
break;
case 80 : arrow_choice++;
break;
}
}
if(arrow_choice==count) arrow_choice=0;
if(arrow_choice<0) arrow_choice=count-1;
goto_xy(x+arrow_choice,y);
write_video(x+arrow_choice,y,menu[arrow_choice],REV_VID);
}
}
void write_video(x,y,p,attrib)
int x,y;
char *p;
int attrib;
{
union REGS r;
register int i,j;
for(i=y;*p;i++)
{
r.h.ah=9;
r.h.bh=0;
r.x.cx=1;
r.h.al=*p++;
r.h.bl=attrib;
int86(0x10,&r,&r);
}
}
void save_video(startx,endx,starty,endy,buf_ptr)
int startx,endx,starty,endy;
unsigned int *buf_ptr;
{
union REGS r;
register int i,j;
for (i=starty;i<endy;i++)
for (j=startx;j<endy;j++)
{
goto_xy(j,i);
r.h.ah=8;
r.h.bh=0;
*buf_ptr++ = int86(0x10,&r,&r);
putchar(' ');
}
}
void restore_video(startx,endx,starty,endy,buf_ptr)
int startx,endx,starty,endy;
unsigned char *buf_ptr;
{
union REGS r;
register int i,j;
for(i=starty;i < endy;i++)
for(j=startx;j < endx;j++)
{
goto_xy(j,i);
r.h.ah = 9;
r.h.bh = 0;
r.x.cx = 1;
r.h.al=*buf_ptr++;
r.h.bl=*buf_ptr++;
int86(0x10,&r,&r);
}
}
void cls()
{
union REGS r;
r.h.ah =6 ;
r.h.al=0;
r.h.ch=0;
r.h.cl=0;
r.h.dh=24;
r.h.dl=79;
r.h.bh=7;
int86(0x10,&r,&r);
}
void goto_xy(x,y)
int x,y;
{
union REGS r;
r.h.ah=2;
r.h.dl=y;
r.h.dh=x;
r.h.bh=0;
int86(0x10,&r,&r);
}
is_in(s,c)
char *s,c;
{
register int i;
for(i=0;*s;i++) if(*s++==c) return i+1;
return 0;
}
void show(menu,count,x,y,border)
char *menu[];
char count;
int border;
{
register int i,len;
int endx,endy;
unsigned int *p;
len = 0;
for(i=0;i<count;i++)
if(strlen(menu[i]) > len)
len = strlen(menu[i]);
endy = len + 2 + y;
endx = count + 1 + x;
p=(unsigned int *) malloc((endx-x+x+1) * (endy-y+1));
if(!p) exit(1);
if(border) draw_border(x,y,endx,endy);
display_menu(menu,x+1,y+1,count);
free(p);
}
void waitibe(void)
{ unsigned char ibe;
do
{
ibe=inportb(0x64);
ibe&=0x02;
}
while (ibe != 0x00 );
}
void waitobf(void)
{ unsigned char obf;
do
{
obf=inportb(0x64);
obf&=0x01;
}
while (obf == 0x00 );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -