Subversion Repositories group.electronics

Rev

Rev 171 | Rev 173 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 171 Rev 172
Line 70... Line 70...
70
            }
70
            }
71
        }
71
        }
72
    }
72
    }
73
 
73
 
74
    public class Led {
74
    public class Led {
75
        protected mcp23017 dev;
-
 
76
        private int bank { get; set; }
75
        public int bank { get; set; }
77
        private int pin { get; set; }
76
        public int pin { get; set; }
78
        private UInt16 address { get; set; }
77
        public UInt16 address { get; set; }
79
        private UInt16 mask { get; set; }
78
        public UInt16 mask { get; set; }
80
        private int shift { get; set; }
79
        public int shift { get; set; }
81
 
80
 
82
        public uint value { get; set; }
81
        public uint value { get; set; }
83
 
82
 
84
        public Led(mcp23017 dev, int bank, int pin, UInt16 address, UInt16 mask, int shift) {
83
        public Led(int bank, int pin, UInt16 address, UInt16 mask, int shift) {
85
            this.dev = dev;
-
 
86
            this.pin = pin;
84
            this.pin = pin;
87
            this.address = address;
85
            this.address = address;
88
            this.mask = mask;
86
            this.mask = mask;
89
            this.shift = shift;
87
            this.shift = shift;
90
            this.value = 0;
88
            this.value = 0;
91
 
89
 
-
 
90
            UInt16 data;
-
 
91
            if (!Globals.BiosOutput.TryGetValue(this.address, out data)) {
92
            Globals.outputs.Add(this.address, this);
92
                Globals.BiosOutput.Add(this.address, 0x0000);
-
 
93
            }
-
 
94
 
93
        }
95
        }
94
 
96
 
95
        public bool Tick(uint data) {
97
        public bool Tick(ref byte shadow) {
-
 
98
            UInt16 data;
-
 
99
            byte tmpshadow = shadow;
-
 
100
            if (Globals.BiosOutput.TryGetValue(this.address, out data)) {
96
            uint newval = (data & mask) >> shift;
101
                this.value = (UInt16)((data & mask) >> shift);
-
 
102
 
-
 
103
                if (this.value == 1)
-
 
104
                    Globals.setBit(shadow, this.pin);
-
 
105
                else
-
 
106
                    Globals.clearBit(shadow, this.pin);
97
 
107
 
98
            if (newval != this.value) {
-
 
99
                byte curr = 0;
-
 
100
                dev.GetBank(this.bank, (byte)this.bank, out curr);
-
 
101
 
108
 
102
                Globals.setBit(curr, pin);
-
 
103
                dev.SetBank(this.bank, curr);
-
 
104
            }
109
            }
105
 
110
 
-
 
111
            if (tmpshadow == shadow)
-
 
112
                return false;
-
 
113
 
106
            return true;
114
            return true;
107
        }
115
        }
108
 
116
 
109
 
117
 
110
    }
118
    }