Tokenizing BASIC into memory with beebasm

handy tools that can assist in the development of new software
Post Reply
User avatar
tricky
Posts: 7694
Joined: Tue Jun 21, 2011 9:25 am
Contact:

Tokenizing BASIC into memory with beebasm

Post by tricky »

On occasion, I have wanted to include machine code on the end of a basic program using beebasm, but it was rather clunky!
PUTBASIC only works to a disc image, so do that, PUTBASIC, extract the file from .ssd, INCBIN, assemble after it, SAVE concatenation!

Locally, I've added INCBASIC which hopefully includes the tokenized BASIC into "memory" at the current assembly point.
I've only given it ONE test as I have to go out, but though I would share my changes here to see what people think.

I've added INCBASIC next to PUTBASIC:
{ "PUTBASIC", &LineParser::HandlePutBasic, 0 },
{ "INCBASIC", &LineParser::HandleIncBasic, 0 },

Renamed HandlePutBasic to HandleIncPutBasic and passed in a bool to choose which behaviour.
void LineParser::HandleIncPutBasic(bool inc)
void LineParser::HandleIncBasic() {HandleIncPutBasic(true);}
void LineParser::HandlePutBasic() {HandleIncPutBasic(false);}

and then changed the end of the old HandlePutBasic function to add the tokenised code, copying from INCBIN!

Code: Select all

	if (inc || 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)
			{
				AsmException_AssembleError_FileOpen e(this);
				e.SetString( m_line );
				e.SetColumn( m_column );
				throw e;
			}
			else
			{
				std::string message = hostFilename + ": " + GetBASICError();
				throw AsmException_UserError( m_line, m_column, message );
			}
		}

		if (inc)
		{
			for (int i = 0; i < fileSize; ++i)
			{
				ObjectCode::Instance().Assemble1(buffer[i], this);
			}
		}
		else if (GlobalData::Instance().UsesDiscImage())
		{
			// disc image version of the save
			GlobalData::Instance().GetDiscImage()->AddFile( beebFilename.c_str(),
															reinterpret_cast< unsigned char* >( buffer ),
															0xFFFF1900,
															0xFFFF8023,
															fileSize );
		}

		delete [] buffer;
	}
This is definitely a quick and dirty hack and a niche of a niche, but what do you think?
garfield
Posts: 547
Joined: Mon Jan 03, 2005 1:38 am
Contact:

Re: Tokenizing BASIC into memory with beebasm

Post by garfield »

Seems like a useful enhancement Tricky.
User avatar
sweh
Posts: 3314
Joined: Sat Mar 10, 2012 12:05 pm
Location: 07410 New Jersey
Contact:

Re: Tokenizing BASIC into memory with beebasm

Post by sweh »

FWIW, I proposed using "*" as the filename to PUTBASIC to inline it

https://www.stardot.org.uk/forums/viewt ... 29#p374229
Rgds
Stephen
User avatar
tricky
Posts: 7694
Joined: Tue Jun 21, 2011 9:25 am
Contact:

Re: Tokenizing BASIC into memory with beebasm

Post by tricky »

"*" would be fine, it didn't occur to me :) send adding a new keyword was so cheap that I didn't try to find another way.
So, maybe two people would use it ;)
Post Reply

Return to “development tools”