Skip to content

Commit d9de4d2

Browse files
committed
[wip] tests/pong-mode0: Add mode 0 pong example
1 parent 58e18ff commit d9de4d2

File tree

16 files changed

+708
-91
lines changed

16 files changed

+708
-91
lines changed

.clang-format

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ PenaltyBreakString: 1000
158158
PenaltyBreakTemplateDeclaration: 10
159159
PenaltyExcessCharacter: 1000000
160160
PenaltyIndentedWhitespace: 0
161-
PenaltyReturnTypeOnItsOwnLine: 60
161+
PenaltyReturnTypeOnItsOwnLine: 1000000
162162
PointerAlignment: Left
163163
PPIndentWidth: -1
164164
QualifierAlignment: Leave

libgba-cpp/arch/display/layers.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include <libgba-cpp/arch/display/layers.h>
2-
32
#include <libgba-cpp/arch/registers.h>
43
#include <libgba-cpp/utils/general.h>
54

@@ -8,15 +7,16 @@ namespace {
87
using gba::display::BackgroundControl;
98
using gba::display::RawPalette;
109

11-
using gba::arch::registers::display::bg_controls;
12-
1310
static auto const bg_address = reinterpret_cast<RawPalette<256>*>(0x0500'0000);
1411
static auto& bg_palette = *new (bg_address) RawPalette<256>{};
1512

16-
}
13+
} // namespace
1714

1815
BackgroundControl& gba::display::bg_control(gba::display::Layer layer) {
19-
return *(reinterpret_cast<BackgroundControl*>(0x0400'0008) + utils::value_of(layer));
16+
return *(
17+
reinterpret_cast<BackgroundControl*>(0x0400'0008) +
18+
utils::value_of(layer)
19+
);
2020
}
2121

2222
RawPalette<256>& gba::display::bg_palette() {

libgba-cpp/arch/display/layers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ enum class MapSize {
110110
};
111111

112112

113-
constexpr geometry::Size extract_size(MapSize size) {
113+
constexpr auto get_size_values(MapSize size) -> geometry::Size {
114114
switch (size) {
115115
case MapSize::TEXT_256X256:
116116
return {256, 256};
Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
11
#include <libgba-cpp/arch/display/objects.h>
2+
#include <libgba-cpp/arch/display/tilemap.h>
23

3-
using gba::display::Color;
44
using gba::display::RawPalette;
55

66
namespace {
77

8-
static auto const obj_palette_address = reinterpret_cast<RawPalette<256>*>(0x0500'0200);
9-
static auto& obj_palette =
10-
*new (obj_palette_address) RawPalette<256>{};
8+
static auto const obj_palette_address =
9+
reinterpret_cast<RawPalette<256>*>(0x0500'0200);
10+
static auto& obj_palette = *new (obj_palette_address) RawPalette<256>{};
1111

12-
}
12+
static auto& oam = *new (reinterpret_cast<void*>(0x0700'0000))
13+
std::array<gba::display::OAMEntry, 128>{};
14+
static auto& sprite_tiles = *new (reinterpret_cast<void*>(0x0601'0000)) std::array<gba::display::map::Tile, 256>{};
15+
// auto oam_map = array<pair<optional<Sprite&>, int>, 128>{};
1316

14-
namespace gba {
17+
} // namespace
1518

16-
RawPalette<256>& display::obj_palette() {
19+
auto gba::display::obj_palette() -> RawPalette<256>& {
1720
return ::obj_palette;
1821
}
1922

23+
auto gba::display::oam_entry(int index) -> OAMEntry& {
24+
return ::oam[index];
2025
}
26+
27+
auto gba::display::sprite_tile(int index) -> gba::display::map::Tile& {
28+
return sprite_tiles[index];
29+
};

libgba-cpp/arch/display/objects.h

Lines changed: 105 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#ifndef GBA_DRIVERS_DISPLAY_OBJ_H
22
#define GBA_DRIVERS_DISPLAY_OBJ_H
33

4+
#include <libgba-cpp/arch/display/tilemap.h>
45
#include <libgba-cpp/arch/display/video.h>
6+
#include <libgba-cpp/utils/bitset.h>
57

68
namespace gba::display {
79

@@ -20,12 +22,10 @@ enum class ObjectMapping {
2022
MAP_TILE_MATRIX,
2123
};
2224

23-
2425
/**
2526
* Object Color Palette array.
2627
*/
27-
RawPalette<256>& obj_palette();
28-
28+
auto obj_palette() -> RawPalette<256>&;
2929

3030
/**
3131
* Changes object mapping mode.
@@ -34,6 +34,108 @@ inline void object_mapping(ObjectMapping map) {
3434
gba::arch::registers::display::lcd_control[6] = utils::value_of(map);
3535
}
3636

37+
enum class ObjectMode {
38+
NORMAL,
39+
SEMI_TRANSPARENT,
40+
OBJECT_WINDOW,
41+
};
42+
43+
enum class ObjectColorMode {
44+
COLORS_16,
45+
COLORS_256,
46+
};
47+
48+
enum class ObjectShape {
49+
SQUARE,
50+
HORIZONTAL,
51+
VERTICAL,
52+
};
53+
54+
enum class ObjectSize {
55+
TINY,
56+
SMALL,
57+
MEDIUM,
58+
BIG,
59+
};
60+
61+
enum class ObjectPriority {
62+
HIGHEST,
63+
HIGH,
64+
LOW,
65+
LOWEST,
66+
};
67+
68+
struct OAMEntry {
69+
gba::utils::bitset<uint16_t> attr0;
70+
gba::utils::bitset<uint16_t> attr1;
71+
gba::utils::bitset<uint16_t> attr2;
72+
uint16_t _unused;
73+
74+
auto set_x(int y) -> void {
75+
attr1 = (attr1.to_ulong() & ~0b11111111) | (y & 0b11111111);
76+
}
77+
78+
auto set_y(int y) -> void {
79+
attr0 = (attr0.to_ulong() & ~0b11111111) | (y & 0b11111111);
80+
}
81+
82+
auto rotation_scaling(bool enabled) -> void {
83+
attr0[8] = enabled;
84+
}
85+
86+
auto visible(bool visible) -> void {
87+
attr0[9] = not visible;
88+
}
89+
90+
auto mode(ObjectMode mode) -> void {
91+
attr0 = (attr0.to_ulong() & ~0b110000000000) |
92+
(utils::value_of(mode) << 10);
93+
}
94+
95+
auto mosaic(bool enabled) -> void {
96+
attr0[12] = enabled;
97+
}
98+
99+
auto color_mode(ObjectColorMode mode) -> void {
100+
attr0[13] = utils::value_of(mode);
101+
}
102+
103+
auto shape(ObjectShape shape) -> void {
104+
attr0 = (attr0.to_ulong() & 0b0011111111111111) |
105+
(utils::value_of(shape) << 14);
106+
}
107+
108+
auto size(ObjectSize size) -> void {
109+
attr1 = (attr1.to_ulong() & 0b0011111111111111) |
110+
(utils::value_of(size) << 14);
111+
}
112+
113+
auto flip_horizontally(bool flip) -> void {
114+
attr1[12] = flip;
115+
}
116+
117+
auto flip_vertically(bool flip) -> void {
118+
attr1[13] = flip;
119+
}
120+
121+
auto tile(int index) -> void {
122+
attr2 = (attr2.to_ulong() & ~0b111111111) | (index & 0b111111111);
123+
}
124+
125+
auto priority(ObjectPriority priority) -> void {
126+
attr2 = (attr2.to_ulong() & ~0b11000000000) |
127+
(utils::value_of(priority) << 10);
128+
}
129+
130+
auto palette(int index) -> void {
131+
attr2 = (attr2.to_ulong() & ~(0xff << 12)) | ((index & 0xff) << 12);
132+
}
133+
};
134+
135+
auto oam_entry(int index) -> OAMEntry&;
136+
137+
auto sprite_tile(int index) -> gba::display::map::Tile&;
138+
37139
}
38140

39141
#endif

libgba-cpp/arch/display/tilemap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class Tile {
4040
Tile() = default;
4141

4242
Tile(std::array<uint32_t, 8> rows):
43-
rows_{move(rows)}
43+
rows_{std::move(rows)}
4444
{}
4545

4646
/**

0 commit comments

Comments
 (0)