rubyboy 1.4.1 → 1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/docs/worker.js +7 -34
- data/lib/executor.rb +2 -2
- data/lib/rubyboy/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f272f80eda6bc8a180619d01183ddeecc4b8f288b1e182983bee8b4ddaec51c
|
4
|
+
data.tar.gz: c05b9f8e41193fb6c21c928e6bd4b2c4dc1de8d2f5264203cbe9d36be1fc9ede
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d33f763fc53d97c0cbc572ceb85f8f5eae609f1dde6fdade9da8a736461cb7e43ffa7131506a748cee86b046e6e2adc930a8d3877a1f15693d21c8f4b8b2e58
|
7
|
+
data.tar.gz: 55e3f162ba70d59c89ad1a2399c20011dc51af7fb22afeb121317ef94bee0c745492fa10c073dc545bb85d1b443af2c52295a93711ffc73124890f1b9cf69e3e
|
data/CHANGELOG.md
CHANGED
data/docs/worker.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import {
|
2
|
-
import {
|
1
|
+
import { DefaultRubyVM } from 'https://cdn.jsdelivr.net/npm/@ruby/wasm-wasi@2.7.0/dist/browser/+esm';
|
2
|
+
import { File } from 'https://cdn.jsdelivr.net/npm/@bjorn3/browser_wasi_shim@0.3.0/+esm';
|
3
3
|
|
4
4
|
const DIRECTION_KEY_MASKS = {
|
5
5
|
'KeyD': 0b0001, // Right
|
@@ -19,20 +19,6 @@ class Rubyboy {
|
|
19
19
|
constructor() {
|
20
20
|
this.wasmUrl = 'https://proxy.sacckey.dev/rubyboy.wasm';
|
21
21
|
|
22
|
-
const rootContents = new Map();
|
23
|
-
rootContents.set('RUBYBOY_TMP', new Directory(new Map()));
|
24
|
-
this.rootFs = rootContents;
|
25
|
-
|
26
|
-
const args = ['ruby.wasm', '-e_=0'];
|
27
|
-
this.wasi = new WASI(args, [], [
|
28
|
-
new OpenFile(new File([])), // stdin
|
29
|
-
new OpenFile(new File([])), // stdout
|
30
|
-
new OpenFile(new File([])), // stderr
|
31
|
-
new PreopenDirectory('/', rootContents)
|
32
|
-
], {
|
33
|
-
debug: false
|
34
|
-
});
|
35
|
-
|
36
22
|
this.directionKey = 0b1111;
|
37
23
|
this.actionKey = 0b1111;
|
38
24
|
}
|
@@ -43,18 +29,8 @@ class Rubyboy {
|
|
43
29
|
response = await fetch(this.wasmUrl);
|
44
30
|
}
|
45
31
|
|
46
|
-
const
|
47
|
-
const
|
48
|
-
wasi_snapshot_preview1: this.wasi.wasiImport,
|
49
|
-
};
|
50
|
-
const vm = new RubyVM();
|
51
|
-
vm.addToImports(imports);
|
52
|
-
|
53
|
-
const { instance } = await WebAssembly.instantiate(buffer, imports);
|
54
|
-
await vm.setInstance(instance);
|
55
|
-
this.wasi.initialize(instance);
|
56
|
-
vm.initialize();
|
57
|
-
|
32
|
+
const module = await WebAssembly.compileStreaming(response)
|
33
|
+
const { vm, wasi } = await DefaultRubyVM(module);
|
58
34
|
vm.eval(`
|
59
35
|
require 'js'
|
60
36
|
require_relative 'lib/executor'
|
@@ -63,15 +39,13 @@ class Rubyboy {
|
|
63
39
|
`);
|
64
40
|
|
65
41
|
this.vm = vm;
|
42
|
+
this.rootDir = wasi.fds[3].dir
|
66
43
|
}
|
67
44
|
|
68
45
|
sendPixelData() {
|
69
46
|
this.vm.eval(`$executor.exec(${this.directionKey}, ${this.actionKey})`);
|
70
47
|
|
71
|
-
const
|
72
|
-
const op = new OpenDirectory(tmpDir);
|
73
|
-
const result = op.path_lookup('video.data', 0);
|
74
|
-
const file = result.inode_obj;
|
48
|
+
const file = this.rootDir.contents.get('video.data');
|
75
49
|
const bytes = file.data;
|
76
50
|
|
77
51
|
postMessage({ type: 'pixelData', data: bytes.buffer }, [bytes.buffer]);
|
@@ -127,8 +101,7 @@ self.addEventListener('message', async (event) => {
|
|
127
101
|
|
128
102
|
if (event.data.type === 'loadROM') {
|
129
103
|
const romFile = new File(new Uint8Array(event.data.data));
|
130
|
-
|
131
|
-
tmpDir.contents.set('rom.data', romFile);
|
104
|
+
rubyboy.rootDir.contents.set('rom.data', romFile);
|
132
105
|
rubyboy.vm.eval(`
|
133
106
|
$executor.read_rom_from_virtual_fs
|
134
107
|
`);
|
data/lib/executor.rb
CHANGED
@@ -15,11 +15,11 @@ class Executor
|
|
15
15
|
|
16
16
|
def exec(direction_key = 0b1111, action_key = 0b1111)
|
17
17
|
bin = @emulator.step(direction_key, action_key).pack('V*')
|
18
|
-
File.binwrite(
|
18
|
+
File.binwrite('/video.data', bin)
|
19
19
|
end
|
20
20
|
|
21
21
|
def read_rom_from_virtual_fs
|
22
|
-
rom_path = '/
|
22
|
+
rom_path = '/rom.data'
|
23
23
|
raise "ROM file not found in virtual filesystem at #{rom_path}" unless File.exist?(rom_path)
|
24
24
|
|
25
25
|
rom_data = File.open(rom_path, 'rb') { |file| file.read.bytes }
|
data/lib/rubyboy/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubyboy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sacckey
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-01-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|