Skip to content

Commit

Permalink
Fix #58, verbose output for INCBIN
Browse files Browse the repository at this point in the history
  • Loading branch information
mungre committed Aug 27, 2024
1 parent dc54a1a commit d7e3860
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
34 changes: 33 additions & 1 deletion src/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -851,9 +851,16 @@ void LineParser::HandleIncBin()
{
string filename = EvaluateExpressionAsString();

if ( m_sourceCode->ShouldOutputAsm() )
{
cout << uppercase << hex << setfill( '0' ) << " ";
cout << setw(4) << ObjectCode::Instance().GetPC() << " ";
}

std::vector<unsigned char> firstFour;
try
{
ObjectCode::Instance().IncBin( filename.c_str() );
ObjectCode::Instance().IncBin( filename.c_str(), firstFour );
}
catch ( AsmException_AssembleError& e )
{
Expand All @@ -862,6 +869,31 @@ void LineParser::HandleIncBin()
throw;
}

if ( m_sourceCode->ShouldOutputAsm() )
{
size_t count = 0;
for ( size_t i = 0; i < firstFour.size(); i++ )
{
if ( i < 3 )
{
cout << setw(2) << static_cast<int>(firstFour[i]) << " ";
count += 3;
}
else if ( i == 3 )
{
cout << "... ";
count += 4;
}
}
while (count < 11)
{
cout << " ";
++count;
}
cout << "INCBIN \"" << filename << '"';
cout << endl << nouppercase << dec << setfill( ' ' );
}

if ( AdvanceAndCheckEndOfStatement() )
{
throw AsmException_SyntaxError_InvalidCharacter( m_line, m_column );
Expand Down
9 changes: 7 additions & 2 deletions src/objectcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ void ObjectCode::Clear( int start, int end, bool bAll )
ObjectCode::IncBin()
*/
/*************************************************************************************************/
void ObjectCode::IncBin( const char* filename )
void ObjectCode::IncBin( const char* filename, std::vector<unsigned char>& firstFour )
{
ifstream binfile;

Expand All @@ -394,7 +394,12 @@ void ObjectCode::IncBin( const char* filename )
while ( binfile.get( c ) )
{
assert( binfile.gcount() == 1 );
Assemble1( static_cast< unsigned char >( c ) );
unsigned char uc = static_cast< unsigned char >( c );
if ( firstFour.size() < 4 )
{
firstFour.push_back(uc);
}
Assemble1( uc );
}

if ( !binfile.eof() )
Expand Down
3 changes: 2 additions & 1 deletion src/objectcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include <cassert>
#include <cstdlib>
#include <vector>


class ObjectCode
Expand All @@ -49,7 +50,7 @@ class ObjectCode
void Assemble1( unsigned int opcode );
void Assemble2( unsigned int opcode, unsigned int val );
void Assemble3( unsigned int opcode, unsigned int addr );
void IncBin( const char* filename );
void IncBin( const char* filename, std::vector<unsigned char>& firstFour );

void SetGuard( int i );
void Clear( int start, int end, bool bAll = true );
Expand Down

0 comments on commit d7e3860

Please sign in to comment.