mirror of
https://github.com/sehugg/8bitworkshop.git
synced 2024-05-28 23:41:32 +00:00
hacked in "incbin" for C files, c64 lz4 example
This commit is contained in:
parent
dd96813b76
commit
2de919a225
BIN
presets/c64/image-c64.multi.lz4
Normal file
BIN
presets/c64/image-c64.multi.lz4
Normal file
Binary file not shown.
49
presets/c64/testlz4.c
Normal file
49
presets/c64/testlz4.c
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
|
||||||
|
// sid config so we don't use stack above $8000
|
||||||
|
|
||||||
|
//#resource "c64-sid.cfg"
|
||||||
|
#define CFGFILE c64-sid.cfg
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
//#link "common.c"
|
||||||
|
|
||||||
|
#include "mcbitmap.h"
|
||||||
|
//#link "mcbitmap.c"
|
||||||
|
|
||||||
|
#include <lz4.h>
|
||||||
|
|
||||||
|
// include the LZ4 binary data -> image_c64_multi_lz4[]
|
||||||
|
|
||||||
|
//#incbin "image-c64.multi.lz4"
|
||||||
|
|
||||||
|
/*
|
||||||
|
CharData equ .
|
||||||
|
ScreenData equ CharData+8000
|
||||||
|
ColorData equ ScreenData+1000
|
||||||
|
XtraData equ ColorData+1000
|
||||||
|
*/
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
char* const uncomp = (char*)0xb000;
|
||||||
|
char bgcolor;
|
||||||
|
|
||||||
|
// setup VIC for multicolor bitmap
|
||||||
|
// colormap = $c000-$c7ff
|
||||||
|
// bitmap = $e000-$ffff
|
||||||
|
setup_bitmap_multi();
|
||||||
|
// enable HIMEM so we can write to $c000-$ffff
|
||||||
|
ENABLE_HIMEM();
|
||||||
|
// decompress into $8000-$a711
|
||||||
|
decompress_lz4(image_c64_multi_lz4+11, uncomp, 10002);
|
||||||
|
// read background color
|
||||||
|
bgcolor = uncomp[10000];
|
||||||
|
// copy data to destination areas
|
||||||
|
memcpy((void*)MCB_BITMAP, uncomp, 8000);
|
||||||
|
memcpy(COLOR_RAM, uncomp+9000, 1000);
|
||||||
|
memcpy((void*)MCB_COLORS, uncomp+8000, 1000);
|
||||||
|
DISABLE_HIMEM();
|
||||||
|
// set background color
|
||||||
|
VIC.bgcolor0 = bgcolor;
|
||||||
|
// wait for key
|
||||||
|
cgetc();
|
||||||
|
}
|
|
@ -424,6 +424,9 @@ export function clamp(minv:number, maxv:number, v:number) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function safeident(s : string) : string {
|
export function safeident(s : string) : string {
|
||||||
|
// if starts with non-alpha character, prefix with '_'
|
||||||
|
if (s.length == 0) return '';
|
||||||
|
if (!s.match(/^[a-zA-Z_]/)) s = '_' + s;
|
||||||
return s.replace(/\W+/g, "_");
|
return s.replace(/\W+/g, "_");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -200,9 +200,9 @@ export class CodeProject {
|
||||||
this.pushAllFiles(files, m[2]);
|
this.pushAllFiles(files, m[2]);
|
||||||
}
|
}
|
||||||
// for .c -- //#resource "file" (or ;resource or #resource)
|
// for .c -- //#resource "file" (or ;resource or #resource)
|
||||||
let re3 = /^\s*([;']|[/][/])#resource\s+"(.+?)"/gm;
|
let re3 = /^\s*([;']|[/][/])#(resource|incbin)\s+"(.+?)"/gm;
|
||||||
while (m = re3.exec(text)) {
|
while (m = re3.exec(text)) {
|
||||||
this.pushAllFiles(files, m[2]);
|
this.pushAllFiles(files, m[3]);
|
||||||
}
|
}
|
||||||
// for XASM only (USE include.ext)
|
// for XASM only (USE include.ext)
|
||||||
// for merlin32 (ASM include.ext)
|
// for merlin32 (ASM include.ext)
|
||||||
|
|
|
@ -23,6 +23,7 @@ const C64_PRESETS = [
|
||||||
{id:'test_multispritelib.c', name:'Sprite Multiplexing Library'},
|
{id:'test_multispritelib.c', name:'Sprite Multiplexing Library'},
|
||||||
{id:'scrolling_text.c', name:'Big Scrolling Text'},
|
{id:'scrolling_text.c', name:'Big Scrolling Text'},
|
||||||
{id:'mcbitmap.c', name:'Multicolor Bitmap Mode'},
|
{id:'mcbitmap.c', name:'Multicolor Bitmap Mode'},
|
||||||
|
{id:'testlz4.c', name:'LZ4 Bitmap Compression'},
|
||||||
//{id:'mandel.c', name:'Mandelbrot Fractal'},
|
//{id:'mandel.c', name:'Mandelbrot Fractal'},
|
||||||
{id:'musicplayer.c', name:'Music Player'},
|
{id:'musicplayer.c', name:'Music Player'},
|
||||||
//{id:'sidtune.dasm', name:'Tiny SID Tune (ASM)'},
|
//{id:'sidtune.dasm', name:'Tiny SID Tune (ASM)'},
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
import { getFilenamePrefix, getRootBasePlatform } from "../../common/util";
|
import { convertDataToUint8Array, getFilenamePrefix, getRootBasePlatform, safeident } from "../../common/util";
|
||||||
import { CodeListingMap, WorkerError } from "../../common/workertypes";
|
import { CodeListingMap, WorkerError } from "../../common/workertypes";
|
||||||
import { re_crlf, BuildStepResult, anyTargetChanged, execMain, gatherFiles, msvcErrorMatcher, populateEntry, populateExtraFiles, populateFiles, print_fn, putWorkFile, setupFS, staleFiles, BuildStep, emglobal, loadNative, moduleInstFn, fixParamsWithDefines, store, makeErrorMatcher, getWorkFileAsString } from "../workermain";
|
import { re_crlf, BuildStepResult, anyTargetChanged, execMain, gatherFiles, msvcErrorMatcher, populateEntry, populateExtraFiles, populateFiles, print_fn, putWorkFile, setupFS, staleFiles, BuildStep, emglobal, loadNative, moduleInstFn, fixParamsWithDefines, store, makeErrorMatcher, getWorkFileAsString } from "../workermain";
|
||||||
import { EmscriptenModule } from "../workermain"
|
import { EmscriptenModule } from "../workermain"
|
||||||
|
@ -272,6 +272,27 @@ 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 filedata = store.getFileData(filename);
|
||||||
|
let bytes = convertDataToUint8Array(filedata);
|
||||||
|
if (!bytes) throw new Error('#incbin: 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;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export function compileCC65(step: BuildStep): BuildStepResult {
|
export function compileCC65(step: BuildStep): BuildStepResult {
|
||||||
loadNative("cc65");
|
loadNative("cc65");
|
||||||
var params = step.params;
|
var params = step.params;
|
||||||
|
@ -303,7 +324,15 @@ export function compileCC65(step: BuildStep): BuildStepResult {
|
||||||
});
|
});
|
||||||
var FS = CC65.FS;
|
var FS = CC65.FS;
|
||||||
setupFS(FS, '65-' + getRootBasePlatform(step.platform));
|
setupFS(FS, '65-' + getRootBasePlatform(step.platform));
|
||||||
populateFiles(step, FS);
|
populateFiles(step, FS, {
|
||||||
|
mainFilePath: step.path,
|
||||||
|
processFn: (path, code) => {
|
||||||
|
if (typeof code === 'string') {
|
||||||
|
code = processIncbin(code);
|
||||||
|
}
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
});
|
||||||
fixParamsWithDefines(step.path, params);
|
fixParamsWithDefines(step.path, params);
|
||||||
var args = [
|
var args = [
|
||||||
'-I', '/share/include',
|
'-I', '/share/include',
|
||||||
|
|
Loading…
Reference in New Issue
Block a user