-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfc64.min.js
1 lines (1 loc) · 16.6 KB
/
fc64.min.js
1
!function(e){"use strict";let s,t;function r(){t.frequency.value=0}function n(){s.resume()}const i=1,o=2,d=4,u=[];const a=64,c=64,l=[{id:"U",index:12,physicalButtonPressed:!1,pressedPrevious:!1,pressedCurrent:!1,isPressed:!1,isJustPressed:!1,isJustReleased:!1},{id:"D",index:13,physicalButtonPressed:!1,pressedPrevious:!1,pressedCurrent:!1,isPressed:!1,isJustPressed:!1,isJustReleased:!1},{id:"L",index:14,physicalButtonPressed:!1,pressedPrevious:!1,pressedCurrent:!1,isPressed:!1,isJustPressed:!1,isJustReleased:!1},{id:"R",index:15,physicalButtonPressed:!1,pressedPrevious:!1,pressedCurrent:!1,isPressed:!1,isJustPressed:!1,isJustReleased:!1},{id:"A",index:0,physicalButtonPressed:!1,pressedPrevious:!1,pressedCurrent:!1,isPressed:!1,isJustPressed:!1,isJustReleased:!1},{id:"B",index:1,physicalButtonPressed:!1,pressedPrevious:!1,pressedCurrent:!1,isPressed:!1,isJustPressed:!1,isJustReleased:!1}];const h=()=>{for(const e of l)e.physicalButtonPressed=!1},A=(e,s)=>s>e.buttons.length-1?null:e.buttons[s],f=[{id:"U",x:13,y:78,width:9,height:9,pressedPrevious:!1,pressedCurrent:!1,isPressed:!1,isJustPressed:!1,isJustReleased:!1},{id:"D",x:13,y:98,width:9,height:9,pressedPrevious:!1,pressedCurrent:!1,isPressed:!1,isJustPressed:!1,isJustReleased:!1},{id:"L",x:3,y:88,width:9,height:9,pressedPrevious:!1,pressedCurrent:!1,isPressed:!1,isJustPressed:!1,isJustReleased:!1},{id:"R",x:23,y:88,width:9,height:9,pressedPrevious:!1,pressedCurrent:!1,isPressed:!1,isJustPressed:!1,isJustReleased:!1},{id:"A",x:42,y:88,width:12,height:12,pressedPrevious:!1,pressedCurrent:!1,isPressed:!1,isJustPressed:!1,isJustReleased:!1},{id:"B",x:57,y:79,width:12,height:12,pressedPrevious:!1,pressedCurrent:!1,isPressed:!1,isJustPressed:!1,isJustReleased:!1}];let p,g,w;const P=new Map;const y=(e,s)=>!![...e.values()].includes(s),m=e=>B(e.pageX,e.pageY,-1),v=e=>E(e.pageX,e.pageY,-1),C=e=>M(e.pageX,e.pageY,-1),R=e=>{for(const s of e.changedTouches)B(s.pageX,s.pageY,s.identifier)},x=e=>{e.preventDefault();for(const s of e.changedTouches)E(s.pageX,s.pageY,s.identifier)},J=e=>{e.preventDefault();for(const s of e.changedTouches)M(s.pageX,s.pageY,s.identifier)},B=(e,s,t)=>{const r=b(e,s),n=D(r.x,r.y);null==n?P.set(`${t}`,"-"):P.set(`${t}`,n.id)},E=(e,s,t)=>{if(P.get(`${t}`)){const r=b(e,s),n=D(r.x,r.y);null==n?P.set(`${t}`,"-"):P.set(`${t}`,n.id)}},M=(e,s,t)=>P.delete(`${t}`),b=(e,s)=>{if(null!=screen)return{x:Math.round(((e-p.offsetLeft)/p.clientWidth+.5)*g),y:Math.round(((s-p.offsetTop)/p.clientHeight+.5)*w)}},D=(e,s)=>{for(let t=0;t<f.length;t++){const r=f[t];if(e>=r.x&&e<=r.x+r.width&&s>=r.y&&s<=r.y+r.height)return r}return null},L=[{id:"U",codes:["ArrowUp","KeyW"],physicalKeyDown:!1,pressedPrevious:!1,pressedCurrent:!1,isPressed:!1,isJustPressed:!1,isJustReleased:!1},{id:"D",codes:["ArrowDown","KeyS"],physicalKeyDown:!1,pressedPrevious:!1,pressedCurrent:!1,isPressed:!1,isJustPressed:!1,isJustReleased:!1},{id:"L",codes:["ArrowLeft","KeyA"],physicalKeyDown:!1,pressedPrevious:!1,pressedCurrent:!1,isPressed:!1,isJustPressed:!1,isJustReleased:!1},{id:"R",codes:["ArrowRight","KeyD"],physicalKeyDown:!1,pressedPrevious:!1,pressedCurrent:!1,isPressed:!1,isJustPressed:!1,isJustReleased:!1},{id:"A",codes:["KeyZ","Period"],physicalKeyDown:!1,pressedPrevious:!1,pressedCurrent:!1,isPressed:!1,isJustPressed:!1,isJustReleased:!1},{id:"B",codes:["KeyX","Slash"],physicalKeyDown:!1,pressedPrevious:!1,pressedCurrent:!1,isPressed:!1,isJustPressed:!1,isJustReleased:!1}];const S=e=>{"F1"!==e.code&&"F3"!==e.code&&"F6"!==e.code&&"F7"!==e.code&&"Tab"!==e.code&&"AltLeft"!==e.code&&"AltRight"!==e.code&&"ArrowRight"!==e.code&&"ArrowDown"!==e.code&&"ArrowLeft"!==e.code&&"ArrowUp"!==e.code||e.preventDefault();const s=T(e.code);null!=s&&(s.physicalKeyDown=!0)},U=e=>{const s=T(e.code);null!=s&&(s.physicalKeyDown=!1)},T=e=>{for(let s=0;s<L.length;s++){const t=L[s];if(t.codes.includes(e))return t}return null},K=0,I=4096,F=4102,k=4104,O=4104,Y=[];function N(e){if(e<0||e>O)throw`Invalid address: peek ${e}`;return Y[e]}function _(e,s){if(e<0||e>O)throw`Invalid address: poke ${e}`;Y[e]=s}const X={charWidth:3,charHeight:5,charTrackingDefault:1,charMap:[[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,1,0,0,1,0,0,1,0,0,0,0,0,1,0],[1,0,1,1,0,1,0,0,0,0,0,0,0,0,0],[1,0,1,1,1,1,1,0,1,1,1,1,1,0,1],[0,1,0,1,1,1,1,0,0,1,1,1,0,1,0],[1,0,1,0,0,1,0,1,0,1,0,0,1,0,1],[1,1,0,1,1,0,1,1,1,1,0,1,0,1,1],[0,1,0,0,1,0,0,0,0,0,0,0,0,0,0],[0,0,1,0,1,0,0,1,0,0,1,0,0,0,1],[1,0,0,0,1,0,0,1,0,0,1,0,1,0,0],[0,0,0,1,0,1,0,1,0,1,0,1,0,0,0],[0,0,0,0,1,0,1,1,1,0,1,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,1,0,1,0,0],[0,0,0,0,0,0,1,1,1,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,1,0],[0,0,1,0,0,1,0,1,0,1,0,0,1,0,0],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,0,0,0,0,0,1,1,1,1,0,0,1,0,0],[0,0,0,0,0,0,0,1,1,0,1,0,1,1,0],[0,0,0,0,1,0,1,1,1,0,1,0,0,1,1],[0,0,0,0,0,0,1,0,1,1,0,1,1,1,1],[0,0,0,0,0,0,1,0,1,1,0,1,0,1,0],[0,0,0,0,0,0,1,0,1,1,1,1,1,1,1],[0,0,0,0,0,0,1,0,1,0,1,0,1,0,1],[0,0,0,1,0,1,1,1,1,0,0,1,1,1,0],[0,0,0,1,1,1,0,1,0,0,0,1,1,1,0],[0,1,1,0,1,0,1,0,0,0,1,0,0,1,1],[0,1,0,0,1,0,0,1,0,0,1,0,0,1,0],[1,1,0,0,1,0,0,0,1,0,1,0,1,1,0],[0,0,0,0,0,0,0,1,1,1,1,0,0,0,0]]};function V(e,s,t,r,n){e===t?function(e,s,t,r){if(s>t){const e=s;s=t,t=e}for(let n=s;n<=t;n++)G(e,n,r)}(e,s,r,n):s===r?W(e,t,s,n):function(e,s,t,r,n){const i=Math.abs(t-e),o=Math.abs(r-s),d=e<t?1:-1,u=s<r?1:-1;let a=i-o;G(e,s,n),G(t,r,n);for(;e!==t||s!==r;){const t=a<<1;t>-o&&(a-=o,e+=d),t<i&&(a+=i,s+=u),G(e,s,n)}}(e,s,t,r,n)}function W(e,s,t,r){if(e>s){const t=e;e=s,s=t}for(let n=e;n<=s;n++)G(n,t,r)}function G(e,s,t){e<0||e>=a||s<0||s>=c||_(K+(0|e)+(0|s)*a,t)}function Q(e,s,t,r,n){const i=s.charMap[e.charCodeAt(0)-32];for(let e=0;e<s.charWidth;e++)for(let o=0;o<s.charHeight;o++)1===i[e+o*s.charWidth]&&G(t+e,r+o,n)}let j,$,H,z;const q=[60,60,60,60,60],Z=72,ee=128,se=4,te=4;function re(e){const s=e-z;if(Math.ceil(s)>1e3/60){q.shift(),q.push(Math.round(1e3/s));const n=Math.round(q.reduce(((e,s)=>e+s))/q.length);z=e,_(k,n),function(){for(const e of L)e.pressedPrevious=e.pressedCurrent,e.pressedCurrent=e.physicalKeyDown,e.isPressed=e.pressedCurrent,e.isJustPressed=e.pressedCurrent&&!e.pressedPrevious,e.isJustReleased=!e.pressedCurrent&&e.pressedPrevious}(),function(){const e=navigator.getGamepads()[0];if(e)for(const s of l){const t=A(e,s.index);null!=t&&(t.pressed?s.physicalButtonPressed=!0:s.physicalButtonPressed=!1)}for(const e of l)e.pressedPrevious=e.pressedCurrent,e.pressedCurrent=e.physicalButtonPressed,e.isPressed=e.pressedCurrent,e.isJustPressed=e.pressedCurrent&&!e.pressedPrevious,e.isJustReleased=!e.pressedCurrent&&e.pressedPrevious}(),function(){for(const e of f)e.pressedPrevious=e.pressedCurrent,e.pressedCurrent=y(P,e.id),e.isPressed=e.pressedCurrent,e.isJustPressed=e.pressedCurrent&&!e.pressedPrevious,e.isJustReleased=!e.pressedCurrent&&e.pressedPrevious}(),function(){for(let e=0;e<6;e++){let s=0;(L[e].isPressed||l[e].isPressed||f[e].isPressed)&&(s|=i),(L[e].isJustPressed||l[e].isJustPressed||f[e].isJustPressed)&&(s|=o),(L[e].isJustReleased||l[e].isJustReleased||f[e].isJustReleased)&&(s|=d),_(I+e,s)}}(),function(){const e=N(F),s=N(F+1);e>0&&s>0?function(e){t.frequency.value=e}(e):r(),s>0&&_(F+1,s-1)}(),romLoop(),function(){for(let e=K;e<K+a*c;e++){const s=u[N(e)];H.data[4*e+0]=s.r,H.data[4*e+1]=s.g,H.data[4*e+2]=s.b,H.data[4*e+3]=255}$.putImageData(H,se,te)}()}window.requestAnimationFrame(re)}window.addEventListener("load",(function(){(function(){Y.length=0;for(let e=0;e<=O;e++)Y.push(0)})(),s=new window.AudioContext,t=s.createOscillator(),t.type="square",t.frequency.value=0,t.connect(s.destination),t.start(0),window.addEventListener("mousedown",n),window.addEventListener("touchstart",n),window.addEventListener("keydown",n),document.addEventListener("visibilitychange",(()=>{"hidden"===document.visibilityState&&r()})),document.addEventListener("keydown",S),document.addEventListener("keyup",U),function(){const e="-webkit-touch-callout: none; -webkit-tap-highlight-color: #000; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; background: #000; color: #888;",s="position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); background: #000};",t="image-rendering: -moz-crisp-edges; image-rendering: -webkit-optimize-contrast; image-rendering: -o-crisp-edges; image-rendering: pixelated;";document.body.style.cssText=e,j=document.createElement("canvas"),j.width=Z,j.height=ee,$=j.getContext("2d",{alpha:!1}),$.imageSmoothingEnabled=!1,j.style.cssText=s+t,$.fillStyle="#ddd",$.fillRect(0,0,Z,ee),$.fillStyle="#333",$.fillRect(se-1,te-1,a+2,c+2);const r=()=>{const e=innerWidth/innerHeight,s=Z/ee,t=e<s,r=t?innerWidth:innerHeight*s,n=t?innerWidth/s:innerHeight;j.style.width=`${r}px`,j.style.height=`${n}px`};window.addEventListener("resize",r),r(),document.body.appendChild(j),H=$.createImageData(a,c)}(),window.addEventListener("gamepaddisconnected",h),function(e,s,t){p=e,g=s,w=t;const r=p.getContext("2d");r.fillRect(13,78,9,29),r.fillRect(3,88,29,9);const n=new Image;n.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABcAAAAFAQMAAACU+uVzAAAABlBMVEUAAAAzM2bT8ENbAAAAAXRSTlMAQObYZgAAABtJREFUCNdjePdKj6GjS4PhxDsgvWgRQ9+jdwBZWAlP4hlWSwAAAABJRU5ErkJggg==",n.onload=()=>{r.drawImage(n,6,71)};const i=new Image;i.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMAQMAAABsu86kAAAABlBMVEUAAACZADPodVumAAAAAXRSTlMAQObYZgAAABxJREFUCNdj4GdgsD/AUP8AhP5/gCOICFAKqAAAEwUPVSVDKX4AAAAASUVORK5CYII=",i.onload=()=>{r.drawImage(i,42,88),r.drawImage(i,57,79)};const o=new Image;o.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAAFAQMAAABYY9+YAAAABlBMVEUAAAAzM2bT8ENbAAAAAXRSTlMAQObYZgAAABFJREFUCNdjSGCYwPABiCcAAA5KAwFW2JXuAAAAAElFTkSuQmCC",o.onload=()=>{r.drawImage(o,46,101)};const d=new Image;d.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAAFAQMAAABYY9+YAAAABlBMVEUAAAAzM2bT8ENbAAAAAXRSTlMAQObYZgAAAA1JREFUCNdjeMAwAYIBEsoDwUh7niQAAAAASUVORK5CYII=",d.onload=()=>{r.drawImage(d,61,92)},document.addEventListener("mousedown",m),document.addEventListener("mousemove",v),document.addEventListener("mouseup",C),document.addEventListener("touchstart",R),document.addEventListener("touchmove",x,{passive:!1}),document.addEventListener("touchend",J,{passive:!1})}(j,Z,ee),romInit(),function(e){for(let s=0;s<=7;s++){const t=e[s],r=(16711680&t)>>16,n=(65280&t)>>8,i=255&t;u.push({r:r,g:n,b:i})}}(window.romPalette),z=performance.now(),re(z)})),window.romPalette=[0,255,16711680,16711935,65280,65535,16776960,16777215],e.ADDRESS_AUD=F,e.ADDRESS_BTN=I,e.ADDRESS_FPS=k,e.ADDRESS_GFX=K,e.Anim=class{constructor(e,s,t){this.frames=e,this.frameTicks=s,this.looping=t}getKeyFrame(e){if(1===this.frames.length)return this.frames[0];let s=Math.floor(e/this.frameTicks);return this.looping?s%=this.frames.length:s=Math.min(this.frames.length-1,s),this.frames[s]}isFinished(e){return!this.looping&&e>=this.frames.length*this.frameTicks}},e.BTN_A=4,e.BTN_B=5,e.BTN_D=1,e.BTN_L=2,e.BTN_R=3,e.BTN_U=0,e.COL_BLK=0,e.COL_BLU=1,e.COL_CYN=5,e.COL_GRN=4,e.COL_MAG=3,e.COL_RED=2,e.COL_WHT=7,e.COL_YEL=6,e.GFX_H=c,e.GFX_W=a,e.Rect=class{constructor(e,s,t,r){this.x=e,this.y=s,this.width=t,this.height=r}overlaps(e){return this.x<e.x+e.width&&this.x+this.width>e.x&&this.y<e.y+e.height&&this.y+this.height>e.y}},e.Vec2=class{constructor(e,s){this.x=e,this.y=s}set(e,s){this.x=e,this.y=s}add(e,s){this.x+=e,this.y+=s}scl(e){this.x*=e,this.y*=e}equals(e){return this.x==e.x&&this.y==e.y}},e.beep=function(e,s,t){(N(F+1)<=0||t)&&(_(F,Math.floor(e)),_(F+1,Math.floor(s)))},e.clamp=function(e,s,t){return Math.max(s,Math.min(e,t))},e.clearGfx=function(e){for(let s=K;s<K+a*c;s++)_(s,e>0?e:0)},e.drawCircle=function(e,s,t,r,n){n>=0&&function(e,s,t,r){let n=0,i=t,o=1-t;for(;n<=i;)W(e-n,e+n,s-i,r),W(e-i,e+i,s-n,r),W(e-i,e+i,s+n,r),W(e-n,e+n,s+i,r),o<0?o+=2*n+1:(o+=2*(n-i)+1,i--),n++}(e,s,t,n),function(e,s,t,r){let n=0,i=t,o=1-t;for(;n<=i;)G(e+n,s+i,r),G(e+n,s-i,r),G(e-n,s+i,r),G(e-n,s-i,r),G(e+i,s+n,r),G(e+i,s-n,r),G(e-i,s+n,r),G(e-i,s-n,r),o<0?o+=2*n+1:(o+=2*(n-i)+1,i--),n++}(e,s,t,r)},e.drawImage=function(e,s,t,r,n,i){const o=[...n];if(i){const e=[];for(;o.length;)e.push(o.splice(0,t));if(i.flipX)for(let s=0;s<r;s++)e[s].reverse();i.flipY&&e.reverse();for(let s=0;s<r;s++)for(let r=0;r<t;r++)o[s*t+r]=e[s][r]}for(let n=0;n<r;n++)for(let r=0;r<t;r++){const i=o[r+n*t];i>=0&&G(e+r,s+n,i)}},e.drawLine=V,e.drawPattern=function(e,s,t,r){if(!(t.length<1))if("number"==typeof t[0])for(let n=0;n<t.length-1;n+=2)G(e+t[n],s+t[n+1],r);else for(let n=0;n<t.length;n++)G(e+t[n].x,s+t[n].y,r)},e.drawPixel=G,e.drawPolygon=function(e,s,t){if(e.length<1)return;let r=[];if("number"==typeof e[0])for(let s=0;s<e.length-1;s+=2)r.push({x:e[s],y:e[s+1]});else r=e;t&&function(e,s,t){let r=c,n=0;for(const s of e)r=Math.min(r,s.y),n=Math.max(n,s.y);for(let s=r;s<=n;s++){let r=[];for(let t=0;t<e.length;t++){const n=e[t],i=e[(t+1)%e.length];if(n.y<s&&i.y>=s||i.y<s&&n.y>=s){const e=(s-n.y)*(i.x-n.x)/(i.y-n.y)+n.x;r.push(e)}else n.y===s&&i.y===s&&(r.push(n.x),r.push(i.x))}r=r.sort(((e,s)=>e-s));for(let n=0;n<r.length;n+=2){const i=Math.ceil(r[n]),o=Math.floor(r[n+1]);let d=!1;for(let t=0,r=e.length-1;t<e.length;r=t++){const n=e[t],o=e[r];n.y>s!=o.y>s&&i<(o.x-n.x)*(s-n.y)/(o.y-n.y)+n.x&&(d=!d)}d&&V(i,s,o,s,t)}}}(r,0,t),function(e,s){for(let t=0;t<e.length;t++){const r=e[t],n=e[(t+1)%e.length];V(r.x,r.y,n.x,n.y,s)}}(r,s)},e.drawRectangle=function(e,s,t,r,n,i){let o=0,d=0,u=0,a=0;t<0?(o=e+t+1,u=e):(o=e,u=e+t-1),r<0?(d=s+r+1,a=s):(d=s,a=s+r-1);for(let e=o;e<=u;e++)for(let s=d;s<=a;s++)e===o||e===u||s===d||s===a?G(e,s,n):i>=0&&G(e,s,i)},e.drawText=function(e,s,t,r,n){const i=(null==n?void 0:n.font)?n.font:X,o=(null==n?void 0:n.tracking)>=0?n.tracking:i.charTrackingDefault;let d=e;for(let e=0;e<t.length;e++)Q(t.charAt(e),i,d,s,r),d+=i.charWidth+o},e.fc64Init=function(e,s,t){window.romInit=e,window.romLoop=s,t&&(window.romPalette=t)},e.getFps=function(){return N(k)},e.getPixel=function(e,s){return e<0||e>=a||s<0||s>=c?-1:N(K+(0|e)+(0|s)*a)},e.imageFromB64String=function(e){const s=4*Math.ceil(e.length/4),t=e.padEnd(s,"="),r=atob(t),n=[];for(let e=0;e<r.length;e++){const s=r.charCodeAt(e),t=s>>4&15,i=15&s;n.push(15===t?-1:t,15===i?-1:i)}return n},e.imageFromHexString=function(e){const s=[];for(const t of e)"f"===t?s.push(-1):s.push(parseInt(t,16));return s},e.isEmptyObject=function(e){return 0===Object.keys(e).length&&e.constructor===Object},e.isJustPressed=function(e){return Boolean(N(I+e)&o)},e.isJustReleased=function(e){return Boolean(N(I+e)&d)},e.isPressed=function(e){return Boolean(N(I+e)&i)},e.peek=N,e.poke=_,e.randomInt=function(e,s){return Math.floor(Math.random()*(s-e+1)+e)},e.swapImageColors=function(e,s,t){if(s.length!=t.length)throw new Error("mismatched old/new list lengths");const r=[...e];for(let n=0;n<s.length;n++)for(let i=0;i<e.length;i++)e[i]===s[n]&&(r[i]=t[n]);return r},e.wrap=function(e,s,t){const r=t-s;return s+((e-s)%r+r)%r}}(window||{});