12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
- <meta name="description" content="pico-8, tic-80, cartridge, converter">
- <meta name="author" content="bzt">
- <!-- o
- o hi, hacker!
- ooo -->
- <title>PICO-8 to TIC-80 cartridge converter</title>
- <style>
- input { width:100%; }
- small { opacity:50%; }
- a[download] { display:none; }
- #jserr { color:white; background:red; font-weight:bold; font-size: 150%; text-align:center; padding: 32px; }
- </style>
- </head>
- <body>
- <h1>PICO-8 to TIC-80 cartridge converter</h1>
- <div id="jserr">Please enable JavaScript</div>
- <script>document.getElementById("jserr").style.display = "none";</script>
- <p>This is a <i>Free and Open Source</i> tool, licensed under the <i>MIT license</i> and written in ANSI C. It's aching to be
- feature complete, therefore it is able to convert assets, PICO-8 codepage, most of the <b>Lua syntax</b> (like <tt>+=</tt> and
- <tt>!=</tt> operators for example) and <b>API calls</b> too (what's not converted directly, provided via
- <a href="https://github.com/musurca/pico2tic" target="new">musurca's wrapper</a> library).
- Check out the converter's <a href="https://gitlab.com/bztsrc/p8totic">source</a>.
- Contributions and improvements are always welcome!</p>
- <input type="file" id="input" onchange="getfile()"><br>
- <small>If the input is a <samp>.p8</samp> text file or a <samp>.p8.png</samp> binary file or a <samp>.tic.png</samp>, then the output is a <samp>.tic</samp> file.<br>
- If the input is a <samp>.tic</samp> file, then the output is <samp>.tic.png</samp> cartridge.</small>
- <script src="p8totic.js"></script>
- <script>
- function getfile() {
- var input=document.getElementById("input");
- if(input.files.length<1) {
- alert("No file given.");
- } else {
- var reader = new FileReader();
- reader.onloadend = function() {
- var p8data = new Uint8Array(reader.result), tic, fn;
- try { fn = input.files[0].name.split("/").pop().replace(".png", "").replace(".p8", "").replace(".tic", "") + ".tic"; }catch(e) { fn = "converted.tic"; }
- try { tic = input.files[0].name.split("/").pop().match(/\.tic$/); }catch(e){ tic = null; }
- if(tic != null) {
- /* if input is .tic, generate a .png */
- var func = Module.cwrap("tictopng", "number", [ "number", "number", "number", "number" ]);
- fn += ".png";
- } else {
- /* for every other type of input, generate .tic */
- var func = Module.cwrap("p8totic", "number", [ "number", "number", "number", "number" ]);
- }
- /* do the thing */
- const buf = Module._malloc(1024*1024);
- const p8 = Module._malloc(p8data.length+1);
- Module.HEAPU8.set(p8data, p8);
- var len = func(p8, p8data.length, buf, 1024*1024);
- if(len > 0) {
- const view = new Uint8Array(Module.HEAPU8.buffer,buf,len);
- var blob = new Blob([view], { type: "application/octet-stream" });
- var url = window.URL.createObjectURL(blob);
- var a = document.createElement("A");
- a.href = url;
- a.download = fn;
- document.body.appendChild(a);
- a.click();
- a.remove();
- window.URL.revokeObjectURL(url);
- } else
- if(len == -1)
- alert("Not a valid PICO-8 cartridge.");
- else
- alert("Unable to generate TIC-80 cartridge.");
- Module._free(buf);
- Module._free(p8);
- };
- reader.readAsArrayBuffer(input.files[0]);
- }
- }
- </script>
- </body>
- </html>
|