Skip to content

Commit

Permalink
Added PUTBASIC command and ported Thomas Harte's BASIC tokenisation c…
Browse files Browse the repository at this point in the history
…ode.

Corrected a few small errors.
  • Loading branch information
richtw1 committed Mar 1, 2011
1 parent 4e2e289 commit 1e9e56f
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 3 deletions.
Binary file modified beebasm.exe
Binary file not shown.
1 change: 1 addition & 0 deletions demo.asm
Expand Up @@ -33,6 +33,7 @@ radius = 100
timerlength = 64*8*26
debugrasters = FALSE


\\ Define some zp locations

ORG 0
Expand Down
Binary file modified demo.ssd
Binary file not shown.
2 changes: 2 additions & 0 deletions src/VS2010/BeebAsm.vcxproj
Expand Up @@ -76,6 +76,7 @@
<ItemGroup>
<ClCompile Include="..\asmexception.cpp" />
<ClCompile Include="..\assemble.cpp" />
<ClCompile Include="..\BASIC.cpp" />
<ClCompile Include="..\commands.cpp" />
<ClCompile Include="..\discimage.cpp" />
<ClCompile Include="..\expression.cpp" />
Expand All @@ -89,6 +90,7 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\asmexception.h" />
<ClInclude Include="..\BASIC.h" />
<ClInclude Include="..\discimage.h" />
<ClInclude Include="..\globaldata.h" />
<ClInclude Include="..\lineparser.h" />
Expand Down
6 changes: 6 additions & 0 deletions src/VS2010/BeebAsm.vcxproj.filters
Expand Up @@ -51,6 +51,9 @@
<ClCompile Include="..\symboltable.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\BASIC.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\asmexception.h">
Expand Down Expand Up @@ -83,5 +86,8 @@
<ClInclude Include="..\tokens.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\BASIC.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
36 changes: 35 additions & 1 deletion src/commands.cpp
Expand Up @@ -34,6 +34,7 @@
#include "sourcefile.h"
#include "asmexception.h"
#include "discimage.h"
#include "BASIC.h"


using namespace std;
Expand Down Expand Up @@ -1390,6 +1391,9 @@ void LineParser::HandlePrint()
/*************************************************************************************************/
void LineParser::HandlePutFile()
{
// Syntax:
// PUTFILE <host filename>, [<beeb filename>,] <start addr> [,<exec addr>]

if ( !AdvanceAndCheckEndOfStatement() )
{
throw AsmException_SyntaxError_EmptyExpression( m_line, m_column );
Expand Down Expand Up @@ -1516,7 +1520,7 @@ void LineParser::HandlePutFile()
if ( GlobalData::Instance().IsSecondPass() )
{
ifstream inputFile;
inputFile.open( hostFilename, ios_base::in | ios_base::binary );
inputFile.open( hostFilename.c_str(), ios_base::in | ios_base::binary );

if ( !inputFile )
{
Expand Down Expand Up @@ -1620,5 +1624,35 @@ void LineParser::HandlePutBasic()
{
throw AsmException_SyntaxError_InvalidCharacter( m_line, m_column );
}

if ( GlobalData::Instance().IsSecondPass() &&
GlobalData::Instance().UsesDiscImage() )
{
Uint8* buffer = new Uint8[ 0x10000 ];
int fileSize;
bool bSuccess = ImportBASIC( hostFilename.c_str(), buffer, &fileSize );

if (!bSuccess)
{
if (GetBASICErrorNum() == 2)
{
throw AsmException_AssembleError_FileOpen();
}
else
{
throw AsmException_FileError( hostFilename.c_str() );
}
}

// disc image version of the save
GlobalData::Instance().GetDiscImage()->AddFile( beebFilename.c_str(),
reinterpret_cast< unsigned char* >( buffer ),
0xFFFF1900,
0xFFFF8023,
fileSize );

delete [] buffer;
}

}

3 changes: 3 additions & 0 deletions src/globaldata.h
Expand Up @@ -44,6 +44,7 @@ class GlobalData
inline void SetDiscImage( DiscImage* d ) { m_pDiscImage = d; }
inline void ResetForId() { m_forId = 0; }
inline void SetSaved() { m_bSaved = true; }
inline void SetOutputFile( const char* p ) { m_pOutputFile = p; }

inline int GetPass() const { return m_pass; }
inline bool IsFirstPass() const { return ( m_pass == 0 ); }
Expand All @@ -54,6 +55,7 @@ class GlobalData
inline DiscImage* GetDiscImage() const { return m_pDiscImage; }
inline int GetNextForId() { return m_forId++; }
inline bool IsSaved() const { return m_bSaved; }
inline const char* GetOutputFile() const { return m_pOutputFile; }


private:
Expand All @@ -71,6 +73,7 @@ class GlobalData
int m_forId;
int m_randomSeed;
bool m_bSaved;
const char* m_pOutputFile;
};


Expand Down
20 changes: 18 additions & 2 deletions src/main.cpp
Expand Up @@ -34,12 +34,13 @@
#include "objectcode.h"
#include "symboltable.h"
#include "discimage.h"
#include "BASIC.h"


using namespace std;


#define VERSION "1.04"
#define VERSION "1.05"


/*************************************************************************************************/
Expand All @@ -56,13 +57,15 @@ using namespace std;
int main( int argc, char* argv[] )
{
const char* pInputFile = NULL;
const char* pOutputFile = NULL;
const char* pDiscInputFile = NULL;
const char* pDiscOutputFile = NULL;

enum STATES
{
READY,
WAITING_FOR_INPUT_FILENAME,
WAITING_FOR_OUTPUT_FILENAME,
WAITING_FOR_DISC_INPUT_FILENAME,
WAITING_FOR_DISC_OUTPUT_FILENAME,
WAITING_FOR_BOOT_FILENAME
Expand All @@ -85,6 +88,10 @@ int main( int argc, char* argv[] )
{
state = WAITING_FOR_INPUT_FILENAME;
}
else if ( strcmp( argv[i], "-o" ) == 0 )
{
state = WAITING_FOR_OUTPUT_FILENAME;
}
else if ( strcmp( argv[i], "-do" ) == 0 )
{
state = WAITING_FOR_DISC_OUTPUT_FILENAME;
Expand All @@ -110,6 +117,7 @@ int main( int argc, char* argv[] )
cout << "beebasm " VERSION << endl << endl;
cout << "Possible options:" << endl;
cout << " -i <file> Specify source filename" << endl;
cout << " -o <file> Specify output filename (when not specified by SAVE command)" << endl;
cout << " -di <file> Specify a disc image file to be added to" << endl;
cout << " -do <file> Specify a disc image file to output" << endl;
cout << " -boot <file> Specify a filename to be run by !BOOT on a new disc image" << endl;
Expand All @@ -134,6 +142,13 @@ int main( int argc, char* argv[] )
break;


case WAITING_FOR_OUTPUT_FILENAME:

pOutputFile = argv[i];
state = READY;
break;


case WAITING_FOR_DISC_OUTPUT_FILENAME:

pDiscOutputFile = argv[i];
Expand All @@ -160,7 +175,7 @@ int main( int argc, char* argv[] )
if ( state != READY )
{
cerr << "Parameter error -" << endl;
cerr << "Type beebasm -help for syntax" << endl;
cerr << "Type beebasm --help for syntax" << endl;
return EXIT_FAILURE;
}

Expand All @@ -186,6 +201,7 @@ int main( int argc, char* argv[] )

SymbolTable::Create();
ObjectCode::Create();
SetupBASICTables();

time_t randomSeed = time( NULL );

Expand Down

0 comments on commit 1e9e56f

Please sign in to comment.