#pragma once
#include "../jabyengine_config.hpp"
#include "controller.hpp"

namespace JabyEngine {
    namespace Periphery {
        static constexpr uint32_t PortCount   = Configuration::Periphery::include_portB() ? 2 : 1;
        static constexpr uint32_t DeviceCount = Configuration::Periphery::use_multi_tap()  ? 4 : 1;

        extern RawController controller[PortCount][DeviceCount];

        void query_controller();
            
        template<typename T>
        inline T& get_controller_as(size_t port, size_t device) {
            return *reinterpret_cast<T*>(&controller[port][device]);
        }

        template<typename T>
        inline T& get_primary_controller_as() {
            return get_controller_as<T>(0, 0);
        }
    }
}