-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOAMMap.cpp
More file actions
186 lines (158 loc) · 4.6 KB
/
OAMMap.cpp
File metadata and controls
186 lines (158 loc) · 4.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
// OAMMap.cpp: A small utility for creating a visual map of the PPU OAM.
#include "pch.h"
void EmitCellText(std::string &text, size_t bit_num, size_t col, size_t row, size_t pp[8])
{
char cell[0x400]{};
const char* CellColor = "";
char CellLabel[0x20]{};
size_t oam_addr;
if (col == 8)
{
oam_addr = row; // Temp OAM
}
else
{
oam_addr = (row << 3) | col;
}
sprintf_s(CellLabel, sizeof(CellLabel), "%02X-%zd\ncol: %zd\nrow: %zd", (uint8_t)oam_addr, bit_num, col, row);
if (col == 8)
{
CellColor = "DarkViolet"; // Temp OAM
}
else
{
switch (oam_addr & 3)
{
case 0:
CellColor = "LimeGreen"; // Y
break;
case 1:
CellColor = "Ivory"; // Index
break;
case 2:
CellColor = "Red"; // Attr
break;
case 3:
CellColor = "Blue"; // X
break;
}
}
sprintf_s(cell, sizeof(cell), cellText, CellLabel, CellColor,
pp[0], pp[1],
pp[2], pp[3],
pp[4], pp[5],
pp[6], pp[7]);
text += cell;
}
const size_t originOffset = 10ULL;
const size_t cellSize = 10ULL;
const size_t GapBetweenBanks = 30ULL;
const size_t GapBetweenCells = 1ULL;
void GenRowLane(std::string & text, size_t& y, size_t bit_num, size_t col, bool ntsc_ppu)
{
int rows_order_ntsc[] = { 31, 15, 23, 7, 27, 11, 19, 3, 30, 14, 22, 6, 26, 10, 18, 2, 29, 13, 21, 5, 25, 9, 17, 1, 28, 12, 20, 4, 24, 8, 16, 0 };
int rows_order_pal[] = { 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 };
int* rows_order = ntsc_ppu ? rows_order_ntsc : rows_order_pal;
size_t pp[8]{};
for (size_t n = 0; n < 32; n++)
{
size_t row = rows_order[n];
size_t x = (cellSize + GapBetweenCells) * n + originOffset;
size_t cell_y = y;
if (bit_num < 4)
{
cell_y += GapBetweenBanks;
}
pp[0] = x;
pp[1] = cell_y;
pp[2] = x + cellSize;
pp[3] = cell_y;
pp[4] = x + cellSize;
pp[5] = cell_y + cellSize;
pp[6] = x;
pp[7] = cell_y + cellSize;
EmitCellText(text, bit_num, col, row, pp);
}
y += cellSize + GapBetweenCells;
}
void GenMap(bool ntsc_ppu)
{
// Order of columns
int cols_order_ntsc[] = { 1, 3, 5, 7, 0, 2, 4, 6, 8 };
int cols_order_pal[] = { 6, 4, 2, 0, 7, 5, 3, 1, 8 };
int cols_order_ntsc_24[] = { 1, 3, 7, 0, 4, 5, 8 };
int cols_order_pal_24[] = { 5, 4, 0, 7, 3, 1, 8 };
std::string text = "";
text += headerText;
size_t y = originOffset;
for (int n = 7; n >= 0; n--)
{
bool bits_24 = (n == 2 || n == 3 || n == 4);
if (bits_24)
{
if (ntsc_ppu)
{
for (size_t p = 0; p < _countof(cols_order_ntsc_24); p++)
{
GenRowLane(text, y, n, cols_order_ntsc_24[p], ntsc_ppu);
}
}
else
{
for (size_t p = 0; p < _countof(cols_order_pal_24); p++)
{
GenRowLane(text, y, n, cols_order_pal_24[p], ntsc_ppu);
}
}
}
else
{
if (ntsc_ppu)
{
for (size_t p = 0; p < _countof(cols_order_ntsc); p++)
{
GenRowLane(text, y, n, cols_order_ntsc[p], ntsc_ppu);
}
}
else
{
for (size_t p = 0; p < _countof(cols_order_pal); p++)
{
GenRowLane(text, y, n, cols_order_pal[p], ntsc_ppu);
}
}
}
}
text += footerText;
FILE* f;
fopen_s(&f, ntsc_ppu ? "oammap_ntsc.xml" : "oammap_pal.xml", "wt");
if (f)
{
fwrite(text.c_str(), 1, text.size(), f);
fclose(f);
}
}
/// <summary>
/// Output the logical NTSC OAM column numbers.
/// The output is from right to left relative to the physical addressing of the columns.
/// </summary>
void PrintNtscColumns()
{
for (int n = 0; n < 4; n++)
{
printf("%d ", (0 << 2) | n);
printf("%d ", (4 << 2) | n);
printf("%d ", (2 << 2) | n);
printf("%d ", (6 << 2) | n);
printf("%d ", (1 << 2) | n);
printf("%d ", (5 << 2) | n);
printf("%d ", (3 << 2) | n);
printf("%d\n", (7 << 2) | n);
}
}
int main()
{
PrintNtscColumns();
GenMap(true);
GenMap(false);
}