beebasm
changeset 30:d0c893ec6da4
Small correction to Makefile.inc
Added PUTFILE command
| author | RichTW <richtw1@gmail.com> |
|---|---|
| date | Tue Mar 01 18:20:28 2011 +0100 |
| parents | 5d32efc3f4ad |
| children | eb7f757ddafa |
| files | beebasm.exe demo.asm demo.ssd src/Makefile.inc src/commands.cpp src/lineparser.h |
| diffstat | 6 files changed, 249 insertions(+), 2 deletions(-) [+] |
line diff
1.1 Binary file beebasm.exe has changed
2.1 --- a/demo.asm Sun Feb 27 16:52:18 2011 +0100 2.2 +++ b/demo.asm Tue Mar 01 18:20:28 2011 +0100 2.3 @@ -33,7 +33,6 @@ 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/Makefile.inc Sun Feb 27 16:52:18 2011 +0100 4.2 +++ b/src/Makefile.inc Tue Mar 01 18:20:28 2011 +0100 4.3 @@ -90,8 +90,10 @@ 4.4 endif 4.5 4.6 ifdef PLATFORM 4.7 +ifndef INCLUDE_DEPS 4.8 $(info Automatically using platform $(PLATFORM)) 4.9 endif 4.10 +endif 4.11 4.12 endif 4.13
5.1 --- a/src/commands.cpp Sun Feb 27 16:52:18 2011 +0100 5.2 +++ b/src/commands.cpp Tue Mar 01 18:20:28 2011 +0100 5.3 @@ -67,7 +67,9 @@ 5.4 { "INCBIN", &LineParser::HandleIncBin, 0 }, 5.5 { "{", &LineParser::HandleOpenBrace, 0 }, 5.6 { "}", &LineParser::HandleCloseBrace, 0 }, 5.7 - { "MAPCHAR", &LineParser::HandleMapChar, 0 } 5.8 + { "MAPCHAR", &LineParser::HandleMapChar, 0 }, 5.9 + { "PUTFILE", &LineParser::HandlePutFile, 0 }, 5.10 + { "PUTBASIC", &LineParser::HandlePutBasic, 0 } 5.11 }; 5.12 5.13 5.14 @@ -1378,3 +1380,245 @@ 5.15 cout << endl; 5.16 } 5.17 } 5.18 + 5.19 + 5.20 + 5.21 +/*************************************************************************************************/ 5.22 +/** 5.23 + LineParser::HandlePutFile() 5.24 +*/ 5.25 +/*************************************************************************************************/ 5.26 +void LineParser::HandlePutFile() 5.27 +{ 5.28 + if ( !AdvanceAndCheckEndOfStatement() ) 5.29 + { 5.30 + throw AsmException_SyntaxError_EmptyExpression( m_line, m_column ); 5.31 + } 5.32 + 5.33 + if ( m_line[ m_column ] != '\"' ) 5.34 + { 5.35 + throw AsmException_SyntaxError_EmptyExpression( m_line, m_column ); 5.36 + } 5.37 + 5.38 + // get first filename 5.39 + size_t endQuotePos = m_line.find_first_of( '\"', m_column + 1 ); 5.40 + 5.41 + if ( endQuotePos == string::npos ) 5.42 + { 5.43 + throw AsmException_SyntaxError_MissingQuote( m_line, m_line.length() ); 5.44 + } 5.45 + 5.46 + string hostFilename( m_line.substr( m_column + 1, endQuotePos - m_column - 1 ) ); 5.47 + string beebFilename = hostFilename; 5.48 + int start = 0; 5.49 + int exec = 0; 5.50 + 5.51 + m_column = endQuotePos + 1; 5.52 + 5.53 + if ( !AdvanceAndCheckEndOfStatement() ) 5.54 + { 5.55 + throw AsmException_SyntaxError_EmptyExpression( m_line, m_column ); 5.56 + } 5.57 + 5.58 + if ( m_line[ m_column ] != ',' ) 5.59 + { 5.60 + throw AsmException_SyntaxError_MissingComma( m_line, m_column ); 5.61 + } 5.62 + 5.63 + m_column++; 5.64 + 5.65 + if ( !AdvanceAndCheckEndOfStatement() ) 5.66 + { 5.67 + throw AsmException_SyntaxError_EmptyExpression( m_line, m_column ); 5.68 + } 5.69 + 5.70 + if ( m_line[ m_column ] == '\"' ) 5.71 + { 5.72 + // string 5.73 + endQuotePos = m_line.find_first_of( '\"', m_column + 1 ); 5.74 + 5.75 + if ( endQuotePos == string::npos ) 5.76 + { 5.77 + throw AsmException_SyntaxError_MissingQuote( m_line, m_line.length() ); 5.78 + } 5.79 + 5.80 + // get the second filename parameter 5.81 + 5.82 + beebFilename = m_line.substr( m_column + 1, endQuotePos - m_column - 1 ); 5.83 + 5.84 + m_column = endQuotePos + 1; 5.85 + 5.86 + if ( !AdvanceAndCheckEndOfStatement() ) 5.87 + { 5.88 + // found nothing 5.89 + throw AsmException_SyntaxError_EmptyExpression( m_line, m_column ); 5.90 + } 5.91 + 5.92 + if ( m_line[ m_column ] != ',' ) 5.93 + { 5.94 + // did not find a comma 5.95 + throw AsmException_SyntaxError_InvalidCharacter( m_line, m_column ); 5.96 + } 5.97 + 5.98 + m_column++; 5.99 + } 5.100 + 5.101 + // Get start address 5.102 + 5.103 + try 5.104 + { 5.105 + start = EvaluateExpressionAsInt(); 5.106 + } 5.107 + catch ( AsmException_SyntaxError_SymbolNotDefined& ) 5.108 + { 5.109 + if ( GlobalData::Instance().IsSecondPass() ) 5.110 + { 5.111 + throw; 5.112 + } 5.113 + } 5.114 + 5.115 + exec = start; 5.116 + 5.117 + if ( start < 0 || start > 0xFFFF ) 5.118 + { 5.119 + throw AsmException_SyntaxError_OutOfRange( m_line, m_column ); 5.120 + } 5.121 + 5.122 + if ( m_line[ m_column ] == ',' ) 5.123 + { 5.124 + m_column++; 5.125 + 5.126 + try 5.127 + { 5.128 + exec = EvaluateExpressionAsInt(); 5.129 + } 5.130 + catch ( AsmException_SyntaxError_SymbolNotDefined& ) 5.131 + { 5.132 + if ( GlobalData::Instance().IsSecondPass() ) 5.133 + { 5.134 + throw; 5.135 + } 5.136 + } 5.137 + 5.138 + if ( exec < 0 || exec > 0xFFFF ) 5.139 + { 5.140 + throw AsmException_SyntaxError_OutOfRange( m_line, m_column ); 5.141 + } 5.142 + } 5.143 + 5.144 + // check this is now the end 5.145 + 5.146 + if ( AdvanceAndCheckEndOfStatement() ) 5.147 + { 5.148 + throw AsmException_SyntaxError_InvalidCharacter( m_line, m_column ); 5.149 + } 5.150 + 5.151 + if ( GlobalData::Instance().IsSecondPass() ) 5.152 + { 5.153 + ifstream inputFile; 5.154 + inputFile.open( hostFilename, ios_base::in | ios_base::binary ); 5.155 + 5.156 + if ( !inputFile ) 5.157 + { 5.158 + throw AsmException_AssembleError_FileOpen(); 5.159 + } 5.160 + 5.161 + inputFile.seekg( 0, ios_base::end ); 5.162 + size_t fileSize = static_cast< size_t >( inputFile.tellg() ); 5.163 + inputFile.seekg( 0, ios_base::beg ); 5.164 + 5.165 + char* buffer = new char[ fileSize ]; 5.166 + inputFile.read( buffer, fileSize ); 5.167 + inputFile.close(); 5.168 + 5.169 + cout << "Read file " << hostFilename << ": size " << fileSize << " bytes" << ": " << hex << start << " " << exec << endl; 5.170 + 5.171 + if ( GlobalData::Instance().UsesDiscImage() ) 5.172 + { 5.173 + // disc image version of the save 5.174 + GlobalData::Instance().GetDiscImage()->AddFile( beebFilename.c_str(), 5.175 + reinterpret_cast< unsigned char* >( buffer ), 5.176 + start, 5.177 + exec, 5.178 + fileSize ); 5.179 + } 5.180 + 5.181 + delete [] buffer; 5.182 + } 5.183 +} 5.184 + 5.185 + 5.186 +/*************************************************************************************************/ 5.187 +/** 5.188 + LineParser::HandlePutBasic() 5.189 +*/ 5.190 +/*************************************************************************************************/ 5.191 +void LineParser::HandlePutBasic() 5.192 +{ 5.193 + if ( !AdvanceAndCheckEndOfStatement() ) 5.194 + { 5.195 + throw AsmException_SyntaxError_EmptyExpression( m_line, m_column ); 5.196 + } 5.197 + 5.198 + if ( m_line[ m_column ] != '\"' ) 5.199 + { 5.200 + throw AsmException_SyntaxError_EmptyExpression( m_line, m_column ); 5.201 + } 5.202 + 5.203 + // get first filename 5.204 + size_t endQuotePos = m_line.find_first_of( '\"', m_column + 1 ); 5.205 + 5.206 + if ( endQuotePos == string::npos ) 5.207 + { 5.208 + throw AsmException_SyntaxError_MissingQuote( m_line, m_line.length() ); 5.209 + } 5.210 + 5.211 + string hostFilename( m_line.substr( m_column + 1, endQuotePos - m_column - 1 ) ); 5.212 + string beebFilename = hostFilename; 5.213 + 5.214 + m_column = endQuotePos + 1; 5.215 + 5.216 + if ( AdvanceAndCheckEndOfStatement() ) 5.217 + { 5.218 + // see if there's a second parameter 5.219 + 5.220 + if ( m_line[ m_column ] != ',' ) 5.221 + { 5.222 + throw AsmException_SyntaxError_MissingComma( m_line, m_column ); 5.223 + } 5.224 + 5.225 + m_column++; 5.226 + 5.227 + if ( !AdvanceAndCheckEndOfStatement() ) 5.228 + { 5.229 + throw AsmException_SyntaxError_EmptyExpression( m_line, m_column ); 5.230 + } 5.231 + 5.232 + if ( m_line[ m_column ] != '\"' ) 5.233 + { 5.234 + throw AsmException_SyntaxError_EmptyExpression( m_line, m_column ); 5.235 + } 5.236 + 5.237 + // string 5.238 + endQuotePos = m_line.find_first_of( '\"', m_column + 1 ); 5.239 + 5.240 + if ( endQuotePos == string::npos ) 5.241 + { 5.242 + throw AsmException_SyntaxError_MissingQuote( m_line, m_line.length() ); 5.243 + } 5.244 + 5.245 + // get the second parameter 5.246 + 5.247 + beebFilename = m_line.substr( m_column + 1, endQuotePos - m_column - 1 ); 5.248 + 5.249 + m_column = endQuotePos + 1; 5.250 + } 5.251 + 5.252 + // check this is now the end 5.253 + 5.254 + if ( AdvanceAndCheckEndOfStatement() ) 5.255 + { 5.256 + throw AsmException_SyntaxError_InvalidCharacter( m_line, m_column ); 5.257 + } 5.258 +} 5.259 +
6.1 --- a/src/lineparser.h Sun Feb 27 16:52:18 2011 +0100 6.2 +++ b/src/lineparser.h Tue Mar 01 18:20:28 2011 +0100 6.3 @@ -148,6 +148,8 @@ 6.4 void HandleGuard(); 6.5 void HandleClear(); 6.6 void HandleMapChar(); 6.7 + void HandlePutFile(); 6.8 + void HandlePutBasic(); 6.9 6.10 // expression evaluating methods 6.11
