Fix inconsistent EOL
This commit is contained in:
@@ -1,106 +1,106 @@
|
||||
#pragma once
|
||||
#include "ioport.hpp"
|
||||
|
||||
namespace JabyEngine {
|
||||
namespace CD_IO_Values {
|
||||
__declare_io_struct(AudioVolumeApply, uint8_t) {
|
||||
static constexpr auto Mute = Bit(0);
|
||||
static constexpr auto ApplyChanges = Bit(5);
|
||||
};
|
||||
|
||||
struct CDDAVolume {
|
||||
using Type = uint8_t;
|
||||
|
||||
static constexpr uint8_t Off = 0x0;
|
||||
static constexpr uint8_t Default = 0x80;
|
||||
static constexpr uint8_t Max = 0xFF;
|
||||
};
|
||||
|
||||
__declare_io_struct(CommandFifo, uint8_t) {
|
||||
};
|
||||
|
||||
__declare_io_struct(DataFifo, uint8_t) {
|
||||
};
|
||||
|
||||
__declare_io_struct(DataFifo16, uint16_t) {
|
||||
};
|
||||
|
||||
__declare_io_struct(InterruptEnable, uint8_t) {
|
||||
static constexpr auto InterruptTypValue = BitRange::from_to(0, 2);
|
||||
static constexpr auto InterruptExtended = BitRange::from_to(0, 4);
|
||||
static constexpr auto UnknownIRQ = Bit(3);
|
||||
static constexpr auto CommandStartIRQ = Bit(4);
|
||||
};
|
||||
using InterruptFlag = InterruptEnable;
|
||||
|
||||
__declare_io_struct(IndexStatus, uint8_t) {
|
||||
static constexpr auto PortIndex = BitRange::from_to(0, 1);
|
||||
static constexpr auto HasXAFifoData = Bit(2);
|
||||
static constexpr auto IsParameterFifoEmpty = Bit(3);
|
||||
static constexpr auto HasParameterFifoSpace = Bit(4);
|
||||
static constexpr auto HasResponseFifoData = Bit(5);
|
||||
static constexpr auto HasDataFifoData = Bit(6);
|
||||
static constexpr auto IsTransmissionBusy = Bit(7);
|
||||
};
|
||||
|
||||
__declare_io_struct(LeftCD2LeftSPU, CDDAVolume::Type) {
|
||||
};
|
||||
|
||||
__declare_io_struct(LeftCD2RightSPU, CDDAVolume::Type) {
|
||||
};
|
||||
|
||||
__declare_io_struct(Mode, uint8_t) {
|
||||
static constexpr auto DoubleSpeed = Bit(7);
|
||||
static constexpr auto SingleSpeed = !DoubleSpeed;
|
||||
static constexpr auto XADPCM = Bit(6);
|
||||
static constexpr auto WholeSector = Bit(5);
|
||||
static constexpr auto DataSector = !WholeSector;
|
||||
static constexpr auto UseXAFilter = Bit(3);
|
||||
static constexpr auto AudioPlayIRQ = Bit(2);
|
||||
static constexpr auto AutoPauseTrack = Bit(1);
|
||||
static constexpr auto CDDA = Bit(0);
|
||||
|
||||
operator uint8_t() const {
|
||||
return this->raw;
|
||||
}
|
||||
};
|
||||
|
||||
__declare_io_struct(ParameterFifo, uint8_t) {
|
||||
};
|
||||
|
||||
__declare_io_struct(Request, uint8_t) {
|
||||
static constexpr auto WantCommandStartIRQ = Bit(5);
|
||||
static constexpr auto WantData = Bit(7);
|
||||
|
||||
static Request want_data() {
|
||||
return Request{static_cast<uint8_t>(Request::WantData)};
|
||||
}
|
||||
|
||||
static Request reset() {
|
||||
return Request{0};
|
||||
}
|
||||
};
|
||||
|
||||
__declare_io_struct(ResponseFifo, uint8_t) {
|
||||
};
|
||||
|
||||
__declare_io_struct(RightCD2LeftSPU, CDDAVolume::Type) {
|
||||
};
|
||||
|
||||
__declare_io_struct(RightCD2RightSPU, CDDAVolume::Type) {
|
||||
};
|
||||
|
||||
__declare_io_struct(SoundMapCoding, uint8_t) {
|
||||
static constexpr auto Stereo = Bit(0);
|
||||
static constexpr auto Mono = !Stereo;
|
||||
static constexpr auto SampleRate_18900hz = Bit(2);
|
||||
static constexpr auto SampleRate_37800hz = !SampleRate_18900hz;
|
||||
static constexpr auto BitsPerSample8 = Bit(4);
|
||||
static constexpr auto BitsPerSample4 = !BitsPerSample8;
|
||||
static constexpr auto Emphasis = Bit(6);
|
||||
};
|
||||
|
||||
__declare_io_struct(SoundMapDataOut, uint8_t) {
|
||||
};
|
||||
}
|
||||
#pragma once
|
||||
#include "ioport.hpp"
|
||||
|
||||
namespace JabyEngine {
|
||||
namespace CD_IO_Values {
|
||||
__declare_io_struct(AudioVolumeApply, uint8_t) {
|
||||
static constexpr auto Mute = Bit(0);
|
||||
static constexpr auto ApplyChanges = Bit(5);
|
||||
};
|
||||
|
||||
struct CDDAVolume {
|
||||
using Type = uint8_t;
|
||||
|
||||
static constexpr uint8_t Off = 0x0;
|
||||
static constexpr uint8_t Default = 0x80;
|
||||
static constexpr uint8_t Max = 0xFF;
|
||||
};
|
||||
|
||||
__declare_io_struct(CommandFifo, uint8_t) {
|
||||
};
|
||||
|
||||
__declare_io_struct(DataFifo, uint8_t) {
|
||||
};
|
||||
|
||||
__declare_io_struct(DataFifo16, uint16_t) {
|
||||
};
|
||||
|
||||
__declare_io_struct(InterruptEnable, uint8_t) {
|
||||
static constexpr auto InterruptTypValue = BitRange::from_to(0, 2);
|
||||
static constexpr auto InterruptExtended = BitRange::from_to(0, 4);
|
||||
static constexpr auto UnknownIRQ = Bit(3);
|
||||
static constexpr auto CommandStartIRQ = Bit(4);
|
||||
};
|
||||
using InterruptFlag = InterruptEnable;
|
||||
|
||||
__declare_io_struct(IndexStatus, uint8_t) {
|
||||
static constexpr auto PortIndex = BitRange::from_to(0, 1);
|
||||
static constexpr auto HasXAFifoData = Bit(2);
|
||||
static constexpr auto IsParameterFifoEmpty = Bit(3);
|
||||
static constexpr auto HasParameterFifoSpace = Bit(4);
|
||||
static constexpr auto HasResponseFifoData = Bit(5);
|
||||
static constexpr auto HasDataFifoData = Bit(6);
|
||||
static constexpr auto IsTransmissionBusy = Bit(7);
|
||||
};
|
||||
|
||||
__declare_io_struct(LeftCD2LeftSPU, CDDAVolume::Type) {
|
||||
};
|
||||
|
||||
__declare_io_struct(LeftCD2RightSPU, CDDAVolume::Type) {
|
||||
};
|
||||
|
||||
__declare_io_struct(Mode, uint8_t) {
|
||||
static constexpr auto DoubleSpeed = Bit(7);
|
||||
static constexpr auto SingleSpeed = !DoubleSpeed;
|
||||
static constexpr auto XADPCM = Bit(6);
|
||||
static constexpr auto WholeSector = Bit(5);
|
||||
static constexpr auto DataSector = !WholeSector;
|
||||
static constexpr auto UseXAFilter = Bit(3);
|
||||
static constexpr auto AudioPlayIRQ = Bit(2);
|
||||
static constexpr auto AutoPauseTrack = Bit(1);
|
||||
static constexpr auto CDDA = Bit(0);
|
||||
|
||||
operator uint8_t() const {
|
||||
return this->raw;
|
||||
}
|
||||
};
|
||||
|
||||
__declare_io_struct(ParameterFifo, uint8_t) {
|
||||
};
|
||||
|
||||
__declare_io_struct(Request, uint8_t) {
|
||||
static constexpr auto WantCommandStartIRQ = Bit(5);
|
||||
static constexpr auto WantData = Bit(7);
|
||||
|
||||
static Request want_data() {
|
||||
return Request{static_cast<uint8_t>(Request::WantData)};
|
||||
}
|
||||
|
||||
static Request reset() {
|
||||
return Request{0};
|
||||
}
|
||||
};
|
||||
|
||||
__declare_io_struct(ResponseFifo, uint8_t) {
|
||||
};
|
||||
|
||||
__declare_io_struct(RightCD2LeftSPU, CDDAVolume::Type) {
|
||||
};
|
||||
|
||||
__declare_io_struct(RightCD2RightSPU, CDDAVolume::Type) {
|
||||
};
|
||||
|
||||
__declare_io_struct(SoundMapCoding, uint8_t) {
|
||||
static constexpr auto Stereo = Bit(0);
|
||||
static constexpr auto Mono = !Stereo;
|
||||
static constexpr auto SampleRate_18900hz = Bit(2);
|
||||
static constexpr auto SampleRate_37800hz = !SampleRate_18900hz;
|
||||
static constexpr auto BitsPerSample8 = Bit(4);
|
||||
static constexpr auto BitsPerSample4 = !BitsPerSample8;
|
||||
static constexpr auto Emphasis = Bit(6);
|
||||
};
|
||||
|
||||
__declare_io_struct(SoundMapDataOut, uint8_t) {
|
||||
};
|
||||
}
|
||||
}
|
@@ -1,152 +1,152 @@
|
||||
#pragma once
|
||||
#include "ioport.hpp"
|
||||
|
||||
namespace JabyEngine {
|
||||
namespace DMA_IO_Values {
|
||||
using Priority = uint32_t;
|
||||
static constexpr Priority HighestPriority = 0;
|
||||
static constexpr Priority LowestPriority = 7;
|
||||
|
||||
__declare_io_struct(BCR, uint32_t) {
|
||||
struct SyncMode0 {
|
||||
static constexpr auto NumberOfWords = BitRange::from_to(0, 15);
|
||||
static constexpr auto CD_OneBlock = Bit(16);
|
||||
|
||||
static constexpr BCR for_cd(size_t words) {
|
||||
return BCR::from(SyncMode0::CD_OneBlock, SyncMode0::NumberOfWords.with(words));
|
||||
}
|
||||
};
|
||||
|
||||
struct SyncMode1 {
|
||||
static constexpr auto BlockSize = BitRange::from_to(0, 15);
|
||||
static constexpr auto BlockAmount = BitRange::from_to(16, 31);
|
||||
};
|
||||
|
||||
struct SyncMode2 {
|
||||
static constexpr BCR for_gpu_cmd() {
|
||||
return {0};
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
__declare_io_struct(CHCHR, uint32_t) {
|
||||
enum SyncMode_t {
|
||||
Sync0 = 0, //Start immediately,
|
||||
Sync1 = 1, //Sync blocks to DMA requests
|
||||
Sync2 = 2, //Linked List
|
||||
};
|
||||
|
||||
static constexpr auto ManualStart = Bit(28);
|
||||
|
||||
static constexpr auto Start = Bit(24);
|
||||
static constexpr auto Busy = Start;
|
||||
|
||||
static constexpr auto ChoppingCPUWindowSize = BitRange::from_to(20, 22);
|
||||
static constexpr auto ChoppingDMAWindowSize = BitRange::from_to(16, 18);
|
||||
|
||||
static constexpr auto SyncMode = BitRange::from_to(9, 10);
|
||||
static constexpr auto UseSyncMode0 = SyncMode.with(Sync0);
|
||||
static constexpr auto UseSyncMode1 = SyncMode.with(Sync1);
|
||||
static constexpr auto UseSyncMode2 = SyncMode.with(Sync2);
|
||||
|
||||
static constexpr auto UseChopping = Bit(8);
|
||||
|
||||
static constexpr auto MemoryAdrDecreaseBy4 = Bit(1);
|
||||
static constexpr auto MemoryAdrIncreaseBy4 = !MemoryAdrDecreaseBy4;
|
||||
|
||||
static constexpr auto FromMainRAM = Bit(0);
|
||||
static constexpr auto ToMainRAM = !FromMainRAM;
|
||||
|
||||
static constexpr CHCHR StartMDECin() {
|
||||
return CHCHR{0x01000201};
|
||||
}
|
||||
|
||||
static constexpr CHCHR StartMDECout() {
|
||||
return CHCHR{0x01000200};
|
||||
}
|
||||
|
||||
static constexpr CHCHR StartGPUReceive() {
|
||||
return CHCHR{0x01000201};
|
||||
}
|
||||
|
||||
static constexpr CHCHR StartGPULinked() {
|
||||
return CHCHR{0x01000401};
|
||||
}
|
||||
|
||||
static constexpr CHCHR StartCDROM() {
|
||||
return CHCHR{0x11000000};
|
||||
}
|
||||
|
||||
static constexpr CHCHR StartSPUReceive() {
|
||||
return CHCHR{0x01000201};
|
||||
}
|
||||
|
||||
static constexpr CHCHR StartOTC() {
|
||||
return CHCHR{0x11000002};
|
||||
}
|
||||
};
|
||||
|
||||
__declare_io_struct(DICR, uint32_t) {
|
||||
static constexpr auto MasterEnable = Bit(31);
|
||||
static constexpr auto Flags = BitRange::from_to(24, 30);
|
||||
static constexpr auto MasterEnableDPCR = Bit(23);
|
||||
static constexpr auto EnableDPCR = BitRange::from_to(16, 22);
|
||||
static constexpr auto ForceIRQ = Bit(15);
|
||||
|
||||
static constexpr DICR empty() {
|
||||
return DICR{0};
|
||||
}
|
||||
};
|
||||
|
||||
__declare_io_struct(DPCR, uint32_t) {
|
||||
struct DMASetting {
|
||||
uint16_t master_bit;
|
||||
|
||||
static constexpr DMASetting create(uint16_t master_bit) {
|
||||
return DMASetting{master_bit};
|
||||
}
|
||||
|
||||
constexpr BitRange::RangeValuePair<uint32_t> turn_on(uint8_t priority) const {
|
||||
return BitRange::from_to(this->master_bit - 3, this->master_bit).with(static_cast<uint32_t>(0b1000 + (priority & 0b111)));
|
||||
}
|
||||
|
||||
constexpr ClearBit turn_off() const {
|
||||
return ClearBit(this->master_bit);
|
||||
}
|
||||
};
|
||||
|
||||
static constexpr const auto OTC = DMASetting(27);
|
||||
static constexpr const auto PIO = DMASetting(23);
|
||||
static constexpr const auto SPU = DMASetting(19);
|
||||
static constexpr const auto CDROM = DMASetting(15);
|
||||
static constexpr const auto GPU = DMASetting(11);
|
||||
static constexpr const auto MDEC_Out = DMASetting(7);
|
||||
static constexpr const auto MDEC_In = DMASetting(3);
|
||||
|
||||
static constexpr auto OTCEnabled = Bit(27);
|
||||
static constexpr auto OTCPriority = BitRange::from_to(24, 26);
|
||||
|
||||
static constexpr auto PIOEnabled = Bit(23);
|
||||
static constexpr auto PIOPriority = BitRange::from_to(20, 22);
|
||||
|
||||
static constexpr auto SPUEnabled = Bit(19);
|
||||
static constexpr auto SPUPriority = BitRange::from_to(16, 18);
|
||||
|
||||
static constexpr auto CDROMEnabled = Bit(15);
|
||||
static constexpr auto CDROMPriority = BitRange::from_to(12, 14);
|
||||
|
||||
static constexpr auto GPUEnabled = Bit(11);
|
||||
static constexpr auto GPUPriority = BitRange::from_to(8, 10);
|
||||
|
||||
static constexpr auto MDECoutEnabled = Bit(7);
|
||||
static constexpr auto MDECoutPriority = BitRange::from_to(4, 6);
|
||||
|
||||
static constexpr auto MDECinEnabled = Bit(3);
|
||||
static constexpr auto MDECinPriority = BitRange::from_to(0, 2);
|
||||
};
|
||||
|
||||
__declare_io_struct(MADR, uint32_t) {
|
||||
static constexpr auto MemoryAdr = BitRange::from_to(0, 23);
|
||||
};
|
||||
}
|
||||
#pragma once
|
||||
#include "ioport.hpp"
|
||||
|
||||
namespace JabyEngine {
|
||||
namespace DMA_IO_Values {
|
||||
using Priority = uint32_t;
|
||||
static constexpr Priority HighestPriority = 0;
|
||||
static constexpr Priority LowestPriority = 7;
|
||||
|
||||
__declare_io_struct(BCR, uint32_t) {
|
||||
struct SyncMode0 {
|
||||
static constexpr auto NumberOfWords = BitRange::from_to(0, 15);
|
||||
static constexpr auto CD_OneBlock = Bit(16);
|
||||
|
||||
static constexpr BCR for_cd(size_t words) {
|
||||
return BCR::from(SyncMode0::CD_OneBlock, SyncMode0::NumberOfWords.with(words));
|
||||
}
|
||||
};
|
||||
|
||||
struct SyncMode1 {
|
||||
static constexpr auto BlockSize = BitRange::from_to(0, 15);
|
||||
static constexpr auto BlockAmount = BitRange::from_to(16, 31);
|
||||
};
|
||||
|
||||
struct SyncMode2 {
|
||||
static constexpr BCR for_gpu_cmd() {
|
||||
return {0};
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
__declare_io_struct(CHCHR, uint32_t) {
|
||||
enum SyncMode_t {
|
||||
Sync0 = 0, //Start immediately,
|
||||
Sync1 = 1, //Sync blocks to DMA requests
|
||||
Sync2 = 2, //Linked List
|
||||
};
|
||||
|
||||
static constexpr auto ManualStart = Bit(28);
|
||||
|
||||
static constexpr auto Start = Bit(24);
|
||||
static constexpr auto Busy = Start;
|
||||
|
||||
static constexpr auto ChoppingCPUWindowSize = BitRange::from_to(20, 22);
|
||||
static constexpr auto ChoppingDMAWindowSize = BitRange::from_to(16, 18);
|
||||
|
||||
static constexpr auto SyncMode = BitRange::from_to(9, 10);
|
||||
static constexpr auto UseSyncMode0 = SyncMode.with(Sync0);
|
||||
static constexpr auto UseSyncMode1 = SyncMode.with(Sync1);
|
||||
static constexpr auto UseSyncMode2 = SyncMode.with(Sync2);
|
||||
|
||||
static constexpr auto UseChopping = Bit(8);
|
||||
|
||||
static constexpr auto MemoryAdrDecreaseBy4 = Bit(1);
|
||||
static constexpr auto MemoryAdrIncreaseBy4 = !MemoryAdrDecreaseBy4;
|
||||
|
||||
static constexpr auto FromMainRAM = Bit(0);
|
||||
static constexpr auto ToMainRAM = !FromMainRAM;
|
||||
|
||||
static constexpr CHCHR StartMDECin() {
|
||||
return CHCHR{0x01000201};
|
||||
}
|
||||
|
||||
static constexpr CHCHR StartMDECout() {
|
||||
return CHCHR{0x01000200};
|
||||
}
|
||||
|
||||
static constexpr CHCHR StartGPUReceive() {
|
||||
return CHCHR{0x01000201};
|
||||
}
|
||||
|
||||
static constexpr CHCHR StartGPULinked() {
|
||||
return CHCHR{0x01000401};
|
||||
}
|
||||
|
||||
static constexpr CHCHR StartCDROM() {
|
||||
return CHCHR{0x11000000};
|
||||
}
|
||||
|
||||
static constexpr CHCHR StartSPUReceive() {
|
||||
return CHCHR{0x01000201};
|
||||
}
|
||||
|
||||
static constexpr CHCHR StartOTC() {
|
||||
return CHCHR{0x11000002};
|
||||
}
|
||||
};
|
||||
|
||||
__declare_io_struct(DICR, uint32_t) {
|
||||
static constexpr auto MasterEnable = Bit(31);
|
||||
static constexpr auto Flags = BitRange::from_to(24, 30);
|
||||
static constexpr auto MasterEnableDPCR = Bit(23);
|
||||
static constexpr auto EnableDPCR = BitRange::from_to(16, 22);
|
||||
static constexpr auto ForceIRQ = Bit(15);
|
||||
|
||||
static constexpr DICR empty() {
|
||||
return DICR{0};
|
||||
}
|
||||
};
|
||||
|
||||
__declare_io_struct(DPCR, uint32_t) {
|
||||
struct DMASetting {
|
||||
uint16_t master_bit;
|
||||
|
||||
static constexpr DMASetting create(uint16_t master_bit) {
|
||||
return DMASetting{master_bit};
|
||||
}
|
||||
|
||||
constexpr BitRange::RangeValuePair<uint32_t> turn_on(uint8_t priority) const {
|
||||
return BitRange::from_to(this->master_bit - 3, this->master_bit).with(static_cast<uint32_t>(0b1000 + (priority & 0b111)));
|
||||
}
|
||||
|
||||
constexpr ClearBit turn_off() const {
|
||||
return ClearBit(this->master_bit);
|
||||
}
|
||||
};
|
||||
|
||||
static constexpr const auto OTC = DMASetting(27);
|
||||
static constexpr const auto PIO = DMASetting(23);
|
||||
static constexpr const auto SPU = DMASetting(19);
|
||||
static constexpr const auto CDROM = DMASetting(15);
|
||||
static constexpr const auto GPU = DMASetting(11);
|
||||
static constexpr const auto MDEC_Out = DMASetting(7);
|
||||
static constexpr const auto MDEC_In = DMASetting(3);
|
||||
|
||||
static constexpr auto OTCEnabled = Bit(27);
|
||||
static constexpr auto OTCPriority = BitRange::from_to(24, 26);
|
||||
|
||||
static constexpr auto PIOEnabled = Bit(23);
|
||||
static constexpr auto PIOPriority = BitRange::from_to(20, 22);
|
||||
|
||||
static constexpr auto SPUEnabled = Bit(19);
|
||||
static constexpr auto SPUPriority = BitRange::from_to(16, 18);
|
||||
|
||||
static constexpr auto CDROMEnabled = Bit(15);
|
||||
static constexpr auto CDROMPriority = BitRange::from_to(12, 14);
|
||||
|
||||
static constexpr auto GPUEnabled = Bit(11);
|
||||
static constexpr auto GPUPriority = BitRange::from_to(8, 10);
|
||||
|
||||
static constexpr auto MDECoutEnabled = Bit(7);
|
||||
static constexpr auto MDECoutPriority = BitRange::from_to(4, 6);
|
||||
|
||||
static constexpr auto MDECinEnabled = Bit(3);
|
||||
static constexpr auto MDECinPriority = BitRange::from_to(0, 2);
|
||||
};
|
||||
|
||||
__declare_io_struct(MADR, uint32_t) {
|
||||
static constexpr auto MemoryAdr = BitRange::from_to(0, 23);
|
||||
};
|
||||
}
|
||||
}
|
@@ -1,220 +1,220 @@
|
||||
#pragma once
|
||||
#include "../../../GPU/gpu_types.hpp"
|
||||
#include "ioport.hpp"
|
||||
|
||||
namespace JabyEngine {
|
||||
namespace GPU_IO_Values {
|
||||
namespace internal {
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
__declare_io_struct(DisplayMode, uint32_t) {
|
||||
enum AreaColorDepth {
|
||||
$15bit = 0,
|
||||
$24bit = 1,
|
||||
};
|
||||
|
||||
enum State {
|
||||
On = 0,
|
||||
Off = 1
|
||||
};
|
||||
|
||||
enum HorizontalResolution {
|
||||
$256 = 0,
|
||||
$320 = 1,
|
||||
$512 = 2,
|
||||
$640 = 3,
|
||||
};
|
||||
|
||||
enum struct TVEncoding {
|
||||
NTSC = 0,
|
||||
PAL = 1,
|
||||
};
|
||||
|
||||
enum VerticalResolution {
|
||||
$240 = 0,
|
||||
$480 = 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 DisplayMode PAL() {
|
||||
return DisplayMode::from(
|
||||
HorizontalResolution.with(HorizontalResolution::$320),
|
||||
VerticalResolution.with(VerticalResolution::$240),
|
||||
VideoMode.with(TVEncoding::PAL),
|
||||
DisplayAreaColorDepth.with(AreaColorDepth::$15bit)
|
||||
);
|
||||
}
|
||||
|
||||
static constexpr DisplayMode NTSC() {
|
||||
return DisplayMode::from(
|
||||
HorizontalResolution.with(HorizontalResolution::$320),
|
||||
VerticalResolution.with(VerticalResolution::$240),
|
||||
VideoMode.with(TVEncoding::NTSC),
|
||||
DisplayAreaColorDepth.with(AreaColorDepth::$15bit)
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
__declare_io_struct(GPUREAD, uint32_t) {
|
||||
};
|
||||
|
||||
__declare_io_struct(GPUSTAT, uint32_t) {
|
||||
enum DMADirection {
|
||||
Off = 0,
|
||||
Fifo = 1,
|
||||
CPU2GPU = 2,
|
||||
GPU2CPU = 3,
|
||||
};
|
||||
|
||||
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);
|
||||
};
|
||||
|
||||
__declare_io_struct(GP0, uint32_t) {
|
||||
static constexpr auto ID = BitRange::from_to(24, 31);
|
||||
static constexpr auto Value = BitRange::from_to(0, 23);
|
||||
|
||||
static constexpr 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 internal::construct_cmd<GP0>(code, Y.as_value(static_cast<uint32_t>(y)) | X.as_value(static_cast<uint32_t>(x)));
|
||||
}
|
||||
|
||||
static constexpr GP0 ClearCache() {
|
||||
return internal::construct_cmd<GP0>(0x01, 0x0);
|
||||
}
|
||||
|
||||
static constexpr GP0 QuickFill(GPU::Color24 color) {
|
||||
return internal::construct_cmd<GP0>(0x02, color.raw());
|
||||
}
|
||||
|
||||
static constexpr GP0 VRAM2VRAMBlitting() {
|
||||
return internal::construct_cmd<GP0>(0x80, 0);
|
||||
}
|
||||
|
||||
static constexpr GP0 CPU2VRAMBlitting() {
|
||||
return internal::construct_cmd<GP0>(0xA0, 0);
|
||||
}
|
||||
|
||||
static constexpr GP0 TexPage(const GPU::PositionU16& page_pos, GPU::SemiTransparency transparency, GPU::TextureColorMode 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);
|
||||
constexpr auto TextureColorRange = BitRange::from_to(7, 8);
|
||||
constexpr auto DitherBit = BitRange::from_to(9, 9);
|
||||
constexpr auto DrawOnDisplayAreaBit = BitRange::from_to(10, 10);
|
||||
|
||||
return internal::construct_cmd<GP0>(0xE1,
|
||||
TexXRange.as_value(page_pos.x >> 6) | TexYRange.as_value(page_pos.y >> 8) |
|
||||
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 DrawAreaTopLeft(const GPU::PositionU16& position) {
|
||||
return GP0::DrawAreaTemplate(0xE3, position.x, position.y);
|
||||
}
|
||||
|
||||
static constexpr GP0 DrawAreaBottomRight(const GPU::PositionU16& position) {
|
||||
return GP0::DrawAreaTemplate(0xE4, position.x, position.y);
|
||||
}
|
||||
|
||||
static constexpr GP0 DrawOffset(const GPU::PositionI16& offset) {
|
||||
constexpr auto X = BitRange::from_to(0, 10);
|
||||
constexpr auto Y = BitRange::from_to(11, 21);
|
||||
|
||||
return internal::construct_cmd<GPU_IO_Values::GP0>(0xE5, X.as_value(static_cast<int32_t>(offset.x)) | Y.as_value(static_cast<int32_t>(offset.y)));
|
||||
}
|
||||
|
||||
static constexpr GP0 PostionTopLeft(const GPU::PositionU16& position) {
|
||||
return GP0{(static_cast<uint32_t>(position.y) << 16u) | position.x};
|
||||
}
|
||||
|
||||
static constexpr GP0 WidthHeight(const GPU::SizeU16& size) {
|
||||
return GP0{(static_cast<uint32_t>(size.height) << 16u) | size.width};
|
||||
}
|
||||
};
|
||||
|
||||
__declare_io_struct(GP1, uint32_t) {
|
||||
static constexpr auto ID = BitRange::from_to(24, 31);
|
||||
static constexpr auto Value = BitRange::from_to(0, 23);
|
||||
|
||||
static constexpr GP1 Reset() {
|
||||
return GP1{0};
|
||||
}
|
||||
|
||||
static constexpr GP1 ResetCMDBuffer() {
|
||||
return internal::construct_cmd<GP1>(0x01, 0);
|
||||
}
|
||||
|
||||
static constexpr GP1 DisplayState(DisplayMode::State state) {
|
||||
return internal::construct_cmd<GP1>(0x03, static_cast<uint32_t>(state));
|
||||
}
|
||||
|
||||
static constexpr GP1 DMADirection(GPUSTAT::DMADirection dir) {
|
||||
return internal::construct_cmd<GP1>(0x04, dir);
|
||||
}
|
||||
|
||||
static constexpr GP1 DisplayArea(const GPU::PositionU16& position) {
|
||||
constexpr auto X = BitRange::from_to(0, 9);
|
||||
constexpr auto Y = BitRange::from_to(10, 18);
|
||||
|
||||
return internal::construct_cmd<GP1>(0x05, X.as_value(static_cast<uint32_t>(position.x)) | Y.as_value(static_cast<uint32_t>(position.y)));
|
||||
}
|
||||
|
||||
static constexpr 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 internal::construct_cmd<GP1>(0x06, X1.as_value(static_cast<uint32_t>(x1)) | X2.as_value(static_cast<uint32_t>(x2)));
|
||||
}
|
||||
|
||||
static constexpr 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 internal::construct_cmd<GP1>(0x07, Y1.as_value(static_cast<uint32_t>(y1)) | Y2.as_value(static_cast<uint32_t>(y2)));
|
||||
}
|
||||
|
||||
static constexpr GP1 DisplayMode(GPU_IO_Values::DisplayMode mode) {
|
||||
return internal::construct_cmd<GP1>(0x08, mode.raw);
|
||||
}
|
||||
};
|
||||
}
|
||||
#pragma once
|
||||
#include "../../../GPU/gpu_types.hpp"
|
||||
#include "ioport.hpp"
|
||||
|
||||
namespace JabyEngine {
|
||||
namespace GPU_IO_Values {
|
||||
namespace internal {
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
__declare_io_struct(DisplayMode, uint32_t) {
|
||||
enum AreaColorDepth {
|
||||
$15bit = 0,
|
||||
$24bit = 1,
|
||||
};
|
||||
|
||||
enum State {
|
||||
On = 0,
|
||||
Off = 1
|
||||
};
|
||||
|
||||
enum HorizontalResolution {
|
||||
$256 = 0,
|
||||
$320 = 1,
|
||||
$512 = 2,
|
||||
$640 = 3,
|
||||
};
|
||||
|
||||
enum struct TVEncoding {
|
||||
NTSC = 0,
|
||||
PAL = 1,
|
||||
};
|
||||
|
||||
enum VerticalResolution {
|
||||
$240 = 0,
|
||||
$480 = 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 DisplayMode PAL() {
|
||||
return DisplayMode::from(
|
||||
HorizontalResolution.with(HorizontalResolution::$320),
|
||||
VerticalResolution.with(VerticalResolution::$240),
|
||||
VideoMode.with(TVEncoding::PAL),
|
||||
DisplayAreaColorDepth.with(AreaColorDepth::$15bit)
|
||||
);
|
||||
}
|
||||
|
||||
static constexpr DisplayMode NTSC() {
|
||||
return DisplayMode::from(
|
||||
HorizontalResolution.with(HorizontalResolution::$320),
|
||||
VerticalResolution.with(VerticalResolution::$240),
|
||||
VideoMode.with(TVEncoding::NTSC),
|
||||
DisplayAreaColorDepth.with(AreaColorDepth::$15bit)
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
__declare_io_struct(GPUREAD, uint32_t) {
|
||||
};
|
||||
|
||||
__declare_io_struct(GPUSTAT, uint32_t) {
|
||||
enum DMADirection {
|
||||
Off = 0,
|
||||
Fifo = 1,
|
||||
CPU2GPU = 2,
|
||||
GPU2CPU = 3,
|
||||
};
|
||||
|
||||
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);
|
||||
};
|
||||
|
||||
__declare_io_struct(GP0, uint32_t) {
|
||||
static constexpr auto ID = BitRange::from_to(24, 31);
|
||||
static constexpr auto Value = BitRange::from_to(0, 23);
|
||||
|
||||
static constexpr 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 internal::construct_cmd<GP0>(code, Y.as_value(static_cast<uint32_t>(y)) | X.as_value(static_cast<uint32_t>(x)));
|
||||
}
|
||||
|
||||
static constexpr GP0 ClearCache() {
|
||||
return internal::construct_cmd<GP0>(0x01, 0x0);
|
||||
}
|
||||
|
||||
static constexpr GP0 QuickFill(GPU::Color24 color) {
|
||||
return internal::construct_cmd<GP0>(0x02, color.raw());
|
||||
}
|
||||
|
||||
static constexpr GP0 VRAM2VRAMBlitting() {
|
||||
return internal::construct_cmd<GP0>(0x80, 0);
|
||||
}
|
||||
|
||||
static constexpr GP0 CPU2VRAMBlitting() {
|
||||
return internal::construct_cmd<GP0>(0xA0, 0);
|
||||
}
|
||||
|
||||
static constexpr GP0 TexPage(const GPU::PositionU16& page_pos, GPU::SemiTransparency transparency, GPU::TextureColorMode 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);
|
||||
constexpr auto TextureColorRange = BitRange::from_to(7, 8);
|
||||
constexpr auto DitherBit = BitRange::from_to(9, 9);
|
||||
constexpr auto DrawOnDisplayAreaBit = BitRange::from_to(10, 10);
|
||||
|
||||
return internal::construct_cmd<GP0>(0xE1,
|
||||
TexXRange.as_value(page_pos.x >> 6) | TexYRange.as_value(page_pos.y >> 8) |
|
||||
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 DrawAreaTopLeft(const GPU::PositionU16& position) {
|
||||
return GP0::DrawAreaTemplate(0xE3, position.x, position.y);
|
||||
}
|
||||
|
||||
static constexpr GP0 DrawAreaBottomRight(const GPU::PositionU16& position) {
|
||||
return GP0::DrawAreaTemplate(0xE4, position.x, position.y);
|
||||
}
|
||||
|
||||
static constexpr GP0 DrawOffset(const GPU::PositionI16& offset) {
|
||||
constexpr auto X = BitRange::from_to(0, 10);
|
||||
constexpr auto Y = BitRange::from_to(11, 21);
|
||||
|
||||
return internal::construct_cmd<GPU_IO_Values::GP0>(0xE5, X.as_value(static_cast<int32_t>(offset.x)) | Y.as_value(static_cast<int32_t>(offset.y)));
|
||||
}
|
||||
|
||||
static constexpr GP0 PostionTopLeft(const GPU::PositionU16& position) {
|
||||
return GP0{(static_cast<uint32_t>(position.y) << 16u) | position.x};
|
||||
}
|
||||
|
||||
static constexpr GP0 WidthHeight(const GPU::SizeU16& size) {
|
||||
return GP0{(static_cast<uint32_t>(size.height) << 16u) | size.width};
|
||||
}
|
||||
};
|
||||
|
||||
__declare_io_struct(GP1, uint32_t) {
|
||||
static constexpr auto ID = BitRange::from_to(24, 31);
|
||||
static constexpr auto Value = BitRange::from_to(0, 23);
|
||||
|
||||
static constexpr GP1 Reset() {
|
||||
return GP1{0};
|
||||
}
|
||||
|
||||
static constexpr GP1 ResetCMDBuffer() {
|
||||
return internal::construct_cmd<GP1>(0x01, 0);
|
||||
}
|
||||
|
||||
static constexpr GP1 DisplayState(DisplayMode::State state) {
|
||||
return internal::construct_cmd<GP1>(0x03, static_cast<uint32_t>(state));
|
||||
}
|
||||
|
||||
static constexpr GP1 DMADirection(GPUSTAT::DMADirection dir) {
|
||||
return internal::construct_cmd<GP1>(0x04, dir);
|
||||
}
|
||||
|
||||
static constexpr GP1 DisplayArea(const GPU::PositionU16& position) {
|
||||
constexpr auto X = BitRange::from_to(0, 9);
|
||||
constexpr auto Y = BitRange::from_to(10, 18);
|
||||
|
||||
return internal::construct_cmd<GP1>(0x05, X.as_value(static_cast<uint32_t>(position.x)) | Y.as_value(static_cast<uint32_t>(position.y)));
|
||||
}
|
||||
|
||||
static constexpr 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 internal::construct_cmd<GP1>(0x06, X1.as_value(static_cast<uint32_t>(x1)) | X2.as_value(static_cast<uint32_t>(x2)));
|
||||
}
|
||||
|
||||
static constexpr 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 internal::construct_cmd<GP1>(0x07, Y1.as_value(static_cast<uint32_t>(y1)) | Y2.as_value(static_cast<uint32_t>(y2)));
|
||||
}
|
||||
|
||||
static constexpr GP1 DisplayMode(GPU_IO_Values::DisplayMode mode) {
|
||||
return internal::construct_cmd<GP1>(0x08, mode.raw);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@@ -1,12 +1,12 @@
|
||||
#pragma once
|
||||
#include "ioport.hpp"
|
||||
|
||||
namespace JabyEngine {
|
||||
namespace Interrupt_IO_Values {
|
||||
__declare_io_struct(Mask, uint32_t) {
|
||||
};
|
||||
|
||||
__declare_io_struct(Status, uint32_t) {
|
||||
};
|
||||
}
|
||||
#pragma once
|
||||
#include "ioport.hpp"
|
||||
|
||||
namespace JabyEngine {
|
||||
namespace Interrupt_IO_Values {
|
||||
__declare_io_struct(Mask, uint32_t) {
|
||||
};
|
||||
|
||||
__declare_io_struct(Status, uint32_t) {
|
||||
};
|
||||
}
|
||||
}
|
@@ -1,118 +1,118 @@
|
||||
#pragma once
|
||||
#include "../../../Auxiliary/types.hpp"
|
||||
#include "../../../Auxiliary/bits.hpp"
|
||||
|
||||
namespace JabyEngine {
|
||||
namespace IOAdress {
|
||||
constexpr uintptr_t patch_adr(uintptr_t adr) {
|
||||
constexpr uintptr_t Mask = 0xF0000000;
|
||||
constexpr uintptr_t Base = 0x10000000; // We might want to change this later to 0xB0000000 for caching and stuff (More research needed)
|
||||
|
||||
return (Base + (adr & ~Mask));
|
||||
}
|
||||
}
|
||||
|
||||
namespace internal {
|
||||
template<typename T, typename S>
|
||||
struct IOValue {
|
||||
typedef S UnderlyingType;
|
||||
|
||||
UnderlyingType raw;
|
||||
|
||||
template<typename...ARGS>
|
||||
static constexpr T from(const ARGS&...args) {
|
||||
return T{0}.set(args...);
|
||||
}
|
||||
|
||||
constexpr T& set(Bit bit) {
|
||||
this->raw = bit::set(this->raw, bit);
|
||||
return static_cast<T&>(*this);
|
||||
}
|
||||
|
||||
constexpr T& set(ClearBit bit) {
|
||||
this->raw = bit::set(this->raw, bit);
|
||||
return static_cast<T&>(*this);
|
||||
}
|
||||
|
||||
constexpr T& set_range(const BitRange& bits, UnderlyingType value) {
|
||||
this->raw = bit::value::set_normalized(this->raw, bits, value);
|
||||
return static_cast<T&>(*this);
|
||||
}
|
||||
|
||||
template<typename U>
|
||||
constexpr T& set(const BitRange::RangeValuePair<U>& value) {
|
||||
this->raw = bit::value::set_normalized(this->raw, value);
|
||||
return static_cast<T&>(*this);
|
||||
}
|
||||
|
||||
template<typename U, typename...ARGS>
|
||||
constexpr T& set(const U& head, const ARGS&...tail) {
|
||||
return this->set(head).set(tail...);
|
||||
}
|
||||
|
||||
constexpr IOValue<T, S>::UnderlyingType get(BitRange bits) const {
|
||||
return bit::value::get_normalized(this->raw, bits.pos, bits.length);
|
||||
}
|
||||
|
||||
constexpr T& clear(Bit bit) {
|
||||
this->raw = bit::clear(this->raw, bit);
|
||||
return static_cast<T&>(*this);
|
||||
}
|
||||
|
||||
constexpr bool is_set(Bit bit) const {
|
||||
return bit::is_set(this->raw, bit);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
struct IOPort {
|
||||
using Value = T;
|
||||
T value;
|
||||
|
||||
T read() const {
|
||||
return {const_cast<const volatile IOPort<T>*>(this)->value.raw};
|
||||
}
|
||||
|
||||
void write(T value) {
|
||||
const_cast<volatile IOPort<T>*>(this)->value.raw = value.raw;
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct IOPort<uint32_t>;
|
||||
|
||||
template<typename T>
|
||||
struct IOPort32 {
|
||||
union ValueHelper {
|
||||
struct {
|
||||
uint16_t low;
|
||||
uint16_t high;
|
||||
};
|
||||
T value;
|
||||
};
|
||||
using Value = T;
|
||||
T value;
|
||||
|
||||
T read() const {
|
||||
const auto* cast_this = reinterpret_cast<const IOPort32<ValueHelper>*>(this);
|
||||
const volatile auto* cv_this = const_cast<volatile decltype(cast_this)>(cast_this);
|
||||
|
||||
return ValueHelper{.low = cv_this->value.low, .high = cv_this->value.high}.value;
|
||||
}
|
||||
|
||||
void write(T value) {
|
||||
const auto new_value = ValueHelper{.value = value};
|
||||
auto* cast_this = reinterpret_cast<IOPort32<ValueHelper>*>(this);
|
||||
volatile auto* v_this = const_cast<volatile decltype(cast_this)>(cast_this);
|
||||
|
||||
v_this->value.low = new_value.low;
|
||||
v_this->value.high = new_value.high;
|
||||
}
|
||||
};
|
||||
|
||||
#define __declare_io_struct(name, type) struct name : public ::JabyEngine::internal::IOValue<struct name, type>
|
||||
#define __declare_io_port(type, adr) *reinterpret_cast<type*>(adr)
|
||||
#define __declare_io_value(type, adr) __declare_io_port(type, adr)
|
||||
#define __declare_io_port_array(type, size, adr) reinterpret_cast<type(&)[size]>(*reinterpret_cast<type*>(adr))
|
||||
#pragma once
|
||||
#include "../../../Auxiliary/types.hpp"
|
||||
#include "../../../Auxiliary/bits.hpp"
|
||||
|
||||
namespace JabyEngine {
|
||||
namespace IOAdress {
|
||||
constexpr uintptr_t patch_adr(uintptr_t adr) {
|
||||
constexpr uintptr_t Mask = 0xF0000000;
|
||||
constexpr uintptr_t Base = 0x10000000; // We might want to change this later to 0xB0000000 for caching and stuff (More research needed)
|
||||
|
||||
return (Base + (adr & ~Mask));
|
||||
}
|
||||
}
|
||||
|
||||
namespace internal {
|
||||
template<typename T, typename S>
|
||||
struct IOValue {
|
||||
typedef S UnderlyingType;
|
||||
|
||||
UnderlyingType raw;
|
||||
|
||||
template<typename...ARGS>
|
||||
static constexpr T from(const ARGS&...args) {
|
||||
return T{0}.set(args...);
|
||||
}
|
||||
|
||||
constexpr T& set(Bit bit) {
|
||||
this->raw = bit::set(this->raw, bit);
|
||||
return static_cast<T&>(*this);
|
||||
}
|
||||
|
||||
constexpr T& set(ClearBit bit) {
|
||||
this->raw = bit::set(this->raw, bit);
|
||||
return static_cast<T&>(*this);
|
||||
}
|
||||
|
||||
constexpr T& set_range(const BitRange& bits, UnderlyingType value) {
|
||||
this->raw = bit::value::set_normalized(this->raw, bits, value);
|
||||
return static_cast<T&>(*this);
|
||||
}
|
||||
|
||||
template<typename U>
|
||||
constexpr T& set(const BitRange::RangeValuePair<U>& value) {
|
||||
this->raw = bit::value::set_normalized(this->raw, value);
|
||||
return static_cast<T&>(*this);
|
||||
}
|
||||
|
||||
template<typename U, typename...ARGS>
|
||||
constexpr T& set(const U& head, const ARGS&...tail) {
|
||||
return this->set(head).set(tail...);
|
||||
}
|
||||
|
||||
constexpr IOValue<T, S>::UnderlyingType get(BitRange bits) const {
|
||||
return bit::value::get_normalized(this->raw, bits.pos, bits.length);
|
||||
}
|
||||
|
||||
constexpr T& clear(Bit bit) {
|
||||
this->raw = bit::clear(this->raw, bit);
|
||||
return static_cast<T&>(*this);
|
||||
}
|
||||
|
||||
constexpr bool is_set(Bit bit) const {
|
||||
return bit::is_set(this->raw, bit);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
struct IOPort {
|
||||
using Value = T;
|
||||
T value;
|
||||
|
||||
T read() const {
|
||||
return {const_cast<const volatile IOPort<T>*>(this)->value.raw};
|
||||
}
|
||||
|
||||
void write(T value) {
|
||||
const_cast<volatile IOPort<T>*>(this)->value.raw = value.raw;
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct IOPort<uint32_t>;
|
||||
|
||||
template<typename T>
|
||||
struct IOPort32 {
|
||||
union ValueHelper {
|
||||
struct {
|
||||
uint16_t low;
|
||||
uint16_t high;
|
||||
};
|
||||
T value;
|
||||
};
|
||||
using Value = T;
|
||||
T value;
|
||||
|
||||
T read() const {
|
||||
const auto* cast_this = reinterpret_cast<const IOPort32<ValueHelper>*>(this);
|
||||
const volatile auto* cv_this = const_cast<volatile decltype(cast_this)>(cast_this);
|
||||
|
||||
return ValueHelper{.low = cv_this->value.low, .high = cv_this->value.high}.value;
|
||||
}
|
||||
|
||||
void write(T value) {
|
||||
const auto new_value = ValueHelper{.value = value};
|
||||
auto* cast_this = reinterpret_cast<IOPort32<ValueHelper>*>(this);
|
||||
volatile auto* v_this = const_cast<volatile decltype(cast_this)>(cast_this);
|
||||
|
||||
v_this->value.low = new_value.low;
|
||||
v_this->value.high = new_value.high;
|
||||
}
|
||||
};
|
||||
|
||||
#define __declare_io_struct(name, type) struct name : public ::JabyEngine::internal::IOValue<struct name, type>
|
||||
#define __declare_io_port(type, adr) *reinterpret_cast<type*>(adr)
|
||||
#define __declare_io_value(type, adr) __declare_io_port(type, adr)
|
||||
#define __declare_io_port_array(type, size, adr) reinterpret_cast<type(&)[size]>(*reinterpret_cast<type*>(adr))
|
||||
}
|
@@ -1,18 +1,18 @@
|
||||
#pragma once
|
||||
#include "ioport.hpp"
|
||||
|
||||
namespace JabyEngine {
|
||||
namespace Memory_IO_Values {
|
||||
__declare_io_struct(CD_DELAY, uint32_t) {
|
||||
static constexpr CD_DELAY create() {
|
||||
return CD_DELAY{0x20943};
|
||||
}
|
||||
};
|
||||
|
||||
__declare_io_struct(COM_DELAY, uint32_t) {
|
||||
static constexpr COM_DELAY create() {
|
||||
return COM_DELAY{0x1325};
|
||||
}
|
||||
};
|
||||
}
|
||||
#pragma once
|
||||
#include "ioport.hpp"
|
||||
|
||||
namespace JabyEngine {
|
||||
namespace Memory_IO_Values {
|
||||
__declare_io_struct(CD_DELAY, uint32_t) {
|
||||
static constexpr CD_DELAY create() {
|
||||
return CD_DELAY{0x20943};
|
||||
}
|
||||
};
|
||||
|
||||
__declare_io_struct(COM_DELAY, uint32_t) {
|
||||
static constexpr COM_DELAY create() {
|
||||
return COM_DELAY{0x1325};
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@@ -1,52 +1,52 @@
|
||||
#pragma once
|
||||
#include "ioport.hpp"
|
||||
|
||||
namespace JabyEngine {
|
||||
namespace Periphery_IO_Values {
|
||||
__declare_io_struct(JOY_BAUD, uint16_t) {
|
||||
static constexpr JOY_BAUD create() {
|
||||
return JOY_BAUD{0x0088};
|
||||
}
|
||||
};
|
||||
|
||||
__declare_io_struct(JOY_CTRL, uint16_t) {
|
||||
static constexpr auto TXEnable = Bit(0);
|
||||
static constexpr auto SelectJoy = Bit(1);
|
||||
static constexpr auto ACK = Bit(4);
|
||||
static constexpr auto ACKIrqEnable = Bit(12);
|
||||
static constexpr auto PortBSelected = Bit(13);
|
||||
static constexpr auto PortASelected = !PortBSelected;
|
||||
|
||||
static constexpr JOY_CTRL create_for(uint16_t port) {
|
||||
return JOY_CTRL{static_cast<uint16_t>(port << PortBSelected)}.set(TXEnable, SelectJoy, ACKIrqEnable);
|
||||
}
|
||||
|
||||
static constexpr JOY_CTRL close() {
|
||||
return JOY_CTRL{0};
|
||||
}
|
||||
};
|
||||
|
||||
__declare_io_struct(JOY_MODE, uint16_t) {
|
||||
static constexpr JOY_MODE create() {
|
||||
return JOY_MODE{0x000D};
|
||||
}
|
||||
};
|
||||
|
||||
__declare_io_struct(JOY_RX_DATA, uint8_t) {
|
||||
};
|
||||
|
||||
__declare_io_struct(JOY_STAT, uint32_t) {
|
||||
static constexpr auto TXReadyStart = Bit(0);
|
||||
static constexpr auto RXFifoNonEmpty = Bit(1);
|
||||
static constexpr auto TXReadyFinished = Bit(2);
|
||||
static constexpr auto RXParityError = Bit(3);
|
||||
static constexpr auto ACKIrqLow = Bit(7);
|
||||
};
|
||||
|
||||
__declare_io_struct(JOY_TX_DATA, uint32_t) {
|
||||
static constexpr JOY_TX_DATA create(uint8_t byte) {
|
||||
return JOY_TX_DATA{byte};
|
||||
}
|
||||
};
|
||||
}
|
||||
#pragma once
|
||||
#include "ioport.hpp"
|
||||
|
||||
namespace JabyEngine {
|
||||
namespace Periphery_IO_Values {
|
||||
__declare_io_struct(JOY_BAUD, uint16_t) {
|
||||
static constexpr JOY_BAUD create() {
|
||||
return JOY_BAUD{0x0088};
|
||||
}
|
||||
};
|
||||
|
||||
__declare_io_struct(JOY_CTRL, uint16_t) {
|
||||
static constexpr auto TXEnable = Bit(0);
|
||||
static constexpr auto SelectJoy = Bit(1);
|
||||
static constexpr auto ACK = Bit(4);
|
||||
static constexpr auto ACKIrqEnable = Bit(12);
|
||||
static constexpr auto PortBSelected = Bit(13);
|
||||
static constexpr auto PortASelected = !PortBSelected;
|
||||
|
||||
static constexpr JOY_CTRL create_for(uint16_t port) {
|
||||
return JOY_CTRL{static_cast<uint16_t>(port << PortBSelected)}.set(TXEnable, SelectJoy, ACKIrqEnable);
|
||||
}
|
||||
|
||||
static constexpr JOY_CTRL close() {
|
||||
return JOY_CTRL{0};
|
||||
}
|
||||
};
|
||||
|
||||
__declare_io_struct(JOY_MODE, uint16_t) {
|
||||
static constexpr JOY_MODE create() {
|
||||
return JOY_MODE{0x000D};
|
||||
}
|
||||
};
|
||||
|
||||
__declare_io_struct(JOY_RX_DATA, uint8_t) {
|
||||
};
|
||||
|
||||
__declare_io_struct(JOY_STAT, uint32_t) {
|
||||
static constexpr auto TXReadyStart = Bit(0);
|
||||
static constexpr auto RXFifoNonEmpty = Bit(1);
|
||||
static constexpr auto TXReadyFinished = Bit(2);
|
||||
static constexpr auto RXParityError = Bit(3);
|
||||
static constexpr auto ACKIrqLow = Bit(7);
|
||||
};
|
||||
|
||||
__declare_io_struct(JOY_TX_DATA, uint32_t) {
|
||||
static constexpr JOY_TX_DATA create(uint8_t byte) {
|
||||
return JOY_TX_DATA{byte};
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@@ -1,215 +1,215 @@
|
||||
#pragma once
|
||||
#include "ioport.hpp"
|
||||
#include <limits.hpp>
|
||||
|
||||
namespace JabyEngine {
|
||||
namespace SPU_IO_Values {
|
||||
namespace MemoryMap {
|
||||
static constexpr uintptr_t ADPCM = 0x01000;
|
||||
static constexpr uintptr_t End = 0x7FFFF;
|
||||
}
|
||||
|
||||
__declare_io_struct(AD, uint16_t) {
|
||||
static constexpr auto AttackMode = Bit(15);
|
||||
static constexpr auto AttackShift = BitRange::from_to(10, 14);
|
||||
static constexpr auto AttackStep = BitRange::from_to(8, 9);
|
||||
static constexpr auto DecayShift = BitRange::from_to(4, 7);
|
||||
static constexpr auto SustainLevel = BitRange::from_to(0, 3);
|
||||
|
||||
static constexpr AD none() {
|
||||
return AD{0};
|
||||
}
|
||||
};
|
||||
|
||||
__declare_io_struct(ControlRegister, uint16_t) {
|
||||
enum RAMTransferMode {
|
||||
Stop = 0,
|
||||
ManualWrite = 1,
|
||||
DMAWrite = 2,
|
||||
DMARead = 3
|
||||
};
|
||||
|
||||
static constexpr auto Enable = Bit(15);
|
||||
static constexpr auto Unmute = Bit(14);
|
||||
static constexpr auto NoiseFrequcenyShift = BitRange::from_to(10, 13);
|
||||
static constexpr auto NoiseFrequcenyStep = BitRange::from_to(8, 9);
|
||||
static constexpr auto ReverbMasterEnable = Bit(7);
|
||||
static constexpr auto IRQ9Enable = Bit(6);
|
||||
static constexpr auto TransferMode = BitRange::from_to(4, 5);
|
||||
static constexpr auto ExternalAudioReverb = Bit(3);
|
||||
static constexpr auto CDAudioReverb = Bit(2);
|
||||
static constexpr auto ExternalAudioEnable = Bit(1);
|
||||
static constexpr auto CDAudioEnable = Bit(0);
|
||||
};
|
||||
|
||||
__declare_io_struct(DataTransferControl, uint16_t) {
|
||||
static constexpr DataTransferControl NormalTransferMode() {
|
||||
return DataTransferControl{0x0004};
|
||||
}
|
||||
};
|
||||
|
||||
__declare_io_struct(Echo, uint32_t) {
|
||||
static constexpr auto EchoBits = BitRange::from_to(0, 23);
|
||||
|
||||
static constexpr Echo AllOff() {
|
||||
return Echo{0};
|
||||
}
|
||||
};
|
||||
|
||||
__declare_io_struct(KeyOff, uint32_t) {
|
||||
static constexpr KeyOff for_specific(uint32_t id) {
|
||||
return KeyOff{1u << id};
|
||||
}
|
||||
|
||||
static constexpr KeyOff all() {
|
||||
return KeyOff{UI32_MAX};
|
||||
}
|
||||
};
|
||||
|
||||
__declare_io_struct(KeyOn, uint32_t) {
|
||||
static constexpr KeyOn for_specific(uint32_t id) {
|
||||
return KeyOn{1u << id};
|
||||
}
|
||||
|
||||
static constexpr KeyOn all() {
|
||||
return KeyOn{UI32_MAX};
|
||||
}
|
||||
};
|
||||
|
||||
__declare_io_struct(KeyStatus, uint32_t) {
|
||||
};
|
||||
|
||||
__declare_io_struct(Noise, uint16_t) {
|
||||
static constexpr auto NoiseBits = BitRange::from_to(0, 23);
|
||||
|
||||
static constexpr Noise AllOff() {
|
||||
return Noise{0};
|
||||
}
|
||||
};
|
||||
|
||||
__declare_io_struct(PitchModulation, uint32_t) {
|
||||
static constexpr auto EnableBits = BitRange::from_to(1, 23);
|
||||
|
||||
static constexpr PitchModulation AllOff() {
|
||||
return PitchModulation{0};
|
||||
}
|
||||
};
|
||||
|
||||
__declare_io_struct(SampleRate, uint16_t) {
|
||||
static constexpr SampleRate stop() {
|
||||
return SampleRate{0};
|
||||
}
|
||||
|
||||
static constexpr SampleRate from_HZ(uint32_t freq) {
|
||||
constexpr uint32_t Base1024Hz = static_cast<uint32_t>((4096.0/44100.0)*1024.0);
|
||||
return SampleRate{static_cast<uint16_t>((freq >> 10)*Base1024Hz)};
|
||||
}
|
||||
|
||||
static constexpr SampleRate from_HZ(double freq) {
|
||||
//4096 == 44100Hz
|
||||
constexpr double Base = (4096.0 / 44100.0);
|
||||
return SampleRate{static_cast<uint16_t>((freq*Base))};
|
||||
}
|
||||
};
|
||||
|
||||
__declare_io_struct(SimpleVolume, int16_t) {
|
||||
static constexpr auto MaxVolume = I16_MAX;
|
||||
|
||||
static constexpr SimpleVolume mute() {
|
||||
return SimpleVolume{0};
|
||||
}
|
||||
|
||||
constexpr operator int16_t() const {
|
||||
return this->raw;
|
||||
}
|
||||
};
|
||||
|
||||
static constexpr SimpleVolume operator""_vol(long double fraction) {
|
||||
return {static_cast<int16_t>(static_cast<long double>(SimpleVolume::MaxVolume)*fraction)};
|
||||
}
|
||||
|
||||
__declare_io_struct(SR, uint16_t) {
|
||||
static constexpr auto SustainMode = Bit(31 - 16);
|
||||
static constexpr auto SustainDirection = Bit(30 - 16);
|
||||
static constexpr auto SustainShift = BitRange::from_to((24 - 16), (28 - 16));
|
||||
static constexpr auto SustainStep = BitRange::from_to((22 - 16), (23 - 16));
|
||||
static constexpr auto ReleaseMode = Bit(21 - 16);
|
||||
static constexpr auto ReleaseShift = BitRange::from_to((16 - 16), (20 - 16));
|
||||
|
||||
static constexpr SR none() {
|
||||
return SR{0};
|
||||
}
|
||||
};
|
||||
|
||||
__declare_io_struct(SRAMAdr, uint16_t) {
|
||||
static constexpr SRAMAdr null() {
|
||||
return SRAMAdr{0x0};
|
||||
}
|
||||
|
||||
static constexpr SRAMAdr adpcm_start() {
|
||||
return SRAMAdr{MemoryMap::ADPCM};
|
||||
}
|
||||
};
|
||||
|
||||
__declare_io_struct(StatusRegister, uint16_t) {
|
||||
enum CapureBufferHalf {
|
||||
First = 0,
|
||||
Second = 1
|
||||
};
|
||||
|
||||
static constexpr auto Unused = BitRange::from_to(12, 15);
|
||||
static constexpr auto CaputreBufferHalf = Bit(11);
|
||||
static constexpr auto TransferBusy = Bit(10);
|
||||
static constexpr auto IsDMARead = Bit(9);
|
||||
static constexpr auto isDMAWrite = Bit(8);
|
||||
static constexpr auto isDMA = Bit(7);
|
||||
static constexpr auto isIRQ = Bit(6);
|
||||
// Copies of ControlRegister
|
||||
static constexpr auto TransferMode = BitRange::from_to(4, 5);
|
||||
static constexpr auto ExternalAudioReverb = Bit(3);
|
||||
static constexpr auto CDAudioReverb = Bit(2);
|
||||
static constexpr auto ExternalAudioEnable = Bit(1);
|
||||
static constexpr auto CDAudioEnable = Bit(0);
|
||||
};
|
||||
|
||||
__declare_io_struct(SweepVolume, int16_t) {
|
||||
struct VolumeMode {
|
||||
static constexpr auto MaxVolume = (I16_MAX >> 1);
|
||||
static constexpr auto EnableSweep = Bit(15);
|
||||
static constexpr auto Enable = !EnableSweep;
|
||||
static constexpr auto Volume = BitRange::from_to(0, 14);
|
||||
};
|
||||
|
||||
struct SweepMode {
|
||||
enum Mode {
|
||||
Linear = 0,
|
||||
Exponential = 1,
|
||||
};
|
||||
|
||||
enum Direction {
|
||||
Increase = 0,
|
||||
Decrease = 1,
|
||||
};
|
||||
|
||||
enum Phase {
|
||||
Posititve = 0,
|
||||
Negative = 1,
|
||||
};
|
||||
|
||||
static constexpr auto Mode = Bit(14);
|
||||
static constexpr auto Direction = Bit(13);
|
||||
static constexpr auto Phase = Bit(12);
|
||||
static constexpr auto Shift = BitRange::from_to(2, 6);
|
||||
static constexpr auto Step = BitRange::from_to(0, 1);
|
||||
};
|
||||
|
||||
static constexpr SweepVolume create(SimpleVolume volume) {
|
||||
return from(VolumeMode::Enable, VolumeMode::Volume.with(volume.raw >> 1));
|
||||
}
|
||||
|
||||
static constexpr SweepVolume mute() {
|
||||
return SweepVolume{0};
|
||||
}
|
||||
};
|
||||
}
|
||||
#pragma once
|
||||
#include "ioport.hpp"
|
||||
#include <limits.hpp>
|
||||
|
||||
namespace JabyEngine {
|
||||
namespace SPU_IO_Values {
|
||||
namespace MemoryMap {
|
||||
static constexpr uintptr_t ADPCM = 0x01000;
|
||||
static constexpr uintptr_t End = 0x7FFFF;
|
||||
}
|
||||
|
||||
__declare_io_struct(AD, uint16_t) {
|
||||
static constexpr auto AttackMode = Bit(15);
|
||||
static constexpr auto AttackShift = BitRange::from_to(10, 14);
|
||||
static constexpr auto AttackStep = BitRange::from_to(8, 9);
|
||||
static constexpr auto DecayShift = BitRange::from_to(4, 7);
|
||||
static constexpr auto SustainLevel = BitRange::from_to(0, 3);
|
||||
|
||||
static constexpr AD none() {
|
||||
return AD{0};
|
||||
}
|
||||
};
|
||||
|
||||
__declare_io_struct(ControlRegister, uint16_t) {
|
||||
enum RAMTransferMode {
|
||||
Stop = 0,
|
||||
ManualWrite = 1,
|
||||
DMAWrite = 2,
|
||||
DMARead = 3
|
||||
};
|
||||
|
||||
static constexpr auto Enable = Bit(15);
|
||||
static constexpr auto Unmute = Bit(14);
|
||||
static constexpr auto NoiseFrequcenyShift = BitRange::from_to(10, 13);
|
||||
static constexpr auto NoiseFrequcenyStep = BitRange::from_to(8, 9);
|
||||
static constexpr auto ReverbMasterEnable = Bit(7);
|
||||
static constexpr auto IRQ9Enable = Bit(6);
|
||||
static constexpr auto TransferMode = BitRange::from_to(4, 5);
|
||||
static constexpr auto ExternalAudioReverb = Bit(3);
|
||||
static constexpr auto CDAudioReverb = Bit(2);
|
||||
static constexpr auto ExternalAudioEnable = Bit(1);
|
||||
static constexpr auto CDAudioEnable = Bit(0);
|
||||
};
|
||||
|
||||
__declare_io_struct(DataTransferControl, uint16_t) {
|
||||
static constexpr DataTransferControl NormalTransferMode() {
|
||||
return DataTransferControl{0x0004};
|
||||
}
|
||||
};
|
||||
|
||||
__declare_io_struct(Echo, uint32_t) {
|
||||
static constexpr auto EchoBits = BitRange::from_to(0, 23);
|
||||
|
||||
static constexpr Echo AllOff() {
|
||||
return Echo{0};
|
||||
}
|
||||
};
|
||||
|
||||
__declare_io_struct(KeyOff, uint32_t) {
|
||||
static constexpr KeyOff for_specific(uint32_t id) {
|
||||
return KeyOff{1u << id};
|
||||
}
|
||||
|
||||
static constexpr KeyOff all() {
|
||||
return KeyOff{UI32_MAX};
|
||||
}
|
||||
};
|
||||
|
||||
__declare_io_struct(KeyOn, uint32_t) {
|
||||
static constexpr KeyOn for_specific(uint32_t id) {
|
||||
return KeyOn{1u << id};
|
||||
}
|
||||
|
||||
static constexpr KeyOn all() {
|
||||
return KeyOn{UI32_MAX};
|
||||
}
|
||||
};
|
||||
|
||||
__declare_io_struct(KeyStatus, uint32_t) {
|
||||
};
|
||||
|
||||
__declare_io_struct(Noise, uint16_t) {
|
||||
static constexpr auto NoiseBits = BitRange::from_to(0, 23);
|
||||
|
||||
static constexpr Noise AllOff() {
|
||||
return Noise{0};
|
||||
}
|
||||
};
|
||||
|
||||
__declare_io_struct(PitchModulation, uint32_t) {
|
||||
static constexpr auto EnableBits = BitRange::from_to(1, 23);
|
||||
|
||||
static constexpr PitchModulation AllOff() {
|
||||
return PitchModulation{0};
|
||||
}
|
||||
};
|
||||
|
||||
__declare_io_struct(SampleRate, uint16_t) {
|
||||
static constexpr SampleRate stop() {
|
||||
return SampleRate{0};
|
||||
}
|
||||
|
||||
static constexpr SampleRate from_HZ(uint32_t freq) {
|
||||
constexpr uint32_t Base1024Hz = static_cast<uint32_t>((4096.0/44100.0)*1024.0);
|
||||
return SampleRate{static_cast<uint16_t>((freq >> 10)*Base1024Hz)};
|
||||
}
|
||||
|
||||
static constexpr SampleRate from_HZ(double freq) {
|
||||
//4096 == 44100Hz
|
||||
constexpr double Base = (4096.0 / 44100.0);
|
||||
return SampleRate{static_cast<uint16_t>((freq*Base))};
|
||||
}
|
||||
};
|
||||
|
||||
__declare_io_struct(SimpleVolume, int16_t) {
|
||||
static constexpr auto MaxVolume = I16_MAX;
|
||||
|
||||
static constexpr SimpleVolume mute() {
|
||||
return SimpleVolume{0};
|
||||
}
|
||||
|
||||
constexpr operator int16_t() const {
|
||||
return this->raw;
|
||||
}
|
||||
};
|
||||
|
||||
static constexpr SimpleVolume operator""_vol(long double fraction) {
|
||||
return {static_cast<int16_t>(static_cast<long double>(SimpleVolume::MaxVolume)*fraction)};
|
||||
}
|
||||
|
||||
__declare_io_struct(SR, uint16_t) {
|
||||
static constexpr auto SustainMode = Bit(31 - 16);
|
||||
static constexpr auto SustainDirection = Bit(30 - 16);
|
||||
static constexpr auto SustainShift = BitRange::from_to((24 - 16), (28 - 16));
|
||||
static constexpr auto SustainStep = BitRange::from_to((22 - 16), (23 - 16));
|
||||
static constexpr auto ReleaseMode = Bit(21 - 16);
|
||||
static constexpr auto ReleaseShift = BitRange::from_to((16 - 16), (20 - 16));
|
||||
|
||||
static constexpr SR none() {
|
||||
return SR{0};
|
||||
}
|
||||
};
|
||||
|
||||
__declare_io_struct(SRAMAdr, uint16_t) {
|
||||
static constexpr SRAMAdr null() {
|
||||
return SRAMAdr{0x0};
|
||||
}
|
||||
|
||||
static constexpr SRAMAdr adpcm_start() {
|
||||
return SRAMAdr{MemoryMap::ADPCM};
|
||||
}
|
||||
};
|
||||
|
||||
__declare_io_struct(StatusRegister, uint16_t) {
|
||||
enum CapureBufferHalf {
|
||||
First = 0,
|
||||
Second = 1
|
||||
};
|
||||
|
||||
static constexpr auto Unused = BitRange::from_to(12, 15);
|
||||
static constexpr auto CaputreBufferHalf = Bit(11);
|
||||
static constexpr auto TransferBusy = Bit(10);
|
||||
static constexpr auto IsDMARead = Bit(9);
|
||||
static constexpr auto isDMAWrite = Bit(8);
|
||||
static constexpr auto isDMA = Bit(7);
|
||||
static constexpr auto isIRQ = Bit(6);
|
||||
// Copies of ControlRegister
|
||||
static constexpr auto TransferMode = BitRange::from_to(4, 5);
|
||||
static constexpr auto ExternalAudioReverb = Bit(3);
|
||||
static constexpr auto CDAudioReverb = Bit(2);
|
||||
static constexpr auto ExternalAudioEnable = Bit(1);
|
||||
static constexpr auto CDAudioEnable = Bit(0);
|
||||
};
|
||||
|
||||
__declare_io_struct(SweepVolume, int16_t) {
|
||||
struct VolumeMode {
|
||||
static constexpr auto MaxVolume = (I16_MAX >> 1);
|
||||
static constexpr auto EnableSweep = Bit(15);
|
||||
static constexpr auto Enable = !EnableSweep;
|
||||
static constexpr auto Volume = BitRange::from_to(0, 14);
|
||||
};
|
||||
|
||||
struct SweepMode {
|
||||
enum Mode {
|
||||
Linear = 0,
|
||||
Exponential = 1,
|
||||
};
|
||||
|
||||
enum Direction {
|
||||
Increase = 0,
|
||||
Decrease = 1,
|
||||
};
|
||||
|
||||
enum Phase {
|
||||
Posititve = 0,
|
||||
Negative = 1,
|
||||
};
|
||||
|
||||
static constexpr auto Mode = Bit(14);
|
||||
static constexpr auto Direction = Bit(13);
|
||||
static constexpr auto Phase = Bit(12);
|
||||
static constexpr auto Shift = BitRange::from_to(2, 6);
|
||||
static constexpr auto Step = BitRange::from_to(0, 1);
|
||||
};
|
||||
|
||||
static constexpr SweepVolume create(SimpleVolume volume) {
|
||||
return from(VolumeMode::Enable, VolumeMode::Volume.with(volume.raw >> 1));
|
||||
}
|
||||
|
||||
static constexpr SweepVolume mute() {
|
||||
return SweepVolume{0};
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@@ -1,31 +1,31 @@
|
||||
#pragma once
|
||||
#include "ioport.hpp"
|
||||
|
||||
namespace JabyEngine {
|
||||
namespace Timer_IO_Values {
|
||||
__declare_io_struct(CounterMode, uint32_t) {
|
||||
static constexpr auto SyncEnable = Bit(0);
|
||||
static constexpr auto FreeRun = !SyncEnable;
|
||||
static constexpr auto SyncMode = BitRange::from_to(1, 2);
|
||||
static constexpr auto ResetAfterTarget = Bit(3);
|
||||
static constexpr auto IRQAtTarget = Bit(4);
|
||||
static constexpr auto IRQAtMax = Bit(5);
|
||||
static constexpr auto IRQEveryTime = Bit(6);
|
||||
static constexpr auto IRQOneShot = !IRQEveryTime;
|
||||
static constexpr auto IRQToggle = Bit(7);
|
||||
static constexpr auto IRQPulse = !IRQToggle;
|
||||
static constexpr auto ClockSource = BitRange::from_to(8, 9);
|
||||
static constexpr auto HasIRQRequest = Bit(10);
|
||||
static constexpr auto IsTargetReached = Bit(11);
|
||||
static constexpr auto IsMaxReached = Bit(12);
|
||||
};
|
||||
|
||||
__declare_io_struct(CounterTarget, uint32_t) {
|
||||
static constexpr auto CounterTargetValue = BitRange::from_to(0, 15);
|
||||
};
|
||||
|
||||
__declare_io_struct(CounterValue, uint32_t) {
|
||||
static constexpr auto Value = BitRange::from_to(0, 15);
|
||||
};
|
||||
}
|
||||
#pragma once
|
||||
#include "ioport.hpp"
|
||||
|
||||
namespace JabyEngine {
|
||||
namespace Timer_IO_Values {
|
||||
__declare_io_struct(CounterMode, uint32_t) {
|
||||
static constexpr auto SyncEnable = Bit(0);
|
||||
static constexpr auto FreeRun = !SyncEnable;
|
||||
static constexpr auto SyncMode = BitRange::from_to(1, 2);
|
||||
static constexpr auto ResetAfterTarget = Bit(3);
|
||||
static constexpr auto IRQAtTarget = Bit(4);
|
||||
static constexpr auto IRQAtMax = Bit(5);
|
||||
static constexpr auto IRQEveryTime = Bit(6);
|
||||
static constexpr auto IRQOneShot = !IRQEveryTime;
|
||||
static constexpr auto IRQToggle = Bit(7);
|
||||
static constexpr auto IRQPulse = !IRQToggle;
|
||||
static constexpr auto ClockSource = BitRange::from_to(8, 9);
|
||||
static constexpr auto HasIRQRequest = Bit(10);
|
||||
static constexpr auto IsTargetReached = Bit(11);
|
||||
static constexpr auto IsMaxReached = Bit(12);
|
||||
};
|
||||
|
||||
__declare_io_struct(CounterTarget, uint32_t) {
|
||||
static constexpr auto CounterTargetValue = BitRange::from_to(0, 15);
|
||||
};
|
||||
|
||||
__declare_io_struct(CounterValue, uint32_t) {
|
||||
static constexpr auto Value = BitRange::from_to(0, 15);
|
||||
};
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user