Skip to content

Commit f301968

Browse files
committed
Add RTC
1 parent 7aeb66d commit f301968

File tree

11 files changed

+271
-10
lines changed

11 files changed

+271
-10
lines changed

.vscode/extensions.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"recommendations": [
3+
"visualstudiotoolsforunity.vstuc"
4+
]
5+
}

.vscode/launch.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Attach to Unity",
6+
"type": "vstuc",
7+
"request": "attach"
8+
}
9+
]
10+
}

.vscode/settings.json

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{
2+
"files.exclude": {
3+
"**/.DS_Store": true,
4+
"**/.git": true,
5+
"**/.vs": true,
6+
"**/.gitmodules": true,
7+
"**/.vsconfig": true,
8+
"**/*.booproj": true,
9+
"**/*.pidb": true,
10+
"**/*.suo": true,
11+
"**/*.user": true,
12+
"**/*.userprefs": true,
13+
"**/*.unityproj": true,
14+
"**/*.dll": true,
15+
"**/*.exe": true,
16+
"**/*.pdf": true,
17+
"**/*.mid": true,
18+
"**/*.midi": true,
19+
"**/*.wav": true,
20+
"**/*.gif": true,
21+
"**/*.ico": true,
22+
"**/*.jpg": true,
23+
"**/*.jpeg": true,
24+
"**/*.png": true,
25+
"**/*.psd": true,
26+
"**/*.tga": true,
27+
"**/*.tif": true,
28+
"**/*.tiff": true,
29+
"**/*.3ds": true,
30+
"**/*.3DS": true,
31+
"**/*.fbx": true,
32+
"**/*.FBX": true,
33+
"**/*.lxo": true,
34+
"**/*.LXO": true,
35+
"**/*.ma": true,
36+
"**/*.MA": true,
37+
"**/*.obj": true,
38+
"**/*.OBJ": true,
39+
"**/*.asset": true,
40+
"**/*.cubemap": true,
41+
"**/*.flare": true,
42+
"**/*.mat": true,
43+
"**/*.meta": true,
44+
"**/*.prefab": true,
45+
"**/*.unity": true,
46+
"build/": true,
47+
"Build/": true,
48+
"Library/": true,
49+
"library/": true,
50+
"obj/": true,
51+
"Obj/": true,
52+
"Logs/": true,
53+
"logs/": true,
54+
"ProjectSettings/": true,
55+
"UserSettings/": true,
56+
"temp/": true,
57+
"Temp/": true
58+
},
59+
"files.associations": {
60+
"*.asset": "yaml",
61+
"*.meta": "yaml",
62+
"*.prefab": "yaml",
63+
"*.unity": "yaml",
64+
},
65+
"explorer.fileNesting.enabled": true,
66+
"explorer.fileNesting.patterns": {
67+
"*.sln": "*.csproj",
68+
},
69+
"dotnet.defaultSolution": "Digital-Logic-Sim.sln"
70+
}

Assets/Scripts/Description/Helpers/ChipTypeHelper.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using UnityEngine.TextCore.Text;
34

45
namespace DLS.Description
56
{
@@ -33,6 +34,8 @@ public static class ChipTypeHelper
3334

3435
{ ChipType.Buzzer, "BUZZER" },
3536

37+
{ ChipType.RTC, "RTC" },
38+
3639
// ---- Not really chips (but convenient to treat them as such anyway) ----
3740

3841
// ---- Inputs/Outputs ----

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ public enum ChipType
4747
BusTerminus_8Bit,
4848

4949
// ---- Audio ----
50-
Buzzer
50+
Buzzer,
51+
52+
// ---- Time ----
53+
RTC,
5154

5255
}
5356
}

Assets/Scripts/Game/Project/BuiltinChipCreator.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ public static ChipDescription[] CreateAllBuiltinChipDescriptions()
5151
CreateBus(PinBitCount.Bit8),
5252
CreateBusTerminus(PinBitCount.Bit8),
5353
// ---- Audio ----
54-
CreateBuzzer()
54+
CreateBuzzer(),
55+
// ---- Time ----
56+
CreateRTC(),
5557
};
5658
}
5759

@@ -82,6 +84,24 @@ static ChipDescription CreateBuzzer()
8284
return CreateBuiltinChipDescription(ChipType.Buzzer, size, col, inputPins, null, null);
8385
}
8486

87+
static ChipDescription CreateRTC()
88+
{
89+
Color col = new(0.4f, 0.4f, 0.4f);
90+
91+
PinDescription[] outputPins =
92+
{
93+
CreatePinDescription("D", 3, PinBitCount.Bit8),
94+
CreatePinDescription("C", 2, PinBitCount.Bit8),
95+
CreatePinDescription("B", 1, PinBitCount.Bit8),
96+
CreatePinDescription("A", 0, PinBitCount.Bit8),
97+
};
98+
99+
float height = SubChipInstance.MinChipHeightForPins(outputPins, null);
100+
Vector2 size = new(CalculateGridSnappedWidth(GridSize * 9), height);
101+
102+
return CreateBuiltinChipDescription(ChipType.RTC, size, col, null, outputPins);
103+
}
104+
85105
static ChipDescription dev_CreateRAM_8()
86106
{
87107
Color col = new(0.85f, 0.45f, 0.3f);

Assets/Scripts/Simulation/Simulator.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,16 @@ static void ProcessBuiltinChip(SimChip chip)
506506
audioState.RegisterNote(freqIndex, (uint)volumeIndex);
507507
break;
508508
}
509+
case ChipType.RTC:
510+
{
511+
const uint ByteMask = 0b11111111;
512+
int unixTime = (int) DateTimeOffset.UtcNow.ToUnixTimeSeconds();
513+
chip.OutputPins[0].State = (ushort)((unixTime >> 24) & ByteMask);
514+
chip.OutputPins[1].State = (ushort)((unixTime >> 16) & ByteMask);
515+
chip.OutputPins[2].State = (ushort)((unixTime >> 8) & ByteMask);
516+
chip.OutputPins[3].State = (ushort)(unixTime & ByteMask);
517+
break;
518+
}
509519
// ---- Bus types ----
510520
default:
511521
{

ProjectSettings/ProjectVersion.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
m_EditorVersion: 6000.0.46f1
2-
m_EditorVersionWithRevision: 6000.0.46f1 (fb93bc360d3a)
1+
m_EditorVersion: 6000.0.49f1
2+
m_EditorVersionWithRevision: 6000.0.49f1 (840e0a9776d9)

TestData/Projects/MainTest/Chips/BuzzTest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"DLSVersion": "2.1.5",
2+
"DLSVersion": "2.1.6",
33
"Name": "BuzzTest",
44
"NameLocation": 0,
55
"ChipType": 0,
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
{
2+
"DLSVersion": "2.1.6",
3+
"Name": "RTCTest",
4+
"NameLocation": 0,
5+
"ChipType": 0,
6+
"Size": {
7+
"x": 1.175,
8+
"y": 2.0
9+
},
10+
"Colour": {
11+
"r": 0.8187522,
12+
"g": 0.385453254,
13+
"b": 0.334759057,
14+
"a": 1
15+
},
16+
"InputPins":[],
17+
"OutputPins":[
18+
{
19+
"Name":"OUT",
20+
"ID":1492030497,
21+
"Position":{
22+
"x":1.25,
23+
"y":1.0
24+
},
25+
"BitCount":8,
26+
"Colour":0,
27+
"ValueDisplayMode":1
28+
},
29+
{
30+
"Name":"OUT",
31+
"ID":900692905,
32+
"Position":{
33+
"x":1.25,
34+
"y":0.5
35+
},
36+
"BitCount":8,
37+
"Colour":0,
38+
"ValueDisplayMode":1
39+
},
40+
{
41+
"Name":"OUT",
42+
"ID":1767071873,
43+
"Position":{
44+
"x":1.25,
45+
"y":0.0
46+
},
47+
"BitCount":8,
48+
"Colour":0,
49+
"ValueDisplayMode":1
50+
},
51+
{
52+
"Name":"OUT",
53+
"ID":1820587991,
54+
"Position":{
55+
"x":1.25,
56+
"y":-0.5
57+
},
58+
"BitCount":8,
59+
"Colour":0,
60+
"ValueDisplayMode":1
61+
}
62+
],
63+
"SubChips":[
64+
{
65+
"Name":"RTC",
66+
"ID":2097162199,
67+
"Label":"",
68+
"Position":{
69+
"x":-1.0,
70+
"y":0.25
71+
},
72+
"OutputPinColourInfo":[{"PinColour":0,"PinID":3},{"PinColour":0,"PinID":2},{"PinColour":0,"PinID":1},{"PinColour":0,"PinID":0}],
73+
"InternalData":null
74+
}
75+
],
76+
"Wires":[
77+
{
78+
"SourcePinAddress":{
79+
"PinID":3,
80+
"PinOwnerID":2097162199
81+
},
82+
"TargetPinAddress":{
83+
"PinID":0,
84+
"PinOwnerID":1492030497
85+
},
86+
"ConnectionType":0,
87+
"ConnectedWireIndex":-1,
88+
"ConnectedWireSegmentIndex":-1,
89+
"Points":[{"x":0.0,"y":0.0},{"x":0.0,"y":0.0}]
90+
},
91+
{
92+
"SourcePinAddress":{
93+
"PinID":2,
94+
"PinOwnerID":2097162199
95+
},
96+
"TargetPinAddress":{
97+
"PinID":0,
98+
"PinOwnerID":900692905
99+
},
100+
"ConnectionType":0,
101+
"ConnectedWireIndex":-1,
102+
"ConnectedWireSegmentIndex":-1,
103+
"Points":[{"x":0.0,"y":0.0},{"x":0.0,"y":0.0}]
104+
},
105+
{
106+
"SourcePinAddress":{
107+
"PinID":1,
108+
"PinOwnerID":2097162199
109+
},
110+
"TargetPinAddress":{
111+
"PinID":0,
112+
"PinOwnerID":1767071873
113+
},
114+
"ConnectionType":0,
115+
"ConnectedWireIndex":-1,
116+
"ConnectedWireSegmentIndex":-1,
117+
"Points":[{"x":0.0,"y":0.0},{"x":0.0,"y":0.0}]
118+
},
119+
{
120+
"SourcePinAddress":{
121+
"PinID":0,
122+
"PinOwnerID":2097162199
123+
},
124+
"TargetPinAddress":{
125+
"PinID":0,
126+
"PinOwnerID":1820587991
127+
},
128+
"ConnectionType":0,
129+
"ConnectedWireIndex":-1,
130+
"ConnectedWireSegmentIndex":-1,
131+
"Points":[{"x":0.0,"y":0.0},{"x":0.0,"y":0.0}]
132+
}
133+
],
134+
"Displays": null
135+
}

0 commit comments

Comments
 (0)