Rev 1013 | Rev 1022 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1013 | Rev 1020 | ||
|---|---|---|---|
| Line -... | Line 1... | ||
| - | 1 | ||
| - | 2 | const MAX_SIZE = 524288; |
|
| 1 | 3 | ||
| 2 | function IntelHex(hexLines) |
4 | function IntelHex(hexLines) |
| 3 | { |
5 | { |
| 4 | //print("constructor of IntelHex\n"); |
6 | //print("constructor of IntelHex\n"); |
| 5 | this.myValid = false; |
7 | this.myValid = false; |
| 6 | this.myHexLength = 0; |
8 | this.myHexLength = 0; |
| 7 | this.myAddrLower = 0x7FFFFFFF; |
9 | this.myAddrLower = 0x7FFFFFFF; |
| 8 | this.myAddrUpper = 0; |
10 | this.myAddrUpper = 0; |
| 9 | this.myHexData = new Array( |
11 | this.myHexData = new Array(MAX_SIZE); |
| 10 | for (var i = 0; i < |
12 | for (var i = 0; i < MAX_SIZE; i++) this.myHexData[i] = 0xFF; |
| 11 | 13 | ||
| 12 | var lineDataCount = 0; |
14 | var lineDataCount = 0; |
| 13 | var lineAddrHigh = 0; |
15 | var lineAddrHigh = 0; |
| 14 | var lineAddr = 0; |
16 | var lineAddr = 0; |
| 15 | var lineCode = 0; |
17 | var lineCode = 0; |
| Line 52... | Line 54... | ||
| 52 | IntelHex.prototype.myHexData = null; |
54 | IntelHex.prototype.myHexData = null; |
| 53 | IntelHex.prototype.myHexLength = null; |
55 | IntelHex.prototype.myHexLength = null; |
| 54 | IntelHex.prototype.myAddrLower = null; |
56 | IntelHex.prototype.myAddrLower = null; |
| 55 | IntelHex.prototype.myAddrUpper = null; |
57 | IntelHex.prototype.myAddrUpper = null; |
| 56 | IntelHex.prototype.myValid = null; |
58 | IntelHex.prototype.myValid = null; |
| - | 59 | ||
| - | 60 | /* |
|
| - | 61 | public int calcCRC(HexFile hf) { |
|
| - | 62 | int crc=0; |
|
| - | 63 | for (ulong i=hf.getAddrLower(); i <= hf.getAddrUpper(); i++) { |
|
| - | 64 | crc = crc16_update(crc, hf.getByte(i)); |
|
| - | 65 | } |
|
| - | 66 | return crc; |
|
| - | 67 | } |
|
| - | 68 | */ |
|
| - | 69 | ||
| - | 70 | IntelHex.prototype.getCRC16 = function() |
|
| - | 71 | { |
|
| - | 72 | var crc=0; |
|
| - | 73 | for (var i = 0; i < this.myHexLength; i++) |
|
| - | 74 | { |
|
| - | 75 | crc = this.crc16_update(crc, this.myHexData[i]); |
|
| - | 76 | } |
|
| - | 77 | return crc&0xffff; |
|
| - | 78 | } |
|
| - | 79 | ||
| - | 80 | IntelHex.prototype.crc16_update = function(crc, byte) |
|
| - | 81 | { |
|
| - | 82 | crc ^= byte; |
|
| - | 83 | for (var i = 0; i<8; ++i) |
|
| - | 84 | { |
|
| - | 85 | if ((crc & 1) != 0) |
|
| - | 86 | { |
|
| - | 87 | crc = (crc >> 1) ^ 0xA001; |
|
| - | 88 | } |
|
| - | 89 | else |
|
| - | 90 | { |
|
| - | 91 | crc = (crc >> 1); |
|
| - | 92 | } |
|
| - | 93 | } |
|
| - | 94 | return crc; |
|
| - | 95 | } |
|
| - | 96 | ||
| - | 97 | /* |
|
| - | 98 | public int crc16_update(int crc, byte a) { |
|
| - | 99 | int i; |
|
| - | 100 | crc ^= a; |
|
| - | 101 | for (i = 0; i < 8; ++i) { |
|
| - | 102 | if ((crc & 1) != 0) |
|
| - | 103 | crc = (crc >> 1) ^ 0xA001; |
|
| - | 104 | else |
|
| - | 105 | crc = (crc >> 1); |
|
| - | 106 | } |
|
| - | 107 | return crc; |
|
| - | 108 | } |
|
| - | 109 | */ |
|
| 57 | 110 | ||
| 58 | IntelHex.prototype.getLength = function() |
111 | IntelHex.prototype.getLength = function() |
| 59 | { |
112 | { |
| 60 | return this.myHexLength; |
113 | return this.myHexLength; |
| 61 | } |
114 | } |
| 62 | 115 | ||
| 63 | IntelHex.prototype.isValid = function() |
116 | IntelHex.prototype.isValid = function() |
| 64 | { |
117 | { |
| 65 | return this.myValid; |
118 | return this.myValid; |
| 66 | } |
119 | } |
| 67 | 120 | ||
| 68 | IntelHex.prototype.getAddrLower = function() |
121 | IntelHex.prototype.getAddrLower = function() |
| - | 122 | { |
|
| - | 123 | return this.myAddrLower; |
|
| - | 124 | } |
|
| - | 125 | ||
| - | 126 | IntelHex.prototype.getAddrUpper = function() |
|
| 69 | { |
127 | { |
| 70 | return this. |
128 | return this.myAddrUpper; |
| 71 | } |
129 | } |
| 72 | 130 | ||
| 73 | IntelHex.prototype.getByte = function(address) |
131 | IntelHex.prototype.getByte = function(address) |
| 74 | { |
132 | { |
| 75 | var byte = 0xff; |
133 | var byte = 0xff; |
| 76 | if (address < |
134 | if (address < MAX_SIZE && this.myValid) { |
| 77 | byte = this.myHexData[address]; |
135 | byte = this.myHexData[address]; |
| 78 | } |
136 | } |
| 79 | 137 | ||
| 80 | return byte; |
138 | return byte; |
| 81 | } |
139 | } |