Class: RPicSim::Memory
- Inherits:
-
Object
- Object
- RPicSim::Memory
- Defined in:
- lib/rpicsim/memory.rb
Overview
This object allows read and write access to the data currently stored in a memory space of the simulated device. Instances are usually retrieved from a Sim object by calling Sim#ram, Sim#program_memory, or Sim#eeprom.
The behavior of read_word
and write_word
differs
depending on what kind of Memory is being used, as shown in the table
below:
Memory type Address type Read/write chunk for word methods
RAM and EEPROM: Byte address 1 byte (8 bits)
PIC18 program memory: Byte address 1 word (16 bits)
Non-PIC18 program memory: Word address 1 word (12 or 14 bits)
The read_byte
and write_byte
methods use the same
type of address as read_word
and write_word
, but
they can only read and write from the lower 8 bits of the word. The upper
bits of the word, if there are any, are left unchanged. For RAM and EEPROM,
read_byte
and write_byte
behave the same way as
read_word
and write_word
.
For more information, see Memories.
Instance Method Summary collapse
-
#read_byte(address) ⇒ Integer
Reads the byte in memory at the specified address.
-
#read_bytes(address, size) ⇒ Array(Integer)
Reads a series of bytes from the simulated memory using
read_byte
and returns them as an array. -
#read_word(address) ⇒ Integer
Reads the word in memory at the specified address.
-
#valid_address?(address) ⇒ Boolean
Returns true if the specified address is valid.
-
#write_byte(address, value) ⇒ Object
Writes the given integer to the byte in memory at the specified address.
-
#write_bytes(address, bytes) ⇒ Object
Writes a series of bytes to the simulated memory.
-
#write_word(address, value) ⇒ Object
Writes the given integer to the word in memory at the specified address.
Instance Method Details
#read_byte(address) ⇒ Integer
Reads the byte in memory at the specified address.
37 38 39 |
# File 'lib/rpicsim/memory.rb', line 37 def read_byte(address) @mplab_memory.read_byte(address) end |
#read_bytes(address, size) ⇒ Array(Integer)
Reads a series of bytes from the simulated memory using
read_byte
and returns them as an array.
76 77 78 |
# File 'lib/rpicsim/memory.rb', line 76 def read_bytes(address, size) size.times.map { |i| read_byte(address + i) } end |
#read_word(address) ⇒ Integer
Reads the word in memory at the specified address.
52 53 54 |
# File 'lib/rpicsim/memory.rb', line 52 def read_word(address) @mplab_memory.read_word(address) end |
#valid_address?(address) ⇒ Boolean
Returns true if the specified address is valid.
66 67 68 |
# File 'lib/rpicsim/memory.rb', line 66 def valid_address?(address) @mplab_memory.valid_address?(address) end |
#write_byte(address, value) ⇒ Object
Writes the given integer to the byte in memory at the specified address.
45 46 47 |
# File 'lib/rpicsim/memory.rb', line 45 def write_byte(address, value) @mplab_memory.write_byte(address, value) end |
#write_bytes(address, bytes) ⇒ Object
Writes a series of bytes to the simulated memory.
84 85 86 87 88 |
# File 'lib/rpicsim/memory.rb', line 84 def write_bytes(address, bytes) bytes = bytes.bytes if bytes.is_a?(String) bytes.each_with_index { |b, i| write_byte(address + i, b) } nil end |
#write_word(address, value) ⇒ Object
Writes the given integer to the word in memory at the specified address.
59 60 61 |
# File 'lib/rpicsim/memory.rb', line 59 def write_word(address, value) @mplab_memory.write_word(address, value) end |