static public void WriteTextBlock( TBlock myBlock )
    { 
      StreamWriter logger = new StreamWriter( fileName, true );
      logger.AutoFlush = true;
      logger.WriteLine( "<<==== NEW BLOCK =====>>" );
      switch ( myBlock.contentType )
      {
        case EContentType.Data:
          logger.WriteLine( "Block type: (0x5D) DATA" );
          break;
        case EContentType.Code:
          logger.WriteLine( "Block type: (0x54) CODE" );
          break;
      }
      logger.WriteLine( "const01: {0:X2}", myBlock.const01 );
      logger.WriteLine( "Content type : {0:X2}", ( byte ) myBlock.blockType );
      logger.WriteLine( "Block size : {0} ({0:x2})", myBlock.blockSize );
      logger.WriteLine( "\t===>BlockHeader =====>" );
      switch( myBlock.contentType)
      {
        case EContentType.Data:
          TDataBlock myData = myBlock.blockHeader as TDataBlock;
          logger.WriteLine( "\t===>DataBlock ====>" );
          logger.WriteLine( "\tHash : " + myData.hash.ToHex()  );
          logger.WriteLine( "\tComputed Hash : " + Utils.ComputeMD5Hash( myBlock.content ).ToHex() );
          logger.WriteLine( "\tHashCRC : " + myData.hashCRC.ToHex() );
          logger.WriteLine( "\tDescription : " + myData.description );
          logger.WriteLine( "\tProcessor type : {0:X2}", myData.processorType );
          logger.WriteLine( "\tUnknown : " + myData.unkn.ToHex() );
          logger.WriteLine( "\tLocation : {0} ({0:X8})", myData.location );
          logger.WriteLine( "\t<===DataBlock <====" );
          break;
        case EContentType.Code:
          TCodeBlock myCode = myBlock.blockHeader as TCodeBlock;
          logger.WriteLine( "\t===>CodeBlock ====>" );
          logger.WriteLine( "\tProcessor type {0:X2}", myCode.processorType );
          logger.WriteLine( "\tUnknown : {0:X4}", myCode.unkn );
          logger.WriteLine( "\tCRC? : {0:X4}", myCode.maybe_crc );
          logger.WriteLine( "\tconst01 : {0:X2}", myCode.const01 );
          logger.WriteLine( "\tContent size : {0} ({0:X16})", myCode.contentSize );
          logger.WriteLine( "\tLocation : {0} ({0:X16})", myCode.location );
          logger.WriteLine( "\t<===CodeBlock <====" );
          break;
      }
      logger.WriteLine( "Block checksum : {0:X2}", myBlock.blockChecksum8 );
      logger.WriteLine( "Computed checksum : {0:X2}", Utils.ComputeBlockChecksum(myBlock.const01,myBlock.blockType,myBlock.blockHeaderSize,myBlock.content ));
      if ( myBlock.contentType == EContentType.Data )
      {
        logger.WriteLine( "========= CONTENT ==========" );
        logger.WriteLine( myBlock.content.ToHex() );
        logger.WriteLine( "========= END CONTENT ==========" );
      }

      logger.Close();
    }
    public void Test(string fname)
    {
      if (Directory.Exists(outputDir))
        Directory.Delete(outputDir, true);
      Directory.CreateDirectory(outputDir);

      BinaryReader br = new BinaryReader(new FileStream(fname, FileMode.Open));
      header.Read(br);
      Int16 i = 0;

      File.WriteAllBytes(outputDir + "\\header.bin", header.unkn);
      while (br.BaseStream.Position < br.BaseStream.Length)
      {
        UInt32 blockOffset = (UInt32)br.BaseStream.Position;
        TBlock block = new TBlock();
        block.Read(br);
        blocks.Add(block);

        Console.Write(" " + block.contentType + " At:" + Utils.ToHex(blockOffset) + " size:" + Utils.ToHex((UInt32)block.content.Length) + " " + Utils.ToHex(block.blockChecksum8));
        switch (block.contentType)
        {
          case EContentType.Code:
            {
              TCodeBlock codeBlock = block.blockHeader as TCodeBlock;
              if (codeBlock != null)
                Console.Write(" " + Utils.ToHex(codeBlock.maybe_crc) + " " + Utils.ToHex(codeBlock.location));
              break;
            }
          case EContentType.Data:
            {
              i++;
              TDataBlock dataBlock = block.blockHeader as TDataBlock;
              if (dataBlock != null)
                Console.Write(" descr:" + dataBlock.description);
              break;
            }
          default:
            {
              throw new Exception("Unknown Block");
            }
        }
        Console.WriteLine("");
      }
      br.Close();

      EContentType oldType = blocks[0].contentType;
      FileStream fs = null;
      BufferedStream bs = null;
      i = 0;
      bool firstCode = false;
      foreach (TBlock block in blocks)
      {
        if (block.contentType == EContentType.Data)
        {
          if (oldType == EContentType.Data)
          {
            fs = new FileStream(outputDir + "\\" + "rofsImage.img", FileMode.Create, FileAccess.Write);
            bs = new BufferedStream(fs);
            firstCode = true;
            // File.WriteAllBytes(outputDir + i + "_InitBytes.bin", block.content);
          }
          else
          {
            fs = new FileStream(outputDir + "\\" + "rofsImage.img", FileMode.Append, FileAccess.Write);
            bs = new BufferedStream(fs);
          }
          //bs.Write(block.content, 0, block.content.Length);
          bs.Write(block.content, firstCode ? 0xc00 : 0, firstCode ? block.content.Length - 0xc00 : block.content.Length);
          firstCode = false;
          bs.Close();
          fs.Close();
        }
        if (block.contentType == EContentType.Data)
        {
          i++;
          //TDataBlock dataBlock = block.blockHeader as TDataBlock;
          //string outfile = outputDir + i + "_" + Utils.CleanFileName(dataBlock.description) + ".bin";
          //File.WriteAllBytes(outfile, block.content);
        }
        oldType = block.contentType;
      }
      bs.Close();
      fs.Close();
    }
    static public void Test(string fname)
    {
      outputDir = Directory.GetCurrentDirectory() + @"\headers";
      if (Directory.Exists(outputDir))
        Directory.Delete(outputDir, true);
      Directory.CreateDirectory(outputDir);

      BinaryReader br = new BinaryReader(new FileStream(fname, FileMode.Open));
      header.Read(br);
      Int16 i = 0;

      File.WriteAllBytes(outputDir + "\\header.bin", header.unkn);
      int cnt = 1;
      while (br.BaseStream.Position < br.BaseStream.Length)
      {
        UInt32 blockOffset = (UInt32)br.BaseStream.Position;
        TBlock block = new TBlock();
        block.Read(br);
        blocks.Add(block);
        Console.Write(" " + block.contentType + " At:" + Utils.ToHex(blockOffset) + " size:" + Utils.ToHex((UInt32)block.content.Length) + " " + Utils.ToHex(block.blockChecksum8));
        switch (block.contentType)
        {
          case EContentType.Code:
            {
              BinaryWriter bwHeader = new BinaryWriter(new FileStream(outputDir + @"\" + cnt.ToString()+ ".header.bin",FileMode.Create));
              block.blockHeader.Write(bwHeader);
              bwHeader.Close();
              cnt++;
              TCodeBlock codeBlock = block.blockHeader as TCodeBlock;
              if (codeBlock != null)
                Console.Write(" " + Utils.ToHex(codeBlock.maybe_crc) + " " + Utils.ToHex(codeBlock.location));
              break;
            }
          case EContentType.Data:
            {
              i++;
              BinaryWriter bwHeader = new BinaryWriter(new FileStream(outputDir + @"\" + cnt.ToString() + ".header.bin", FileMode.Create));
              block.blockHeader.Write(bwHeader);
              bwHeader.Close();
              cnt++;
              TDataBlock dataBlock = block.blockHeader as TDataBlock;
              if (dataBlock != null)
                Console.Write(" descr:" + dataBlock.description);
              break;
            }
          default:
            {
              throw new Exception("Unknown Block");
            }
        }
        Console.WriteLine("");
      }
      br.Close();


      // Merge the Code Blocks
      // Dump Data and Code to file...
      EContentType oldType = blocks[0].contentType;
      FileStream fs = null;
      BufferedStream bs = null;
      i = 0;
      foreach (TBlock block in blocks)
      {
        if (block.contentType == EContentType.Data)
        {
          if (oldType == EContentType.Data)
          {
            fs = new FileStream(outputDir + "\\" + i + "_code.bin", FileMode.Create, FileAccess.Write);
            bs = new BufferedStream(fs);
            // File.WriteAllBytes(outputDir + i + "_InitBytes.bin", block.content);
          }
          else
          {
            fs = new FileStream(outputDir + "\\" + i + "_code.bin", FileMode.Append, FileAccess.Write);
            bs = new BufferedStream(fs);
          }
          bs.Write(block.content, 0, block.content.Length);
          bs.Close();
          fs.Close();
        }
        if (block.contentType == EContentType.Data)
        {
          i++;
          //TDataBlock dataBlock = block.blockHeader as TDataBlock;
          //string outfile = outputDir + i + "_" + Utils.CleanFileName(dataBlock.description) + ".bin";
          //File.WriteAllBytes(outfile, block.content);
        }
        oldType = block.contentType;
      }
      bs.Close();
      fs.Close();
    }