Skip to content

Commit 7a80580

Browse files
author
Parshwa
committed
fixed a few bugs
1 parent bde3e55 commit 7a80580

19 files changed

Lines changed: 312 additions & 1153 deletions

File tree

Assets/Scripts/Description/Helpers/ChipTypeHelper.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ public static class ChipTypeHelper
1616
{ ChipType.TriStateBuffer, "3-STATE BUFFER" },
1717
// ---- Memory ----
1818
{ ChipType.dev_Ram_8Bit, "dev.RAM-8" },
19+
{ ChipType.Rom_256x2x8, $"ROM 256{mulSymbol}x2x8" },
1920
{ ChipType.Rom_256x16, $"ROM 256{mulSymbol}16" },
21+
{ ChipType.Rom_256x32, $"ROM 256{mulSymbol}32" },
2022
// ---- Split / Merge ----
2123
{ ChipType.Split_4To1Bit, "4-1BIT" },
2224
{ ChipType.Split_8To1Bit, "8-1BIT" },
@@ -69,7 +71,7 @@ public static class ChipTypeHelper
6971

7072
public static bool IsBusTerminusType(ChipType type) => type is ChipType.BusTerminus_1Bit or ChipType.BusTerminus_4Bit or ChipType.BusTerminus_8Bit or ChipType.BusTerminus_16Bit;
7173

72-
public static bool IsRomType(ChipType type) => type == ChipType.Rom_256x16;
74+
public static bool IsRomType(ChipType type) => type is ChipType.Rom_256x2x8 or ChipType.Rom_256x16 or ChipType.Rom_256x32;
7375

7476
public static ChipType GetCorrespondingBusTerminusType(ChipType type)
7577
{

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@ public enum ChipType
1212

1313
// ---- Memory ----
1414
dev_Ram_8Bit,
15+
Rom_256x2x8,
1516
Rom_256x16,
17+
Rom_256x32,
1618

1719
// ---- Displays ----
18-
//TODO: Make all displays use 0 to 255 for RGB, and make sure you duplicate them first so only if needed overide them, also make the RGBLED
1920
SevenSegmentDisplay,
2021
DisplayRGB,
2122
DisplayDot,
2223
DisplayLED,
2324
DisplayRGBLED,
2425

2526
// ---- Merge / Split ----
26-
//TODO: Make the 16 MERGES AND SPLITS atcually work
2727
Merge_1To4Bit,
2828
Merge_1To8Bit,
2929
Merge_4To8Bit,

Assets/Scripts/Game/Project/BuiltinChipCreator.cs

Lines changed: 81 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ public static ChipDescription[] CreateAllBuiltinChipDescriptions()
3131
CreatePulse(),
3232
// ---- Memory ----
3333
dev_CreateRAM_8(),
34-
CreateROM_8(),
34+
CreateROM(ChipType.Rom_256x2x8),
35+
CreateROM(ChipType.Rom_256x16),
36+
CreateROM(ChipType.Rom_256x32),
3537
// ---- Merge / Split ----
3638
CreateBitConversionChip(ChipType.Split_4To1Bit, PinBitCount.Bit4, PinBitCount.Bit1, 1, 4),
3739
CreateBitConversionChip(ChipType.Split_8To4Bit, PinBitCount.Bit8, PinBitCount.Bit4, 1, 2),
@@ -94,22 +96,76 @@ static ChipDescription dev_CreateRAM_8()
9496
return CreateBuiltinChipDescription(ChipType.dev_Ram_8Bit, size, col, inputPins, outputPins);
9597
}
9698

97-
static ChipDescription CreateROM_8()
99+
static ChipDescription CreateROM(ChipType type)
98100
{
99-
PinDescription[] inputPins =
100-
{
101-
CreatePinDescription("ADDRESS", 0, PinBitCount.Bit8)
102-
};
103-
PinDescription[] outputPins =
104-
{
105-
CreatePinDescription("OUT B", 1, PinBitCount.Bit8),
106-
CreatePinDescription("OUT A", 2, PinBitCount.Bit8)
107-
};
101+
switch(type){
102+
case ChipType.Rom_256x2x8:
103+
{
104+
PinDescription[] inputPins =
105+
{
106+
CreatePinDescription("ADDRESS", 0, PinBitCount.Bit8)
107+
};
108+
PinDescription[] outputPins =
109+
{
110+
CreatePinDescription("OUT B", 1, PinBitCount.Bit8),
111+
CreatePinDescription("OUT A", 2, PinBitCount.Bit8)
112+
};
113+
114+
Color col = new(0.25f, 0.35f, 0.5f);
115+
Vector2 size = new(GridSize * 12, SubChipInstance.MinChipHeightForPins(inputPins, outputPins));
108116

109-
Color col = new(0.25f, 0.35f, 0.5f);
110-
Vector2 size = new(GridSize * 12, SubChipInstance.MinChipHeightForPins(inputPins, outputPins));
117+
return CreateBuiltinChipDescription(ChipType.Rom_256x2x8, size, col, inputPins, outputPins);
118+
}
119+
case ChipType.Rom_256x16:
120+
{
121+
PinDescription[] inputPins =
122+
{
123+
CreatePinDescription("ADDRESS", 0, PinBitCount.Bit8)
124+
};
125+
PinDescription[] outputPins =
126+
{
127+
CreatePinDescription("OUT A", 1, PinBitCount.Bit16)
128+
};
129+
130+
Color col = new(0.25f, 0.35f, 0.5f);
131+
Vector2 size = new(GridSize * 12, SubChipInstance.MinChipHeightForPins(inputPins, outputPins));
132+
133+
return CreateBuiltinChipDescription(ChipType.Rom_256x16, size, col, inputPins, outputPins);
134+
}
135+
case ChipType.Rom_256x32:
136+
{
137+
PinDescription[] inputPins =
138+
{
139+
CreatePinDescription("ADDRESS", 0, PinBitCount.Bit8)
140+
};
141+
PinDescription[] outputPins =
142+
{
143+
CreatePinDescription("OUT B", 1, PinBitCount.Bit16),
144+
CreatePinDescription("OUT A", 2, PinBitCount.Bit16)
145+
};
111146

112-
return CreateBuiltinChipDescription(ChipType.Rom_256x16, size, col, inputPins, outputPins);
147+
Color col = new(0.25f, 0.35f, 0.5f);
148+
Vector2 size = new(GridSize * 12, SubChipInstance.MinChipHeightForPins(inputPins, outputPins));
149+
150+
return CreateBuiltinChipDescription(ChipType.Rom_256x32, size, col, inputPins, outputPins);
151+
}
152+
default:
153+
{
154+
PinDescription[] inputPins =
155+
{
156+
CreatePinDescription("ADDRESS", 0, PinBitCount.Bit8)
157+
};
158+
PinDescription[] outputPins =
159+
{
160+
CreatePinDescription("OUT A", 1, PinBitCount.Bit16)
161+
};
162+
163+
Color col = new(0.25f, 0.35f, 0.5f);
164+
Vector2 size = new(GridSize * 12, SubChipInstance.MinChipHeightForPins(inputPins, outputPins));
165+
166+
return CreateBuiltinChipDescription(ChipType.Rom_256x16, size, col, inputPins, outputPins);
167+
}
168+
}
113169
}
114170

115171
static ChipDescription CreateInputKeyChip()
@@ -216,30 +272,30 @@ static ChipDescription CreateDisplay7Seg()
216272

217273
static ChipDescription CreateDisplayRGB()
218274
{
219-
float height = GridSize * 21;
220-
float width = height;
221-
float displayWidth = height - GridSize * 2;
275+
float displayWidth = GridSize * 19;
222276

223277
Color col = new(0.1f, 0.1f, 0.1f);
224-
Vector2 size = new(width, height);
225278

226279
PinDescription[] inputPins =
227280
{
228281
CreatePinDescription("ADDRESS", 0, PinBitCount.Bit8),
229-
CreatePinDescription("RED", 1, PinBitCount.Bit4),
230-
CreatePinDescription("GREEN", 2, PinBitCount.Bit4),
231-
CreatePinDescription("BLUE", 3, PinBitCount.Bit4),
282+
CreatePinDescription("RED", 1, PinBitCount.Bit8),
283+
CreatePinDescription("GREEN", 2, PinBitCount.Bit8),
284+
CreatePinDescription("BLUE", 3, PinBitCount.Bit8),
232285
CreatePinDescription("RESET", 4),
233286
CreatePinDescription("WRITE", 5),
234287
CreatePinDescription("REFRESH", 6),
235288
CreatePinDescription("CLOCK", 7)
236289
};
290+
float height = SubChipInstance.MinChipHeightForPins(inputPins, null);
291+
float width = height;
292+
Vector2 size = new(width, height);
237293

238294
PinDescription[] outputPins =
239295
{
240-
CreatePinDescription("R OUT", 8, PinBitCount.Bit4),
241-
CreatePinDescription("G OUT", 9, PinBitCount.Bit4),
242-
CreatePinDescription("B OUT", 10, PinBitCount.Bit4)
296+
CreatePinDescription("R OUT", 8, PinBitCount.Bit8),
297+
CreatePinDescription("G OUT", 9, PinBitCount.Bit8),
298+
CreatePinDescription("B OUT", 10, PinBitCount.Bit8)
243299
};
244300

245301
DisplayDescription[] displays =
@@ -361,7 +417,7 @@ static ChipDescription CreateDisplayRGBLED()
361417
new()
362418
{
363419
Position = Vector2.right * PinRadius / 3 * 0,
364-
Scale = displayWidth,
420+
Scale = GridSize * 1,
365421
SubChipID = -1
366422
}
367423
};

Assets/Scripts/Game/Project/BuiltinCollectionCreator.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ public static ChipCollection[] CreateDefaultChipCollections()
6363
ChipType.DisplayRGBLED
6464
),
6565
CreateChipCollection("MEMORY",
66-
ChipType.Rom_256x16
66+
ChipType.Rom_256x2x8,
67+
ChipType.Rom_256x16,
68+
ChipType.Rom_256x32
6769
)
6870
};
6971
}

Assets/Scripts/Graphics/UI/Menus/RomEditMenu.cs

Lines changed: 56 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Text;
33
using DLS.Game;
4+
using DLS.Description;
45
using Seb.Helpers;
56
using Seb.Types;
67
using Seb.Vis;
@@ -214,78 +215,81 @@ static bool ValidateInputString(string text)
214215
// Convert from uint to display string with given display mode
215216
static string UIntToDisplayString(uint raw, DataDisplayMode displayFormat, int bitCount)
216217
{
217-
return displayFormat switch
218+
string data = displayFormat switch
218219
{
219220
DataDisplayMode.Binary => Convert.ToString(raw, 2).PadLeft(bitCount, '0'),
220221
DataDisplayMode.DecimalSigned => Maths.TwosComplement(raw, bitCount) + "",
221222
DataDisplayMode.DecimalUnsigned => raw + "",
222223
DataDisplayMode.HEX => raw.ToString("X").PadLeft(bitCount / 4, '0'),
223224
_ => throw new NotImplementedException("Unsupported display format: " + displayFormat)
224225
};
226+
Debug.Log("Loaded "+data);
227+
return data;
225228
}
226229

227230
// Convert string with given format to uint
228231
static uint DisplayStringToUInt(string displayString, DataDisplayMode stringFormat, int bitCount)
229232
{
230233
displayString = displayString.Replace(" ", string.Empty);
234+
Debug.Log("Display " + displayString);
231235
uint uintVal;
232-
233-
switch (stringFormat)
234-
{
235-
case DataDisplayMode.Binary:
236-
uintVal = Convert.ToUInt32(displayString, 2);
237-
break;
238-
case DataDisplayMode.DecimalSigned:
236+
try{
237+
switch (stringFormat)
239238
{
240-
int signedValue = int.Parse(displayString);
241-
uint unsignedRange = 1u << bitCount;
242-
if (signedValue < 0)
243-
{
244-
uintVal = (uint)(signedValue + unsignedRange);
245-
}
246-
else
239+
case DataDisplayMode.Binary:
240+
uintVal = Convert.ToUInt32(displayString, 2);
241+
break;
242+
case DataDisplayMode.DecimalSigned:
247243
{
248-
uintVal = (uint)signedValue;
249-
}
244+
int signedValue = int.Parse(displayString);
245+
uint unsignedRange = 1u << bitCount;
246+
if (signedValue < 0)
247+
{
248+
uintVal = (uint)(signedValue + unsignedRange);
249+
}
250+
else
251+
{
252+
uintVal = (uint)signedValue;
253+
}
250254

251-
break;
255+
break;
256+
}
257+
case DataDisplayMode.DecimalUnsigned:
258+
uintVal = uint.Parse(displayString);
259+
break;
260+
case DataDisplayMode.HEX:
261+
int value = Convert.ToInt32(displayString, 16);
262+
uintVal = (uint)value;
263+
break;
264+
default:
265+
throw new NotImplementedException("Unsupported display format: " + stringFormat);
266+
}
267+
}catch (Exception e){
268+
Debug.Log(e);
269+
if (stringFormat is DataDisplayMode.Binary){
270+
uintVal =(uint) ((ulong) (Convert.ToInt64(displayString, 2))& 0b11111111111111111111111111111111);
252271
}
253-
case DataDisplayMode.DecimalUnsigned:
254-
uintVal = uint.Parse(displayString);
255-
break;
256-
case DataDisplayMode.HEX:
257-
int value = Convert.ToInt32(displayString, 16);
258-
uintVal = (uint)value;
259-
break;
260-
default:
261-
throw new NotImplementedException("Unsupported display format: " + stringFormat);
272+
uintVal = 0;
262273
}
263-
274+
Debug.Log(uintVal);
264275
return uintVal;
265276
}
266277

267278
static bool TryParseDisplayStringToUInt(string displayString, DataDisplayMode stringFormat, int bitCount, out uint raw)
268279
{
269-
try
270-
{
271-
raw = DisplayStringToUInt(displayString, stringFormat, bitCount);
272-
uint maxVal = (1u << bitCount) - 1;
273-
274-
// If value is too large to fit in given bit-count, clamp the result and return failure
275-
// (note: maybe makes more sense to wrap the result, but I think it's more obvious to player what happened if it just clamps)
276-
if (raw > maxVal)
277-
{
278-
raw = maxVal;
279-
return false;
280-
}
280+
raw = DisplayStringToUInt(displayString, stringFormat, bitCount);
281+
long maxVal = (long) Math.Pow(2,bitCount) - 1;
282+
uint max = (uint) maxVal;
281283

282-
return true;
283-
}
284-
catch (Exception)
284+
// If value is too large to fit in given bit-count, clamp the result and return failure
285+
// (note: maybe makes more sense to wrap the result, but I think it's more obvious to player what happened if it just clamps)
286+
if (raw > max)
285287
{
286-
raw = 0;
288+
raw = max;
287289
return false;
288290
}
291+
292+
return true;
289293
}
290294

291295
static void SaveChangesToROM()
@@ -340,7 +344,14 @@ public static void OnMenuOpened()
340344
{
341345
romChip = (SubChipInstance)ContextMenu.interactionContext;
342346
RowCount = romChip.InternalData.Length;
343-
ActiveRomDataBitCount = 16; //
347+
ActiveRomDataBitCount = romChip.ChipType switch
348+
{
349+
ChipType.Rom_256x2x8 => 16,
350+
ChipType.Rom_256x16 => 16,
351+
ChipType.Rom_256x32 => 32,
352+
_ => 16
353+
};
354+
344355

345356
ID_DataDisplayMode = new UIHandle("ROM_DataDisplayMode", romChip.ID);
346357
ID_scrollbar = new UIHandle("ROM_EditScrollbar", romChip.ID);

Assets/Scripts/Graphics/World/DevSceneDrawer.cs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,6 @@ public static Bounds2D DrawDisplayWithBackground(DisplayInstance display, Vector
379379
Bounds2D bounds = DrawDisplay(display, pos, 1, rootChip, sim);
380380

381381
// Border colour around display
382-
Draw.ModifyQuad(displayBorderID, bounds.Centre, bounds.Size + Vector2.one * 0.03f, borderCol);
383382
// Black background behind display to fill any gaps
384383
Draw.ModifyQuad(displayBackingID, bounds.Centre, bounds.Size, Color.black);
385384

@@ -454,9 +453,10 @@ public static Bounds2D DrawDisplay(DisplayInstance display, Vector2 posParent, f
454453
public static Bounds2D DrawDisplay_RGB(Vector2 centre, float scale, SimChip simSource)
455454
{
456455
const int pixelsPerRow = 16;
457-
const float borderFrac = 0.95f;
458-
const float pixelSizeT = 0.925f;
456+
const float borderFrac = 1f;
457+
const float pixelSizeT = 1f;
459458
// Draw background
459+
Debug.Log(scale);
460460
Draw.Quad(centre, Vector2.one * scale, Color.black);
461461
float size = scale * borderFrac;
462462

@@ -475,9 +475,9 @@ public static Bounds2D DrawDisplay_RGB(Vector2 centre, float scale, SimChip simS
475475
{
476476
int address = y * 16 + x;
477477
uint pixelState = simSource.InternalState[address];
478-
float red = Unpack4BitColChannel(pixelState);
479-
float green = Unpack4BitColChannel(pixelState >> 4);
480-
float blue = Unpack4BitColChannel(pixelState >> 8);
478+
float red = Unpack8BitColChannel(pixelState);
479+
float green = Unpack8BitColChannel(pixelState >> 8);
480+
float blue = Unpack8BitColChannel(pixelState >> 16);
481481
col = new Color(red, green, blue);
482482
}
483483

@@ -487,11 +487,6 @@ public static Bounds2D DrawDisplay_RGB(Vector2 centre, float scale, SimChip simS
487487
}
488488

489489
return Bounds2D.CreateFromCentreAndSize(centre, Vector2.one * scale);
490-
491-
float Unpack4BitColChannel(uint raw)
492-
{
493-
return (raw & 0b1111) / 15f;
494-
}
495490
}
496491

497492
public static Bounds2D DrawDisplay_Dot(Vector2 centre, float scale, SimChip simSource)

0 commit comments

Comments
 (0)