Memory device

This is the user manual for the memory device of the Bedrock computer system.

This document is aimed at people who are learning about or writing programs for the Bedrock system. For people who are implementing the system from scratch, the memory device specification will provide more relevant information.

Overview

The memory device provides access to up to 16 megabytes of additional working memory. This memory is handled separately from the program memory used by the Bedrock system.

Concepts

Memory is allocated to a single contiguous pool in blocks of 256 bytes, called pages. This is done by writing the number of pages required to the count port. The largest amount of memory that can be allocated at one time is 65535 pages, or almost 16 megabytes.

There are two read-write heads that both access the same pool of allocated memory. The read-write heads have separate address values, which means that a byte can be read from one region of memory and written to a different region without having to change addresses. The first half of the device controls the first read-write head, and the second half controls the second head.

Each read-write head has a page offset value and an address offset value, which are used together to determine the address of each head. The page offset determines the page of memory to start addressing from, and the address offset determines the number of bytes to add to that address. For most purposes, the page offset will be locked to one value, and the address offset will be used to move around inside the following 65536 byte region.

Each read-write head also has a head port, used for reading or writing bytes to memory through that head. Each read or write operation will increment the address offset of that head, so that successive bytes will be accessed with each operation.

Pages of memory can be copied in bulk with the copy port.

Ports

Port Name Description Read Write
10 Count Number of pages allocated.
11 grouped grouped
12 Page offset Page offset of first head.
13 grouped grouped
14 Address offset Address offset of first head.
15 grouped grouped
16 Head Read and write with first head.
17 aliased aliased
18 Copy Copy one page to another.
19 grouped grouped
1A Page offset Page offset of second head.
1B grouped grouped
1C Address offset Address offset of second head.
1D grouped grouped
1E Head Read and write with second head.
1F aliased aliased

Count

Writing a double to this port will request for that many pages of memory to be allocated for use, with each page being a 256 byte block of memory. If the system can’t allocate enough memory, it will still try to allocate as much as it can.

Reading a double from this port will return the number of pages currently allocated.

See the allocating memory example.

Page offset

There are two page offset port groups, one for each read-write head. Reading a double from one of these ports will return the page offset of that head, and writing a double will set the page offset.

See the setting the address example.

Address offset

There are two address offset port groups, one for each read-write head. Reading a double from one of these ports will return the address offset of that head, and writing a double will set the address offset.

See the setting the address example.

There are two head port groups, one for each read-write head. Reading a byte from one of these ports will read a byte of memory through that head, and writing a byte will set a byte of memory through that same head. Each read or write will increment the page offset of that head, so that successive bytes will be accessed with each operation.

Each head port is followed by a port alias, allowing double values to be read or written with a single instruction.

See the reading and writing example.

Copy

Writing a double to this port will request for that many pages of memory to be copied from the second head to the first head. The page offset of the second head marks the initial page to copy, and the page offset of the first head marks the initial page to be overwritten. Pages are copied sequentially until all requested pages have been copied.

Wake behaviour

This device will never wake the system from sleep.

Examples

Allocating memory

Memory must be allocated before it can be used. To allocate memory, write the total number of pages required to the count port, and then read back the value to check that the system was able to allocate the full amount:

*:0002   ( 0002 ) ( 2 pages, or 512 bytes         )
STD*:10  (      ) ( write value to the count port )
LDD*:10  ( 0002 ) ( check if allocation succeeded )

Setting the address

The address of each read-write head is determined by the page offset and address offset ports of that head. The page offset determines the page to start from, and the address offset will offset a number of bytes from the start of that page. The following example shows two different ways to set the address of the first read-write head to 0180:

*:0000 STD*:12  (   page 0000 )
*:0180 STD*:14  ( offset 0180 )

*:0001 STD*:12  (   page 0001 )
*:0080 STD*:14  ( offset 0080 )

Reading and writing

The head ports are used to read or write bytes to memory. Each read or write will increment the address offset of that head, so the address offset will need to be reset before we can read back the bytes that were written:

*:0001 STD*:10  ( allocate 1 page           )

*:0000 STD*:12  ( set page offset to 0      )
*:0000 STD*:14  ( set address offset to 0   )

:01 STD:16      ( memory is 01 00 00 00 ... )
:02 STD:16      ( memory is 01 02 00 00 ... )
*:0304 STD*:16  ( memory is 01 02 03 04 ... )

*:0000 STD*:14  ( reset address offset to 0 )

LDD:16          ( stack is 01               )
LDD:16          ( stack is 01 02            )
LDD*:16         ( stack is 01 02 03 04      )