index.html 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  6. <meta name="description" content="pico-8, tic-80, cartridge, converter">
  7. <meta name="author" content="bzt">
  8. <!-- o
  9. o hi, hacker!
  10. ooo -->
  11. <title>PICO-8 to TIC-80 cartridge converter</title>
  12. <style>
  13. input { width:100%; }
  14. small { opacity:50%; }
  15. a[download] { display:none; }
  16. #jserr { color:white; background:red; font-weight:bold; font-size: 150%; text-align:center; padding: 32px; }
  17. </style>
  18. </head>
  19. <body>
  20. <h1>PICO-8 to TIC-80 cartridge converter</h1>
  21. <div id="jserr">Please enable JavaScript</div>
  22. <script>document.getElementById("jserr").style.display = "none";</script>
  23. <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
  24. feature complete, therefore it is able to convert assets, PICO-8 codepage, most of the <b>Lua syntax</b> (like <tt>+=</tt> and
  25. <tt>!=</tt> operators for example) and <b>API calls</b> too (what's not converted directly, provided via
  26. <a href="https://github.com/musurca/pico2tic" target="new">musurca's wrapper</a> library).
  27. Check out the converter's <a href="https://gitlab.com/bztsrc/p8totic">source</a>.
  28. Contributions and improvements are always welcome!</p>
  29. <input type="file" id="input" onchange="getfile()"><br>
  30. <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>
  31. If the input is a <samp>.tic</samp> file, then the output is <samp>.tic.png</samp> cartridge.</small>
  32. <script src="p8totic.js"></script>
  33. <script>
  34. function getfile() {
  35. var input=document.getElementById("input");
  36. if(input.files.length<1) {
  37. alert("No file given.");
  38. } else {
  39. var reader = new FileReader();
  40. reader.onloadend = function() {
  41. var p8data = new Uint8Array(reader.result), tic, fn;
  42. try { fn = input.files[0].name.split("/").pop().replace(".png", "").replace(".p8", "").replace(".tic", "") + ".tic"; }catch(e) { fn = "converted.tic"; }
  43. try { tic = input.files[0].name.split("/").pop().match(/\.tic$/); }catch(e){ tic = null; }
  44. if(tic != null) {
  45. /* if input is .tic, generate a .png */
  46. var func = Module.cwrap("tictopng", "number", [ "number", "number", "number", "number" ]);
  47. fn += ".png";
  48. } else {
  49. /* for every other type of input, generate .tic */
  50. var func = Module.cwrap("p8totic", "number", [ "number", "number", "number", "number" ]);
  51. }
  52. /* do the thing */
  53. const buf = Module._malloc(1024*1024);
  54. const p8 = Module._malloc(p8data.length+1);
  55. Module.HEAPU8.set(p8data, p8);
  56. var len = func(p8, p8data.length, buf, 1024*1024);
  57. if(len > 0) {
  58. const view = new Uint8Array(Module.HEAPU8.buffer,buf,len);
  59. var blob = new Blob([view], { type: "application/octet-stream" });
  60. var url = window.URL.createObjectURL(blob);
  61. var a = document.createElement("A");
  62. a.href = url;
  63. a.download = fn;
  64. document.body.appendChild(a);
  65. a.click();
  66. a.remove();
  67. window.URL.revokeObjectURL(url);
  68. } else
  69. if(len == -1)
  70. alert("Not a valid PICO-8 cartridge.");
  71. else
  72. alert("Unable to generate TIC-80 cartridge.");
  73. Module._free(buf);
  74. Module._free(p8);
  75. };
  76. reader.readAsArrayBuffer(input.files[0]);
  77. }
  78. }
  79. </script>
  80. </body>
  81. </html>