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,3 +1,7 @@
## [1.7.1] - 2026-10-11

- Fix RLC and RRC on memory writing values over a byte, which could stop the Spinel browser build

## [1.7.0] - 2026-10-10

- Require Ruby 4.0 or higher
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.7.0)
rubyboy (1.7.1)
ffi (~> 1.16, >= 1.16.3)

GEM
Expand Down
4 changes: 2 additions & 2 deletions lib/rubyboy/cpu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1071,7 +1071,7 @@ def reti(cycles:)

def rlc8(x, cycles:)
value = get_value(x)
value = (value << 1) | (value >> 7)
value = ((value << 1) | (value >> 7)) & 0xff
set_value(x, value)
update_flags(
z: value == 0,
Expand All @@ -1085,7 +1085,7 @@ def rlc8(x, cycles:)

def rrc8(x, cycles:)
value = get_value(x)
value = (value >> 1) | (value << 7)
value = ((value >> 1) | (value << 7)) & 0xff
set_value(x, value)
update_flags(
z: value == 0,
Expand Down
2 changes: 1 addition & 1 deletion lib/rubyboy/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Rubyboy
VERSION = '1.7.0'
VERSION = '1.7.1'
end
29 changes: 29 additions & 0 deletions spec/rubyboy/cpu_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# frozen_string_literal: true

RSpec.describe Rubyboy::Cpu do
let(:memory) { Array.new(0x10000, 0) }
let(:cpu) do
bus = instance_double(Rubyboy::Bus)
allow(bus).to receive(:read_byte) { |addr| memory[addr] }
allow(bus).to receive(:read_word) { |addr| memory[addr] | (memory[addr + 1] << 8) }
allow(bus).to receive(:write_byte) { |addr, value| memory[addr] = value }
described_class.new(bus, Rubyboy::Interrupt.new)
end

# LD HL, 0xc000, then the CB-prefixed rotate eight times: the byte comes back.
def rotate_hl_eight_times(cb_opcode, value)
program = [0x21, 0x00, 0xc0] + ([0xcb, cb_opcode] * 8)
memory[0x0100, program.size] = program
memory[0xc000] = value
9.times { cpu.exec }
memory[0xc000]
end

it 'keeps RLC (HL) within a byte' do
expect(rotate_hl_eight_times(0x06, 0x81)).to eq(0x81)
end

it 'keeps RRC (HL) within a byte' do
expect(rotate_hl_eight_times(0x0e, 0x81)).to eq(0x81)
end
end
Loading