Skip to content

Commit 68ba7bd

Browse files
committed
A little more cleanup, display cpu freq & mem freq, hidden secrets
1 parent 557cf06 commit 68ba7bd

File tree

2 files changed

+85
-48
lines changed

2 files changed

+85
-48
lines changed

Makefile.nxdk

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ NXDK_DIR ?= $(CURDIR)/../..
55

66
NXDK_SDL = y
77

8-
CFLAGS += -O2 -Wall -Wextra -pedantic
9-
CXXFLAGS += -O2 -Wall -Wextra -pedantic
8+
CFLAGS += -Og -Wall -Wextra -pedantic
9+
CXXFLAGS += -Og -Wall -Wextra -pedantic
1010

11-
NXDK_CFLAGS += -O2 -Wall -Wextra -pedantic
12-
NXDK_CXXFLAGS += -O2 -Wall -Wextra -pedantic
11+
NXDK_CFLAGS += -Og -Wall -Wextra -pedantic
12+
NXDK_CXXFLAGS += -Og -Wall -Wextra -pedantic
1313

1414
include $(NXDK_DIR)/Makefile

main.c

Lines changed: 81 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,16 @@
2121
#include <windows.h>
2222
#include <SDL.h>
2323

24-
#define BASE_CLOCK_INT 16667
24+
#define CPU_BASE_MULTIPLIER 5.5f
25+
#define BASE_CLOCK_INT 16667
2526
#define BASE_CLOCK_FLOAT 16.667f
2627

28+
ULONG original_fsb, wanted_fsb, hidden_fsb;
29+
ULONG original_nvclk, wanted_nvclk;
30+
int original_m, original_n, original_p, original_mp;
31+
int wanted_m, wanted_n, wanted_p, wanted_mp;
32+
ULONG pci_buff, cpu_coeff;
33+
2734
// https://github.com/WulfyStylez/XBOverclock
2835
void calc_clock_params(int clk, int *n, int *m)
2936
{
@@ -58,6 +65,47 @@ ULONG get_GPU_frequency()
5865
return current_nvclk;
5966
}
6067

68+
void outputClocks()
69+
{
70+
calc_clock_params(wanted_fsb, &wanted_n, &wanted_m);
71+
hidden_fsb = (BASE_CLOCK_FLOAT / wanted_m) * wanted_n;
72+
73+
ULONG cpu_clk = (int)(wanted_fsb * CPU_BASE_MULTIPLIER);
74+
ULONG mem_clk = ((BASE_CLOCK_FLOAT / wanted_m) * (wanted_p * 2 * wanted_n)) / (2 * wanted_mp);
75+
76+
cpu_coeff = (pci_buff & ~0x00FFFFFF) | (wanted_mp << 20) | (wanted_p << 16) | (wanted_n << 8) | wanted_m;
77+
78+
debugPrint("\nFSB: %03luMHz, CPU: %03luMHz, RAM: %03luMHz\n", wanted_fsb, cpu_clk, mem_clk);
79+
debugPrint("NVCLK : %03luMHz\n", wanted_nvclk);
80+
}
81+
82+
static inline void writeCPUClocks(ULONG coeff)
83+
{
84+
// wait and disable interrupts
85+
Sleep(1000);
86+
__asm__("cli\n\t"
87+
"sfence\n\t"
88+
"nop\n\t"
89+
"nop\n\t"
90+
"nop\n\t"
91+
"nop\n\t"
92+
"nop\n\t"
93+
);
94+
95+
HalReadWritePCISpace(0, 0x60, 0x6C, &coeff, sizeof(coeff), TRUE);
96+
97+
// wait and enable interrupts
98+
__asm__("nop\n\t"
99+
"nop\n\t"
100+
"nop\n\t"
101+
"nop\n\t"
102+
"nop\n\t"
103+
"sfence\n\t"
104+
"sti\n\t"
105+
);
106+
Sleep(1000);
107+
}
108+
61109
int main(void)
62110
{
63111
XVideoSetMode(640, 480, 32, REFRESH_DEFAULT);
@@ -81,17 +129,22 @@ int main(void)
81129
}
82130

83131
// Read in the current FSB setting
84-
ULONG pci_buff = 0;
132+
pci_buff = 0;
85133
HalReadWritePCISpace(0, 0x60, 0x6C, &pci_buff, sizeof(pci_buff), FALSE);
86-
ULONG original_fsb = (BASE_CLOCK_FLOAT / (pci_buff & 0xFF)) * ((pci_buff >> 8) & 0xFF);
87-
ULONG wanted_fsb = original_fsb;
134+
135+
original_m = wanted_m = pci_buff & 0xFF;
136+
original_n = wanted_n = (pci_buff >> 8) & 0xFF;
137+
original_p = wanted_p = (pci_buff >> 16) & 0xF;
138+
original_mp = wanted_mp = (pci_buff >> 20) & 0xF;
139+
140+
original_fsb = (BASE_CLOCK_FLOAT / wanted_m) * wanted_n;
141+
wanted_fsb = original_fsb;
88142

89143
// GPU
90-
ULONG original_nvclk = get_GPU_frequency();
91-
ULONG wanted_nvclk = original_nvclk;
144+
original_nvclk = get_GPU_frequency();
145+
wanted_nvclk = original_nvclk;
92146

93-
debugPrint("\nFSB : %03luMHz\n", wanted_fsb);
94-
debugPrint("NVCLK : %03luMHz\n", wanted_nvclk);
147+
outputClocks();
95148

96149
debugPrint("\nThis tool may cause irreparable harm to your Xbox.\n");
97150
debugPrint("This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
@@ -112,10 +165,12 @@ int main(void)
112165
while (SDL_PollEvent(&event)) {
113166
if (event.type == SDL_CONTROLLERBUTTONDOWN) {
114167
switch (event.cbutton.button) {
115-
case SDL_CONTROLLER_BUTTON_DPAD_LEFT: wanted_fsb--; break;
116-
case SDL_CONTROLLER_BUTTON_DPAD_RIGHT: wanted_fsb++; break;
117-
case SDL_CONTROLLER_BUTTON_DPAD_DOWN: wanted_nvclk--; break;
118-
case SDL_CONTROLLER_BUTTON_DPAD_UP: wanted_nvclk++; break;
168+
case SDL_CONTROLLER_BUTTON_DPAD_LEFT: --wanted_fsb; break;
169+
case SDL_CONTROLLER_BUTTON_DPAD_RIGHT: ++wanted_fsb; break;
170+
case SDL_CONTROLLER_BUTTON_DPAD_DOWN: --wanted_nvclk; break;
171+
case SDL_CONTROLLER_BUTTON_DPAD_UP: ++wanted_nvclk; break;
172+
case SDL_CONTROLLER_BUTTON_X: ++wanted_mp; break;
173+
case SDL_CONTROLLER_BUTTON_B: --wanted_mp; break;
119174
case SDL_CONTROLLER_BUTTON_START:
120175
SDL_Quit(); // have less stuff running
121176

@@ -127,45 +182,28 @@ int main(void)
127182
debugClearScreen();
128183
debugPrint("Setting NVCLK to: %03dMHz\n", (BASE_CLOCK_INT * n / m) / 2 / 1000);
129184

130-
coeff = *((volatile ULONG *)0xFD680500) & ~0x0000FFFF | n << 8 | m;
185+
coeff = (*((volatile ULONG *)0xFD680500) & ~0x0000FFFF) | (n << 8) | m;
131186

132187
Sleep(500);
133188
*((volatile ULONG *)0xFD680500) = coeff;
134189
Sleep(500);
135190
}
136191

137-
if (wanted_fsb != original_fsb) {
138-
calc_clock_params((++wanted_fsb), &n, &m);
139-
int clk = BASE_CLOCK_FLOAT * n / m;
192+
// We MUST set this before CPU clocks
193+
if (wanted_mp != original_mp) {
140194
debugClearScreen();
141-
debugPrint("Setting FSB to: %dMHz\n", clk);
142-
debugPrint("CPU: %dMHz\n", (int)(clk * 5.5f));
195+
debugPrint("Setting MemDiv to: %d\n", wanted_mp);
196+
197+
// We don't use cpu_coeff as it might have FSB bits changed and we can't set both at the same time.
198+
coeff = (pci_buff & ~0x00F00000) | (wanted_mp << 20);
199+
writeCPUClocks(coeff);
200+
}
143201

144-
coeff = (pci_buff & ~0x0000FFFF) | (n << 8) | m;
202+
if (wanted_fsb != original_fsb) {
203+
debugClearScreen();
204+
debugPrint("Setting FSB to: %03dMHz\n", (int)(BASE_CLOCK_FLOAT * wanted_n / wanted_m));
145205

146-
// wait and disable interrupts
147-
Sleep(500);
148-
__asm__("cli\n\t"
149-
"sfence\n\t"
150-
"nop\n\t"
151-
"nop\n\t"
152-
"nop\n\t"
153-
"nop\n\t"
154-
"nop\n\t"
155-
);
156-
157-
HalReadWritePCISpace(0, 0x60, 0x6C, &coeff, sizeof(coeff), TRUE);
158-
159-
// wait and enable interrupts
160-
__asm__("nop\n\t"
161-
"nop\n\t"
162-
"nop\n\t"
163-
"nop\n\t"
164-
"nop\n\t"
165-
"sfence\n\t"
166-
"sti\n\t"
167-
);
168-
Sleep(500);
206+
writeCPUClocks(cpu_coeff);
169207
}
170208

171209
debugPrint("SET\n");
@@ -180,8 +218,7 @@ int main(void)
180218
}
181219

182220
debugResetCursor();
183-
debugPrint("\nFSB : %03luMHz\n", wanted_fsb);
184-
debugPrint("NVCLK : %03luMHz\n", wanted_nvclk);
221+
outputClocks();
185222
}
186223
}
187224
}

0 commit comments

Comments
 (0)