/*****************************\
*Program Function:Memery test
*Coder:LiF
*Midify:
\*****************************/
#include "C:\watcom\H\stdio.h"
#include "C:\watcom\H\conio.h"
#include "C:\watcom\H\dos.h"
#include "C:\watcom\H\process.h"
#include "C:\watcom\H\stdlib.h"
#include "C:\watcom\H\GRAPH.H"
#include "C:\watcom\H\i86.H"
#define MC_PRO_BAR 0x01
#define MC_TEST_BYTE 1
#define MC_TEST_WORD 2
#define MC_TEST_DW 3
#define MC_ERROR_COUNT 20
#define MC_STRICT_COUNT 5000
unsigned long ulAddressLow; //地址下限
unsigned long ulAddressHigh; //地址上限
//四个结构,分别存储在测试的过程中发现的错误信息,错误信息没有全部存储,只存储了前MC_ERROR_COUNT个
struct ErrorByte
{
unsigned long ulAddress; //地址
char cWrite; //写的内容
char cRead; //读的内容
}sErrorByte[MC_ERROR_COUNT];
unsigned long iErrorCountByte; //记录产生了多少个错误
struct ErrorWord
{
unsigned long ulAddress; //地址
short sWrite; //写的内容
short sRead; //读的内容
}sErrorWord[MC_ERROR_COUNT];
unsigned long iErrorCountWord; //记录产生了多少个错误
struct ErrorDW
{
unsigned long ulAddress; //地址
long lWrite; //写的内容
long lRead; //读的内容
}sErrorDW[MC_ERROR_COUNT];
unsigned long iErrorCountDW; //记录产生了多少个错误
struct ErrorComplexTest
{
unsigned long ulAddressMod; //写什么地址时发现了另外的地址不对
unsigned long ulAddressAff; //发现问题的地址
char cWrite; //地址一写的内容
char cRead; //地址二读的内容
}sErrorComplexTest[MC_ERROR_COUNT];
unsigned long iErrorCountComplexTest;//记录产生了多少个错误
struct ErrorStrictTest
{
unsigned long ulAddressMod; //写什么地址时发现了另外
unsigned long ulAddressAff; //发现问题的地址
char cWrite; //地址一写的内容
char cRead; //地址二读的内容
}sErrorStrictTest[MC_ERROR_COUNT];
unsigned long iErrorCountStrictTest;//记录产生了多少个错误
/******************************
*Function:move_to_xy
*description: change place of cursor to (x,y)
*input: x,y:new Place of cursor
*
*******************************/
void move_to_xy(int x,int y)
{
union REGS regs;
if (x>79||x<0||y>24||y<0) exit;
regs.h.ah = 2;
regs.h.dh = y;
regs.h.dl = x;
regs.h.bh = 0;
int386(0x10, ®s,®s);
}
/******************************
*Function:write_char
*description:write a char at point(x,y)
*input:
*
*******************************/
write_char(int x,int y,char c)
{
union REGS regs;
move_to_xy(x,y);
regs.h.ah = 0xa;
regs.h.bh = 0;
regs.h.al = c;
regs.x.ecx = 1;
int386(0x10,®s,®s);
}
/******************************
*Function:print_state
*description:print a sting in state area
*input: char c[]
*
*******************************/
void print_state(char c[])
{
char cArr[70];
int iLoop;
for (iLoop = 0; iLoop<69;iLoop++)
{
cArr[iLoop] = ' ';
}
cArr[69] = '\0';
for (iLoop = 0; (c[iLoop]!='\0')&&(iLoop<69);iLoop++)
{
cArr[iLoop] = c[iLoop];
}
move_to_xy(4,21);
printf("STAT:%s\n",cArr);
}
/******************************
*Function:print_hint
*description:print a string in hint area
*input: char c[]--content of string
*
*******************************/
void print_hint(char c[])
{
char cArr[71];
int iLoop;
for (iLoop = 0; iLoop<70;iLoop++)
{
cArr[iLoop] = ' ';
}
cArr[70] = '\0';
for (iLoop = 0; (c[iLoop]!='\0')&&(iLoop<70);iLoop++)
{
cArr[iLoop] = c[iLoop];
}
move_to_xy(4,23);
printf("HINT:%s\n",cArr);
}
void clear_report_area()
{
char cArr[78];
int iLoop;
for (iLoop = 0; iLoop<77;iLoop++)
{
cArr[iLoop] = ' ';
}
cArr[77] = '\0';
for (iLoop = 5; iLoop<20;iLoop++)
{
move_to_xy(1,iLoop);
printf("%s\n",cArr);
}
}
/******************************
*Function:zero_memory
*description:write all memory with 0x00
*input: NONE
*
*******************************/
void zero_memory()
{
unsigned long ulAddress;
char * pc;
for(ulAddress=ulAddressLow;ulAddress<ulAddressHigh;ulAddress+=1)
{
pc = (char *)ulAddress;
*pc = 0x00;
}
}
/******************************
*Function:simple_test
*description:Simple test,write a value to an address and only read this address
*input: iTestType---Write byte,word or double word
* ulValue---Write what
*******************************/
void simple_test(int iTestType, unsigned long ulValue)
{
unsigned long ulAddress;
char * pc;
char c;
short *ps;
short s;
long * pl;
long l;
switch (iTestType)
{
case MC_TEST_BYTE:
for(ulAddress=ulAddressLow;ulAddress<ulAddressHigh;ulAddress+=1)
{
pc = (char *)ulAddress;
*pc = (char)ulValue;
}
for(ulAddress=ulAddressLow;ulAddress<ulAddressHigh;ulAddress+=1)
{
pc = (char *)ulAddress;
c = *pc;
if (c!=(char)ulValue)
{
if (iErrorCountByte<MC_ERROR_COUNT)
{
sErrorByte[iErrorCountByte].ulAddress = ulAddress;
sErrorByte[iErrorCountByte].cWrite = (char)ulValue;
sErrorByte[iErrorCountByte].cRead = c;
}
iErrorCountByte++;
}
}
break;
case MC_TEST_WORD:
for(ulAddress=ulAddressLow;ulAddress<ulAddressHigh;ulAddress+=2)
{
ps = (short *)ulAddress;
*ps = (short)ulValue;
}
for(ulAddress=ulAddressLow;ulAddress<ulAddressHigh;ulAddress+=2)
{
ps = (short *)ulAddress;
s = *ps ;
if (s != (short)ulValue)
{
if (iErrorCountWord<MC_ERROR_COUNT)
{
sErrorWord[iErrorCountWord].ulAddress = ulAddress;
sErrorWord[iErrorCountWord].sWrite = (short)ulValue;
sErrorWord[iErrorCountWord].sRead = s;
}
iErrorCountWord++;
}
}
break;
case MC_TEST_DW:
for(ulAddress=ulAddressLow;ulAddress<ulAddressHigh;ulAddress+=4)
{
pl = (long *)ulAddress;
*pl = (long)ulValue;
}
for(ulAddress=ulAddressLow;ulAddress<ulAddressHigh;ulAddress+=4)
{
pl = (long *)ulAddress;
l = *pl;
if (l != (long)ulValue)
{
if (iErrorCountDW<MC_ERROR_COUNT)
{
sErrorDW[iErrorCountDW].ulAddress = ulAddress;
sErrorDW[iErrorCountDW].lWrite = (short)ulValue;
sErrorDW[iErrorCountDW].lRead = l;
}
iErrorCountDW++;
}
}
break;
}
}
/******************************
*Function:complex_test
*description:complex test,write a value to an address and read this address or others
*input: iTestType---Write byte,word or double word
* ulValue---Write what
*******************************/
void complex_test(char cValue)
{
int iLoop;
unsigned long ulAddress;
unsigned long ulReadLoop;
unsigned long ulStep;
char * pc;
unsigned long ulGroupCount; //已经测试了几组,每组打印一个进度块;
unsigned long ulNumberInGroup; //每组多少个单元需要测试
unsigned long ulCountInGroup; //已经测试了多少个,凑够一组后清零
ulNumberInGroup = (ulAddressHigh - ulAddressLow)/66;
print_hint("");
for (iLoop = 9;iLoop <75; iLoop++)
{
write_char(iLoop,23,2);
}
ulGroupCount = 0;
ulCountInGroup = 0;
for(ulAddress=ulAddressLow;ulAddress<ulAddressHigh;ulAddress+=1,ulCountInGroup++)
{
pc = (char *)ulAddress;
*pc = cValue;
ulStep = 1;
for (ulReadLoop = ulAddress + ulStep;ulReadLoop < ulAddressHigh; ulReadLoop += ulStep,ulStep*=2)
{
pc = (char *)ulReadLoop;
if (*pc != 0x00)
{
if (iErrorCountComplexTest<MC_ERROR_COUNT)
{
sErrorComplexTest[iErrorCountComplexTest].ulAddressMod = ulAddress;
sErrorComplexTest[iErrorCountComplexTest].ulAddressAff = ulReadLoop;
sErrorComplexTest[iErrorCountComplexTest].cWrite = cValue;
sErrorComplexTest[iErrorCountComplexTest].cRead = *pc;
}
iErrorCountComplexTest++;
*pc = 0;
}
}
if (ulCountInGroup == ulNumberInGroup)
{
ulCountInGroup = 0;
ulGroupCount++;
write_char(ulGroupCount+8,23,1);
}
}
}
/******************************
*Function:sample_strict_test
*description:Get MC_STRICT_COUNT address,write a v