gearmulator

Emulation of classic VA synths of the late 90s/2000s that are based on Motorola 56300 family DSPs
Log | Files | Refs | Submodules | README | LICENSE

leds.cpp (1414B)


      1 #include "leds.h"
      2 
      3 #include "mqtypes.h"
      4 
      5 #include "mc68k/port.h"
      6 
      7 namespace mqLib
      8 {
      9 	bool Leds::exec(const mc68k::Port& _portF, const mc68k::Port& _portGP, const mc68k::Port& _portE)
     10 	{
     11 		bool changed = false;
     12 
     13 		if(_portE.getDirection() & (1<<LedPower))
     14 		{
     15 			const uint32_t powerLedState = (_portE.read() >> LedPower) & 1;
     16 
     17 			if(setLed(static_cast<uint32_t>(Led::Power), powerLedState))
     18 				changed = true;
     19 		}
     20 
     21 		if(!(_portF.getDirection() & (1<<LedWriteLatch)))
     22 			return ret(changed);
     23 
     24 		if(_portGP.getDirection() != 0xff)
     25 			return ret(changed);
     26 
     27 		const auto prevF7 = m_stateF7;
     28 		const auto stateF7 = _portF.read() & (1<<LedWriteLatch);
     29 		m_stateF7 = stateF7;
     30 
     31 		if(!stateF7 || prevF7)
     32 			return ret(changed);
     33 
     34 		const auto gp = _portGP.read();
     35 		const auto group = (gp >> 5) - 1;
     36 		const auto leds = gp & 0x1f;
     37 		
     38 		if(group >= 5)
     39 			return ret(changed);
     40 
     41 		uint32_t ledIndex = group;
     42 
     43 		for(auto i=0; i<5; ++i)
     44 		{
     45 			changed |= setLed(ledIndex, (leds >> i) & 1);
     46 
     47 			ledIndex += 5;
     48 		}
     49 
     50 		return ret(changed);
     51 	}
     52 
     53 	bool Leds::setLed(uint32_t _index, uint32_t _value)
     54 	{
     55 		auto& led = m_ledState[_index];
     56 		const auto prev = led;
     57 		led = _value;
     58 
     59 		if(led == prev)
     60 			return false;
     61 
     62 //		LOG("LED " << _index << " changed to " << _value);
     63 		return true;
     64 	}
     65 
     66 	bool Leds::ret(const bool _changed) const
     67 	{
     68 		if(!_changed)
     69 			return false;
     70 		if(m_changeCallback)
     71 			m_changeCallback();
     72 		return true;
     73 	}
     74 }