1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-11-25 18:33:11 +00:00

support ;#define CFGFILE and ;#define LIBARGS for non-C ca65 programs

This commit is contained in:
Steven Hugg 2019-05-21 21:39:37 -04:00
parent 7b1ec939b6
commit 029c1156ed
6 changed files with 23 additions and 14 deletions

View File

@ -154,6 +154,7 @@ TODO:
- support projects with subdirectories, file list?
- emulator needs reset shortcut for nes
- switching platform of a repo?
- what to load if no main file?
WEB WORKER FORMAT

View File

@ -359,6 +359,7 @@ if (window.location.host.endsWith('8bitworkshop.com')) {
<p>Enter the GitHub repository URL:</p>
<p><input id="importGithubURL" size="60" placeholder="https://github.com/user/repo"></input></p>
<p>If the project is compatible with 8bitworkshop, it should build automatically.</p>
<p>Otherwise, some work may be required -- make sure you've selected the correct platform.</p>
<p>Source files must be in the root folder of the repository.</p>
<p><button type="button" class="btn btn-primary" id="importGithubButton">Import Project</button></p>
</div>

View File

@ -98,8 +98,8 @@ export class CodeProject {
while (m = re2.exec(text)) {
this.pushAllFiles(files, m[2]);
}
// for .c -- //#link "file" (or ;link or #link)
let re3 = /^\s*([;#]|[/][/][#])resource\s+"(.+?)"/gm;
// for .c -- //#resource "file" (or ;resource or #resource)
let re3 = /^\s*([;]|[/][/])#resource\s+"(.+?)"/gm;
while (m = re3.exec(text)) {
this.pushAllFiles(files, m[2]);
}
@ -114,7 +114,7 @@ export class CodeProject {
//
} else {
// for .c -- //#link "file" (or ;link or #link)
let re = /^\s*([;#]|[/][/][#])link\s+"(.+?)"/gm;
let re = /^\s*([;]|[/][/])#link\s+"(.+?)"/gm;
while (m = re.exec(text)) {
this.pushAllFiles(files, m[2]);
}

View File

@ -572,13 +572,11 @@ function pushChangesToGithub(message:string) {
files.push({path:newpath, data:data});
}
}
// TODO: include built ROM file in bin/[mainfile].rom
/*
// include built ROM file in bin/[mainfile].rom
if (current_output instanceof Uint8Array) {
let binpath = "bin/"+getCurrentMainFilename()+".rom";
files.push({path:binpath, data:current_output});
}
*/
// push files
setWaitDialog(true);
return getGithubService().login().then( () => {

View File

@ -197,11 +197,6 @@ var PLATFORM_PARAMS = {
{name:'Cartridge RAM',start:0x6000,size:0x2000,type:'ram'},
],
},
'nes-asm': {
cfgfile: 'nes.cfg',
define: '__NES__',
libargs: ['nes.lib'],
},
'apple2': {
define: '__APPLE2__',
cfgfile: 'apple2-hgr.cfg',
@ -776,6 +771,9 @@ function assembleDASM(step:BuildStep) {
listings[path] = {lines:[]};
}
parseDASMListing(alst, listings, errors, unresolved);
if (errors.length) {
return {errors:errors};
}
// read binary rom output and symbols
var aout, asym;
aout = FS.readFile(binpath);
@ -914,6 +912,7 @@ function assembleCA65(step:BuildStep) {
var FS = CA65['FS'];
setupFS(FS, '65-'+getRootBasePlatform(step.platform));
populateFiles(step, FS);
fixParamsWithDefines(step.path, step.params);
execMain(step, CA65, ['-v', '-g', '-I', '/share/asminc', '-o', objpath, '-l', lstpath, step.path]);
if (errors.length)
return {errors:errors};
@ -947,6 +946,10 @@ function linkLD65(step:BuildStep) {
setupFS(FS, '65-'+getRootBasePlatform(step.platform));
populateFiles(step, FS);
populateExtraFiles(step, FS, params.extra_link_files);
// populate .cfg file, if it is a custom one
if (workfs[params.cfgfile]) {
populateEntry(FS, params.cfgfile, workfs[params.cfgfile], null);
}
var libargs = params.libargs;
var cfgfile = params.cfgfile;
var args = ['--cfg-path', '/share/cfg',
@ -1034,6 +1037,7 @@ function fixParamsWithDefines(path:string, params){
if (path && libargs) {
var code = getWorkFileAsString(path);
if (code) {
var oldcfgfile = params.cfgfile;
var ident2index = {};
// find all lib args "IDENT=VALUE"
for (var i=0; i<libargs.length; i++) {
@ -1043,7 +1047,7 @@ function fixParamsWithDefines(path:string, params){
}
}
// find #defines and replace them
var re = /^#define\s+(\w+)\s+(\S+)/gmi;
var re = /^[;]?#define\s+(\w+)\s+(\S+)/gmi; // TODO: empty string?
var m;
while (m = re.exec(code)) {
var ident = m[1];
@ -1055,8 +1059,13 @@ function fixParamsWithDefines(path:string, params){
// TODO: MMC3 mapper switch
if (ident == 'NES_MAPPER' && value == '4') {
params.cfgfile = 'nesbanked.cfg';
console.log('Using config file', params.cfgfile);
console.log("using config file", params.cfgfile);
}
} else if (ident == 'CFGFILE' && value) {
params.cfgfile = value;
} else if (ident == 'LIBARGS' && value) {
params.libargs = value.split(',').filter((s) => { return s!=''; });
console.log('Using libargs', params.libargs);
}
}
}

View File

@ -110,7 +110,7 @@ describe('Worker', function() {
compile('cc65', '#include "NOSUCH.file"\n', 'nes', done, 0, 0, 1, {ignoreErrorPath:true});
});
it('should assemble CA65', function(done) {
compile('ca65', '\t.segment "HEADER"\n\t.segment "STARTUP"\n\t.segment "CHARS"\n\t.segment "VECTORS"\n\tlda #0\n\tsta $1\n', 'nes-asm', done, 40976, 2);
compile('ca65', ';#define LIBARGS ,\n\t.segment "HEADER"\n\t.segment "STARTUP"\n\t.segment "CHARS"\n\t.segment "VECTORS"\n\t.segment "SAMPLES"\n\t.segment "CODE"\n\tlda #0\n\tsta $1\n', 'nes', done, 40976, 2);
});
/*
it('should assemble Z80ASM', function(done) {