Skip to content

Commit

Permalink
fix(demo): support for large hex files
Browse files Browse the repository at this point in the history
improve intelhex loader to handle 04 records
  • Loading branch information
urish committed Apr 20, 2021
1 parent 40eaf0e commit 25e3a6c
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions demo/intelhex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@
* Copyright (C) 2019, Uri Shaked
*/

export function loadHex(source: string, target: Uint8Array) {
export function loadHex(source: string, target: Uint8Array, baseAddress: number = 0) {
let highAddressBytes = 0;
for (const line of source.split('\n')) {
if (line[0] === ':' && line.substr(7, 2) === '04') {
highAddressBytes = parseInt(line.substr(9, 4), 16);
}
if (line[0] === ':' && line.substr(7, 2) === '00') {
const bytes = parseInt(line.substr(1, 2), 16);
const addr = parseInt(line.substr(3, 4), 16);
const addr = ((highAddressBytes << 16) | parseInt(line.substr(3, 4), 16)) - baseAddress;
for (let i = 0; i < bytes; i++) {
target[addr + i] = parseInt(line.substr(9 + i * 2, 2), 16);
}
Expand Down

0 comments on commit 25e3a6c

Please sign in to comment.