Skip to content

Commit

Permalink
Add support for compiler flags (#36)
Browse files Browse the repository at this point in the history
Co-authored-by: Antonio Vivace <[email protected]>
  • Loading branch information
SelvinPL and avivace authored Sep 17, 2024
1 parent a06495a commit a77fbe3
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 4 deletions.
22 changes: 22 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
>Store data between sessions</label
>
</li>
<li id="settingsmenu">Settings...</li>
</ul>
</li>
<li>
Expand Down Expand Up @@ -399,6 +400,27 @@
</div>
</div>
</div>

<div id="settingsdialog" class="modal">
<div class="content">
<span id="settingsdialogclose" class="close"></span>
<div class="tabs">
<input
type="radio"
name="settings_mode"
id="settings_mode_compiler"
checked
/><label for="settings_mode_compiler">Compiler</label>
<div>
<p>Additional options for</p>
<p>RGBASM: <input id="copmpiler_settings_asm" /></p>
<p>RGBLINK: <input id="copmpiler_settings_link" /></p>
<p>RGBFIX: <input id="copmpiler_settings_fix" /></p>
<p><button id="copmpiler_settings_set">Set</button></p>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
20 changes: 16 additions & 4 deletions js/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ var log_callback;
var error_list = [];
var rom_symbols = [];
var ram_symbols = [];
var asm_options = [];
var fix_options = [];
var link_options = [];

var line_nr_regex = /([\w\.]+)[\w\.\:~]*\(([0-9]+)\)/gi;
Expand Down Expand Up @@ -79,10 +81,18 @@ export function getRamSymbols() {
return ram_symbols;
}

export function setAsmOptions(options) {
asm_options = options;
}

export function setLinkOptions(options) {
link_options = options;
}

export function setFixOptions(options) {
fix_options = options;
}

function trigger() {
if (typeof start_delay_timer != "undefined") clearTimeout(start_delay_timer);
start_delay_timer = setTimeout(startCompile, 500);
Expand All @@ -102,9 +112,10 @@ function startCompile() {

function runRgbAsm(targets, obj_files) {
var target = targets.pop();
logFunction("Running: rgbasm " + target + " -o " + target + ".o -Wall");
var args = [target, "-o", "output.o", "-Wall"].concat(asm_options);
logFunction("Running: rgbasm " + args.join(" "));
createRgbAsm({
arguments: [target, "-o", "output.o", "-Wall"],
arguments: args,
preRun: function (m) {
var FS = m.FS;
for (const [key, value] of Object.entries(storage.getFiles())) {
Expand Down Expand Up @@ -169,9 +180,10 @@ function runRgbLink(obj_files) {
}

function runRgbFix(input_rom_file, map_file) {
logFunction("Running: rgbfix -v output.gb -p 0xff");
var args = ["-v", "output.gb", "-p", "0xff"].concat(fix_options);
logFunction("Running: rgbfix " + args.join(" "));
createRgbFix({
arguments: ["-v", "output.gb", "-p", "0xff"],
arguments: args,
preRun: function (m) {
var FS = m.FS;
FS.writeFile("output.gb", input_rom_file);
Expand Down
66 changes: 66 additions & 0 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,24 @@ function deleteFile(name) {
export function init(event) {
textEditor.register("textEditorDiv", compileCode);
gfxEditor.register("gfxEditorDiv");

var urlParams = new URLSearchParams(window.location.search);
const asmOptions = (urlParams.get('asm') ?? '').trim();
if(asmOptions != '') {
document.getElementById("copmpiler_settings_asm").value = asmOptions;
compiler.setAsmOptions(asmOptions.split(' '));
}
const linkOptions = (urlParams.get('link') ?? '').trim();
if(linkOptions != '') {
document.getElementById("copmpiler_settings_link").value = linkOptions;
compiler.setLinkOptions(linkOptions.split(' '));
}
const fixOptions =(urlParams.get('fix') ?? '').trim();
if(fixOptions != '') {
document.getElementById("copmpiler_settings_fix").value = fixOptions;
compiler.setFixOptions(fixOptions.split(' '));
}

storage.autoLoad();
editors.setCurrentFile(Object.keys(storage.getFiles()).pop());
updateFileList();
Expand Down Expand Up @@ -615,4 +633,52 @@ export function init(event) {
).checked;
storage.update();
};

document.getElementById("settingsmenu").onclick = function () {
document.getElementById("settingsdialog").style.display = "block";
};
document.getElementById("settingsdialog").onclick = function (e) {
if (e.target == document.getElementById("settingsdialog"))
document.getElementById("settingsdialog").style.display = "none";
};
document.getElementById("settingsdialogclose").onclick = function () {
document.getElementById("settingsdialog").style.display = "none";
};
document.getElementById("copmpiler_settings_set").onclick =
function () {
urlParams = new URLSearchParams(window.location.search);
var asmOptions = document.getElementById("copmpiler_settings_asm").value.trim();
if(asmOptions != '') {
urlParams.set('asm', asmOptions);
compiler.setAsmOptions(asmOptions.split(' '));
} else {
compiler.setAsmOptions([]);
urlParams.delete('asm');
}
var linkOptions = document.getElementById("copmpiler_settings_link").value.trim();
if(linkOptions != '') {
urlParams.set('link', linkOptions);
compiler.setLinkOptions(linkOptions.split(' '));
} else {
compiler.setLinkOptions([]);
urlParams.delete('link');
}
var fixOptions = document.getElementById("copmpiler_settings_fix").value.trim();
if(fixOptions != '') {
urlParams.set('fix', fixOptions);
compiler.setFixOptions(fixOptions.split(' '));
} else {
urlParams.delete('fix');
compiler.setFixOptions([]);
}
var url = new URL(window.location);
url.search = urlParams.toString();
window.history.replaceState({}, '', url);
document.getElementById("settingsdialog").style.display = "none";
compileCode();
};
if(urlParams.has('autorun')) {
document.getElementById("cpu_run_check").checked = true;
document.getElementById("cpu_run_check").onclick();
}
}

0 comments on commit a77fbe3

Please sign in to comment.