mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-01-09 15:49:25 +01:00
Completely fixed DSPTool, on all of its memory leaks, bad API and bad C++. (compiling with include works perfectly)
More small leftover fixes git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@3071 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
parent
72febe7b8a
commit
1045fc7e98
@ -620,7 +620,7 @@ bool WriteStringToFile(bool text_file, const std::string &str, const char *filen
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ReadFileToString(bool text_file, const char *filename, std::string *str)
|
||||
bool ReadFileToString(bool text_file, const char *filename, std::string &str)
|
||||
{
|
||||
FILE *f = fopen(filename, text_file ? "r" : "rb");
|
||||
if (!f)
|
||||
@ -630,7 +630,7 @@ bool ReadFileToString(bool text_file, const char *filename, std::string *str)
|
||||
fseek(f, 0, SEEK_SET);
|
||||
char *buf = new char[len + 1];
|
||||
buf[fread(buf, 1, len, f)] = 0;
|
||||
*str = std::string(buf, len);
|
||||
str = std::string(buf, len);
|
||||
fclose(f);
|
||||
delete [] buf;
|
||||
return true;
|
||||
|
@ -100,7 +100,7 @@ std::string GetBundleDirectory();
|
||||
#endif
|
||||
|
||||
bool WriteStringToFile(bool text_file, const std::string &str, const char *filename);
|
||||
bool ReadFileToString(bool text_file, const char *filename, std::string *str);
|
||||
bool ReadFileToString(bool text_file, const char *filename, std::string &str);
|
||||
|
||||
} // namespace
|
||||
|
||||
|
@ -226,17 +226,19 @@ void SetLidOpen(bool _bOpen)
|
||||
else
|
||||
dvdMem.CoverReg.Hex = 0x0;
|
||||
|
||||
CPeripheralInterface::SetInterrupt(CPeripheralInterface::INT_CAUSE_DI, true);
|
||||
GenerateDVDInterrupt(INT_CVRINT);
|
||||
|
||||
/*
|
||||
Todo: Make this work perhaps?
|
||||
|
||||
//Todo: Make this work perhaps?
|
||||
/*
|
||||
if (_bOpen)
|
||||
dvdMem.CoverReg.CVR = 1;
|
||||
else
|
||||
dvdMem.CoverReg.CVR = 0;
|
||||
*/
|
||||
|
||||
UpdateInterrupts();
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
bool IsLidOpen()
|
||||
|
@ -15,6 +15,7 @@
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include "Common.h"
|
||||
@ -24,7 +25,7 @@
|
||||
#include "disassemble.h"
|
||||
|
||||
|
||||
bool Assemble(const char *text, std::vector<u16> *code)
|
||||
bool Assemble(const char *text, std::vector<u16> &code)
|
||||
{
|
||||
AssemblerSettings settings;
|
||||
settings.pc = 0;
|
||||
@ -36,14 +37,14 @@ bool Assemble(const char *text, std::vector<u16> *code)
|
||||
// TODO: fix the terrible api of the assembler.
|
||||
DSPAssembler assembler(settings);
|
||||
if (!assembler.Assemble(text, code)) {
|
||||
printf("%s", assembler.GetErrorString().c_str());
|
||||
std::cerr << assembler.GetErrorString() << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Disassemble(const std::vector<u16> &code, bool line_numbers, std::string *text)
|
||||
bool Disassemble(const std::vector<u16> &code, bool line_numbers, std::string &text)
|
||||
{
|
||||
if (code.empty())
|
||||
return false;
|
||||
@ -79,9 +80,9 @@ bool Compare(const std::vector<u16> &code1, const std::vector<u16> &code2)
|
||||
{
|
||||
std::string line1, line2;
|
||||
u16 pc = i;
|
||||
disassembler.DisOpcode(&code1[0], 2, &pc, &line1);
|
||||
disassembler.DisOpcode(&code1[0], 2, &pc, line1);
|
||||
pc = i;
|
||||
disassembler.DisOpcode(&code2[0], 2, &pc, &line2);
|
||||
disassembler.DisOpcode(&code2[0], 2, &pc, line2);
|
||||
printf("!! %04x : %04x vs %04x - %s vs %s\n", i, code1[i], code2[i], line1.c_str(), line2.c_str());
|
||||
}
|
||||
}
|
||||
@ -93,7 +94,7 @@ bool Compare(const std::vector<u16> &code1, const std::vector<u16> &code2)
|
||||
{
|
||||
u16 pc = i;
|
||||
std::string line;
|
||||
disassembler.DisOpcode(&longest[0], 2, &pc, &line);
|
||||
disassembler.DisOpcode(&longest[0], 2, &pc, line);
|
||||
printf("!! %s\n", line.c_str());
|
||||
}
|
||||
}
|
||||
@ -101,64 +102,64 @@ bool Compare(const std::vector<u16> &code1, const std::vector<u16> &code2)
|
||||
return code1.size() == code2.size() && code1.size() == count_equal;
|
||||
}
|
||||
|
||||
void GenRandomCode(int size, std::vector<u16> *code)
|
||||
void GenRandomCode(int size, std::vector<u16> &code)
|
||||
{
|
||||
code->resize(size);
|
||||
code.resize(size);
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
(*code)[i] = rand() ^ (rand() << 8);
|
||||
code[i] = rand() ^ (rand() << 8);
|
||||
}
|
||||
}
|
||||
|
||||
void CodeToHeader(const std::vector<u16> &code, const char *name, std::string *header)
|
||||
void CodeToHeader(const std::vector<u16> &code, const char *name, std::string &header)
|
||||
{
|
||||
std::vector<u16> code_copy = code;
|
||||
// Add some nops at the end to align the size a bit.
|
||||
while (code_copy.size() & 7)
|
||||
code_copy.push_back(0);
|
||||
char buffer[1024];
|
||||
header->clear();
|
||||
header->reserve(code.size() * 4);
|
||||
header->append("#ifndef _MSCVER\n");
|
||||
header.clear();
|
||||
header.reserve(code.size() * 4);
|
||||
header.append("#ifndef _MSCVER\n");
|
||||
sprintf(buffer, "const unsigned short %s[0x1000] = {\n", name);
|
||||
header->append(buffer);
|
||||
header->append("#else\n");
|
||||
header.append(buffer);
|
||||
header.append("#else\n");
|
||||
sprintf(buffer, "const unsigned short %s[0x1000] __attribute__ ((aligned (64))) = {\n", name);
|
||||
header->append(buffer);
|
||||
header->append("#endif\n\n ");
|
||||
header.append(buffer);
|
||||
header.append("#endif\n\n ");
|
||||
for (int i = 0; i < code.size(); i++)
|
||||
{
|
||||
if (i && ((i & 15) == 0))
|
||||
header->append("\n ");
|
||||
header.append("\n ");
|
||||
sprintf(buffer, "0x%04x, ", code[i]);
|
||||
header->append(buffer);
|
||||
header.append(buffer);
|
||||
}
|
||||
header->append("\n};\n");
|
||||
header.append("\n};\n");
|
||||
}
|
||||
|
||||
void CodeToBinaryStringBE(const std::vector<u16> &code, std::string *str)
|
||||
void CodeToBinaryStringBE(const std::vector<u16> &code, std::string &str)
|
||||
{
|
||||
str->resize(code.size() * 2);
|
||||
str.resize(code.size() * 2);
|
||||
for (int i = 0; i < code.size(); i++)
|
||||
{
|
||||
(*str)[i * 2 + 0] = code[i] >> 8;
|
||||
(*str)[i * 2 + 1] = code[i] & 0xff;
|
||||
str[i * 2 + 0] = code[i] >> 8;
|
||||
str[i * 2 + 1] = code[i] & 0xff;
|
||||
}
|
||||
}
|
||||
|
||||
void BinaryStringBEToCode(const std::string &str, std::vector<u16> *code)
|
||||
void BinaryStringBEToCode(const std::string &str, std::vector<u16> &code)
|
||||
{
|
||||
code->resize(str.size() / 2);
|
||||
for (int i = 0; i < code->size(); i++)
|
||||
code.resize(str.size() / 2);
|
||||
for (int i = 0; i < code.size(); i++)
|
||||
{
|
||||
(*code)[i] = ((u16)(u8)str[i * 2 + 0] << 8) | ((u16)(u8)str[i * 2 + 1]);
|
||||
code[i] = ((u16)(u8)str[i * 2 + 0] << 8) | ((u16)(u8)str[i * 2 + 1]);
|
||||
}
|
||||
}
|
||||
|
||||
bool LoadBinary(const char *filename, std::vector<u16> *code)
|
||||
bool LoadBinary(const char *filename, std::vector<u16> &code)
|
||||
{
|
||||
std::string buffer;
|
||||
if (!File::ReadFileToString(false, filename, &buffer))
|
||||
if (!File::ReadFileToString(false, filename, buffer))
|
||||
return false;
|
||||
|
||||
BinaryStringBEToCode(buffer, code);
|
||||
@ -168,7 +169,7 @@ bool LoadBinary(const char *filename, std::vector<u16> *code)
|
||||
bool SaveBinary(const std::vector<u16> &code, const char *filename)
|
||||
{
|
||||
std::string buffer;
|
||||
CodeToBinaryStringBE(code, &buffer);
|
||||
CodeToBinaryStringBE(code, buffer);
|
||||
if (!File::WriteStringToFile(false, buffer, filename))
|
||||
return false;
|
||||
return true;
|
||||
|
@ -23,18 +23,18 @@
|
||||
|
||||
#include "Common.h"
|
||||
|
||||
bool Assemble(const char *text, std::vector<u16> *code);
|
||||
bool Disassemble(const std::vector<u16> &code, bool line_numbers, std::string *text);
|
||||
bool Assemble(const char *text, std::vector<u16> &code);
|
||||
bool Disassemble(const std::vector<u16> &code, bool line_numbers, std::string &text);
|
||||
bool Compare(const std::vector<u16> &code1, const std::vector<u16> &code2);
|
||||
void GenRandomCode(int size, std::vector<u16> *code);
|
||||
void CodeToHeader(const std::vector<u16> &code, const char *name, std::string *header);
|
||||
void GenRandomCode(int size, std::vector<u16> &code);
|
||||
void CodeToHeader(const std::vector<u16> &code, const char *name, std::string &header);
|
||||
|
||||
// Big-endian, for writing straight to file using File::WriteStringToFile.
|
||||
void CodeToBinaryStringBE(const std::vector<u16> &code, std::string *str);
|
||||
void BinaryStringBEToCode(const std::string &str, std::vector<u16> *code);
|
||||
void CodeToBinaryStringBE(const std::vector<u16> &code, std::string &str);
|
||||
void BinaryStringBEToCode(const std::string &str, std::vector<u16> &code);
|
||||
|
||||
// Load code (big endian binary).
|
||||
bool LoadBinary(const char *filename, std::vector<u16> *code);
|
||||
bool LoadBinary(const char *filename, std::vector<u16> &code);
|
||||
bool SaveBinary(const std::vector<u16> &code, const char *filename);
|
||||
|
||||
#endif // _DSPCODEUTIL_H
|
@ -35,7 +35,7 @@ void LabelMap::RegisterDefaults()
|
||||
}
|
||||
}
|
||||
|
||||
void LabelMap::RegisterLabel(const char *label, u16 lval, LabelType type)
|
||||
void LabelMap::RegisterLabel(const std::string &label, u16 lval, LabelType type)
|
||||
{
|
||||
u16 old_value;
|
||||
if (GetLabelValue(label, &old_value) && old_value != lval)
|
||||
@ -47,12 +47,12 @@ void LabelMap::RegisterLabel(const char *label, u16 lval, LabelType type)
|
||||
labels.push_back(label_t(label, lval, type));
|
||||
}
|
||||
|
||||
void LabelMap::DeleteLabel(const char *label)
|
||||
void LabelMap::DeleteLabel(const std::string &label)
|
||||
{
|
||||
for (std::vector<label_t>::iterator iter = labels.begin();
|
||||
iter != labels.end(); ++iter)
|
||||
{
|
||||
if (!strcmp(label, iter->name.c_str()))
|
||||
if (!label.compare(iter->name))
|
||||
{
|
||||
labels.erase(iter);
|
||||
return;
|
||||
@ -60,11 +60,11 @@ void LabelMap::DeleteLabel(const char *label)
|
||||
}
|
||||
}
|
||||
|
||||
bool LabelMap::GetLabelValue(const char *label, u16 *value, LabelType type) const
|
||||
bool LabelMap::GetLabelValue(const std::string &label, u16 *value, LabelType type) const
|
||||
{
|
||||
for (int i = 0; i < labels.size(); i++)
|
||||
{
|
||||
if (!strcmp(labels[i].name.c_str(), label))
|
||||
if (!label.compare(labels[i].name))
|
||||
{
|
||||
if (type & labels[i].type) {
|
||||
*value = labels[i].addr;
|
||||
|
@ -35,7 +35,7 @@ class LabelMap
|
||||
{
|
||||
struct label_t
|
||||
{
|
||||
label_t(const char *lbl, s32 address, LabelType ltype) : name(lbl), addr(address), type(ltype) {}
|
||||
label_t(const std::string &lbl, s32 address, LabelType ltype) : name(lbl), addr(address), type(ltype) {}
|
||||
std::string name;
|
||||
s32 addr;
|
||||
LabelType type;
|
||||
@ -44,10 +44,11 @@ class LabelMap
|
||||
|
||||
public:
|
||||
LabelMap();
|
||||
~LabelMap() { }
|
||||
void RegisterDefaults();
|
||||
void RegisterLabel(const char *label, u16 lval, LabelType type = LABEL_VALUE);
|
||||
void DeleteLabel(const char *label);
|
||||
bool GetLabelValue(const char *label, u16 *value, LabelType type = LABEL_ANY) const;
|
||||
void RegisterLabel(const std::string &label, u16 lval, LabelType type = LABEL_VALUE);
|
||||
void DeleteLabel(const std::string &label);
|
||||
bool GetLabelValue(const std::string &label, u16 *value, LabelType type = LABEL_ANY) const;
|
||||
void Clear();
|
||||
};
|
||||
|
||||
|
@ -37,11 +37,13 @@ Initial import
|
||||
|
||||
====================================================================*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <cstdio>
|
||||
#include <memory.h>
|
||||
#include <stdlib.h>
|
||||
#include <cstdlib>
|
||||
|
||||
#include <map>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
#include "Common.h"
|
||||
#include "FileUtil.h"
|
||||
@ -89,9 +91,10 @@ DSPAssembler::DSPAssembler(const AssemblerSettings &settings) :
|
||||
|
||||
DSPAssembler::~DSPAssembler()
|
||||
{
|
||||
free(gdg_buffer);
|
||||
}
|
||||
|
||||
bool DSPAssembler::Assemble(const char *text, std::vector<u16> *code, std::vector<int> *line_numbers)
|
||||
bool DSPAssembler::Assemble(const char *text, std::vector<u16> &code, std::vector<int> *line_numbers)
|
||||
{
|
||||
if (line_numbers)
|
||||
line_numbers->clear();
|
||||
@ -101,13 +104,25 @@ bool DSPAssembler::Assemble(const char *text, std::vector<u16> *code, std::vecto
|
||||
InitPass(1);
|
||||
if (!AssembleFile(fname, 1))
|
||||
return false;
|
||||
|
||||
// We now have the size of the output buffer
|
||||
if (m_totalSize > 0)
|
||||
{
|
||||
if(gdg_buffer)
|
||||
free(gdg_buffer);
|
||||
|
||||
gdg_buffer = (char *)malloc(m_totalSize * sizeof(u16) + 4);
|
||||
memset(gdg_buffer, 0, m_totalSize * sizeof(u16));
|
||||
} else
|
||||
return false;
|
||||
|
||||
InitPass(2);
|
||||
if (!AssembleFile(fname, 2))
|
||||
return false;
|
||||
|
||||
code->resize(gdg_buffer_size);
|
||||
for (int i = 0; i < gdg_buffer_size; i++) {
|
||||
(*code)[i] = *(u16 *)(gdg_buffer + i * 2);
|
||||
code.resize(m_totalSize);
|
||||
for (int i = 0; i < m_totalSize; i++) {
|
||||
code[i] = *(u16 *)(gdg_buffer + i * 2);
|
||||
}
|
||||
|
||||
last_error_str = "(no errors)";
|
||||
@ -124,10 +139,6 @@ void DSPAssembler::ShowError(err_t err_code, const char *extra_info)
|
||||
buf_ptr += sprintf(buf_ptr, "%i : %s", code_line, cur_line.c_str());
|
||||
if (!extra_info)
|
||||
extra_info = "-";
|
||||
if (fsrc)
|
||||
fclose(fsrc);
|
||||
else
|
||||
buf_ptr += sprintf(buf_ptr, "ERROR: %s : %s\n", err_string[err_code], extra_info);
|
||||
|
||||
if (m_current_param == 0)
|
||||
buf_ptr += sprintf(buf_ptr, "ERROR: %s Line: %d : %s\n", err_string[err_code], code_line, extra_info);
|
||||
@ -724,6 +735,7 @@ void DSPAssembler::InitPass(int pass)
|
||||
aliases["S40"] = "SET40";
|
||||
}
|
||||
m_cur_addr = 0;
|
||||
m_totalSize = 0;
|
||||
cur_segment = SEGMENT_CODE;
|
||||
segment_addr[SEGMENT_CODE] = 0;
|
||||
segment_addr[SEGMENT_DATA] = 0;
|
||||
@ -734,29 +746,29 @@ bool DSPAssembler::AssembleFile(const char *fname, int pass)
|
||||
{
|
||||
int disable_text = 0; // modified by Hermes
|
||||
|
||||
fsrc = fopen(fname, "r");
|
||||
if (fsrc == NULL)
|
||||
std::ifstream fsrc(fname);
|
||||
|
||||
if (fsrc.fail())
|
||||
{
|
||||
fprintf(stderr, "Cannot open %s file\n", fname);
|
||||
std::cerr << "Cannot open file " << fname << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
fseek(fsrc, 0, SEEK_SET);
|
||||
|
||||
printf("%s: Pass %d\n", fname, pass);
|
||||
code_line = 0;
|
||||
m_cur_pass = pass;
|
||||
|
||||
#define LINEBUF_SIZE 1024
|
||||
char linebuffer[LINEBUF_SIZE];
|
||||
while (!failed && !feof(fsrc))
|
||||
char line[LINEBUF_SIZE] = {0};
|
||||
while (!failed && !fsrc.fail() && !fsrc.eof())
|
||||
{
|
||||
int opcode_size = 0;
|
||||
memset(linebuffer, 0, LINEBUF_SIZE);
|
||||
if (!fgets(linebuffer, LINEBUF_SIZE, fsrc))
|
||||
fsrc.getline(line, LINEBUF_SIZE);
|
||||
if(fsrc.fail())
|
||||
break;
|
||||
cur_line = linebuffer;
|
||||
//printf("A: %s", linebuffer);
|
||||
|
||||
cur_line = line;
|
||||
//printf("A: %s\n", line);
|
||||
code_line++;
|
||||
|
||||
param_t params[10] = {{0}};
|
||||
@ -764,16 +776,16 @@ bool DSPAssembler::AssembleFile(const char *fname, int pass)
|
||||
|
||||
for (int i = 0; i < LINEBUF_SIZE; i++)
|
||||
{
|
||||
char c = linebuffer[i];
|
||||
char c = line[i];
|
||||
// This stuff handles /**/ and // comments.
|
||||
// modified by Hermes : added // and /* */ for long commentaries
|
||||
if (c == '/')
|
||||
{
|
||||
if (i < 1023)
|
||||
{
|
||||
if (linebuffer[i+1] == '/')
|
||||
if (line[i+1] == '/')
|
||||
c = 0x00;
|
||||
else if (linebuffer[i+1] == '*')
|
||||
else if (line[i+1] == '*')
|
||||
{
|
||||
// toggle comment mode.
|
||||
disable_text = !disable_text;
|
||||
@ -782,11 +794,11 @@ bool DSPAssembler::AssembleFile(const char *fname, int pass)
|
||||
}
|
||||
else if (c == '*')
|
||||
{
|
||||
if (i < 1023 && linebuffer[i+1] == '/' && disable_text)
|
||||
if (i < 1023 && line[i+1] == '/' && disable_text)
|
||||
{
|
||||
disable_text = 0;
|
||||
c = 32;
|
||||
linebuffer[i + 1] = 32;
|
||||
line[i + 1] = 32;
|
||||
}
|
||||
}
|
||||
|
||||
@ -799,37 +811,35 @@ bool DSPAssembler::AssembleFile(const char *fname, int pass)
|
||||
c = ' ';
|
||||
if (c >= 'a' && c <= 'z') // convert to uppercase
|
||||
c = c - 'a' + 'A';
|
||||
linebuffer[i] = c;
|
||||
line[i] = c;
|
||||
if (c == 0)
|
||||
break; // modified by Hermes
|
||||
}
|
||||
char *ptr = linebuffer;
|
||||
char *ptr = line;
|
||||
|
||||
char *opcode = NULL;
|
||||
char *label = NULL;
|
||||
char *col_ptr;
|
||||
if ((col_ptr = strstr(ptr, ":")) != NULL)
|
||||
std::string label;
|
||||
|
||||
size_t col_pos = std::string(line).find(":");
|
||||
if (col_pos != std::string::npos)
|
||||
{
|
||||
int j;
|
||||
bool valid;
|
||||
j = 0;
|
||||
valid = true;
|
||||
while ((ptr+j) < col_ptr)
|
||||
bool valid = true;
|
||||
|
||||
for(int j = 0; j < (int)col_pos; j++)
|
||||
{
|
||||
if (j == 0)
|
||||
if (!((ptr[j] >= 'A' && ptr[j] <= 'Z') || (ptr[j] == '_')))
|
||||
valid = false;
|
||||
if (!((ptr[j] >= '0' && ptr[j] <= '9') || (ptr[j] >= 'A' && ptr[j] <= 'Z') || (ptr[j] == '_')))
|
||||
valid = false;
|
||||
j++;
|
||||
}
|
||||
if (valid)
|
||||
{
|
||||
label = strtok(ptr, ":\x20");
|
||||
ptr = col_ptr + 1;
|
||||
label = std::string(line).substr(0, col_pos);
|
||||
ptr += col_pos + 1;
|
||||
}
|
||||
}
|
||||
|
||||
char *opcode = NULL;
|
||||
opcode = strtok(ptr, " ");
|
||||
char *opcode_ext = NULL;
|
||||
|
||||
@ -868,7 +878,7 @@ bool DSPAssembler::AssembleFile(const char *fname, int pass)
|
||||
params_count_ext = GetParams(paramstr_ext, params_ext);
|
||||
}
|
||||
|
||||
if (label)
|
||||
if (!label.empty())
|
||||
{
|
||||
// there is a valid label so lets store it in labels table
|
||||
u32 lval = m_cur_addr;
|
||||
@ -893,7 +903,8 @@ bool DSPAssembler::AssembleFile(const char *fname, int pass)
|
||||
if (params[0].type == P_STR)
|
||||
{
|
||||
char *tmpstr;
|
||||
FILE *thisSrc = fsrc;
|
||||
u32 thisCodeline = code_line;
|
||||
|
||||
if (include_dir.size())
|
||||
{
|
||||
tmpstr = (char *)malloc(include_dir.size() + strlen(params[0].str) + 2);
|
||||
@ -904,8 +915,10 @@ bool DSPAssembler::AssembleFile(const char *fname, int pass)
|
||||
tmpstr = (char *)malloc(strlen(params[0].str) + 1);
|
||||
strcpy(tmpstr, params[0].str);
|
||||
}
|
||||
|
||||
AssembleFile(tmpstr, pass);
|
||||
fsrc = thisSrc;
|
||||
|
||||
code_line = thisCodeline;
|
||||
|
||||
free(tmpstr);
|
||||
}
|
||||
@ -986,15 +999,11 @@ bool DSPAssembler::AssembleFile(const char *fname, int pass)
|
||||
}
|
||||
|
||||
m_cur_addr += opcode_size;
|
||||
m_totalSize += opcode_size;
|
||||
};
|
||||
|
||||
if (gdg_buffer == NULL)
|
||||
{
|
||||
gdg_buffer_size = m_cur_addr;
|
||||
gdg_buffer = (char *)malloc(gdg_buffer_size * sizeof(u16) + 4);
|
||||
memset(gdg_buffer, 0, gdg_buffer_size * sizeof(u16));
|
||||
}
|
||||
if (! failed)
|
||||
fclose(fsrc);
|
||||
if (!failed)
|
||||
fsrc.close();
|
||||
|
||||
return !failed;
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ public:
|
||||
// one for each word of code, indicating the source assembler code line number it came from.
|
||||
|
||||
// If returns false, call GetErrorString to get some text to present to the user.
|
||||
bool Assemble(const char *text, std::vector<u16> *code, std::vector<int> *line_numbers = NULL);
|
||||
bool Assemble(const char *text, std::vector<u16> &code, std::vector<int> *line_numbers = NULL);
|
||||
|
||||
std::string GetErrorString() const { return last_error_str; }
|
||||
err_t GetError() const { return last_error; }
|
||||
@ -112,17 +112,16 @@ private:
|
||||
void BuildCode(const opc_t *opc, param_t *par, u32 par_count, u16 *outbuf);
|
||||
|
||||
char *gdg_buffer;
|
||||
int gdg_buffer_size;
|
||||
|
||||
std::string include_dir;
|
||||
std::string cur_line;
|
||||
|
||||
u32 m_cur_addr;
|
||||
int m_totalSize;
|
||||
u8 m_cur_pass;
|
||||
|
||||
LabelMap labels;
|
||||
|
||||
FILE *fsrc;
|
||||
u32 code_line;
|
||||
bool failed;
|
||||
std::string last_error_str;
|
||||
|
@ -72,7 +72,7 @@ DSPDisassembler::~DSPDisassembler()
|
||||
fclose(uo);
|
||||
}
|
||||
|
||||
bool DSPDisassembler::Disassemble(int start_pc, const std::vector<u16> &code, std::string *text)
|
||||
bool DSPDisassembler::Disassemble(int start_pc, const std::vector<u16> &code, std::string &text)
|
||||
{
|
||||
const char *tmp1 = "tmp1.bin";
|
||||
const char *tmp2 = "tmp.txt";
|
||||
@ -187,7 +187,7 @@ static void MakeLowerCase(char *ptr)
|
||||
}
|
||||
}
|
||||
|
||||
void DSPDisassembler::DisOpcode(const u16 *binbuf, int pass, u16 *pc, std::string *dest)
|
||||
void DSPDisassembler::DisOpcode(const u16 *binbuf, int pass, u16 *pc, std::string &dest)
|
||||
{
|
||||
char buffer[256];
|
||||
char *buf = buffer;
|
||||
@ -200,7 +200,7 @@ void DSPDisassembler::DisOpcode(const u16 *binbuf, int pass, u16 *pc, std::strin
|
||||
if ((*pc & 0x7fff) >= 0x1000)
|
||||
{
|
||||
*pc++;
|
||||
dest->append("; outside memory");
|
||||
dest.append("; outside memory");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -318,10 +318,10 @@ void DSPDisassembler::DisOpcode(const u16 *binbuf, int pass, u16 *pc, std::strin
|
||||
*pc += opc->size & ~P_EXT;
|
||||
|
||||
if (pass == 2)
|
||||
dest->append(buffer);
|
||||
dest.append(buffer);
|
||||
}
|
||||
|
||||
bool DSPDisassembler::DisFile(const char* name, int pass, std::string *output)
|
||||
bool DSPDisassembler::DisFile(const char* name, int pass, std::string &output)
|
||||
{
|
||||
FILE* in = fopen(name, "rb");
|
||||
if (in == NULL)
|
||||
@ -342,7 +342,7 @@ bool DSPDisassembler::DisFile(const char* name, int pass, std::string *output)
|
||||
{
|
||||
DisOpcode(binbuf, pass, &pc, output);
|
||||
if (pass == 2)
|
||||
output->append("\n");
|
||||
output.append("\n");
|
||||
}
|
||||
delete [] binbuf;
|
||||
return true;
|
||||
|
@ -63,15 +63,15 @@ public:
|
||||
DSPDisassembler(const AssemblerSettings &settings);
|
||||
~DSPDisassembler();
|
||||
|
||||
bool Disassemble(int start_pc, const std::vector<u16> &code, std::string *text);
|
||||
bool Disassemble(int start_pc, const std::vector<u16> &code, std::string &text);
|
||||
|
||||
// Warning - this one is trickier to use right.
|
||||
// Use pass == 2 if you're just using it by itself.
|
||||
void DisOpcode(const u16 *binbuf, int pass, u16 *pc, std::string *dest);
|
||||
void DisOpcode(const u16 *binbuf, int pass, u16 *pc, std::string &dest);
|
||||
|
||||
private:
|
||||
// Moves PC forward and writes the result to dest.
|
||||
bool DisFile(const char* name, int pass, std::string *output);
|
||||
bool DisFile(const char* name, int pass, std::string &output);
|
||||
|
||||
char* DisParams(const DSPOPCTemplate& opc, u16 op1, u16 op2, char* strbuf);
|
||||
std::map<u16, int> unk_opcodes;
|
||||
|
@ -33,19 +33,19 @@ bool RoundTrip(const std::vector<u16> &code1)
|
||||
{
|
||||
std::vector<u16> code2;
|
||||
std::string text;
|
||||
if (!Disassemble(code1, false, &text))
|
||||
if (!Disassemble(code1, false, text))
|
||||
{
|
||||
printf("RoundTrip: Disassembly failed.\n");
|
||||
return false;
|
||||
}
|
||||
if (!Assemble(text.c_str(), &code2))
|
||||
if (!Assemble(text.c_str(), code2))
|
||||
{
|
||||
printf("RoundTrip: Assembly failed.\n");
|
||||
return false;
|
||||
}
|
||||
if (!Compare(code1, code2))
|
||||
{
|
||||
Disassemble(code1, true, &text);
|
||||
Disassemble(code1, true, text);
|
||||
printf("%s", text.c_str());
|
||||
}
|
||||
return true;
|
||||
@ -57,13 +57,13 @@ bool SuperTrip(const char *asm_code)
|
||||
{
|
||||
std::vector<u16> code1, code2;
|
||||
std::string text;
|
||||
if (!Assemble(asm_code, &code1))
|
||||
if (!Assemble(asm_code, code1))
|
||||
{
|
||||
printf("SuperTrip: First assembly failed\n");
|
||||
return false;
|
||||
}
|
||||
printf("First assembly: %i words\n", (int)code1.size());
|
||||
if (!Disassemble(code1, false, &text))
|
||||
if (!Disassemble(code1, false, text))
|
||||
{
|
||||
printf("SuperTrip: Disassembly failed\n");
|
||||
return false;
|
||||
@ -73,7 +73,7 @@ bool SuperTrip(const char *asm_code)
|
||||
printf("Disass:\n");
|
||||
printf("%s", text.c_str());
|
||||
}
|
||||
if (!Assemble(text.c_str(), &code2))
|
||||
if (!Assemble(text.c_str(), code2))
|
||||
{
|
||||
printf("SuperTrip: Second assembly failed\n");
|
||||
return false;
|
||||
@ -186,7 +186,7 @@ void RunAsmTests()
|
||||
*/
|
||||
|
||||
std::string dsp_test;
|
||||
if (File::ReadFileToString(true, "Testdata/dsp_test.s", &dsp_test))
|
||||
if (File::ReadFileToString(true, "Testdata/dsp_test.s", dsp_test))
|
||||
fail = fail || !SuperTrip(dsp_test.c_str());
|
||||
if (!fail)
|
||||
printf("All passed!\n");
|
||||
@ -256,10 +256,10 @@ int main(int argc, const char *argv[])
|
||||
// Two binary inputs, let's diff.
|
||||
std::string binary_code;
|
||||
std::vector<u16> code1, code2;
|
||||
File::ReadFileToString(false, input_name.c_str(), &binary_code);
|
||||
BinaryStringBEToCode(binary_code, &code1);
|
||||
File::ReadFileToString(false, output_name.c_str(), &binary_code);
|
||||
BinaryStringBEToCode(binary_code, &code2);
|
||||
File::ReadFileToString(false, input_name.c_str(), binary_code);
|
||||
BinaryStringBEToCode(binary_code, code1);
|
||||
File::ReadFileToString(false, output_name.c_str(), binary_code);
|
||||
BinaryStringBEToCode(binary_code, code2);
|
||||
Compare(code1, code2);
|
||||
return 0;
|
||||
}
|
||||
@ -273,10 +273,10 @@ int main(int argc, const char *argv[])
|
||||
}
|
||||
std::string binary_code;
|
||||
std::vector<u16> code;
|
||||
File::ReadFileToString(false, input_name.c_str(), &binary_code);
|
||||
BinaryStringBEToCode(binary_code, &code);
|
||||
File::ReadFileToString(false, input_name.c_str(), binary_code);
|
||||
BinaryStringBEToCode(binary_code, code);
|
||||
std::string text;
|
||||
Disassemble(code, true, &text);
|
||||
Disassemble(code, true, text);
|
||||
if (!output_name.empty())
|
||||
File::WriteStringToFile(true, text, output_name.c_str());
|
||||
else
|
||||
@ -290,26 +290,29 @@ int main(int argc, const char *argv[])
|
||||
return 1;
|
||||
}
|
||||
std::string source;
|
||||
if (File::ReadFileToString(true, input_name.c_str(), &source))
|
||||
if (File::ReadFileToString(true, input_name.c_str(), source))
|
||||
{
|
||||
std::vector<u16> code;
|
||||
if(!Assemble(source.c_str(), &code)) {
|
||||
|
||||
if(!Assemble(source.c_str(), code)) {
|
||||
printf("Assemble: Assembly failed due to errors\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!output_name.empty())
|
||||
{
|
||||
std::string binary_code;
|
||||
CodeToBinaryStringBE(code, &binary_code);
|
||||
CodeToBinaryStringBE(code, binary_code);
|
||||
File::WriteStringToFile(false, binary_code, output_name.c_str());
|
||||
}
|
||||
if (!output_header_name.empty())
|
||||
{
|
||||
std::string header;
|
||||
CodeToHeader(code, output_header_name.c_str(), &header);
|
||||
CodeToHeader(code, output_header_name.c_str(), header);
|
||||
File::WriteStringToFile(true, header, (output_header_name + ".h").c_str());
|
||||
}
|
||||
}
|
||||
source.clear();
|
||||
}
|
||||
|
||||
printf("Assembly completed successfully!\n");
|
||||
|
@ -219,7 +219,7 @@ void DSPDebuggerLLE::RebuildDisAsmListView()
|
||||
|
||||
DSPDisassembler disasm(settings);
|
||||
std::string op_str;
|
||||
disasm.DisOpcode(binbuf, 2, &settings.pc, &op_str);
|
||||
disasm.DisOpcode(binbuf, 2, &settings.pc, op_str);
|
||||
const char* pParameter = NULL;
|
||||
const char* pExtension = NULL;
|
||||
|
||||
|
@ -48,7 +48,7 @@ bool DumpDSPCode(const u8 *code_be, int size_in_bytes, u32 crc)
|
||||
|
||||
// Load the binary back in.
|
||||
std::vector<u16> code;
|
||||
LoadBinary(binFile, &code);
|
||||
LoadBinary(binFile, code);
|
||||
|
||||
AssemblerSettings settings;
|
||||
settings.show_hex = true;
|
||||
@ -59,7 +59,7 @@ bool DumpDSPCode(const u8 *code_be, int size_in_bytes, u32 crc)
|
||||
|
||||
std::string text;
|
||||
DSPDisassembler disasm(settings);
|
||||
if (!disasm.Disassemble(0, code, &text))
|
||||
if (!disasm.Disassemble(0, code, text))
|
||||
return false;
|
||||
|
||||
return File::WriteStringToFile(true, text, txtFile);
|
||||
|
Loading…
x
Reference in New Issue
Block a user