Skip to content

Commit

Permalink
render: wrap U coord on texture fetch overflow
Browse files Browse the repository at this point in the history
render_line: error calculation now mimic HW
  • Loading branch information
JaCzekanski committed Sep 30, 2019
1 parent d31ccc0 commit 6747f45
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/device/gpu/render/render_line.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void Render::drawLine(gpu::GPU* gpu, const primitive::Line& line) {
int dx = x1 - x0;
int dy = y1 - y0;
int derror = std::abs(dy) * 2;
int error = 0;
int error = !steep;
int _y = y0;

float length = sqrtf(powf(x1 - x0, 2) + powf(y1 - y0, 2));
Expand Down
8 changes: 5 additions & 3 deletions src/device/gpu/render/texture_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,20 @@ enum class ColorDepth { NONE, BIT_4, BIT_8, BIT_16 };
namespace {
// Using unsigned vectors allows compiler to generate slightly faster division code
INLINE uint16_t tex4bit(gpu::GPU* gpu, glm::uvec2 tex, glm::uvec2 texPage, glm::uvec2 clut) {
uint16_t index = gpuVRAM[texPage.y + tex.y][texPage.x + tex.x / 4];
uint16_t index = gpuVRAM[(texPage.y + tex.y) & 511][(texPage.x + tex.x / 4) & 1023];
uint8_t entry = (index >> ((tex.x & 3) * 4)) & 0xf;
return gpuVRAM[clut.y][clut.x + entry];
}

INLINE uint16_t tex8bit(gpu::GPU* gpu, glm::uvec2 tex, glm::uvec2 texPage, glm::uvec2 clut) {
uint16_t index = gpuVRAM[texPage.y + tex.y][texPage.x + tex.x / 2];
uint16_t index = gpuVRAM[(texPage.y + tex.y) & 511][(texPage.x + tex.x / 2) & 1023];
uint8_t entry = (index >> ((tex.x & 1) * 8)) & 0xff;
return gpuVRAM[clut.y][clut.x + entry];
}

INLINE uint16_t tex16bit(gpu::GPU* gpu, glm::uvec2 tex, glm::uvec2 texPage) { return gpuVRAM[texPage.y + tex.y][texPage.x + tex.x]; }
INLINE uint16_t tex16bit(gpu::GPU* gpu, glm::uvec2 tex, glm::uvec2 texPage) {
return gpuVRAM[(texPage.y + tex.y) & 511][(texPage.x + tex.x) & 1023];
}

template <ColorDepth bits>
INLINE PSXColor fetchTex(gpu::GPU* gpu, glm::uvec2 texel, const glm::ivec2 texPage, const glm::ivec2 clut) {
Expand Down
101 changes: 99 additions & 2 deletions src/platform/windows/gui/options/memory_card.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,99 @@
#include "system.h"

namespace gui::options {

char sjisToAscii(uint16_t sjis) {
uint8_t l = sjis & 0xff;
uint8_t h = (sjis >> 8) & 0xff;
if (sjis == 0) return 0;
if (l == 0x81) {
// if (h == 0x14) return '-';
if (h == 0x5b) return '-';
if (h == 0x40) return ' ';
if (h == 0x46) return ':';
if (h == 0x49) return '!';
if (h == 0x5e) return '/';
if (h == 0x6d) return '[';
if (h == 0x6e) return ']';
if (h == 0x69) return '(';
if (h == 0x6a) return ')';
if (h == 0x7b) return '+';
if (h == 0x7c) return ',';
if (h == 0x93) return '%';
// if (h >= 0x43 && h <= 0x97) return ' ' + (h-0x43);
}
if (l == 0x82) {
if (h >= 0x4f && h <= 0x58) return '0' + (h - 0x4f);
if (h >= 0x60 && h <= 0x79) return 'A' + (h - 0x60);
if (h >= 0x81 && h <= 0x9a) return 'a' + (h - 0x81);
}
// fmt::print("Unknown S-JIS: 0x{:02x} 0x{:02x}\n", l, h);
return '?';
}

void MemoryCard::parseAndDisplayCard(peripherals::MemoryCard* card) {
auto data = card->data;
auto read32
= [data](size_t pos) -> uint32_t { return data[pos] | (data[pos + 1] << 8) | (data[pos + 2] << 16) | (data[pos + 3] << 24); };

const int BLOCKS = 15;
const auto FRAME_SIZE = 0x80;
const auto BLOCK_SIZE = FRAME_SIZE * 64;

ImGui::Text("Contents:");

enum BlockNum { First = 1, Middle = 2, Last = 3 };

std::string names[BLOCKS];
int links[BLOCKS];

for (size_t i = 1; i < BLOCKS + 1; i++) {
size_t offset = 0x80 * i;
uint32_t state = read32(offset + 0);

bool inUse = false;
if (state >= 0x51 && state <= 0x53) {
if (state == 0x51) {
links[i - 1] = -1;
}
inUse = true;
}

if (!inUse) {
ImGui::Selectable(fmt::format("{:2d}. ---", i).c_str());
continue;
}

// state == 0x51 - block in use, first block
// state == 0x52 - block in use, middle block
// state == 0x53 - block in use, end block

if (state == 0x51) {
uint32_t size = read32(offset + 4) / 1024;
std::string filename;
for (int i = 0; i < 20; i++) {
filename += data[offset + 0x0a + i];
}

// Parse block
std::string title;

for (int s = 0; s < 32; s++) {
size_t offset = BLOCK_SIZE * i + 4;
uint16_t sjis = data[offset + s * 2] | (data[offset + s * 2 + 1] << 8);

char c = sjisToAscii(sjis);
if (c == 0) break;
title += c;
}

ImGui::Selectable(fmt::format("{:2d}. {} ({})", i, title, filename).c_str());
continue;
}

ImGui::Selectable(fmt::format("{:2d}. USED", i).c_str());
}
}
void MemoryCard::memoryCardWindow(System* sys) {
if (loadPaths) {
for (size_t i = 0; i < cardPaths.size(); i++) {
Expand All @@ -26,9 +119,13 @@ void MemoryCard::memoryCardWindow(System* sys) {

bool inserted = sys->controller->card[i]->inserted;
if (ImGui::Checkbox("Inserted", &inserted)) {
sys->controller->card[0]->inserted = inserted;
sys->controller->card[i]->inserted = inserted;
}

// ImGui::BeginChild("Contents");
parseAndDisplayCard(sys->controller->card[i].get());
// ImGui::EndChild();

ImGui::EndTabItem();
}
}
Expand All @@ -40,4 +137,4 @@ void MemoryCard::memoryCardWindow(System* sys) {
void MemoryCard::displayWindows(System* sys) {
if (memoryCardWindowOpen) memoryCardWindow(sys);
}
} // namespace gui::options::memory_card
} // namespace gui::options
7 changes: 6 additions & 1 deletion src/platform/windows/gui/options/memory_card.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@
#include <string>

struct System;
namespace peripherals {
struct MemoryCard;
};

namespace gui::options {
class MemoryCard {
bool loadPaths = true;
std::array<std::string, 2> cardPaths;

void parseAndDisplayCard(peripherals::MemoryCard* card);
void memoryCardWindow(System* sys);

public:
bool memoryCardWindowOpen = false;
void displayWindows(System* sys);
};
} // namespace gui::options::memory_card
} // namespace gui::options

0 comments on commit 6747f45

Please sign in to comment.