Skip to content

Commit c9354a8

Browse files
committed
changed #incbin to #embed (loosely based on C23 standard)
1 parent 73c7ac5 commit c9354a8

File tree

3 files changed

+14
-18
lines changed

3 files changed

+14
-18
lines changed

presets/c64/testlz4.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@
1313
#include <lz4.h>
1414

1515
// include the LZ4 binary data -> image_c64_multi_lz4[]
16-
17-
//#incbin "image-c64.multi.lz4"
16+
const char image_c64_multi_lz4[] = {
17+
#embed "image-c64.multi.lz4"
18+
};
1819

1920
/*
20-
CharData equ .
21-
ScreenData equ CharData+8000
22-
ColorData equ ScreenData+1000
23-
XtraData equ ColorData+1000
21+
CharData 8000 bytes
22+
ScreenData 1000 bytes
23+
ColorData 1000 bytes
24+
XtraData 2 bytes
2425
*/
2526

2627
void main() {

src/ide/project.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,12 @@ export class CodeProject {
189189
} else {
190190
// for .asm -- [.%]include "file"
191191
// for .c -- #include "file"
192-
let re2 = /^\s*[.#%]?(include|incbin)\s+"(.+?)"/gmi;
192+
let re2 = /^\s*[.#%]?(include|incbin|embed)\s+"(.+?)"/gmi;
193193
while (m = re2.exec(text)) {
194194
this.pushAllFiles(files, m[2]);
195195
}
196196
// for .c -- //#resource "file" (or ;resource or #resource)
197-
let re3 = /^\s*([;']|[/][/])#(resource|incbin)\s+"(.+?)"/gm;
197+
let re3 = /^\s*([;']|[/][/])#(resource)\s+"(.+?)"/gm;
198198
while (m = re3.exec(text)) {
199199
this.pushAllFiles(files, m[3]);
200200
}

src/worker/tools/cc65.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -273,22 +273,17 @@ export function linkLD65(step: BuildStep): BuildStepResult {
273273
}
274274

275275
function processIncbin(code: string) {
276-
let re3 = /^\s*([;']|[/][/])#incbin\s+"(.+?)"/gm;
277-
// find #incbin "filename.bin" and replace with C array declaration
278-
return code.replace(re3, (m, m1, m2) => {
279-
let filename = m2;
276+
let re3 = /^\s*#embed\s+"(.+?)"/gm;
277+
// find #embed "filename.bin" and replace with C array data
278+
return code.replace(re3, (m, m1) => {
279+
let filename = m1;
280280
let filedata = store.getFileData(filename);
281281
let bytes = convertDataToUint8Array(filedata);
282-
if (!bytes) throw new Error('#incbin: file not found: "' + filename + '"');
282+
if (!bytes) throw new Error('#embed: file not found: "' + filename + '"');
283283
let out = '';
284-
let ident = safeident(filename);
285-
console.log('#incbin', filename, ident, bytes.length);
286-
out += 'const unsigned char ' + ident + '[' + bytes.length + '] = {';
287284
for (let i = 0; i < bytes.length; i++) {
288285
out += bytes[i].toString() + ',';
289286
}
290-
out += '};';
291-
console.log('incbin', out);
292287
return out;
293288
});
294289
}

0 commit comments

Comments
 (0)