-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzarck.html
158 lines (127 loc) · 3.59 KB
/
zarck.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<html>
<head>
<style>
@font-face {
font-family: "MorePerfectDOSVGA";
src: url("MorePerfectDOSVGA.woff2") format("woff2");
font-weight: normal;
font-style: normal;
}
.term
{
white-space: pre;
}
body, input, span
{
background: #222;
color: #AAA;
font-family: 'MorePerfectDOSVGA';
font-size: 2.15vw;
display: inline-block;
padding: 0 10px;
border: none;
}
.input
{
border-right: 1vw solid transparent;
outline: none;
padding: 0;
caret-color: transparent;
}
.input:focus
{
animation: PulseAttention 1.5s cubic-bezier(.215, .61, .355, 1) forwards infinite;
}
@keyframes PulseAttention {
50% {
border-color: currentColor;
}
}
</style>
</head>
<body>
<!--
source ~/Projects/emsdk/emsdk_env.sh
emcc -o zarck.html vanalles.c world.c main.c -O3 -s WASM=1 --shell-file template.html -s NO_EXIT_RUNTIME=1 -s "EXTRA_EXPORTED_RUNTIME_METHODS=['ccall']" --emrun
emrun zarck.html
-->
<script async type="text/javascript" src="zarck.js"></script>
<script>
var Module = { "print": ( d ) =>
{
document.querySelector(".term").innerHTML += d + "<br>";
document.querySelector( ".input" ).scrollIntoView();
}
};
var mudata = new Int32Array( 7 );
//var id = Math.random() * (2**30) | 0;
var message = null;
window.addEventListener( "click", ()=>
{
document.querySelector( ".input" ).focus();
document.querySelector( ".input" ).click();
} );
window.addEventListener( "load", ( e ) =>
{
var input = document.querySelector( ".input" );
input.focus();
input.click();
// set initial mudata
setTimeout( ( e ) =>
{
try
{
var ptr = Module.ccall( "mudata", "array", [ "array", "int" ], [ mudata, mudata.length ] ) / mudata.BYTES_PER_ELEMENT;
mudata = HEAPU32.subarray( ptr, ptr + mudata.length );
// Set request timer
setInterval( ( e ) =>
{
var postData = Array.from( mudata );
if ( message )
{
postData.push( message );
message = null;
}
var data = new URLSearchParams();
data.append( "json", JSON.stringify( postData ) );
fetch( "mudata.php", {
method: 'POST',
headers: { "Content-Type": "application/x-www-form-urlencoded" },
body: data
} ).then( _response =>
{
return _response.json();
} ).then( _data =>
{
_data.forEach( (s) => Module.print(s) );
} );
}, 1500 )
}
catch ( _e )
{
console.log( "no mudata" )
}
}, 500 );
input.addEventListener( "keypress", ( e ) =>
{
if ( e.key === "Enter" )
{
document.querySelector(".term").innerHTML += input.textContent + "<br>"
Module.ccall( "command", null, ["string"], [input.textContent] );
// update mudata
var ptr = Module.ccall( "mudata", "array", [ "array", "int" ], [ mudata, mudata.length ] ) / mudata.BYTES_PER_ELEMENT;
mudata = HEAPU32.subarray( ptr, ptr + mudata.length )
if ( input.textContent.toUpperCase().startsWith( "SAY " ) )
message = input.textContent.substr( 4 );
input.textContent = "";
e.preventDefault();
}
} );
} );
</script>
<div class="term">
C:\ZARCK>zarck.exe<br><br>
</div>
<span class="input" contenteditable="true" tabindex="0"></span>
</body>
</html>