asm80
Version:
ASM80 stand-alone assembler
12 lines • 2.05 kB
JavaScript
var ASM=require("./asm.js");var Parser=require("./parser.js");var Monolith=require("./monolith.js");var path=require("path");var fs=require("fs");var LFS=require("./lfsnode.js");
var program=require("commander");program.version("1.0.0").usage("[options] <file>").option("-o, --output <file>","Output file name").option("-t, --type <type>","Output type [hex]").option("-n, --nolist","Suppress listing").option("-m, --machine <type>","Processor type (see below)").on("--help",function(){console.log(" Machine types:");
console.log("");for(var a in Monolith){console.log(" - "+a);}console.log("");}).parse(process.argv);if(!program.args.length){program.help();}var asmType=function(b){var a=path.extname(b).toUpperCase();
if(a===".A80"){return"I8080";}if(a===".A68"){return"M6800";}if(a===".A18"){return"CDP1802";}if(a===".A09"){return"M6809";}if(a===".A65"){return"C6502";
}if(a===".816"){return"C65816";}if(a===".Z80"){return"Z80";}return"unknown";};var fn=path.resolve(__dirname,program.args[program.args.length-1]);var asmtype=(asmType(fn));
var data=LFS.load(program.args[program.args.length-1]);if(program.machine){asmtype=program.machine.toUpperCase();}switch(asmtype){case"I8080":vxx=ASM.compile(data,Monolith.I8080);
break;case"C6502":vxx=ASM.compile(data,Monolith.C6502);break;case"C65816":vxx=ASM.compile(data,Monolith.C65816);break;case"Z80":vxx=ASM.compile(data,Monolith.Z80);
break;case"M6800":vxx=ASM.compile(data,Monolith.M6800);break;case"CDP1802":vxx=ASM.compile(data,Monolith.CDP1802);break;case"M6809":vxx=ASM.compile(data,Monolith.M6809);
break;default:console.log("Unrecognized ASM type");process.exit(-1);}if(vxx[0]){console.log(vxx[0].msg+"\nLine: "+vxx[0].s.numline);process.exit(-1);}var npath=path.parse(fn);
npath.ext=".hex";delete (npath.base);var vx=vxx[1];var hex=ASM.hex(vx[0]);if(program.output){npath.base=program.output;}LFS.save(path.format(npath),hex);
if(!program.nolist){var lpath=path.parse(path.format(npath));lpath.ext=".lst";delete (lpath.base);var lst=ASM.lst(vx[0],vx[1]);LFS.save(path.format(lpath),lst);
}