1.1 --- a/ArduinoAm29F010.cpp Sun Aug 09 19:08:15 2015 +0200
1.2 +++ b/ArduinoAm29F010.cpp Sun Aug 09 19:51:29 2015 +0200
1.3 @@ -170,7 +170,10 @@
1.4 i = 2;
1.5 }
1.6 else
1.7 + {
1.8 + high = 0;
1.9 i = 1;
1.10 + }
1.11
1.12 high |= (fromHex(buffer[i]) << 4) + (fromHex(buffer[i+1]));
1.13 low = (fromHex(buffer[i+2]) << 4) + (fromHex(buffer[i+3]));
1.14 @@ -188,7 +191,10 @@
1.15 i = 2;
1.16 }
1.17 else
1.18 + {
1.19 + high = 0;
1.20 i = 1;
1.21 + }
1.22
1.23 high |= (fromHex(buffer[i]) << 4) + (fromHex(buffer[i+1]));
1.24 low = (fromHex(buffer[i+2]) << 4) + (fromHex(buffer[i+3]));
1.25 @@ -238,10 +244,10 @@
1.26 {
1.27 int high;
1.28
1.29 - // 3-bit number shifted to A16...A14 with A16 discarded.
1.30 - // Thus, only sectors from 0 to 3 are supported.
1.31 + // 3-bit number shifted to A16...A14.
1.32 + // Thus, only sectors from 0 to 7 are supported.
1.33
1.34 - high = (fromHex(buffer[1]) << 6) & 0xff;
1.35 + high = (fromHex(buffer[1]) << 6) & 0x1ff;
1.36
1.37 for (int i = 0; i < 5; i++)
1.38 {
1.39 @@ -256,11 +262,22 @@
1.40
1.41 bool program(const char buffer[])
1.42 {
1.43 - int high, low, data;
1.44 + int high, low, data, i;
1.45
1.46 - high = (fromHex(buffer[1]) << 4) + (fromHex(buffer[2]));
1.47 - low = (fromHex(buffer[3]) << 4) + (fromHex(buffer[4]));
1.48 - data = (fromHex(buffer[5]) << 4) + (fromHex(buffer[6]));
1.49 + if (nread > 7)
1.50 + {
1.51 + high = fromHex(buffer[1]) << 8;
1.52 + i = 2;
1.53 + }
1.54 + else
1.55 + {
1.56 + high = 0;
1.57 + i = 1;
1.58 + }
1.59 +
1.60 + high |= (fromHex(buffer[i]) << 4) + (fromHex(buffer[i+1]));
1.61 + low = (fromHex(buffer[i+2]) << 4) + (fromHex(buffer[i+3]));
1.62 + data = (fromHex(buffer[i+4]) << 4) + (fromHex(buffer[i+5]));
1.63
1.64 for (int i = 0; i < 3; i++)
1.65 {