Skip to content
Permalink
Browse files

silenced template warnings, refactoring

added vram png dump
  • Loading branch information
JaCzekanski committed Sep 10, 2019
1 parent baaf19c commit b766eda5c4fe8b933e5052ba99760c001beac4b0
@@ -140,6 +140,7 @@ project "core"
"src",
"externals/glm",
"externals/json/include",
"externals/stb",
"externals/miniz",
"externals/libchdr/src",
"externals/EventBus/lib/include",
@@ -223,9 +223,9 @@ uint8_t CDROM::readByte() {
return data;
}

std::string CDROM::dumpFifo(const fifo<16, uint8_t> f) {
std::string CDROM::dumpFifo(const FIFO& f) {
std::string log = "";
for (size_t i = 0; i < f.size(); i++) {
for (size_t i = 0u; i < f.size(); i++) {
log += fmt::format("0x{:02x}", f[i]);
if (i < f.size() - 1) log += ", ";
}
@@ -97,13 +97,15 @@ class CDROM {
Filter() : file(0), channel(0) {}
};

using FIFO = fifo<uint8_t, 16>;

int verbose = 1;

CDROM_Status status;
uint8_t interruptEnable = 0;
fifo<16, uint8_t> CDROM_params;
fifo<16, uint8_t> CDROM_response;
fifo<16, uint8_t> interruptQueue;
FIFO CDROM_params;
FIFO CDROM_response;
FIFO interruptQueue;

Mode mode;
Filter filter;
@@ -165,7 +167,7 @@ class CDROM {
interruptQueue.add(irq);
}

std::string dumpFifo(const fifo<16, uint8_t> f);
std::string dumpFifo(const FIFO& f);

public:
uint8_t volumeLeftToLeft = 0;
@@ -1,7 +1,7 @@
#pragma once
#include <cstddef>

template <size_t length, typename T>
template <typename T, size_t length>
class fifo {
// Elements are added to the back and are read from the front
T data[length] = {};
@@ -58,5 +58,5 @@ class fifo {
return data[(read_ptr + ptr) % length];
}

T operator[](T ptr) const { return peek(ptr); }
T operator[](size_t ptr) const { return peek(ptr); }
};
@@ -36,7 +36,7 @@ struct AnalogController : public DigitalController {

bool operator==(const Vibration& r) { return small == r.small && big == r.big; }
bool operator!=(const Vibration& r) { return !(*this == r); }
bool operator!=(const int r) { return small != r || small != r; }
bool operator!=(const int r) { return small != r || big != r; }
};

uint8_t _handle(uint8_t byte); // Wrapper for handler for catching return value
@@ -7,6 +7,9 @@
#include "utils/logic.h"
#include "utils/macros.h"

// For vram dump
#include <stb_image_write.h>

namespace gpu {
GPU::GPU() {
busToken = bus.listen<Event::Config::Graphics>([&](auto) { reload(); });
@@ -743,8 +746,16 @@ bool GPU::insideDrawingArea(int x, int y) const {
bool GPU::isNtsc() { return forceNtsc || gp1_08.videoMode == GP1_08::VideoMode::ntsc; }

void GPU::dumpVram() {
std::vector<uint8_t> vram;
vram.assign(this->vram.begin(), this->vram.end());
putFileContents("vram.bin", vram);
const char* dumpName = "vram.png";
std::vector<uint8_t> vram(VRAM_WIDTH * VRAM_HEIGHT * 3);

for (size_t i = 0; i < this->vram.size(); i++) {
PSXColor c(this->vram[i]);
vram[i * 3 + 0] = c.r << 3;
vram[i * 3 + 1] = c.g << 3;
vram[i * 3 + 2] = c.b << 3;
}

stbi_write_png(dumpName, VRAM_WIDTH, VRAM_HEIGHT, 3, vram.data(), VRAM_WIDTH * 3);
}
} // namespace gpu
@@ -183,7 +183,7 @@ void MDEC::idct(std::array<int16_t, 64>& src) {
}

int round = (sum >> 31) & 1;
src[x + y * 8] = (sum >> 32) + round;
src[x + y * 8] = (uint16_t)((sum >> 32) + round);
}
}
}
@@ -1,7 +1,7 @@
#include "utils/file.h"
#include <cstdio>

bool fileExists(std::string name) {
bool fileExists(const std::string &name) {
FILE *f = fopen(name.c_str(), "r");
bool exists = false;
if (f) {
@@ -11,7 +11,7 @@ bool fileExists(std::string name) {
return exists;
}

std::vector<uint8_t> getFileContents(std::string name) {
std::vector<uint8_t> getFileContents(const std::string &name) {
std::vector<uint8_t> contents;

FILE *f = fopen(name.c_str(), "rb");
@@ -28,7 +28,7 @@ std::vector<uint8_t> getFileContents(std::string name) {
return contents;
}

bool putFileContents(std::string name, std::vector<unsigned char> &contents) {
bool putFileContents(const std::string &name, const std::vector<unsigned char> &contents) {
FILE *f = fopen(name.c_str(), "wb");
if (!f) return false;

@@ -39,7 +39,7 @@ bool putFileContents(std::string name, std::vector<unsigned char> &contents) {
return true;
}

bool putFileContents(std::string name, std::string contents) {
bool putFileContents(const std::string &name, const std::string contents) {
FILE *f = fopen(name.c_str(), "wb");
if (!f) return false;

@@ -50,7 +50,7 @@ bool putFileContents(std::string name, std::string contents) {
return true;
}

std::string getFileContentsAsString(std::string name) {
std::string getFileContentsAsString(const std::string &name) {
std::string contents;

FILE *f = fopen(name.c_str(), "rb");
@@ -67,7 +67,7 @@ std::string getFileContentsAsString(std::string name) {
return contents;
}

size_t getFileSize(std::string name) {
size_t getFileSize(const std::string &name) {
FILE *f = fopen(name.c_str(), "rb");
if (!f) return 0;

@@ -1,7 +1,7 @@
#include "utils/file.h"
#include <SDL.h>

bool fileExists(std::string name) {
bool fileExists(const std::string &name) {
SDL_RWops *f = SDL_RWFromFile(name.c_str(), "r");
bool exists = false;
if (f) {
@@ -11,7 +11,7 @@ bool fileExists(std::string name) {
return exists;
}

std::vector<uint8_t> getFileContents(std::string name) {
std::vector<uint8_t> getFileContents(const std::string &name) {
std::vector<uint8_t> contents;

SDL_RWops *f = SDL_RWFromFile(name.c_str(), "rb");
@@ -28,7 +28,7 @@ std::vector<uint8_t> getFileContents(std::string name) {
return contents;
}

bool putFileContents(std::string name, std::vector<unsigned char> &contents) {
bool putFileContents(const std::string &name, const std::vector<unsigned char> &contents) {
SDL_RWops *f = SDL_RWFromFile(name.c_str(), "wb");
if (!f) return false;

@@ -39,7 +39,7 @@ bool putFileContents(std::string name, std::vector<unsigned char> &contents) {
return true;
}

bool putFileContents(std::string name, std::string contents) {
bool putFileContents(const std::string &name, const std::string contents) {
SDL_RWops *f = SDL_RWFromFile(name.c_str(), "wb");
if (!f) return false;

@@ -50,7 +50,7 @@ bool putFileContents(std::string name, std::string contents) {
return true;
}

std::string getFileContentsAsString(std::string name) {
std::string getFileContentsAsString(const std::string &name) {
std::string contents;

SDL_RWops *f = SDL_RWFromFile(name.c_str(), "rb");
@@ -67,7 +67,7 @@ std::string getFileContentsAsString(std::string name) {
return contents;
}

size_t getFileSize(std::string name) {
size_t getFileSize(const std::string &name) {
SDL_RWops *f = SDL_RWFromFile(name.c_str(), "rb");
if (!f) return 0;

@@ -46,7 +46,7 @@ Segment Segment::fromAddress(uint32_t address) {

std::string formatOpcode(mips::Opcode& opcode) {
auto disasm = debugger::decodeInstruction(opcode);
return fmt::format("{} {:{}c} {}", disasm.mnemonic, ' ', std::max<int>(0, 6 - disasm.mnemonic.length()), disasm.parameters);
return fmt::format("{} {:{}c} {}", disasm.mnemonic, ' ', std::max(0, 6 - (int)disasm.mnemonic.length()), disasm.parameters);
}

void CPU::debuggerWindow(System* sys) {
@@ -96,7 +96,7 @@ void CPU::debuggerWindow(System* sys) {
ImGui::TextUnformatted(reg);
ImGui::SameLine();

auto color = ImVec4(1.0, 1.0, 1.0, (val == 0) ? 0.25 : 1.0);
auto color = ImVec4(1.f, 1.f, 1.f, (val == 0) ? 0.25f : 1.f);
ImGui::TextColored(color, "0x%08x", val);
ImGui::NextColumn();

@@ -149,7 +149,7 @@ void CPU::debuggerWindow(System* sys) {
auto lineHeight = ImGui::GetTextLineHeight();
int16_t branchOffset = disasm.opcode.offset;

int xEnd = xStart - clamp<int>(abs(branchOffset), glyphSize, xStart);
int xEnd = xStart - clamp(abs(branchOffset), (int)glyphSize, xStart);

ImVec2 src = ImGui::GetCursorScreenPos();
src.y += lineHeight / 2;
@@ -213,9 +213,9 @@ void CPU::debuggerWindow(System* sys) {
ImGui::PushStyleColor(ImGuiCol_Text, color);

auto line
= fmt::format("{} {:{}c} {}", disasm.mnemonic, ' ', std::max<int>(0, 6 - disasm.mnemonic.length()), disasm.parameters);
= fmt::format("{} {:{}c} {}", disasm.mnemonic, ' ', std::max(0, 6 - (int)disasm.mnemonic.length()), disasm.parameters);
if (ImGui::Selectable(fmt::format(" {}:0x{:08x}: {} {:{}c} {}", segment.name, address, line, ' ',
std::max<int>(0, 25 - line.length()), comment)
std::max(0, 25 - (int)line.length()), comment)
.c_str())) {
auto bp = sys->cpu->breakpoints.find(address);
if (bp == sys->cpu->breakpoints.end()) {
@@ -42,7 +42,7 @@ struct Field {
void drawRegisterFields(const char* name, const std::vector<Field>& fields) {
const size_t colNum = 3;
ImVec2 charSize = ImGui::CalcTextSize("_");
std::vector<unsigned int> columnsWidth(colNum);
std::vector<size_t> columnsWidth(colNum);

for (size_t i = 0; i < fields.size(); i++) {
auto& f = fields[i];
@@ -177,10 +177,10 @@ void openFile() {
ImGui::BeginChild("##files", ImVec2(0, 0));
ImGui::Columns(2, nullptr, false);

auto formatFileSize = [](long bytes) {
auto formatFileSize = [](uintmax_t bytes) {
std::string units = "kMGTPE";

int unit = 1024;
size_t unit = 1024;
if (bytes < unit) return fmt::format("{:4d} B", bytes);
int exp = (int)(std::log(bytes) / std::log(unit));

@@ -192,20 +192,20 @@ void openFile() {
float maxColumnWidth = 0.f;
for (auto& f : files) {
auto filename = f.path().filename().string();
ImVec4 color = ImVec4(1.0, 1.0, 1.0, 1.0);
ImVec4 color = ImVec4(1.f, 1.f, 1.f, 1.f);
bool isSupported = false;

if (fs::is_directory(f)) {
color = ImVec4(0.34, 0.54, 0.56, 1.0);
color = ImVec4(0.34f, 0.54f, 0.56f, 1.f);
} else if (filename[0] == '.' && filename != "..") {
color = ImVec4(color.x - 0.3, color.y - 0.3, color.z - 0.3, 1.0);
color = ImVec4(color.x - 0.3f, color.y - 0.3f, color.z - 0.3f, 1.f);
} else {
std::string ext = f.path().extension().string();
std::transform(ext.begin(), ext.end(), ext.begin(), tolower);
isSupported = std::find(supportedFiles.begin(), supportedFiles.end(), ext) != supportedFiles.end();

if (!isSupported) {
color = ImVec4(0.3, 0.3, 0.3, 1.0);
color = ImVec4(0.3f, 0.3f, 0.3f, 1.f);
}
}

@@ -158,6 +158,7 @@ void renderImgui(System* sys) {
sys->dumpRam();
sys->spu->dumpRam();
sys->gpu->dumpVram();
toast("State dumped");
}
ImGui::EndMenu();
}
@@ -1,6 +1,5 @@
#include "images.h"
#include <fmt/core.h>
#define STB_IMAGE_IMPLEMENTATION
#include <stb_image.h>
#include <unordered_map>
#include "utils/file.h"
@@ -0,0 +1,2 @@
#define STB_IMAGE_IMPLEMENTATION
#include <stb_image.h>
@@ -0,0 +1,2 @@
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include <stb_image_write.h>
@@ -1,10 +1,8 @@
#include "opengl.h"
#include <SDL.h>
#include <fmt/core.h>
#include <algorithm>
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include <imgui.h>
#include <stb_image_write.h>
#include <algorithm>
#include <glm/gtc/type_ptr.hpp>
#include "config.h"

@@ -246,10 +244,10 @@ void OpenGL::renderVertices(gpu::GPU* gpu) {
return;
}

int areaX = lastPos.x;
int areaY = lastPos.y;
int areaW = gpu->gp1_08.getHorizontalResoulution();
int areaH = gpu->gp1_08.getVerticalResoulution();
int areaX = static_cast<int>(lastPos.x);
int areaY = static_cast<int>(lastPos.y);
int areaW = static_cast<int>(gpu->gp1_08.getHorizontalResoulution());
int areaH = static_cast<int>(gpu->gp1_08.getVerticalResoulution());

// Simulate GPU in Shader (skip if no entries in renderlist)
glViewport(0, 0, renderWidth, renderHeight);
@@ -2,7 +2,7 @@

GLuint Buffer::currentId = 0;

Buffer::Buffer(int size) {
Buffer::Buffer(size_t size) {
GLint lastBuffer;
glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &lastBuffer);

@@ -7,7 +7,7 @@ class Buffer {
public:
static GLuint currentId;

Buffer(int size);
Buffer(size_t size);
~Buffer();

void update(int size, const void* data);

0 comments on commit b766eda

Please sign in to comment.
You can’t perform that action at this time.