jabyengine/include/PSX/System/IOPorts/gpu_io.hpp

213 lines
8.1 KiB
C++

#ifndef __JABYENGINE_GPU_IO_HPP__
#define __JABYENGINE_GPU_IO_HPP__
#include "ioport.hpp"
#include "../../GPU/gpu_types.hpp"
#include <stdio.h>
namespace JabyEngine {
namespace GPU_IO {
enum struct SemiTransparency {
B_Half_add_F_Half = 0,
B_add_F = 1,
B_sub_F = 2,
B_add_F_Quarter = 3,
};
enum struct DisplayAreaColorDepth {
$15bit = 0,
$24bit = 1,
};
enum struct TexturePageColor {
$4bit = 0,
$8bit = 1,
$15bit = 2,
};
enum struct HorizontalResolution {
$256 = 0,
$320 = 1,
$512 = 2,
$640 = 3,
};
enum struct VerticalResolution {
$240 = 0,
$480 = 1
};
enum struct DMADirection {
Off = 0,
Fifo = 1,
CPU2GPU = 2,
GPU2CPU = 3,
};
enum struct DisplayState {
On = 0,
Off = 1
};
__declare_io_type(DisplayMode, uint32_t,
enum struct TVEncoding {
NTSC = 0,
PAL = 1,
};
static constexpr auto HorizontalResolution368 = Bit(6);
static constexpr auto VerticalInterlace = Bit(5);
static constexpr auto DisplayAreaColorDepth = BitRange::from_to(4, 4);
static constexpr auto VideoMode = BitRange::from_to(3, 3);
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(
HorizontalResolution.with(GPU_IO::HorizontalResolution::$320),
VerticalResolution.with(GPU_IO::VerticalResolution::$240),
VideoMode.with(TVEncoding::PAL),
DisplayAreaColorDepth.with(GPU_IO::DisplayAreaColorDepth::$15bit)
);
}
static constexpr Self NTSC() {
return Self::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,
);
struct Command {
struct Helper {
static constexpr GP0_t 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 GP0_t::from(Command.with(code), Y.with(y), X.with(x));
}
static constexpr uint32_t construct_cmd(uint8_t cmd, uint32_t value) {
return ((cmd << 24) | value);
}
};
static constexpr GP0_t QuickFill(GPU::Color24 color) {
return {(0x02 << 24) | color.raw()};
}
static constexpr GP0_t VRAM2VRAM_Blitting() {
return {(0b100u << 29)};
}
static constexpr GP0_t CPU2VRAM_Blitting() {
return {(0b101u << 29)};
}
static constexpr GP0_t DrawAreaTopLeft(uint16_t x, uint16_t y) {
return Helper::DrawAreaTemplate(0xE3, x, y);
}
static constexpr GP0_t DrawAreaBottomRight(uint16_t x, uint16_t y) {
return Helper::DrawAreaTemplate(0xE4, x, y);
}
static constexpr GP0_t TopLeftPosition(uint16_t x, uint16_t y) {
return {static_cast<uint32_t>((y << 16u) | x)};
}
static constexpr GP0_t WidthHeight(uint16_t w, uint16_t h) {
return {static_cast<uint32_t>((h << 16u) | w)};
}
static constexpr GP1_t Reset() {
return {0};
}
static constexpr GP1_t ResetCMDBufer() {
return {Helper::construct_cmd(0x01, 0)};
}
static constexpr GP1_t SetDisplayState(DisplayState state) {
return {Helper::construct_cmd(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 GP1_t DisplayArea(uint32_t x, uint32_t y) {
constexpr auto X = BitRange::from_to(0, 9);
constexpr auto Y = BitRange::from_to(10, 18);
return {Helper::construct_cmd(0x05, X.as_value(x) | Y.as_value(y))};
}
static constexpr GP1_t HorizontalDisplayRange(uint32_t x1, uint32_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(x1) | X2.as_value(x2))};
}
static constexpr GP1_t VerticalDisplayRange(uint32_t y1, uint32_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(y1) | Y2.as_value(y2))};
}
static constexpr GP1_t DisplayMode(DisplayMode_t mode) {
return {Helper::construct_cmd(0x08, mode)};
}
};
__declare_io_type(GPUSTAT, uint32_t,
static constexpr auto DrawingOddLinesInterlaced = Bit(31);
static constexpr auto DMADirectionValue = BitRange::from_to(29, 30);
static constexpr auto DMAReady = Bit(28);
static constexpr auto VRAMtoCPUtransferReay = Bit(27);
static constexpr auto GP0ReadyForCMD = Bit(26);
static constexpr auto FifoNotFull = Bit(25); // Only for Fifo
static constexpr auto InterruptRequest = Bit(24);
static constexpr auto DisplayDisabled = Bit(23);
static constexpr auto VerticalInterlaceOn = Bit(22);
static constexpr auto DisplayAreaColorDepth = BitRange::from_to(21, 21);
static constexpr auto VideoModePal = Bit(20);
static constexpr auto VerticalResolutionValue = BitRange::from_to(19, 19);
static constexpr auto HorizontalResolutionValue = BitRange::from_to(17, 18);
static constexpr auto HorizontalResolution368 = Bit(16);
static constexpr auto TexturesDisabled = Bit(15);
static constexpr auto NotDrawingMaskedPixels = Bit(12);
static constexpr auto MaskBitSetDuringDrawEnabled = Bit(11);
static constexpr auto DrawingToDisplayAreadAllowed = Bit(10);
static constexpr auto DitherEnabled = Bit(9);
static constexpr auto TexturePageColorValue = BitRange::from_to(7, 8);
static constexpr auto SemiTransparencyValue = BitRange::from_to(5, 6);
static constexpr auto TexturePageY = BitRange::from_to(4, 4); // N*256
static constexpr auto TexturePageX = BitRange::from_to(0, 3); // N*64
static constexpr auto VerticalResolution480 = Bit(19);
static constexpr auto TexturePageY256 = Bit(4);
);
typedef volatile uint32_t GPUREAD_v;
__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);
}
}
#endif //!__JABYENGINE_GPU_IO_HPP__