Skip to content

Commit 6747f45

Browse files
committed
render: wrap U coord on texture fetch overflow
render_line: error calculation now mimic HW
1 parent d31ccc0 commit 6747f45

4 files changed

Lines changed: 111 additions & 7 deletions

File tree

src/device/gpu/render/render_line.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void Render::drawLine(gpu::GPU* gpu, const primitive::Line& line) {
4040
int dx = x1 - x0;
4141
int dy = y1 - y0;
4242
int derror = std::abs(dy) * 2;
43-
int error = 0;
43+
int error = !steep;
4444
int _y = y0;
4545

4646
float length = sqrtf(powf(x1 - x0, 2) + powf(y1 - y0, 2));

src/device/gpu/render/texture_utils.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,20 @@ enum class ColorDepth { NONE, BIT_4, BIT_8, BIT_16 };
99
namespace {
1010
// Using unsigned vectors allows compiler to generate slightly faster division code
1111
INLINE uint16_t tex4bit(gpu::GPU* gpu, glm::uvec2 tex, glm::uvec2 texPage, glm::uvec2 clut) {
12-
uint16_t index = gpuVRAM[texPage.y + tex.y][texPage.x + tex.x / 4];
12+
uint16_t index = gpuVRAM[(texPage.y + tex.y) & 511][(texPage.x + tex.x / 4) & 1023];
1313
uint8_t entry = (index >> ((tex.x & 3) * 4)) & 0xf;
1414
return gpuVRAM[clut.y][clut.x + entry];
1515
}
1616

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

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

2527
template <ColorDepth bits>
2628
INLINE PSXColor fetchTex(gpu::GPU* gpu, glm::uvec2 texel, const glm::ivec2 texPage, const glm::ivec2 clut) {

src/platform/windows/gui/options/memory_card.cpp

Lines changed: 99 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,99 @@
66
#include "system.h"
77

88
namespace gui::options {
9+
10+
char sjisToAscii(uint16_t sjis) {
11+
uint8_t l = sjis & 0xff;
12+
uint8_t h = (sjis >> 8) & 0xff;
13+
if (sjis == 0) return 0;
14+
if (l == 0x81) {
15+
// if (h == 0x14) return '-';
16+
if (h == 0x5b) return '-';
17+
if (h == 0x40) return ' ';
18+
if (h == 0x46) return ':';
19+
if (h == 0x49) return '!';
20+
if (h == 0x5e) return '/';
21+
if (h == 0x6d) return '[';
22+
if (h == 0x6e) return ']';
23+
if (h == 0x69) return '(';
24+
if (h == 0x6a) return ')';
25+
if (h == 0x7b) return '+';
26+
if (h == 0x7c) return ',';
27+
if (h == 0x93) return '%';
28+
// if (h >= 0x43 && h <= 0x97) return ' ' + (h-0x43);
29+
}
30+
if (l == 0x82) {
31+
if (h >= 0x4f && h <= 0x58) return '0' + (h - 0x4f);
32+
if (h >= 0x60 && h <= 0x79) return 'A' + (h - 0x60);
33+
if (h >= 0x81 && h <= 0x9a) return 'a' + (h - 0x81);
34+
}
35+
// fmt::print("Unknown S-JIS: 0x{:02x} 0x{:02x}\n", l, h);
36+
return '?';
37+
}
38+
39+
void MemoryCard::parseAndDisplayCard(peripherals::MemoryCard* card) {
40+
auto data = card->data;
41+
auto read32
42+
= [data](size_t pos) -> uint32_t { return data[pos] | (data[pos + 1] << 8) | (data[pos + 2] << 16) | (data[pos + 3] << 24); };
43+
44+
const int BLOCKS = 15;
45+
const auto FRAME_SIZE = 0x80;
46+
const auto BLOCK_SIZE = FRAME_SIZE * 64;
47+
48+
ImGui::Text("Contents:");
49+
50+
enum BlockNum { First = 1, Middle = 2, Last = 3 };
51+
52+
std::string names[BLOCKS];
53+
int links[BLOCKS];
54+
55+
for (size_t i = 1; i < BLOCKS + 1; i++) {
56+
size_t offset = 0x80 * i;
57+
uint32_t state = read32(offset + 0);
58+
59+
bool inUse = false;
60+
if (state >= 0x51 && state <= 0x53) {
61+
if (state == 0x51) {
62+
links[i - 1] = -1;
63+
}
64+
inUse = true;
65+
}
66+
67+
if (!inUse) {
68+
ImGui::Selectable(fmt::format("{:2d}. ---", i).c_str());
69+
continue;
70+
}
71+
72+
// state == 0x51 - block in use, first block
73+
// state == 0x52 - block in use, middle block
74+
// state == 0x53 - block in use, end block
75+
76+
if (state == 0x51) {
77+
uint32_t size = read32(offset + 4) / 1024;
78+
std::string filename;
79+
for (int i = 0; i < 20; i++) {
80+
filename += data[offset + 0x0a + i];
81+
}
82+
83+
// Parse block
84+
std::string title;
85+
86+
for (int s = 0; s < 32; s++) {
87+
size_t offset = BLOCK_SIZE * i + 4;
88+
uint16_t sjis = data[offset + s * 2] | (data[offset + s * 2 + 1] << 8);
89+
90+
char c = sjisToAscii(sjis);
91+
if (c == 0) break;
92+
title += c;
93+
}
94+
95+
ImGui::Selectable(fmt::format("{:2d}. {} ({})", i, title, filename).c_str());
96+
continue;
97+
}
98+
99+
ImGui::Selectable(fmt::format("{:2d}. USED", i).c_str());
100+
}
101+
}
9102
void MemoryCard::memoryCardWindow(System* sys) {
10103
if (loadPaths) {
11104
for (size_t i = 0; i < cardPaths.size(); i++) {
@@ -26,9 +119,13 @@ void MemoryCard::memoryCardWindow(System* sys) {
26119

27120
bool inserted = sys->controller->card[i]->inserted;
28121
if (ImGui::Checkbox("Inserted", &inserted)) {
29-
sys->controller->card[0]->inserted = inserted;
122+
sys->controller->card[i]->inserted = inserted;
30123
}
31124

125+
// ImGui::BeginChild("Contents");
126+
parseAndDisplayCard(sys->controller->card[i].get());
127+
// ImGui::EndChild();
128+
32129
ImGui::EndTabItem();
33130
}
34131
}
@@ -40,4 +137,4 @@ void MemoryCard::memoryCardWindow(System* sys) {
40137
void MemoryCard::displayWindows(System* sys) {
41138
if (memoryCardWindowOpen) memoryCardWindow(sys);
42139
}
43-
} // namespace gui::options::memory_card
140+
} // namespace gui::options

src/platform/windows/gui/options/memory_card.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,20 @@
33
#include <string>
44

55
struct System;
6+
namespace peripherals {
7+
struct MemoryCard;
8+
};
69

710
namespace gui::options {
811
class MemoryCard {
912
bool loadPaths = true;
1013
std::array<std::string, 2> cardPaths;
14+
15+
void parseAndDisplayCard(peripherals::MemoryCard* card);
1116
void memoryCardWindow(System* sys);
1217

1318
public:
1419
bool memoryCardWindowOpen = false;
1520
void displayWindows(System* sys);
1621
};
17-
} // namespace gui::options::memory_card
22+
} // namespace gui::options

0 commit comments

Comments
 (0)