48 lines
1.2 KiB
C++
48 lines
1.2 KiB
C++
#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);
|
|
}
|
|
}
|