fix: download binary files
This commit is contained in:
parent
553a46eb48
commit
50c6e37098
54
main.html
54
main.html
|
@ -142,7 +142,7 @@
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<a href="javascript:download()">
|
<a href="javascript:downloadnow()">
|
||||||
<span class="red-168-text">D</span>ownload
|
<span class="red-168-text">D</span>ownload
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
@ -214,7 +214,7 @@
|
||||||
<div class="tui-window tui-no-shadow" style="height:20%;width:1000px">
|
<div class="tui-window tui-no-shadow" style="height:20%;width:1000px">
|
||||||
<fieldset class="tui-fieldset" style="height:100%">
|
<fieldset class="tui-fieldset" style="height:100%">
|
||||||
<legend class="center">Results</legend>
|
<legend class="center">Results</legend>
|
||||||
<div id="result" class="" style="overflow: scroll;height:100%;width:100%"></div>
|
<div class="" style="overflow: scroll;height:100%;width:100%"><pre id="result" style="margin-top: -5px;"></pre></div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -275,7 +275,6 @@ function toSyntax(atype)
|
||||||
$("#syntax").html(" Syntax:Intel ");
|
$("#syntax").html(" Syntax:Intel ");
|
||||||
}
|
}
|
||||||
syntax=atype;
|
syntax=atype;
|
||||||
$("#result").html("");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function toResult(atype)
|
function toResult(atype)
|
||||||
|
@ -290,7 +289,7 @@ function toResult(atype)
|
||||||
else
|
else
|
||||||
$("#array").html("√");
|
$("#array").html("√");
|
||||||
type=atype;
|
type=atype;
|
||||||
$("#result").html("");
|
dumpall(zones);
|
||||||
}
|
}
|
||||||
|
|
||||||
function newfile(){
|
function newfile(){
|
||||||
|
@ -307,31 +306,19 @@ function exportfile(){
|
||||||
saveTextAsFile($("#editor").val(),file);
|
saveTextAsFile($("#editor").val(),file);
|
||||||
}
|
}
|
||||||
|
|
||||||
function download(){
|
function downloadnow(){
|
||||||
if ($("#result").val()=="")
|
|
||||||
return
|
|
||||||
if (type=="array" || type=="string")
|
if (type=="array" || type=="string")
|
||||||
|
{
|
||||||
|
if ($("#result").html()=="")
|
||||||
|
return
|
||||||
var ext=".c";
|
var ext=".c";
|
||||||
|
download($("#result").html(), filename+ext);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
var ext=".bin";
|
{
|
||||||
saveTextAsFile($("#result").val, file+ext);
|
arr=makebin(zones);
|
||||||
}
|
download(arr,filename+'.bin');
|
||||||
|
|
||||||
function saveTextAsFile(textToWrite, fileNameToSaveAs) {
|
|
||||||
var textFileAsBlob = new Blob([textToWrite], {type:'text/plain'});
|
|
||||||
var downloadLink = document.createElement("a");
|
|
||||||
downloadLink.download = fileNameToSaveAs;
|
|
||||||
downloadLink.innerHTML = "Download File";
|
|
||||||
if (window.webkitURL != null) {
|
|
||||||
downloadLink.href = window.webkitURL.createObjectURL(textFileAsBlob);
|
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
downloadLink.href = window.URL.createObjectURL(textFileAsBlob);
|
|
||||||
downloadLink.onclick = destroyClickedElement;
|
|
||||||
downloadLink.style.display = "none";
|
|
||||||
document.body.appendChild(downloadLink);
|
|
||||||
}
|
|
||||||
downloadLink.click();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function realopen(file)
|
function realopen(file)
|
||||||
|
@ -380,13 +367,21 @@ function hexByte(value) {
|
||||||
return str.slice(-2);
|
return str.slice(-2);
|
||||||
};
|
};
|
||||||
|
|
||||||
function dumpall(zones)
|
function makebin(allzones)
|
||||||
|
{
|
||||||
|
var output = [];
|
||||||
|
for (const zone of allzones)
|
||||||
|
output.push(...zone.asm);
|
||||||
|
return new Uint8Array(output);
|
||||||
|
}
|
||||||
|
|
||||||
|
function dumpall(allzones)
|
||||||
{
|
{
|
||||||
if (type=="binary")
|
if (type=="binary")
|
||||||
var output = '<table class="">';
|
var output = '<table class="">';
|
||||||
else
|
else
|
||||||
var output = '';
|
var output = '';
|
||||||
for (const zone of zones)
|
for (const zone of allzones)
|
||||||
output+=dump(zone);
|
output+=dump(zone);
|
||||||
if (type=="binary")
|
if (type=="binary")
|
||||||
output += '</table>';
|
output += '</table>';
|
||||||
|
@ -417,7 +412,7 @@ function dump(zone) {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'array':
|
case 'array':
|
||||||
output += "const uint8_t buffer[] = {\n";
|
output += "const uint8_t "+zone.title+"[] = {\n";
|
||||||
for (var offset = 0; offset < mcLen; offset += 8) {
|
for (var offset = 0; offset < mcLen; offset += 8) {
|
||||||
output += " ";
|
output += " ";
|
||||||
for (var i = offset; i < offset + 8 && i < mcLen; i++) {
|
for (var i = offset; i < offset + 8 && i < mcLen; i++) {
|
||||||
|
@ -430,7 +425,7 @@ function dump(zone) {
|
||||||
output += "\n};\n";
|
output += "\n};\n";
|
||||||
break;
|
break;
|
||||||
case 'string':
|
case 'string':
|
||||||
output += "const char* buffer =\n";
|
output += "const char* "+zone.title+" =\n";
|
||||||
for (var offset = 0; offset < mcLen; offset += 16) {
|
for (var offset = 0; offset < mcLen; offset += 16) {
|
||||||
output += " \"";
|
output += " \"";
|
||||||
for (var i = offset; i < offset + 16 && i < mcLen; i++) {
|
for (var i = offset; i < offset + 16 && i < mcLen; i++) {
|
||||||
|
@ -460,7 +455,6 @@ function make()
|
||||||
var id=0;
|
var id=0;
|
||||||
var org=0;
|
var org=0;
|
||||||
var type=32;
|
var type=32;
|
||||||
var zones=[];
|
|
||||||
var status=true;
|
var status=true;
|
||||||
showresult('');
|
showresult('');
|
||||||
while (assembly.length!=0)
|
while (assembly.length!=0)
|
||||||
|
|
Loading…
Reference in New Issue