Initial
This commit is contained in:
47
as68hc11/S19Generator.cpp
Normal file
47
as68hc11/S19Generator.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
#include <as68hc11/S19Generator.hpp>
|
||||
|
||||
bool S19Generator::generateCode(PureViewOfFile &rawCode,const String &strPathOutput)
|
||||
{
|
||||
File outFile;
|
||||
DWORD genBytes=0;
|
||||
String endLine;
|
||||
|
||||
endLine="S9030000FC";
|
||||
rawCode.rewind();
|
||||
if(!outFile.open(strPathOutput,"wb"))return false;
|
||||
generateLines(rawCode.tell(),rawCode.size(),rawCode,outFile);
|
||||
outFile.writeLine(endLine);
|
||||
::OutputDebugString(endLine+String("\r\n"));
|
||||
return false;
|
||||
}
|
||||
|
||||
void S19Generator::generateLines(DWORD origin,DWORD codeSize,PureViewOfFile &rawCode,File &outFile)
|
||||
{
|
||||
String strByte;
|
||||
BYTE codeByte;
|
||||
int checksum=0;
|
||||
|
||||
while(codeSize>0)
|
||||
{
|
||||
String strLine;
|
||||
checksum=0;
|
||||
int bytesInLine=codeSize<MaxDataBytesPerLine?codeSize:MaxDataBytesPerLine;
|
||||
::sprintf(strLine,"S1%02x%04x",bytesInLine+1+2,origin);
|
||||
checksum+=(bytesInLine+1+2);
|
||||
checksum+=origin;
|
||||
for(int index=0;index<bytesInLine;index++,codeSize--,origin++)
|
||||
{
|
||||
rawCode.read(codeByte);
|
||||
checksum+=codeByte;
|
||||
::sprintf(strByte,"%02x",codeByte);
|
||||
strLine+=strByte;
|
||||
}
|
||||
checksum=checksum&0xFF;
|
||||
checksum=~checksum;
|
||||
::sprintf(strByte,"%02x",(BYTE)checksum);
|
||||
strLine+=strByte;
|
||||
strLine.upper();
|
||||
::OutputDebugString(strLine+String("\r\n"));
|
||||
outFile.writeLine(strLine);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user