rubyboy 1.4.2 → 1.5.0

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: 8f272f80eda6bc8a180619d01183ddeecc4b8f288b1e182983bee8b4ddaec51c
4
- data.tar.gz: c05b9f8e41193fb6c21c928e6bd4b2c4dc1de8d2f5264203cbe9d36be1fc9ede
3
+ metadata.gz: f906ad2a5676ad89d614d3898dee887cf2b1b0a76c2b5ae906a7f234e806e779
4
+ data.tar.gz: d5c133d3ba340a570febc3bd4e4d67245e14a5fef408af6d0aba711a7738c503
5
5
  SHA512:
6
- metadata.gz: 5d33f763fc53d97c0cbc572ceb85f8f5eae609f1dde6fdade9da8a736461cb7e43ffa7131506a748cee86b046e6e2adc930a8d3877a1f15693d21c8f4b8b2e58
7
- data.tar.gz: 55e3f162ba70d59c89ad1a2399c20011dc51af7fb22afeb121317ef94bee0c745492fa10c073dc545bb85d1b443af2c52295a93711ffc73124890f1b9cf69e3e
6
+ metadata.gz: 66db379a951b75f717339c4030e201dbfcf79d85fec15deb2a4c0d03e6513262122411eb4149b00533eae5f18c5ed44ab23d57b0ffb2ed2c7b64076c06f1fb77
7
+ data.tar.gz: 648a015c3aeceab1b53b1ae3d20023c573c24a0fd91f3fde2c9da66ad0dd8caddfa6a2013374f96f7ab8dd7b70d510c32437cdd48cc46327f431f8ed06b00440
data/CHANGELOG.md CHANGED
@@ -1,4 +1,7 @@
1
- ## [Unreleased]
1
+ ## [1.5.0] - 2025-02-09
2
+
3
+ - Add EmulatorHeadless and use it for bench
4
+ - Bump ruby.wasm version to 2.7.1
2
5
 
3
6
  ## [1.4.2] - 2025-01-11
4
7
 
data/docs/worker.js CHANGED
@@ -1,4 +1,4 @@
1
- import { DefaultRubyVM } from 'https://cdn.jsdelivr.net/npm/@ruby/wasm-wasi@2.7.0/dist/browser/+esm';
1
+ import { DefaultRubyVM } from 'https://cdn.jsdelivr.net/npm/@ruby/wasm-wasi@2.7.1/dist/browser/+esm';
2
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 = {
data/exe/rubyboy-bench CHANGED
@@ -40,4 +40,4 @@ else
40
40
  puts 'YJIT is not available in this environment.'
41
41
  end
42
42
 
43
- Rubyboy::Bench.new.bench(**options)
43
+ Rubyboy::Bench.new.run(**options)
data/exe/rubyboy-wasm CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  case ARGV[0]
5
5
  when 'build'
6
- command = %w[build --ruby-version 3.3 -o ./docs/ruby-js.wasm]
6
+ command = %w[build --ruby-version 3.4 -o ./docs/ruby-js.wasm]
7
7
  when 'pack'
8
8
  command = %w[pack ./docs/ruby-js.wasm --dir ./lib::/lib -o ./docs/rubyboy.wasm]
9
9
  else
data/lib/bench.rb CHANGED
@@ -1,22 +1,24 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'stackprof'
4
- require_relative 'rubyboy'
3
+ require_relative 'rubyboy/emulator_headless'
5
4
 
6
5
  module Rubyboy
7
6
  class Bench
8
- def stackprof
9
- StackProf.run(mode: :cpu, out: 'stackprof-cpu-myapp.dump', raw: true) do
10
- Rubyboy::Emulator.new('lib/roms/tobu.gb').bench
11
- end
12
- end
13
-
14
- def bench(count: 3, frames: 1500, rom_path: 'lib/roms/tobu.gb')
7
+ def run(count: 3, frames: 1500, rom_path: 'lib/roms/tobu.gb')
15
8
  time_sum = 0
9
+
16
10
  count.times do |i|
17
- time = Rubyboy::Emulator.new(rom_path).bench(frames)
18
- time_sum += time
11
+ emulator = Rubyboy::EmulatorHeadless.new(rom_path)
12
+ frame_count = 0
13
+ start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC, :nanosecond)
14
+ while frame_count < frames
15
+ emulator.step
16
+ frame_count += 1
17
+ end
18
+ time = Process.clock_gettime(Process::CLOCK_MONOTONIC, :nanosecond) - start_time
19
19
  puts "#{i + 1}: #{time / 1_000_000_000.0} sec"
20
+
21
+ time_sum += time
20
22
  end
21
23
 
22
24
  puts "FPS: #{frames * count * 1_000_000_000.0 / time_sum}"
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'apu'
4
+ require_relative 'bus'
5
+ require_relative 'cpu'
6
+ require_relative 'ppu'
7
+ require_relative 'rom'
8
+ require_relative 'ram'
9
+ require_relative 'timer'
10
+ require_relative 'joypad'
11
+ require_relative 'interrupt'
12
+ require_relative 'cartridge/factory'
13
+
14
+ module Rubyboy
15
+ class EmulatorHeadless
16
+ def initialize(rom_path)
17
+ rom_data = File.open(rom_path, 'r') { _1.read.bytes }
18
+ rom = Rom.new(rom_data)
19
+ ram = Ram.new
20
+ mbc = Cartridge::Factory.create(rom, ram)
21
+ interrupt = Interrupt.new
22
+ @ppu = Ppu.new(interrupt)
23
+ @timer = Timer.new(interrupt)
24
+ joypad = Joypad.new(interrupt)
25
+ @apu = Apu.new
26
+ bus = Bus.new(@ppu, rom, ram, mbc, @timer, interrupt, joypad, @apu)
27
+ @cpu = Cpu.new(bus, interrupt)
28
+ end
29
+
30
+ def step
31
+ loop do
32
+ cycles = @cpu.exec
33
+ @timer.step(cycles)
34
+ @apu.step(cycles)
35
+ break if @ppu.step(cycles)
36
+ end
37
+ end
38
+ end
39
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rubyboy
4
- VERSION = '1.4.2'
4
+ VERSION = '1.5.0'
5
5
  end
data/lib/stackprof.rb ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'stackprof'
4
+ require_relative 'rubyboy/emulator'
5
+
6
+ module Rubyboy
7
+ class Stackprof
8
+ def run
9
+ StackProf.run(mode: :cpu, out: 'stackprof-cpu-myapp.dump', raw: true) do
10
+ Rubyboy::Emulator.new('lib/roms/tobu.gb').bench
11
+ end
12
+ end
13
+ end
14
+ end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubyboy
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.2
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - sacckey
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2025-01-11 00:00:00.000000000 Z
10
+ date: 2025-02-09 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: ffi
@@ -30,8 +29,6 @@ dependencies:
30
29
  - - ">="
31
30
  - !ruby/object:Gem::Version
32
31
  version: 1.16.3
33
- description:
34
- email:
35
32
  executables:
36
33
  - rubyboy
37
34
  - rubyboy-bench
@@ -91,6 +88,7 @@ files:
91
88
  - lib/rubyboy/cartridge/nombc.rb
92
89
  - lib/rubyboy/cpu.rb
93
90
  - lib/rubyboy/emulator.rb
91
+ - lib/rubyboy/emulator_headless.rb
94
92
  - lib/rubyboy/emulator_wasm.rb
95
93
  - lib/rubyboy/interrupt.rb
96
94
  - lib/rubyboy/joypad.rb
@@ -105,6 +103,7 @@ files:
105
103
  - lib/rubyboy/sdl.rb
106
104
  - lib/rubyboy/timer.rb
107
105
  - lib/rubyboy/version.rb
106
+ - lib/stackprof.rb
108
107
  - resource/logo/logo.png
109
108
  - resource/logo/logo.svg
110
109
  - resource/logo/rubyboy.png
@@ -120,7 +119,6 @@ metadata:
120
119
  source_code_uri: https://github.com/sacckey/rubyboy
121
120
  changelog_uri: https://github.com/sacckey/rubyboy/blob/main/CHANGELOG.md
122
121
  rubygems_mfa_required: 'true'
123
- post_install_message:
124
122
  rdoc_options: []
125
123
  require_paths:
126
124
  - lib
@@ -135,8 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
133
  - !ruby/object:Gem::Version
136
134
  version: '0'
137
135
  requirements: []
138
- rubygems_version: 3.5.3
139
- signing_key:
136
+ rubygems_version: 3.6.2
140
137
  specification_version: 4
141
138
  summary: A Game Boy emulator written in Ruby
142
139
  test_files: []