@@ -79,6 +79,7 @@ public GamelogicEngineLamp[] AvailableLamps {
79
79
80
80
private bool _isRunning ;
81
81
private bool _sizeAnnounced ;
82
+ private byte [ ] _frameBuffer ;
82
83
83
84
private static readonly Logger Logger = LogManager . GetCurrentClassLogger ( ) ;
84
85
private static readonly Color Tint = new Color ( 1 , 0.18f , 0 ) ;
@@ -130,9 +131,32 @@ private void UpdateDmd(int index, PinMameDisplayLayout displayLayout, IntPtr fra
130
131
if ( ! _sizeAnnounced ) {
131
132
OnDisplaysAvailable ? . Invoke ( this , new AvailableDisplays ( new DisplayConfig ( DisplayDmd , displayLayout . width , displayLayout . height ) ) ) ;
132
133
_sizeAnnounced = true ;
134
+ _frameBuffer = new byte [ displayLayout . width * displayLayout . height ] ;
133
135
}
134
- OnDisplayFrame ? . Invoke ( this , new DisplayFrameData ( DisplayDmd , GetDisplayType ( displayLayout . type ) , framePtr ) ) ;
135
136
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 ;
136
160
}
137
161
138
162
private void SolenoidChanged ( object sender , EventArgs e , int internalId , bool isActive )
@@ -259,7 +283,7 @@ private static DisplayFrameFormat GetDisplayType(PinMameDisplayType dp)
259
283
case PinMameDisplayType . SEG16S :
260
284
break ;
261
285
case PinMameDisplayType . DMD :
262
- return DisplayFrameFormat . Dmd2PinMame ;
286
+ return DisplayFrameFormat . Dmd2 ;
263
287
264
288
case PinMameDisplayType . VIDEO :
265
289
break ;
@@ -273,5 +297,28 @@ private static DisplayFrameFormat GetDisplayType(PinMameDisplayType dp)
273
297
274
298
throw new NotImplementedException ( "only dmd frames supported for now" ) ;
275
299
}
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
+
276
323
}
277
324
}
0 commit comments