@@ -79,6 +79,7 @@ public GamelogicEngineLamp[] AvailableLamps {
7979
8080 private bool _isRunning ;
8181 private bool _sizeAnnounced ;
82+ private byte [ ] _frameBuffer ;
8283
8384 private static readonly Logger Logger = LogManager . GetCurrentClassLogger ( ) ;
8485 private static readonly Color Tint = new Color ( 1 , 0.18f , 0 ) ;
@@ -130,9 +131,32 @@ private void UpdateDmd(int index, PinMameDisplayLayout displayLayout, IntPtr fra
130131 if ( ! _sizeAnnounced ) {
131132 OnDisplaysAvailable ? . Invoke ( this , new AvailableDisplays ( new DisplayConfig ( DisplayDmd , displayLayout . width , displayLayout . height ) ) ) ;
132133 _sizeAnnounced = true ;
134+ _frameBuffer = new byte [ displayLayout . width * displayLayout . height ] ;
133135 }
134- OnDisplayFrame ? . Invoke ( this , new DisplayFrameData ( DisplayDmd , GetDisplayType ( displayLayout . type ) , framePtr ) ) ;
135136
137+ var map = GetMap ( displayLayout ) ;
138+ unsafe {
139+ var ptr = ( byte * ) framePtr ;
140+ for ( var y = 0 ; y < displayLayout . height ; y ++ ) {
141+ for ( var x = 0 ; x < displayLayout . width ; x ++ ) {
142+ var pos = y * displayLayout . width + x ;
143+ _frameBuffer [ pos ] = map [ ptr [ pos ] ] ;
144+ }
145+ }
146+ }
147+
148+ OnDisplayFrame ? . Invoke ( this , new DisplayFrameData ( DisplayDmd , GetDisplayType ( displayLayout . type ) , _frameBuffer ) ) ;
149+ }
150+
151+ private Dictionary < byte , byte > GetMap ( PinMameDisplayLayout displayLayout )
152+ {
153+ if ( displayLayout . depth == 2 ) {
154+ return DmdMap2Bit ;
155+ }
156+
157+ return ( _pinMame . GetHardwareGen ( ) & ( PinMameHardwareGen . SAM | PinMameHardwareGen . SPA ) ) > 0
158+ ? DmdMapSam
159+ : DmdMapGts ;
136160 }
137161
138162 private void SolenoidChanged ( object sender , EventArgs e , int internalId , bool isActive )
@@ -259,7 +283,7 @@ private static DisplayFrameFormat GetDisplayType(PinMameDisplayType dp)
259283 case PinMameDisplayType . SEG16S :
260284 break ;
261285 case PinMameDisplayType . DMD :
262- return DisplayFrameFormat . Dmd2PinMame ;
286+ return DisplayFrameFormat . Dmd2 ;
263287
264288 case PinMameDisplayType . VIDEO :
265289 break ;
@@ -273,5 +297,28 @@ private static DisplayFrameFormat GetDisplayType(PinMameDisplayType dp)
273297
274298 throw new NotImplementedException ( "only dmd frames supported for now" ) ;
275299 }
300+
301+ private static readonly Dictionary < byte , byte > DmdMap2Bit = new Dictionary < byte , byte > {
302+ { 0x00 , 0x0 } ,
303+ { 0x14 , 0x0 } ,
304+ { 0x21 , 0x1 } ,
305+ { 0x43 , 0x1 } ,
306+ { 0x64 , 0x4 } ,
307+ } ;
308+
309+ private static readonly Dictionary < byte , byte > DmdMapSam = new Dictionary < byte , byte > {
310+ { 0x00 , 0x0 } , { 0x14 , 0x1 } , { 0x19 , 0x2 } , { 0x1E , 0x3 } ,
311+ { 0x23 , 0x4 } , { 0x28 , 0x5 } , { 0x2D , 0x6 } , { 0x32 , 0x7 } ,
312+ { 0x37 , 0x8 } , { 0x3C , 0x9 } , { 0x41 , 0xa } , { 0x46 , 0xb } ,
313+ { 0x4B , 0xc } , { 0x50 , 0xd } , { 0x5A , 0xe } , { 0x64 , 0xf }
314+ } ;
315+
316+ private static readonly Dictionary < byte , byte > DmdMapGts = new Dictionary < byte , byte > {
317+ { 0x00 , 0x0 } , { 0x1E , 0x1 } , { 0x23 , 0x2 } , { 0x28 , 0x3 } ,
318+ { 0x2D , 0x4 } , { 0x32 , 0x5 } , { 0x37 , 0x6 } , { 0x3C , 0x7 } ,
319+ { 0x41 , 0x8 } , { 0x46 , 0x9 } , { 0x4B , 0xa } , { 0x50 , 0xb } ,
320+ { 0x55 , 0xc } , { 0x5A , 0xd } , { 0x5F , 0xe } , { 0x64 , 0xf }
321+ } ;
322+
276323 }
277324}
0 commit comments