Spectrum Memory                     Rampack


When Sinclair first announced the Spectrum in 1982 there were 2 models, 16K and 48K. Meaning that they had 16 and 48 kilobytes of Random Access Memory (RAM) respectively. They also had 16K of Read Only Memory (ROM).

As the name read only suggests, ROM contents were fixed. The ROM contained all the code and information the Spectrum needed to edit and run Basic programs. RAM was the area you (the programmer) could use to store information, though some of it was reserved for specific purposes.

FromToInformation
016383
#3FFF
ROM - all the code and info needed to edit and run Sinclair Basic
16384
#4000
22527
#
Screen pixel data, each row of 32 bytes decides whether each pixel on a screen line is INK or PAPER (foreground or background colour). The sequence is a bit fiddly for the human brain, the first 32 bytes represents the top line from left to right, the next 32 bytes represents the 8th line from the top, then the 16th, 24th, 32nd, 40th, 48th, 56th and then .... the 2nd line from the top, 9th, 17th .... told you it was fiddly. Then when it's completed the top 64 rows (a 3rd of the screen), it starts again with the 65th row and fills the 2nd third of the screen, then it does the erm.... third third. No really, that's how it is. There's an animation below showing screen data being slowly loaded from tape that might make it a bit clearer: Or not
22528
#
23295
#
Screen colour (Attribute) data - each byte decides the INK colour, PAPER colour, BRIGHTNESS and FLASH setting for an 8 x 8 pixel square, alternatively a character cell. The first 32 bytes set the colour for the top row, the next 32 for the 2nd row and so on in a nice ordely fashion for all 24 rows.

#5B00

#5BFF
From here to available memory you have the area used by the ROM to manage your Basic environment. You write your own data here, but only if you are willing to go "offroad" - run machine code, switch off standard interrupts and you have no plans to use the ROM without restarting your computer.
Printer buffer, used to send data to (by design) the ZX Printer. Other printers were available.

#5C00

#5CBF
System variables, used by the ROM to keep track of what's going on with your Basic program, the screen settings and oher things. Set the wrong value here from Basic and you can get some interesting crashes.

#5CC0

#5CCA
A little bit more reserved space

#5CCB
32767
#7FFF
Free space on your 16K machine. Actually that's not entirely true, 7F58 upwards (or the last 167 bytes)  would be the small space reserved called RAMTOP, which can be moved to say 30000 by using the command CLEAR 30000. 
32768
#8000
65536
#FFFF
The additional 32K free on a 48K machine, again by default the last few bytes reserved for RAMTOP by default but can be moved using the CLEAR command

RAMTOP was designed to set a boundary between your BASIC program and space where you might want to store addtitional date for machine code or POKE / PEEK commands (to store a value in an address or read it). But move it down too much and you may not have room for that extra line of Basic or to setup another Basic variable.
(or the last
Now the memory map mentioned that awkward screen layout. Here's an animated image of a screen loading so you can see how the screen data is laid out. Those of you who used the Spectrum back in the day will hear the loading noise as you watch this.

Cybernoid 
This is loading byte by byte through the screen memory, first row 0, then row 8, then rows 16, 24 ,32 40, 48, 56 then it moves on to row 1, 9, 17 until the first 3rd of the screen is filled. Then the next two thirds, then the colour info.

If you're using Basic Print, or someone else's code to move things around screen, this screen layout is just an SEP (Somebody Else's Problem), but if you want to write machine code to move something pixel by pixel then you'll need to get to grips with it. So it helps to see exactly how the screen loads, byte by byte, through the 6k of pixel data then the 768 bytes of ATTR (colour) data.

Under the assembly tips we can include some of the many different approaches to updating the screen.





128K machines

The Z80A processor in the Spectrum uses 16 bits for addressing, which means it can access address 0 to 65535 (or 64 Kilobytes). To access any more memory you need to instruct the computer to swap around 16K memory blocks by making an OUT to port &7FFD

There were subtle differences about which block can go where between the 1st two 128K models (the "Toastrack and the +2") and later models. But since I don't really understand either paging system I'll wait until one of the following