Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mode0 pong example #20

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ DisableFormat: false
EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: LogicalBlock
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
FixNamespaceComments: false
ForEachMacros:
- foreach
- Q_FOREACH
Expand Down Expand Up @@ -158,7 +158,7 @@ PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyIndentedWhitespace: 0
PenaltyReturnTypeOnItsOwnLine: 60
PenaltyReturnTypeOnItsOwnLine: 1000000
PointerAlignment: Left
PPIndentWidth: -1
QualifierAlignment: Leave
Expand All @@ -180,8 +180,8 @@ SpaceAroundPointerQualifiers: Default
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeCtorInitializerColon: false
SpaceBeforeInheritanceColon: false
SpaceBeforeParens: ControlStatements
SpaceBeforeParensOptions:
AfterControlStatements: true
Expand Down
1 change: 1 addition & 0 deletions .clangd
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ CompileFlags:
-I/opt/devkitpro/devkitARM/arm-none-eabi/include,
-I/opt/devkitpro/devkitARM/arm-none-eabi/include/c++/13.2.0/arm-none-eabi/,
]
Remove: [-mthumb-interwork]
2 changes: 1 addition & 1 deletion libgba-cpp/arch/cpu/interrupts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ auto& register_at(uint16_t address) {
}

void set_interrupt_bit(Handler handler, bool enabled) {
const auto& sender = senders[utils::value_of(handler.type)];
const auto& sender = senders[gba::utils::value_of(handler.type)];
register_at(sender.offset)[sender.bit] = enabled;
}

Expand Down
10 changes: 5 additions & 5 deletions libgba-cpp/arch/display/layers.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <libgba-cpp/arch/display/layers.h>

#include <libgba-cpp/arch/registers.h>
#include <libgba-cpp/utils/general.h>

Expand All @@ -8,15 +7,16 @@ namespace {
using gba::display::BackgroundControl;
using gba::display::RawPalette;

using gba::arch::registers::display::bg_controls;

static auto const bg_address = reinterpret_cast<RawPalette<256>*>(0x0500'0000);
static auto& bg_palette = *new (bg_address) RawPalette<256>{};

}
} // namespace

BackgroundControl& gba::display::bg_control(gba::display::Layer layer) {
return *(reinterpret_cast<BackgroundControl*>(0x0400'0008) + utils::value_of(layer));
return *(
reinterpret_cast<BackgroundControl*>(0x0400'0008) +
utils::value_of(layer)
);
}

RawPalette<256>& gba::display::bg_palette() {
Expand Down
2 changes: 1 addition & 1 deletion libgba-cpp/arch/display/layers.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ enum class MapSize {
};


constexpr geometry::Size extract_size(MapSize size) {
constexpr auto get_size_values(MapSize size) -> geometry::Size {
switch (size) {
case MapSize::TEXT_256X256:
return {256, 256};
Expand Down
23 changes: 16 additions & 7 deletions libgba-cpp/arch/display/objects.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
#include <libgba-cpp/arch/display/objects.h>
#include <libgba-cpp/arch/display/tilemap.h>

using gba::display::Color;
using gba::display::RawPalette;

namespace {

static auto const obj_palette_address = reinterpret_cast<RawPalette<256>*>(0x0500'0200);
static auto& obj_palette =
*new (obj_palette_address) RawPalette<256>{};
static auto const obj_palette_address =
reinterpret_cast<RawPalette<256>*>(0x0500'0200);
static auto& obj_palette = *new (obj_palette_address) RawPalette<256>{};

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

namespace gba {
} // namespace

RawPalette<256>& display::obj_palette() {
auto gba::display::obj_palette() -> RawPalette<256>& {
return ::obj_palette;
}

auto gba::display::oam_entry(int index) -> OAMEntry& {
return ::oam[index];
}

auto gba::display::sprite_tile(int index) -> gba::display::map::Tile& {
return sprite_tiles[index];
};
116 changes: 109 additions & 7 deletions libgba-cpp/arch/display/objects.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#ifndef GBA_DRIVERS_DISPLAY_OBJ_H
#define GBA_DRIVERS_DISPLAY_OBJ_H

#include <libgba-cpp/arch/display/tilemap.h>
#include <libgba-cpp/arch/display/video.h>
#include <libgba-cpp/utils/bitset.h>

namespace gba::display {

Expand All @@ -10,22 +12,20 @@ namespace gba::display {
*/
enum class ObjectMapping {
/**
* Object data as unidimensional array.
* Object data as tile matrix.
*/
MAP_ARRAY,
MAP_TILE_MATRIX,

/**
* Object data as tile matrix.
* Object data as unidimensional array.
*/
MAP_TILE_MATRIX,
MAP_ARRAY,
};


/**
* Object Color Palette array.
*/
RawPalette<256>& obj_palette();

auto obj_palette() -> RawPalette<256>&;

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

enum class ObjectMode {
NORMAL,
SEMI_TRANSPARENT,
OBJECT_WINDOW,
};

enum class ObjectColorMode {
COLORS_16,
COLORS_256,
};

enum class ObjectShape {
SQUARE,
HORIZONTAL,
VERTICAL,
};

enum class ObjectSize {
TINY,
SMALL,
MEDIUM,
BIG,
};

enum class ObjectPriority {
HIGHEST,
HIGH,
LOW,
LOWEST,
};

struct OAMEntry {
gba::utils::bitset<uint16_t> attr0;
gba::utils::bitset<uint16_t> attr1;
gba::utils::bitset<uint16_t> attr2;
uint16_t _unused;

auto set_x(int y) -> void {
attr1 = (attr1.to_ulong() & ~0b11111111) | (y & 0b11111111);
}

auto set_y(int y) -> void {
attr0 = (attr0.to_ulong() & ~0b11111111) | (y & 0b11111111);
}

auto rotation_scaling(bool enabled) -> void {
attr0[8] = enabled;
}

auto visible(bool visible) -> void {
attr0[9] = not visible;
}

auto mode(ObjectMode mode) -> void {
attr0 = (attr0.to_ulong() & ~0b110000000000) |
(utils::value_of(mode) << 10);
}

auto mosaic(bool enabled) -> void {
attr0[12] = enabled;
}

auto color_mode(ObjectColorMode mode) -> void {
attr0[13] = utils::value_of(mode);
}

auto shape(ObjectShape shape) -> void {
attr0 = (attr0.to_ulong() & 0b0011111111111111) |
(utils::value_of(shape) << 14);
}

auto size(ObjectSize size) -> void {
attr1 = (attr1.to_ulong() & 0b0011111111111111) |
(utils::value_of(size) << 14);
}

auto flip_horizontally(bool flip) -> void {
attr1[12] = flip;
}

auto flip_vertically(bool flip) -> void {
attr1[13] = flip;
}

auto base_tile(int index) -> void {
attr2 = (attr2.to_ulong() & ~0b111111111) | (index & 0b111111111);
}

auto priority(ObjectPriority priority) -> void {
attr2 = (attr2.to_ulong() & ~0b11000000000) |
(utils::value_of(priority) << 10);
}

auto palette(int index) -> void {
attr2 = (attr2.to_ulong() & ~(0xff << 12)) | ((index & 0xff) << 12);
}
};

auto oam_entry(int index) -> OAMEntry&;

auto sprite_tile(int index) -> gba::display::map::Tile&;

}

#endif
2 changes: 1 addition & 1 deletion libgba-cpp/arch/display/tilemap.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Tile {
Tile() = default;

Tile(std::array<uint32_t, 8> rows):
rows_{move(rows)}
rows_{std::move(rows)}
{}

/**
Expand Down
6 changes: 3 additions & 3 deletions libgba-cpp/arch/display/video.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,14 @@ class Color {
/**
* Constructs black color.
*/
Color() = default;
constexpr Color() = default;

/**
* Constructs color from specified value.
*
* @param value Value (in X1B5G5R5 format).
*/
Color(unsigned value):
constexpr Color(unsigned value):
value_{static_cast<uint16_t>(value)}
{}

Expand All @@ -113,7 +113,7 @@ class Color {
* @param g Green channel intensity.
* @param b Blue channel intensity.
*/
Color(int r, int g, int b):
constexpr Color(int r, int g, int b):
value_{static_cast<uint16_t>(
((r & 0x1f) << 0) |
((g & 0x1f) << 5) |
Expand Down
Loading