@@ -360,6 +360,28 @@ function convertRecordTo(iHexRecord: string, recordType: RecordType): string {
360
360
return `${ START_CODE_STR } ${ recordContentStr } ${ checksumStr } ` ;
361
361
}
362
362
363
+ /**
364
+ * Converts and Extended Segment Linear Address record to an Extended Linear
365
+ * Address record.
366
+ *
367
+ * @throws {Error } When the record does not contain exactly 2 bytes.
368
+ * @throws {Error } When the Segmented Address is not a multiple of 0x1000.
369
+ *
370
+ * @param iHexRecord Intel hex record line without line terminator.
371
+ */
372
+ function convertExtSegToLinAddressRecord ( iHexRecord : string ) : string {
373
+ const segmentAddress = getRecordData ( iHexRecord ) ;
374
+ if (
375
+ segmentAddress . length !== 2 ||
376
+ segmentAddress [ 0 ] & 0xf || // Only process multiples of 0x1000
377
+ segmentAddress [ 1 ] !== 0
378
+ ) {
379
+ throw new Error ( `Invalid Extended Segment Address record ${ iHexRecord } ` ) ;
380
+ }
381
+ const startAddress = segmentAddress [ 0 ] << 12 ;
382
+ return extLinAddressRecord ( startAddress ) ;
383
+ }
384
+
363
385
/**
364
386
* Separates an Intel Hex file (string) into an array of Record strings.
365
387
*
@@ -386,8 +408,8 @@ function iHexToRecordStrs(iHexStr: string): string[] {
386
408
* This is useful to identify the expected max size of the data records for an
387
409
* Intel Hex, and then be able to generate new custom records of the same size.
388
410
*
389
- * @param iHexRecords Array of Intel Hex Records
390
- * @returns Number of data bytes th
411
+ * @param iHexRecords Array of Intel Hex Records.
412
+ * @returns Number of data bytes in a full record.
391
413
*/
392
414
function findDataFieldLength ( iHexRecords : string [ ] ) : number {
393
415
let maxDataBytes = 16 ;
@@ -423,6 +445,7 @@ export {
423
445
blockEndRecord ,
424
446
paddedDataRecord ,
425
447
convertRecordTo ,
448
+ convertExtSegToLinAddressRecord ,
426
449
iHexToRecordStrs ,
427
450
findDataFieldLength ,
428
451
} ;
0 commit comments