changed #incbin to #embed (loosely based on C23 standard)

This commit is contained in:
Steven Hugg 2023-11-17 10:29:35 -06:00
parent 73c7ac5941
commit c9354a83ea
3 changed files with 14 additions and 18 deletions

View File

@ -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() {

View File

@ -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]);
}

View File

@ -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;
});
}