Example #1
0
        private byte ReadEeprom8(uint address)
        {
            if (this.eepromReadAddress == -1) return 1;

            byte retval = 0;

            if (this.curEepromByte >= 4)
            {
                retval = (byte)((this.eeprom[this.eepromReadAddress * 8 + ((this.curEepromByte - 4) / 8)] >> (7 - ((this.curEepromByte - 4) & 7))) & 1);
            }

            this.curEepromByte++;

            if (this.curEepromByte == this.dmaRegs[3, 2])
            {
                this.eepromReadAddress = -1;
                this.eepromMode = EepromModes.Idle;
            }

            return retval;
        }
Example #2
0
        private void WriteEeprom8(uint address, byte value)
        {
            // EEPROM writes must be done by DMA 3
            if ((this.dmaRegs[3, 3] & (1 << 15)) == 0) return;
            // 0 length eeprom writes are bad
            if (this.dmaRegs[3, 2] == 0) return;

            if (this.eepromMode != EepromModes.ReadData)
            {
                this.curEepromByte = 0;
                this.eepromMode = EepromModes.ReadData;
                this.eepromReadAddress = -1;

                for (int i = 0; i < this.eepromStore.Length; i++) this.eepromStore[i] = 0;
            }

            this.eepromStore[this.curEepromByte >> 3] |= (byte)(value << (7 - (this.curEepromByte & 0x7)));
            this.curEepromByte++;

            if (this.curEepromByte == this.dmaRegs[3, 2])
            {
                if ((this.eepromStore[0] & 0x80) == 0) return;

                if ((this.eepromStore[0] & 0x40) != 0)
                {
                    // Read request
                    if (this.curEepromByte == 9)
                    {
                        this.eepromReadAddress = this.eepromStore[0] & 0x3F;
                    }
                    else
                    {
                        this.eepromReadAddress = ((this.eepromStore[0] & 0x3F) << 8) | this.eepromStore[1];
                    }
                    
                    this.curEepromByte = 0;
                }
                else
                {
                    // Write request
                    int eepromAddress, offset;
                    if (this.curEepromByte == 64 + 9)
                    {
                        eepromAddress = (int)(this.eepromStore[0] & 0x3F);
                        offset = 1;
                    }
                    else
                    {
                        eepromAddress = ((this.eepromStore[0] & 0x3F) << 8) | this.eepromStore[1];
                        offset = 2;
                    }

                    for (int i = 0; i < 8; i++)
                    {
                        this.eeprom[eepromAddress * 8 + i] = this.eepromStore[i + offset];
                    }

                    this.eepromMode = EepromModes.Idle;
                }
            }
        }