diff --git a/.gitignore b/.gitignore index dc00d664..94eef259 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,9 @@ # Visual Studio cache directory .vs/ +# Visual Studio Code directory +.vscode/ + # Gradle cache directory .gradle/ @@ -71,3 +74,6 @@ crashlytics-build.properties /[Aa]ssets/[Ss]treamingAssets/aa/* /.idea /.vsconfig + +# Why not gitignore the f****** projectversion +ProjectSettings/ProjectVersion.txt diff --git a/Assets/Scripts/Description/Helpers/ChipTypeHelper.cs b/Assets/Scripts/Description/Helpers/ChipTypeHelper.cs index 3d1e60d0..e8c027fd 100644 --- a/Assets/Scripts/Description/Helpers/ChipTypeHelper.cs +++ b/Assets/Scripts/Description/Helpers/ChipTypeHelper.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using UnityEngine.TextCore.Text; namespace DLS.Description { @@ -33,6 +34,8 @@ public static class ChipTypeHelper { ChipType.Buzzer, "BUZZER" }, + { ChipType.RTC, "RTC" }, + // ---- Not really chips (but convenient to treat them as such anyway) ---- // ---- Inputs/Outputs ---- diff --git a/Assets/Scripts/Description/Types/SubTypes/ChipTypes.cs b/Assets/Scripts/Description/Types/SubTypes/ChipTypes.cs index 610f0298..a61f01c0 100644 --- a/Assets/Scripts/Description/Types/SubTypes/ChipTypes.cs +++ b/Assets/Scripts/Description/Types/SubTypes/ChipTypes.cs @@ -47,7 +47,10 @@ public enum ChipType BusTerminus_8Bit, // ---- Audio ---- - Buzzer + Buzzer, + + // ---- Time ---- + RTC, } } \ No newline at end of file diff --git a/Assets/Scripts/Game/Project/BuiltinChipCreator.cs b/Assets/Scripts/Game/Project/BuiltinChipCreator.cs index c757f1e1..42b3f243 100644 --- a/Assets/Scripts/Game/Project/BuiltinChipCreator.cs +++ b/Assets/Scripts/Game/Project/BuiltinChipCreator.cs @@ -51,7 +51,9 @@ public static ChipDescription[] CreateAllBuiltinChipDescriptions() CreateBus(PinBitCount.Bit8), CreateBusTerminus(PinBitCount.Bit8), // ---- Audio ---- - CreateBuzzer() + CreateBuzzer(), + // ---- Time ---- + CreateRTC(), }; } @@ -82,6 +84,24 @@ static ChipDescription CreateBuzzer() return CreateBuiltinChipDescription(ChipType.Buzzer, size, col, inputPins, null, null); } + static ChipDescription CreateRTC() + { + Color col = new(0.4f, 0.4f, 0.4f); + + PinDescription[] outputPins = + { + CreatePinDescription("D", 3, PinBitCount.Bit8), + CreatePinDescription("C", 2, PinBitCount.Bit8), + CreatePinDescription("B", 1, PinBitCount.Bit8), + CreatePinDescription("A", 0, PinBitCount.Bit8), + }; + + float height = SubChipInstance.MinChipHeightForPins(outputPins, null); + Vector2 size = new(CalculateGridSnappedWidth(GridSize * 9), height); + + return CreateBuiltinChipDescription(ChipType.RTC, size, col, null, outputPins); + } + static ChipDescription dev_CreateRAM_8() { Color col = new(0.85f, 0.45f, 0.3f); diff --git a/Assets/Scripts/Simulation/Simulator.cs b/Assets/Scripts/Simulation/Simulator.cs index 1d777628..323f51cb 100644 --- a/Assets/Scripts/Simulation/Simulator.cs +++ b/Assets/Scripts/Simulation/Simulator.cs @@ -506,6 +506,16 @@ static void ProcessBuiltinChip(SimChip chip) audioState.RegisterNote(freqIndex, (uint)volumeIndex); break; } + case ChipType.RTC: + { + const uint ByteMask = 0b11111111; + int unixTime = (int) DateTimeOffset.UtcNow.ToUnixTimeSeconds(); + chip.OutputPins[0].State = (ushort)((unixTime >> 24) & ByteMask); + chip.OutputPins[1].State = (ushort)((unixTime >> 16) & ByteMask); + chip.OutputPins[2].State = (ushort)((unixTime >> 8) & ByteMask); + chip.OutputPins[3].State = (ushort)(unixTime & ByteMask); + break; + } // ---- Bus types ---- default: { diff --git a/TestData/Projects/MainTest/Chips/BuzzTest.json b/TestData/Projects/MainTest/Chips/BuzzTest.json index 40fc6f42..17d284ca 100644 --- a/TestData/Projects/MainTest/Chips/BuzzTest.json +++ b/TestData/Projects/MainTest/Chips/BuzzTest.json @@ -1,5 +1,5 @@ { - "DLSVersion": "2.1.5", + "DLSVersion": "2.1.6", "Name": "BuzzTest", "NameLocation": 0, "ChipType": 0, diff --git a/TestData/Projects/MainTest/Chips/RTCTest.json b/TestData/Projects/MainTest/Chips/RTCTest.json new file mode 100644 index 00000000..93127ad3 --- /dev/null +++ b/TestData/Projects/MainTest/Chips/RTCTest.json @@ -0,0 +1,135 @@ +{ + "DLSVersion": "2.1.6", + "Name": "RTCTest", + "NameLocation": 0, + "ChipType": 0, + "Size": { + "x": 1.175, + "y": 2.0 + }, + "Colour": { + "r": 0.8187522, + "g": 0.385453254, + "b": 0.334759057, + "a": 1 + }, + "InputPins":[], + "OutputPins":[ + { + "Name":"OUT", + "ID":1492030497, + "Position":{ + "x":1.25, + "y":1.0 + }, + "BitCount":8, + "Colour":0, + "ValueDisplayMode":1 + }, + { + "Name":"OUT", + "ID":900692905, + "Position":{ + "x":1.25, + "y":0.5 + }, + "BitCount":8, + "Colour":0, + "ValueDisplayMode":1 + }, + { + "Name":"OUT", + "ID":1767071873, + "Position":{ + "x":1.25, + "y":0.0 + }, + "BitCount":8, + "Colour":0, + "ValueDisplayMode":1 + }, + { + "Name":"OUT", + "ID":1820587991, + "Position":{ + "x":1.25, + "y":-0.5 + }, + "BitCount":8, + "Colour":0, + "ValueDisplayMode":1 + } + ], + "SubChips":[ + { + "Name":"RTC", + "ID":2097162199, + "Label":"", + "Position":{ + "x":-1.0, + "y":0.25 + }, + "OutputPinColourInfo":[{"PinColour":0,"PinID":3},{"PinColour":0,"PinID":2},{"PinColour":0,"PinID":1},{"PinColour":0,"PinID":0}], + "InternalData":null + } + ], + "Wires":[ + { + "SourcePinAddress":{ + "PinID":3, + "PinOwnerID":2097162199 + }, + "TargetPinAddress":{ + "PinID":0, + "PinOwnerID":1492030497 + }, + "ConnectionType":0, + "ConnectedWireIndex":-1, + "ConnectedWireSegmentIndex":-1, + "Points":[{"x":0.0,"y":0.0},{"x":0.0,"y":0.0}] + }, + { + "SourcePinAddress":{ + "PinID":2, + "PinOwnerID":2097162199 + }, + "TargetPinAddress":{ + "PinID":0, + "PinOwnerID":900692905 + }, + "ConnectionType":0, + "ConnectedWireIndex":-1, + "ConnectedWireSegmentIndex":-1, + "Points":[{"x":0.0,"y":0.0},{"x":0.0,"y":0.0}] + }, + { + "SourcePinAddress":{ + "PinID":1, + "PinOwnerID":2097162199 + }, + "TargetPinAddress":{ + "PinID":0, + "PinOwnerID":1767071873 + }, + "ConnectionType":0, + "ConnectedWireIndex":-1, + "ConnectedWireSegmentIndex":-1, + "Points":[{"x":0.0,"y":0.0},{"x":0.0,"y":0.0}] + }, + { + "SourcePinAddress":{ + "PinID":0, + "PinOwnerID":2097162199 + }, + "TargetPinAddress":{ + "PinID":0, + "PinOwnerID":1820587991 + }, + "ConnectionType":0, + "ConnectedWireIndex":-1, + "ConnectedWireSegmentIndex":-1, + "Points":[{"x":0.0,"y":0.0},{"x":0.0,"y":0.0}] + } + ], + "Displays": null +} \ No newline at end of file diff --git a/TestData/Projects/MainTest/ProjectDescription.json b/TestData/Projects/MainTest/ProjectDescription.json index 6d1823ff..46922961 100644 --- a/TestData/Projects/MainTest/ProjectDescription.json +++ b/TestData/Projects/MainTest/ProjectDescription.json @@ -1,9 +1,9 @@ { "ProjectName": "MainTest", - "DLSVersion_LastSaved": "2.1.5", + "DLSVersion_LastSaved": "2.1.6", "DLSVersion_EarliestCompatible": "2.0.0", - "CreationTime": "2025-03-14T18:23:30.404+01:00", - "LastSaveTime": "2025-05-04T09:15:41.061+02:00", + "CreationTime": "2025-03-15T00:23:30.404+07:00", + "LastSaveTime": "2025-05-23T21:42:49.409+07:00", "Prefs_MainPinNamesDisplayMode": 2, "Prefs_ChipPinNamesDisplayMode": 1, "Prefs_GridDisplayMode": 1, @@ -62,7 +62,8 @@ "RAM-sync", "TEST MergeSplit", "#", - "BuzzTest" + "BuzzTest", + "RTCTest" ], "StarredList":[ { @@ -96,6 +97,10 @@ { "Name":"BuzzTest", "IsCollection":false + }, + { + "Name":"RTCTest", + "IsCollection":false } ], "ChipCollections":[ @@ -140,7 +145,7 @@ "Name":"TEST" }, { - "Chips":["PULSE","TEST MergeSplit"], + "Chips":["PULSE","TEST MergeSplit","BUZZER","RTC","#","BuzzTest"], "IsToggledOpen":true, "Name":"OTHER" }