Skip to content

Commit

Permalink
changed #incbin to #embed (loosely based on C23 standard)
Browse files Browse the repository at this point in the history
  • Loading branch information
sehugg committed Nov 17, 2023
1 parent 73c7ac5 commit c9354a8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
13 changes: 7 additions & 6 deletions presets/c64/testlz4.c
Expand Up @@ -13,14 +13,15 @@
#include <lz4.h>

// include the LZ4 binary data -> image_c64_multi_lz4[]

//#incbin "image-c64.multi.lz4"
const char image_c64_multi_lz4[] = {
#embed "image-c64.multi.lz4"
};

/*
CharData equ .
ScreenData equ CharData+8000
ColorData equ ScreenData+1000
XtraData equ ColorData+1000
CharData 8000 bytes
ScreenData 1000 bytes
ColorData 1000 bytes
XtraData 2 bytes
*/

void main() {
Expand Down
4 changes: 2 additions & 2 deletions src/ide/project.ts
Expand Up @@ -189,12 +189,12 @@ export class CodeProject {
} else {
// for .asm -- [.%]include "file"
// for .c -- #include "file"
let re2 = /^\s*[.#%]?(include|incbin)\s+"(.+?)"/gmi;
let re2 = /^\s*[.#%]?(include|incbin|embed)\s+"(.+?)"/gmi;
while (m = re2.exec(text)) {
this.pushAllFiles(files, m[2]);
}
// for .c -- //#resource "file" (or ;resource or #resource)
let re3 = /^\s*([;']|[/][/])#(resource|incbin)\s+"(.+?)"/gm;
let re3 = /^\s*([;']|[/][/])#(resource)\s+"(.+?)"/gm;
while (m = re3.exec(text)) {
this.pushAllFiles(files, m[3]);
}
Expand Down
15 changes: 5 additions & 10 deletions src/worker/tools/cc65.ts
Expand Up @@ -273,22 +273,17 @@ export function linkLD65(step: BuildStep): BuildStepResult {
}

function processIncbin(code: string) {
let re3 = /^\s*([;']|[/][/])#incbin\s+"(.+?)"/gm;
// find #incbin "filename.bin" and replace with C array declaration
return code.replace(re3, (m, m1, m2) => {
let filename = m2;
let re3 = /^\s*#embed\s+"(.+?)"/gm;
// find #embed "filename.bin" and replace with C array data
return code.replace(re3, (m, m1) => {
let filename = m1;
let filedata = store.getFileData(filename);
let bytes = convertDataToUint8Array(filedata);
if (!bytes) throw new Error('#incbin: file not found: "' + filename + '"');
if (!bytes) throw new Error('#embed: file not found: "' + filename + '"');
let out = '';
let ident = safeident(filename);
console.log('#incbin', filename, ident, bytes.length);
out += 'const unsigned char ' + ident + '[' + bytes.length + '] = {';
for (let i = 0; i < bytes.length; i++) {
out += bytes[i].toString() + ',';
}
out += '};';
console.log('incbin', out);
return out;
});
}
Expand Down

0 comments on commit c9354a8

Please sign in to comment.