Skip to content

Commit bde3e55

Browse files
author
Parshwa
committed
ALL 16-BIT merge and Splits work now
1 parent 7cbe789 commit bde3e55

7 files changed

Lines changed: 919 additions & 4 deletions

File tree

Assets/Scripts/Game/Project/BuiltinChipCreator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public static ChipDescription[] CreateAllBuiltinChipDescriptions()
3636
CreateBitConversionChip(ChipType.Split_4To1Bit, PinBitCount.Bit4, PinBitCount.Bit1, 1, 4),
3737
CreateBitConversionChip(ChipType.Split_8To4Bit, PinBitCount.Bit8, PinBitCount.Bit4, 1, 2),
3838
CreateBitConversionChip(ChipType.Split_8To1Bit, PinBitCount.Bit8, PinBitCount.Bit1, 1, 8),
39-
CreateBitConversionChip(ChipType.Split_16To1Bit, PinBitCount.Bit16, PinBitCount.Bit1, 1, 8),
39+
CreateBitConversionChip(ChipType.Split_16To1Bit, PinBitCount.Bit16, PinBitCount.Bit1, 1, 16),
4040
CreateBitConversionChip(ChipType.Split_16To4Bit, PinBitCount.Bit16, PinBitCount.Bit4, 1, 4),
4141
CreateBitConversionChip(ChipType.Split_16To8Bit, PinBitCount.Bit16, PinBitCount.Bit8, 1, 2),
4242

Assets/Scripts/Graphics/World/DevSceneDrawer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -581,10 +581,10 @@ public static Bounds2D DrawDisplay_DisplayRGBLED(Vector2 centre, float scale, bo
581581
// Draw background
582582
Draw.Quad(centre, Vector2.one * scale, Color.black);
583583
Vector2 pixelDrawSize = Vector2.one * (pixelSize * pixelSizeT);
584-
Color onColor = ActiveTheme.DisplayLEDCols[1]; // default fallback
584+
Color onColor;
585585
if (sim == null)
586586
{
587-
onColor = Color.white;
587+
onColor = Color.white; // default fallback
588588
}
589589
else
590590
{

Assets/Scripts/Simulation/PinState.cs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,75 @@ public static void Set4BitFrom8BitSource(ref uint state, uint source8bit, bool f
4949
}
5050
}
5151

52+
public static void Set8BitFrom16BitSource(ref uint state, uint source16bit, bool firstNibble)
53+
{
54+
ushort sourceBitStates = GetBitStates(source16bit);
55+
ushort sourceTristateFlags = GetTristateFlags(source16bit);
56+
57+
if (firstNibble)
58+
{
59+
const ushort mask = 0b11111111;
60+
Set(ref state, (ushort)(sourceBitStates & mask), (ushort)(sourceTristateFlags & mask));
61+
}
62+
else
63+
{
64+
const uint mask = 0b1111111100000000;
65+
Set(ref state, (ushort)((sourceBitStates & mask) >> 8), (ushort)((sourceTristateFlags & mask) >> 8));
66+
}
67+
}
68+
69+
public static void Set4BitFrom16BitSource(ref uint state, uint source16Bit, int section)
70+
{
71+
ushort sourceBitStates = GetBitStates(source16Bit);
72+
ushort sourceTristateFlags = GetTristateFlags(source16Bit);
73+
74+
if (section == 0)
75+
{
76+
const ushort mask = 0b1111;
77+
Set(ref state, (ushort)(sourceBitStates & mask), (ushort)(sourceTristateFlags & mask));
78+
}
79+
else if (section == 1)
80+
{
81+
const uint mask = 0b11110000;
82+
Set(ref state, (ushort)((sourceBitStates & mask) >> 4), (ushort)((sourceTristateFlags & mask) >> 4));
83+
}
84+
else if (section == 2)
85+
{
86+
const uint mask = 0b111100000000;
87+
Set(ref state, (ushort)((sourceBitStates & mask) >> 4), (ushort)((sourceTristateFlags & mask) >> 8));
88+
}
89+
else if (section == 3)
90+
{
91+
const uint mask = 0b1111000000000000;
92+
Set(ref state, (ushort)((sourceBitStates & mask) >> 4), (ushort)((sourceTristateFlags & mask) >> 12));
93+
}
94+
}
95+
5296
public static void Set8BitFrom4BitSources(ref uint state, uint a, uint b)
5397
{
5498
ushort bitStates = (ushort)(GetBitStates(a) | (GetBitStates(b) << 4));
5599
ushort tristateFlags = (ushort)((GetTristateFlags(a) & 0b1111) | ((GetTristateFlags(b) & 0b1111) << 4));
56100
Set(ref state, bitStates, tristateFlags);
57101
}
58102

103+
public static void Set16BitFrom4BitSources(ref uint state, uint a, uint b, uint c, uint d)
104+
{
105+
ushort bitStates1 = (ushort)(GetBitStates(a) | (GetBitStates(b) << 4));
106+
ushort tristateFlags1 = (ushort)((GetTristateFlags(a) & 0b1111) | ((GetTristateFlags(b) & 0b1111) << 4));
107+
ushort bitStates2 = (ushort)(GetBitStates(c) | (GetBitStates(d) << 4));
108+
ushort tristateFlags2 = (ushort)((GetTristateFlags(c) & 0b1111) | ((GetTristateFlags(d) & 0b1111) << 4));
109+
ushort bitStates = (ushort)(GetBitStates(bitStates1) | (GetBitStates(bitStates2) << 8));
110+
ushort tristateFlags = (ushort)((GetTristateFlags(bitStates1) & 0b11111111) | ((GetTristateFlags(bitStates2) & 0b11111111) << 8));
111+
Set(ref state, bitStates, tristateFlags);
112+
}
113+
114+
public static void Set16BitFrom8BitSources(ref uint state, uint a, uint b)
115+
{
116+
ushort bitStates = (ushort)(GetBitStates(a) | (GetBitStates(b) << 8));
117+
ushort tristateFlags = (ushort)((GetTristateFlags(a) & 0b11111111) | ((GetTristateFlags(b) & 0b11111111) << 8));
118+
Set(ref state, bitStates, tristateFlags);
119+
}
120+
59121

60122
public static void Toggle(ref uint state, int bitIndex)
61123
{

Assets/Scripts/Simulation/Simulator.cs

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,49 @@ static void ProcessBuiltinChip(SimChip chip)
289289
PinState.Set8BitFrom4BitSources(ref out8.State, in4B.State, in4A.State);
290290
break;
291291
}
292+
case ChipType.Merge_1To16Bit:
293+
{
294+
uint stateA = chip.InputPins[15].State & PinState.SingleBitMask; // lsb
295+
uint stateB = chip.InputPins[14].State & PinState.SingleBitMask;
296+
uint stateC = chip.InputPins[13].State & PinState.SingleBitMask;
297+
uint stateD = chip.InputPins[12].State & PinState.SingleBitMask;
298+
uint stateE = chip.InputPins[11].State & PinState.SingleBitMask;
299+
uint stateF = chip.InputPins[10].State & PinState.SingleBitMask;
300+
uint stateG = chip.InputPins[9].State & PinState.SingleBitMask;
301+
uint stateH = chip.InputPins[8].State & PinState.SingleBitMask;
302+
uint stateI = chip.InputPins[7].State & PinState.SingleBitMask;
303+
uint stateJ = chip.InputPins[6].State & PinState.SingleBitMask;
304+
uint stateK = chip.InputPins[5].State & PinState.SingleBitMask;
305+
uint stateL = chip.InputPins[4].State & PinState.SingleBitMask;
306+
uint stateM = chip.InputPins[3].State & PinState.SingleBitMask;
307+
uint stateN = chip.InputPins[2].State & PinState.SingleBitMask;
308+
uint stateO = chip.InputPins[1].State & PinState.SingleBitMask;
309+
uint stateP = chip.InputPins[0].State & PinState.SingleBitMask;
310+
chip.OutputPins[0].State = stateA | stateB << 1 | stateC << 2
311+
| stateD << 3 | stateE << 4 | stateF << 5 | stateG << 6
312+
| stateH << 7 | stateI << 8 | stateJ << 9 | stateK << 10
313+
| stateL << 11 | stateM << 12 | stateN << 13 | stateO << 14
314+
| stateP << 15;
315+
break;
316+
}
317+
case ChipType.Merge_4To16Bit:
318+
{
319+
SimPin in4A = chip.InputPins[0];
320+
SimPin in4B = chip.InputPins[1];
321+
SimPin in4C = chip.InputPins[2];
322+
SimPin in4D = chip.InputPins[3];
323+
SimPin out16 = chip.OutputPins[0];
324+
PinState.Set16BitFrom4BitSources(ref out16.State, in4D.State, in4C.State, in4B.State, in4A.State);
325+
break;
326+
}
327+
case ChipType.Merge_8To16Bit:
328+
{
329+
SimPin in8A = chip.InputPins[0];
330+
SimPin in8B = chip.InputPins[1];
331+
SimPin out16 = chip.OutputPins[0];
332+
PinState.Set16BitFrom8BitSources(ref out16.State, in8B.State, in8A.State);
333+
break;
334+
}
292335
case ChipType.Split_8To4Bit:
293336
{
294337
SimPin in8 = chip.InputPins[0];
@@ -311,6 +354,49 @@ static void ProcessBuiltinChip(SimChip chip)
311354
chip.OutputPins[7].State = (in8 >> 0) & PinState.SingleBitMask;
312355
break;
313356
}
357+
case ChipType.Split_16To1Bit:
358+
{
359+
uint in16 = chip.InputPins[0].State;
360+
chip.OutputPins[0].State = (in16 >> 15) & PinState.SingleBitMask;
361+
chip.OutputPins[1].State = (in16 >> 14) & PinState.SingleBitMask;
362+
chip.OutputPins[2].State = (in16 >> 13) & PinState.SingleBitMask;
363+
chip.OutputPins[3].State = (in16 >> 12) & PinState.SingleBitMask;
364+
chip.OutputPins[4].State = (in16 >> 11) & PinState.SingleBitMask;
365+
chip.OutputPins[5].State = (in16 >> 10) & PinState.SingleBitMask;
366+
chip.OutputPins[6].State = (in16 >> 9) & PinState.SingleBitMask;
367+
chip.OutputPins[7].State = (in16 >> 8) & PinState.SingleBitMask;
368+
chip.OutputPins[8].State = (in16 >> 7) & PinState.SingleBitMask;
369+
chip.OutputPins[9].State = (in16 >> 6) & PinState.SingleBitMask;
370+
chip.OutputPins[10].State = (in16 >> 5) & PinState.SingleBitMask;
371+
chip.OutputPins[11].State = (in16 >> 4) & PinState.SingleBitMask;
372+
chip.OutputPins[12].State = (in16 >> 3) & PinState.SingleBitMask;
373+
chip.OutputPins[13].State = (in16 >> 2) & PinState.SingleBitMask;
374+
chip.OutputPins[14].State = (in16 >> 1) & PinState.SingleBitMask;
375+
chip.OutputPins[15].State = (in16 >> 0) & PinState.SingleBitMask;
376+
break;
377+
}
378+
case ChipType.Split_16To4Bit:
379+
{
380+
SimPin in16 = chip.InputPins[0];
381+
SimPin out4A = chip.OutputPins[0];
382+
SimPin out4B = chip.OutputPins[1];
383+
SimPin out4C = chip.OutputPins[2];
384+
SimPin out4D = chip.OutputPins[3];
385+
PinState.Set4BitFrom16BitSource(ref out4A.State, in16.State, 3);
386+
PinState.Set4BitFrom16BitSource(ref out4B.State, in16.State, 2);
387+
PinState.Set4BitFrom16BitSource(ref out4C.State, in16.State, 1);
388+
PinState.Set4BitFrom16BitSource(ref out4D.State, in16.State, 0);
389+
break;
390+
}
391+
case ChipType.Split_16To8Bit:
392+
{
393+
SimPin in16 = chip.InputPins[0];
394+
SimPin out8A = chip.OutputPins[0];
395+
SimPin out8B = chip.OutputPins[1];
396+
PinState.Set4BitFrom8BitSource(ref out8A.State, in16.State, false);
397+
PinState.Set4BitFrom8BitSource(ref out8B.State, in16.State, true);
398+
break;
399+
}
314400
case ChipType.TriStateBuffer:
315401
{
316402
SimPin dataPin = chip.InputPins[0];

TestData/Projects/MainTest/ProjectDescription.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"DLSVersion_LastSaved": "2.1.4",
44
"DLSVersion_EarliestCompatible": "2.0.0",
55
"CreationTime": "2025-03-14T22:53:30.404+05:30",
6-
"LastSaveTime": "2025-04-27T10:46:43.427+05:30",
6+
"LastSaveTime": "2025-04-27T11:27:43.890+05:30",
77
"Prefs_MainPinNamesDisplayMode": 2,
88
"Prefs_ChipPinNamesDisplayMode": 1,
99
"Prefs_GridDisplayMode": 1,

0 commit comments

Comments
 (0)