From cb787edf43c0f8792168034d9a008b38ef30fb48 Mon Sep 17 00:00:00 2001 From: Colby Swandale Date: Mon, 26 Sep 2016 23:01:01 +1000 Subject: [PATCH] simplify MBC ROM spec and make have reader for ROM ram --- lib/waterfoul/mbc/rom.rb | 8 +++++--- spec/mbc/rom_spec.rb | 35 ++++++++--------------------------- 2 files changed, 13 insertions(+), 30 deletions(-) diff --git a/lib/waterfoul/mbc/rom.rb b/lib/waterfoul/mbc/rom.rb index 2484c69..1724292 100644 --- a/lib/waterfoul/mbc/rom.rb +++ b/lib/waterfoul/mbc/rom.rb @@ -3,15 +3,17 @@ module Waterfoul class ROM EXTERNAL_RAM_SIZE = 0x1FFF + attr_reader :ram + def initialize(program) - @external_ram = Array.new EXTERNAL_RAM_SIZE, 0 + @ram = Array.new EXTERNAL_RAM_SIZE, 0 @program = program end def [](i) case i when 0xA000...0xC000 - @external_ram[i - 0xA000] + @ram[i - 0xA000] else @program[i] end @@ -20,7 +22,7 @@ module Waterfoul def []=(i,v) case i when 0xA000...0xC000 - @external_ram[i - 0xA000] = v + @ram[i - 0xA000] = v end end end diff --git a/spec/mbc/rom_spec.rb b/spec/mbc/rom_spec.rb index db40431..4c937e2 100644 --- a/spec/mbc/rom_spec.rb +++ b/spec/mbc/rom_spec.rb @@ -2,39 +2,20 @@ require 'spec_helper' describe Waterfoul::MBC::ROM do - let(:game_program) { double :game_program } - let(:eram) { double :eram } - - subject { Waterfoul::MBC::ROM.new game_program, eram } + let(:game_program) { Array.new 65_536, 0 } + subject { Waterfoul::MBC::ROM.new game_program } describe '#[]' do - let(:addr) { 0xA1B } - it 'reads byte at given addr' do - expect(game_program).to receive(:[]).with(addr) - subject[addr] - end - - context 'reading from external address space' do - let(:addr) { 0xA1FB } - it 'reads byte from external memory' do - expect(eram).to receive(:[]).with(addr) - subject[addr] - end - - context 'writing to addr 0x123' do - let(:addr) { 0x1 } - it 'raises an error writng to forbidden space' do - allow(eram).to receive(:[]=) - expect { subject[addr] = 5 }.to raise_error - end - end + before { game_program[0x151] = 0x51 } + it 'reads byte at address from the game program' do + expect(subject[0x151]).to eq 0x51 end end describe '#[]=' do - it 'writes byte to external ram with 0xA000 offset' do - expect(eram).to receive(:[]=).with(0x1BF, 5) - subject[0xA1BF] = 5 + it 'stores byte in external ram' do + subject[0xA001] = 0x8F + expect(subject.ram[0x1]).to eq 0x8F end end end