diff options
| author | Markus Wick <degasus@users.noreply.github.com> | 2017-05-23 14:36:16 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-05-23 14:36:16 +0200 |
| commit | e3980d4c2285fe75ae5eb2b65285e73a7114342e (patch) | |
| tree | d1a7347824a75579355a69e21a268a0af00c2525 /Source/Core | |
| parent | 3a2ec8c8a11e571a19c3bee676b5ab21f5aa79c9 (diff) | |
| parent | a182c7f2a542df9487d6aad781a5e66fb8fb3880 (diff) | |
Merge pull request #5450 from ligfx/dspassemblefreerom
Small cleanups of DSPAssembler and the free DSP ROM code
Diffstat (limited to 'Source/Core')
| -rw-r--r-- | Source/Core/Core/DSP/DSPAssembler.cpp | 51 | ||||
| -rw-r--r-- | Source/Core/Core/DSP/DSPAssembler.h | 5 |
2 files changed, 35 insertions, 21 deletions
diff --git a/Source/Core/Core/DSP/DSPAssembler.cpp b/Source/Core/Core/DSP/DSPAssembler.cpp index 25686013e0..b5ca9dd01b 100644 --- a/Source/Core/Core/DSP/DSPAssembler.cpp +++ b/Source/Core/Core/DSP/DSPAssembler.cpp @@ -46,7 +46,8 @@ static const char* err_string[] = {"", "Wrong parameter: must be accumulator register", "Wrong parameter: must be mid accumulator register", "Invalid register", - "Number out of range"}; + "Number out of range", + "Program counter out of range"}; DSPAssembler::DSPAssembler(const AssemblerSettings& settings) : m_cur_addr(0), m_cur_pass(0), m_current_param(0), settings_(settings) @@ -61,11 +62,8 @@ bool DSPAssembler::Assemble(const std::string& text, std::vector<u16>& code, { if (line_numbers) line_numbers->clear(); - const std::string file_name = "tmp.asm"; - if (!File::WriteStringToFile(text, file_name)) - return false; InitPass(1); - if (!AssembleFile(file_name, 1)) + if (!AssemblePass(text, 1)) return false; // We now have the size of the output buffer @@ -75,7 +73,7 @@ bool DSPAssembler::Assemble(const std::string& text, std::vector<u16>& code, m_output_buffer.resize(m_totalSize); InitPass(2); - if (!AssembleFile(file_name, 2)) + if (!AssemblePass(text, 2)) return false; code = std::move(m_output_buffer); @@ -752,18 +750,11 @@ void DSPAssembler::InitPass(int pass) segment_addr[SEGMENT_OVERLAY] = 0; } -bool DSPAssembler::AssembleFile(const std::string& file_path, int pass) +bool DSPAssembler::AssemblePass(const std::string& text, int pass) { int disable_text = 0; // modified by Hermes - std::ifstream fsrc; - OpenFStream(fsrc, file_path, std::ios_base::in); - - if (fsrc.fail()) - { - std::cerr << "Cannot open file " << file_path << std::endl; - return false; - } + std::istringstream fsrc(text); // printf("%s: Pass %d\n", fname, pass); code_line = 0; @@ -929,7 +920,9 @@ bool DSPAssembler::AssembleFile(const std::string& file_path, int pass) include_file_path = include_dir + '/' + params[0].str; } - AssembleFile(include_file_path, pass); + std::string included_text; + File::ReadFileToString(include_file_path, included_text); + AssemblePass(included_text, pass); code_line = this_code_line; } @@ -952,9 +945,32 @@ bool DSPAssembler::AssembleFile(const std::string& file_path, int pass) if (strcmp("ORG", opcode) == 0) { if (params[0].type == P_VAL) + { + m_totalSize = std::max(m_cur_addr, params[0].val); m_cur_addr = params[0].val; + } else + { ShowError(ERR_EXPECTED_PARAM_VAL); + } + continue; + } + + if (strcmp("WARNPC", opcode) == 0) + { + if (params[0].type == P_VAL) + { + if (m_cur_addr > params[0].val) + { + std::string msg = StringFromFormat("WARNPC at 0x%04x, expected 0x%04x or less", + m_cur_addr, params[0].val); + ShowError(ERR_OUT_RANGE_PC, msg.c_str()); + } + } + else + { + ShowError(ERR_EXPECTED_PARAM_VAL); + } continue; } @@ -1017,9 +1033,6 @@ bool DSPAssembler::AssembleFile(const std::string& file_path, int pass) m_totalSize += opcode_size; }; - if (!failed) - fsrc.close(); - return !failed; } } // namespace DSP diff --git a/Source/Core/Core/DSP/DSPAssembler.h b/Source/Core/Core/DSP/DSPAssembler.h index 1887de09e7..aab86f92e9 100644 --- a/Source/Core/Core/DSP/DSPAssembler.h +++ b/Source/Core/Core/DSP/DSPAssembler.h @@ -42,7 +42,8 @@ enum err_t ERR_WRONG_PARAMETER_ACC, ERR_WRONG_PARAMETER_MID_ACC, ERR_INVALID_REGISTER, - ERR_OUT_RANGE_NUMBER + ERR_OUT_RANGE_NUMBER, + ERR_OUT_RANGE_PC, }; // Unless you want labels to carry over between files, you probably @@ -91,7 +92,7 @@ private: u32 GetParams(char* parstr, param_t* par); void InitPass(int pass); - bool AssembleFile(const std::string& file_path, int pass); + bool AssemblePass(const std::string& text, int pass); void ShowError(err_t err_code, const char* extra_info = nullptr); // void ShowWarning(err_t err_code, const char *extra_info = nullptr); |
