beebasm

changeset 31:eb7f757ddafa

Added PUTBASIC command and ported Thomas Harte's BASIC tokenisation code. Corrected a few small errors.
author RichTW <richtw1@gmail.com>
date Tue Mar 01 20:05:08 2011 +0100
parents d0c893ec6da4
children ceed0131ba5d
files beebasm.exe demo.asm demo.ssd src/VS2010/BeebAsm.vcxproj src/VS2010/BeebAsm.vcxproj.filters src/commands.cpp src/globaldata.h src/main.cpp
diffstat 8 files changed, 65 insertions(+), 3 deletions(-) [+]
line diff
     1.1 Binary file beebasm.exe has changed
     2.1 --- a/demo.asm	Tue Mar 01 18:20:28 2011 +0100
     2.2 +++ b/demo.asm	Tue Mar 01 20:05:08 2011 +0100
     2.3 @@ -33,6 +33,7 @@
     2.4  timerlength		= 64*8*26
     2.5  debugrasters	= FALSE
     2.6  
     2.7 +
     2.8  \\ Define some zp locations
     2.9  
    2.10  ORG 0
     3.1 Binary file demo.ssd has changed
     4.1 --- a/src/VS2010/BeebAsm.vcxproj	Tue Mar 01 18:20:28 2011 +0100
     4.2 +++ b/src/VS2010/BeebAsm.vcxproj	Tue Mar 01 20:05:08 2011 +0100
     4.3 @@ -76,6 +76,7 @@
     4.4    <ItemGroup>
     4.5      <ClCompile Include="..\asmexception.cpp" />
     4.6      <ClCompile Include="..\assemble.cpp" />
     4.7 +    <ClCompile Include="..\BASIC.cpp" />
     4.8      <ClCompile Include="..\commands.cpp" />
     4.9      <ClCompile Include="..\discimage.cpp" />
    4.10      <ClCompile Include="..\expression.cpp" />
    4.11 @@ -89,6 +90,7 @@
    4.12    </ItemGroup>
    4.13    <ItemGroup>
    4.14      <ClInclude Include="..\asmexception.h" />
    4.15 +    <ClInclude Include="..\BASIC.h" />
    4.16      <ClInclude Include="..\discimage.h" />
    4.17      <ClInclude Include="..\globaldata.h" />
    4.18      <ClInclude Include="..\lineparser.h" />
     5.1 --- a/src/VS2010/BeebAsm.vcxproj.filters	Tue Mar 01 18:20:28 2011 +0100
     5.2 +++ b/src/VS2010/BeebAsm.vcxproj.filters	Tue Mar 01 20:05:08 2011 +0100
     5.3 @@ -51,6 +51,9 @@
     5.4      <ClCompile Include="..\symboltable.cpp">
     5.5        <Filter>Source Files</Filter>
     5.6      </ClCompile>
     5.7 +    <ClCompile Include="..\BASIC.cpp">
     5.8 +      <Filter>Source Files</Filter>
     5.9 +    </ClCompile>
    5.10    </ItemGroup>
    5.11    <ItemGroup>
    5.12      <ClInclude Include="..\asmexception.h">
    5.13 @@ -83,5 +86,8 @@
    5.14      <ClInclude Include="..\tokens.h">
    5.15        <Filter>Header Files</Filter>
    5.16      </ClInclude>
    5.17 +    <ClInclude Include="..\BASIC.h">
    5.18 +      <Filter>Header Files</Filter>
    5.19 +    </ClInclude>
    5.20    </ItemGroup>
    5.21  </Project>
    5.22 \ No newline at end of file
     6.1 --- a/src/commands.cpp	Tue Mar 01 18:20:28 2011 +0100
     6.2 +++ b/src/commands.cpp	Tue Mar 01 20:05:08 2011 +0100
     6.3 @@ -34,6 +34,7 @@
     6.4  #include "sourcefile.h"
     6.5  #include "asmexception.h"
     6.6  #include "discimage.h"
     6.7 +#include "BASIC.h"
     6.8  
     6.9  
    6.10  using namespace std;
    6.11 @@ -1390,6 +1391,9 @@
    6.12  /*************************************************************************************************/
    6.13  void LineParser::HandlePutFile()
    6.14  {
    6.15 +	// Syntax:
    6.16 +	// PUTFILE <host filename>, [<beeb filename>,] <start addr> [,<exec addr>]
    6.17 +
    6.18  	if ( !AdvanceAndCheckEndOfStatement() )
    6.19  	{
    6.20  		throw AsmException_SyntaxError_EmptyExpression( m_line, m_column );
    6.21 @@ -1516,7 +1520,7 @@
    6.22  	if ( GlobalData::Instance().IsSecondPass() )
    6.23  	{
    6.24  		ifstream inputFile;
    6.25 -		inputFile.open( hostFilename, ios_base::in | ios_base::binary );
    6.26 +		inputFile.open( hostFilename.c_str(), ios_base::in | ios_base::binary );
    6.27  
    6.28  		if ( !inputFile )
    6.29  		{
    6.30 @@ -1620,5 +1624,35 @@
    6.31  	{
    6.32  		throw AsmException_SyntaxError_InvalidCharacter( m_line, m_column );
    6.33  	}
    6.34 +
    6.35 +	if ( GlobalData::Instance().IsSecondPass() &&
    6.36 +		 GlobalData::Instance().UsesDiscImage() )
    6.37 +	{
    6.38 +		Uint8* buffer = new Uint8[ 0x10000 ];
    6.39 +		int fileSize;
    6.40 +		bool bSuccess = ImportBASIC( hostFilename.c_str(), buffer, &fileSize );
    6.41 +
    6.42 +		if (!bSuccess)
    6.43 +		{
    6.44 +			if (GetBASICErrorNum() == 2)
    6.45 +			{
    6.46 +				throw AsmException_AssembleError_FileOpen();
    6.47 +			}
    6.48 +			else
    6.49 +			{
    6.50 +				throw AsmException_FileError( hostFilename.c_str() );
    6.51 +			}
    6.52 +		}
    6.53 +
    6.54 +		// disc image version of the save
    6.55 +		GlobalData::Instance().GetDiscImage()->AddFile( beebFilename.c_str(),
    6.56 +														reinterpret_cast< unsigned char* >( buffer ),
    6.57 +														0xFFFF1900,
    6.58 +														0xFFFF8023,
    6.59 +														fileSize );
    6.60 +
    6.61 +		delete [] buffer;
    6.62 +	}
    6.63 +
    6.64  }
    6.65  
     7.1 --- a/src/globaldata.h	Tue Mar 01 18:20:28 2011 +0100
     7.2 +++ b/src/globaldata.h	Tue Mar 01 20:05:08 2011 +0100
     7.3 @@ -44,6 +44,7 @@
     7.4  	inline void SetDiscImage( DiscImage* d )	{ m_pDiscImage = d; }
     7.5  	inline void ResetForId()					{ m_forId = 0; }
     7.6  	inline void SetSaved()						{ m_bSaved = true; }
     7.7 +	inline void SetOutputFile( const char* p )	{ m_pOutputFile = p; }
     7.8  
     7.9  	inline int GetPass() const					{ return m_pass; }
    7.10  	inline bool IsFirstPass() const				{ return ( m_pass == 0 ); }
    7.11 @@ -54,6 +55,7 @@
    7.12  	inline DiscImage* GetDiscImage() const		{ return m_pDiscImage; }
    7.13  	inline int GetNextForId()					{ return m_forId++; }
    7.14  	inline bool IsSaved() const					{ return m_bSaved; }
    7.15 +	inline const char* GetOutputFile() const	{ return m_pOutputFile; }
    7.16  
    7.17  
    7.18  private:
    7.19 @@ -71,6 +73,7 @@
    7.20  	int							m_forId;
    7.21  	int							m_randomSeed;
    7.22  	bool						m_bSaved;
    7.23 +	const char*					m_pOutputFile;
    7.24  };
    7.25  
    7.26  
     8.1 --- a/src/main.cpp	Tue Mar 01 18:20:28 2011 +0100
     8.2 +++ b/src/main.cpp	Tue Mar 01 20:05:08 2011 +0100
     8.3 @@ -34,12 +34,13 @@
     8.4  #include "objectcode.h"
     8.5  #include "symboltable.h"
     8.6  #include "discimage.h"
     8.7 +#include "BASIC.h"
     8.8  
     8.9  
    8.10  using namespace std;
    8.11  
    8.12  
    8.13 -#define VERSION "1.04"
    8.14 +#define VERSION "1.05"
    8.15  
    8.16  
    8.17  /*************************************************************************************************/
    8.18 @@ -56,6 +57,7 @@
    8.19  int main( int argc, char* argv[] )
    8.20  {
    8.21  	const char* pInputFile = NULL;
    8.22 +	const char* pOutputFile = NULL;
    8.23  	const char* pDiscInputFile = NULL;
    8.24  	const char* pDiscOutputFile = NULL;
    8.25  
    8.26 @@ -63,6 +65,7 @@
    8.27  	{
    8.28  		READY,
    8.29  		WAITING_FOR_INPUT_FILENAME,
    8.30 +		WAITING_FOR_OUTPUT_FILENAME,
    8.31  		WAITING_FOR_DISC_INPUT_FILENAME,
    8.32  		WAITING_FOR_DISC_OUTPUT_FILENAME,
    8.33  		WAITING_FOR_BOOT_FILENAME
    8.34 @@ -85,6 +88,10 @@
    8.35  				{
    8.36  					state = WAITING_FOR_INPUT_FILENAME;
    8.37  				}
    8.38 +				else if ( strcmp( argv[i], "-o" ) == 0 )
    8.39 +				{
    8.40 +					state = WAITING_FOR_OUTPUT_FILENAME;
    8.41 +				}
    8.42  				else if ( strcmp( argv[i], "-do" ) == 0 )
    8.43  				{
    8.44  					state = WAITING_FOR_DISC_OUTPUT_FILENAME;
    8.45 @@ -110,6 +117,7 @@
    8.46  					cout << "beebasm " VERSION << endl << endl;
    8.47  					cout << "Possible options:" << endl;
    8.48  					cout << " -i <file>      Specify source filename" << endl;
    8.49 +					cout << " -o <file>      Specify output filename (when not specified by SAVE command)" << endl;
    8.50  					cout << " -di <file>     Specify a disc image file to be added to" << endl;
    8.51  					cout << " -do <file>     Specify a disc image file to output" << endl;
    8.52  					cout << " -boot <file>   Specify a filename to be run by !BOOT on a new disc image" << endl;
    8.53 @@ -134,6 +142,13 @@
    8.54  				break;
    8.55  
    8.56  
    8.57 +			case WAITING_FOR_OUTPUT_FILENAME:
    8.58 +
    8.59 +				pOutputFile = argv[i];
    8.60 +				state = READY;
    8.61 +				break;
    8.62 +
    8.63 +
    8.64  			case WAITING_FOR_DISC_OUTPUT_FILENAME:
    8.65  
    8.66  				pDiscOutputFile = argv[i];
    8.67 @@ -160,7 +175,7 @@
    8.68  	if ( state != READY )
    8.69  	{
    8.70  		cerr << "Parameter error -" << endl;
    8.71 -		cerr << "Type beebasm -help for syntax" << endl;
    8.72 +		cerr << "Type beebasm --help for syntax" << endl;
    8.73  		return EXIT_FAILURE;
    8.74  	}
    8.75  
    8.76 @@ -186,6 +201,7 @@
    8.77  
    8.78  	SymbolTable::Create();
    8.79  	ObjectCode::Create();
    8.80 +	SetupBASICTables();
    8.81  
    8.82  	time_t randomSeed = time( NULL );
    8.83