Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## [Unreleased]

## [1.4.1] - 2024-12-25

- PPU performance optimization through data caching and pixel format changes

## [1.4.0] - 2024-09-29

- Works on browser using ruby.wasm
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
rubyboy (1.4.0)
rubyboy (1.4.1)
ffi (~> 1.16, >= 1.16.3)

GEM
Expand Down
2 changes: 1 addition & 1 deletion lib/executor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def initialize
end

def exec(direction_key = 0b1111, action_key = 0b1111)
bin = @emulator.step(direction_key, action_key).pack('C*')
bin = @emulator.step(direction_key, action_key).pack('V*')
File.binwrite(File.join('/RUBYBOY_TMP', 'video.data'), bin)
end

Expand Down
1 change: 1 addition & 0 deletions lib/rubyboy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require 'rubyboy/sdl'
require_relative 'rubyboy/apu'
require_relative 'rubyboy/audio'
require_relative 'rubyboy/bus'
require_relative 'rubyboy/cpu'
require_relative 'rubyboy/emulator'
Expand Down
8 changes: 4 additions & 4 deletions lib/rubyboy/apu.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# frozen_string_literal: true

require_relative 'audio'
require_relative 'apu_channels/channel1'
require_relative 'apu_channels/channel2'
require_relative 'apu_channels/channel3'
require_relative 'apu_channels/channel4'

module Rubyboy
class Apu
attr_reader :samples

def initialize
@audio = Audio.new
@nr50 = 0
@nr51 = 0
@cycles = 0
Expand Down Expand Up @@ -67,10 +67,10 @@ def step(cycles)
@sample_idx += 1
end

return if @sample_idx < 512
return false if @sample_idx < 512

@sample_idx = 0
@audio.queue(@samples)
true
end

def read_byte(addr)
Expand Down
118 changes: 0 additions & 118 deletions lib/rubyboy/apu_wasm.rb

This file was deleted.

3 changes: 2 additions & 1 deletion lib/rubyboy/emulator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def initialize(rom_path)
@bus = Bus.new(@ppu, rom, ram, mbc, @timer, interrupt, @joypad, @apu)
@cpu = Cpu.new(@bus, interrupt)
@lcd = Lcd.new
@audio = Audio.new
end

def start
Expand All @@ -31,7 +32,7 @@ def start
while elapsed_real_time > elapsed_machine_time
cycles = @cpu.exec
@timer.step(cycles)
@apu.step(cycles)
@audio.queue(@apu.samples) if @apu.step(cycles)
if @ppu.step(cycles)
@lcd.draw(@ppu.buffer)
key_input_check
Expand Down
8 changes: 4 additions & 4 deletions lib/rubyboy/emulator_wasm.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# frozen_string_literal: true

require_relative 'apu_wasm'
require_relative 'apu'
require_relative 'bus'
require_relative 'cpu'
require_relative 'emulator'
require_relative 'ppu_wasm'
require_relative 'ppu'
require_relative 'rom'
require_relative 'ram'
require_relative 'timer'
Expand All @@ -22,10 +22,10 @@ def initialize(rom_data)
ram = Ram.new
mbc = Cartridge::Factory.create(rom, ram)
interrupt = Interrupt.new
@ppu = PpuWasm.new(interrupt)
@ppu = Ppu.new(interrupt)
@timer = Timer.new(interrupt)
@joypad = Joypad.new(interrupt)
@apu = ApuWasm.new
@apu = Apu.new
@bus = Bus.new(@ppu, rom, ram, mbc, @timer, interrupt, @joypad, @apu)
@cpu = Cpu.new(@bus, interrupt)
end
Expand Down
8 changes: 4 additions & 4 deletions lib/rubyboy/lcd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ class Lcd
def initialize
raise SDL.GetError() if SDL.InitSubSystem(SDL::INIT_VIDEO) != 0

@buffer = FFI::MemoryPointer.new(:uint8, SCREEN_WIDTH * SCREEN_HEIGHT * 3)
@buffer = FFI::MemoryPointer.new(:uint32, SCREEN_WIDTH * SCREEN_HEIGHT)
@window = SDL.CreateWindow('Ruby Boy', 0, 0, SCREEN_WIDTH * SCALE, SCREEN_HEIGHT * SCALE, SDL::SDL_WINDOW_RESIZABLE)

raise SDL.GetError() if @window.null?

@renderer = SDL.CreateRenderer(@window, -1, 0)
SDL.SetHint('SDL_HINT_RENDER_SCALE_QUALITY', '2')
SDL.RenderSetLogicalSize(@renderer, SCREEN_WIDTH * SCALE, SCREEN_HEIGHT * SCALE)
@texture = SDL.CreateTexture(@renderer, SDL::PIXELFORMAT_RGB24, 1, SCREEN_WIDTH, SCREEN_HEIGHT)
@texture = SDL.CreateTexture(@renderer, SDL::PIXELFORMAT_ABGR8888, 1, SCREEN_WIDTH, SCREEN_HEIGHT)
@event = FFI::MemoryPointer.new(:pointer)
end

def draw(framebuffer)
@buffer.write_array_of_uint8(framebuffer)
SDL.UpdateTexture(@texture, nil, @buffer, SCREEN_WIDTH * 3)
@buffer.write_array_of_uint32(framebuffer)
SDL.UpdateTexture(@texture, nil, @buffer, SCREEN_WIDTH * 4)
SDL.RenderClear(@renderer)
SDL.RenderCopy(@renderer, @texture, nil, nil)
SDL.RenderPresent(@renderer)
Expand Down
Loading
Loading