OpenCores
URL https://opencores.org/ocsvn/lem1_9min/lem1_9min/trunk

Subversion Repositories lem1_9min

[/] [lem1_9min/] [trunk/] [Form1.cs] - Blame information for rev 7

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 7 marcus.erl
using System;
2
using System.IO;
3
using System.Drawing;
4
using System.Collections;
5
using System.ComponentModel;
6
using System.Windows.Forms;
7
 
8
namespace lem9_1min_asm
9
{
10
        /// 
11
        /// Summary description for Form1.
12
        /// 
13
        public class Form1 : System.Windows.Forms.Form
14
        {
15
                private int IP;
16
                private System.Windows.Forms.ListBox listBox1;
17
                private int[] mem = new int[2048];
18
                private void HLT()      {mem[IP++]=0;}          //DEF   9B#000000000    ; wait for system clock
19
                private void CACC() {mem[IP++]=0x10;}   //DEF   9B#000010000    ; clear A, clear C
20
                private void CASC() {mem[IP++]=0x11;}   //DEF   9B#000010001    ; clear A. set C
21
                private void SACC() {mem[IP++]=0x12;}   //DEF   9B#000010010    ; set A, clear C
22
                private void SASC() {mem[IP++]=0x13;}   //DEF   9B#000010011    ; set A, set C
23
                private void CC()       {mem[IP++]=0x14;}       //DEF   9B#000010100    ; clear C
24
                private void SC()       {mem[IP++]=0x15;}       //DEF   9B#000010101    ; set C
25
                private void CA()       {mem[IP++]=0x16;}       //DEF   9B#000010110    ; clear A
26
                private void SA()       {mem[IP++]=0x17;}       //DEF   9B#000010111    ; set A
27
                private void OR2C()     {mem[IP++]=0x18;}       //DEF   9B#000011000    ; A | C to C
28
                private void NA()       {mem[IP++]=0x19;}       //DEF   9B#000011001    ; negate A
29
                private void NC()       {mem[IP++]=0x1a;}       //DEF   9B#000011010    ; negate C
30
                private void NANC() {mem[IP++]=0x1b;}   //DEF   9B#000011011    ; negate A, negate C
31
                private void AND2C(){mem[IP++]=0x1c;}   //DEF   9B#000011100    ; A & C to C
32
                private void C2A()      {mem[IP++]=0x1d;}       //DEF   9B#000011101    ; copy C to A
33
                private void A2C()      {mem[IP++]=0x1e;}       //DEF   9B#000011110    ; copy A to C
34
                private void XAC()      {mem[IP++]=0x1f;}       //DEF   9B#000011111    ; swap A and C
35
                private void ST(int x)  {mem[IP++]=0x040 | x;}  //DEF   ST,6VB#000000   ; store A at memory location
36
                private void LD(int x)  {mem[IP++]=0x080 | x;}  //DEF   LD,6VB#000000   ; load A from memory location
37
                private void LDC(int x) {mem[IP++]=0x0c0 | x;}  //DEF   LDC,6VB#000000  ; load A complement from memory location
38
                private void AND(int x) {mem[IP++]=0x100 | x;}  //DEF   AND,6VB#000000  ; AND memory location into A
39
                private void OR(int x)  {mem[IP++]=0x140 | x;}  //DEF   OR,6VB#000000   ; OR memory location into A
40
                private void XOR(int x) {mem[IP++]=0x180 | x;}  //DEF   EOR,6VB#000000  ; XOR memory location into A
41
                private void ADC(int x) {mem[IP++]=0x1c0 | x;}
42
                private System.Windows.Forms.Label label1;
43
                private System.Windows.Forms.TextBox textBox2;
44
                private System.Windows.Forms.Button button1;
45
                private System.Windows.Forms.Label label2;
46
                private System.Windows.Forms.TextBox textBox3;
47
                private System.Windows.Forms.Button button2;
48
                /// 
49
                /// Required designer variable.
50
                /// 
51
                private System.ComponentModel.Container components = null;
52
 
53
                public Form1()
54
                {
55
                        //
56
                        // Required for Windows Form Designer support
57
                        //
58
                        InitializeComponent();
59
 
60
                        //
61
                        // TODO: Add any constructor code after InitializeComponent call
62
                        //
63
                }
64
 
65
                /// 
66
                /// Clean up any resources being used.
67
                /// 
68
                protected override void Dispose( bool disposing )
69
                {
70
                        if( disposing )
71
                        {
72
                                if (components != null)
73
                                {
74
                                        components.Dispose();
75
                                }
76
                        }
77
                        base.Dispose( disposing );
78
                }
79
 
80
 
81
                /// 
82
                /// The main entry point for the application.
83
                /// 
84
                [STAThread]
85
                static void Main()
86
                {
87
                        Application.Run(new Form1());
88
                }
89
 
90
                #region Windows Form Designer generated code
91
                /// 
92
                /// Required method for Designer support - do not modify
93
                /// the contents of this method with the code editor.
94
                /// 
95
                private void InitializeComponent()
96
                {
97
                        this.label1 = new System.Windows.Forms.Label();
98
                        this.textBox2 = new System.Windows.Forms.TextBox();
99
                        this.button1 = new System.Windows.Forms.Button();
100
                        this.label2 = new System.Windows.Forms.Label();
101
                        this.textBox3 = new System.Windows.Forms.TextBox();
102
                        this.button2 = new System.Windows.Forms.Button();
103
                        this.listBox1 = new System.Windows.Forms.ListBox();
104
                        this.SuspendLayout();
105
                        //
106
                        // label1
107
                        //
108
                        this.label1.Location = new System.Drawing.Point(152, 128);
109
                        this.label1.Name = "label1";
110
                        this.label1.Size = new System.Drawing.Size(56, 16);
111
                        this.label1.TabIndex = 1;
112
                        this.label1.Text = "File Name";
113
                        //
114
                        // textBox2
115
                        //
116
                        this.textBox2.Location = new System.Drawing.Point(16, 152);
117
                        this.textBox2.Name = "textBox2";
118
                        this.textBox2.Size = new System.Drawing.Size(280, 20);
119
                        this.textBox2.TabIndex = 2;
120
                        this.textBox2.Text = "lem1_9min_hw_041127";
121
                        //
122
                        // button1
123
                        //
124
                        this.button1.Location = new System.Drawing.Point(16, 184);
125
                        this.button1.Name = "button1";
126
                        this.button1.Size = new System.Drawing.Size(64, 23);
127
                        this.button1.TabIndex = 3;
128
                        this.button1.Text = "save xmt";
129
                        this.button1.Click += new System.EventHandler(this.button1_Click);
130
                        //
131
                        // label2
132
                        //
133
                        this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
134
                        this.label2.Location = new System.Drawing.Point(96, 0);
135
                        this.label2.Name = "label2";
136
                        this.label2.Size = new System.Drawing.Size(112, 23);
137
                        this.label2.TabIndex = 5;
138
                        this.label2.Text = "lem1_9min_asm";
139
                        //
140
                        // textBox3
141
                        //
142
                        this.textBox3.AcceptsReturn = true;
143
                        this.textBox3.AcceptsTab = true;
144
                        this.textBox3.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
145
                        this.textBox3.Location = new System.Drawing.Point(320, 0);
146
                        this.textBox3.Multiline = true;
147
                        this.textBox3.Name = "textBox3";
148
                        this.textBox3.ScrollBars = System.Windows.Forms.ScrollBars.Both;
149
                        this.textBox3.Size = new System.Drawing.Size(368, 616);
150
                        this.textBox3.TabIndex = 3;
151
                        this.textBox3.Text = "; lem1_9min listing";
152
                        //
153
                        // button2
154
                        //
155
                        this.button2.Location = new System.Drawing.Point(16, 104);
156
                        this.button2.Name = "button2";
157
                        this.button2.Size = new System.Drawing.Size(64, 23);
158
                        this.button2.TabIndex = 6;
159
                        this.button2.Text = "assemble";
160
                        this.button2.Click += new System.EventHandler(this.button2_Click);
161
                        //
162
                        // listBox1
163
                        //
164
                        this.listBox1.Items.AddRange(new object[] {
165
                                                                                                                  "toggle",
166
                                                                                                                  "cntr24",
167
                                                                                                                  "HEllo UJord"});
168
                        this.listBox1.Location = new System.Drawing.Point(16, 32);
169
                        this.listBox1.Name = "listBox1";
170
                        this.listBox1.Size = new System.Drawing.Size(176, 56);
171
                        this.listBox1.TabIndex = 8;
172
                        //
173
                        // Form1
174
                        //
175
                        this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
176
                        this.ClientSize = new System.Drawing.Size(696, 630);
177
                        this.Controls.AddRange(new System.Windows.Forms.Control[] {
178
                                                                                                                                                  this.listBox1,
179
                                                                                                                                                  this.button2,
180
                                                                                                                                                  this.textBox3,
181
                                                                                                                                                  this.label2,
182
                                                                                                                                                  this.button1,
183
                                                                                                                                                  this.textBox2,
184
                                                                                                                                                  this.label1});
185
                        this.Name = "Form1";
186
                        this.Text = "Form1";
187
                        this.ResumeLayout(false);
188
 
189
                }
190
                #endregion
191
 
192
                private void toggle()                           // toggle Accum & Carry
193
                        {CACC(); SASC(); HLT();}
194
 
195
                private void INC(int loc)                       // increment memory bit "macro"
196
                        {ADC(loc); ST(loc); CA();}
197
                private void CNTR24()                           // 24 bit incrementing counter "macro"
198
                {CASC(); for(int i=23; i>0; i--)INC(i); ADC(0); ST(0);}
199
 
200
                private void cntr24(){CNTR24(); HLT();} // 24 bit incrementing counter program
201
 
202
                private void HEllo_UJorld()                     // sliding 7-segment "hello world" with w via reversed & forward "j"
203
                {       CNTR24();       // lsb at location 23, msb at location 0
204
                        // add segment position ("00"+14..15) to counter position (4..7)
205
                        const int LT0=56, LT1=57, LT2=58, LT3=59, CT14=14, CT15=15, CT7=5, CT6=4, CT5=3, CT4=2;
206
                        CACC(); LD(CT15); ADC(CT7); ST(LT0);
207
                        LD(CT14); ADC(CT6); ST(LT1);
208
                        CA(); ADC(CT5); ST(LT2);
209
                        CA(); ADC(CT4); ST(LT3);
210
                        // digit select decode, from 14..15, acitve low
211
                        const int DIG3 = 60, DIG2 = 61, DIG1 = 62, DIG0 = 63, BT0 = 15, BT1 = 14;
212
                        LD(BT1); OR(BT0); ST(DIG0);
213
                        LDC(BT1); OR(BT0); ST(DIG2);
214
                        XOR(BT1); ST(DIG3);
215
                        XOR(BT0); ST(DIG1);
216
                        // segment logic, segments: 0:top, 1:top right, 2:bottom right; 3:bottom, 4:bottom left,
217
                        //                                                      5:top left, 6:middle, 7:decimal point
218
                        const int SEG0=55, SEG1=54, SEG2=53, SEG3=52, SEG4=51, SEG5=50, SEG6=49, DP=48;
219
                        const int A0=LT3, B0=LT2, C0=LT1, D0=LT0;
220
 
221
//                      LD(LT0); OR(LT1); OR(LT2); OR(LT3); ST(DP);     // rotating decimal point
222
                        SA(); ST(DP);   // no decimal point
223
 
224
                        // rotating HELLO UJOrLd
225
                        const int AB=47, AD=46, BD=45, NCD=44, BNCD=43, NANB=42, CND=41, t=40;
226
                        LD(A0); AND(B0); ST(AB);        //ab
227
                        LD(A0); AND(D0); ST(AD);        //ad
228
                        LD(B0); AND(D0); ST(BD);        //bd
229
                        LDC(C0); AND(D0); ST(NCD); AND(B0); ST(BNCD);   //ncd, bncd
230
                        LD(A0); OR(B0); NA(); ST(NANB); //nanb
231
                        LDC(D0); AND(C0); ST(CND);      //cnd
232
 
233
                        LDC(D0); AND(NANB); OR(C0); OR(BD); OR(AD); OR(AB); ST(SEG0);   //nanbnd+c+bd+ad+ab
234
                        LD(NANB); AND(D0); OR(NCD); OR(CND); OR(AB); ST(SEG1);  // ncd+cnd+ab+nanbd
235
                        LD(NANB); AND(C0); ST(t); LDC(B0); AND(CND); OR(t); OR(NCD); OR(AB); ST(SEG2);  //ncd+ab+nanbc+nbcnd
236
                        LD(C0); OR(D0); NA(); AND(NANB); ST(t); LD(A0); AND(NCD); OR(t); OR(BNCD); OR(AB); ST(SEG3);// nanbncnd+bncd+ancd+ab
237
                        LD(BNCD); OR(AB); ST(SEG4);     // bncd+ab
238
                        LD(BD); OR(AD); OR(AB); ST(SEG5);       // bd+ad+ab
239
                        LDC(A0); AND(C0); ST(t); LDC(D0); AND(A0); OR(B0); OR(t); ST(SEG6);     //nac+b+and
240
 
241
//                      // rotating HEllo UJorld
242
//                      const int t1=47, t2=46, t3=45, t4=44, t5=43, t6=42;
243
//                      LDC(D0); OR(A0); OR(B0); OR(C0); ST(SEG0);
244
 
245
//                      LD(A0); OR(B0); OR(C0); OR(D0); ST(t1);
246
//                      LD(B0); AND(C0); AND(D0); NA(); OR(A0); AND(t1); ST(t1);
247
//                      LD(A0); AND(C0); AND(D0); NA(); OR(B0); AND(t1); ST(SEG1);
248
 
249
//                      LD(B0); AND(C0); NA(); OR(A0); ST(t2);
250
//                      LD(B0); OR(C0); OR(D0); AND(t2); ST(t2);
251
//                      LD(A0); AND(C0); AND(D0); NA(); OR(B0); AND(t2); ST(t2);
252
//                      LD(A0); OR(C0); OR(D0); AND(t2); ST(SEG2);
253
 
254
//                      LDC(B0); OR(A0); OR(D0); ST(t3);
255
//                      LD(B0); AND(C0); NA(); OR(A0); AND(t3); ST(t3);
256
//                      LDC(A0); OR(B0); OR(C0); OR(D0); AND(t3); ST(t3);
257
//                      LD(A0); AND(C0); AND(D0); NA(); OR(B0); AND(t3);
258
//                      AND(SEG0); ST(SEG3);
259
 
260
//                      LD(A0); OR(D0); ST(t4);
261
//                      LDC(C0); OR(A0); AND(t4); AND(B0); ST(SEG4);
262
 
263
//                      LD(A0); OR(B0); ST(t5);
264
//                      LDC(C0); OR(A0); OR(D0); AND(t5); ST(t5);
265
//                      LDC(C0); OR(B0); OR(D0); AND(t5); ST(SEG5);
266
 
267
//                      LD(B0); OR(C0); ST(t6);
268
//                      LD(A0); OR(C0); OR(D0); AND(t6); ST(t6);
269
//                      LD(A0); AND(D0); NA(); OR(B0); AND(t6); ST(SEG6);
270
 
271
//                      // rotating HEllo UJorld
272
                        //const int AB=47, BD=46, BNC=45, BNCD=44, ANC=43, NANB=42, NANBC=41, NANBD=40, NANBND=39,
273
                        //              CND=38, NBCND=37, NCD=36, NBND=35;
274
//                      LD(A0); AND(B0); ST(AB); LDC(D0); AND(C0); ST(CND); LD(A0); OR(B0); NA(); ST(NANB); AND(D0); ST(NANBD);
275
//                      LDC(C0); AND(B0); ST(BNC); LDC(C0); AND(A0); ST(ANC); OR(BNC); OR(NANBD); OR(CND); OR(AB); ST(SEG1);
276
 
277
//                      LDC(C0); AND(D0); ST(NCD); LD(NANB); AND(C0); ST(NANBC); LD(B0); OR(D0); NA(); ST(NBND); AND(C0);
278
//                      OR(NANBC); OR(AB); OR(NCD); ST(SEG2);
279
 
280
//                      LDC(C0); AND(B0); AND(D0); A2C(); LD(A0); AND(B0); OR2C(); C2A(); ST(SEG4);
281
//                      LDC(C0); AND(B0); AND(D0); ST(SEG4); LD(A0); AND(B0); OR(SEG4); ST(SEG4);
282
 
283
//                      SA(); ST(SEG3); SA(); ST(SEG4); SA(); ST(SEG5); SA(); ST(SEG6);
284
//                      ST(SEG1); ST(SEG2);
285
//                      LD(A0); AND(B0); ST(AB);
286
//                      LD(B0); AND(D0); ST(BD);
287
//                      LDC(C0); AND(B0); ST(BNC); AND(D0); ST(BNCD);
288
//                      LDC(C0); AND(A0); ST(ANC);
289
//                      LD(A0); OR(B0); NA(); ST(NANB); AND(C0); ST(NANBC);
290
//                      LD(NANB); AND(D0); ST(NANBD);
291
//                      LDC(D0); AND(NANB); ST(NANBND); NA(); OR(C0); ST(SEG0); // seg A = a+b+c+nd
292
//                      LDC(D0); AND(C0); ST(CND);
293
//                      LDC(B0); AND(CND); ST(NBCND);
294
//                      LDC(A0); AND(C0); OR(BD); OR(CND); OR(AB); ST(SEG6); // seg G = nac+bd+cnd+ab
295
//                      LDC(C0); AND(D0); OR(AB); OR(NANBC); OR(NBCND); ST(SEG2); // seg C = ncd+ab+nabc+nbcd
296
//                      LD(A0); AND(D0); OR(BNC); OR(BD); OR(ANC); OR(AB); ST(SEG5); // seg F = bnc+bd+anc+ad+ab
297
//                      LDC(C0); AND(A0); AND(D0);
298
//                      OR(NANBND); OR(NANBC); OR(BNCD); OR(AB); OR(NBCND); ST(SEG3); // seg D = nanbnd+nanbc+bncd+ancd+ab+nbcnd
299
//                      LD(NANBD); OR(AB); OR(CND); OR(BNC); OR(ANC); ST(SEG1); // seg B = ab+cnd+nanbd+bnc+anc
300
//                      LD(NBCND); OR(AB); ST(SEG4); // seg E = bncd+ab
301
                        HLT();
302
                }
303
 
304
                private void listBox1_SelectedIndexChanged(object sender, System.EventArgs e)
305
                {
306
                }
307
 
308
                private void button1_Click(object sender, System.EventArgs e)
309
                {       // wirte assembled binary to Xilinx "RAMB16_S9 generic map(" initialization text
310
                        FileInfo cvf = new FileInfo(@"C:\br\digilent_projs\d3_lem1_9min_hw\"+textBox2.Text+".xmt");
311
                        StreamWriter stmw = cvf.CreateText();
312
                        int nwds = IP;
313
                        int nlines = (nwds+31)/32;
314
                        int nplines = (nwds+255)/256;
315
                        byte[] wds = new byte[nlines*32];
316
                        byte[] pbits = new byte[nplines*256];
317
                        for (int i=0; i
318
                        {
319
                                wds[i] = (byte)(mem[i] & 0xff);
320
                                pbits[i] = (byte)(mem[i] >> 8 & 1);
321
                        }
322
                        for (int i=0; i
323
                        {       stmw.Write("    INIT_{0:X2}  => X\"",i);
324
                                for (int j=31; j>=0; j--) stmw.Write("{0:X2}",wds[i*32+j]);
325
                                stmw.WriteLine("\",");
326
                        }
327
                        for (int i=0; i
328
                        {       stmw.Write("    INITP_{0:X2} => X\"",i);
329
                                for (int j=63; j>=0; j--) stmw.Write("{0:X1}",
330
                                                                                          pbits[i*256+j*4+3]*8 + pbits[i*256+j*4+2]*4 +
331
                                                                                          pbits[i*256+j*4+1]*2 + pbits[i*256+j*4]);
332
                                stmw.WriteLine((i == (nplines-1)) ? "\")" : "\",");
333
                        }
334
                        stmw.Close();
335
                }
336
 
337
                private void button2_Click(object sender, System.EventArgs e)
338
                {       int prog = listBox1.SelectedIndex;
339
                        IP = 0;
340
                        switch (prog)
341
                        {       case 0: toggle(); break;
342
                                case 1: cntr24(); break;
343
                                case 2: HEllo_UJorld(); break;
344
                        }
345
                        string[] xx = new String[IP+1];
346
                        xx[0] = listBox1.SelectedItem + " listing";
347
                        for (int i=0; i
348
                                xx[i+1] =  i.ToString("X3").PadLeft(3,'0') +
349
                                                                         ": " + mem[i].ToString("X3").PadLeft(3,'0');
350
                        textBox3.Lines = xx;
351
                }
352
        }
353
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.