MCPcopy Index your code
hub / github.com/Moddable-OpenSource/moddable / run

Method run

tools/mchex.js:105–145  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

103 }
104
105 run() {
106 const source = new Uint8Array(this.readFileBuffer(this.sourcePath));
107 let len = source.length;
108 let pos = 0;
109 let address = this.address;
110
111 const parts = this.splitPath(this.sourcePath);
112 parts.extension = ".hex";
113 if (this.outputDirectory)
114 parts.directory = this.outputDirectory;
115 if (this.outputName)
116 parts.name = this.outputName;
117 const outputPath = this.joinPath(parts);
118
119 const output = new FILE(outputPath, "wb");
120
121 while (len) {
122 if (this.currentSegment != (address & 0xffff0000))
123 output.writeString(this.generateSegment(address) + "\n");
124
125 const lineSize = len > 16 ? 16 : len;
126
127 const buf = source.slice(pos, pos+lineSize);
128 pos += lineSize;
129 len -= lineSize;
130
131 let out = ":" + ("00" + lineSize.toString(16)).slice(-2);
132 out += ("0000" + (address - this.currentSegment).toString(16)).slice(-4);
133 out += "00";
134 for(let j=0; j<lineSize; j++)
135 out += ("00" + (buf[j].toString(16))).slice(-2);
136
137 const chk = this.hexChecksum(out);
138 output.writeString((out + chk + "\n").toUpperCase());
139
140 address += lineSize;
141 }
142
143 output.writeString(":00000001FF");
144 output.close();
145 }
146}

Callers

nothing calls this directly

Calls 6

generateSegmentMethod · 0.80
hexChecksumMethod · 0.80
sliceMethod · 0.65
closeMethod · 0.65
writeStringMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected