From ec589d929ae428402f072d5dcb21a9369fb269ed Mon Sep 17 00:00:00 2001 From: Gustavo Henrique Santos Souza de Miranda Date: Wed, 3 Jun 2026 14:13:50 -0300 Subject: [PATCH] Update the timing for the delays and also create the Write method on the HAL to choreograph the writing process in the YMF262 and create the Set_OPL_Mode , and also created the YMF262-Types.hpp to hold types used by the YMF262 --- Lib/YMF262-HAL/Inc/YMF262-HAL.hpp | 13 +++++++++---- Lib/YMF262-HAL/Inc/YMF262-Types.hpp | 9 +++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 Lib/YMF262-HAL/Inc/YMF262-Types.hpp diff --git a/Lib/YMF262-HAL/Inc/YMF262-HAL.hpp b/Lib/YMF262-HAL/Inc/YMF262-HAL.hpp index 6c225fd..2fa0fee 100644 --- a/Lib/YMF262-HAL/Inc/YMF262-HAL.hpp +++ b/Lib/YMF262-HAL/Inc/YMF262-HAL.hpp @@ -3,12 +3,13 @@ #include #include "GPIO.hpp" +#include "YMF262-Types.hpp" template class YMF262_HAL{ private: - GPIOPolicy _gpio; + GPIOPolicy& _gpio; uint32_t _t_icw_ticks; uint32_t _t_as_ticks; uint32_t _t_ah_ticks; @@ -40,9 +41,9 @@ class YMF262_HAL{ public: - YMF262_HAL(GPIOPolicy policy, uint32_t opl_clock, uint32_t cpu_clock){ - _t_icw_ticks = (400 * cpu_clock) / opl_clock; - _t_recovery_ticks = (32 * cpu_clock) / opl_clock; + YMF262_HAL(GPIOPolicy& policy, uint32_t opl_clock, uint32_t cpu_clock):_gpio(policy){ + _t_icw_ticks = 400 * (cpu_clock/ opl_clock); + _t_recovery_ticks = 32 * (cpu_clock / opl_clock); double ticks_per_ns = (double)cpu_clock / 1.0e9; _t_as_ticks = (uint32_t)(10 * ticks_per_ns); _t_ah_ticks = (uint32_t)(10 * ticks_per_ns); @@ -61,6 +62,10 @@ class YMF262_HAL{ write_bus(bank,Port::DATA,data); }; + void set_OPL_Mode(OPLMode mode){ + write(Bank::BANK_1, 0x105, (mode == OPLMode::OPL3) ? 0x01 : 0x00); + }; + }; #endif \ No newline at end of file diff --git a/Lib/YMF262-HAL/Inc/YMF262-Types.hpp b/Lib/YMF262-HAL/Inc/YMF262-Types.hpp new file mode 100644 index 0000000..addcfc2 --- /dev/null +++ b/Lib/YMF262-HAL/Inc/YMF262-Types.hpp @@ -0,0 +1,9 @@ +#ifndef YMF262_MODES_HPP +#define YMF262_MODES_HPP + +enum class OPLMode{ + OPL3, + OPL2 +}; + +#endif \ No newline at end of file