2 * avr-sim: An atmel AVR simulator
3 * Copyright (C) 2008 Tom Haber
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "Registers.h"
32 Eeprom::Eeprom(Bus
& bus
, unsigned int size
, unsigned int rdyVec
)
33 : Hardware(bus
), Memory(size
), rdyVec(rdyVec
), oldEecr(0) {
39 void Eeprom::writeToAddress(unsigned int addr
, unsigned char val
) {
43 unsigned char Eeprom::readFromAddress(unsigned int addr
) {
44 return readByte(addr
);
47 bool Eeprom::attachReg(const char *name
, IORegister
*reg
) {
48 if( strcmp(name
, "eecr") == 0 )
50 else if( strcmp(name
, "eedr") == 0 ) {
53 } else if( strcmp(name
, "eearl") == 0 )
55 else if( strcmp(name
, "eearh") == 0 )
60 reg
->registerHW(this);
64 void Eeprom::regChanged( IORegister
*reg
) {
66 eear
= (eear
& 0x00ff) | (*eearh
<< 8);
67 else if( reg
== eearl
)
68 eear
= (eear
& 0xff00) | (*eearl
);
69 else if( reg
== eecr
)
79 eecr
->set( *eecr
& CLEAR
);
80 writeToAddress( eear
, *eedr
);
82 if( (*eecr
& EERIE
) != 0 )
83 bus
.raiseInterrupt(rdyVec
);
89 eecr
->set( *eecr
& CLEAR
);
90 *eedr
= readFromAddress( eear
);
96 eecr
->set( *eecr
& ~EEMWE
);
102 void Eeprom::setEECR( unsigned char eecr
) {
103 if( ((eecr
& EEMWE
) != 0) && (state
== READY
) ) {
104 state
= WRITE_ENABLED
;
105 bus
.reassignBreakDelta(writeEnableCycles
, this);
106 } else if( ((eecr
& EEWE
) != 0) && (state
== WRITE_ENABLED
) ) {
108 setHoldCycles( writeCycles
);
109 bus
.reassignBreakDelta(writeCycles
, this);
110 } else if( (eecr
& EERE
) != 0 ) {
111 //EERE EEprom read enable
112 if( state
== WRITE
) {
114 bus
.clearBreak(this);
117 setHoldCycles( readCycles
);
118 bus
.reassignBreakDelta(readCycles
, this);
122 } else if( (eecr
& 0x07) != 0x00 ) {
124 bus
.clearBreak( this );