1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-07-22 20:29:37 +00:00

started integrating batariBASIC

This commit is contained in:
Steven Hugg 2018-11-20 12:31:19 -05:00
parent 97f69c2af1
commit f337b52be3
7 changed files with 4558 additions and 7 deletions

View File

@ -0,0 +1,24 @@
 rem Hello World
playfield:
................................
......X.X.XXX.X...X...XXX.......
......X.X.X...X...X...X.X.......
......XXX.XX..X...X...X.X.......
......X.X.X...X...X...X.X.......
......X.X.XXX.XXX.XXX.XXX.......
................................
.....X...X.XXX.XX..X...XX.......
.....X...X.X.X.X.X.X...X.X......
.....X.X.X.X.X.XX..X...X.X......
.....XX.XX.XXX.X.X.XXX.XX.......
end
COLUPF = 22
COLUBK = 2
mainloop
drawscreen
score = score + 1
goto mainloop

View File

@ -41,6 +41,7 @@ const VCS_PRESETS = [
// {id:'examples/testlibrary', name:'VCS Library Demo'},
// {id:'examples/music2', name:'Pitch-Accurate Music'},
// {id:'examples/fullgame', name:'Thru Hike: The Game', title:'Thru Hike'},
{id:'bb/helloworld.bas', name:'Hello World (batariBASIC)'},
];
Javatari.AUTO_START = false;
@ -95,7 +96,7 @@ class VCSPlatform extends BasePlatform {
//console.log(Javatari.room.console.isRunning(), Javatari.room.console.isPowerOn);
return Javatari.room && Javatari.room.console.isRunning();
}
pause() {
pause() {
Javatari.room.console.pause();
Javatari.room.speaker.mute();
}
@ -114,7 +115,7 @@ class VCSPlatform extends BasePlatform {
step() { Javatari.room.console.debugSingleStepCPUClock(); }
stepBack() { Javatari.room.console.debugStepBackInstruction(); }
runEval(evalfunc) { Javatari.room.console.debugEval(evalfunc); }
setupDebug(callback) {
Javatari.room.console.onBreakpointHit = (state) => {
state.c.PC = (state.c.PC - 1) & 0xffff;
@ -132,7 +133,7 @@ class VCSPlatform extends BasePlatform {
Javatari.room.console.onBreakpointHit = null;
if (this.isRunning()) Javatari.room.speaker.play();
}
reset() {
Javatari.room.console.powerOff();
Javatari.room.console.resetDebug();
@ -205,6 +206,7 @@ class VCSPlatform extends BasePlatform {
return "\n" + dumpRAM(ram, 0x80, 0x80);
}
getToolForFilename(fn) {
if (fn.endsWith(".bb") || fn.endsWith(".bas")) return "bataribasic";
return "dasm";
}
getDefaultExtension() { return ".a"; };

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,200 @@
var Module = typeof Module !== 'undefined' ? Module : {};
if (!Module.expectedDataFileDownloads) {
Module.expectedDataFileDownloads = 0;
Module.finishedDataFileDownloads = 0;
}
Module.expectedDataFileDownloads++;
(function() {
var loadPackage = function(metadata) {
var PACKAGE_PATH;
if (typeof window === 'object') {
PACKAGE_PATH = window['encodeURIComponent'](window.location.pathname.toString().substring(0, window.location.pathname.toString().lastIndexOf('/')) + '/');
} else if (typeof location !== 'undefined') {
// worker
PACKAGE_PATH = encodeURIComponent(location.pathname.toString().substring(0, location.pathname.toString().lastIndexOf('/')) + '/');
} else {
throw 'using preloaded data can only be done on a web page or in a web worker';
}
var PACKAGE_NAME = 'fs2600basic.data';
var REMOTE_PACKAGE_BASE = 'fs2600basic.data';
if (typeof Module['locateFilePackage'] === 'function' && !Module['locateFile']) {
Module['locateFile'] = Module['locateFilePackage'];
err('warning: you defined Module.locateFilePackage, that has been renamed to Module.locateFile (using your locateFilePackage for now)');
}
var REMOTE_PACKAGE_NAME = Module['locateFile'] ? Module['locateFile'](REMOTE_PACKAGE_BASE, '') : REMOTE_PACKAGE_BASE;
var REMOTE_PACKAGE_SIZE = metadata.remote_package_size;
var PACKAGE_UUID = metadata.package_uuid;
function fetchRemotePackage(packageName, packageSize, callback, errback) {
var xhr = new XMLHttpRequest();
xhr.open('GET', packageName, true);
xhr.responseType = 'arraybuffer';
xhr.onprogress = function(event) {
var url = packageName;
var size = packageSize;
if (event.total) size = event.total;
if (event.loaded) {
if (!xhr.addedTotal) {
xhr.addedTotal = true;
if (!Module.dataFileDownloads) Module.dataFileDownloads = {};
Module.dataFileDownloads[url] = {
loaded: event.loaded,
total: size
};
} else {
Module.dataFileDownloads[url].loaded = event.loaded;
}
var total = 0;
var loaded = 0;
var num = 0;
for (var download in Module.dataFileDownloads) {
var data = Module.dataFileDownloads[download];
total += data.total;
loaded += data.loaded;
num++;
}
total = Math.ceil(total * Module.expectedDataFileDownloads/num);
if (Module['setStatus']) Module['setStatus']('Downloading data... (' + loaded + '/' + total + ')');
} else if (!Module.dataFileDownloads) {
if (Module['setStatus']) Module['setStatus']('Downloading data...');
}
};
xhr.onerror = function(event) {
throw new Error("NetworkError for: " + packageName);
}
xhr.onload = function(event) {
if (xhr.status == 200 || xhr.status == 304 || xhr.status == 206 || (xhr.status == 0 && xhr.response)) { // file URLs can return 0
var packageData = xhr.response;
callback(packageData);
} else {
throw new Error(xhr.statusText + " : " + xhr.responseURL);
}
};
xhr.send(null);
};
function handleError(error) {
console.error('package error:', error);
};
var fetchedCallback = null;
var fetched = Module['getPreloadedPackage'] ? Module['getPreloadedPackage'](REMOTE_PACKAGE_NAME, REMOTE_PACKAGE_SIZE) : null;
if (!fetched) fetchRemotePackage(REMOTE_PACKAGE_NAME, REMOTE_PACKAGE_SIZE, function(data) {
if (fetchedCallback) {
fetchedCallback(data);
fetchedCallback = null;
} else {
fetched = data;
}
}, handleError);
function runWithFS() {
function assert(check, msg) {
if (!check) throw msg + new Error().stack;
}
Module['FS_createPath']('/', 'includes', true, true);
function DataRequest(start, end, audio) {
this.start = start;
this.end = end;
this.audio = audio;
}
DataRequest.prototype = {
requests: {},
open: function(mode, name) {
this.name = name;
this.requests[name] = this;
Module['addRunDependency']('fp ' + this.name);
},
send: function() {},
onload: function() {
var byteArray = this.byteArray.subarray(this.start, this.end);
this.finish(byteArray);
},
finish: function(byteArray) {
var that = this;
Module['FS_createDataFile'](this.name, null, byteArray, true, true, true); // canOwn this data in the filesystem, it is a slide into the heap that will never change
Module['removeRunDependency']('fp ' + that.name);
this.requests[this.name] = null;
}
};
var files = metadata.files;
for (var i = 0; i < files.length; ++i) {
new DataRequest(files[i].start, files[i].end, files[i].audio).open('GET', files[i].filename);
}
function processPackageData(arrayBuffer) {
Module.finishedDataFileDownloads++;
assert(arrayBuffer, 'Loading data file failed.');
assert(arrayBuffer instanceof ArrayBuffer, 'bad input to processPackageData');
var byteArray = new Uint8Array(arrayBuffer);
var curr;
// copy the entire loaded file into a spot in the heap. Files will refer to slices in that. They cannot be freed though
// (we may be allocating before malloc is ready, during startup).
var ptr = Module['getMemory'](byteArray.length);
Module['HEAPU8'].set(byteArray, ptr);
DataRequest.prototype.byteArray = Module['HEAPU8'].subarray(ptr, ptr+byteArray.length);
var files = metadata.files;
for (var i = 0; i < files.length; ++i) {
DataRequest.prototype.requests[files[i].filename].onload();
}
Module['removeRunDependency']('datafile_fs2600basic.data');
};
Module['addRunDependency']('datafile_fs2600basic.data');
if (!Module.preloadResults) Module.preloadResults = {};
Module.preloadResults[PACKAGE_NAME] = {fromCache: false};
if (fetched) {
processPackageData(fetched);
fetched = null;
} else {
fetchedCallback = processPackageData;
}
}
if (Module['calledRun']) {
runWithFS();
} else {
if (!Module['preRun']) Module['preRun'] = [];
Module["preRun"].push(runWithFS); // FS is not initialized yet, wait for it
}
Module['removeRunDependency']('fs2600basic.js.metadata');
}
function runMetaWithFS() {
Module['addRunDependency']('fs2600basic.js.metadata');
var REMOTE_METADATA_NAME = Module['locateFile'] ? Module['locateFile']('fs2600basic.js.metadata', '') : 'fs2600basic.js.metadata';
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
loadPackage(JSON.parse(xhr.responseText));
}
}
xhr.open('GET', REMOTE_METADATA_NAME, true);
xhr.overrideMimeType('application/json');
xhr.send(null);
}
if (Module['calledRun']) {
runMetaWithFS();
} else {
if (!Module['preRun']) Module['preRun'] = [];
Module["preRun"].push(runMetaWithFS);
}
})();

View File

@ -0,0 +1 @@
{"files":[{"start":0,"audio":0,"end":311,"filename":"/includes/2600basicfooter.asm"},{"start":311,"audio":0,"end":5628,"filename":"/includes/macro.h"},{"start":5628,"audio":0,"end":5907,"filename":"/includes/bankswitch.inc"},{"start":5907,"audio":0,"end":7100,"filename":"/includes/6lives.asm"},{"start":7100,"audio":0,"end":16497,"filename":"/includes/vcs.h"},{"start":16497,"audio":0,"end":16776,"filename":"/includes/superchip.inc"},{"start":16776,"audio":0,"end":17446,"filename":"/includes/div_mul16.asm"},{"start":17446,"audio":0,"end":20386,"filename":"/includes/std_overscan.asm"},{"start":20386,"audio":0,"end":31722,"filename":"/includes/std_kernel.asm"},{"start":31722,"audio":0,"end":34956,"filename":"/includes/2600basic.h"},{"start":34956,"audio":0,"end":35731,"filename":"/includes/banksw.asm"},{"start":35731,"audio":0,"end":36075,"filename":"/includes/multispriteheader.asm"},{"start":36075,"audio":0,"end":36543,"filename":"/includes/div_mul.asm"},{"start":36543,"audio":0,"end":38512,"filename":"/includes/6lives_statusbar.asm"},{"start":38512,"audio":0,"end":55929,"filename":"/includes/multisprite_kernel.asm"},{"start":55929,"audio":0,"end":56940,"filename":"/includes/default.inc"},{"start":56940,"audio":0,"end":57313,"filename":"/includes/superchipheader.asm"},{"start":57313,"audio":0,"end":60959,"filename":"/includes/pf_scrolling.asm"},{"start":60959,"audio":0,"end":61376,"filename":"/includes/std_routines.asm"},{"start":61376,"audio":0,"end":61718,"filename":"/includes/2600basicheader.asm"},{"start":61718,"audio":0,"end":62836,"filename":"/includes/multisprite_bankswitch.inc"},{"start":62836,"audio":0,"end":63521,"filename":"/includes/startup.asm"},{"start":63521,"audio":0,"end":66385,"filename":"/includes/pf_drawing.asm"},{"start":66385,"audio":0,"end":69155,"filename":"/includes/score_graphics.asm"},{"start":69155,"audio":0,"end":69411,"filename":"/includes/pfread_msk.asm"},{"start":69411,"audio":0,"end":71348,"filename":"/includes/fixed_point_math.asm"},{"start":71348,"audio":0,"end":74117,"filename":"/includes/multisprite.h"},{"start":74117,"audio":0,"end":75008,"filename":"/includes/multisprite.inc"}],"remote_package_size":75008,"package_uuid":"b68e90d4-dae1-4423-bf56-6dc26335d90c"}

View File

@ -649,7 +649,10 @@ function assembleDASM(step:BuildStep) {
var binpath = step.prefix+'.bin';
var lstpath = step.prefix+'.lst';
var sympath = step.prefix+'.sym';
execMain(step, Module, [step.path, "-l"+lstpath, "-o"+binpath, "-s"+sympath ]);
execMain(step, Module, [step.path,
"-l"+lstpath,
"-o"+binpath,
"-s"+sympath ]);
var alst = FS.readFile(lstpath, {'encoding':'utf8'});
// parse main listing, get errors
var listing = parseDASMListing(alst, unresolved, step.path);
@ -905,7 +908,8 @@ function compileCC65(step:BuildStep) {
return {
nexttool:"ca65",
path:destpath,
args:[destpath]
args:[destpath],
files:[destpath],
};
}
@ -1139,7 +1143,8 @@ function compileSDCC(step:BuildStep) {
return {
nexttool:"sdasz80",
path:outpath,
args:[outpath]
args:[outpath],
files:[outpath],
};
}
@ -1482,6 +1487,72 @@ error1.asm(11): warning: 'foobar' treated as label (instruction typo?)
}
}
function compileBatariBasic(step:BuildStep) {
load("bb2600basic");
var params = step.params;
// stdout
var asmout = "";
function addasmout_fn(s) {
asmout += s;
asmout += "\n";
}
// stderr
var re_err1 = /[(](\d+)[)]:?\s*(.+)/;
var errors = [];
var errline = 0;
function match_fn(s) {
console.log(s);
var matches = re_err1.exec(s);
if (matches) {
errline = parseInt(matches[1]);
errors.push({
line:errline,
msg:matches[2]
});
}
}
gatherFiles(step, {mainFilePath:"main.bas"});
var destpath = step.prefix + '.asm';
if (staleFiles(step, [destpath])) {
var BB = emglobal.bb2600basic({
noInitialRun:true,
//logReadFiles:true,
print:addasmout_fn,
printErr:match_fn,
noFSInit:true,
});
var FS = BB['FS'];
populateFiles(step, FS);
// pipe file to stdin
var code = workfs[step.path].data as string; // TODO
setupStdin(FS, code);
setupFS(FS, '2600basic');
execMain(step, BB, ["-i", "/share", step.path]);
if (errors.length)
return {errors:errors};
// build final assembly output from include file list
var includesout = FS.readFile("includes.bB", {encoding:'utf8'});
var redefsout = FS.readFile("2600basic_variable_redefs.h", {encoding:'utf8'});
var includes = includesout.trim().split("\n");
var combinedasm = "";
for (var incfile of includes) {
var inctext = (incfile=="bB.asm") ? asmout : FS.readFile("/share/includes/"+incfile, {encoding:'utf8'});
console.log(incfile, inctext.length);
combinedasm += "\n\n;;;" + incfile + "\n\n";
combinedasm += inctext;
}
// TODO: ; bB.asm file is split here
putWorkFile(destpath, combinedasm);
putWorkFile("2600basic.h", FS.readFile("/share/includes/2600basic.h"));
putWorkFile("2600basic_variable_redefs.h", redefsout);
}
return {
nexttool:"dasm",
path:destpath,
args:[destpath],
files:[destpath, "2600basic.h", "2600basic_variable_redefs.h"]
};
}
////////////////////////////
@ -1505,6 +1576,7 @@ var TOOLS = {
//'caspr': compileCASPR,
'jsasm': compileJSASMStep,
'zmac': assembleZMAC,
'bataribasic': compileBatariBasic,
}
var TOOL_PRELOADFS = {
@ -1519,6 +1591,7 @@ var TOOL_PRELOADFS = {
'sdasz80': 'sdcc',
'sdcc': 'sdcc',
'sccz80': 'sccz80',
'bataribasic': '2600basic',
}
function applyDefaultErrorPath(errors:WorkerError[], path:string) {
@ -1582,7 +1655,7 @@ function executeBuildSteps() {
var asmstep = {
tool:step.result.nexttool,
platform:platform,
files:[step.result.path],
files:step.result.files,
path:step.result.path,
args:step.result.args
};