Browse Source

adding start of basic asm compiler

master
constantinfuerst 3 years ago
parent
commit
0db706d30d
  1. 10
      cpu_design_and_emulator.sln
  2. 20
      cpu_design_and_emulator/main.cpp
  3. 1
      cpu_design_and_emulator/microprocessor/sdh/sdh.h
  4. 399
      custom_asm_macro_compiler/compiler/compiler.cpp
  5. 94
      custom_asm_macro_compiler/compiler/compiler.h
  6. 185
      custom_asm_macro_compiler/custom_asm_macro_compiler.vcxproj
  7. 36
      custom_asm_macro_compiler/custom_asm_macro_compiler.vcxproj.filters
  8. 6
      custom_asm_macro_compiler/custom_asm_macro_compiler.vcxproj.user
  9. 25
      custom_asm_macro_compiler/main.cpp
  10. 1
      custom_asm_macro_compiler/pch.cpp
  11. 7
      custom_asm_macro_compiler/pch.h

10
cpu_design_and_emulator.sln

@ -7,6 +7,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cpu_design_and_emulator", "
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "xpm_to_ppubytecode", "xpm_to_ppubytecode\xpm_to_ppubytecode.vcxproj", "{DE32A01E-9770-4935-9208-FA707B2A39AD}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "custom_asm_macro_compiler", "custom_asm_macro_compiler\custom_asm_macro_compiler.vcxproj", "{8680365F-7DFF-4466-84B9-4450FC469AF6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
@ -31,6 +33,14 @@ Global
{DE32A01E-9770-4935-9208-FA707B2A39AD}.Release|x64.Build.0 = Release|x64
{DE32A01E-9770-4935-9208-FA707B2A39AD}.Release|x86.ActiveCfg = Release|Win32
{DE32A01E-9770-4935-9208-FA707B2A39AD}.Release|x86.Build.0 = Release|Win32
{8680365F-7DFF-4466-84B9-4450FC469AF6}.Debug|x64.ActiveCfg = Debug|x64
{8680365F-7DFF-4466-84B9-4450FC469AF6}.Debug|x64.Build.0 = Debug|x64
{8680365F-7DFF-4466-84B9-4450FC469AF6}.Debug|x86.ActiveCfg = Debug|Win32
{8680365F-7DFF-4466-84B9-4450FC469AF6}.Debug|x86.Build.0 = Debug|Win32
{8680365F-7DFF-4466-84B9-4450FC469AF6}.Release|x64.ActiveCfg = Release|x64
{8680365F-7DFF-4466-84B9-4450FC469AF6}.Release|x64.Build.0 = Release|x64
{8680365F-7DFF-4466-84B9-4450FC469AF6}.Release|x86.ActiveCfg = Release|Win32
{8680365F-7DFF-4466-84B9-4450FC469AF6}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

20
cpu_design_and_emulator/main.cpp

@ -24,8 +24,8 @@ public:
private:
uint16_t romsize;
uint16_t memsize;
uint16_t memoffset;
uint16_t ramsize;
uint16_t ramoffset;
uint8_t* code;
uint8_t* memory;
@ -68,15 +68,19 @@ public:
};
void computer::initMembers() {
memoffset = 0x0010;
memsize = 0x0800;
const uint16_t stackStart = memsize / 4;
const uint16_t true_memsize = memsize + 1 - memoffset;
const uint16_t romend = 0xffff;
ramoffset = 0x0010;
ramsize = 0x1000;
romsize = romend - ramoffset - ramsize;
const uint16_t stackStart = (ramsize / 4) + ramoffset;
const uint16_t true_memsize = ramsize + 1 - ramoffset;
memory = new uint8_t[true_memsize]{ 0x00 };
const addressRange ramRange(memoffset, memsize - 1);
const addressRange romRange(memsize, memsize + romsize - 1);
const addressRange ramRange(ramoffset, ramsize - 1);
const addressRange romRange(ramsize + ramoffset, romsize);
p_cpu = new cpu(&main_bus, quit, romRange.addrRangeLow, stackStart);
p_ram = new dbgmem_RAM(memory, ramRange);

1
cpu_design_and_emulator/microprocessor/sdh/sdh.h

@ -17,6 +17,7 @@ private:
uint8_t c_green = 0x00;
uint8_t c_blue = 0x00;
};
uint8_t cp_cached = 0x00;
bool cache_valid = false;
std::array<color, 4> c_palette = {0x00, 0x00, 0x00, 0xff, 0xff, 0xff};

399
custom_asm_macro_compiler/compiler/compiler.cpp

@ -0,0 +1,399 @@
#include "pch.h"
#include "compiler.h"
compiler::asmLine* compiler::captureInstrLine(const std::string& instrLine) {
auto* asml = new asmLine;
auto notfound = [&]() { asml->clear(); asml->push_back(std::make_unique<asmPart>(0, opCode)); return asml; };
if (instrLine.size() < 4) return notfound();
//separate argument strings
std::array<std::string, 3> args;
auto pushArg = [&](const std::string& strIn) { for (auto& str : args) { if (str.empty()) { str = strIn; break; }}};
unsigned int arguments = 0;
bool zpoArg = false;
bool relArg = false;
std::stringstream sstr;
for (char& chr : instrLine.substr(4)) {
if (chr == ',' || chr == ';') {
auto str = sstr.str();
auto spc = str.substr(0, 4);
if (spc[0] == '0' && spc[1] == 'f') {
arguments++;
auto arg1 = "0x" + str.substr(2, 2);
auto arg2 = "0x" + str.substr(4, 2);
pushArg(arg1);
pushArg(arg2);
}
else pushArg(str);
if (spc == "zpo:") zpoArg = true;
if (spc == "rel:") relArg = true;
arguments++;
sstr.str(std::string());
}
else if (chr == ' ') continue;
else sstr << chr;
if (chr == ';') break;
}
//acquire opcode
uint8_t opcode = 0x00;
dataType dtype = imp;
bool opcodefound = false;
std::string instrTXT = instrLine.substr(0, 3);
for (auto& instr : *lookupTableINSTR) {
if (instr.opString != instrTXT) continue;
for (auto& data : *lookupTableDATA) {
if (instr.expected != data.dt) continue;
if (data.bcount != arguments) continue;
if (data.zpo != zpoArg) continue;
if (data.rel != relArg) continue;
opcode = instr.opCode;
dtype = instr.expected;
opcodefound = true; break;
}
if (opcodefound == true) break;
}
if (opcode == 0) return notfound();
asml->push_back(std::make_unique<asmPart>(opcode, opCode));
//helper lambdas for conversions and pushing
auto hchrtoi = [&](const char chr) { switch (chr) { case '0': return 0; case '1': return 1; case '2': return 2; case '3': return 3; case '4': return 4; case '5': return 5; case '6': return 6; case '7': return 7; case '8': return 8; case '9': return 9; case 'a': case 'A': return 10; case 'b': case 'B': return 11; case 'c': case 'C': return 12; case 'd': case 'D': return 13; case 'e': case 'E': return 14; case 'f': case 'F': return 15; default: return 0; }};
auto hstrtoi = [&](const std::string& str) { return hchrtoi(str[2]) * 16 + hchrtoi(str[3]);};
auto byteoff = [&](const unsigned int& i) { switch (i) { case 7: return 1; case 6: return 2; case 5: return 4; case 4: return 8; case 3: return 16; case 2: return 32; case 1: return 64; case 0: return 128; default: return 0; }; };
auto bstrtoi = [&](const std::string& str) { int retval = 0x00; for (auto i = 2; i < 10; i++) { if (str[i] == '1') { retval += byteoff(i); }} return retval; };
auto strtoi = [&](const std::string& str) { if (str[0] == '0' && str[1] == 'x') { return hstrtoi(str); } else if (str[0] == '0' && str[1] == 'b') { return bstrtoi(str); } else if (str[0] != '0') { return hstrtoi(str.substr(5, 4)); } else { return std::stoi(str); }};
auto pushToASML = [&](const asmPart& prt) {asml->push_back(std::make_unique<asmPart>(prt)); };
//lambdas to extract arguments
auto getArgVAL = [&]() {
pushToASML({ static_cast<uint8_t>(strtoi(args[0])), value });
};
auto getArgZP0 = [&]() {
pushToASML({ static_cast<uint8_t>(strtoi(args[0])), p0offset });
};
auto getArgABS = [&]() {
pushToASML({ static_cast<uint8_t>(strtoi(args[0])), addressLO });
pushToASML({ static_cast<uint8_t>(strtoi(args[1])), addressHI });
};
auto getArgDAV = [&]() {
pushToASML({ static_cast<uint8_t>(strtoi(args[0])), addressLO });
pushToASML({ static_cast<uint8_t>(strtoi(args[1])), addressHI });
pushToASML({ static_cast<uint8_t>(strtoi(args[2])), value });
};
auto getArgDZV = [&]() {
pushToASML({ static_cast<uint8_t>(strtoi(args[0])), p0offset });
pushToASML({ static_cast<uint8_t>(strtoi(args[1])), value });
};
auto getArgDRV = [&]() {
pushToASML({ static_cast<uint8_t>(strtoi(args[0])), relative });
pushToASML({ static_cast<uint8_t>(strtoi(args[1])), value });
};
auto getArgREL = [&]() {
pushToASML({ static_cast<uint8_t>(strtoi(args[0])), relative });
};
//switch to select the correct lambda
switch (dtype) {
case val: getArgVAL(); break;
case zpo: getArgZP0(); break;
case abs: getArgABS(); break;
case dav: getArgDAV(); break;
case dzv: getArgDZV(); break;
case drv: getArgDRV(); break;
case rel: getArgREL(); break;
default: break;
}
return asml;
}
compiler::compiler() {
lookupTableDATA = new std::array<dataTranslate, 8> {
dataTranslate{imp, 0, {emptyP, emptyP, emptyP}, false, false},
dataTranslate{val, 1, {asmVal, emptyP, emptyP}, false, false},
dataTranslate{zpo, 1, {asmP0off, emptyP, emptyP}, true, false},
dataTranslate{abs, 2, {asmAddrLO, asmAddrHI, emptyP}, false, false},
dataTranslate{dav, 3, {asmAddrLO, asmAddrHI, asmVal}, false, false},
dataTranslate{dzv, 2, {asmP0off, asmVal, emptyP}, true, false},
dataTranslate{drv, 2, {asmRel, asmVal, emptyP}, false, true},
dataTranslate{rel, 1, {asmRel, emptyP, emptyP}, false, true}
};
lookupTableINSTR = new std::array<instruction, 256> {
instruction(0x00,"NOP", imp),
instruction(0x01,"NOP", imp),
instruction(0x02,"CLC", imp),
instruction(0x03,"CLO", imp),
instruction(0x04,"CLD", imp),
instruction(0x05,"CLI", imp),
instruction(0x06,"NOP", imp),
instruction(0x07,"BRK", val),
instruction(0x08,"BRT", imp),
instruction(0x09,"NOP", imp),
instruction(0x0a,"PUS", imp),
instruction(0x0b,"POP", imp),
instruction(0x0c,"NOP", imp),
instruction(0x0d,"SET", val),
instruction(0x0e,"SET", zpo),
instruction(0x0f,"SET", abs),
instruction(0x10,"MOV", dav),
instruction(0x11,"MOV", abs),
instruction(0x12,"MOV", zpo),
instruction(0x13,"NOP", imp),
instruction(0x14,"NOP", imp),
instruction(0x15,"NOP", imp),
instruction(0x16,"NOP", imp),
instruction(0x17,"MSR", abs),
instruction(0x18,"NOP", imp),
instruction(0x19,"NOP", imp),
instruction(0x1a,"NOP", imp),
instruction(0x1b,"NOP", imp),
instruction(0x1c,"JJR", imp),
instruction(0x1d,"MJL", imp),
instruction(0x1e,"MJH", imp),
instruction(0x1f,"MOV", dzv),
instruction(0x20,"LOD", abs),
instruction(0x21,"LOD", zpo),
instruction(0x22,"LDA", zpo),
instruction(0x23,"LD1", imp),
instruction(0x24,"NOP", imp),
instruction(0x25,"NOP", imp),
instruction(0x26,"NOP", imp),
instruction(0x27,"NOP", imp),
instruction(0x28,"NOP", imp),
instruction(0x29,"MUL", abs),
instruction(0x2a,"NOP", imp),
instruction(0x2b,"MUL", imp),
instruction(0x2c,"NOP", imp),
instruction(0x2d,"NOP", imp),
instruction(0x2e,"NOP", imp),
instruction(0x2f,"NOP", imp),
instruction(0x30,"ADC", val),
instruction(0x31,"ADC", abs),
instruction(0x32,"AC1", imp),
instruction(0x33,"ADC", zpo),
instruction(0x34,"SBC", val),
instruction(0x35,"SBC", abs),
instruction(0x36,"SC1", imp),
instruction(0x37,"SBC", zpo),
instruction(0x38,"INT", val),
instruction(0x39,"DET", val),
instruction(0x3a,"IN1", imp),
instruction(0x3b,"NOP", imp),
instruction(0x3c,"DE1", imp),
instruction(0x3d,"NOP", imp),
instruction(0x3e,"INR", abs),
instruction(0x3f,"DER", abs),
instruction(0x40,"JMP", abs),
instruction(0x41,"JPR", abs),
instruction(0x42,"BOE", dav),
instruction(0x43,"NOP", imp),
instruction(0x44,"NOP", imp),
instruction(0x45,"BNE", dav),
instruction(0x46,"NOP", imp),
instruction(0x47,"NOP", imp),
instruction(0x48,"RET", imp),
instruction(0x49,"NOP", imp),
instruction(0x4a,"NOP", imp),
instruction(0x4b,"NOP", imp),
instruction(0x4c,"NOP", imp),
instruction(0x4d,"NOP", imp),
instruction(0x4e,"NOP", imp),
instruction(0x4f,"NOP", imp),
instruction(0x50,"BOE", drv),
instruction(0x51,"BNE", drv),
instruction(0x52,"BRE", rel),
instruction(0x53,"BRN", rel),
instruction(0x54,"NOP", imp),
instruction(0x55,"NOP", imp),
instruction(0x56,"NOP", imp),
instruction(0x57,"NOP", imp),
instruction(0x58,"NOP", imp),
instruction(0x59,"NOP", imp),
instruction(0x5a,"NOP", imp),
instruction(0x5b,"NOP", imp),
instruction(0x5c,"BLM", abs),
instruction(0x5d,"BRM", abs),
instruction(0x5e,"BSL", val),
instruction(0x5f,"BSR", val),
instruction(0x60,"CMP", val),
instruction(0x61,"CP1", val),
instruction(0x62,"CP2", val),
instruction(0x63,"NOP", imp),
instruction(0x64,"NOP", imp),
instruction(0x65,"NOP", imp),
instruction(0x66,"NOP", imp),
instruction(0x67,"NOP", imp),
instruction(0x68,"NOP", imp),
instruction(0x69,"RSR", val),
instruction(0x6a,"NOP", imp),
instruction(0x6b,"NOP", imp),
instruction(0x6c,"NOP", imp),
instruction(0x6d,"NOP", imp),
instruction(0x6e,"NOP", imp),
instruction(0x6f,"NOP", imp),
instruction(0x70,"PPU", dav),
instruction(0x71,"POX", val),
instruction(0x72,"POY", val),
instruction(0x73,"NOP", imp),
instruction(0x74,"NOP", imp),
instruction(0x75,"NOP", imp),
instruction(0x76,"NOP", imp),
instruction(0x77,"NOP", imp),
instruction(0x78,"NOP", imp),
instruction(0x79,"NOP", imp),
instruction(0x7a,"NOP", imp),
instruction(0x7b,"NOP", imp),
instruction(0x7c,"NOP", imp),
instruction(0x7d,"NOP", imp),
instruction(0x7e,"NOP", imp),
instruction(0x7f,"NOP", imp),
instruction(0x80,"NOP", imp),
instruction(0x81,"NOP", imp),
instruction(0x82,"NOP", imp),
instruction(0x83,"NOP", imp),
instruction(0x84,"NOP", imp),
instruction(0x85,"NOP", imp),
instruction(0x86,"NOP", imp),
instruction(0x87,"NOP", imp),
instruction(0x88,"NOP", imp),
instruction(0x89,"NOP", imp),
instruction(0x8a,"NOP", imp),
instruction(0x8b,"NOP", imp),
instruction(0x8c,"NOP", imp),
instruction(0x8d,"NOP", imp),
instruction(0x8e,"NOP", imp),
instruction(0x8f,"NOP", imp),
instruction(0x90,"NOP", imp),
instruction(0x91,"NOP", imp),
instruction(0x92,"NOP", imp),
instruction(0x93,"NOP", imp),
instruction(0x94,"NOP", imp),
instruction(0x95,"NOP", imp),
instruction(0x96,"NOP", imp),
instruction(0x97,"NOP", imp),
instruction(0x98,"NOP", imp),
instruction(0x99,"NOP", imp),
instruction(0x9a,"NOP", imp),
instruction(0x9b,"NOP", imp),
instruction(0x9c,"NOP", imp),
instruction(0x9d,"NOP", imp),
instruction(0x9e,"NOP", imp),
instruction(0x9f,"NOP", imp),
instruction(0xa0,"NOP", imp),
instruction(0xa1,"NOP", imp),
instruction(0xa2,"NOP", imp),
instruction(0xa3,"NOP", imp),
instruction(0xa4,"NOP", imp),
instruction(0xa5,"NOP", imp),
instruction(0xa6,"NOP", imp),
instruction(0xa7,"NOP", imp),
instruction(0xa8,"NOP", imp),
instruction(0xa9,"NOP", imp),
instruction(0xaa,"NOP", imp),
instruction(0xab,"NOP", imp),
instruction(0xac,"NOP", imp),
instruction(0xad,"NOP", imp),
instruction(0xae,"NOP", imp),
instruction(0xaf,"NOP", imp),
instruction(0xb0,"NOP", imp),
instruction(0xb1,"NOP", imp),
instruction(0xb2,"NOP", imp),
instruction(0xb3,"NOP", imp),
instruction(0xb4,"NOP", imp),
instruction(0xb5,"NOP", imp),
instruction(0xb6,"NOP", imp),
instruction(0xb7,"NOP", imp),
instruction(0xb8,"NOP", imp),
instruction(0xb9,"NOP", imp),
instruction(0xba,"NOP", imp),
instruction(0xbb,"NOP", imp),
instruction(0xbc,"NOP", imp),
instruction(0xbd,"NOP", imp),
instruction(0xbe,"NOP", imp),
instruction(0xbf,"NOP", imp),
instruction(0xc0,"NOP", imp),
instruction(0xc1,"NOP", imp),
instruction(0xc2,"NOP", imp),
instruction(0xc3,"NOP", imp),
instruction(0xc4,"NOP", imp),
instruction(0xc5,"NOP", imp),
instruction(0xc6,"NOP", imp),
instruction(0xc7,"NOP", imp),
instruction(0xc8,"NOP", imp),
instruction(0xc9,"NOP", imp),
instruction(0xca,"NOP", imp),
instruction(0xcb,"NOP", imp),
instruction(0xcc,"NOP", imp),
instruction(0xcd,"NOP", imp),
instruction(0xce,"NOP", imp),
instruction(0xcf,"NOP", imp),
instruction(0xd0,"NOP", imp),
instruction(0xd1,"NOP", imp),
instruction(0xd2,"NOP", imp),
instruction(0xd3,"NOP", imp),
instruction(0xd4,"NOP", imp),
instruction(0xd5,"NOP", imp),
instruction(0xd6,"NOP", imp),
instruction(0xd7,"NOP", imp),
instruction(0xd8,"NOP", imp),
instruction(0xd9,"NOP", imp),
instruction(0xda,"NOP", imp),
instruction(0xdb,"NOP", imp),
instruction(0xdc,"NOP", imp),
instruction(0xdd,"NOP", imp),
instruction(0xde,"NOP", imp),
instruction(0xdf,"NOP", imp),
instruction(0xe0,"NOP", imp),
instruction(0xe1,"NOP", imp),
instruction(0xe2,"NOP", imp),
instruction(0xe3,"NOP", imp),
instruction(0xe4,"NOP", imp),
instruction(0xe5,"NOP", imp),
instruction(0xe6,"NOP", imp),
instruction(0xe7,"NOP", imp),
instruction(0xe8,"NOP", imp),
instruction(0xe9,"NOP", imp),
instruction(0xea,"NOP", imp),
instruction(0xeb,"NOP", imp),
instruction(0xec,"NOP", imp),
instruction(0xed,"NOP", imp),
instruction(0xee,"NOP", imp),
instruction(0xef,"NOP", imp),
instruction(0xf0,"OUT", val),
instruction(0xf1,"END", imp),
instruction(0xf2,"NOP", imp),
instruction(0xf3,"NOP", imp),
instruction(0xf4,"NOP", imp),
instruction(0xf5,"NOP", imp),
instruction(0xf6,"NOP", imp),
instruction(0xf7,"NOP", imp),
instruction(0xf8,"NOP", imp),
instruction(0xf9,"NOP", imp),
instruction(0xfa,"NOP", imp),
instruction(0xfb,"NOP", imp),
instruction(0xfc,"NOP", imp),
instruction(0xfd,"NOP", imp),
instruction(0xfe,"NOP", imp),
instruction(0xff,"NOP", imp),
};
}

94
custom_asm_macro_compiler/compiler/compiler.h

@ -0,0 +1,94 @@
#pragma once
#include "pch.h"
class compiler final {
private:
//statements for automated data arrangement
uint16_t codeLocationZeroOffset = 0x1000;
uint16_t paletteStart = 0x0000;
uint16_t segmentStart = 0x0000;
uint16_t programStart = 0x0000;
enum byteUse { emptyByte, opCode, addressLO, addressHI, value, relative, p0offset, storage };
enum blockUse { emptyBlock, instr, paletteDeclaration, segmentDeclaration };
enum dataType { imp, val, zpo, abs, dav, dzv, drv, rel };
enum asmParameter { emptyP, asmInstr, asmVal, asmAddrLO, asmAddrHI, asmP0off, asmRel };
struct byte {
uint8_t data;
byteUse use = emptyByte;
byte(const uint8_t& d, const byteUse& u) { data = d; use = u; }
};
struct block {
typedef std::unique_ptr<std::vector<byte>> dvec;
dvec data;
blockUse use = emptyBlock;
block(dvec d, const blockUse& u) { data.swap(d); use = u; }
};
struct collection {
typedef std::unique_ptr<std::vector<uint8_t>> dvec;
dvec data;
blockUse use;
collection(dvec d, const blockUse& u) { data.swap(d); use = u; }
collection() { data = nullptr; use = emptyBlock; }
};
struct asmPart {
uint8_t data;
byteUse use;
asmPart(const uint8_t& d, const byteUse& u) { data = d; use = u; }
};
struct instruction {
uint8_t opCode;
std::string opString;
dataType expected;
instruction(const uint8_t& b, const std::string& str, const dataType& d) { opCode = b; opString = str; expected = d; }
instruction() { opCode = 0x00; opString = ""; expected = imp; }
};
typedef std::vector<std::unique_ptr<asmPart>> asmLine;
typedef std::array<std::array<uint8_t, 3>, 4> palette;
typedef std::array<uint8_t, 16> segment;
typedef std::array<asmParameter, 3> dataTriplet;
struct dataTranslate { dataType dt = imp; unsigned int bcount = 0; dataTriplet trip = { emptyP }; bool zpo = false; bool rel = false; };
std::array<dataTranslate, 8>* lookupTableDATA;
std::array<instruction, 256>* lookupTableINSTR;
collection segments;
collection palettes;
std::vector<block*> code;
//pre-processor functions
//block* handleMacro(const std::string& macroName, const int& input);
//compiler functions
asmLine* captureInstrLine(const std::string& instrLine);
//block* translateASM(asmLine* asml);
//void appendBlock(block* bptr);
//post-processor
//void appendPalette(const palette& p);
//void appendSegment(const segment& s);
//void implementBootSector();
public:
compiler();
std::vector<std::string>* test(const std::string& test_string) {
auto* v = new std::vector<std::string>;
auto* t = captureInstrLine(test_string);
std::stringstream ss;
for (auto& b : *t) {
int d = (*b).data;
ss << "0x";
if (d < 16) ss << "0";
ss << std::hex << d;
std::cout << ss.str() << std::endl;
v->push_back(ss.str());
}
delete t;
return v;
}
//void loadFile(const std::string& ifname);
//void convertFile();
//void storeConversion(const std::string& ofname);
};

185
custom_asm_macro_compiler/custom_asm_macro_compiler.vcxproj

@ -0,0 +1,185 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<ProjectGuid>{8680365f-7dff-4466-84b9-4450fc469af6}</ProjectGuid>
<RootNamespace>custom_asm_macro_compiler</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>$(SolutionDir)build\debug\x86-32\</OutDir>
<IntDir>$(SolutionDir)build\int\debug\x86-32\</IntDir>
<TargetName>$(ProjectName)-d32</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>$(SolutionDir)build\release\x86-32\</OutDir>
<IntDir>$(SolutionDir)build\int\release\x86-32\</IntDir>
<TargetName>$(ProjectName)-r32</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<OutDir>$(SolutionDir)build\debug\x86-64\</OutDir>
<IntDir>$(SolutionDir)build\int\debug\x86-64\</IntDir>
<TargetName>$(ProjectName)-d64</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<OutDir>$(SolutionDir)build\release\x86-64\</OutDir>
<IntDir>$(SolutionDir)build\int\release\x86-64\</IntDir>
<TargetName>$(ProjectName)-r64</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
<AdditionalIncludeDirectories>$(ProjectDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
<AdditionalIncludeDirectories>$(ProjectDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
<AdditionalIncludeDirectories>$(ProjectDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<OmitFramePointers>true</OmitFramePointers>
<EnableFiberSafeOptimizations>true</EnableFiberSafeOptimizations>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
<AdditionalIncludeDirectories>$(ProjectDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<OmitFramePointers>true</OmitFramePointers>
<EnableFiberSafeOptimizations>true</EnableFiberSafeOptimizations>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="compiler\compiler.cpp" />
<ClCompile Include="main.cpp" />
<ClCompile Include="pch.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="compiler\compiler.h" />
<ClInclude Include="pch.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

36
custom_asm_macro_compiler/custom_asm_macro_compiler.vcxproj.filters

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="pch.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="compiler\compiler.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="pch.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="compiler\compiler.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

6
custom_asm_macro_compiler/custom_asm_macro_compiler.vcxproj.user

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ShowAllFiles>true</ShowAllFiles>
</PropertyGroup>
</Project>

25
custom_asm_macro_compiler/main.cpp

@ -0,0 +1,25 @@
#include "pch.h"
#include "compiler/compiler.h"
/*
*
* ASM LINE SYNTAX:
* [3 chars opcode][1 space][arg1][comma][1 space][arg2][comma][1 space][arg3][semicolon]
*
* number types supported:
* 1) "rel:" and "zpo:" -> 0xZZ only
* 2) 0b00000000
* 3) 0xZZ
* 4) cases supporting abs -> 0fZZZZ
*
* special ident:
* 1) every zero page offset 0xOO has to be transformed into zpo:0xOO
* 2) every relative jump 0xRR has to be transformed into rel:0xRR
*
*/
int main() {
compiler c;
auto v = c.test("JMP 0f0102;");
return 0;
}

1
custom_asm_macro_compiler/pch.cpp

@ -0,0 +1 @@
#include "pch.h"

7
custom_asm_macro_compiler/pch.h

@ -0,0 +1,7 @@
#pragma once
#include <iostream>
#include <vector>
#include <cstdint>
#include <array>
#include <sstream>
Loading…
Cancel
Save