-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathBenchmark.h
69 lines (57 loc) · 1.8 KB
/
Benchmark.h
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
#ifndef BENCHMARK_H
#define BENCHMARK_H
#include "BuildConfig.h"
#include "SPISlave.h"
#include "Utils.h"
namespace Benchmark {
typedef struct {
u32 frame;
u32 goodPackets;
u32 badPackets;
} State;
ALWAYS_INLINE void onVBlank(State& state) {
state.frame++;
if (state.frame >= 60) {
m3_plot(20, 80, state.goodPackets >= 40000 ? CLR_GREEN : CLR_RED);
m3_plot(30, 80, state.goodPackets >= 45000 ? CLR_GREEN : CLR_RED);
m3_plot(40, 80, state.goodPackets >= 50000 ? CLR_GREEN : CLR_RED);
m3_plot(50, 80, state.goodPackets >= 55000 ? CLR_GREEN : CLR_RED);
m3_plot(60, 80, state.goodPackets >= 60000 ? CLR_GREEN : CLR_RED);
m3_plot(70, 80, state.goodPackets >= 65000 ? CLR_GREEN : CLR_RED);
m3_plot(80, 80, state.goodPackets >= 67500 ? CLR_GREEN : CLR_RED);
m3_plot(90, 80, state.goodPackets >= 70000 ? CLR_GREEN : CLR_RED);
m3_plot(100, 80, state.goodPackets >= 75000 ? CLR_GREEN : CLR_RED);
m3_plot(110, 80, state.goodPackets >= 80000 ? CLR_GREEN : CLR_RED);
m3_plot(220, 80, state.badPackets > 0 ? CLR_RED : CLR_GREEN);
state.frame = 0;
state.goodPackets = 0;
state.badPackets = 0;
}
}
CODE_IWRAM void mainLoop() {
bool wasVBlank = false;
State state;
state.frame = 0;
state.goodPackets = 0;
state.badPackets = 0;
while (true) {
bool isVBlank = IS_VBLANK;
u32 packetToSend = 0x12345678;
if (!wasVBlank && isVBlank) {
onVBlank(state);
wasVBlank = true;
packetToSend = 0x123456bb;
} else if (wasVBlank && !isVBlank)
wasVBlank = false;
u32 receivedPacket = spiSlave->transfer(packetToSend);
if (receivedPacket == 0x98765432)
state.goodPackets++;
else
state.badPackets++;
}
}
ALWAYS_INLINE void init() {
REG_DISPCNT = DCNT_MODE3 | DCNT_BG2;
}
} // namespace Benchmark
#endif // BENCHMARK_H