Skip to content

Commit

Permalink
Added default SAVE filename facility (takes filename from the command…
Browse files Browse the repository at this point in the history
… line instead of the SAVE command)

Removed some debugging aids from the code completely.
  • Loading branch information
richtw1 committed Apr 25, 2011
1 parent ea0cf26 commit 4506417
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 50 deletions.
Binary file modified beebasm.exe
Binary file not shown.
2 changes: 1 addition & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ LDLIBS := -lstdc++ -lm
# Parameters to the executable

PARAMS := -i ../demo.6502 -do ../demo.ssd -boot Code -v
#PARAMS := -i ../test.6502 -v
#PARAMS := -i ../test.6502 -v -do ../test.ssd



Expand Down
2 changes: 2 additions & 0 deletions src/asmexception.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ DEFINE_SYNTAX_EXCEPTION( TooManyIFs, "Too many nested IFs." );
DEFINE_SYNTAX_EXCEPTION( BadAlignment, "Bad alignment." );
DEFINE_SYNTAX_EXCEPTION( OutOfRange, "Out of range." );
DEFINE_SYNTAX_EXCEPTION( BackwardsSkip, "Attempted to skip backwards to an address." );
DEFINE_SYNTAX_EXCEPTION( NoAnonSave, "Cannot specify SAVE without a filename if no default output filename has been specified." );
DEFINE_SYNTAX_EXCEPTION( OnlyOneAnonSave, "Can only use SAVE without a filename once per project." );



Expand Down
87 changes: 55 additions & 32 deletions src/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,8 @@ void LineParser::HandleSave()
int exec = 0;
int reload = 0;

int oldColumn = m_column;

// syntax is SAVE "filename", start, end [, exec [, reload] ]

if ( !AdvanceAndCheckEndOfStatement() )
Expand All @@ -943,46 +945,40 @@ void LineParser::HandleSave()
throw AsmException_SyntaxError_EmptyExpression( m_line, m_column );
}

if ( m_line[ m_column ] != '\"' )
{
// did not find a string
throw AsmException_SyntaxError_InvalidCharacter( m_line, m_column );
}

// get filename

size_t endQuotePos = m_line.find_first_of( '\"', m_column + 1 );
string saveFile;

if ( endQuotePos == string::npos )
if ( m_line[ m_column ] == '\"' )
{
// did not find the end of the string
throw AsmException_SyntaxError_MissingQuote( m_line, m_line.length() );
}
// get filename

string saveFile( m_line.substr( m_column + 1, endQuotePos - m_column - 1 ) );
size_t endQuotePos = m_line.find_first_of( '\"', m_column + 1 );

if ( GlobalData::Instance().ShouldOutputAsm() )
{
cout << "Saving file '" << saveFile << "'" << endl;
}
if ( endQuotePos == string::npos )
{
// did not find the end of the string
throw AsmException_SyntaxError_MissingQuote( m_line, m_line.length() );
}

m_column = endQuotePos + 1;
saveFile = m_line.substr( m_column + 1, endQuotePos - m_column - 1 );

// get start address
m_column = endQuotePos + 1;

if ( !AdvanceAndCheckEndOfStatement() )
{
// found nothing
throw AsmException_SyntaxError_EmptyExpression( m_line, m_column );
}
if ( !AdvanceAndCheckEndOfStatement() )
{
// found nothing
throw AsmException_SyntaxError_EmptyExpression( m_line, m_column );
}

if ( m_line[ m_column ] != ',' )
{
// did not find a comma
throw AsmException_SyntaxError_InvalidCharacter( m_line, m_column );
if ( m_line[ m_column ] != ',' )
{
// did not find a comma
throw AsmException_SyntaxError_InvalidCharacter( m_line, m_column );
}

m_column++;
}

m_column++;
// get start address

start = EvaluateExpressionAsInt();
exec = start;
Expand Down Expand Up @@ -1057,6 +1053,35 @@ void LineParser::HandleSave()
throw AsmException_SyntaxError_UnexpectedComma( m_line, m_column );
}

if ( saveFile == "" )
{
if ( GlobalData::Instance().GetOutputFile() != NULL )
{
saveFile = GlobalData::Instance().GetOutputFile();

if ( GlobalData::Instance().IsSecondPass() )
{
if ( GlobalData::Instance().GetNumAnonSaves() > 0 )
{
throw AsmException_SyntaxError_OnlyOneAnonSave( m_line, oldColumn );
}
else
{
GlobalData::Instance().IncNumAnonSaves();
}
}
}
else
{
throw AsmException_SyntaxError_NoAnonSave( m_line, oldColumn );
}
}

if ( GlobalData::Instance().ShouldOutputAsm() )
{
cout << "Saving file '" << saveFile << "'" << endl;
}

// OK - do it

if ( GlobalData::Instance().IsSecondPass() )
Expand Down Expand Up @@ -1683,7 +1708,6 @@ void LineParser::HandleMacro()
}

m_sourceCode->GetCurrentMacro()->SetName( macroName );
// cout << "MACRO '" << macroName << "'" << endl;
}
}
else
Expand Down Expand Up @@ -1715,7 +1739,6 @@ void LineParser::HandleMacro()
if ( GlobalData::Instance().IsFirstPass() )
{
m_sourceCode->GetCurrentMacro()->AddParameter( param );
// cout << " param: '" << param << "'" << endl;
}
bExpectComma = true;
bHasParameters = true;
Expand Down
3 changes: 2 additions & 1 deletion src/globaldata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ GlobalData::GlobalData()
m_bUseDiscImage( false ),
m_pDiscImage( NULL ),
m_bSaved( false ),
m_pOutputFile( NULL )
m_pOutputFile( NULL ),
m_numAnonSaves( 0 )
{
}

Expand Down
3 changes: 3 additions & 0 deletions src/globaldata.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class GlobalData
inline void ResetForId() { m_forId = 0; }
inline void SetSaved() { m_bSaved = true; }
inline void SetOutputFile( const char* p ) { m_pOutputFile = p; }
inline void IncNumAnonSaves() { m_numAnonSaves++; }

inline int GetPass() const { return m_pass; }
inline bool IsFirstPass() const { return ( m_pass == 0 ); }
Expand All @@ -56,6 +57,7 @@ class GlobalData
inline int GetNextForId() { return m_forId++; }
inline bool IsSaved() const { return m_bSaved; }
inline const char* GetOutputFile() const { return m_pOutputFile; }
inline int GetNumAnonSaves() const { return m_numAnonSaves; }


private:
Expand All @@ -74,6 +76,7 @@ class GlobalData
int m_randomSeed;
bool m_bSaved;
const char* m_pOutputFile;
int m_numAnonSaves;
};


Expand Down
15 changes: 1 addition & 14 deletions src/lineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,12 @@ void LineParser::Process()

if ( !SymbolTable::Instance().IsSymbolDefined( paramName ) )
{
// cout << " (symbol '" << paramName << "' = " << value << ")" << endl;
SymbolTable::Instance().AddSymbol( paramName, value );
}

}
catch ( AsmException_SyntaxError_SymbolNotDefined& )
{
// cout << " (symbol '" << paramName << "' not yet known)" << endl;
if ( GlobalData::Instance().IsSecondPass() )
{
throw;
Expand All @@ -250,13 +248,6 @@ void LineParser::Process()
MacroInstance macroInstance( macro, m_sourceCode );
macroInstance.Process();

// for ( int i = 0; i < macro->GetNumberOfLines(); i++ )
// {
// LineParser macroLine( m_sourceCode, macro->GetLine( i ) );
// cout << " macro: " << macro->GetLine( i ) << endl;
// macroLine.Process();
// }

HandleCloseBrace();

if ( GlobalData::Instance().ShouldOutputAsm() )
Expand Down Expand Up @@ -323,10 +314,7 @@ void LineParser::SkipStatement()
}
}

if ( m_sourceCode->GetCurrentMacro() != NULL )//&&
// m_line[ oldColumn ] != ':' &&
// m_line[ oldColumn ] != '\\' &&
// m_line[ oldColumn ] != ';' )
if ( m_sourceCode->GetCurrentMacro() != NULL )
{
string command = m_line.substr( oldColumn, m_column - oldColumn );

Expand All @@ -336,7 +324,6 @@ void LineParser::SkipStatement()
}

m_sourceCode->GetCurrentMacro()->AddLine( command );
// cout << " '" << command << "'" << endl;
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/sourcecode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ void SourceCode::Process()

string lineFromFile;

// while ( getline( m_file, lineFromFile ) )
while ( GetLine( lineFromFile ) )
{
// Convert tabs to spaces
Expand Down Expand Up @@ -532,7 +531,6 @@ void SourceCode::EndMacro( const string& line, int column )

if ( GlobalData::Instance().IsFirstPass() )
{
// cout << "Macro: '" << m_currentMacro->GetBody() << "'" << endl;
MacroTable::Instance().Add( m_currentMacro );
m_currentMacro = NULL;
}
Expand Down

0 comments on commit 4506417

Please sign in to comment.