rubyboy 1.2.0 → 1.3.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/.rubocop.yml +6 -0
- data/CHANGELOG.md +8 -0
- data/lib/rubyboy/apu.rb +118 -0
- data/lib/rubyboy/apu_channels/channel1.rb +154 -0
- data/lib/rubyboy/apu_channels/channel2.rb +116 -0
- data/lib/rubyboy/apu_channels/channel3.rb +117 -0
- data/lib/rubyboy/apu_channels/channel4.rb +148 -0
- data/lib/rubyboy/audio.rb +33 -0
- data/lib/rubyboy/bus.rb +63 -117
- data/lib/rubyboy/cartridge/factory.rb +1 -1
- data/lib/rubyboy/cartridge/mbc1.rb +52 -36
- data/lib/rubyboy/cpu.rb +701 -676
- data/lib/rubyboy/lcd.rb +30 -20
- data/lib/rubyboy/ppu.rb +16 -4
- data/lib/rubyboy/raylib/audio.rb +32 -0
- data/lib/rubyboy/raylib/lcd.rb +40 -0
- data/lib/rubyboy/raylib/raylib_loader.rb +36 -0
- data/lib/rubyboy/registers.rb +67 -61
- data/lib/rubyboy/sdl.rb +71 -0
- data/lib/rubyboy/version.rb +1 -1
- data/lib/rubyboy.rb +19 -42
- metadata +21 -5
data/lib/rubyboy/lcd.rb
CHANGED
@@ -1,38 +1,48 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'rubyboy/sdl'
|
4
4
|
|
5
5
|
module Rubyboy
|
6
6
|
class Lcd
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
HEIGHT = 144
|
11
|
-
SCALE = 4
|
7
|
+
SCREEN_WIDTH = 160
|
8
|
+
SCREEN_HEIGHT = 144
|
9
|
+
SCALE = 3
|
12
10
|
|
13
11
|
def initialize
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
@
|
18
|
-
@vector = Vector2.create(0, 0)
|
19
|
-
end
|
12
|
+
raise SDL.GetError() if SDL.InitSubSystem(SDL::INIT_VIDEO) != 0
|
13
|
+
|
14
|
+
@buffer = FFI::MemoryPointer.new(:uint8, SCREEN_WIDTH * SCREEN_HEIGHT * 3)
|
15
|
+
@window = SDL.CreateWindow('RUBY BOY', 0, 0, SCREEN_WIDTH * SCALE, SCREEN_HEIGHT * SCALE, SDL::SDL_WINDOW_RESIZABLE)
|
20
16
|
|
21
|
-
|
22
|
-
UpdateTexture(@texture, pixel_data)
|
17
|
+
raise SDL.GetError() if @window.null?
|
23
18
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
19
|
+
@renderer = SDL.CreateRenderer(@window, -1, 0)
|
20
|
+
SDL.SetHint('SDL_HINT_RENDER_SCALE_QUALITY', '2')
|
21
|
+
SDL.RenderSetLogicalSize(@renderer, SCREEN_WIDTH * SCALE, SCREEN_HEIGHT * SCALE)
|
22
|
+
@texture = SDL.CreateTexture(@renderer, SDL::PIXELFORMAT_RGB24, 1, SCREEN_WIDTH, SCREEN_HEIGHT)
|
23
|
+
@event = FFI::MemoryPointer.new(:pointer)
|
24
|
+
end
|
25
|
+
|
26
|
+
def draw(framebuffer)
|
27
|
+
@buffer.write_array_of_uint8(framebuffer)
|
28
|
+
SDL.UpdateTexture(@texture, nil, @buffer, SCREEN_WIDTH * 3)
|
29
|
+
SDL.RenderClear(@renderer)
|
30
|
+
SDL.RenderCopy(@renderer, @texture, nil, nil)
|
31
|
+
SDL.RenderPresent(@renderer)
|
28
32
|
end
|
29
33
|
|
30
34
|
def window_should_close?
|
31
|
-
|
35
|
+
while SDL.PollEvent(@event) != 0
|
36
|
+
event_type = @event.read_int
|
37
|
+
return true if event_type == SDL::QUIT
|
38
|
+
end
|
39
|
+
|
40
|
+
false
|
32
41
|
end
|
33
42
|
|
34
43
|
def close_window
|
35
|
-
|
44
|
+
SDL.DestroyWindow(@window)
|
45
|
+
SDL.Quit
|
36
46
|
end
|
37
47
|
end
|
38
48
|
end
|
data/lib/rubyboy/ppu.rb
CHANGED
@@ -64,7 +64,7 @@ module Rubyboy
|
|
64
64
|
@wly = 0x00
|
65
65
|
@cycles = 0
|
66
66
|
@interrupt = interrupt
|
67
|
-
@buffer = Array.new(144 * 160, 0x00)
|
67
|
+
@buffer = Array.new(144 * 160 * 3, 0x00)
|
68
68
|
@bg_pixels = Array.new(LCD_WIDTH, 0x00)
|
69
69
|
end
|
70
70
|
|
@@ -196,7 +196,11 @@ module Rubyboy
|
|
196
196
|
x = (i + @scx) % 256
|
197
197
|
tile_index = get_tile_index(tile_map_addr + (x / 8))
|
198
198
|
pixel = get_pixel(tile_index << 4, 7 - (x % 8), (y % 8) * 2)
|
199
|
-
|
199
|
+
color = get_color(@bgp, pixel)
|
200
|
+
base = @ly * LCD_WIDTH * 3 + i * 3
|
201
|
+
@buffer[base] = color
|
202
|
+
@buffer[base + 1] = color
|
203
|
+
@buffer[base + 2] = color
|
200
204
|
@bg_pixels[i] = pixel
|
201
205
|
end
|
202
206
|
end
|
@@ -215,7 +219,11 @@ module Rubyboy
|
|
215
219
|
x = i - (@wx - 7)
|
216
220
|
tile_index = get_tile_index(tile_map_addr + (x / 8))
|
217
221
|
pixel = get_pixel(tile_index << 4, 7 - (x % 8), (y % 8) * 2)
|
218
|
-
|
222
|
+
color = get_color(@bgp, pixel)
|
223
|
+
base = @ly * LCD_WIDTH * 3 + i * 3
|
224
|
+
@buffer[base] = color
|
225
|
+
@buffer[base + 1] = color
|
226
|
+
@buffer[base + 2] = color
|
219
227
|
@bg_pixels[i] = pixel
|
220
228
|
end
|
221
229
|
@wly += 1 if rendered
|
@@ -258,7 +266,11 @@ module Rubyboy
|
|
258
266
|
next if pixel == 0 || i >= LCD_WIDTH
|
259
267
|
next if flags[SPRITE_FLAGS[:priority]] == 1 && @bg_pixels[i] != 0
|
260
268
|
|
261
|
-
|
269
|
+
color = get_color(pallet, pixel)
|
270
|
+
base = @ly * LCD_WIDTH * 3 + i * 3
|
271
|
+
@buffer[base] = color
|
272
|
+
@buffer[base + 1] = color
|
273
|
+
@buffer[base + 2] = color
|
262
274
|
end
|
263
275
|
end
|
264
276
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'raylib'
|
4
|
+
|
5
|
+
module Rubyboy
|
6
|
+
module Raylib
|
7
|
+
class Audio
|
8
|
+
include Raylib
|
9
|
+
|
10
|
+
MAX_SAMPLES = 512
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
InitAudioDevice()
|
14
|
+
SetAudioStreamBufferSizeDefault(MAX_SAMPLES * 2)
|
15
|
+
@stream = LoadAudioStream(48000, 32, 2)
|
16
|
+
PlayAudioStream(@stream)
|
17
|
+
end
|
18
|
+
|
19
|
+
def play(samples)
|
20
|
+
samples_pointer = FFI::MemoryPointer.new(:float, samples.size)
|
21
|
+
samples_pointer.put_array_of_float(0, samples)
|
22
|
+
|
23
|
+
UpdateAudioStream(@stream, samples_pointer, samples.size)
|
24
|
+
end
|
25
|
+
|
26
|
+
def close
|
27
|
+
UnloadAudioStream(@stream)
|
28
|
+
CloseAudioDevice()
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'raylib'
|
4
|
+
|
5
|
+
module Rubyboy
|
6
|
+
module Raylib
|
7
|
+
class Lcd
|
8
|
+
include Raylib
|
9
|
+
|
10
|
+
WIDTH = 160
|
11
|
+
HEIGHT = 144
|
12
|
+
SCALE = 4
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
InitWindow(WIDTH * SCALE, HEIGHT * SCALE, 'RUBY BOY')
|
16
|
+
image = GenImageColor(WIDTH, HEIGHT, BLACK)
|
17
|
+
image.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8
|
18
|
+
@texture = LoadTextureFromImage(image)
|
19
|
+
@vector = Vector2.create(0, 0)
|
20
|
+
end
|
21
|
+
|
22
|
+
def draw(pixel_data)
|
23
|
+
UpdateTexture(@texture, pixel_data.pack('C*'))
|
24
|
+
|
25
|
+
BeginDrawing()
|
26
|
+
ClearBackground(BLACK)
|
27
|
+
DrawTextureEx(@texture, @vector, 0.0, SCALE, WHITE)
|
28
|
+
EndDrawing()
|
29
|
+
end
|
30
|
+
|
31
|
+
def window_should_close?
|
32
|
+
WindowShouldClose()
|
33
|
+
end
|
34
|
+
|
35
|
+
def close_window
|
36
|
+
CloseWindow()
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'raylib'
|
4
|
+
|
5
|
+
module Rubyboy
|
6
|
+
module Raylib
|
7
|
+
class RaylibLoader
|
8
|
+
include Raylib
|
9
|
+
|
10
|
+
def load_raylib
|
11
|
+
shared_lib_path = "#{Gem::Specification.find_by_name('raylib-bindings').full_gem_path}/lib/"
|
12
|
+
case RUBY_PLATFORM
|
13
|
+
when /mswin|msys|mingw/ # Windows
|
14
|
+
Raylib.load_lib("#{shared_lib_path}libraylib.dll")
|
15
|
+
when /darwin/ # macOS
|
16
|
+
arch = RUBY_PLATFORM.split('-')[0]
|
17
|
+
Raylib.load_lib(shared_lib_path + "libraylib.#{arch}.dylib")
|
18
|
+
when /linux/ # Ubuntu Linux (x86_64 or aarch64)
|
19
|
+
arch = RUBY_PLATFORM.split('-')[0]
|
20
|
+
Raylib.load_lib(shared_lib_path + "libraylib.#{arch}.so")
|
21
|
+
else
|
22
|
+
raise "Unknown system: #{RUBY_PLATFORM}"
|
23
|
+
end
|
24
|
+
|
25
|
+
SetTraceLogLevel(LOG_ERROR)
|
26
|
+
end
|
27
|
+
|
28
|
+
def key_input_check
|
29
|
+
direction = (IsKeyUp(KEY_D) && 1 || 0) | ((IsKeyUp(KEY_A) && 1 || 0) << 1) | ((IsKeyUp(KEY_W) && 1 || 0) << 2) | ((IsKeyUp(KEY_S) && 1 || 0) << 3)
|
30
|
+
action = (IsKeyUp(KEY_K) && 1 || 0) | ((IsKeyUp(KEY_J) && 1 || 0) << 1) | ((IsKeyUp(KEY_U) && 1 || 0) << 2) | ((IsKeyUp(KEY_I) && 1 || 0) << 3)
|
31
|
+
@joypad.direction_button(direction)
|
32
|
+
@joypad.action_button(action)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/rubyboy/registers.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module Rubyboy
|
4
4
|
class Registers
|
5
|
-
attr_reader :
|
5
|
+
attr_reader :a, :b, :c, :d, :e, :h, :l, :f
|
6
6
|
|
7
7
|
def initialize
|
8
8
|
@a = 0x01
|
@@ -15,66 +15,72 @@ module Rubyboy
|
|
15
15
|
@f = 0xb0
|
16
16
|
end
|
17
17
|
|
18
|
-
def
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
end
|
53
|
-
|
54
|
-
def
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
end
|
75
|
-
|
76
|
-
def
|
77
|
-
|
18
|
+
def a=(value)
|
19
|
+
@a = value & 0xff
|
20
|
+
end
|
21
|
+
|
22
|
+
def b=(value)
|
23
|
+
@b = value & 0xff
|
24
|
+
end
|
25
|
+
|
26
|
+
def c=(value)
|
27
|
+
@c = value & 0xff
|
28
|
+
end
|
29
|
+
|
30
|
+
def d=(value)
|
31
|
+
@d = value & 0xff
|
32
|
+
end
|
33
|
+
|
34
|
+
def e=(value)
|
35
|
+
@e = value & 0xff
|
36
|
+
end
|
37
|
+
|
38
|
+
def h=(value)
|
39
|
+
@h = value & 0xff
|
40
|
+
end
|
41
|
+
|
42
|
+
def l=(value)
|
43
|
+
@l = value & 0xff
|
44
|
+
end
|
45
|
+
|
46
|
+
def f=(value)
|
47
|
+
@f = value & 0xf0
|
48
|
+
end
|
49
|
+
|
50
|
+
def af
|
51
|
+
(@a << 8) | @f
|
52
|
+
end
|
53
|
+
|
54
|
+
def bc
|
55
|
+
(@b << 8) | @c
|
56
|
+
end
|
57
|
+
|
58
|
+
def de
|
59
|
+
(@d << 8) | @e
|
60
|
+
end
|
61
|
+
|
62
|
+
def hl
|
63
|
+
(@h << 8) | @l
|
64
|
+
end
|
65
|
+
|
66
|
+
def af=(value)
|
67
|
+
@a = (value >> 8) & 0xff
|
68
|
+
@f = value & 0xf0
|
69
|
+
end
|
70
|
+
|
71
|
+
def bc=(value)
|
72
|
+
@b = (value >> 8) & 0xff
|
73
|
+
@c = value & 0xff
|
74
|
+
end
|
75
|
+
|
76
|
+
def de=(value)
|
77
|
+
@d = (value >> 8) & 0xff
|
78
|
+
@e = value & 0xff
|
79
|
+
end
|
80
|
+
|
81
|
+
def hl=(value)
|
82
|
+
@h = (value >> 8) & 0xff
|
83
|
+
@l = value & 0xff
|
78
84
|
end
|
79
85
|
end
|
80
86
|
end
|
data/lib/rubyboy/sdl.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ffi'
|
4
|
+
|
5
|
+
module Rubyboy
|
6
|
+
module SDL
|
7
|
+
extend FFI::Library
|
8
|
+
ffi_lib 'SDL2'
|
9
|
+
|
10
|
+
INIT_TIMER = 0x01
|
11
|
+
INIT_AUDIO = 0x10
|
12
|
+
INIT_VIDEO = 0x20
|
13
|
+
INIT_KEYBOARD = 0x200
|
14
|
+
WINDOW_RESIZABLE = 0x20
|
15
|
+
PIXELFORMAT_RGB24 = 386930691
|
16
|
+
SDL_WINDOW_RESIZABLE = 0x20
|
17
|
+
QUIT = 0x100
|
18
|
+
|
19
|
+
SDL_SCANCODE_W = 26
|
20
|
+
SDL_SCANCODE_A = 4
|
21
|
+
SDL_SCANCODE_S = 22
|
22
|
+
SDL_SCANCODE_D = 7
|
23
|
+
SDL_SCANCODE_J = 13
|
24
|
+
SDL_SCANCODE_K = 14
|
25
|
+
SDL_SCANCODE_U = 24
|
26
|
+
SDL_SCANCODE_I = 12
|
27
|
+
|
28
|
+
attach_function :Init, 'SDL_Init', [:uint32], :int
|
29
|
+
attach_function :InitSubSystem, 'SDL_InitSubSystem', [:uint32], :int
|
30
|
+
attach_function :CreateWindow, 'SDL_CreateWindow', %i[string int int int int uint32], :pointer
|
31
|
+
attach_function :DestroyWindow, 'SDL_DestroyWindow', [:pointer], :void
|
32
|
+
attach_function :CreateRenderer, 'SDL_CreateRenderer', %i[pointer int uint32], :pointer
|
33
|
+
attach_function :CreateTexture, 'SDL_CreateTexture', %i[pointer uint32 int int int], :pointer
|
34
|
+
attach_function :UpdateTexture, 'SDL_UpdateTexture', %i[pointer pointer pointer int], :int
|
35
|
+
attach_function :LockTexture, 'SDL_LockTexture', %i[pointer pointer pointer int], :int
|
36
|
+
attach_function :UnlockTexture, 'SDL_UnlockTexture', [:pointer], :void
|
37
|
+
attach_function :RenderClear, 'SDL_RenderClear', [:pointer], :int
|
38
|
+
attach_function :RenderCopy, 'SDL_RenderCopy', %i[pointer pointer pointer pointer], :int
|
39
|
+
attach_function :RenderPresent, 'SDL_RenderPresent', [:pointer], :int
|
40
|
+
attach_function :PumpEvents, 'SDL_PumpEvents', [], :void
|
41
|
+
attach_function :GetKeyboardState, 'SDL_GetKeyboardState', [:pointer], :pointer
|
42
|
+
attach_function :SetHint, 'SDL_SetHint', %i[string string], :int
|
43
|
+
attach_function :RenderSetLogicalSize, 'SDL_RenderSetLogicalSize', %i[pointer int int], :int
|
44
|
+
attach_function :SetWindowTitle, 'SDL_SetWindowTitle', %i[pointer string], :void
|
45
|
+
attach_function :RaiseWindow, 'SDL_RaiseWindow', [:pointer], :void
|
46
|
+
attach_function :GetError, 'SDL_GetError', [], :string
|
47
|
+
attach_function :SetRenderDrawColor, 'SDL_SetRenderDrawColor', %i[pointer uint8 uint8 uint8 uint8], :int
|
48
|
+
attach_function :PollEvent, 'SDL_PollEvent', [:pointer], :int
|
49
|
+
attach_function :Quit, 'SDL_Quit', [], :void
|
50
|
+
|
51
|
+
AUDIO_F32SYS = 0x8120
|
52
|
+
attach_function :OpenAudioDevice, 'SDL_OpenAudioDevice', %i[string int pointer pointer int], :uint32
|
53
|
+
attach_function :PauseAudioDevice, 'SDL_PauseAudioDevice', %i[uint32 int], :void
|
54
|
+
attach_function :GetQueuedAudioSize, 'SDL_GetQueuedAudioSize', [:uint32], :uint32
|
55
|
+
attach_function :QueueAudio, 'SDL_QueueAudio', %i[uint32 pointer uint32], :int
|
56
|
+
|
57
|
+
class AudioSpec < FFI::Struct
|
58
|
+
layout(
|
59
|
+
:freq, :int,
|
60
|
+
:format, :ushort,
|
61
|
+
:channels, :uchar,
|
62
|
+
:silence, :uchar,
|
63
|
+
:samples, :ushort,
|
64
|
+
:padding, :ushort,
|
65
|
+
:size, :uint,
|
66
|
+
:callback, :pointer,
|
67
|
+
:userdata, :pointer
|
68
|
+
)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
data/lib/rubyboy/version.rb
CHANGED
data/lib/rubyboy.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'rubyboy/sdl'
|
4
|
+
require_relative 'rubyboy/apu'
|
4
5
|
require_relative 'rubyboy/bus'
|
5
6
|
require_relative 'rubyboy/cpu'
|
6
7
|
require_relative 'rubyboy/ppu'
|
@@ -14,10 +15,7 @@ require_relative 'rubyboy/cartridge/factory'
|
|
14
15
|
|
15
16
|
module Rubyboy
|
16
17
|
class Console
|
17
|
-
include Raylib
|
18
|
-
|
19
18
|
def initialize(rom_path)
|
20
|
-
load_raylib
|
21
19
|
rom_data = File.open(rom_path, 'r') { _1.read.bytes }
|
22
20
|
rom = Rom.new(rom_data)
|
23
21
|
ram = Ram.new
|
@@ -26,19 +24,23 @@ module Rubyboy
|
|
26
24
|
@ppu = Ppu.new(interrupt)
|
27
25
|
@timer = Timer.new(interrupt)
|
28
26
|
@joypad = Joypad.new(interrupt)
|
29
|
-
@
|
27
|
+
@apu = Apu.new
|
28
|
+
@bus = Bus.new(@ppu, rom, ram, mbc, @timer, interrupt, @joypad, @apu)
|
30
29
|
@cpu = Cpu.new(@bus, interrupt)
|
31
30
|
@lcd = Lcd.new
|
32
31
|
end
|
33
32
|
|
34
33
|
def start
|
35
|
-
|
34
|
+
SDL.InitSubSystem(SDL::INIT_KEYBOARD)
|
35
|
+
loop do
|
36
36
|
cycles = @cpu.exec
|
37
37
|
@timer.step(cycles)
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
38
|
+
@apu.step(cycles)
|
39
|
+
next unless @ppu.step(cycles)
|
40
|
+
|
41
|
+
@lcd.draw(@ppu.buffer)
|
42
|
+
key_input_check
|
43
|
+
break if @lcd.window_should_close?
|
42
44
|
end
|
43
45
|
@lcd.close_window
|
44
46
|
rescue StandardError => e
|
@@ -63,40 +65,15 @@ module Rubyboy
|
|
63
65
|
|
64
66
|
private
|
65
67
|
|
66
|
-
def draw
|
67
|
-
pixel_data = buffer_to_pixel_data(@ppu.buffer)
|
68
|
-
@lcd.draw(pixel_data)
|
69
|
-
end
|
70
|
-
|
71
|
-
def buffer_to_pixel_data(buffer)
|
72
|
-
buffer.flat_map do |row|
|
73
|
-
[row, row, row]
|
74
|
-
end.pack('C*')
|
75
|
-
end
|
76
|
-
|
77
68
|
def key_input_check
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
@joypad.action_button(action)
|
82
|
-
end
|
83
|
-
|
84
|
-
def load_raylib
|
85
|
-
shared_lib_path = "#{Gem::Specification.find_by_name('raylib-bindings').full_gem_path}/lib/"
|
86
|
-
case RUBY_PLATFORM
|
87
|
-
when /mswin|msys|mingw/ # Windows
|
88
|
-
Raylib.load_lib("#{shared_lib_path}libraylib.dll")
|
89
|
-
when /darwin/ # macOS
|
90
|
-
arch = RUBY_PLATFORM.split('-')[0]
|
91
|
-
Raylib.load_lib(shared_lib_path + "libraylib.#{arch}.dylib")
|
92
|
-
when /linux/ # Ubuntu Linux (x86_64 or aarch64)
|
93
|
-
arch = RUBY_PLATFORM.split('-')[0]
|
94
|
-
Raylib.load_lib(shared_lib_path + "libraylib.#{arch}.so")
|
95
|
-
else
|
96
|
-
raise "Unknown system: #{RUBY_PLATFORM}"
|
97
|
-
end
|
69
|
+
SDL.PumpEvents
|
70
|
+
keyboard = SDL.GetKeyboardState(nil)
|
71
|
+
keyboard_state = keyboard.read_array_of_uint8(229)
|
98
72
|
|
99
|
-
|
73
|
+
direction = (keyboard_state[SDL::SDL_SCANCODE_D]) | (keyboard_state[SDL::SDL_SCANCODE_A] << 1) | (keyboard_state[SDL::SDL_SCANCODE_W] << 2) | (keyboard_state[SDL::SDL_SCANCODE_S] << 3)
|
74
|
+
action = (keyboard_state[SDL::SDL_SCANCODE_K]) | (keyboard_state[SDL::SDL_SCANCODE_J] << 1) | (keyboard_state[SDL::SDL_SCANCODE_U] << 2) | (keyboard_state[SDL::SDL_SCANCODE_I] << 3)
|
75
|
+
@joypad.direction_button(15 - direction)
|
76
|
+
@joypad.action_button(15 - action)
|
100
77
|
end
|
101
78
|
end
|
102
79
|
end
|
metadata
CHANGED
@@ -1,29 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubyboy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sacckey
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-03-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: ffi
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: '1.16'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.16.3
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
27
|
- - "~>"
|
25
28
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
29
|
+
version: '1.16'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.16.3
|
27
33
|
description:
|
28
34
|
email:
|
29
35
|
executables:
|
@@ -61,6 +67,12 @@ files:
|
|
61
67
|
- lib/roms/instr_timing/readme.txt
|
62
68
|
- lib/roms/tobu.gb
|
63
69
|
- lib/rubyboy.rb
|
70
|
+
- lib/rubyboy/apu.rb
|
71
|
+
- lib/rubyboy/apu_channels/channel1.rb
|
72
|
+
- lib/rubyboy/apu_channels/channel2.rb
|
73
|
+
- lib/rubyboy/apu_channels/channel3.rb
|
74
|
+
- lib/rubyboy/apu_channels/channel4.rb
|
75
|
+
- lib/rubyboy/audio.rb
|
64
76
|
- lib/rubyboy/bus.rb
|
65
77
|
- lib/rubyboy/cartridge/factory.rb
|
66
78
|
- lib/rubyboy/cartridge/mbc1.rb
|
@@ -71,8 +83,12 @@ files:
|
|
71
83
|
- lib/rubyboy/lcd.rb
|
72
84
|
- lib/rubyboy/ppu.rb
|
73
85
|
- lib/rubyboy/ram.rb
|
86
|
+
- lib/rubyboy/raylib/audio.rb
|
87
|
+
- lib/rubyboy/raylib/lcd.rb
|
88
|
+
- lib/rubyboy/raylib/raylib_loader.rb
|
74
89
|
- lib/rubyboy/registers.rb
|
75
90
|
- lib/rubyboy/rom.rb
|
91
|
+
- lib/rubyboy/sdl.rb
|
76
92
|
- lib/rubyboy/timer.rb
|
77
93
|
- lib/rubyboy/version.rb
|
78
94
|
- resource/logo/logo.png
|