From b9dfd552a62a46449532d49adc0773589076c808 Mon Sep 17 00:00:00 2001 From: Uri Shaked Date: Thu, 21 Nov 2019 19:40:02 +0200 Subject: feat: add blink demo --- demo/src/intelhex.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 demo/src/intelhex.ts (limited to 'demo/src/intelhex.ts') diff --git a/demo/src/intelhex.ts b/demo/src/intelhex.ts new file mode 100644 index 0000000..ba5d6c8 --- /dev/null +++ b/demo/src/intelhex.ts @@ -0,0 +1,18 @@ +/** + * Minimal Intel HEX loader + * Part of AVR8js + * + * Copyright (C) 2019, Uri Shaked + */ + +export function loadHex(source: string, target: Uint8Array) { + for (const line of source.split('\n')) { + if (line[0] === ':' && line.substr(7, 2) === '00') { + const bytes = parseInt(line.substr(1, 2), 16); + const addr = parseInt(line.substr(3, 4), 16); + for (let i = 0; i < bytes; i++) { + target[addr + i] = parseInt(line.substr(9 + i * 2, 2), 16); + } + } + } +} -- cgit v1.2.3