Building blocks for copying and transferring data between different types of memory devices.
More...
|
file | mem_rw.h |
| Stream like access functions for ROM / RAM.
|
|
|
bool | mem_is_opened (void) |
| Tests whether ROM/RAM accessor is opened or not.
|
|
void | mem_open (uint8_t *loc) |
| Open ROM/RAM accessor.
|
|
void | mem_close (void) |
| Close ROM/RAM accessor.
|
|
void | mem_dup (uint16_t offset, size_t len) |
| Duplicate a sequence of bytes beginning at the specified offset in the output stream at the current position or later.
|
|
uint8_t * | mem_ptr (void) |
| Get current position of ROM/RAM accessor.
|
|
bool | mem_is_in_free_area (uint8_t *p, size_t len) |
| Tests whether the specified range is in free area.
|
|
void | mem_write_chunk (const uint8_t *src, size_t len) |
| Write a chunk to RAM.
|
|
void | mem_read_chunk (uint8_t *dst, size_t len) |
| Read a chunk from ROM/RAM.
|
|
void | mem_write_byte (uint8_t x) |
| Write an octet to RAM.
|
|
uint8_t | mem_read_byte (void) |
| Read an octet from ROM/RAM.
|
|
Building blocks for copying and transferring data between different types of memory devices.
#include <mem_rw.h>
◆ mem_is_opened()
bool mem_is_opened |
( |
void |
| ) |
|
Tests whether ROM/RAM accessor is opened or not.
- Returns
- whether ROM/RAM accessor is opened or not.
◆ mem_open()
void mem_open |
( |
uint8_t * |
loc | ) |
|
Open ROM/RAM accessor.
- Parameters
-
- Precondition
!mem_is_opened()
◆ mem_close()
◆ mem_dup()
void mem_dup |
( |
uint16_t |
offset, |
|
|
size_t |
len |
|
) |
| |
Duplicate a sequence of bytes beginning at the specified offset in the output stream at the current position or later.
A data in range of [p - offset, p - offset + len)
of RAM/ROM will be copied to [p, p + len)
, where p
is current position. If both area overlaps, repetition is occur.
For example, if the byte in p-1
is X
, then mem_dup(1, 3)
copies X
to p
, p+1
, p+2
and p
is increased by 3
.
- Parameters
-
offset | distance from the current position. |
length | length in bytes. |
- Precondition
mem_is_opened()
◆ mem_ptr()
uint8_t * mem_ptr |
( |
void |
| ) |
|
Get current position of ROM/RAM accessor.
- Returns
- current position.
- Precondition
mem_is_opened()
◆ mem_is_in_free_area()
bool mem_is_in_free_area |
( |
uint8_t * |
p, |
|
|
size_t |
len |
|
) |
| |
Tests whether the specified range is in free area.
- Parameters
-
p | base address of the range. |
len | length the range in bytes. |
- Returns
true
if the range is in [0xc000
, (HIMEM)
), otherwise false
.
- Note
- This function just checks that the specified area is in range of free area. No data is written to the memory.
-
Page #
0
..#2
(0x0000
..0xbfff
) are ROM.
-
HIMEM
points the lowest address of reserved area. (out of free area)
-
DATA segment, HEAP, and stack area are in the free area.
-
Address
0xffff
is not memory, that is "extended slot selector" register.
- Attention
- When writing to memory, the stack area or work area is overwritten (broken) if it intersects the destination area. Unfortunately, however, the library cannot determine the proper boundaries. This must be addressed by the application programmer.
◆ mem_write_chunk()
void mem_write_chunk |
( |
const uint8_t * |
src, |
|
|
size_t |
len |
|
) |
| |
Write a chunk to RAM.
- Parameters
-
src | source base address. |
len | number of bytes to be copied. |
- Precondition
mem_is_opened()
- Note
- The destination [
mem
, mem+len
) must be in range of [0xc000
, (HIMEM)
), where mem
is the current position.
◆ mem_read_chunk()
void mem_read_chunk |
( |
uint8_t * |
dst, |
|
|
size_t |
len |
|
) |
| |
Read a chunk from ROM/RAM.
- Parameters
-
dst | destination base address. |
len | number of bytes to be copied. |
- Precondition
mem_is_opened()
- Note
- The destination [
dst
, dst+len
) must be in range of [0xc000
, (HIMEM)
).
◆ mem_write_byte()
void mem_write_byte |
( |
uint8_t |
x | ) |
|
Write an octet to RAM.
- Parameters
-
x | a value to be written to RAM. |
- Note
- The current position must be in range of [
0xc000
, (HIMEM)
).
◆ mem_read_byte()
uint8_t mem_read_byte |
( |
void |
| ) |
|
Read an octet from ROM/RAM.
- Returns
- a value read from ROM/RAM.
- Precondition
mem_is_opened()