cscの作法 その181

# 概要
cscの作法、調べてみた。
タイミングチャート、書いてみた。

# 写真

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/18104/ab859f26-b6aa-6b3b-d8e8-85d4b0039411.png)


# サンプルコード

```

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

class form1: Form {
	TextBox bo1;
	private int op;
	private int[] w = new int[] { 0, 0, 0, 0, 0, 0 };
	private int[] p0 = new int[] { 0, 0, 0, 0, 0, 0 };
	private int[] p1 = new int[] { 0, 0, 0, 0, 0, 0 };
	private int[] p2 = new int[] { 0, 0, 0, 0, 0, 0 };
	private int[] p3 = new int[] { 0, 0, 0, 0, 0, 0 };
	public form1() {
		this.Text = "jk";
		this.BackColor = SystemColors.Window;
		this.ClientSize = new Size(500, 600);
		Button btn1 = new Button();
		btn1.Location = new Point(50, 320);
		btn1.Text = "run";
		btn1.Click += btn1_Click;
		Controls.AddRange(new Control[] {
			btn1
		});
		bo1 = new TextBox();
		bo1.Location = new Point(50, 350);
		bo1.Width = 200;
		bo1.Height = 200;
		bo1.Multiline = true;
		bo1.Text = "make 6\r\nin 0 1\r\nwire 2 3\r\nand 0 5 2\r\nand 1 4 3\r\nnor 2 4 5\r\nnor 3 5 4\r\nout 4 5\r\n";
		Controls.AddRange(new Control[] {
			bo1
		});
	}
	void btn1_Click(object sender, System.EventArgs e) {
		this.Invalidate();
	}
	protected override void OnPaint(PaintEventArgs e) {
		Graphics g = e.Graphics;
		int i;
		string str = bo1.Text;
		string[] lines = str.Split(new string[] {
			"\r\n"
		}, StringSplitOptions.None);
		List<int[]> s = new List<int[]>();
		for (i = 0; i < lines.Length; i++)
		{
			if (lines[i].Length < 1)
				break;
			string[] code = lines[i].Split(new string[] {
				" "
			}, StringSplitOptions.None);
			int a;
			int b;
			int c;
			switch (code[0])
			{
			case "":
			break;
			case "wire":
			break;
			case "out":
			break;
			case "make":
				this.op = 0;
			break;
			case "in":
			break;
			case "and":
				a = int.Parse(code[1]);
				b = int.Parse(code[2]);
				c = int.Parse(code[3]);
				this.and(a, b, c);
			break;
			case "nor":
				a = int.Parse(code[1]);
				b = int.Parse(code[2]);
				c = int.Parse(code[3]);
				this.nor(a, b, c);
			break;
			default:
			break;
			}
		}
		int[] t = new int[] { 0, 1, 0, 1, 0, 0, 0, 1, 0 };
		int[] u = new int[] { 0, 0, 1, 1, 0, 1, 0, 0, 0 };
		int[] v;
		for (int j = 0; j < 9; j++)
		{
			this.in0(t[j]);
			this.in1(u[j]);
			v = this.exec();
			s.Add(new int[] { v[0], v[1], v[2], v[3], v[4], v[5] });
		}
		for (i = 0; i < 6; i++)
		{
			int[] x = new int[] {
				(int) s[0].GetValue(i),
				(int) s[1].GetValue(i),
				(int) s[2].GetValue(i),
				(int) s[3].GetValue(i),
				(int) s[4].GetValue(i),
				(int) s[5].GetValue(i),
				(int) s[6].GetValue(i),
				(int) s[7].GetValue(i),
				(int) s[8].GetValue(i)
			};
			draw(g, i, x);
		}
	}
	private void draw(Graphics g, int row, int[] w) {
		Pen pen0 = new Pen(Color.Red, 2);
		Pen pen1 = new Pen(Color.Blue, 2);
		SolidBrush brush = new SolidBrush(Color.Yellow);
		Font fontv = new Font("Arial", 12);
		int CLK_OFSET = 60;
		int TICK_WIDTH = 30;
		int y0 = row * TICK_WIDTH + CLK_OFSET;
		g.DrawString(String.Format("{0}", row), fontv, Brushes.Blue, 50, y0 + 10);
		for (int i = 0; i < 8; i++)
		{
			int x0 = i * 30 + 100;
			int x1 = (i + 1) * 30 + 100;
			int y = row * TICK_WIDTH + CLK_OFSET + 30;
			if (w[i] == 0)
			{
				g.DrawLine(pen1, x0, y, x1, y);
			}
			if (w[i] == 1)
			{
				g.DrawLine(pen1, x0, y - TICK_WIDTH + 5, x1, y - TICK_WIDTH + 5);
			}
			if (w[i] != w[i + 1])
			{
				g.DrawLine(pen1, x1, y, x1, y - TICK_WIDTH + 5);
			}
		}
	}
	private void and(int a, int b, int c) {
		this.p0[this.op] = 3;
		this.p1[this.op] = a;
		this.p2[this.op] = b;
		this.p3[this.op] = c;
		this.op++;
	}
	private void nor(int a, int b, int c) {
		this.p0[this.op] = 4;
		this.p1[this.op] = a;
		this.p2[this.op] = b;
		this.p3[this.op] = c;
		this.op++;
	}
	private void in0(int a) {
		this.w[0] = a;
	}
	private void in1(int a) {
		this.w[1] = a;
	}
	private int[] exec() {
		int i;
		int j = this.op;
		while (j > 0)
		{
			for (i = 0; i < j; i++)
			{
				int s;
				if (this.p0[i] == 3)
				{
					s = this.w[this.p1[i]] & this.w[this.p2[i]];
					this.w[this.p3[i]] = s;
				}
				if (this.p0[i] == 4)
				{
					s = this.w[this.p1[i]] | this.w[this.p2[i]];
					if (s == 0)
					{
						this.w[this.p3[i]] = 1;
					}
					else
					{
						this.w[this.p3[i]] = 0;
					}
				}
			}
			j--;
		}
		return this.w;
	}
	[STAThread]
	public static void Main() {
		Application.Run(new form1());
	}
}





```

以上。