For DOS Protected Mode version of sensor core software
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

868 lines
25 KiB

//----------------------------------------------------------------------------
// Laser Guard Ltd.
// Copyright ?2000-2002. All Rights Reserved.
// Version 1.0 01/01/2000
// Last modification: 19/08/2002
// PROJECT:
// SUBSYSTEM:
// FILE: BOARD.CPP
// AUTHOR: Sergey Chizhevskiy
// OVERVIEW
// ~~~~~~~~
// Source file of BOARD.CPP
//----------------------------------------------------------------------------
#include "stdafx.h"
#include "board.h"
#include "screen.h"
//#include "..\LgLib\version.h"
#include "hardware.h"
bool HID_UI_Debug = false;
#ifdef DEBUG_ENABLE_OLD_BOARD
extern "C" void SMM( short, short[] );
short CBoard::s_pDataArray[4] = {0,0,0,0};
#endif
//#ifdef INCLUDE_WINDOWS_DEFINITIONS
// //static DWORD far* g_Timer = (DWORD far*)0x46CL;
// static DWORD far* g_Timer = ((DWORD far*) 0x46CL + __djgpp_conventional_base );
// static DWORD old_Timer = 0;
// #define TIMER() *g_Timer
//#else
// #define TIMER() (GetTickCount() * 10 / 182)
//#endif
#ifdef DMA_TRANSFERS
#ifdef ALS_300_EDMA
bool validateDMASettingsChecSumm( DMA_IO_BUFFER *Buffer ){
uint16_t Summ;
Summ = 0;
#ifdef DEBUG_PRINTOUT_MSGS
debugProcBegin("Validating CheckSumm");
#endif
for( uint8_t index = 0; index < (sizeof(DMA_IO_BUFFER)-1); index++ ){
Summ += (( uint8_t *) Buffer )[index];
Summ = Summ & 0xFF;
};
#ifdef DEBUG_PRINTOUT_MSGS
if( Buffer->CheckSumm == Summ ){
debugProcEnd();
return true;
} else {
debugProcEnd(0);
return false;
};
#else
return ( Buffer->fields.CheckSumm == Summ );
#endif
};
void updateDMASettingsChecSumm( DMA_IO_BUFFER *Buffer ){
uint16_t Summ;
Summ = 0;
for( uint8_t index = 0; index < (sizeof(DMA_IO_BUFFER)-1); index++ ){
Summ += (( uint8_t *) Buffer )[index];
Summ = Summ & 0xFF;
};
Buffer->fields.CheckSumm = Summ;
};
bool CBoard::LoadDMASettings( int DMA, DMA_IO_BUFFER *Buffer ){
long LinearAddress;
unsigned int Page, OffSet;
//Convert pointer to linear address
LinearAddress = FP_SEG ( Buffer );
LinearAddress = ( LinearAddress << 4 ) + FP_OFF( Buffer );
Page = LinearAddress >> 16; //Calculate page
OffSet = LinearAddress & 0xFFFF; //Calculate offset in the page
#ifdef DEBUG_PRINTOUT_MSGS
debugProcBegin( "Programm DMA Channel %d transfer %d bytes from board", DMA, sizeof(DMA_IO_BUFFER));
#endif
outportb (0x0A, 4 | DMA); //Mask DMA channel
outportb (0x0C, 0); //Clear byte pointer
outportb (0x0B, 0x44 | DMA ); //Set mode
/*
The mode consists of the following:
0x14 + x = binary 01 00 01 xx
|| || || ||
|| || || ++- DMA channel
|| || |+--- Write operation (the DSP writes to memory)
|| || +---- Read operation (the DSP reads from memory)
|| |+------ Autoinit
|| +------- Increment - 1/Decrement - 0
|+--------- Single mode - 1 -+--- 00 - on Demand
+---------- Block mode - 1 -+
*/
outportb (DMA << 1, OffSet & 0xFF ); //Write the offset to the DMA controller
outportb (DMA << 1, OffSet >> 8 );
if (DMA == 0) outportb ( 0x87, Page );
if (DMA == 1) outportb ( 0x83, Page );
if (DMA == 3) outportb ( 0x82, Page );
outportb (( DMA << 1 ) + 1, ( sizeof(DMA_IO_BUFFER) - 1 ) & 0xFF );
outportb (( DMA << 1 ) + 1, ( ( sizeof(DMA_IO_BUFFER) - 1 ) >> 8 ) & 0xFF );
outportb (0x0A, DMA); //Unmask DMA channel
#ifdef DEBUG_PRINTOUT_MSGS
debugProcEnd();
#endif
bool TranzactionComplete = false;
unsigned char Retry = 3;
DWORD Timeout;
static DWORD far* g_Timer = (DWORD far*)0x46CL;
uint8_t TCMASK = ( 0x01 << DMA );
while( ( TranzactionComplete == 0 ) && Retry ){
#ifdef DEBUG_PRINTOUT_MSGS
debugProcBegin("Signal To Board");
#endif
SignalToBoard( DMA_LOAD_ADDRESS );
#ifdef DEBUG_PRINTOUT_MSGS
debugProcEnd();
#endif
Retry--;
Timeout = 5; // Timeout 1/200 sec.
#ifdef DEBUG_PRINTOUT_MSGS
debugProcBegin("Wait till CF Flag Rise");
#endif
Timeout = *g_Timer;
while( !( TranzactionComplete = ( ( inportb( 0x08 ) & TCMASK ) == TCMASK ) ) && ( ( *g_Timer - Timeout ) < 18 ) );// {
// Timeout --;
// delay(1);
//};
#ifdef DEBUG_PRINTOUT_MSGS
if( TranzactionComplete ){
debugProcEnd();
} else {
debugProcEnd( 0 );
};
#endif
};
#ifdef DEBUG_PRINTOUT_MSGS
debugProcBegin("Small Delay");
#endif
delay(1);
#ifdef DEBUG_PRINTOUT_MSGS
debugProcEnd();
#endif
//outportb (0x0A, 4 | DMA); //Mask DMA channel
#ifdef DEBUG_PRINTOUT_MSGS
debugProcEnd();
#endif
if( TranzactionComplete ){
return validateDMASettingsChecSumm( Buffer );
};
return false;
};
bool CBoard::SaveDMASettings( int DMA, DMA_IO_BUFFER *Buffer ){
long LinearAddress;
unsigned int Page, OffSet;
#ifdef DEBUG_PRINTOUT_MSGS
debugProcBegin("Alloc DMA Buffer");
debugProcBegin("Calc Checksum");
#endif
updateDMASettingsChecSumm( Buffer );
#ifdef DEBUG_PRINTOUT_MSGS
debugProcEnd();
#endif
//Convert pointer to linear address
LinearAddress = FP_SEG ( Buffer );
LinearAddress = ( LinearAddress << 4 ) + FP_OFF( Buffer );
Page = LinearAddress >> 16; //Calculate page
OffSet = LinearAddress & 0xFFFF; //Calculate offset in the page
#ifdef DEBUG_PRINTOUT_MSGS
char temp[255];
sprintf(temp, "Programm DMA Channel %d transfer %d bytes to board", DMA, sizeof(DMA_IO_BUFFER) );
debugProcBegin(temp);
#endif
outportb (0x0A, 4 | DMA); //Mask DMA channel
outportb (0x0C, 0); //Clear byte pointer
outportb (0x0B, 0x08 | DMA); //Set mode
/*
The mode consists of the following:
0x14 + x = binary 00 00 10 xx
|| || || ||
|| || || ++- DMA channel
|| || |+--- Write operation (the DSP writes to memory)
|| || +---- Read operation (the DSP reads from memory)
|| |+------ Autoinit
|| +------- Increment - 1/Decrement - 0
|+--------- Single mode - 1 -+--- 00 - on Demand
+---------- Block mode - 1 -+
*/
outportb (DMA << 1, OffSet & 0xFF ); //Write the offset to the DMA controller
outportb (DMA << 1, OffSet >> 8 );
if (DMA == 0) outportb ( 0x87, Page );
if (DMA == 1) outportb ( 0x83, Page );
if (DMA == 3) outportb ( 0x82, Page );
outportb (( DMA << 1 ) + 1, ( sizeof(DMA_IO_BUFFER) - 1 ) & 0xFF );
outportb (( DMA << 1 ) + 1, ( ( sizeof(DMA_IO_BUFFER) - 1 ) >> 8 ) & 0xFF );
outportb (0x0A, DMA); //Unmask DMA channel
#ifdef DEBUG_PRINTOUT_MSGS
debugProcEnd();
#endif
/***** Signal to the board to load Data *****/
bool TranzactionComplete = false;
unsigned char Retry = 3;
DWORD Timeout;
static DWORD far* g_Timer = (DWORD far*)0x46CL;
uint8_t TCMASK = (0x01 << DMA );
while( ( !TranzactionComplete ) && Retry ){
#ifdef DEBUG_PRINTOUT_MSGS
debugProcBegin("Signal To Board");
#endif
SignalToBoard( DMA_SAVE_ADDRESS );
#ifdef DEBUG_PRINTOUT_MSGS
debugProcEnd();
#endif
Retry--;
Timeout = 5; // Timeout 1/200 sec
#ifdef DEBUG_PRINTOUT_MSGS
debugProcBegin("Wait till CF Flag Rise");
#endif
Timeout = *g_Timer;
while( !( TranzactionComplete = ( ( inportb( 0x08 ) & TCMASK ) == TCMASK ) ) && ( ( *g_Timer - Timeout ) < 18 ) );//{
// Timeout --;
// delay(1);
//};
#ifdef DEBUG_PRINTOUT_MSGS
if( TranzactionComplete ){
debugProcEnd();
} else {
debugProcEnd( 0 );
};
#endif
};
#ifdef DEBUG_PRINTOUT_MSGS
debugProcBegin("Small Delay");
#endif
delay(1);
#ifdef DEBUG_PRINTOUT_MSGS
debugProcEnd();
#endif
//outportb (0x0A, 4 | DMA); //Mask DMA channel
#ifdef DEBUG_PRINTOUT_MSGS
debugProcEnd();
#endif
return TranzactionComplete;
}
#endif //ALS_300_EDMA
#endif //DMA_TRANSFERS
uint32_t CBoard::getRandomSeedFromLicense( uint32_t LIC ){
uint32_t RetVal=0;
uint32_t cm;
int i,j=0;
for (i=0; i< 32; i++){
cm = 1ul << i;
if ( i%2 == 1){ // Odd values = Random Seed
if ( LIC & cm ){
RetVal |= 0x01 << j;
};
j++;
};
};
//printf("\n");
return RetVal;
};
uint32_t CBoard::getSoftwareIDFromLicense( uint32_t LIC ){
uint32_t RetVal=0;
uint32_t cm;
int i,j=0;
for (i=0; i< 32; i++){
cm=1ul << i;
if (i%2==0){ // Even values = Software ID
if ( (LIC & cm ) > 0 ){
RetVal |= 0x01 << j;
};
j++;
};
};
return RetVal;
};
uint32_t CBoard::getRandomSeedFromHiddenID( char *HID ){
uint32_t LLIC=0;
sscanf(HID,"%8lX",&LLIC);
return getRandomSeedFromLicense( LLIC );
};
uint32_t CBoard::getSoftwareIDFromHiddenID(char *HID){
uint32_t LLIC=0;
sscanf(HID,"%8lX",&LLIC);
return getSoftwareIDFromLicense( LLIC );
};
char *CBoard::assembleHiddenID( uint32_t SWID, uint32_t RND ){
unsigned char tArr[8];
int i,k;
uint32_t cm;
if( BSNS == NULL ){
BSNS = (char *) malloc(9); // Board SN Placeholder
};
k=0;
tArr[k]=0;
for ( i = 0; i<16; i++){
cm = 1 << i;
if ( i%4 == 0 && i != 0 ){
k++;
tArr[k]=0;
};
if( ( SWID & cm ) > 0 ){
tArr[k] |= 0x01 << ((i%4)*2);
} else {
tArr[k] |= 0x00 << ((i%4)*2);
};
if( ( RND & cm ) > 0 ){
tArr[k] |= 0x02 << ((i%4)*2);
} else {
tArr[k] |= 0x00 << ((i%4)*2);
};
}
for (i=0;i<4;i++){
sprintf( BSNS+(i*2),"%02X",tArr[3-i]);
};
BSNS[8]='\0';
return BSNS;
};
bool CBoard::UpdateLicensing(){
#ifndef BOARD_SIMULATION
ffblk buffer[1];
char *HID;
char *DUMMY=_T( " LIBERMANDA " );
unsigned long a,b;
unsigned long LicenseID,NRN;
FILE *fileID;
if ( findfirst("license", buffer,0)==0 ){
#ifdef DEBUG_PRINTOUT_LIC_MSGS
printf("\nUpgrading the License\n");
#endif
fileID=fopen("license","r");
if ( fileID ){
LicenseID=0;
fscanf(fileID,"%8lX",&LicenseID);
fclose(fileID);
unlink("license");
#ifdef DEBUG_PRINTOUT_LIC_MSGS
printf("License file read and deleted\nLicense ID: %lX \n\n",LicenseID );
#endif
HID=GetHiddenParam( nHID );
if ( HID!=NULL ){ //proceed License
if ( getRandomSeedFromLicense( LicenseID ) == getRandomSeedFromHiddenID( HID ) ){ // License generated for this software install
HID = assembleHiddenID( getSoftwareIDFromLicense( LicenseID ),getRandomSeedFromHiddenID( HID ));
#ifdef DEBUG_PRINTOUT_LIC_MSGS
printf("Upgrated HID: %s\n", HID );
#endif
SetHiddenParam( nHID, HID );
} else {
#ifdef DEBUG_PRINTOUT_LIC_MSGS
printf("Incorrect License Version %x %x\n", getRandomSeedFromLicense( LicenseID ), getRandomSeedFromHiddenID( HID ));
#endif
};
} else { // Must Set Random Number to HiddenID - License is Ignored;
//randomize();
srand (time (NULL));
#ifdef DEBUG_PRINTOUT_LIC_MSGS
printf("No Hidden ID present\n Generating New one: %s\n",assembleHiddenID(rand(),rand()));
#endif
SetHiddenParam( nHID , HID );
};
sprintf(DUMMY, _T("%c:\\license.txt"), 65+nHID );
fileID=fopen( DUMMY,"w" );
if ( fileID!= NULL ){
fprintf(fileID,"%s\n",assembleHiddenID( mwBoardID, mwRandomSeed ));
fclose(fileID);
};
return true;
} else {
#ifdef DEBUG_PRINTOUT_LIC_MSGS
printf("License file cannot be opened\n\n");
#endif
};
} else {
#ifdef DEBUG_PRINTOUT_LIC_MSGS
printf("No License where found\n\n");
#endif
}
#endif // BOARD_SIMULATION
return false;
};
void CBoard::SetupLicense(){
#ifndef BOARD_SIMULATION
char *HID;
HID = GetHiddenParam( nHID );
if ( HID == NULL ){ // New Software Installation - Must Generate New Random Seed
//randomize();
srand( time (NULL) );
HID=assembleHiddenID(rand(),rand());
#ifdef DEBUG_PRINTOUT_MSGS
#ifdef DEBUG_PRINTOUT_LIC_MSGS
printf("NEW RHID: %s\n",HID );
#endif
#endif
SetHiddenParam( nHID , HID );
};
mwSoftwareID = getSoftwareIDFromHiddenID(HID);
mwRandomSeed = getRandomSeedFromHiddenID(HID);
#ifdef DEBUG_PRINTOUT_MSGS
#ifdef DEBUG_PRINTOUT_LIC_MSGS
printf("Hidden ID: %s\n", HID );
printf("Random seed: %X\n", mwRandomSeed );
printf("Software ID: %X\n", mwSoftwareID );
#endif
#endif
#endif // BOARD_SIMULATION
};
char *CBoard::GetHiddenParam( unsigned char DiskID ){
#ifndef BOARD_SIMULATION
unsigned char HAttr = 0x19;
unsigned char bobo[512];
unsigned int ReservedSectors;
unsigned int BytesPerSector;
unsigned int SectorsPerFAT;
unsigned int RootDirEntries;
unsigned char FatCopies;
char cname[12];
unsigned char cattr;
unsigned int RootStart;
int i=0,j=0;
#ifdef DEBUG
printf("Get HID from [%d]\n", DiskID );
#endif
if( absread( DiskID, 1, 0, bobo ) == 0 ) {
/*
Offset in Boot Sector Length in Bytes Mnemonic
03 8 OEM_Identifier
0B 2 BytesPerSector
0D 1 SectorsPerCluster
0E 2 ReservedSectors
10 1 NumberOfFATs
11 2 RootEntries
13 2 NumberOfSectors
15 1 MediaDescriptor
16 2 SectorsPerFAT
18 2 SectorsPerHead
1A 2 HeadsPerCylinder
1C 4 HiddenSectors
20 4 BigNumberOfSectors
24 4 BigSectorsPerFAT
28 2 ExtFlags
2A 2 FSVersion
2C 4 RootDirectoryStart
30 2 FSInfoSector
32 2 BackupBootSector
34 12d Reserved
*/
BytesPerSector = ( unsigned int )*(bobo+0x0B);
ReservedSectors = ( unsigned int )*(bobo+0x0E);
FatCopies = ( unsigned char ) *(bobo+0x10);
RootDirEntries = ( unsigned int )*(bobo+0x11);
SectorsPerFAT = ( unsigned int )*(bobo+0x16);
RootStart = ReservedSectors + SectorsPerFAT * FatCopies;
if( BytesPerSector == 0 ) BytesPerSector = 512;
if( RootDirEntries == 0 ) RootDirEntries = 512;
#if defined( DEBUG_PRINTOUT_MSGS ) || defined( DEBUG_PRINTOUT_LIC_MSGS )
printf( "DI:Reserved: %06d\n", ReservedSectors );
printf( "DI:Sec.P.FT: %06d\n", SectorsPerFAT );
printf( "DI:Root Entry: %03d\n", RootDirEntries );
printf( "DI:FAT Copies: %02d\n", FatCopies );
printf( "DI:Bytes per Sector: %02d\n", BytesPerSector );
#endif
} else {
#if defined( DEBUG_PRINTOUT_MSGS ) || defined( DEBUG_PRINTOUT_LIC_MSGS )
printf( "ERROR:Disk Read Failure!\n" );
#endif
return NULL;
};
for ( i = 0; i< ( RootDirEntries*32/BytesPerSector ); i++){
if ( absread( DiskID, 1, RootStart + i, bobo ) == 0 ) {
for(j=0;j<16;j++){
if ( bobo[j*32] == 0 ) break;
sprintf(cname,"%.11s",(char *)(bobo+j*32));
cname[11]=(char)0;
cattr=bobo[j*32+0x0b];
#if defined( DEBUG_PRINTOUT_MSGS ) || defined( DEBUG_PRINTOUT_LIC_MSGS )
printf("DIR ENTRY> [ %s ] %02x\n",cname,cattr);
#endif
if ( cattr==HAttr ){
#if defined( DEBUG_PRINTOUT_MSGS ) || defined( DEBUG_PRINTOUT_LIC_MSGS )
printf("ID Found!\n");
#endif
return strdup( cname );
};
};
#if defined( DEBUG_PRINTOUT_MSGS ) || defined( DEBUG_PRINTOUT_LIC_MSGS )
} else {
printf( "ERROR2:Disk Read Failure!\n" );
#endif
};
if ( j > 0 && j < 15 ) break;
};
#if defined( DEBUG_PRINTOUT_MSGS ) || defined( DEBUG_PRINTOUT_LIC_MSGS )
printf("ID NOT Found!\n");
#endif
return NULL;
#else
#if defined( DEBUG_PRINTOUT_MSGS ) || defined( DEBUG_PRINTOUT_LIC_MSGS )
debug("Simulating LICENSE [5FDF5D77]" );
#endif
return "5FDF5D77";
#endif // BOARD_SIMULATION
};
void CBoard::SetHiddenParam( unsigned char DiskID, char *Param ){
#ifndef BOARD_SIMULATION
unsigned char HAttr = 0x19;
unsigned char bobo[512];
unsigned int ReservedSectors;
unsigned int BytesPerSector;
unsigned int SectorsPerFAT;
unsigned int RootDirEntries;
unsigned char FatCopies;
char cname[12];
char path[18];
unsigned char cattr;
unsigned int RootStart;
char Token[12];
int i=0,j=0;
if ( absread( DiskID, 1, 0, bobo ) == 0 ) {
BytesPerSector = ( unsigned int )*(bobo+0x0B);
ReservedSectors = ( unsigned int )*(bobo+0x0E);
FatCopies = ( unsigned char ) *(bobo+0x10);
RootDirEntries = ( unsigned int )*(bobo+0x11);
SectorsPerFAT = ( unsigned int )*(bobo+0x16);
RootStart = ReservedSectors + SectorsPerFAT * FatCopies;
if( BytesPerSector == 0 ) BytesPerSector = 512;
if( RootDirEntries == 0 ) RootDirEntries = 512;
#if defined( DEBUG_PRINTOUT_MSGS ) || defined( DEBUG_PRINTOUT_LIC_MSGS )
printf( " *******************\n" );
printf( " * Disk Info: *\n" );
printf( " * Reserved: %06d*\n", ReservedSectors );
printf( " * Sec.P.FT: %06d*\n", SectorsPerFAT );
printf( " * Root Entry: %03d *\n", RootDirEntries );
printf( " * FAT Copies: %02d *\n", FatCopies );
printf( " * Bytes Per Sec: %d*\n", BytesPerSector );
printf( " *******************\n" );
#endif
} else {
#if defined( DEBUG_PRINTOUT_MSGS ) || defined( DEBUG_PRINTOUT_LIC_MSGS )
printf( "Disk Read Failure\n" );
#endif
return;
};
for ( i = 0; i< ( RootDirEntries*32/BytesPerSector ); i++){
if ( absread( DiskID, 1, RootStart + i, bobo ) == 0 ) {
for(j=0;j<16;j++){
if ( bobo[j*32] == 0 ) break;
sprintf(cname,"%.11s",(char *)(bobo+j*32));
cattr=bobo[j*32+0x0b];
#if defined( DEBUG_PRINTOUT_MSGS ) || defined( DEBUG_PRINTOUT_LIC_MSGS )
printf("> %s %02x\n",cname,cattr);
#endif
if ( cattr==HAttr ) {
sprintf((char *)(bobo+j*32),"%.11s",Param);
bobo[j*32+0x0b] = HAttr;
#if defined( DEBUG_PRINTOUT_MSGS ) || defined( DEBUG_PRINTOUT_LIC_MSGS )
printf("Upgrading ... \n");
#endif
int RetVal = abswrite( DiskID, 1, RootStart + i, bobo );
#if defined( DEBUG_PRINTOUT_MSGS ) || defined( DEBUG_PRINTOUT_LIC_MSGS )
if( RetVal == 0 ){
printf( "Ok\n" );
} else {
printf( "Disk Write Failure\n" );
};
#endif
return;
};
};
} else {
#if defined( DEBUG_PRINTOUT_MSGS ) || defined( DEBUG_PRINTOUT_LIC_MSGS )
printf( "Disk Read Failure\n" );
#endif
};
if ( j > 0 && j < 15 ) break;
};
if ( strlen(Param)>8 ){
sprintf(path,"%c:\\%.8s.%.3s",(char )(DiskID+65),Param,(char *)(Param+8));
} else {
sprintf(path,"%c:\\%s",(char )(DiskID+65),Param);
};
#if defined( DEBUG_PRINTOUT_MSGS ) || defined( DEBUG_PRINTOUT_LIC_MSGS )
printf("Create New Hidden ID\n");
#endif
mkdir( path, S_IWUSR );
switch(strlen(Param)){
case 1: sprintf(Token, "%s ",Param); break;
case 2: sprintf(Token, "%s ",Param); break;
case 3: sprintf(Token, "%s ",Param); break;
case 4: sprintf(Token, "%s ",Param); break;
case 5: sprintf(Token, "%s ",Param); break;
case 6: sprintf(Token, "%s ",Param); break;
case 7: sprintf(Token, "%s ",Param); break;
case 8: sprintf(Token, "%s ",Param); break;
case 9: sprintf(Token, "%s ",Param); break;
case 10: sprintf(Token,"%s ",Param); break;
case 11: sprintf(Token,"%s",Param); break;
default: sprintf(Token,"Error Copy String: %s",Param);
};
for ( i = 0; i< ( RootDirEntries*32/512 ); i++){
if ( absread( DiskID, 1, RootStart + i, bobo ) == 0 ) {
for(j=0;j<16;j++){
if ( bobo[j*32] == 0 ) break;
sprintf( cname, "%c%c%c%c%c%c%c%c%c%c%c",
((char *)(bobo+j*32))[0],
((char *)(bobo+j*32))[1],
((char *)(bobo+j*32))[2],
((char *)(bobo+j*32))[3],
((char *)(bobo+j*32))[4],
((char *)(bobo+j*32))[5],
((char *)(bobo+j*32))[6],
((char *)(bobo+j*32))[7],
((char *)(bobo+j*32))[8],
((char *)(bobo+j*32))[9],
((char *)(bobo+j*32))[10] );
cattr=bobo[j*32+0x0b];
#if defined( DEBUG_PRINTOUT_MSGS ) || defined( DEBUG_PRINTOUT_LIC_MSGS )
printf(" >%s< %02x >%s< == >%s<\n",cname,cattr,Param,Token);
#endif
if ( strcmp( cname, Token )==0 ) {
bobo[j*32+0x0b] = HAttr;
#if defined( DEBUG_PRINTOUT_MSGS ) || defined( DEBUG_PRINTOUT_LIC_MSGS )
printf("Hidding the Marker\n");
#endif
int RetVal = abswrite( DiskID, 1, RootStart + i, bobo );
#if defined( DEBUG_PRINTOUT_MSGS ) || defined( DEBUG_PRINTOUT_LIC_MSGS )
if( RetVal == 0 ){
printf( "Ok\n" );
} else {
printf( "Disk Write Failure\n" );
};
#endif
return;
#if defined( DEBUG_PRINTOUT_MSGS ) || defined( DEBUG_PRINTOUT_LIC_MSGS )
} else {
printf("No Match\n");
#endif
};
};
#if defined( DEBUG_PRINTOUT_MSGS ) || defined( DEBUG_PRINTOUT_LIC_MSGS )
} else {
printf( "Disk Read Failure\n" );
#endif
};
if ( j > 0 && j < 15 ) break;
};
#endif // BOARD_SIMULATION
};
void CBoard::ClearHiddenParam( unsigned char DiskID ){
#ifndef BOARD_SIMULATION
unsigned char HAttr = 0x19;
unsigned char UAttr = 0x10;
unsigned char bobo[512];
unsigned int ReservedSectors;
unsigned int BytesPerSector;
unsigned int SectorsPerFAT;
unsigned int RootDirEntries;
unsigned char FatCopies;
char cname[12];
char path[18];
unsigned char cattr;
unsigned int RootStart;
char Token[12];
int i=0,j=0;
if ( absread( DiskID, 1, 0, bobo ) == 0 ) {
BytesPerSector = ( unsigned int )*(bobo+0x0B);
ReservedSectors = ( unsigned int )*(bobo+0x0E);
FatCopies = ( unsigned char ) *(bobo+0x10);
RootDirEntries = ( unsigned int )*(bobo+0x11);
SectorsPerFAT = ( unsigned int )*(bobo+0x16);
if( BytesPerSector == 0 ) BytesPerSector = 512;
if( RootDirEntries == 0 ) RootDirEntries = 512;
RootStart = ReservedSectors + SectorsPerFAT * FatCopies;
#if defined( DEBUG_PRINTOUT_MSGS ) || defined( DEBUG_PRINTOUT_LIC_MSGS )
printf( " *******************\n" );
printf( " * Disk Info: *\n" );
printf( " * Reserved: %06d*\n", ReservedSectors );
printf( " * Sec.P.FT: %06d*\n", SectorsPerFAT );
printf( " * Root Entry: %03d *\n", RootDirEntries );
printf( " * FAT Copies: %02d *\n", FatCopies );
printf( " *******************\n" );
#endif
} else {
#if defined( DEBUG_PRINTOUT_MSGS ) || defined( DEBUG_PRINTOUT_LIC_MSGS )
printf( "Disk Read Failure\n" );
#endif
return;
};
for ( i = 0; i< ( RootDirEntries*32/BytesPerSector ); i++){
if ( absread( DiskID, 1, RootStart + i, bobo ) == 0 ) {
for(j=0;j<16;j++){
if ( bobo[j*32] == 0 ) break;
sprintf(cname,"%.11s",(char *)(bobo+j*32));
cattr=bobo[j*32+0x0b];
#if defined( DEBUG_PRINTOUT_MSGS ) || defined( DEBUG_PRINTOUT_LIC_MSGS )
printf("> %s %02x\n",cname,cattr);
#endif
if ( cattr==HAttr ) {
bobo[j*32+0x0b] = UAttr;
int RetVal = abswrite( DiskID, 1, RootStart + i, bobo );
#if defined( DEBUG_PRINTOUT_MSGS ) || defined( DEBUG_PRINTOUT_LIC_MSGS )
if( RetVal == 0 ){
printf( "Ok\n" );
} else {
printf( "Disk Write Failure\n" );
};
#endif
return;
};
};
#if defined( DEBUG_PRINTOUT_MSGS ) || defined( DEBUG_PRINTOUT_LIC_MSGS )
} else {
printf( "Disk Read Failure\n" );
#endif
};
if ( j > 0 && j < 15 ) break;
};
#endif // BOARD_SIMULATION
};
char *CBoard::GetBSN( void ){ // Get Board Serial Number
return assembleHiddenID( mwBoardID, mwRandomSeed );
};
char *CBoard::GetBSW( void ){
if( BSCD == NULL ){
BSCD = ( char * ) malloc( 16 );
};
if( BSCD != NULL ){
#ifdef BOARD_SIMULATION
sprintf( BSCD, "SIMULA" );
#else
if( fw_year > 0 && fw_year < 100 ){
sprintf( BSCD ,"%02d%02d%02d", fw_year, fw_month, fw_day );
BSCD[6]='\0';
} else {
sprintf( BSCD ,"UNKNOWN" );
BSCD[7]='\0';
};
#endif
};
return BSCD;
};
char *CBoard::GetBFW( void ){
if( BFCD == NULL ){
BFCD = ( char * ) malloc( 16 );
};
if( BFCD != NULL ){
#ifdef BOARD_SIMULATION
sprintf( BFCD, "SIMULA" );
#else
if( bl_year > 0 && bl_year < 100 ){
sprintf( BFCD ,"%02d%02d%02d", bl_year, bl_month, bl_day );
BFCD[6]='\0';
} else {
sprintf( BFCD ,"UNKNOWN" );
BFCD[7]='\0';
};
#endif
};
return BFCD;
};
void CBoard::OnFWBL(){
}
#ifdef DEBUG_BOARD_PRINT_NO_IRQ
uint16_t CBoard::ReadNewBoard(){
uint8_t bData[2];
bData[0] = inportb(NEW_BASE_ADDRESS);
bData[1] = inportb(NEW_BASE_ADDRESS+1);
uint16_t& wData = (uint16_t&) bData[0];
return wData;
}
#endif
/*
void CBoard::SetTestBit( bool bOn )
{
switch( m_nBoardType )
{
case BT_NEW:
// update mask
m_bOutputMask = bOn ? (m_bOutputMask | BE_NEW_OUTPUT0) : (m_bOutputMask & ~BE_NEW_OUTPUT0);
m_bOutputDirty = true;
break;
#ifdef DEBUG_ENABLE_OLD_BOARD
case BT_OLD:
// update mask
m_bOutputMask = bOn ? (m_bOutputMask | 0x10) : (m_bOutputMask & ~0x10);
outportb( OLD_BASE_ADDRESS, m_bOutputMask );
break;
#endif
}
}
void CBoard::SetTestBit2( bool bOn )
{
switch( m_nBoardType )
{
case BT_NEW:
// update mask
m_bOutputMask = bOn ? (m_bOutputMask | BE_NEW_OUTPUT1) : (m_bOutputMask & ~BE_NEW_OUTPUT1);
m_bOutputDirty = true;
break;
}
} */
void CBoard::SetRelayBit( bool bOn ){
switch( m_eBoardType ){
case BT_VORTEX_SX:
case BT_VORTEX_DX:
case BT_VORTEX_MX:
// update mask
#ifdef RELAY_ACTIVATE_BY_ZERO
m_bOutputMask = bOn ? (m_bOutputMask & ~(BE_NEW_DC0|BE_NEW_DC1)) : (m_bOutputMask | (BE_NEW_DC0|BE_NEW_DC1));
#else
m_bOutputMask = bOn ? (m_bOutputMask | BE_NEW_DC0) : (m_bOutputMask & ~BE_NEW_DC0);
#endif
m_bOutputDirty = true;
break;
};
};
DWORD CBoard::GetTimer( void ){
#ifdef NO_WDT2_INIT
if( g_bIsDMABoard ){
DWORD TT;
mOld_TV = clock();
TT =( DWORD )( mOld_TV & 0xFFFFFFFFL );
return TT;
} else {
return m_wTimer;
};
#else
//if( g_bIsVortex ) {
// return get_sys_clock();
//} else {
//if( g_bIsDMABoard ){
DWORD TT;
mOld_TV = clock();
TT =( DWORD )( mOld_TV & 0xFFFFFFFFL );
return TT;
//} else {
// return m_wTimer;
//};
//};
#endif
}