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

3 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. //----------------------------------------------------------------------------
  2. // Laser Guard Ltd.
  3. // Copyright ?2000-2002. All Rights Reserved.
  4. // Version 1.0 01/01/2000
  5. // Last modification: 19/08/2002
  6. // PROJECT:
  7. // SUBSYSTEM:
  8. // FILE: BOARD.CPP
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of BOARD.CPP
  13. //----------------------------------------------------------------------------
  14. #include "stdafx.h"
  15. #include "board.h"
  16. #include "screen.h"
  17. //#include "..\LgLib\version.h"
  18. #include "hardware.h"
  19. bool HID_UI_Debug = false;
  20. #ifdef DEBUG_ENABLE_OLD_BOARD
  21. extern "C" void SMM( short, short[] );
  22. short CBoard::s_pDataArray[4] = {0,0,0,0};
  23. #endif
  24. //#ifdef INCLUDE_WINDOWS_DEFINITIONS
  25. // //static DWORD far* g_Timer = (DWORD far*)0x46CL;
  26. // static DWORD far* g_Timer = ((DWORD far*) 0x46CL + __djgpp_conventional_base );
  27. // static DWORD old_Timer = 0;
  28. // #define TIMER() *g_Timer
  29. //#else
  30. // #define TIMER() (GetTickCount() * 10 / 182)
  31. //#endif
  32. #ifdef DMA_TRANSFERS
  33. #ifdef ALS_300_EDMA
  34. bool validateDMASettingsChecSumm( DMA_IO_BUFFER *Buffer ){
  35. uint16_t Summ;
  36. Summ = 0;
  37. #ifdef DEBUG_PRINTOUT_MSGS
  38. debugProcBegin("Validating CheckSumm");
  39. #endif
  40. for( uint8_t index = 0; index < (sizeof(DMA_IO_BUFFER)-1); index++ ){
  41. Summ += (( uint8_t *) Buffer )[index];
  42. Summ = Summ & 0xFF;
  43. };
  44. #ifdef DEBUG_PRINTOUT_MSGS
  45. if( Buffer->CheckSumm == Summ ){
  46. debugProcEnd();
  47. return true;
  48. } else {
  49. debugProcEnd(0);
  50. return false;
  51. };
  52. #else
  53. return ( Buffer->fields.CheckSumm == Summ );
  54. #endif
  55. };
  56. void updateDMASettingsChecSumm( DMA_IO_BUFFER *Buffer ){
  57. uint16_t Summ;
  58. Summ = 0;
  59. for( uint8_t index = 0; index < (sizeof(DMA_IO_BUFFER)-1); index++ ){
  60. Summ += (( uint8_t *) Buffer )[index];
  61. Summ = Summ & 0xFF;
  62. };
  63. Buffer->fields.CheckSumm = Summ;
  64. };
  65. bool CBoard::LoadDMASettings( int DMA, DMA_IO_BUFFER *Buffer ){
  66. long LinearAddress;
  67. unsigned int Page, OffSet;
  68. //Convert pointer to linear address
  69. LinearAddress = FP_SEG ( Buffer );
  70. LinearAddress = ( LinearAddress << 4 ) + FP_OFF( Buffer );
  71. Page = LinearAddress >> 16; //Calculate page
  72. OffSet = LinearAddress & 0xFFFF; //Calculate offset in the page
  73. #ifdef DEBUG_PRINTOUT_MSGS
  74. debugProcBegin( "Programm DMA Channel %d transfer %d bytes from board", DMA, sizeof(DMA_IO_BUFFER));
  75. #endif
  76. outportb (0x0A, 4 | DMA); //Mask DMA channel
  77. outportb (0x0C, 0); //Clear byte pointer
  78. outportb (0x0B, 0x44 | DMA ); //Set mode
  79. /*
  80. The mode consists of the following:
  81. 0x14 + x = binary 01 00 01 xx
  82. || || || ||
  83. || || || ++- DMA channel
  84. || || |+--- Write operation (the DSP writes to memory)
  85. || || +---- Read operation (the DSP reads from memory)
  86. || |+------ Autoinit
  87. || +------- Increment - 1/Decrement - 0
  88. |+--------- Single mode - 1 -+--- 00 - on Demand
  89. +---------- Block mode - 1 -+
  90. */
  91. outportb (DMA << 1, OffSet & 0xFF ); //Write the offset to the DMA controller
  92. outportb (DMA << 1, OffSet >> 8 );
  93. if (DMA == 0) outportb ( 0x87, Page );
  94. if (DMA == 1) outportb ( 0x83, Page );
  95. if (DMA == 3) outportb ( 0x82, Page );
  96. outportb (( DMA << 1 ) + 1, ( sizeof(DMA_IO_BUFFER) - 1 ) & 0xFF );
  97. outportb (( DMA << 1 ) + 1, ( ( sizeof(DMA_IO_BUFFER) - 1 ) >> 8 ) & 0xFF );
  98. outportb (0x0A, DMA); //Unmask DMA channel
  99. #ifdef DEBUG_PRINTOUT_MSGS
  100. debugProcEnd();
  101. #endif
  102. bool TranzactionComplete = false;
  103. unsigned char Retry = 3;
  104. DWORD Timeout;
  105. static DWORD far* g_Timer = (DWORD far*)0x46CL;
  106. uint8_t TCMASK = ( 0x01 << DMA );
  107. while( ( TranzactionComplete == 0 ) && Retry ){
  108. #ifdef DEBUG_PRINTOUT_MSGS
  109. debugProcBegin("Signal To Board");
  110. #endif
  111. SignalToBoard( DMA_LOAD_ADDRESS );
  112. #ifdef DEBUG_PRINTOUT_MSGS
  113. debugProcEnd();
  114. #endif
  115. Retry--;
  116. Timeout = 5; // Timeout 1/200 sec.
  117. #ifdef DEBUG_PRINTOUT_MSGS
  118. debugProcBegin("Wait till CF Flag Rise");
  119. #endif
  120. Timeout = *g_Timer;
  121. while( !( TranzactionComplete = ( ( inportb( 0x08 ) & TCMASK ) == TCMASK ) ) && ( ( *g_Timer - Timeout ) < 18 ) );// {
  122. // Timeout --;
  123. // delay(1);
  124. //};
  125. #ifdef DEBUG_PRINTOUT_MSGS
  126. if( TranzactionComplete ){
  127. debugProcEnd();
  128. } else {
  129. debugProcEnd( 0 );
  130. };
  131. #endif
  132. };
  133. #ifdef DEBUG_PRINTOUT_MSGS
  134. debugProcBegin("Small Delay");
  135. #endif
  136. delay(1);
  137. #ifdef DEBUG_PRINTOUT_MSGS
  138. debugProcEnd();
  139. #endif
  140. //outportb (0x0A, 4 | DMA); //Mask DMA channel
  141. #ifdef DEBUG_PRINTOUT_MSGS
  142. debugProcEnd();
  143. #endif
  144. if( TranzactionComplete ){
  145. return validateDMASettingsChecSumm( Buffer );
  146. };
  147. return false;
  148. };
  149. bool CBoard::SaveDMASettings( int DMA, DMA_IO_BUFFER *Buffer ){
  150. long LinearAddress;
  151. unsigned int Page, OffSet;
  152. #ifdef DEBUG_PRINTOUT_MSGS
  153. debugProcBegin("Alloc DMA Buffer");
  154. debugProcBegin("Calc Checksum");
  155. #endif
  156. updateDMASettingsChecSumm( Buffer );
  157. #ifdef DEBUG_PRINTOUT_MSGS
  158. debugProcEnd();
  159. #endif
  160. //Convert pointer to linear address
  161. LinearAddress = FP_SEG ( Buffer );
  162. LinearAddress = ( LinearAddress << 4 ) + FP_OFF( Buffer );
  163. Page = LinearAddress >> 16; //Calculate page
  164. OffSet = LinearAddress & 0xFFFF; //Calculate offset in the page
  165. #ifdef DEBUG_PRINTOUT_MSGS
  166. char temp[255];
  167. sprintf(temp, "Programm DMA Channel %d transfer %d bytes to board", DMA, sizeof(DMA_IO_BUFFER) );
  168. debugProcBegin(temp);
  169. #endif
  170. outportb (0x0A, 4 | DMA); //Mask DMA channel
  171. outportb (0x0C, 0); //Clear byte pointer
  172. outportb (0x0B, 0x08 | DMA); //Set mode
  173. /*
  174. The mode consists of the following:
  175. 0x14 + x = binary 00 00 10 xx
  176. || || || ||
  177. || || || ++- DMA channel
  178. || || |+--- Write operation (the DSP writes to memory)
  179. || || +---- Read operation (the DSP reads from memory)
  180. || |+------ Autoinit
  181. || +------- Increment - 1/Decrement - 0
  182. |+--------- Single mode - 1 -+--- 00 - on Demand
  183. +---------- Block mode - 1 -+
  184. */
  185. outportb (DMA << 1, OffSet & 0xFF ); //Write the offset to the DMA controller
  186. outportb (DMA << 1, OffSet >> 8 );
  187. if (DMA == 0) outportb ( 0x87, Page );
  188. if (DMA == 1) outportb ( 0x83, Page );
  189. if (DMA == 3) outportb ( 0x82, Page );
  190. outportb (( DMA << 1 ) + 1, ( sizeof(DMA_IO_BUFFER) - 1 ) & 0xFF );
  191. outportb (( DMA << 1 ) + 1, ( ( sizeof(DMA_IO_BUFFER) - 1 ) >> 8 ) & 0xFF );
  192. outportb (0x0A, DMA); //Unmask DMA channel
  193. #ifdef DEBUG_PRINTOUT_MSGS
  194. debugProcEnd();
  195. #endif
  196. /***** Signal to the board to load Data *****/
  197. bool TranzactionComplete = false;
  198. unsigned char Retry = 3;
  199. DWORD Timeout;
  200. static DWORD far* g_Timer = (DWORD far*)0x46CL;
  201. uint8_t TCMASK = (0x01 << DMA );
  202. while( ( !TranzactionComplete ) && Retry ){
  203. #ifdef DEBUG_PRINTOUT_MSGS
  204. debugProcBegin("Signal To Board");
  205. #endif
  206. SignalToBoard( DMA_SAVE_ADDRESS );
  207. #ifdef DEBUG_PRINTOUT_MSGS
  208. debugProcEnd();
  209. #endif
  210. Retry--;
  211. Timeout = 5; // Timeout 1/200 sec
  212. #ifdef DEBUG_PRINTOUT_MSGS
  213. debugProcBegin("Wait till CF Flag Rise");
  214. #endif
  215. Timeout = *g_Timer;
  216. while( !( TranzactionComplete = ( ( inportb( 0x08 ) & TCMASK ) == TCMASK ) ) && ( ( *g_Timer - Timeout ) < 18 ) );//{
  217. // Timeout --;
  218. // delay(1);
  219. //};
  220. #ifdef DEBUG_PRINTOUT_MSGS
  221. if( TranzactionComplete ){
  222. debugProcEnd();
  223. } else {
  224. debugProcEnd( 0 );
  225. };
  226. #endif
  227. };
  228. #ifdef DEBUG_PRINTOUT_MSGS
  229. debugProcBegin("Small Delay");
  230. #endif
  231. delay(1);
  232. #ifdef DEBUG_PRINTOUT_MSGS
  233. debugProcEnd();
  234. #endif
  235. //outportb (0x0A, 4 | DMA); //Mask DMA channel
  236. #ifdef DEBUG_PRINTOUT_MSGS
  237. debugProcEnd();
  238. #endif
  239. return TranzactionComplete;
  240. }
  241. #endif //ALS_300_EDMA
  242. #endif //DMA_TRANSFERS
  243. uint32_t CBoard::getRandomSeedFromLicense( uint32_t LIC ){
  244. uint32_t RetVal=0;
  245. uint32_t cm;
  246. int i,j=0;
  247. for (i=0; i< 32; i++){
  248. cm = 1ul << i;
  249. if ( i%2 == 1){ // Odd values = Random Seed
  250. if ( LIC & cm ){
  251. RetVal |= 0x01 << j;
  252. };
  253. j++;
  254. };
  255. };
  256. //printf("\n");
  257. return RetVal;
  258. };
  259. uint32_t CBoard::getSoftwareIDFromLicense( uint32_t LIC ){
  260. uint32_t RetVal=0;
  261. uint32_t cm;
  262. int i,j=0;
  263. for (i=0; i< 32; i++){
  264. cm=1ul << i;
  265. if (i%2==0){ // Even values = Software ID
  266. if ( (LIC & cm ) > 0 ){
  267. RetVal |= 0x01 << j;
  268. };
  269. j++;
  270. };
  271. };
  272. return RetVal;
  273. };
  274. uint32_t CBoard::getRandomSeedFromHiddenID( char *HID ){
  275. uint32_t LLIC=0;
  276. sscanf(HID,"%8lX",&LLIC);
  277. return getRandomSeedFromLicense( LLIC );
  278. };
  279. uint32_t CBoard::getSoftwareIDFromHiddenID(char *HID){
  280. uint32_t LLIC=0;
  281. sscanf(HID,"%8lX",&LLIC);
  282. return getSoftwareIDFromLicense( LLIC );
  283. };
  284. char *CBoard::assembleHiddenID( uint32_t SWID, uint32_t RND ){
  285. unsigned char tArr[8];
  286. int i,k;
  287. uint32_t cm;
  288. if( BSNS == NULL ){
  289. BSNS = (char *) malloc(9); // Board SN Placeholder
  290. };
  291. k=0;
  292. tArr[k]=0;
  293. for ( i = 0; i<16; i++){
  294. cm = 1 << i;
  295. if ( i%4 == 0 && i != 0 ){
  296. k++;
  297. tArr[k]=0;
  298. };
  299. if( ( SWID & cm ) > 0 ){
  300. tArr[k] |= 0x01 << ((i%4)*2);
  301. } else {
  302. tArr[k] |= 0x00 << ((i%4)*2);
  303. };
  304. if( ( RND & cm ) > 0 ){
  305. tArr[k] |= 0x02 << ((i%4)*2);
  306. } else {
  307. tArr[k] |= 0x00 << ((i%4)*2);
  308. };
  309. }
  310. for (i=0;i<4;i++){
  311. sprintf( BSNS+(i*2),"%02X",tArr[3-i]);
  312. };
  313. BSNS[8]='\0';
  314. return BSNS;
  315. };
  316. bool CBoard::UpdateLicensing(){
  317. #ifndef BOARD_SIMULATION
  318. ffblk buffer[1];
  319. char *HID;
  320. char *DUMMY=_T( " LIBERMANDA " );
  321. unsigned long a,b;
  322. unsigned long LicenseID,NRN;
  323. FILE *fileID;
  324. if ( findfirst("license", buffer,0)==0 ){
  325. #ifdef DEBUG_PRINTOUT_LIC_MSGS
  326. printf("\nUpgrading the License\n");
  327. #endif
  328. fileID=fopen("license","r");
  329. if ( fileID ){
  330. LicenseID=0;
  331. fscanf(fileID,"%8lX",&LicenseID);
  332. fclose(fileID);
  333. unlink("license");
  334. #ifdef DEBUG_PRINTOUT_LIC_MSGS
  335. printf("License file read and deleted\nLicense ID: %lX \n\n",LicenseID );
  336. #endif
  337. HID=GetHiddenParam( nHID );
  338. if ( HID!=NULL ){ //proceed License
  339. if ( getRandomSeedFromLicense( LicenseID ) == getRandomSeedFromHiddenID( HID ) ){ // License generated for this software install
  340. HID = assembleHiddenID( getSoftwareIDFromLicense( LicenseID ),getRandomSeedFromHiddenID( HID ));
  341. #ifdef DEBUG_PRINTOUT_LIC_MSGS
  342. printf("Upgrated HID: %s\n", HID );
  343. #endif
  344. SetHiddenParam( nHID, HID );
  345. } else {
  346. #ifdef DEBUG_PRINTOUT_LIC_MSGS
  347. printf("Incorrect License Version %x %x\n", getRandomSeedFromLicense( LicenseID ), getRandomSeedFromHiddenID( HID ));
  348. #endif
  349. };
  350. } else { // Must Set Random Number to HiddenID - License is Ignored;
  351. //randomize();
  352. srand (time (NULL));
  353. #ifdef DEBUG_PRINTOUT_LIC_MSGS
  354. printf("No Hidden ID present\n Generating New one: %s\n",assembleHiddenID(rand(),rand()));
  355. #endif
  356. SetHiddenParam( nHID , HID );
  357. };
  358. sprintf(DUMMY, _T("%c:\\license.txt"), 65+nHID );
  359. fileID=fopen( DUMMY,"w" );
  360. if ( fileID!= NULL ){
  361. fprintf(fileID,"%s\n",assembleHiddenID( mwBoardID, mwRandomSeed ));
  362. fclose(fileID);
  363. };
  364. return true;
  365. } else {
  366. #ifdef DEBUG_PRINTOUT_LIC_MSGS
  367. printf("License file cannot be opened\n\n");
  368. #endif
  369. };
  370. } else {
  371. #ifdef DEBUG_PRINTOUT_LIC_MSGS
  372. printf("No License where found\n\n");
  373. #endif
  374. }
  375. #endif // BOARD_SIMULATION
  376. return false;
  377. };
  378. void CBoard::SetupLicense(){
  379. #ifndef BOARD_SIMULATION
  380. char *HID;
  381. HID = GetHiddenParam( nHID );
  382. if ( HID == NULL ){ // New Software Installation - Must Generate New Random Seed
  383. //randomize();
  384. srand( time (NULL) );
  385. HID=assembleHiddenID(rand(),rand());
  386. #ifdef DEBUG_PRINTOUT_MSGS
  387. #ifdef DEBUG_PRINTOUT_LIC_MSGS
  388. printf("NEW RHID: %s\n",HID );
  389. #endif
  390. #endif
  391. SetHiddenParam( nHID , HID );
  392. };
  393. mwSoftwareID = getSoftwareIDFromHiddenID(HID);
  394. mwRandomSeed = getRandomSeedFromHiddenID(HID);
  395. #ifdef DEBUG_PRINTOUT_MSGS
  396. #ifdef DEBUG_PRINTOUT_LIC_MSGS
  397. printf("Hidden ID: %s\n", HID );
  398. printf("Random seed: %X\n", mwRandomSeed );
  399. printf("Software ID: %X\n", mwSoftwareID );
  400. #endif
  401. #endif
  402. #endif // BOARD_SIMULATION
  403. };
  404. char *CBoard::GetHiddenParam( unsigned char DiskID ){
  405. #ifndef BOARD_SIMULATION
  406. unsigned char HAttr = 0x19;
  407. unsigned char bobo[512];
  408. unsigned int ReservedSectors;
  409. unsigned int BytesPerSector;
  410. unsigned int SectorsPerFAT;
  411. unsigned int RootDirEntries;
  412. unsigned char FatCopies;
  413. char cname[12];
  414. unsigned char cattr;
  415. unsigned int RootStart;
  416. int i=0,j=0;
  417. #ifdef DEBUG
  418. printf("Get HID from [%d]\n", DiskID );
  419. #endif
  420. if( absread( DiskID, 1, 0, bobo ) == 0 ) {
  421. /*
  422. Offset in Boot Sector Length in Bytes Mnemonic
  423. 03 8 OEM_Identifier
  424. 0B 2 BytesPerSector
  425. 0D 1 SectorsPerCluster
  426. 0E 2 ReservedSectors
  427. 10 1 NumberOfFATs
  428. 11 2 RootEntries
  429. 13 2 NumberOfSectors
  430. 15 1 MediaDescriptor
  431. 16 2 SectorsPerFAT
  432. 18 2 SectorsPerHead
  433. 1A 2 HeadsPerCylinder
  434. 1C 4 HiddenSectors
  435. 20 4 BigNumberOfSectors
  436. 24 4 BigSectorsPerFAT
  437. 28 2 ExtFlags
  438. 2A 2 FSVersion
  439. 2C 4 RootDirectoryStart
  440. 30 2 FSInfoSector
  441. 32 2 BackupBootSector
  442. 34 12d Reserved
  443. */
  444. BytesPerSector = ( unsigned int )*(bobo+0x0B);
  445. ReservedSectors = ( unsigned int )*(bobo+0x0E);
  446. FatCopies = ( unsigned char ) *(bobo+0x10);
  447. RootDirEntries = ( unsigned int )*(bobo+0x11);
  448. SectorsPerFAT = ( unsigned int )*(bobo+0x16);
  449. RootStart = ReservedSectors + SectorsPerFAT * FatCopies;
  450. if( BytesPerSector == 0 ) BytesPerSector = 512;
  451. if( RootDirEntries == 0 ) RootDirEntries = 512;
  452. #if defined( DEBUG_PRINTOUT_MSGS ) || defined( DEBUG_PRINTOUT_LIC_MSGS )
  453. printf( "DI:Reserved: %06d\n", ReservedSectors );
  454. printf( "DI:Sec.P.FT: %06d\n", SectorsPerFAT );
  455. printf( "DI:Root Entry: %03d\n", RootDirEntries );
  456. printf( "DI:FAT Copies: %02d\n", FatCopies );
  457. printf( "DI:Bytes per Sector: %02d\n", BytesPerSector );
  458. #endif
  459. } else {
  460. #if defined( DEBUG_PRINTOUT_MSGS ) || defined( DEBUG_PRINTOUT_LIC_MSGS )
  461. printf( "ERROR:Disk Read Failure!\n" );
  462. #endif
  463. return NULL;
  464. };
  465. for ( i = 0; i< ( RootDirEntries*32/BytesPerSector ); i++){
  466. if ( absread( DiskID, 1, RootStart + i, bobo ) == 0 ) {
  467. for(j=0;j<16;j++){
  468. if ( bobo[j*32] == 0 ) break;
  469. sprintf(cname,"%.11s",(char *)(bobo+j*32));
  470. cname[11]=(char)0;
  471. cattr=bobo[j*32+0x0b];
  472. #if defined( DEBUG_PRINTOUT_MSGS ) || defined( DEBUG_PRINTOUT_LIC_MSGS )
  473. printf("DIR ENTRY> [ %s ] %02x\n",cname,cattr);
  474. #endif
  475. if ( cattr==HAttr ){
  476. #if defined( DEBUG_PRINTOUT_MSGS ) || defined( DEBUG_PRINTOUT_LIC_MSGS )
  477. printf("ID Found!\n");
  478. #endif
  479. return strdup( cname );
  480. };
  481. };
  482. #if defined( DEBUG_PRINTOUT_MSGS ) || defined( DEBUG_PRINTOUT_LIC_MSGS )
  483. } else {
  484. printf( "ERROR2:Disk Read Failure!\n" );
  485. #endif
  486. };
  487. if ( j > 0 && j < 15 ) break;
  488. };
  489. #if defined( DEBUG_PRINTOUT_MSGS ) || defined( DEBUG_PRINTOUT_LIC_MSGS )
  490. printf("ID NOT Found!\n");
  491. #endif
  492. return NULL;
  493. #else
  494. #if defined( DEBUG_PRINTOUT_MSGS ) || defined( DEBUG_PRINTOUT_LIC_MSGS )
  495. debug("Simulating LICENSE [5FDF5D77]" );
  496. #endif
  497. return "5FDF5D77";
  498. #endif // BOARD_SIMULATION
  499. };
  500. void CBoard::SetHiddenParam( unsigned char DiskID, char *Param ){
  501. #ifndef BOARD_SIMULATION
  502. unsigned char HAttr = 0x19;
  503. unsigned char bobo[512];
  504. unsigned int ReservedSectors;
  505. unsigned int BytesPerSector;
  506. unsigned int SectorsPerFAT;
  507. unsigned int RootDirEntries;
  508. unsigned char FatCopies;
  509. char cname[12];
  510. char path[18];
  511. unsigned char cattr;
  512. unsigned int RootStart;
  513. char Token[12];
  514. int i=0,j=0;
  515. if ( absread( DiskID, 1, 0, bobo ) == 0 ) {
  516. BytesPerSector = ( unsigned int )*(bobo+0x0B);
  517. ReservedSectors = ( unsigned int )*(bobo+0x0E);
  518. FatCopies = ( unsigned char ) *(bobo+0x10);
  519. RootDirEntries = ( unsigned int )*(bobo+0x11);
  520. SectorsPerFAT = ( unsigned int )*(bobo+0x16);
  521. RootStart = ReservedSectors + SectorsPerFAT * FatCopies;
  522. if( BytesPerSector == 0 ) BytesPerSector = 512;
  523. if( RootDirEntries == 0 ) RootDirEntries = 512;
  524. #if defined( DEBUG_PRINTOUT_MSGS ) || defined( DEBUG_PRINTOUT_LIC_MSGS )
  525. printf( " *******************\n" );
  526. printf( " * Disk Info: *\n" );
  527. printf( " * Reserved: %06d*\n", ReservedSectors );
  528. printf( " * Sec.P.FT: %06d*\n", SectorsPerFAT );
  529. printf( " * Root Entry: %03d *\n", RootDirEntries );
  530. printf( " * FAT Copies: %02d *\n", FatCopies );
  531. printf( " * Bytes Per Sec: %d*\n", BytesPerSector );
  532. printf( " *******************\n" );
  533. #endif
  534. } else {
  535. #if defined( DEBUG_PRINTOUT_MSGS ) || defined( DEBUG_PRINTOUT_LIC_MSGS )
  536. printf( "Disk Read Failure\n" );
  537. #endif
  538. return;
  539. };
  540. for ( i = 0; i< ( RootDirEntries*32/BytesPerSector ); i++){
  541. if ( absread( DiskID, 1, RootStart + i, bobo ) == 0 ) {
  542. for(j=0;j<16;j++){
  543. if ( bobo[j*32] == 0 ) break;
  544. sprintf(cname,"%.11s",(char *)(bobo+j*32));
  545. cattr=bobo[j*32+0x0b];
  546. #if defined( DEBUG_PRINTOUT_MSGS ) || defined( DEBUG_PRINTOUT_LIC_MSGS )
  547. printf("> %s %02x\n",cname,cattr);
  548. #endif
  549. if ( cattr==HAttr ) {
  550. sprintf((char *)(bobo+j*32),"%.11s",Param);
  551. bobo[j*32+0x0b] = HAttr;
  552. #if defined( DEBUG_PRINTOUT_MSGS ) || defined( DEBUG_PRINTOUT_LIC_MSGS )
  553. printf("Upgrading ... \n");
  554. #endif
  555. int RetVal = abswrite( DiskID, 1, RootStart + i, bobo );
  556. #if defined( DEBUG_PRINTOUT_MSGS ) || defined( DEBUG_PRINTOUT_LIC_MSGS )
  557. if( RetVal == 0 ){
  558. printf( "Ok\n" );
  559. } else {
  560. printf( "Disk Write Failure\n" );
  561. };
  562. #endif
  563. return;
  564. };
  565. };
  566. } else {
  567. #if defined( DEBUG_PRINTOUT_MSGS ) || defined( DEBUG_PRINTOUT_LIC_MSGS )
  568. printf( "Disk Read Failure\n" );
  569. #endif
  570. };
  571. if ( j > 0 && j < 15 ) break;
  572. };
  573. if ( strlen(Param)>8 ){
  574. sprintf(path,"%c:\\%.8s.%.3s",(char )(DiskID+65),Param,(char *)(Param+8));
  575. } else {
  576. sprintf(path,"%c:\\%s",(char )(DiskID+65),Param);
  577. };
  578. #if defined( DEBUG_PRINTOUT_MSGS ) || defined( DEBUG_PRINTOUT_LIC_MSGS )
  579. printf("Create New Hidden ID\n");
  580. #endif
  581. mkdir( path, S_IWUSR );
  582. switch(strlen(Param)){
  583. case 1: sprintf(Token, "%s ",Param); break;
  584. case 2: sprintf(Token, "%s ",Param); break;
  585. case 3: sprintf(Token, "%s ",Param); break;
  586. case 4: sprintf(Token, "%s ",Param); break;
  587. case 5: sprintf(Token, "%s ",Param); break;
  588. case 6: sprintf(Token, "%s ",Param); break;
  589. case 7: sprintf(Token, "%s ",Param); break;
  590. case 8: sprintf(Token, "%s ",Param); break;
  591. case 9: sprintf(Token, "%s ",Param); break;
  592. case 10: sprintf(Token,"%s ",Param); break;
  593. case 11: sprintf(Token,"%s",Param); break;
  594. default: sprintf(Token,"Error Copy String: %s",Param);
  595. };
  596. for ( i = 0; i< ( RootDirEntries*32/512 ); i++){
  597. if ( absread( DiskID, 1, RootStart + i, bobo ) == 0 ) {
  598. for(j=0;j<16;j++){
  599. if ( bobo[j*32] == 0 ) break;
  600. sprintf( cname, "%c%c%c%c%c%c%c%c%c%c%c",
  601. ((char *)(bobo+j*32))[0],
  602. ((char *)(bobo+j*32))[1],
  603. ((char *)(bobo+j*32))[2],
  604. ((char *)(bobo+j*32))[3],
  605. ((char *)(bobo+j*32))[4],
  606. ((char *)(bobo+j*32))[5],
  607. ((char *)(bobo+j*32))[6],
  608. ((char *)(bobo+j*32))[7],
  609. ((char *)(bobo+j*32))[8],
  610. ((char *)(bobo+j*32))[9],
  611. ((char *)(bobo+j*32))[10] );
  612. cattr=bobo[j*32+0x0b];
  613. #if defined( DEBUG_PRINTOUT_MSGS ) || defined( DEBUG_PRINTOUT_LIC_MSGS )
  614. printf(" >%s< %02x >%s< == >%s<\n",cname,cattr,Param,Token);
  615. #endif
  616. if ( strcmp( cname, Token )==0 ) {
  617. bobo[j*32+0x0b] = HAttr;
  618. #if defined( DEBUG_PRINTOUT_MSGS ) || defined( DEBUG_PRINTOUT_LIC_MSGS )
  619. printf("Hidding the Marker\n");
  620. #endif
  621. int RetVal = abswrite( DiskID, 1, RootStart + i, bobo );
  622. #if defined( DEBUG_PRINTOUT_MSGS ) || defined( DEBUG_PRINTOUT_LIC_MSGS )
  623. if( RetVal == 0 ){
  624. printf( "Ok\n" );
  625. } else {
  626. printf( "Disk Write Failure\n" );
  627. };
  628. #endif
  629. return;
  630. #if defined( DEBUG_PRINTOUT_MSGS ) || defined( DEBUG_PRINTOUT_LIC_MSGS )
  631. } else {
  632. printf("No Match\n");
  633. #endif
  634. };
  635. };
  636. #if defined( DEBUG_PRINTOUT_MSGS ) || defined( DEBUG_PRINTOUT_LIC_MSGS )
  637. } else {
  638. printf( "Disk Read Failure\n" );
  639. #endif
  640. };
  641. if ( j > 0 && j < 15 ) break;
  642. };
  643. #endif // BOARD_SIMULATION
  644. };
  645. void CBoard::ClearHiddenParam( unsigned char DiskID ){
  646. #ifndef BOARD_SIMULATION
  647. unsigned char HAttr = 0x19;
  648. unsigned char UAttr = 0x10;
  649. unsigned char bobo[512];
  650. unsigned int ReservedSectors;
  651. unsigned int BytesPerSector;
  652. unsigned int SectorsPerFAT;
  653. unsigned int RootDirEntries;
  654. unsigned char FatCopies;
  655. char cname[12];
  656. char path[18];
  657. unsigned char cattr;
  658. unsigned int RootStart;
  659. char Token[12];
  660. int i=0,j=0;
  661. if ( absread( DiskID, 1, 0, bobo ) == 0 ) {
  662. BytesPerSector = ( unsigned int )*(bobo+0x0B);
  663. ReservedSectors = ( unsigned int )*(bobo+0x0E);
  664. FatCopies = ( unsigned char ) *(bobo+0x10);
  665. RootDirEntries = ( unsigned int )*(bobo+0x11);
  666. SectorsPerFAT = ( unsigned int )*(bobo+0x16);
  667. if( BytesPerSector == 0 ) BytesPerSector = 512;
  668. if( RootDirEntries == 0 ) RootDirEntries = 512;
  669. RootStart = ReservedSectors + SectorsPerFAT * FatCopies;
  670. #if defined( DEBUG_PRINTOUT_MSGS ) || defined( DEBUG_PRINTOUT_LIC_MSGS )
  671. printf( " *******************\n" );
  672. printf( " * Disk Info: *\n" );
  673. printf( " * Reserved: %06d*\n", ReservedSectors );
  674. printf( " * Sec.P.FT: %06d*\n", SectorsPerFAT );
  675. printf( " * Root Entry: %03d *\n", RootDirEntries );
  676. printf( " * FAT Copies: %02d *\n", FatCopies );
  677. printf( " *******************\n" );
  678. #endif
  679. } else {
  680. #if defined( DEBUG_PRINTOUT_MSGS ) || defined( DEBUG_PRINTOUT_LIC_MSGS )
  681. printf( "Disk Read Failure\n" );
  682. #endif
  683. return;
  684. };
  685. for ( i = 0; i< ( RootDirEntries*32/BytesPerSector ); i++){
  686. if ( absread( DiskID, 1, RootStart + i, bobo ) == 0 ) {
  687. for(j=0;j<16;j++){
  688. if ( bobo[j*32] == 0 ) break;
  689. sprintf(cname,"%.11s",(char *)(bobo+j*32));
  690. cattr=bobo[j*32+0x0b];
  691. #if defined( DEBUG_PRINTOUT_MSGS ) || defined( DEBUG_PRINTOUT_LIC_MSGS )
  692. printf("> %s %02x\n",cname,cattr);
  693. #endif
  694. if ( cattr==HAttr ) {
  695. bobo[j*32+0x0b] = UAttr;
  696. int RetVal = abswrite( DiskID, 1, RootStart + i, bobo );
  697. #if defined( DEBUG_PRINTOUT_MSGS ) || defined( DEBUG_PRINTOUT_LIC_MSGS )
  698. if( RetVal == 0 ){
  699. printf( "Ok\n" );
  700. } else {
  701. printf( "Disk Write Failure\n" );
  702. };
  703. #endif
  704. return;
  705. };
  706. };
  707. #if defined( DEBUG_PRINTOUT_MSGS ) || defined( DEBUG_PRINTOUT_LIC_MSGS )
  708. } else {
  709. printf( "Disk Read Failure\n" );
  710. #endif
  711. };
  712. if ( j > 0 && j < 15 ) break;
  713. };
  714. #endif // BOARD_SIMULATION
  715. };
  716. char *CBoard::GetBSN( void ){ // Get Board Serial Number
  717. return assembleHiddenID( mwBoardID, mwRandomSeed );
  718. };
  719. char *CBoard::GetBSW( void ){
  720. if( BSCD == NULL ){
  721. BSCD = ( char * ) malloc( 16 );
  722. };
  723. if( BSCD != NULL ){
  724. #ifdef BOARD_SIMULATION
  725. sprintf( BSCD, "SIMULA" );
  726. #else
  727. if( fw_year > 0 && fw_year < 100 ){
  728. sprintf( BSCD ,"%02d%02d%02d", fw_year, fw_month, fw_day );
  729. BSCD[6]='\0';
  730. } else {
  731. sprintf( BSCD ,"UNKNOWN" );
  732. BSCD[7]='\0';
  733. };
  734. #endif
  735. };
  736. return BSCD;
  737. };
  738. char *CBoard::GetBFW( void ){
  739. if( BFCD == NULL ){
  740. BFCD = ( char * ) malloc( 16 );
  741. };
  742. if( BFCD != NULL ){
  743. #ifdef BOARD_SIMULATION
  744. sprintf( BFCD, "SIMULA" );
  745. #else
  746. if( bl_year > 0 && bl_year < 100 ){
  747. sprintf( BFCD ,"%02d%02d%02d", bl_year, bl_month, bl_day );
  748. BFCD[6]='\0';
  749. } else {
  750. sprintf( BFCD ,"UNKNOWN" );
  751. BFCD[7]='\0';
  752. };
  753. #endif
  754. };
  755. return BFCD;
  756. };
  757. void CBoard::OnFWBL(){
  758. }
  759. #ifdef DEBUG_BOARD_PRINT_NO_IRQ
  760. uint16_t CBoard::ReadNewBoard(){
  761. uint8_t bData[2];
  762. bData[0] = inportb(NEW_BASE_ADDRESS);
  763. bData[1] = inportb(NEW_BASE_ADDRESS+1);
  764. uint16_t& wData = (uint16_t&) bData[0];
  765. return wData;
  766. }
  767. #endif
  768. /*
  769. void CBoard::SetTestBit( bool bOn )
  770. {
  771. switch( m_nBoardType )
  772. {
  773. case BT_NEW:
  774. // update mask
  775. m_bOutputMask = bOn ? (m_bOutputMask | BE_NEW_OUTPUT0) : (m_bOutputMask & ~BE_NEW_OUTPUT0);
  776. m_bOutputDirty = true;
  777. break;
  778. #ifdef DEBUG_ENABLE_OLD_BOARD
  779. case BT_OLD:
  780. // update mask
  781. m_bOutputMask = bOn ? (m_bOutputMask | 0x10) : (m_bOutputMask & ~0x10);
  782. outportb( OLD_BASE_ADDRESS, m_bOutputMask );
  783. break;
  784. #endif
  785. }
  786. }
  787. void CBoard::SetTestBit2( bool bOn )
  788. {
  789. switch( m_nBoardType )
  790. {
  791. case BT_NEW:
  792. // update mask
  793. m_bOutputMask = bOn ? (m_bOutputMask | BE_NEW_OUTPUT1) : (m_bOutputMask & ~BE_NEW_OUTPUT1);
  794. m_bOutputDirty = true;
  795. break;
  796. }
  797. } */
  798. void CBoard::SetRelayBit( bool bOn ){
  799. switch( m_eBoardType ){
  800. case BT_VORTEX_SX:
  801. case BT_VORTEX_DX:
  802. case BT_VORTEX_MX:
  803. // update mask
  804. #ifdef RELAY_ACTIVATE_BY_ZERO
  805. m_bOutputMask = bOn ? (m_bOutputMask & ~(BE_NEW_DC0|BE_NEW_DC1)) : (m_bOutputMask | (BE_NEW_DC0|BE_NEW_DC1));
  806. #else
  807. m_bOutputMask = bOn ? (m_bOutputMask | BE_NEW_DC0) : (m_bOutputMask & ~BE_NEW_DC0);
  808. #endif
  809. m_bOutputDirty = true;
  810. break;
  811. };
  812. };
  813. DWORD CBoard::GetTimer( void ){
  814. #ifdef NO_WDT2_INIT
  815. if( g_bIsDMABoard ){
  816. DWORD TT;
  817. mOld_TV = clock();
  818. TT =( DWORD )( mOld_TV & 0xFFFFFFFFL );
  819. return TT;
  820. } else {
  821. return m_wTimer;
  822. };
  823. #else
  824. //if( g_bIsVortex ) {
  825. // return get_sys_clock();
  826. //} else {
  827. //if( g_bIsDMABoard ){
  828. DWORD TT;
  829. mOld_TV = clock();
  830. TT =( DWORD )( mOld_TV & 0xFFFFFFFFL );
  831. return TT;
  832. //} else {
  833. // return m_wTimer;
  834. //};
  835. //};
  836. #endif
  837. }