Class: Zemu::Config::Memory
- Inherits:
-
BusDevice
- Object
- Zemu::ConfigObject
- BusDevice
- Zemu::Config::Memory
- Defined in:
- lib/zemu/config.rb
Overview
Memory object.
This is an abstract class from which all other memory objects inherit.
Instance Method Summary collapse
-
#contents(*args) ⇒ Object
Gets or sets an array of bytes representing the initial state of this memory block.
-
#from_binary(file) ⇒ Object
Reads the contents of a file in binary format and returns them as an array.
-
#initialize ⇒ Memory
constructor
Constructor.
-
#mem_read(addr) ⇒ Object
Memory bus read handler.
-
#mem_write(addr, value) ⇒ Object
Memory bus write handler.
-
#memory ⇒ Object
Parameters used for generating C code to implement this memory block.
-
#params ⇒ Object
Valid parameters for this object.
-
#readonly? ⇒ Boolean
Is this memory read-only?.
Methods inherited from BusDevice
#clock, #functions, #interrupt, #interrupt?, #io_read, #io_write, #nmi, #nmi?, #when_setup
Methods inherited from Zemu::ConfigObject
Constructor Details
#initialize ⇒ Memory
Constructor.
Do not use, as this is an abstract class. Use one of the subclasses instead.
200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/zemu/config.rb', line 200 def initialize if self.class == Zemu::Config::Memory raise NotImplementedError, "Cannot construct an instance of the abstract class Zemu::Config::Memory." end @contents = [] super # Pad contents with 0x00 bytes. (@size - @contents.size).times do @contents << 0x00 end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Zemu::ConfigObject
Instance Method Details
#contents(*args) ⇒ Object
Gets or sets an array of bytes representing the initial state of this memory block.
217 218 219 220 221 222 223 |
# File 'lib/zemu/config.rb', line 217 def contents(*args) if args.size.zero? return @contents else @contents = args[0] end end |
#from_binary(file) ⇒ Object
Reads the contents of a file in binary format and returns them as an array.
285 286 287 288 289 290 291 292 293 |
# File 'lib/zemu/config.rb', line 285 def from_binary(file) return File.open(file, "rb") do |f| bin = [] f.each_byte { |b| bin << b } bin end end |
#mem_read(addr) ⇒ Object
Memory bus read handler.
Handles read access via the memory bus to this device.
Returns the value read, or nil if no value (e.g. if address falls outside range for this device).
264 265 266 |
# File 'lib/zemu/config.rb', line 264 def mem_read(addr) nil end |
#mem_write(addr, value) ⇒ Object
Memory bus write handler.
Handles write access via the memory bus to this device.
274 275 |
# File 'lib/zemu/config.rb', line 274 def mem_write(addr, value) end |
#memory ⇒ Object
Parameters used for generating C code to implement this memory block.
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/zemu/config.rb', line 232 def memory contents_initializer = "" @contents.each_slice(32) do |c| contents_initializer += c.map { |b| b.to_s }.join(", ") contents_initializer += ",\n" end m = OpenStruct.new m.setup = "zuint8 memory_\#{name}[\#{size}] =\n{\n \#{contents_initializer}\n};\n" m.address = address m.size = size m.access_read = "memory_#{name}" m.access_write = "memory_#{name}" m end |
#params ⇒ Object
Valid parameters for this object. Should be extended by subclasses but NOT REPLACED.
279 280 281 |
# File 'lib/zemu/config.rb', line 279 def params super + %w(address size) end |
#readonly? ⇒ Boolean
Is this memory read-only?
226 227 228 |
# File 'lib/zemu/config.rb', line 226 def readonly? false end |