mirror of
https://github.com/SourMesen/Mesen.git
synced 2025-04-02 10:52:48 -04:00
Assembler: Added support for .byte statements
This commit is contained in:
parent
930b4f2641
commit
15bc6c85ac
6 changed files with 45 additions and 26 deletions
|
@ -2,6 +2,7 @@
|
|||
#include <regex>
|
||||
#include <unordered_map>
|
||||
#include "../Utilities/HexUtilities.h"
|
||||
#include "../Utilities/StringUtilities.h"
|
||||
#include "Assembler.h"
|
||||
#include "CPU.h"
|
||||
#include "DisassemblyInfo.h"
|
||||
|
@ -10,25 +11,26 @@
|
|||
static const std::regex instRegex = std::regex("^\\s*([a-z]{3})[*]{0,1}[\\s]*([#]{0,1})([(]{0,1})[\\s]*([$]{0,1})([^,)(;:]*)[\\s]*((,x\\)|\\),y|,x|,y|\\)){0,1})\\s*(;*)(.*)", std::regex_constants::icase);
|
||||
static const std::regex isCommentOrBlank = std::regex("^\\s*([;]+.*$|\\s*$)", std::regex_constants::icase);
|
||||
static const std::regex labelRegex = std::regex("^\\s*([@_a-z][@_a-z0-9]*):(.*)", std::regex_constants::icase);
|
||||
static const std::regex byteRegex = std::regex("^\\s*[.]byte\\s+((\\$[a-f0-9]{1,2},)*)(\\$[a-f0-9]{1,2})+\\s*(;*)(.*)$", std::regex_constants::icase);
|
||||
|
||||
static string opName[256] = {
|
||||
// 0 1 2 3 4 5 6 7 8 9 A B C D E F
|
||||
"BRK", "ORA", "STP", "SLO", "NOP", "ORA", "ASL", "SLO", "PHP", "ORA", "ASL", "ANC", "NOP", "ORA", "ASL", "SLO", //0
|
||||
"BPL", "ORA", "ST1", "SLO", "NOP", "ORA", "ASL", "SLO", "CLC", "ORA", "NOP", "SLO", "NOP", "ORA", "ASL", "SLO", //1
|
||||
"JSR", "AND", "ST2", "RLA", "BIT", "AND", "ROL", "RLA", "PLP", "AND", "ROL", "ANC", "BIT", "AND", "ROL", "RLA", //2
|
||||
"BMI", "AND", "ST3", "RLA", "NOP", "AND", "ROL", "RLA", "SEC", "AND", "NOP", "RLA", "NOP", "AND", "ROL", "RLA", //3
|
||||
"RTI", "EOR", "ST4", "SRE", "NOP", "EOR", "LSR", "SRE", "PHA", "EOR", "LSR", "ALR", "JMP", "EOR", "LSR", "SRE", //4
|
||||
"BVC", "EOR", "ST5", "SRE", "NOP", "EOR", "LSR", "SRE", "CLI", "EOR", "NOP", "SRE", "NOP", "EOR", "LSR", "SRE", //5
|
||||
"RTS", "ADC", "ST6", "RRA", "NOP", "ADC", "ROR", "RRA", "PLA", "ADC", "ROR", "ARR", "JMP", "ADC", "ROR", "RRA", //6
|
||||
"BVS", "ADC", "ST7", "RRA", "NOP", "ADC", "ROR", "RRA", "SEI", "ADC", "NOP", "RRA", "NOP", "ADC", "ROR", "RRA", //7
|
||||
"BPL", "ORA", "STP", "SLO", "NOP", "ORA", "ASL", "SLO", "CLC", "ORA", "NOP", "SLO", "NOP", "ORA", "ASL", "SLO", //1
|
||||
"JSR", "AND", "STP", "RLA", "BIT", "AND", "ROL", "RLA", "PLP", "AND", "ROL", "ANC", "BIT", "AND", "ROL", "RLA", //2
|
||||
"BMI", "AND", "STP", "RLA", "NOP", "AND", "ROL", "RLA", "SEC", "AND", "NOP", "RLA", "NOP", "AND", "ROL", "RLA", //3
|
||||
"RTI", "EOR", "STP", "SRE", "NOP", "EOR", "LSR", "SRE", "PHA", "EOR", "LSR", "ALR", "JMP", "EOR", "LSR", "SRE", //4
|
||||
"BVC", "EOR", "STP", "SRE", "NOP", "EOR", "LSR", "SRE", "CLI", "EOR", "NOP", "SRE", "NOP", "EOR", "LSR", "SRE", //5
|
||||
"RTS", "ADC", "STP", "RRA", "NOP", "ADC", "ROR", "RRA", "PLA", "ADC", "ROR", "ARR", "JMP", "ADC", "ROR", "RRA", //6
|
||||
"BVS", "ADC", "STP", "RRA", "NOP", "ADC", "ROR", "RRA", "SEI", "ADC", "NOP", "RRA", "NOP", "ADC", "ROR", "RRA", //7
|
||||
"NOP", "STA", "NOP", "SAX", "STY", "STA", "STX", "SAX", "DEY", "NOP", "TXA", "XAA", "STY", "STA", "STX", "SAX", //8
|
||||
"BCC", "STA", "ST8", "AHX", "STY", "STA", "STX", "SAX", "TYA", "STA", "TXS", "TAS", "SHY", "STA", "SHX", "AXA", //9
|
||||
"BCC", "STA", "STP", "AHX", "STY", "STA", "STX", "SAX", "TYA", "STA", "TXS", "TAS", "SHY", "STA", "SHX", "AXA", //9
|
||||
"LDY", "LDA", "LDX", "LAX", "LDY", "LDA", "LDX", "LAX", "TAY", "LDA", "TAX", "LAX", "LDY", "LDA", "LDX", "LAX", //A
|
||||
"BCS", "LDA", "ST9", "LAX", "LDY", "LDA", "LDX", "LAX", "CLV", "LDA", "TSX", "LAS", "LDY", "LDA", "LDX", "LAX", //B
|
||||
"BCS", "LDA", "STP", "LAX", "LDY", "LDA", "LDX", "LAX", "CLV", "LDA", "TSX", "LAS", "LDY", "LDA", "LDX", "LAX", //B
|
||||
"CPY", "CMP", "NOP", "DCP", "CPY", "CMP", "DEC", "DCP", "INY", "CMP", "DEX", "AXS", "CPY", "CMP", "DEC", "DCP", //C
|
||||
"BNE", "CMP", "HLT", "DCP", "NOP", "CMP", "DEC", "DCP", "CLD", "CMP", "NOP", "DCP", "NOP", "CMP", "DEC", "DCP", //D
|
||||
"BNE", "CMP", "STP", "DCP", "NOP", "CMP", "DEC", "DCP", "CLD", "CMP", "NOP", "DCP", "NOP", "CMP", "DEC", "DCP", //D
|
||||
"CPX", "SBC", "NOP", "ISC", "CPX", "SBC", "INC", "ISC", "INX", "SBC", "NOP", "SBC", "CPX", "SBC", "INC", "ISC", //E
|
||||
"BEQ", "SBC", "HL2", "ISC", "NOP", "SBC", "INC", "ISC", "SED", "SBC", "NOP", "ISC", "NOP", "SBC", "INC", "ISC" //F
|
||||
"BEQ", "SBC", "STP", "ISC", "NOP", "SBC", "INC", "ISC", "SED", "SBC", "NOP", "ISC", "NOP", "SBC", "INC", "ISC" //F
|
||||
};
|
||||
|
||||
void Assembler::ProcessLine(string code, uint16_t &instructionAddress, vector<int16_t>& output, std::unordered_map<string, uint16_t> &labels)
|
||||
|
@ -45,7 +47,14 @@ void Assembler::ProcessLine(string code, uint16_t &instructionAddress, vector<in
|
|||
|
||||
//Determine if the line is blank, a comment, a label or code
|
||||
std::smatch match;
|
||||
if(std::regex_search(code, match, labelRegex)) {
|
||||
if(std::regex_search(code, match, byteRegex)) {
|
||||
vector<string> bytes = StringUtilities::Split(match.str(1) + match.str(3), ',');
|
||||
for(string &byte : bytes) {
|
||||
output.push_back((uint8_t)(HexUtilities::FromHex(byte.substr(1))));
|
||||
instructionAddress++;
|
||||
}
|
||||
output.push_back(AssemblerSpecialCodes::EndOfLine);
|
||||
} else if(std::regex_search(code, match, labelRegex)) {
|
||||
string label = match.str(1);
|
||||
string afterLabel = match.str(2);
|
||||
int32_t addr = _labelManager->GetLabelRelativeAddress(label);
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "CPU.h"
|
||||
#include "LabelManager.h"
|
||||
#include "../Utilities/HexUtilities.h"
|
||||
#include "../Utilities/StringUtilities.h"
|
||||
#include "Debugger.h"
|
||||
|
||||
Disassembler::Disassembler(uint8_t* internalRam, uint8_t* prgRom, uint32_t prgSize, uint8_t* prgRam, uint32_t prgRamSize, Debugger* debugger)
|
||||
|
@ -241,18 +242,6 @@ void Disassembler::InvalidateCache(uint16_t memoryAddr, int32_t absoluteRamAddr)
|
|||
}
|
||||
}
|
||||
|
||||
vector<string> Disassembler::SplitComment(string input)
|
||||
{
|
||||
vector<string> result;
|
||||
size_t index;
|
||||
while((index = input.find('\n')) != string::npos) {
|
||||
result.push_back(input.substr(0, index));
|
||||
input = input.substr(index + 1, input.size() - index - 1);
|
||||
}
|
||||
result.push_back(input);
|
||||
return result;
|
||||
}
|
||||
|
||||
static const char* hexTable[256] = {
|
||||
"00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "0A", "0B", "0C", "0D", "0E", "0F",
|
||||
"10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "1A", "1B", "1C", "1D", "1E", "1F",
|
||||
|
@ -428,7 +417,7 @@ string Disassembler::GetCode(uint32_t startAddr, uint32_t endAddr, uint16_t memo
|
|||
speculativeCode = false;
|
||||
|
||||
if(commentString.find_first_of('\n') != string::npos) {
|
||||
for(string &str : SplitComment(commentString)) {
|
||||
for(string &str : StringUtilities::Split(commentString, '\n')) {
|
||||
GetLine(commentLines, "", str);
|
||||
}
|
||||
commentString.clear();
|
||||
|
|
|
@ -22,7 +22,6 @@ private:
|
|||
|
||||
bool IsJump(uint8_t opCode);
|
||||
bool IsUnconditionalJump(uint8_t opCode);
|
||||
vector<string> SplitComment(string input);
|
||||
void GetLine(string &out, string code = "", string comment = string(), int32_t cpuAddress = -1, int32_t absoluteAddress = -1);
|
||||
void GetCodeLine(string &out, string &code, string &comment, int32_t cpuAddress, int32_t absoluteAddress, string &byteCode, string &addressing, bool speculativeCode, bool isCode);
|
||||
void GetSubHeader(string &out, DisassemblyInfo *info, string &label, uint16_t relativeAddr, uint16_t resetVector, uint16_t nmiVector, uint16_t irqVector);
|
||||
|
|
18
Utilities/StringUtilities.h
Normal file
18
Utilities/StringUtilities.h
Normal file
|
@ -0,0 +1,18 @@
|
|||
#pragma once
|
||||
#include "stdafx.h"
|
||||
|
||||
class StringUtilities
|
||||
{
|
||||
public:
|
||||
static vector<string> Split(string input, char delimiter)
|
||||
{
|
||||
vector<string> result;
|
||||
size_t index;
|
||||
while((index = input.find(delimiter)) != string::npos) {
|
||||
result.push_back(input.substr(0, index));
|
||||
input = input.substr(index + 1, input.size() - index - 1);
|
||||
}
|
||||
result.push_back(input);
|
||||
return result;
|
||||
}
|
||||
};
|
|
@ -346,6 +346,7 @@
|
|||
<ClInclude Include="Scale2x\scale2x.h" />
|
||||
<ClInclude Include="Scale2x\scale3x.h" />
|
||||
<ClInclude Include="Scale2x\scalebit.h" />
|
||||
<ClInclude Include="StringUtilities.h" />
|
||||
<ClInclude Include="SZReader.h" />
|
||||
<ClInclude Include="UPnPPortMapper.h" />
|
||||
<ClInclude Include="SimpleLock.h" />
|
||||
|
|
|
@ -140,6 +140,9 @@
|
|||
<ClInclude Include="CamstudioCodec.h">
|
||||
<Filter>Avi</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="StringUtilities.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="stdafx.cpp">
|
||||
|
|
Loading…
Add table
Reference in a new issue