📄 hex_core.c
字号:
0x84210 is the 5 nibble blocks.
The whole row is 80 bits given by DataSize.
The number of times the block repeat itself
is found by DataSize/(4*0x05) which is 4.
0xFF -- Compress by the most frequently happen byte.
Example:
Original stream: 0x04020401030904040404
Compressed stream: 0xFF04(0,1,0x02,0,1,0x01,1,0x03,1,0x09,0,0,0)
or: 0xFF044090181C240
Detail: 0xFF is the code, 0x04 is the key.
a bit of 0 represent the key shall be put into
the current bit position and a bit of 1
represent copying the next of 8 bits of data
in.
Input
SF----------------Data has compression code if true
Return
ByteData-----------The data stream from ispVM file
*****************************************************************************/
void ispVMData()
{
unsigned short int size;
short int i, j, m, index, getData = 0;
unsigned char xch, compress = 0;
short int FFcount = 0;
unsigned char compr_char = 0xFF;
char ByteData;
char compression=0;
/*convert number in bits to bytes*/
if (DataSize%8>0) size = DataSize/8 + 1;
else size = DataSize/8;
/*if there is compression, then check if compress by key of 0x00 or 0xFF
or by other keys or by nibble blocks*/
if (DataType&COMPRESS){
compression = 1;
if ((compress = GetByte()) == VAR && DataType&HEAP_IN) {
getData = 1;
DataType &= ~(HEAP_IN);
compress = GetByte();
}
switch (compress){
case 0x00: /*no compression*/
compression = 0;
break;
case 0x01: /*compress by byte 0x00*/
compr_char = 0x00;
break;
case 0x02: /*compress by byte 0xFF*/
compr_char = 0xFF;
break;
case 0xFF: /*huffman encoding*/
compr_char = GetByte();
i = 8;
for (index = 0; index < size; index++)
{
ByteData = 0x00;
if (i>7){
xch = GetByte();
i = 0;
}
if ((xch << i++) & 0x80) m = 8;
else {
ByteData= compr_char;
m = 0;
}
for (j = 0; j < m; j++) {
if (i > 7) {
xch = GetByte();
i = 0;
}
ByteData |=((xch << i++)&0x80) >> j;
}
}
size = 0;
break;
default: /*compression by nibble blocks*/
for (index = 0; index < size; index++)
ByteData = 0x00;
for (index = 0; index < compress; index++)
{
if (index%2 == 0) xch = GetByte();
for (i = 0; i < size*2/compress; i++){
j = index + i*compress;
/*clear the nibble to zero first*/
if (j%2) {
if (index%2) ByteData |= xch & 0x0F;
else ByteData |= xch >> 4;
}
else {
if (index%2) ByteData |= xch << 4;
else ByteData |= xch & 0xF0;
}
}
}
size = 0;
break;
}
}
FFcount = 0;
#ifdef VME_DEBUG
printf("\ncompression=%d, compress=%02X, size=%d key=%X\n", compression, compress, DataSize, compr_char);
#endif
/*decompress by byte 0x00 or 0xFF*/
for (index = 0; index < size; index++) {
if (FFcount <= 0) {
xch = GetByte();
if ((xch == VAR) && (DataType&HEAP_IN) && !getData && !(DataType&COMPRESS)) {
getData = 1;
DataType &= ~(HEAP_IN);
xch = GetByte();
}
ByteData = xch;
if ((compression) &&(xch == compr_char)) /*decompression is on*/
FFcount = ispVMDataSize(); /*The number of 0xFF or 0x00 bytes*/
}
else {
FFcount--; /*Use up the 0xFF chain first*/
ByteData = compr_char;
}
}
if (getData) {
DataType |= HEAP_IN;
getData = 0;
}
return;
}
/*************************************************************
* *
* GETBYTE *
* This procedure reads a byte from the ispVM File *
*************************************************************/
unsigned char GetByte()
{
unsigned char data;
if (DataType&HEAP_IN) { /*fetch data from HEAP memory where repeat loop is*/
if (HeapCounter>HEAPSize) return -1; /*heap over-run occur*/
data = HEAPMem[HeapCounter++]; /*fetch data from the stored repeat loop*/
}
else {
data = (unsigned char) fgetc(fpr);
if (feof(fpr))
return 0xFF;
}
return (data);
}
char ispVMLoop(unsigned short loop_cnt)
{
char rcode=0;
int x = 0, y = 0;
int loops;
int byteCounter = 0;
/*the data operator such as SHR and SHL, DEC INC etc shall be initialize upon
entering the repeat loop*/
OPCount=0;
/*store the entire repeat loop into memory first*/
for (x = 0; x < HEAPSize; x++) {
HEAPMem[x] = GetByte();
}
if (HEAPMem[x-1]!=ENDLOOP)
return(-4); /*the last opcode must be ENDLOOP*/
/*set the flag to indicate data is from the stored repeat loop*/
DataType |= HEAP_IN;
#ifdef VME_DEBUG
printf("\n=====>In Repeat Loops (%d).\n",loop_cnt);
#endif
for (loops=0; loops<loop_cnt; loops++) {
HeapCounter=0; /*restore pointer to the first byte*/
rcode = ispVMCode();
RepeatLoops++;
if (rcode < 0)
break;
} /* for */
#ifdef VME_DEBUG
printf("\n====>Exit Repeat Loops (%d).\n",loop_cnt);
#endif
if (HEAPMem != NULL) {
free(HEAPMem);
HEAPMem = NULL;
}
/*clear all the flags to indicate success*/
DataType &= ~(HEAP_IN);
return (rcode);
}
/****************************************************************************
ispVM Amble
This routine is to extract Header and Trailer parameter for SIR and
SDR operations.
The Header and Trailer parameter are the pre-amble and post-amble bit
stream need to be shifted into TDI or out of TDO of the devices. Mostly
is for the purpose of bypassing the leading or trailing devices. ispVM
supports only shifting data into TDI to bypass the devices.
For a single device, the header and trailer parameters are all set to 0
as default by ispVM. If it is for multiple devices, the header and trailer
value will change as specified by the VME file.
Input
Code---------------HIR, HDR, TIR ,TDR.
Return
rcode--------------pass or fail
*****************************************************************************/
char ispVMAmble(char Code)
{
int compress = 0;
int temp;
DataSize = ispVMDataSize();
if (DataSize) {
GetByte(); /*discard the TDI opcode*/
/* header and trailers are not compressed */
if (DataType&COMPRESS) {
DataType &= ~(COMPRESS);
compress = 1;
}
}
temp = DataSize;
switch (Code) {
case HIR: /*modify the IR length of lead devices*/
if (temp){
/*hold the IR opcode for the lead devices*/
if (temp > hirdata)
hirdata = temp;
DataSize = temp;
ispVMData();
}
break;
case TIR: /*modify the IR length of the trailing devices*/
if (temp) {
/*hold the IR opcode for the trailing devices*/
if (temp > tirdata)
tirdata = temp;
DataSize = temp;
ispVMData();
}
break;
case HDR: /*modify the DATA length of the lead devices*/
if (temp) {
/*hold the data stream for the lead devices*/
if (temp > hdrdata)
hdrdata = temp;
DataSize = temp;
ispVMData();
}
break;
case TDR: /*modify the DATA length of the trailing devices*/
if (temp) {
/*hold the data stream for the trailing devices*/
if (temp > tdrdata)
tdrdata = temp;
DataSize = tdrdata;
ispVMData();
}
break;
default:
break;
}
/* resume compression */
if (compress)
DataType |= COMPRESS;
if (DataSize) { /* Search for CONTINUE */
Code = GetByte();
if (Code == CONTINUE) {
return 0;
}
else {
return -4;
}
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -