OpenCores
URL https://opencores.org/ocsvn/a-z80/a-z80/trunk

Subversion Repositories a-z80

[/] [a-z80/] [trunk/] [tools/] [z80_pla_checker/] [source/] [ClassPLAEntry.cs] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 gdevic
using System;
2
 
3
namespace z80_pla_checker
4
{
5
    /// 
6
    /// This class defines a single PLA entry and the operations on it
7
    /// 
8
    public class ClassPlaEntry
9
    {
10
        // IX/IY Modifiers
11
        [FlagsAttribute]
12
        public enum Modifier
13
        {
14
            IXY0 = (1 << 6),                    // IX or IY flag is reset
15
            IXY1 = (1 << 5),                    // IX or IY flag is set
16
            NHALT = (1 << 4),                   // Not in HALT state
17
            ALU  = (1 << 3),                    // ALU operation
18
            XX = (1 << 2),                      // Regular instruction
19
            CB = (1 << 1),                      // CB instruction table modifier
20
            ED = (1 << 0)                       // ED instruction table modifier
21
        };
22
 
23
        private int prefix;                         // Modifier bitfield
24
        private int opcode;                         // Opcode bitfield
25
        private bool duplicate;                     // This entry is a duplicate
26
        public bool IsDuplicate() { return duplicate; }
27
 
28
        public int N { get; private set; }          // Ordinal number of this entry, or the entry ID
29
        public string Comment { get; private set; } // PLA line description / comment text
30
        public string Raw { get; private set; }     // Raw line as-is
31
        public bool Ignored = false;                // This entry can optionally be ignored
32
 
33
        /// 
34
        /// PLA entry class constructor
35
        /// Accepts the init string which should contain a line from the PLA master table.
36
        /// Various fields from that line are read into this class.
37
        /// 
38
        public bool Init(string init)
39
        {
40
            try
41
            {
42
                Raw = init;
43
                char[] delimiterChars = { '\t' };
44
                string[] w = init.Split(delimiterChars);
45
 
46
                // Example of an input line:
47
                // w[0]                    w[1] w[2] w[3]     w[4]
48
                // ....1.. 1.1........1.11.  D   63  00xxx110 ld r,*
49
 
50
                // Mark a duplicate
51
                duplicate = w[1].Contains("D");
52
 
53
                // Read the 7 bits of the prefix
54
                for (int i = 0; i < 7; i++)
55
                    if (w[0][6-i] == '1') prefix |= (1 << i);
56
 
57
                // Read 16 bits of the opcode mask
58
                for (int i = 0; i < 16; i++)
59
                    if (w[0][23 - i] == '1') opcode |= (1 << i);
60
 
61
                N = Convert.ToInt32(w[2]);
62
                Comment = w[4];
63
 
64
                return true;
65
            }
66
            catch (Exception ex)
67
            {
68
                ClassLog.Log("ClassPlaEntry: Can't parse line: " + init);
69
                ClassLog.Log(ex.Message);
70
            }
71
            return false;
72
        }
73
 
74
 
75
        /// 
76
        /// Matches a given opcode to this PLA line. Returns empty string if not a match
77
        /// or PLA number and mnemonic if there is a match. Duplicates are ignored.
78
        /// 
79
        public string Match(Modifier modifier, Byte instr)
80
        {
81
            if (duplicate) return string.Empty;
82
 
83
            // Check the modifiers against the prefix bitfield.
84
            if ((((int)modifier) & prefix) != prefix)
85
                return string.Empty;
86
 
87
            // Check each opcode bit
88
            // If any bit in the opcode map is 1, the instruction needs to be "0" or "1"
89
            for (int i = 0; i < 8; i++)
90
            {
91
                int testbit = (instr >> i) & 1;
92
                int test1 = (opcode >> (i * 2)) & 1;
93
                int test0 = (opcode >> (i * 2 + 1)) & 1;
94
                if (test1 == 1 && testbit != 1) return string.Empty;
95
                if (test0 == 1 && testbit != 0) return string.Empty;
96
            }
97
 
98
            return string.Format("[{0}] {1}", N, Comment);
99
        }
100
 
101
        /// 
102
        /// Return a PLA entry suitable to use in a System Verilog compare statement
103
        /// 
104
        public string GetBitstream()
105
        {
106
            // Write out these bits in order; they can be 1 or don't care (X)
107
            string bitstream = "";
108
            // Create 7 bits of the prefix
109
            for (int i = 6; i >= 0; i--)
110
                bitstream += (prefix & (1 << i))==0 ? "X" : "1";
111
            bitstream += "_";
112
            // Followed by the 8 bits of the opcode mask
113
            for (int i = 7; i >= 0; i--)
114
            {
115
                string code = "X";
116
                int test1 = (opcode >> (i * 2)) & 1;
117
                int test0 = (opcode >> (i * 2 + 1)) & 1;
118
                if (test1 == 1)
119
                    code = "1";
120
                if (test0 == 1)
121
                    code = "0";
122
                bitstream += code;
123
            }
124
            return bitstream;
125
        }
126
    }
127
}

powered by: WebSVN 2.1.0

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