Browse Source

implementing color palette check

checks every segment in multi-file-mode and adjusts its colors according to changes made to the color palette during loading and converting files with different color configuration but same or compatible colors
master
constantinfuerst 3 years ago
parent
commit
6926e0f560
  1. BIN
      .vs/cpu_design_and_emulator/v16/Solution.VC.db-shm
  2. BIN
      .vs/cpu_design_and_emulator/v16/Solution.VC.db-wal
  3. 1
      custom_asm_macro_compiler/compiler/compiling/wrappers.cpp
  4. 14
      custom_asm_macro_compiler/compiler/decompiling/decompiler.cpp
  5. 1
      custom_asm_macro_compiler/compiler/decompiling/decompiler.h
  6. 11
      program_data/execute_compile-exec.bat
  7. 9
      program_data/execute_compile.bat
  8. 9
      program_data/execute_convert.bat
  9. 3
      program_data/execute_exec.bat
  10. 0
      program_data/execute_full.bat
  11. 5
      program_data/test.txt
  12. 25
      program_data/testDECOMPILED.txt
  13. BIN
      program_data/testOUTPUT.bin
  14. 4
      xpm_to_ppubytecode/converter/converter.cpp
  15. 4
      xpm_to_ppubytecode/converter/converter.h
  16. 4
      xpm_to_ppubytecode/main.cpp
  17. 35
      xpm_to_ppubytecode/reader/reader.cpp
  18. 3
      xpm_to_ppubytecode/reader/reader.h

BIN
.vs/cpu_design_and_emulator/v16/Solution.VC.db-shm

BIN
.vs/cpu_design_and_emulator/v16/Solution.VC.db-wal

1
custom_asm_macro_compiler/compiler/compiling/wrappers.cpp

@ -1,7 +1,6 @@
#include "pch.h"
#include "../compiler.h"
void compiler::assembleProgram() {
for (size_t i = 0; i < functions.size(); i++) {
cdef::function* f = functions[i];

14
custom_asm_macro_compiler/compiler/decompiling/decompiler.cpp

@ -46,10 +46,20 @@ void decompiler::processFile() {
auto pushString = [&]() {
instrText->push_back(current.str()); current.str("");
};
auto checkCodeEnd = [&]() {
if (instr == 0x1f && data.front() == 0x04)
codeEnd = (codeEnd & 0xff00) + data.back();
if (instr == 0x1f && data.front() == 0x05)
codeEnd = (codeEnd & 0x00ff) + (data.back() << 8);
};
for (auto& byte : *binptr) {
if (instrLength == 0) {
processQueue(); pushString(); setLength(byte);
uint16_t currentLine = lineCounter - 16 + 4112;
if (codeEnd != 0 && currentLine == codeEnd) {
processQueue(); pushString(); break;
}
else if (instrLength == 0) {
checkCodeEnd(); processQueue(); pushString(); setLength(byte);
}
else {
data.push(byte); instrLength--;

1
custom_asm_macro_compiler/compiler/decompiling/decompiler.h

@ -8,6 +8,7 @@ private:
std::vector<uint8_t>* binptr = nullptr;
std::vector<std::string>* instrText = nullptr;
unsigned int lineCounter = 16;
uint16_t codeEnd = 0;
void readFile(const std::string& binFile);
void processFile();

11
program_data/execute_compile-exec.bat

@ -0,0 +1,11 @@
@echo off
C:\Projects\cpu_design_and_emulator\build\debug\x86-64\build\ASM\custom_asm_macro_compiler-d64.exe
:loop2
timeout /t 1 /nobreak >nul 2>&1
tasklist | find /i "prog2.exe" >nul 2>&1
if errorlevel 1 goto cont2
goto loop2
:cont2
start "cpu" "C:\Projects\cpu_design_and_emulator\build\debug\x86-64\build\CPU\cpudesign-d64.exe"

9
program_data/execute_compile.bat

@ -0,0 +1,9 @@
@echo off
C:\Projects\cpu_design_and_emulator\build\debug\x86-64\build\ASM\custom_asm_macro_compiler-d64.exe
:loop2
timeout /t 1 /nobreak >nul 2>&1
tasklist | find /i "prog2.exe" >nul 2>&1
if errorlevel 1 goto cont2
goto loop2
:cont2

9
program_data/execute_convert.bat

@ -0,0 +1,9 @@
@echo off
C:\Projects\cpu_design_and_emulator\build\debug\x86-64\build\XPM\xpmtobyte-d64.exe
:loop1
timeout /t 1 /nobreak >nul 2>&1
tasklist | find /i "prog1.exe" >nul 2>&1
if errorlevel 1 goto cont1
goto loop1
:cont1

3
program_data/execute_exec.bat

@ -0,0 +1,3 @@
@echo off
start "cpu" "C:\Projects\cpu_design_and_emulator\build\debug\x86-64\build\CPU\cpudesign-d64.exe"

0
program_data/redo.bat → program_data/execute_full.bat

5
program_data/test.txt

@ -1,2 +1,5 @@
includeImageFile(C:\Projects\cpu_design_and_emulator\program_data\segment_number_one.json);
PPU 0x12, 0x1a, 0x00;
PPU 0x12, 0x1a, 0x00;
PPU 0x12, 0x1b, 0x01;
PPU 0x12, 0x1c, 0x02;
PPU 0x12, 0x1d, 0x03;

25
program_data/testDECOMPILED.txt

@ -1,24 +1,11 @@
4112 | 1010: MOV 0x02, 0x2a
4112 | 1010: MOV 0x02, 0x3c
4115 | 1013: MOV 0x03, 0x10
4118 | 1016: MOV 0x04, 0x24
4118 | 1016: MOV 0x04, 0x30
4121 | 1019: MOV 0x05, 0x10
4124 | 101c: JMP 0x1f, 0x10
4127 | 101f: PPU 0x12, 0x1a, 0x00
4131 | 1023: END
4132 | 1024: NOP
4133 | 1025: NOP
4134 | 1026: NOP
4135 | 1027: NOP
4136 | 1028: NOP
4137 | 1029: NOP
4138 | 102a: NOP
4139 | 102b: NOP
4140 | 102c: NOP
4141 | 102d: NOP
4142 | 102e: BOE 0x55, 0x10
4145 | 1031: CLD
4146 | 1032: MOV 0x04, 0x50, 0x05
4150 | 1036: CLD
4151 | 1037: NOP
4152 | 1038: NOP
4131 | 1023: PPU 0x12, 0x1b, 0x01
4135 | 1027: PPU 0x12, 0x1c, 0x02
4139 | 102b: PPU 0x12, 0x1d, 0x03
4143 | 102f: END

BIN
program_data/testOUTPUT.bin

4
xpm_to_ppubytecode/converter/converter.cpp

@ -150,13 +150,13 @@ unsigned int converter::convertColors(const char& num) {
}
bool converter::colorStr::operator==(const colorStr& comp) const {
if (r == comp.r || g == comp.g || b == comp.b)
if (r == comp.r && g == comp.g && b == comp.b)
return true;
return false;
}
bool converter::colorStr::operator!=(const colorStr& comp) const {
if (r == comp.r || g == comp.g || b == comp.b)
if (r == comp.r && g == comp.g && b == comp.b)
return false;
return true;
}

4
xpm_to_ppubytecode/converter/converter.h

@ -31,13 +31,13 @@ private:
unsigned int convertColors(const char& colorSelector);
std::array<char, 2> checkPixel(const char& colorSelector);
void readColor(const std::string& line, const unsigned int& counter);
unsigned int translateHex(const char& num);
unsigned int getColorVal(const colorStr& color);
static unsigned int translateHex(const char& num);
void readPixel(const std::string& line, const unsigned int& counter);
void sortColors();
public:
static unsigned int getColorVal(const colorStr& color);
converter::bytecode* processXPM();
void setFSTR(std::fstream* fsptr);
converter(std::fstream* fsptr);

4
xpm_to_ppubytecode/main.cpp

@ -4,9 +4,9 @@
int main() {
reader xpmtobyte("C:\\Projects\\cpu_design_and_emulator\\program_data\\segment_number_one.json");
//xpmtobyte.readFolder("C:\\Projects\\cpu_design_and_emulator\\program_data\\xpm_files\\");
xpmtobyte.readFolder("C:\\Projects\\cpu_design_and_emulator\\program_data\\xpm_files\\");
//xpmtobyte.readFile("C:\\Projects\\cpu_design_and_emulator\\program_data\\xpm_files\\segment_1cols.xpm");
xpmtobyte.readFile("C:\\Projects\\cpu_design_and_emulator\\program_data\\xpm_files\\segment_2cols.xpm");
//xpmtobyte.readFile("C:\\Projects\\cpu_design_and_emulator\\program_data\\xpm_files\\segment_2cols.xpm");
//xpmtobyte.readFile("C:\\Projects\\cpu_design_and_emulator\\program_data\\xpm_files\\segment_3cols.xpm");
//xpmtobyte.readFile("C:\\Projects\\cpu_design_and_emulator\\program_data\\xpm_files\\segment_4cols.xpm");
}

35
xpm_to_ppubytecode/reader/reader.cpp

@ -27,6 +27,8 @@ void reader::translate(converter::bytecode* bcode, const std::string& fname) {
}
void reader::outputPalette(const std::array<converter::colorStr, 4>& colors) {
segment_cprofiles.push_back(colors);
currentProfile = colors;
unsigned int counter = 0;
for (auto& c : colors)
if (c.ident != '-') {
@ -83,5 +85,38 @@ void reader::readFolder(const std::string& fname) {
translate(files[i], fileNames[i]);
}
correctColorProfiles();
writeOutput();
}
void reader::correctColorProfiles() {
auto getSTR = [&](unsigned int i) { switch (i) {case 0: return "00"; case 1: return "01"; case 2: return "10"; case 3: return "11"; default: return "00";}};
auto segs = out["segments"]["count"].get<unsigned int>();
for (unsigned int i = 0; i < segs; i++) {
const auto ident = "segment_" + std::to_string(i);
auto segment = out["segments"][ident].get<std::array<std::string, 16>>();
unsigned int counter = 0;
for (auto j = 0; j < 4; j++) {
const auto& segcol = segment_cprofiles[i][j];
const auto& colj = currentProfile[j];
if (segcol.ident == '-') continue;
if (segcol != colj) {
for (auto k = 0; k < 4; k++) {
const auto& colk = currentProfile[k];
if (segcol == colk) {
const std::string find = getSTR(j), replace = getSTR(k);
for (auto& str : segment) {
for (unsigned int l = 2; l < 10; l += 2) {
if (str[l] == find[0] && str[l+1] == find[1]) {
str[l] = replace[0]; str[l + 1] = replace[1];
}
}
}
}
}
}
}
out["segments"][ident] = segment;
}
}

3
xpm_to_ppubytecode/reader/reader.h

@ -8,6 +8,9 @@ private:
converter::bytecode* read(const std::string& fname);
void translate(converter::bytecode* bcode, const std::string& fname = "");
std::vector<std::array<converter::colorStr, 4>> segment_cprofiles;
std::array<converter::colorStr, 4> currentProfile;
void correctColorProfiles();
nlohmann::json out;
void outputPalette(const std::array<converter::colorStr, 4>& colors);

Loading…
Cancel
Save