rubyboy 1.4.1 → 1.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f029df58812310dc308546c77d25e75496e0e7b0aff605a5d0826deba85d9014
4
- data.tar.gz: c2fffa4e8f4535ae4fad4bdf3c5742f569443fffc925ee02fa06f6b268f5e2c4
3
+ metadata.gz: 8f272f80eda6bc8a180619d01183ddeecc4b8f288b1e182983bee8b4ddaec51c
4
+ data.tar.gz: c05b9f8e41193fb6c21c928e6bd4b2c4dc1de8d2f5264203cbe9d36be1fc9ede
5
5
  SHA512:
6
- metadata.gz: c7f5d75b7ae8ec29488242943aca521b013875c896c8b368622f02408f52803b01e94b548b720fb4bad1ffca30d4223cfbf15ab2e8bd04b89799dc2a41bcf164
7
- data.tar.gz: b21b63a6c19263c3a72aa9b592505358dc55f450b0fd9fd3c8fb8b907d2057c07b2dae41dc9c0fa1be2fcd4e77010d4dcaf8ca7eafab908f27f7b5d903596a69
6
+ metadata.gz: 5d33f763fc53d97c0cbc572ceb85f8f5eae609f1dde6fdade9da8a736461cb7e43ffa7131506a748cee86b046e6e2adc930a8d3877a1f15693d21c8f4b8b2e58
7
+ data.tar.gz: 55e3f162ba70d59c89ad1a2399c20011dc51af7fb22afeb121317ef94bee0c745492fa10c073dc545bb85d1b443af2c52295a93711ffc73124890f1b9cf69e3e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [1.4.2] - 2025-01-11
4
+
5
+ - Use DefaultRubyVM
6
+ - Bump ruby.wasm version to 2.7.0
7
+
3
8
  ## [1.4.1] - 2024-12-25
4
9
 
5
10
  - PPU performance optimization through data caching and pixel format changes
data/docs/worker.js CHANGED
@@ -1,5 +1,5 @@
1
- import { RubyVM } from 'https://cdn.jsdelivr.net/npm/@ruby/wasm-wasi@2.6.2/+esm';
2
- import { Directory, File, OpenDirectory, OpenFile, PreopenDirectory, WASI } from 'https://cdn.jsdelivr.net/npm/@bjorn3/browser_wasi_shim@0.3.0/+esm';
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 buffer = await response.arrayBuffer();
47
- const imports = {
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 tmpDir = this.rootFs.get('RUBYBOY_TMP');
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
- const tmpDir = rubyboy.rootFs.get('RUBYBOY_TMP');
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(File.join('/RUBYBOY_TMP', 'video.data'), bin)
18
+ File.binwrite('/video.data', bin)
19
19
  end
20
20
 
21
21
  def read_rom_from_virtual_fs
22
- rom_path = '/RUBYBOY_TMP/rom.data'
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 }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rubyboy
4
- VERSION = '1.4.1'
4
+ VERSION = '1.4.2'
5
5
  end
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.1
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: 2024-12-25 00:00:00.000000000 Z
11
+ date: 2025-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi