rubyboy 1.5.1 → 1.7.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 +4 -4
- data/CHANGELOG.md +24 -0
- data/README.md +39 -27
- data/exe/rubyboy +16 -5
- data/exe/rubyboy-bench +15 -7
- data/lib/bench.rb +33 -7
- data/lib/executor.rb +19 -10
- data/lib/rubyboy/apu.rb +15 -4
- data/lib/rubyboy/apu_channels/channel1.rb +4 -4
- data/lib/rubyboy/apu_channels/channel2.rb +4 -4
- data/lib/rubyboy/apu_channels/channel3.rb +2 -9
- data/lib/rubyboy/apu_channels/channel4.rb +0 -7
- data/lib/rubyboy/audio.rb +17 -4
- data/lib/rubyboy/cartridge/mbc1.rb +30 -18
- data/lib/rubyboy/emulator.rb +145 -47
- data/lib/rubyboy/emulator_headless.rb +6 -2
- data/lib/rubyboy/emulator_wasm.rb +31 -8
- data/lib/rubyboy/hardware_state.rb +450 -0
- data/lib/rubyboy/lcd.rb +2 -1
- data/lib/rubyboy/ram.rb +2 -2
- data/lib/rubyboy/rom.rb +26 -0
- data/lib/rubyboy/save_file.rb +36 -0
- data/lib/rubyboy/sdl.rb +12 -0
- data/lib/rubyboy/state_file.rb +49 -0
- data/lib/rubyboy/version.rb +1 -1
- data/lib/rubyboy.rb +3 -0
- metadata +9 -48
- data/.rspec +0 -3
- data/.rubocop.yml +0 -54
- data/CODE_OF_CONDUCT.md +0 -84
- data/Rakefile +0 -12
- data/docs/favicon.png +0 -0
- data/docs/index.html +0 -75
- data/docs/index.js +0 -113
- data/docs/logo-light-23.svg +0 -1
- data/docs/ogp.png +0 -0
- data/docs/styles.css +0 -245
- data/docs/worker.js +0 -115
- data/exe/rubyboy-wasm +0 -26
- data/lib/opcodes.json +0 -11657
- data/lib/roms/bgbtest.gb +0 -0
- data/lib/roms/cpu_instrs/cpu_instrs.gb +0 -0
- data/lib/roms/cpu_instrs/individual/01-special.gb +0 -0
- data/lib/roms/cpu_instrs/individual/02-interrupts.gb +0 -0
- data/lib/roms/cpu_instrs/individual/03-op sp,hl.gb +0 -0
- data/lib/roms/cpu_instrs/individual/04-op r,imm.gb +0 -0
- data/lib/roms/cpu_instrs/individual/05-op rp.gb +0 -0
- data/lib/roms/cpu_instrs/individual/06-ld r,r.gb +0 -0
- data/lib/roms/cpu_instrs/individual/07-jr,jp,call,ret,rst.gb +0 -0
- data/lib/roms/cpu_instrs/individual/08-misc instrs.gb +0 -0
- data/lib/roms/cpu_instrs/individual/09-op r,r.gb +0 -0
- data/lib/roms/cpu_instrs/individual/10-bit ops.gb +0 -0
- data/lib/roms/cpu_instrs/individual/11-op a,(hl).gb +0 -0
- data/lib/roms/cpu_instrs/readme.txt +0 -119
- data/lib/roms/dmg-acid2.gb +0 -0
- data/lib/roms/hello-world.gb +0 -0
- data/lib/roms/instr_timing/instr_timing.gb +0 -0
- data/lib/roms/instr_timing/readme.txt +0 -139
- data/lib/rubyboy/raylib/audio.rb +0 -32
- data/lib/rubyboy/raylib/lcd.rb +0 -40
- data/lib/rubyboy/raylib/raylib_loader.rb +0 -36
- data/lib/stackprof.rb +0 -14
- data/resource/logo/logo.png +0 -0
- data/resource/logo/logo.svg +0 -1
- data/resource/logo/rubyboy.png +0 -0
- data/resource/screenshots/pokemon.png +0 -0
- data/resource/screenshots/puyopuyo.png +0 -0
- data/sig/rubyboy.rbs +0 -4
data/docs/styles.css
DELETED
|
@@ -1,245 +0,0 @@
|
|
|
1
|
-
body {
|
|
2
|
-
background-color: #f0d0ce;
|
|
3
|
-
display: flex;
|
|
4
|
-
margin: 0;
|
|
5
|
-
font-family: 'Helvetica', 'Arial', sans-serif;
|
|
6
|
-
flex-direction: column;
|
|
7
|
-
min-height: 100vh;
|
|
8
|
-
overflow-x: hidden;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
.main-content {
|
|
12
|
-
display: flex;
|
|
13
|
-
flex-direction: column;
|
|
14
|
-
align-items: center;
|
|
15
|
-
padding: 20px;
|
|
16
|
-
flex-grow: 1;
|
|
17
|
-
width: 100%;
|
|
18
|
-
box-sizing: border-box;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
.gameboy {
|
|
22
|
-
background-color: #cc342d;
|
|
23
|
-
border-radius: 10px 10px 70px 10px;
|
|
24
|
-
padding: 25px 20px 40px;
|
|
25
|
-
box-shadow: 5px 5px 15px rgba(0,0,0,0.3);
|
|
26
|
-
display: flex;
|
|
27
|
-
flex-direction: column;
|
|
28
|
-
align-items: center;
|
|
29
|
-
width: 100%;
|
|
30
|
-
max-width: 380px;
|
|
31
|
-
justify-content: flex-start;
|
|
32
|
-
margin-bottom: 20px;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
.screen-container {
|
|
36
|
-
background-color: #f0d0ce;
|
|
37
|
-
border-radius: 10px;
|
|
38
|
-
padding: 20px;
|
|
39
|
-
margin-bottom: 80px;
|
|
40
|
-
width: 100%;
|
|
41
|
-
box-sizing: border-box;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
#canvas {
|
|
45
|
-
background-color: #881e1a;
|
|
46
|
-
display: block;
|
|
47
|
-
width: 100%;
|
|
48
|
-
height: auto;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
.controls {
|
|
52
|
-
display: flex;
|
|
53
|
-
justify-content: space-between;
|
|
54
|
-
width: 100%;
|
|
55
|
-
margin-bottom: 60px;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
.d-pad {
|
|
59
|
-
width: 100px;
|
|
60
|
-
height: 100px;
|
|
61
|
-
position: relative;
|
|
62
|
-
background-color: #881e1a;
|
|
63
|
-
border-radius: 50%;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
.d-pad-button {
|
|
67
|
-
position: absolute;
|
|
68
|
-
background-color: #550e0c;
|
|
69
|
-
border: none;
|
|
70
|
-
cursor: pointer;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
#d-pad-left, #d-pad-right {
|
|
74
|
-
width: 30px;
|
|
75
|
-
height: 30px;
|
|
76
|
-
top: 35px;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
#d-pad-left {
|
|
80
|
-
left: 5px;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
#d-pad-right {
|
|
84
|
-
right: 5px;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
#d-pad-up, #d-pad-down {
|
|
88
|
-
width: 30px;
|
|
89
|
-
height: 30px;
|
|
90
|
-
left: 35px;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
#d-pad-up {
|
|
94
|
-
top: 5px;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
#d-pad-down {
|
|
98
|
-
bottom: 5px;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
.buttons {
|
|
102
|
-
background-color: #881e1a;
|
|
103
|
-
border-radius: 50%;
|
|
104
|
-
width: 100px;
|
|
105
|
-
height: 100px;
|
|
106
|
-
position: relative;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
.action-button {
|
|
110
|
-
position: absolute;
|
|
111
|
-
background-color: #ff6b66;
|
|
112
|
-
border: none;
|
|
113
|
-
border-radius: 50%;
|
|
114
|
-
width: 35px;
|
|
115
|
-
height: 35px;
|
|
116
|
-
cursor: pointer;
|
|
117
|
-
color: #881e1a;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
#button-a {
|
|
121
|
-
top: 15px;
|
|
122
|
-
right: 15px;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
#button-b {
|
|
126
|
-
bottom: 15px;
|
|
127
|
-
left: 15px;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
.start-select {
|
|
131
|
-
display: flex;
|
|
132
|
-
justify-content: center;
|
|
133
|
-
margin-bottom: 50px;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
.start-select button {
|
|
137
|
-
background-color: #881e1a;
|
|
138
|
-
border: none;
|
|
139
|
-
width: 50px;
|
|
140
|
-
height: 15px;
|
|
141
|
-
margin: 0 15px;
|
|
142
|
-
transform: rotate(-25deg);
|
|
143
|
-
cursor: pointer;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
.control-panel {
|
|
147
|
-
width: 100%;
|
|
148
|
-
max-width: 500px;
|
|
149
|
-
background-color: #ffffff;
|
|
150
|
-
border-radius: 10px;
|
|
151
|
-
padding: 20px;
|
|
152
|
-
box-shadow: 0 0 10px rgba(0,0,0,0.1);
|
|
153
|
-
box-sizing: border-box;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
.control-panel section {
|
|
157
|
-
margin-bottom: 20px;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
.rom-upload-button {
|
|
161
|
-
display: inline-block;
|
|
162
|
-
padding: 10px 20px;
|
|
163
|
-
background-color: #cc342d;
|
|
164
|
-
color: white;
|
|
165
|
-
border: none;
|
|
166
|
-
border-radius: 4px;
|
|
167
|
-
font-family: Arial, sans-serif;
|
|
168
|
-
cursor: pointer;
|
|
169
|
-
transition: all 0.3s ease;
|
|
170
|
-
margin-top: 10px;
|
|
171
|
-
margin-left: 0;
|
|
172
|
-
width: 100%;
|
|
173
|
-
box-sizing: border-box;
|
|
174
|
-
text-align: center;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
.rom-upload-button.disabled {
|
|
178
|
-
background-color: #cccccc;
|
|
179
|
-
color: #666666;
|
|
180
|
-
cursor: not-allowed;
|
|
181
|
-
opacity: 0.7;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
.rom-upload-button input[type="file"] {
|
|
185
|
-
display: none;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
.rom-select-box {
|
|
189
|
-
width: 100%;
|
|
190
|
-
margin-bottom: 10px;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
.footer {
|
|
194
|
-
background-color: #cc342d;
|
|
195
|
-
color: white;
|
|
196
|
-
text-align: center;
|
|
197
|
-
width: 100%;
|
|
198
|
-
box-sizing: border-box;
|
|
199
|
-
margin-top: 20px;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
kbd {
|
|
203
|
-
background-color: #eee;
|
|
204
|
-
border-radius: 3px;
|
|
205
|
-
border: 1px solid #b4b4b4;
|
|
206
|
-
box-shadow:
|
|
207
|
-
0 1px 1px rgba(0, 0, 0, 0.2),
|
|
208
|
-
0 2px 0 0 rgba(255, 255, 255, 0.7) inset;
|
|
209
|
-
color: #333;
|
|
210
|
-
display: inline-block;
|
|
211
|
-
font-size: 0.85em;
|
|
212
|
-
line-height: 1;
|
|
213
|
-
padding: 2px 4px;
|
|
214
|
-
white-space: nowrap;
|
|
215
|
-
font-family: Courier;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
@media (min-width: 900px) {
|
|
219
|
-
.main-content {
|
|
220
|
-
flex-direction: row;
|
|
221
|
-
justify-content: center;
|
|
222
|
-
align-items: flex-start;
|
|
223
|
-
padding: 50px;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
.gameboy {
|
|
227
|
-
margin-right: 50px;
|
|
228
|
-
margin-bottom: 0;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
.control-panel {
|
|
232
|
-
flex: 1;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
.rom-upload-button {
|
|
236
|
-
width: auto;
|
|
237
|
-
margin-left: 20px;
|
|
238
|
-
margin-top: 0;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
.rom-select-box {
|
|
242
|
-
width: auto;
|
|
243
|
-
margin-bottom: 0;
|
|
244
|
-
}
|
|
245
|
-
}
|
data/docs/worker.js
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import { DefaultRubyVM } from 'https://cdn.jsdelivr.net/npm/@ruby/wasm-wasi@2.7.1/dist/browser/+esm';
|
|
2
|
-
import { File } from 'https://cdn.jsdelivr.net/npm/@bjorn3/browser_wasi_shim@0.3.0/+esm';
|
|
3
|
-
|
|
4
|
-
const DIRECTION_KEY_MASKS = {
|
|
5
|
-
'KeyD': 0b0001, // Right
|
|
6
|
-
'KeyA': 0b0010, // Left
|
|
7
|
-
'KeyW': 0b0100, // Up
|
|
8
|
-
'KeyS': 0b1000 // Down
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
const ACTION_KEY_MASKS = {
|
|
12
|
-
'KeyK': 0b0001, // A
|
|
13
|
-
'KeyJ': 0b0010, // B
|
|
14
|
-
'KeyU': 0b0100, // Select
|
|
15
|
-
'KeyI': 0b1000 // Start
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
class Rubyboy {
|
|
19
|
-
constructor() {
|
|
20
|
-
this.wasmUrl = 'https://proxy.sacckey.dev/rubyboy.wasm';
|
|
21
|
-
|
|
22
|
-
this.directionKey = 0b1111;
|
|
23
|
-
this.actionKey = 0b1111;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
async init() {
|
|
27
|
-
let response = await fetch('./rubyboy.wasm');
|
|
28
|
-
if (!response.ok) {
|
|
29
|
-
response = await fetch(this.wasmUrl);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const module = await WebAssembly.compileStreaming(response)
|
|
33
|
-
const { vm, wasi } = await DefaultRubyVM(module);
|
|
34
|
-
vm.eval(`
|
|
35
|
-
require 'js'
|
|
36
|
-
require_relative 'lib/executor'
|
|
37
|
-
|
|
38
|
-
$executor = Executor.new
|
|
39
|
-
`);
|
|
40
|
-
|
|
41
|
-
this.vm = vm;
|
|
42
|
-
this.rootDir = wasi.fds[3].dir
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
sendPixelData() {
|
|
46
|
-
this.vm.eval(`$executor.exec(${this.directionKey}, ${this.actionKey})`);
|
|
47
|
-
|
|
48
|
-
const file = this.rootDir.contents.get('video.data');
|
|
49
|
-
const bytes = file.data;
|
|
50
|
-
|
|
51
|
-
postMessage({ type: 'pixelData', data: bytes.buffer }, [bytes.buffer]);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
emulationLoop() {
|
|
55
|
-
this.sendPixelData();
|
|
56
|
-
setTimeout(this.emulationLoop.bind(this), 0);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const rubyboy = new Rubyboy();
|
|
61
|
-
|
|
62
|
-
self.addEventListener('message', async (event) => {
|
|
63
|
-
if (event.data.type === 'initRubyboy') {
|
|
64
|
-
try {
|
|
65
|
-
await rubyboy.init();
|
|
66
|
-
postMessage({ type: 'initialized', message: 'ok' });
|
|
67
|
-
} catch (error) {
|
|
68
|
-
postMessage({ type: 'error', message: error.message });
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (event.data.type === 'startRubyboy') {
|
|
73
|
-
try {
|
|
74
|
-
rubyboy.emulationLoop();
|
|
75
|
-
} catch (error) {
|
|
76
|
-
postMessage({ type: 'error', message: error.message });
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (event.data.type === 'keydown' || event.data.type === 'keyup') {
|
|
81
|
-
const code = event.data.code;
|
|
82
|
-
const directionKeyMask = DIRECTION_KEY_MASKS[code];
|
|
83
|
-
const actionKeyMask = ACTION_KEY_MASKS[code];
|
|
84
|
-
|
|
85
|
-
if (directionKeyMask) {
|
|
86
|
-
if (event.data.type === 'keydown') {
|
|
87
|
-
rubyboy.directionKey &= ~directionKeyMask;
|
|
88
|
-
} else {
|
|
89
|
-
rubyboy.directionKey |= directionKeyMask;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if (actionKeyMask) {
|
|
94
|
-
if (event.data.type === 'keydown') {
|
|
95
|
-
rubyboy.actionKey &= ~actionKeyMask;
|
|
96
|
-
} else {
|
|
97
|
-
rubyboy.actionKey |= actionKeyMask;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
if (event.data.type === 'loadROM') {
|
|
103
|
-
const romFile = new File(new Uint8Array(event.data.data));
|
|
104
|
-
rubyboy.rootDir.contents.set('rom.data', romFile);
|
|
105
|
-
rubyboy.vm.eval(`
|
|
106
|
-
$executor.read_rom_from_virtual_fs
|
|
107
|
-
`);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
if (event.data.type === 'loadPreInstalledRom') {
|
|
111
|
-
rubyboy.vm.eval(`
|
|
112
|
-
$executor.read_pre_installed_rom("${event.data.romName}")
|
|
113
|
-
`);
|
|
114
|
-
}
|
|
115
|
-
});
|
data/exe/rubyboy-wasm
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
# frozen_string_literal: true
|
|
3
|
-
|
|
4
|
-
case ARGV[0]
|
|
5
|
-
when 'build'
|
|
6
|
-
command = %w[build --ruby-version 3.4 -o ./docs/ruby-js.wasm]
|
|
7
|
-
when 'pack'
|
|
8
|
-
command = %w[pack ./docs/ruby-js.wasm --dir ./lib::/lib -o ./docs/rubyboy.wasm]
|
|
9
|
-
else
|
|
10
|
-
puts "Invalid argument. Use 'build' or 'pack'."
|
|
11
|
-
exit 1
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
ENV['BUNDLE_ONLY'] = 'wasm'
|
|
15
|
-
|
|
16
|
-
require 'bundler/setup'
|
|
17
|
-
require 'ruby_wasm'
|
|
18
|
-
require 'ruby_wasm/cli'
|
|
19
|
-
|
|
20
|
-
# Exclude all gems except the 'js' gem for packaging
|
|
21
|
-
definition = Bundler.definition
|
|
22
|
-
excluded_gems = definition.resolve.materialize(definition.requested_dependencies).map(&:name)
|
|
23
|
-
excluded_gems -= %w[js]
|
|
24
|
-
RubyWasm::Packager::EXCLUDED_GEMS.concat(excluded_gems)
|
|
25
|
-
|
|
26
|
-
RubyWasm::CLI.new(stdout: $stdout, stderr: $stderr).run(command)
|