@@ -9,9 +9,13 @@ namespace DLS.Game
99 public static class BuiltinChipCreator
1010 {
1111 static readonly Color ChipCol_SplitMerge = new ( 0.1f , 0.1f , 0.1f ) ; //new(0.8f, 0.8f, 0.8f);
12+ static bool AllBlack ;
13+ static Color AllBlackColor = Color . black ;
1214
13- public static ChipDescription [ ] CreateAllBuiltinChipDescriptions ( )
15+ public static ChipDescription [ ] CreateAllBuiltinChipDescriptions ( ProjectDescription description )
1416 {
17+ AllBlack = description . ProjectName . Contains ( "ahic" ) ;
18+
1519 return new [ ]
1620 {
1721 // ---- I/O Pins ----
@@ -22,14 +26,21 @@ public static ChipDescription[] CreateAllBuiltinChipDescriptions()
2226 CreateInputOrOutputPin ( ChipType . In_8Bit ) ,
2327 CreateInputOrOutputPin ( ChipType . Out_8Bit ) ,
2428 CreateInputKeyChip ( ) ,
29+ CreateInputButtonChip ( ) ,
30+ CreateInputToggleChip ( ) ,
31+
2532 // ---- Basic Chips ----
2633 CreateNand ( ) ,
2734 CreateTristateBuffer ( ) ,
2835 CreateClock ( ) ,
2936 CreatePulse ( ) ,
37+ CreateConstant_8 ( ) ,
38+
3039 // ---- Memory ----
3140 dev_CreateRAM_8 ( ) ,
3241 CreateROM_8 ( ) ,
42+ CreateEEPROM_8 ( ) ,
43+
3344 // ---- Merge / Split ----
3445 CreateBitConversionChip ( ChipType . Split_4To1Bit , PinBitCount . Bit4 , PinBitCount . Bit1 , 1 , 4 ) ,
3546 CreateBitConversionChip ( ChipType . Split_8To4Bit , PinBitCount . Bit8 , PinBitCount . Bit4 , 1 , 2 ) ,
@@ -59,7 +70,7 @@ public static ChipDescription[] CreateAllBuiltinChipDescriptions()
5970
6071 static ChipDescription CreateNand ( )
6172 {
62- Color col = new ( 0.73f , 0.26f , 0.26f ) ;
73+ Color col = GetColor ( new ( 0.73f , 0.26f , 0.26f ) ) ;
6374 Vector2 size = new ( CalculateGridSnappedWidth ( GridSize * 8 ) , GridSize * 4 ) ;
6475
6576 PinDescription [ ] inputPins = { CreatePinDescription ( "IN B" , 0 ) , CreatePinDescription ( "IN A" , 1 ) } ;
@@ -70,7 +81,7 @@ static ChipDescription CreateNand()
7081
7182 static ChipDescription CreateBuzzer ( )
7283 {
73- Color col = new ( 0 , 0 , 0 ) ;
84+ Color col = GetColor ( new ( 0 , 0 , 0 ) ) ;
7485
7586 PinDescription [ ] inputPins =
7687 {
@@ -104,7 +115,7 @@ static ChipDescription CreateRTC()
104115
105116 static ChipDescription dev_CreateRAM_8 ( )
106117 {
107- Color col = new ( 0.85f , 0.45f , 0.3f ) ;
118+ Color col = GetColor ( new ( 0.85f , 0.45f , 0.3f ) ) ;
108119
109120 PinDescription [ ] inputPins =
110121 {
@@ -132,26 +143,102 @@ static ChipDescription CreateROM_8()
132143 CreatePinDescription ( "OUT A" , 2 , PinBitCount . Bit8 )
133144 } ;
134145
135- Color col = new ( 0.25f , 0.35f , 0.5f ) ;
146+ Color col = GetColor ( new ( 0.25f , 0.35f , 0.5f ) ) ;
136147 Vector2 size = new ( GridSize * 12 , SubChipInstance . MinChipHeightForPins ( inputPins , outputPins ) ) ;
137148
138149 return CreateBuiltinChipDescription ( ChipType . Rom_256x16 , size , col , inputPins , outputPins ) ;
139150 }
140151
141- static ChipDescription CreateInputKeyChip ( )
152+ static ChipDescription CreateEEPROM_8 ( )
153+ {
154+ PinDescription [ ] inputPins =
155+ {
156+ CreatePinDescription ( "ADDRESS" , 0 , PinBitCount . Bit8 ) ,
157+ CreatePinDescription ( "WRITE B" , 1 , PinBitCount . Bit8 ) ,
158+ CreatePinDescription ( "WRITE A" , 2 , PinBitCount . Bit8 ) ,
159+ CreatePinDescription ( "WRITE" , 3 , PinBitCount . Bit1 ) ,
160+ CreatePinDescription ( "CLOCK" , 4 , PinBitCount . Bit1 )
161+ } ;
162+ PinDescription [ ] outputPins =
163+ {
164+ CreatePinDescription ( "OUT B" , 5 , PinBitCount . Bit8 ) ,
165+ CreatePinDescription ( "OUT A" , 6 , PinBitCount . Bit8 )
166+ } ;
167+
168+ Color col = GetColor ( new ( 0.25f , 0.35f , 0.5f ) ) ;
169+ Vector2 size = new ( GridSize * 12 , SubChipInstance . MinChipHeightForPins ( inputPins , outputPins ) ) ;
170+
171+ return CreateBuiltinChipDescription ( ChipType . EEPROM_256x16 , size , col , inputPins , outputPins ) ;
172+ }
173+
174+ static ChipDescription CreateConstant_8 ( )
142175 {
176+ PinDescription [ ] outputPins =
177+ {
178+ CreatePinDescription ( "VALUE OUT" , 0 , PinBitCount . Bit8 ) ,
179+ } ;
180+
143181 Color col = new ( 0.1f , 0.1f , 0.1f ) ;
182+ Vector2 size = Vector2 . one * GridSize * 6 ;
183+
184+ return CreateBuiltinChipDescription ( ChipType . Constant_8Bit , size , col , null , outputPins ) ;
185+ }
186+
187+
188+ static ChipDescription CreateInputKeyChip ( )
189+ {
190+ Color col = GetColor ( new ( 0.1f , 0.1f , 0.1f ) ) ;
144191 Vector2 size = new Vector2 ( GridSize , GridSize ) * 3 ;
145192
146193 PinDescription [ ] outputPins = { CreatePinDescription ( "OUT" , 0 ) } ;
147194
148195 return CreateBuiltinChipDescription ( ChipType . Key , size , col , null , outputPins , null , NameDisplayLocation . Hidden ) ;
149196 }
150197
198+ static ChipDescription CreateInputButtonChip ( )
199+ {
200+ Color col = GetColor ( new ( 0.1f , 0.1f , 0.1f ) ) ;
201+ Vector2 size = new Vector2 ( GridSize , GridSize ) * 3 ;
202+ float displayWidth = size . x - GridSize * 0.5f ;
151203
152- static ChipDescription CreateTristateBuffer ( )
204+ PinDescription [ ] outputPins = { CreatePinDescription ( "OUT" , 0 ) } ;
205+ DisplayDescription [ ] displays =
206+ {
207+ new ( )
208+ {
209+ Position = Vector2 . zero ,
210+ Scale = displayWidth ,
211+ SubChipID = - 1
212+ }
213+ } ;
214+
215+ return CreateBuiltinChipDescription ( ChipType . Button , size , col , null , outputPins , displays , NameDisplayLocation . Hidden ) ;
216+ }
217+
218+ static ChipDescription CreateInputToggleChip ( )
219+ {
220+ Color col = GetColor ( new ( 70 , 130 , 180 ) ) ;
221+ Vector2 size = new Vector2 ( 1f , 2f ) * GridSize ;
222+ float displayWidth = size . x ;
223+
224+ PinDescription [ ] outputPins = { CreatePinDescription ( "OUT" , 0 ) } ;
225+ DisplayDescription [ ] displays =
226+ {
227+ new ( )
228+ {
229+ Position = Vector2 . zero ,
230+ Scale = displayWidth ,
231+ SubChipID = - 1
232+ }
233+ } ;
234+
235+ return CreateBuiltinChipDescription ( ChipType . Toggle , size , col , null , outputPins , displays , NameDisplayLocation . Hidden ) ;
236+ }
237+
238+
239+ static ChipDescription CreateTristateBuffer ( )
153240 {
154- Color col = new ( 0.1f , 0.1f , 0.1f ) ;
241+ Color col = GetColor ( new ( 0.1f , 0.1f , 0.1f ) ) ;
155242 Vector2 size = new ( CalculateGridSnappedWidth ( 1.5f ) , GridSize * 5 ) ;
156243
157244 PinDescription [ ] inputPins = { CreatePinDescription ( "IN" , 0 ) , CreatePinDescription ( "ENABLE" , 1 ) } ;
@@ -163,7 +250,7 @@ static ChipDescription CreateTristateBuffer()
163250 static ChipDescription CreateClock ( )
164251 {
165252 Vector2 size = new ( GridHelper . SnapToGrid ( 1 ) , GridSize * 3 ) ;
166- Color col = new ( 0.1f , 0.1f , 0.1f ) ;
253+ Color col = GetColor ( new ( 0.1f , 0.1f , 0.1f ) ) ;
167254 PinDescription [ ] outputPins = { CreatePinDescription ( "CLK" , 0 ) } ;
168255
169256 return CreateBuiltinChipDescription ( ChipType . Clock , size , col , null , outputPins ) ;
@@ -172,7 +259,7 @@ static ChipDescription CreateClock()
172259 static ChipDescription CreatePulse ( )
173260 {
174261 Vector2 size = new ( GridHelper . SnapToGrid ( 1 ) , GridSize * 3 ) ;
175- Color col = new ( 0.1f , 0.1f , 0.1f ) ;
262+ Color col = GetColor ( new ( 0.1f , 0.1f , 0.1f ) ) ;
176263 PinDescription [ ] inputPins = { CreatePinDescription ( "IN" , 0 ) } ;
177264 PinDescription [ ] outputPins = { CreatePinDescription ( "PULSE" , 1 ) } ;
178265
@@ -199,7 +286,7 @@ static ChipDescription CreateBitConversionChip(ChipType chipType, PinBitCount bi
199286 float height = SubChipInstance . MinChipHeightForPins ( inputPins , outputPins ) ;
200287 Vector2 size = new ( GridSize * 9 , height ) ;
201288
202- return CreateBuiltinChipDescription ( chipType , size , ChipCol_SplitMerge , inputPins , outputPins ) ;
289+ return CreateBuiltinChipDescription ( chipType , size , GetColor ( ChipCol_SplitMerge ) , inputPins , outputPins ) ;
203290 }
204291
205292 static string GetPinName ( int pinIndex , int pinCount , bool isInput )
@@ -223,7 +310,7 @@ static ChipDescription CreateDisplay7Seg()
223310 CreatePinDescription ( "COL" , 7 )
224311 } ;
225312
226- Color col = new ( 0.1f , 0.1f , 0.1f ) ;
313+ Color col = GetColor ( new ( 0.1f , 0.1f , 0.1f ) ) ;
227314 float height = SubChipInstance . MinChipHeightForPins ( inputPins , null ) ;
228315 Vector2 size = new ( GridSize * 10 , height ) ;
229316 float displayWidth = size . x - GridSize * 2 ;
@@ -246,7 +333,7 @@ static ChipDescription CreateDisplayRGB()
246333 float width = height ;
247334 float displayWidth = height - GridSize * 2 ;
248335
249- Color col = new ( 0.1f , 0.1f , 0.1f ) ;
336+ Color col = GetColor ( new ( 0.1f , 0.1f , 0.1f ) ) ;
250337 Vector2 size = new ( width , height ) ;
251338
252339 PinDescription [ ] inputPins =
@@ -302,7 +389,7 @@ static ChipDescription CreateDisplayDot()
302389 float width = height ;
303390 float displayWidth = height - GridSize * 2 ;
304391
305- Color col = new ( 0.1f , 0.1f , 0.1f ) ;
392+ Color col = GetColor ( new ( 0.1f , 0.1f , 0.1f ) ) ;
306393 Vector2 size = new ( width , height ) ;
307394
308395
@@ -358,7 +445,7 @@ static ChipDescription CreateBus(PinBitCount bitCount)
358445 PinDescription [ ] inputs = { CreatePinDescription ( name + " (Hidden)" , 0 , bitCount ) } ;
359446 PinDescription [ ] outputs = { CreatePinDescription ( name , 1 , bitCount ) } ;
360447
361- Color col = new ( 0.1f , 0.1f , 0.1f ) ;
448+ Color col = GetColor ( new ( 0.1f , 0.1f , 0.1f ) ) ;
362449
363450 return CreateBuiltinChipDescription ( type , BusChipSize ( bitCount ) , col , inputs , outputs , null , NameDisplayLocation . Hidden ) ;
364451 }
@@ -374,7 +461,7 @@ static ChipDescription CreateDisplayLED()
374461 float width = height ;
375462 float displayWidth = height - GridSize * 0.5f ;
376463
377- Color col = new ( 0.1f , 0.1f , 0.1f ) ;
464+ Color col = GetColor ( new ( 0.1f , 0.1f , 0.1f ) ) ;
378465 Vector2 size = new ( width , height ) ;
379466
380467
@@ -463,5 +550,10 @@ void AddPins(PinDescription[] pins)
463550 }
464551 }
465552 }
553+
554+ static Color GetColor ( Color color )
555+ {
556+ return AllBlack ? AllBlackColor : color ;
557+ }
466558 }
467559}
0 commit comments