move loading cartridge from MMU initialize to attr_accessor

This commit is contained in:
Colby 2016-07-17 22:06:15 +10:00
parent 196235bce3
commit 4fa99873e4
2 changed files with 20 additions and 12 deletions

View file

@ -7,7 +7,8 @@ module Waterfoul
# initialize emulated CPU, GPU & Sound components # initialize emulated CPU, GPU & Sound components
cartridge = Cartridge.new rom cartridge = Cartridge.new rom
# initialize emulated memory management unit # initialize emulated memory management unit
$mmu = MMU.new cartridge $mmu = MMU.new
$mmu.cartridge = cartridge
cpu = CPU.new cpu = CPU.new
@cpu = options.has_key?('skip_boot') ? SkipBoot.set_state(cpu) : cpu @cpu = options.has_key?('skip_boot') ? SkipBoot.set_state(cpu) : cpu
@gpu = GPU.new @gpu = GPU.new

View file

@ -18,10 +18,11 @@ module Waterfoul
DIV_MEM_LOC = 0xFF04 DIV_MEM_LOC = 0xFF04
attr_reader :memory attr_reader :memory
attr_accessor :cartridge
# Set the initial state the memory management unit when program starts # Set the initial state the memory management unit when program starts
def initialize(cartridge) def initialize
@cartridge = cartridge @cartridge = []
# flag to indicate if the boot rom is mapped to memory # flag to indicate if the boot rom is mapped to memory
@map_boot_rom = true @map_boot_rom = true
# storage for usable memory (zero filled) # storage for usable memory (zero filled)
@ -58,10 +59,11 @@ module Waterfoul
# Storage 1 byte into memory given address # Storage 1 byte into memory given address
# @param i Integer location in memory to storage value # @param i Integer location in memory to storage value
# @param v Integer value to be written into memory # @param v Integer value to be written into memory
def []=(i, v) def []=(i, v, options = {})
# raise exception if an attempt is made to read memory that is out of bounds # raise exception if an attempt is made to read memory that is out of bounds
raise MemoryOutOfBounds if i > MEMORY_SIZE || i < 0 raise MemoryOutOfBounds if i > MEMORY_SIZE || i < 0
unless options[:hardware_operation]
case i case i
when UNMAP_BOOT_ROM_MEM_LOC when UNMAP_BOOT_ROM_MEM_LOC
# unmap the boot rom when 0xFF50 is wrtiten to in memory # unmap the boot rom when 0xFF50 is wrtiten to in memory
@ -70,6 +72,11 @@ module Waterfoul
@cartridge[i] = v @cartridge[i] = v
when 0xFF46 when 0xFF46
byebug byebug
when 0xFF04 # reset divider register
self[i] = 0
else
@memory[i] = v
end
else else
@memory[i] = v @memory[i] = v
end end