Skip to content

Commit 0768897

Browse files
committed
ass wasm
1 parent 0b4d256 commit 0768897

File tree

15 files changed

+5779
-1
lines changed

15 files changed

+5779
-1
lines changed

.vscode/c_cpp_properties.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "Win32",
5+
"includePath": [
6+
"${workspaceFolder}/**"
7+
],
8+
"defines": [
9+
"_DEBUG",
10+
"UNICODE",
11+
"_UNICODE"
12+
],
13+
"windowsSdkVersion": "10.0.22621.0",
14+
"compilerPath": "cl.exe",
15+
"cStandard": "c17",
16+
"cppStandard": "c++17",
17+
"intelliSenseMode": "windows-msvc-x64"
18+
}
19+
],
20+
"version": 4
21+
}

.vscode/settings.json

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"files.associations": {
3+
"xstring": "cpp",
4+
"vector": "cpp",
5+
"xutility": "cpp",
6+
"algorithm": "cpp",
7+
"atomic": "cpp",
8+
"bit": "cpp",
9+
"cctype": "cpp",
10+
"cfenv": "cpp",
11+
"charconv": "cpp",
12+
"clocale": "cpp",
13+
"cmath": "cpp",
14+
"compare": "cpp",
15+
"concepts": "cpp",
16+
"cstddef": "cpp",
17+
"cstdint": "cpp",
18+
"cstdio": "cpp",
19+
"cstdlib": "cpp",
20+
"cstring": "cpp",
21+
"ctime": "cpp",
22+
"cwchar": "cpp",
23+
"exception": "cpp",
24+
"format": "cpp",
25+
"initializer_list": "cpp",
26+
"ios": "cpp",
27+
"iosfwd": "cpp",
28+
"iostream": "cpp",
29+
"istream": "cpp",
30+
"iterator": "cpp",
31+
"limits": "cpp",
32+
"locale": "cpp",
33+
"memory": "cpp",
34+
"new": "cpp",
35+
"optional": "cpp",
36+
"ostream": "cpp",
37+
"stdexcept": "cpp",
38+
"streambuf": "cpp",
39+
"system_error": "cpp",
40+
"tuple": "cpp",
41+
"type_traits": "cpp",
42+
"typeinfo": "cpp",
43+
"utility": "cpp",
44+
"xfacet": "cpp",
45+
"xiosbase": "cpp",
46+
"xlocale": "cpp",
47+
"xlocbuf": "cpp",
48+
"xlocinfo": "cpp",
49+
"xlocmes": "cpp",
50+
"xlocmon": "cpp",
51+
"xlocnum": "cpp",
52+
"xloctime": "cpp",
53+
"xmemory": "cpp",
54+
"xtr1common": "cpp"
55+
}
56+
}

frontend/src/c/CMakeLists.txt

Whitespace-only changes.

frontend/src/c/hello.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#include <emscripten/bind.h>
2+
#include <cstdint>
3+
#include <iostream>
4+
#include <vector>
5+
#include "zlibUtil.hpp"
6+
7+
#define CHAR_TO_U32(c) (static_cast<uint32_t>(static_cast<unsigned char>(c)))
8+
#define CHAR_TO_U8(c) (static_cast<uint8_t>(c))
9+
10+
void helloWorld()
11+
{
12+
std::cout << "Hello from WASM!" << std::endl;
13+
}
14+
15+
struct ChunkDescription
16+
{
17+
uint32_t offset;
18+
uint8_t sectorCount;
19+
};
20+
21+
ChunkDescription getChunkDescription(std::string &data, uint8_t x, uint8_t y)
22+
{
23+
uint32_t off = (y * 32 + x) * 4;
24+
uint32_t offset = CHAR_TO_U32(data[off]) << 2;
25+
offset |= CHAR_TO_U32(data[off + 1]) << 1;
26+
offset |= CHAR_TO_U32(data[off + 2]);
27+
uint8_t sectorCount = CHAR_TO_U8(data[off + 3]);
28+
return {offset, sectorCount};
29+
}
30+
31+
// void readChunk(std::string &data, ChunkDescription chunkDescription)
32+
// {
33+
// uint32_t byteOffset = chunkDescription.offset * 4096;
34+
// size_t byteSize = chunkDescription.sectorCount * 4096;
35+
// std::vector<Bytef> res = decompress(reinterpret_cast<const Bytef *>(&(data.c_str()[byteOffset])), byteSize);
36+
// std::cout << res[0] << std::endl;
37+
// }
38+
39+
void read(std::string data)
40+
{
41+
// readChunk(data, getChunkDescription(data, 0, 0));
42+
for (uint8_t y = 0; y < 32; y++)
43+
{
44+
for (uint8_t x = 0; x < 32; x++)
45+
{
46+
ChunkDescription d = getChunkDescription(data, x, y);
47+
std::cout << "x: " << uint32_t(x) << " y: " << uint32_t(y) << " offset: " << d.offset << " sectors: " << uint32_t(d.sectorCount) << std::endl;
48+
}
49+
}
50+
}
51+
52+
using namespace emscripten;
53+
EMSCRIPTEN_BINDINGS(my_module)
54+
{
55+
function("helloWorld", &helloWorld);
56+
function("read", &read);
57+
}

frontend/src/c/hello.d.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// TypeScript bindings for emscripten-generated code. Automatically generated at compile time.
2+
declare namespace RuntimeExports {
3+
let HEAPF32: any;
4+
let HEAPF64: any;
5+
let HEAP_DATA_VIEW: any;
6+
let HEAP8: any;
7+
let HEAPU8: any;
8+
let HEAP16: any;
9+
let HEAPU16: any;
10+
let HEAP32: any;
11+
let HEAPU32: any;
12+
let HEAP64: any;
13+
let HEAPU64: any;
14+
}
15+
interface WasmModule {
16+
}
17+
18+
type EmbindString = ArrayBuffer|Uint8Array|Uint8ClampedArray|Int8Array|string;
19+
interface EmbindModule {
20+
helloWorld(): void;
21+
read(_0: EmbindString): void;
22+
}
23+
24+
export type MainModule = WasmModule & typeof RuntimeExports & EmbindModule;
25+
export default function MainModuleFactory (options?: unknown): Promise<MainModule>;

0 commit comments

Comments
 (0)