How can I detect a 64KB EEPROM
I have several different pieces of hardware that all run the same software. It all works fine, but recently some versions of the hardware have 64KB EEPROMs. Is there some way (programmatically) to detect the larger EEPROM?

Comments
First read $0000 and $8000. Then write something to $8000 other than what you originally found at $0000 and $8000. Then read $0000. If $0000 has what you wrote to $8000, then you have a 32KB eeprom. If $0000 has what you originally found in $0000, then you have a 64KB eeprom.
Make sure you put whatever you originally found at $0000 and, if the test finds the EEPROM has 64KB, at $8000, back! This test messes them up, and they probably had something important! $0000 did, at least (clkfreq).
The part to detect the size of the EEPROM works but the rest of the code is buggy.
PRI _detectEEPROM | tmp tmp := $99 ' just some value that is unlikely to already be in the $8000 address (or $0000) IF (MEM.read($8000, 1) <> MEM.read($0000, 1)) MEM.write($8000, @tmp, 1) IF (MEM.read($8000, 1) == tmp) RETURN bigEE := true RETURN bigEE := falseTry this:
PRI _detectEEPROM | lo, hi, newlo, newhi lo := MEM.read($0000, 1) ' read $0000 hi := MEM.read($8000, 1) ' read $8000 if lo <> hi ' they don't match? it's a 64KB EEPROM return bigEE := true newhi := (lo+1) & $FF ' newhi <> lo { you can uncomment this but kuroneku pointed out that it's unecessary if newhi == hi ' if newhi == hi newhi := (hi+1) & $FF ' then make newhi <> hi (and still <> lo) ' now new <> lo and new <> hi } MEM.write($8000, @newhi, 1) ' put new value in $8000 newlo := MEM.read($0000, 1) ' read value from $0000 bigEE := (newlo == lo) ' if $0000 didn't change, it's a big EEPROM ' if it did change, it should == newhi or else your EEPROM is bad if bigEE MEM.write($8000, @hi, 1) ' we messed up $8000, so put it back to how we found it else MEM.write($0000, @lo, 1) ' we messed up $0000 (which is the same as $8000 for a small EEPROM), so put it back to how we found it return bigEE ' return resultI just tested it over a Telnet connection and it came back "-1 ok"
Why not just compare the low 32K to the high 32K?
If they are different it's a 64K device.
If they are the same it's most likely a 32K device, do the write/read test to be sure.
This saves a writing to the EEPROM in the majority of cases.
It relies on address wrap over in 32K devices. Is that always true?
Yes, the address wraps over but the test is just in case you have an identical image in the top 32K (for some reason)
... which could easily be the case if you're loading to RAM and the EEPROM had never been programmed.
-Phil
It just saves 0.000001% of the life time of the EEPROM in a lot of cases and the 10E-20 chance that the write/read/write test gets interrupted in the middle and corrupts the EEPROM content