Skip to content

Commit fa13055

Browse files
authored
Merge branch 'main' into feat-RTC
2 parents f301968 + dbecdc9 commit fa13055

45 files changed

Lines changed: 1697 additions & 72 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Assets/Scripts/Description/Helpers/ChipTypeHelper.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ public static class ChipTypeHelper
1515
{ ChipType.Clock, "CLOCK" },
1616
{ ChipType.Pulse, "PULSE" },
1717
{ ChipType.TriStateBuffer, "3-STATE BUFFER" },
18+
{ ChipType.Constant_8Bit, "CONST" },
1819
// ---- Memory ----
19-
{ ChipType.dev_Ram_8Bit, "dev.RAM-8" },
20+
{ ChipType.dev_Ram_8Bit, "RAM-8" },
2021
{ ChipType.Rom_256x16, $"ROM 256{mulSymbol}16" },
22+
{ ChipType.EEPROM_256x16, $"EEPROM 256{mulSymbol}16" },
2123
// ---- Split / Merge ----
2224
{ ChipType.Split_4To1Bit, "4-1BIT" },
2325
{ ChipType.Split_8To1Bit, "8-1BIT" },
@@ -46,6 +48,9 @@ public static class ChipTypeHelper
4648
{ ChipType.Out_4Bit, "OUT-4" },
4749
{ ChipType.Out_8Bit, "OUT-8" },
4850
{ ChipType.Key, "KEY" },
51+
{ ChipType.Button, "BUTTON" },
52+
{ ChipType.Toggle, "DIPSWITCH" },
53+
4954
// ---- Buses ----
5055
{ ChipType.Bus_1Bit, "BUS-1" },
5156
{ ChipType.Bus_4Bit, "BUS-4" },
@@ -63,7 +68,7 @@ public static class ChipTypeHelper
6368

6469
public static bool IsBusTerminusType(ChipType type) => type is ChipType.BusTerminus_1Bit or ChipType.BusTerminus_4Bit or ChipType.BusTerminus_8Bit;
6570

66-
public static bool IsRomType(ChipType type) => type == ChipType.Rom_256x16;
71+
public static bool IsRomType(ChipType type) => type == ChipType.Rom_256x16 || type == ChipType.EEPROM_256x16;
6772

6873
public static ChipType GetCorrespondingBusTerminusType(ChipType type)
6974
{
@@ -111,5 +116,15 @@ public static (bool isInput, bool isOutput, PinBitCount numBits) IsInputOrOutput
111116
_ => (false, false, PinBitCount.Bit1)
112117
};
113118
}
119+
120+
public static bool IsClickableDisplayType(ChipType type) {
121+
// Return true for any chiptype that is a clickable display
122+
123+
return type == ChipType.Button || type == ChipType.Toggle;
124+
}
125+
126+
public static bool IsInternalDataModifiable(ChipType type) {
127+
return type == ChipType.EEPROM_256x16 || type == ChipType.Toggle;
128+
}
114129
}
115130
}

Assets/Scripts/Description/Types/SubTypes/ChipTypes.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public enum ChipType
1313
// ---- Memory ----
1414
dev_Ram_8Bit,
1515
Rom_256x16,
16+
EEPROM_256x16,
1617

1718
// ---- Displays ----
1819
SevenSegmentDisplay,
@@ -38,8 +39,13 @@ public enum ChipType
3839

3940
Key,
4041

41-
// ---- Buses ----
42-
Bus_1Bit,
42+
Button,
43+
Toggle,
44+
45+
Constant_8Bit,
46+
47+
// ---- Buses ----
48+
Bus_1Bit,
4349
BusTerminus_1Bit,
4450
Bus_4Bit,
4551
BusTerminus_4Bit,

Assets/Scripts/Game/Elements/DisplayInstance.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace DLS.Game
66
{
7-
public class DisplayInstance
7+
public class DisplayInstance : IClickable
88
{
99
public List<DisplayInstance> ChildDisplays;
1010
public DisplayDescription Desc;

Assets/Scripts/Game/Elements/SubChipInstance.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,12 @@ public void FlipBus()
378378
}
379379
}
380380

381+
public void UpdateInternalData(uint[] data)
382+
{
383+
if (!ChipTypeHelper.IsInternalDataModifiable(ChipType)) throw new Exception("Internal Data is not modifiable for the type of chip : " + ChipTypeHelper.GetName(ChipType));
384+
Array.Copy(data, InternalData, data.Length);
385+
}
386+
381387
void LoadOutputPinColours(OutputPinColourInfo[] cols)
382388
{
383389
if (cols == null) return;

Assets/Scripts/Game/Interaction/ChipInteractionController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public class ChipInteractionController
5050
public bool CanInteractWithPin => CanInteract;
5151
public bool CanInteractWithPinStateDisplay => CanInteract && !IsCreatingWire && Project.ActiveProject.CanEditViewedChip;
5252
public bool CanInteractWithPinHandle => CanInteractWithPinStateDisplay;
53-
53+
public bool CanInteractWithButton => CanInteract;
5454

5555
public ChipInteractionController(Project project)
5656
{
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System.Numerics;
2+
using Seb.Types;
3+
4+
namespace DLS.Game
5+
{
6+
public interface IClickable : IInteractable
7+
{
8+
9+
}
10+
}

Assets/Scripts/Game/Interaction/Interfaces/IClickable.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Scripts/Game/Project/BuiltinChipCreator.cs

Lines changed: 108 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)