Port GPU IO
This commit is contained in:
@@ -35,7 +35,7 @@ namespace JabyEngine {
|
||||
Off = 1
|
||||
};
|
||||
|
||||
__declare_io_type(DisplayMode, uint32_t,
|
||||
__new_declare_io_value(DisplayMode, uint32_t) {
|
||||
enum struct TVEncoding {
|
||||
NTSC = 0,
|
||||
PAL = 1,
|
||||
@@ -48,8 +48,8 @@ namespace JabyEngine {
|
||||
static constexpr auto VerticalResolution = BitRange::from_to(2, 2);
|
||||
static constexpr auto HorizontalResolution = BitRange::from_to(0, 1);
|
||||
|
||||
static constexpr Self PAL() {
|
||||
return Self::from(
|
||||
static constexpr DisplayMode PAL() {
|
||||
return DisplayMode::from(
|
||||
HorizontalResolution.with(GPU_IO::HorizontalResolution::$320),
|
||||
VerticalResolution.with(GPU_IO::VerticalResolution::$240),
|
||||
VideoMode.with(TVEncoding::PAL),
|
||||
@@ -57,51 +57,55 @@ namespace JabyEngine {
|
||||
);
|
||||
}
|
||||
|
||||
static constexpr Self NTSC() {
|
||||
return Self::from(
|
||||
static constexpr DisplayMode NTSC() {
|
||||
return DisplayMode::from(
|
||||
HorizontalResolution.with(GPU_IO::HorizontalResolution::$320),
|
||||
VerticalResolution.with(GPU_IO::VerticalResolution::$240),
|
||||
VideoMode.with(TVEncoding::NTSC),
|
||||
DisplayAreaColorDepth.with(GPU_IO::DisplayAreaColorDepth::$15bit)
|
||||
);
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
__declare_io_type(GP0, uint32_t,
|
||||
);
|
||||
|
||||
__declare_io_type(GP1, uint32_t,
|
||||
);
|
||||
__new_declare_io_value(GP0, uint32_t) {
|
||||
static constexpr auto ID = BitRange::from_to(24, 31);
|
||||
static constexpr auto Value = BitRange::from_to(0, 23);
|
||||
};
|
||||
|
||||
__new_declare_io_value(GP1, uint32_t) {
|
||||
static constexpr auto ID = BitRange::from_to(24, 31);
|
||||
static constexpr auto Value = BitRange::from_to(0, 23);
|
||||
};
|
||||
|
||||
struct Command {
|
||||
struct Helper {
|
||||
static constexpr uint32_t construct_cmd(uint8_t cmd, uint32_t value) {
|
||||
return ((cmd << 24) | value);
|
||||
template<typename T>
|
||||
static constexpr T construct_cmd(uint32_t cmd, uint32_t value) {
|
||||
return T::from(T::ID.with(cmd), T::Value.with(value));
|
||||
}
|
||||
|
||||
static constexpr GP0_t DrawAreaTemplate(uint8_t code, uint16_t x, uint16_t y) {
|
||||
static constexpr struct GP0 DrawAreaTemplate(uint8_t code, uint16_t x, uint16_t y) {
|
||||
constexpr auto Command = BitRange::from_to(24, 31);
|
||||
constexpr auto Y = BitRange::from_to(10, 18);
|
||||
constexpr auto X = BitRange::from_to(0, 9);
|
||||
|
||||
return {construct_cmd(code, Y.as_value(static_cast<uint32_t>(y)) | X.as_value(static_cast<uint32_t>(x)))};
|
||||
return construct_cmd<struct GP0>(code, Y.as_value(static_cast<uint32_t>(y)) | X.as_value(static_cast<uint32_t>(x)));
|
||||
}
|
||||
};
|
||||
|
||||
static constexpr GP0_t QuickFill(GPU::Color24 color) {
|
||||
return {(0x02 << 24) | color.raw()};
|
||||
static constexpr struct GP0 QuickFill(GPU::Color24 color) {
|
||||
return Helper::construct_cmd<struct GP0>(0x02, color.raw());
|
||||
}
|
||||
|
||||
static constexpr GP0_t VRAM2VRAM_Blitting() {
|
||||
return {(0b100u << 29)};
|
||||
static constexpr struct GP0 VRAM2VRAM_Blitting() {
|
||||
return Helper::construct_cmd<struct GP0>(0x80, 0);
|
||||
}
|
||||
|
||||
static constexpr GP0_t CPU2VRAM_Blitting() {
|
||||
return {(0b101u << 29)};
|
||||
static constexpr struct GP0 CPU2VRAM_Blitting() {
|
||||
return Helper::construct_cmd<struct GP0>(0xA0, 0);
|
||||
}
|
||||
|
||||
static constexpr GP0_t TexPage(const GPU::PositionU16& page_pos, GPU::SemiTransparency transparency, GPU::TexturePageColor tex_color, bool dither, bool draw_on_display_area) {
|
||||
static constexpr struct GP0 TexPage(const GPU::PositionU16& page_pos, GPU::SemiTransparency transparency, GPU::TexturePageColor tex_color, bool dither, bool draw_on_display_area) {
|
||||
constexpr auto TexXRange = BitRange::from_to(0, 3);
|
||||
constexpr auto TexYRange = BitRange::from_to(4, 4);
|
||||
constexpr auto TransparencyRange = BitRange::from_to(5, 6);
|
||||
@@ -109,79 +113,79 @@ namespace JabyEngine {
|
||||
constexpr auto DitherBit = BitRange::from_to(9, 9);
|
||||
constexpr auto DrawOnDisplayAreaBit = BitRange::from_to(10, 10);
|
||||
|
||||
return {Helper::construct_cmd(0xE1,
|
||||
return Helper::construct_cmd<struct GP0>(0xE1,
|
||||
TexXRange.as_value(page_pos.x >> 6) | TexYRange.as_value(page_pos.y >> 7) |
|
||||
TransparencyRange.as_value(static_cast<uint32_t>(transparency)) | TextureColorRange.as_value(static_cast<uint32_t>(tex_color)) |
|
||||
DitherBit.as_value(static_cast<uint32_t>(dither)) | DrawOnDisplayAreaBit.as_value(static_cast<uint32_t>(draw_on_display_area))
|
||||
)};
|
||||
);
|
||||
}
|
||||
|
||||
static constexpr GP0_t DrawAreaTopLeft(const GPU::PositionU16& position) {
|
||||
static constexpr struct GP0 DrawAreaTopLeft(const GPU::PositionU16& position) {
|
||||
return Helper::DrawAreaTemplate(0xE3, position.x, position.y);
|
||||
}
|
||||
|
||||
static constexpr GP0_t DrawAreaBottomRight(const GPU::PositionU16& position) {
|
||||
static constexpr struct GP0 DrawAreaBottomRight(const GPU::PositionU16& position) {
|
||||
return Helper::DrawAreaTemplate(0xE4, position.x, position.y);
|
||||
}
|
||||
|
||||
static constexpr GP0_t SetDrawOffset(const GPU::PositionI16& offset) {
|
||||
static constexpr struct GP0 SetDrawOffset(const GPU::PositionI16& offset) {
|
||||
constexpr auto X = BitRange::from_to(0, 10);
|
||||
constexpr auto Y = BitRange::from_to(11, 21);
|
||||
|
||||
return {Helper::construct_cmd(0xE5, X.as_value(static_cast<int32_t>(offset.x)) | Y.as_value(static_cast<int32_t>(offset.y)))};
|
||||
return Helper::construct_cmd<struct GP0>(0xE5, X.as_value(static_cast<int32_t>(offset.x)) | Y.as_value(static_cast<int32_t>(offset.y)));
|
||||
}
|
||||
|
||||
static constexpr GP0_t TopLeftPosition(const GPU::PositionU16& position) {
|
||||
static constexpr struct GP0 TopLeftPosition(const GPU::PositionU16& position) {
|
||||
return {(static_cast<uint32_t>(position.y) << 16u) | position.x};
|
||||
}
|
||||
|
||||
static constexpr GP0_t WidthHeight(const GPU::SizeU16& size) {
|
||||
static constexpr struct GP0 WidthHeight(const GPU::SizeU16& size) {
|
||||
return {(static_cast<uint32_t>(size.height) << 16u) | size.width};
|
||||
}
|
||||
|
||||
static constexpr GP1_t Reset() {
|
||||
static constexpr struct GP1 Reset() {
|
||||
return {0};
|
||||
}
|
||||
|
||||
static constexpr GP1_t ResetCMDBufer() {
|
||||
return {Helper::construct_cmd(0x01, 0)};
|
||||
static constexpr struct GP1 ResetCMDBufer() {
|
||||
return Helper::construct_cmd<struct GP1>(0x01, 0);
|
||||
}
|
||||
|
||||
static constexpr GP1_t SetDisplayState(DisplayState state) {
|
||||
return {Helper::construct_cmd(0x03, static_cast<uint32_t>(state))};
|
||||
static constexpr struct GP1 SetDisplayState(DisplayState state) {
|
||||
return Helper::construct_cmd<struct GP1>(0x03, static_cast<uint32_t>(state));
|
||||
}
|
||||
|
||||
static constexpr GP1_t DMADirection(DMADirection dir) {
|
||||
return {Helper::construct_cmd(0x04, static_cast<uint32_t>(dir))};
|
||||
static constexpr struct GP1 DMADirection(DMADirection dir) {
|
||||
return Helper::construct_cmd<struct GP1>(0x04, static_cast<uint32_t>(dir));
|
||||
}
|
||||
|
||||
static constexpr GP1_t DisplayArea(const GPU::PositionU16& position) {
|
||||
static constexpr struct GP1 DisplayArea(const GPU::PositionU16& position) {
|
||||
constexpr auto X = BitRange::from_to(0, 9);
|
||||
constexpr auto Y = BitRange::from_to(10, 18);
|
||||
|
||||
return {Helper::construct_cmd(0x05, X.as_value(static_cast<uint32_t>(position.x)) | Y.as_value(static_cast<uint32_t>(position.y)))};
|
||||
return Helper::construct_cmd<struct GP1>(0x05, X.as_value(static_cast<uint32_t>(position.x)) | Y.as_value(static_cast<uint32_t>(position.y)));
|
||||
}
|
||||
|
||||
static constexpr GP1_t HorizontalDisplayRange(uint16_t x1, uint16_t x2) {
|
||||
static constexpr struct GP1 HorizontalDisplayRange(uint16_t x1, uint16_t x2) {
|
||||
constexpr auto X1 = BitRange::from_to(0, 11);
|
||||
constexpr auto X2 = BitRange::from_to(12, 23);
|
||||
|
||||
return {Helper::construct_cmd(0x06, X1.as_value(static_cast<uint32_t>(x1)) | X2.as_value(static_cast<uint32_t>(x2)))};
|
||||
return Helper::construct_cmd<struct GP1>(0x06, X1.as_value(static_cast<uint32_t>(x1)) | X2.as_value(static_cast<uint32_t>(x2)));
|
||||
}
|
||||
|
||||
static constexpr GP1_t VerticalDisplayRange(uint16_t y1, uint16_t y2) {
|
||||
static constexpr struct GP1 VerticalDisplayRange(uint16_t y1, uint16_t y2) {
|
||||
constexpr auto Y1 = BitRange::from_to(0, 9);
|
||||
constexpr auto Y2 = BitRange::from_to(10, 19);
|
||||
|
||||
return {Helper::construct_cmd(0x07, Y1.as_value(static_cast<uint32_t>(y1)) | Y2.as_value(static_cast<uint32_t>(y2)))};
|
||||
return Helper::construct_cmd<struct GP1>(0x07, Y1.as_value(static_cast<uint32_t>(y1)) | Y2.as_value(static_cast<uint32_t>(y2)));
|
||||
}
|
||||
|
||||
static constexpr GP1_t DisplayMode(DisplayMode_t mode) {
|
||||
return {Helper::construct_cmd(0x08, mode)};
|
||||
static constexpr struct GP1 DisplayMode(DisplayMode mode) {
|
||||
return Helper::construct_cmd<struct GP1>(0x08, mode.raw);
|
||||
}
|
||||
};
|
||||
|
||||
__declare_io_type(GPUSTAT, uint32_t,
|
||||
__new_declare_io_value(GPUSTAT, uint32_t) {
|
||||
static constexpr auto DrawingOddLinesInterlaced = Bit(31);
|
||||
static constexpr auto DMADirectionValue = BitRange::from_to(29, 30);
|
||||
static constexpr auto DMAReady = Bit(28);
|
||||
@@ -208,15 +212,13 @@ namespace JabyEngine {
|
||||
|
||||
static constexpr auto VerticalResolution480 = Bit(19);
|
||||
static constexpr auto TexturePageY256 = Bit(4);
|
||||
);
|
||||
};
|
||||
|
||||
typedef volatile uint32_t GPUREAD_v;
|
||||
__new_declare_io_port(, GP0, 0x1F801810);
|
||||
__new_declare_io_port(, GP1, 0x1F801814);
|
||||
|
||||
__declare_new_io_port(GP0, 0x1F801810);
|
||||
__declare_new_io_port(GP1, 0x1F801814);
|
||||
|
||||
__declare_new_const_io_port(GPUREAD, 0x1F801810);
|
||||
__declare_new_const_io_port(GPUSTAT, 0x1F801814);
|
||||
__new_declare_io_port(const, GPUREAD, 0x1F801810);
|
||||
__new_declare_io_port(const, GPUSTAT, 0x1F801814);
|
||||
}
|
||||
}
|
||||
#endif //!__JABYENGINE_GPU_IO_HPP__
|
Reference in New Issue
Block a user