commit d6ef8732602f81993bad6a282df580b62eb5cc6a
Author: evenfri <evenfri256@gmail.com>
Date: Thu, 13 Aug 2026 01:01:30 +0800
initial commit
Diffstat:
17 files changed, 561 insertions(+), 0 deletions(-)
diff --git a/.editorconfig b/.editorconfig
@@ -0,0 +1,4 @@
+root = true
+
+[*]
+charset = utf-8
diff --git a/.gitattributes b/.gitattributes
@@ -0,0 +1,2 @@
+# Normalize EOL for all files that Git considers text files.
+* text=auto eol=lf
diff --git a/.gitignore b/.gitignore
@@ -0,0 +1,3 @@
+# Godot 4+ specific ignores
+.godot/
+/android/
diff --git a/computer.png b/computer.png
Binary files differ.
diff --git a/computer.png.import b/computer.png.import
@@ -0,0 +1,40 @@
+[remap]
+
+importer="texture"
+type="CompressedTexture2D"
+uid="uid://osbck513ghe3"
+path="res://.godot/imported/computer.png-b68f47fb53ff69fa8b397299ff070cc0.ctex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://computer.png"
+dest_files=["res://.godot/imported/computer.png-b68f47fb53ff69fa8b397299ff070cc0.ctex"]
+
+[params]
+
+compress/mode=0
+compress/high_quality=false
+compress/lossy_quality=0.7
+compress/uastc_level=0
+compress/rdo_quality_loss=0.0
+compress/hdr_compression=1
+compress/normal_map=0
+compress/channel_pack=0
+mipmaps/generate=false
+mipmaps/limit=-1
+roughness/mode=0
+roughness/src_normal=""
+process/channel_remap/red=0
+process/channel_remap/green=1
+process/channel_remap/blue=2
+process/channel_remap/alpha=3
+process/fix_alpha_border=true
+process/premult_alpha=false
+process/normal_map_invert_y=false
+process/hdr_as_srgb=false
+process/hdr_clamp_exposure=false
+process/size_limit=0
+detect_3d/compress_to=1
diff --git a/computer_interface.cs b/computer_interface.cs
@@ -0,0 +1,77 @@
+using Godot;
+using System;
+
+public partial class computer_interface : Node {
+
+[Export] public Button[] button_bits;
+[Export] public Button[] button_memory_bits;
+[Export] public Sprite2D[] lamp_current_instruction;
+
+[Export] public Color lamp_on = Colors.Red;
+[Export] public Color lamp_off = Colors.DarkGray;
+
+[Export] public Button button_write_byte;
+[Export] public Button button_jmp_memory;
+[Export] public Button button_examine;
+
+emulator emu;
+short curr_addr;
+byte curr_instr;
+
+public override void _Ready() {
+ emu = new emulator();
+ button_write_byte.Pressed += write_byte;
+ button_jmp_memory.Pressed += jmp_memory;
+ button_examine.Pressed += examine;
+
+ update_lamps(curr_instr);
+}
+
+public override void _Process(double delta) {
+}
+
+void write_byte() {
+ byte b = assem_byte(button_bits, 0);
+
+ curr_instr = b;
+ emu.write_byte(b, curr_addr);
+ update_lamps(b);
+
+ GD.Print($"write byte 0x{b:x2} by 0x{curr_addr:x4}");
+}
+
+void jmp_memory() {
+ byte b0 = assem_byte(button_memory_bits, 0);
+ byte b1 = assem_byte(button_memory_bits, 8);
+
+ short r = (short)((b1 << 8) | b0);
+ curr_addr = r;
+
+ GD.Print($"jump to 0x{curr_addr:x4}");
+}
+
+void examine() {
+ curr_instr = emu.read_byte(curr_addr);
+ update_lamps(curr_instr);
+
+ GD.Print($"read byte 0x{curr_instr:x2} by 0x{curr_addr:x4}");
+}
+
+void update_lamps(byte value) {
+ for (int i = 0; i < 8 && i < lamp_current_instruction.Length; i++) {
+ bool is_bit_set = (value & (1 << i)) != 0;
+ lamp_current_instruction[i].SelfModulate = is_bit_set ? lamp_on : lamp_off;
+ }
+}
+
+byte assem_byte(Button[] buttons, int offset) {
+ byte r = 0;
+ for (int i = 0; i < 8; i++) {
+ if (buttons[offset + i].ButtonPressed) {
+ r |= (byte)(1 << i);
+ }
+ }
+ return r;
+}
+
+}
+\ No newline at end of file
diff --git a/computer_interface.cs.uid b/computer_interface.cs.uid
@@ -0,0 +1 @@
+uid://cgdypxcbuexde
diff --git a/emulator.cs b/emulator.cs
@@ -0,0 +1,13 @@
+public class emulator {
+
+byte[] memory = new byte[1024*16];
+
+public void write_byte(byte b, short addr) {
+ memory[addr] = b;
+}
+
+public byte read_byte(short addr) {
+ return memory[addr];
+}
+
+}
+\ No newline at end of file
diff --git a/emulator.cs.uid b/emulator.cs.uid
@@ -0,0 +1 @@
+uid://betivycg1fnii
diff --git a/icon.svg b/icon.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="128" height="128"><rect width="124" height="124" x="2" y="2" fill="#363d52" stroke="#212532" stroke-width="4" rx="14"/><g fill="#fff" transform="translate(12.322 12.322)scale(.101)"><path d="M105 673v33q407 354 814 0v-33z"/><path fill="#478cbf" d="m105 673 152 14q12 1 15 14l4 67 132 10 8-61q2-11 15-15h162q13 4 15 15l8 61 132-10 4-67q3-13 15-14l152-14V427q30-39 56-81-35-59-83-108-43 20-82 47-40-37-88-64 7-51 8-102-59-28-123-42-26 43-46 89-49-7-98 0-20-46-46-89-64 14-123 42 1 51 8 102-48 27-88 64-39-27-82-47-48 49-83 108 26 42 56 81zm0 33v39c0 276 813 276 814 0v-39l-134 12-5 69q-2 10-14 13l-162 11q-12 0-16-11l-10-65H446l-10 65q-4 11-16 11l-162-11q-12-3-14-13l-5-69z"/><path d="M483 600c0 34 58 34 58 0v-86c0-34-58-34-58 0z"/><circle cx="725" cy="526" r="90"/><circle cx="299" cy="526" r="90"/></g><g fill="#414042" transform="translate(12.322 12.322)scale(.101)"><circle cx="307" cy="532" r="60"/><circle cx="717" cy="532" r="60"/></g></svg>
diff --git a/icon.svg.import b/icon.svg.import
@@ -0,0 +1,43 @@
+[remap]
+
+importer="texture"
+type="CompressedTexture2D"
+uid="uid://d4mvmwt2k6nc7"
+path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://icon.svg"
+dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"]
+
+[params]
+
+compress/mode=0
+compress/high_quality=false
+compress/lossy_quality=0.7
+compress/uastc_level=0
+compress/rdo_quality_loss=0.0
+compress/hdr_compression=1
+compress/normal_map=0
+compress/channel_pack=0
+mipmaps/generate=false
+mipmaps/limit=-1
+roughness/mode=0
+roughness/src_normal=""
+process/channel_remap/red=0
+process/channel_remap/green=1
+process/channel_remap/blue=2
+process/channel_remap/alpha=3
+process/fix_alpha_border=true
+process/premult_alpha=false
+process/normal_map_invert_y=false
+process/hdr_as_srgb=false
+process/hdr_clamp_exposure=false
+process/size_limit=0
+detect_3d/compress_to=1
+svg/scale=1.0
+editor/scale_with_editor_scale=false
+editor/convert_colors_with_editor_theme=false
diff --git a/lamp.png b/lamp.png
Binary files differ.
diff --git a/lamp.png.import b/lamp.png.import
@@ -0,0 +1,40 @@
+[remap]
+
+importer="texture"
+type="CompressedTexture2D"
+uid="uid://bb5mof51kodyv"
+path="res://.godot/imported/lamp.png-a09bb450d3eef19f1d08c9cf2f65382f.ctex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://lamp.png"
+dest_files=["res://.godot/imported/lamp.png-a09bb450d3eef19f1d08c9cf2f65382f.ctex"]
+
+[params]
+
+compress/mode=0
+compress/high_quality=false
+compress/lossy_quality=0.7
+compress/uastc_level=0
+compress/rdo_quality_loss=0.0
+compress/hdr_compression=1
+compress/normal_map=0
+compress/channel_pack=0
+mipmaps/generate=false
+mipmaps/limit=-1
+roughness/mode=0
+roughness/src_normal=""
+process/channel_remap/red=0
+process/channel_remap/green=1
+process/channel_remap/blue=2
+process/channel_remap/alpha=3
+process/fix_alpha_border=true
+process/premult_alpha=false
+process/normal_map_invert_y=false
+process/hdr_as_srgb=false
+process/hdr_clamp_exposure=false
+process/size_limit=0
+detect_3d/compress_to=1
diff --git a/main.tscn b/main.tscn
@@ -0,0 +1,273 @@
+[gd_scene format=3 uid="uid://ct47fh1ow17f"]
+
+[ext_resource type="Texture2D" uid="uid://osbck513ghe3" path="res://computer.png" id="1_ig7tw"]
+[ext_resource type="Script" uid="uid://cgdypxcbuexde" path="res://computer_interface.cs" id="2_0xm2m"]
+[ext_resource type="Texture2D" uid="uid://bb5mof51kodyv" path="res://lamp.png" id="3_h2yge"]
+
+[node name="main" type="Node2D" unique_id=1804574269]
+
+[node name="cam" type="Camera2D" parent="." unique_id=1611617563]
+zoom = Vector2(1.5, 1.5)
+
+[node name="computer" type="Sprite2D" parent="." unique_id=1267147980 node_paths=PackedStringArray("button_bits", "button_memory_bits", "lamp_current_instruction", "button_write_byte", "button_jmp_memory", "button_examine")]
+position = Vector2(-352, -128)
+texture = ExtResource("1_ig7tw")
+centered = false
+script = ExtResource("2_0xm2m")
+button_bits = [NodePath("data/bit-0"), NodePath("data/bit-1"), NodePath("data/bit-2"), NodePath("data/bit-3"), NodePath("data/bit-4"), NodePath("data/bit-5"), NodePath("data/bit-6"), NodePath("data/bit-7")]
+button_memory_bits = [NodePath("memory/bit-0"), NodePath("memory/bit-1"), NodePath("memory/bit-2"), NodePath("memory/bit-3"), NodePath("memory/bit-4"), NodePath("memory/bit-5"), NodePath("memory/bit-6"), NodePath("memory/bit-7"), NodePath("memory/bit-8"), NodePath("memory/bit-9"), NodePath("memory/bit-10"), NodePath("memory/bit-11"), NodePath("memory/bit-12"), NodePath("memory/bit-13"), NodePath("memory/bit-14"), NodePath("memory/bit-15")]
+lamp_current_instruction = [NodePath("curr_data/lamp"), NodePath("curr_data/lamp2"), NodePath("curr_data/lamp3"), NodePath("curr_data/lamp4"), NodePath("curr_data/lamp5"), NodePath("curr_data/lamp6"), NodePath("curr_data/lamp7"), NodePath("curr_data/lamp8")]
+button_write_byte = NodePath("data/write")
+button_jmp_memory = NodePath("memory/jmp")
+button_examine = NodePath("curr_data/examine")
+
+[node name="data" type="Node2D" parent="computer" unique_id=969809626]
+position = Vector2(257, 212)
+
+[node name="bit-0" type="CheckButton" parent="computer/data" unique_id=928947275]
+offset_right = 44.0
+offset_bottom = 24.0
+rotation = 4.712389
+
+[node name="bit-1" type="CheckButton" parent="computer/data" unique_id=1497880795]
+offset_left = 24.0
+offset_right = 68.0
+offset_bottom = 24.0
+rotation = 4.712389
+
+[node name="bit-2" type="CheckButton" parent="computer/data" unique_id=1937568649]
+offset_left = 48.0
+offset_right = 92.0
+offset_bottom = 24.0
+rotation = 4.712389
+
+[node name="bit-3" type="CheckButton" parent="computer/data" unique_id=789265495]
+offset_left = 72.0
+offset_right = 116.0
+offset_bottom = 24.0
+rotation = 4.712389
+
+[node name="bit-4" type="CheckButton" parent="computer/data" unique_id=833821743]
+offset_left = 96.0
+offset_right = 140.0
+offset_bottom = 24.0
+rotation = 4.712389
+
+[node name="bit-5" type="CheckButton" parent="computer/data" unique_id=1557534661]
+offset_left = 120.0
+offset_right = 164.0
+offset_bottom = 24.0
+rotation = 4.712389
+
+[node name="bit-6" type="CheckButton" parent="computer/data" unique_id=1615780657]
+offset_left = 144.0
+offset_right = 188.0
+offset_bottom = 24.0
+rotation = 4.712389
+
+[node name="bit-7" type="CheckButton" parent="computer/data" unique_id=787642520]
+offset_left = 168.0
+offset_right = 212.0
+offset_bottom = 24.0
+rotation = 4.712389
+
+[node name="write" type="Button" parent="computer/data" unique_id=5392396]
+offset_left = 192.0
+offset_top = -37.0
+offset_right = 222.0
+offset_bottom = -7.0
+
+[node name="text" type="Label" parent="computer/data" unique_id=917668259]
+offset_left = 223.0
+offset_top = -37.0
+offset_right = 263.0
+offset_bottom = -14.0
+text = "write"
+
+[node name="text2" type="Label" parent="computer/data" unique_id=1336008430]
+offset_left = -33.0
+offset_top = -37.0
+offset_right = 2.0
+offset_bottom = -14.0
+text = "data"
+
+[node name="memory" type="Node2D" parent="computer" unique_id=733435300]
+position = Vector2(160, 175)
+
+[node name="bit-0" type="CheckButton" parent="computer/memory" unique_id=325488317]
+offset_right = 44.0
+offset_bottom = 24.0
+rotation = 4.712389
+
+[node name="bit-1" type="CheckButton" parent="computer/memory" unique_id=1336488479]
+offset_left = 24.0
+offset_right = 68.0
+offset_bottom = 24.0
+rotation = 4.712389
+
+[node name="bit-2" type="CheckButton" parent="computer/memory" unique_id=695745454]
+offset_left = 48.0
+offset_right = 92.0
+offset_bottom = 24.0
+rotation = 4.712389
+
+[node name="bit-3" type="CheckButton" parent="computer/memory" unique_id=1690503583]
+offset_left = 72.0
+offset_right = 116.0
+offset_bottom = 24.0
+rotation = 4.712389
+
+[node name="bit-4" type="CheckButton" parent="computer/memory" unique_id=760018466]
+offset_left = 96.0
+offset_right = 140.0
+offset_bottom = 24.0
+rotation = 4.712389
+
+[node name="bit-5" type="CheckButton" parent="computer/memory" unique_id=1404060575]
+offset_left = 120.0
+offset_right = 164.0
+offset_bottom = 24.0
+rotation = 4.712389
+
+[node name="bit-6" type="CheckButton" parent="computer/memory" unique_id=313744853]
+offset_left = 144.0
+offset_right = 188.0
+offset_bottom = 24.0
+rotation = 4.712389
+
+[node name="bit-7" type="CheckButton" parent="computer/memory" unique_id=210349797]
+offset_left = 168.0
+offset_right = 212.0
+offset_bottom = 24.0
+rotation = 4.712389
+
+[node name="bit-8" type="CheckButton" parent="computer/memory" unique_id=1283918352]
+offset_left = 192.0
+offset_right = 236.0
+offset_bottom = 24.0
+rotation = 4.712389
+
+[node name="bit-9" type="CheckButton" parent="computer/memory" unique_id=1421105136]
+offset_left = 216.0
+offset_right = 260.0
+offset_bottom = 24.0
+rotation = 4.712389
+
+[node name="bit-10" type="CheckButton" parent="computer/memory" unique_id=2076865949]
+offset_left = 240.0
+offset_right = 284.0
+offset_bottom = 24.0
+rotation = 4.712389
+
+[node name="bit-11" type="CheckButton" parent="computer/memory" unique_id=1943659506]
+offset_left = 264.0
+offset_right = 308.0
+offset_bottom = 24.0
+rotation = 4.712389
+
+[node name="bit-12" type="CheckButton" parent="computer/memory" unique_id=2099906965]
+offset_left = 288.0
+offset_right = 332.0
+offset_bottom = 24.0
+rotation = 4.712389
+
+[node name="bit-13" type="CheckButton" parent="computer/memory" unique_id=70508066]
+offset_left = 312.0
+offset_right = 356.0
+offset_bottom = 24.0
+rotation = 4.712389
+
+[node name="bit-14" type="CheckButton" parent="computer/memory" unique_id=862879246]
+offset_left = 336.0
+offset_right = 380.0
+offset_bottom = 24.0
+rotation = 4.712389
+
+[node name="bit-15" type="CheckButton" parent="computer/memory" unique_id=2129421308]
+offset_left = 360.0
+offset_right = 404.0
+offset_bottom = 24.0
+rotation = 4.712389
+
+[node name="jmp" type="Button" parent="computer/memory" unique_id=137966172]
+offset_left = 384.0
+offset_top = -37.0
+offset_right = 414.0
+offset_bottom = -7.0
+
+[node name="text" type="Label" parent="computer/memory" unique_id=663994812]
+offset_left = 414.0
+offset_top = -37.0
+offset_right = 454.0
+offset_bottom = -14.0
+text = "jump"
+
+[node name="text2" type="Label" parent="computer/memory" unique_id=783362460]
+offset_left = -58.0
+offset_top = -37.0
+offset_right = 3.0
+offset_bottom = -14.0
+text = "address"
+
+[node name="curr_data" type="Node2D" parent="computer" unique_id=1993962898]
+position = Vector2(352, 71)
+
+[node name="lamp" type="Sprite2D" parent="computer/curr_data" unique_id=691408274]
+position = Vector2(-112, 6)
+scale = Vector2(0.5, 0.5)
+texture = ExtResource("3_h2yge")
+
+[node name="lamp2" type="Sprite2D" parent="computer/curr_data" unique_id=1393453519]
+position = Vector2(-80, 6)
+scale = Vector2(0.5, 0.5)
+texture = ExtResource("3_h2yge")
+
+[node name="lamp3" type="Sprite2D" parent="computer/curr_data" unique_id=1888166272]
+position = Vector2(-48, 6)
+scale = Vector2(0.5, 0.5)
+texture = ExtResource("3_h2yge")
+
+[node name="lamp4" type="Sprite2D" parent="computer/curr_data" unique_id=1421031255]
+position = Vector2(-16, 6)
+scale = Vector2(0.5, 0.5)
+texture = ExtResource("3_h2yge")
+
+[node name="lamp5" type="Sprite2D" parent="computer/curr_data" unique_id=1492744603]
+position = Vector2(16, 6)
+scale = Vector2(0.5, 0.5)
+texture = ExtResource("3_h2yge")
+
+[node name="lamp6" type="Sprite2D" parent="computer/curr_data" unique_id=605179344]
+position = Vector2(48, 6)
+scale = Vector2(0.5, 0.5)
+texture = ExtResource("3_h2yge")
+
+[node name="lamp7" type="Sprite2D" parent="computer/curr_data" unique_id=1033917715]
+position = Vector2(80, 6)
+scale = Vector2(0.5, 0.5)
+texture = ExtResource("3_h2yge")
+
+[node name="lamp8" type="Sprite2D" parent="computer/curr_data" unique_id=2000831074]
+position = Vector2(112, 6)
+scale = Vector2(0.5, 0.5)
+texture = ExtResource("3_h2yge")
+
+[node name="examine" type="Button" parent="computer/curr_data" unique_id=1814681530]
+offset_left = 128.0
+offset_top = -10.0
+offset_right = 160.0
+offset_bottom = 22.0
+
+[node name="text" type="Label" parent="computer/curr_data" unique_id=1029160794]
+offset_left = 160.0
+offset_top = -10.0
+offset_right = 227.0
+offset_bottom = 13.0
+text = "examine"
+
+[node name="text2" type="Label" parent="computer/curr_data" unique_id=424486015]
+offset_left = -163.0
+offset_top = -10.0
+offset_right = -128.0
+offset_bottom = 13.0
+text = "data"
diff --git a/old-pc-simulator.csproj b/old-pc-simulator.csproj
@@ -0,0 +1,8 @@
+<Project Sdk="Godot.NET.Sdk/4.7.1">
+ <PropertyGroup>
+ <TargetFramework>net8.0</TargetFramework>
+ <TargetFramework Condition=" '$(GodotTargetPlatform)' == 'android' ">net9.0</TargetFramework>
+ <EnableDynamicLoading>true</EnableDynamicLoading>
+ <RootNamespace>oldpcsimulator</RootNamespace>
+ </PropertyGroup>
+</Project>
+\ No newline at end of file
diff --git a/old-pc-simulator.sln b/old-pc-simulator.sln
@@ -0,0 +1,19 @@
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 2012
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "old-pc-simulator", "old-pc-simulator.csproj", "{B2FDDD25-7178-4115-83F7-4B1BDD51599F}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ ExportDebug|Any CPU = ExportDebug|Any CPU
+ ExportRelease|Any CPU = ExportRelease|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {B2FDDD25-7178-4115-83F7-4B1BDD51599F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {B2FDDD25-7178-4115-83F7-4B1BDD51599F}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {B2FDDD25-7178-4115-83F7-4B1BDD51599F}.ExportDebug|Any CPU.ActiveCfg = ExportDebug|Any CPU
+ {B2FDDD25-7178-4115-83F7-4B1BDD51599F}.ExportDebug|Any CPU.Build.0 = ExportDebug|Any CPU
+ {B2FDDD25-7178-4115-83F7-4B1BDD51599F}.ExportRelease|Any CPU.ActiveCfg = ExportRelease|Any CPU
+ {B2FDDD25-7178-4115-83F7-4B1BDD51599F}.ExportRelease|Any CPU.Build.0 = ExportRelease|Any CPU
+ EndGlobalSection
+EndGlobal
diff --git a/project.godot b/project.godot
@@ -0,0 +1,33 @@
+; Engine configuration file.
+; It's best edited using the editor UI and not directly,
+; since the parameters that go here are not all obvious.
+;
+; Format:
+; [section] ; section goes between []
+; param=value ; assign values to parameters
+
+config_version=5
+
+[application]
+
+config/name="old-pc-simulator"
+run/main_scene="uid://ct47fh1ow17f"
+config/features=PackedStringArray("4.7", "Forward Plus")
+config/icon="res://icon.svg"
+
+[display]
+
+window/stretch/mode="canvas_items"
+window/stretch/aspect="expand"
+
+[dotnet]
+
+project/assembly_name="old-pc-simulator"
+
+[physics]
+
+3d/physics_engine="Jolt Physics"
+
+[rendering]
+
+rendering_device/driver.windows="d3d12"