From d7e38607fbc436622c44f3d9c65267b801791fac Mon Sep 17 00:00:00 2001 From: Charles Reilly Date: Fri, 23 Aug 2024 22:45:59 +0100 Subject: [PATCH] Fix #58, verbose output for INCBIN --- src/commands.cpp | 34 +++++++++++++++++++++++++++++++++- src/objectcode.cpp | 9 +++++++-- src/objectcode.h | 3 ++- 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/commands.cpp b/src/commands.cpp index 0e04719..79e34eb 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -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 firstFour; try { - ObjectCode::Instance().IncBin( filename.c_str() ); + ObjectCode::Instance().IncBin( filename.c_str(), firstFour ); } catch ( AsmException_AssembleError& e ) { @@ -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(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 ); diff --git a/src/objectcode.cpp b/src/objectcode.cpp index 84c2370..cfb3d98 100644 --- a/src/objectcode.cpp +++ b/src/objectcode.cpp @@ -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& firstFour ) { ifstream binfile; @@ -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() ) diff --git a/src/objectcode.h b/src/objectcode.h index db6414b..b504d21 100644 --- a/src/objectcode.h +++ b/src/objectcode.h @@ -25,6 +25,7 @@ #include #include +#include class ObjectCode @@ -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& firstFour ); void SetGuard( int i ); void Clear( int start, int end, bool bAll = true );