fix: download binary files

This commit is contained in:
root 2022-08-16 02:07:50 +02:00
parent 553a46eb48
commit 50c6e37098
1 changed files with 27 additions and 33 deletions

View File

@ -142,7 +142,7 @@
</a>
</li>
<li>
<a href="javascript:download()">
<a href="javascript:downloadnow()">
<span class="red-168-text">D</span>ownload
</a>
</li>
@ -214,7 +214,7 @@
<div class="tui-window tui-no-shadow" style="height:20%;width:1000px">
<fieldset class="tui-fieldset" style="height:100%">
<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>
</div>
@ -275,7 +275,6 @@ function toSyntax(atype)
$("#syntax").html("&nbsp;Syntax:Intel&nbsp;");
}
syntax=atype;
$("#result").html("");
}
function toResult(atype)
@ -290,7 +289,7 @@ function toResult(atype)
else
$("#array").html("√");
type=atype;
$("#result").html("");
dumpall(zones);
}
function newfile(){
@ -307,31 +306,19 @@ function exportfile(){
saveTextAsFile($("#editor").val(),file);
}
function download(){
if ($("#result").val()=="")
return
function downloadnow(){
if (type=="array" || type=="string")
{
if ($("#result").html()=="")
return
var ext=".c";
download($("#result").html(), filename+ext);
}
else
var ext=".bin";
saveTextAsFile($("#result").val, file+ext);
}
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();
{
arr=makebin(zones);
download(arr,filename+'.bin');
}
}
function realopen(file)
@ -380,13 +367,21 @@ function hexByte(value) {
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")
var output = '<table class="">';
else
var output = '';
for (const zone of zones)
for (const zone of allzones)
output+=dump(zone);
if (type=="binary")
output += '</table>';
@ -417,7 +412,7 @@ function dump(zone) {
}
break;
case 'array':
output += "const uint8_t buffer[] = {\n";
output += "const uint8_t "+zone.title+"[] = {\n";
for (var offset = 0; offset < mcLen; offset += 8) {
output += " ";
for (var i = offset; i < offset + 8 && i < mcLen; i++) {
@ -427,10 +422,10 @@ function dump(zone) {
output += "\n";
}
output = output.substring(0, output.length - 2);
output += "\n};\n";
output += "\n};\n";
break;
case 'string':
output += "const char* buffer =\n";
output += "const char* "+zone.title+" =\n";
for (var offset = 0; offset < mcLen; offset += 16) {
output += " \"";
for (var i = offset; i < offset + 16 && i < mcLen; i++) {
@ -439,7 +434,7 @@ function dump(zone) {
output += "\"\n";
}
output = output.substring(0, output.length - 1);
output += ";\n";
output += ";\n";
break;
}
return output;
@ -460,7 +455,6 @@ function make()
var id=0;
var org=0;
var type=32;
var zones=[];
var status=true;
showresult('');
while (assembly.length!=0)