mirror of
https://github.com/colby-swandale/waterfoul
synced 2025-01-29 20:34:21 +01:00
simplify MBC ROM spec and make have reader for ROM ram
This commit is contained in:
parent
365724a3b5
commit
cb787edf43
2 changed files with 13 additions and 30 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue