Skip to main content

Using Paged RAM

Source

Adapted from Using paged RAM.

Classic Spectranet hardware provides general-purpose memory in addition to the Ethernet interface: 128K of flash ROM and 128K of static RAM. The paged memory is organized as 4K pages within a 1MB address space.

Paging areas​

When Spectranet memory is paged in, two 4K pages are fixed:

  • flash at 0x0000 to 0x0FFF
  • SRAM at 0x3000 to 0x3FFF

Between them are two programmable paging areas:

  • area A: 0x1000 to 0x1FFF
  • area B: 0x2000 to 0x2FFF

Spectranet ROM functions often use area A for data-like pages, such as W5100 buffers or character data, and area B for executable code. This is a convention rather than a hard hardware rule.

Paging memory in​

Prefer ROM routines over direct port writes. The public routines setpagea and setpageb select the page for area A or B and update Spectranet system variables. The pushpagea/poppagea and corresponding area B routines save and restore previous mappings.

Assembly example:

ld a, 0xC2
call SETPAGEA

C example:

setpagea(0xC2);

The current pages are stored in Spectranet system variables v_pga and v_pgb.

Page-in and page-out​

Programs running from main Spectrum RAM can page Spectranet memory in with:

call PAGEIN

This must be a real CALL to the page-in entry point because the CPLD decodes the CALL instruction. Conditional calls or jumps do not perform the same operation.

Spectranet memory is paged out with:

call PAGEOUT

Calling routines while paged in​

If Spectranet memory must remain visible, do not use HLCALL or IXCALL, because those gateways page out after the call. Instead, page in once and call the jump table routine directly:

call PAGEIN
ld c, SOCK_STREAM
call SOCKET
call PAGEOUT

C programs that run in this state should link against the non-paging library variants.

Reading and writing RAM​

Once a SRAM page is mapped into an address range, it is accessed like normal memory. Ordinary Z80 loads and stores work as they do with Spectrum RAM.