objfile_c.cpp

来自「MCS51单片机的宏汇编器源程序。有需要的朋友请下载!」· C++ 代码 · 共 76 行

CPP
76
字号
//---------------------------------------------------------------------------
//-------- OBJfile_C.cpp ---------------------------------------------------
//---------------------------------------------------------------------------

#include "OBJfile_H.h"
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
void OBJfile::Open()
{ FilePt = fopen(FileName,"wb");
  if(FilePt == NULL)
   { printf("\nCannot open file %s to write!",FileName());
     exit(-1);
   } // endif
  // The file has opened...
} // end Open
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
void OBJfile::Close()
{ printf("\nOBJ records have been written to %s.",FileName());
  if( fclose(FilePt) )
   { printf("\nClose file %s error.",FileName()); } // endif
} // end Close
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
void OBJfile::Write(const void* buf, int16u len)
{ if(fwrite(buf, len,1, FilePt) != 1 )
   { printf("\nError occured while writing file %s.",FileName());
     exit(-1);
   } // endif
} // end Write
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
// 注意,文件必须先打开。
//---------------------------------------------------------------------------
void OBJfile::WriteARecord(const OBJrecord& rec)
{ int8u typ = rec.GetTYP();
  Write(&typ, 1);
  int16u len = rec.GetLEN();
  Write(&len, 2);
  register const int8u* dp = (const char*)rec;
  Write(dp, len - 1);
  int8u chk = rec.GetCHK();
  Write(&chk, 1);
} // end WriteARecord
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
// 写一个文件头到目标文件上。
//---------------------------------------------------------------------------
void OBJfile::WriteFileHeaderRecord(const Jstring& cmnd, const AsmFile &Srcfile)
{ OBJrecord FHR(0x70);  // File Header Record

  FHR.AddByte(0xff);
  FHR.AddJstr(cmnd);
  FHR.AddWord(0x0000);
  FHR.AddLong(0x00000000);     // the time
  FHR.AddJstr(FileName);
  FHR.AddWord(0x0001);
  FHR.AddLong(0x00000000);     // the time
  FHR.AddJstr(Srcfile.FileName);

  WriteARecord(FHR);
} // end WriteFileHeaderRecord
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
// end OBJfile_C.cpp
//---------------------------------------------------------------------------
//               Written by JamesyFront.    ZLGmcu Dev.Co.Ltd.  2002.
//---------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?