Screen Modes
Description
There are four screen modes, the special file type for SCREEN$ contains the screen data appended with Palette data and line palette changes when saving on tape or disk.
To locate the base memory address of the currently displayed screen from the Video Memory Page Register (VMPR - port 252) you can use the following from BASIC:
LET SCREENADDR = ((IN 252 BAND 31)+1)*16384
Mode 1
Palette of 16 colours chosen from 128
32x24 cells, each cell with 2 colour capability in 8x8 pixels, attribute compatible with ZX Spectrum
Mode 1 screen byte: 76543210 =bit number xxxxxxxx =bit specifies the CLUT selection of paper(0) or pen(1) from the corresponding attribute 01234567 =pixel x-position (from left to right)
Screen Data: 6144 bytes
Attributes: 768 bytes
Palette Data: min. 41 bytes (when saving as SCREEN$ only)
The first 6912 bytes are the same as the ZX Spectrum (.SCR format) with additional bytes for Sam's palette data appended to this.
Details from http://www.zx-modules.de/fileformats/scrformat.html (Via WayBack Machine)
A MODE1 screen is split into 3 thirds which describe the pixels areas in pixel line blocks. After the 3 thirds containing pixel line blocks, the attribute area follows.
All Screen Data (6912 bytes):
Offset: | Field type: | Length: | Description: | Additional information: |
0 | Screen Third #1 | 2048 | Top 8 char lines of the screen | 256 x 64 pixels (pixel line 0..63) |
2048 | Screen Third #2 | 2048 | Center 8 char lines of the screen | 256 x 64 pixels (pixel line 64..127) |
4096 | Screen Third #3 | 2048 | Bottom 8 char lines of the screen | 256 x 64 pixels (pixel line 128..191) |
6144 | Colour attributes | 768 |
Bit 7 - Flash |
colour attributes of whole screen (32 x 24 characters) each byte covers colours for 8 x 8 pixels or one character. |
For each Screen Third (2048 bytes) covering 256x64 pixels:
Offset: | Field type: | Length: | Description: | Additional information: |
0 | Pixel Line Block #1 | 256 | covers 8 char lines | pixel lines 0, 8, 16, 24, 32, 40, 48, 56 |
256 | Pixel Line Block #2 | 256 | covers 8 char lines | pixel lines 1, 9, 17, 25, 33, 41, 49, 57 |
512 | Pixel Line Block #3 | 256 | covers 8 char lines | pixel lines 2, 10, 18, 26, 34, 42, 50, 58 |
768 | Pixel Line Block #4 | 256 | covers 8 char lines | pixel lines 3, 11, 19, 27, 35, 43, 51, 59 |
1024 | Pixel Line Block #5 | 256 | covers 8 char lines | pixel lines 4, 12, 20, 28, 36, 44, 52, 60 |
1280 | Pixel Line Block #6 | 256 | covers 8 char lines | pixel lines 5, 13, 21, 29, 37, 45, 53, 61 |
1536 | Pixel Line Block #7 | 256 | covers 8 char lines | pixel lines 6, 14, 22, 30, 38, 46, 54, 62 |
1792 | Pixel Line Block #8 | 256 | covers 8 char lines | pixel lines 7, 15, 23, 31, 39, 47, 55, 63 |
And finally for Pixel Line Block (256 bytes) covering 256x8 pixels:
Offset: | Field type: | Length: | Description: | Additional information: |
0 | 32 | Xth pixel line of 1st char line | screen line (256 x 1 pixels) | |
32 | 32 | Xth pixel line of 2nd char line | screen line (256 x 1 pixels) | |
64 | 32 | Xth pixel line of 3rd char line | screen line (256 x 1 pixels) | |
96 | 32 | Xth pixel line of 4th char line | screen line (256 x 1 pixels) | |
128 | 32 | Xth pixel line of 5th char line | screen line (256 x 1 pixels) | |
160 | 32 | Xth pixel line of 6th char line | screen line (256 x 1 pixels) | |
192 | 32 | Xth pixel line of 7th char line | screen line (256 x 1 pixels) | |
224 | 32 | Xth pixel line of 8th char line | screen line (256 x 1 pixels) |
The screen thirds, pixel line blocks and attributes can be easliy seen when loading from tape such as this example on the ZX Spectrum loading Jetpac.
SCREEN$ files are a minimum of 6953 bytes in size depending on the amount of stored line palette changes.
File extension as used on other platforms .ss1
Mode 2
Palette of 16 colours chosen from 128
32x192 cells, each cell with 2 colour capability in 8x1 pixels
Pixel data is stored contigously (in contrast to MODE 1) as individual bits in groups of 8 with MSB being the first pixel of the group through LSB being the last. This data is then padded with 2Kbytes to the 8Kb boundry before the 8x1 attribute data
Mode 2 screen byte: 76543210 =bit number xxxxxxxx =bit specifies the CLUT selection of paper(0) or pen(1) from the corresponding attribute 01234567 =pixel x-position (from left to right)
Screen Data: 6144 bytes
Padding: 2048 bytes
Attributes: 6144 bytes
Palette Data: min. 41 bytes (when saving as SCREEN$ only)
Offset: | Field type: | Length: | Description: | Additional information: |
0 | Screen Data | 6144 | All screen pixels | 256 x 192 pixels |
6144 | Padding | 2048 | Ignored | |
8192 | Colour attributes | 6144 |
Bit 4-7 Paper |
colour attributes of whole screen (32 x 192 cells) each byte covers colours for 8 x 1 pixels |
SCREEN$ files are a minimum of 14377 bytes in size depending on the amount of stored line palette changes.
File extension as used on other platforms .ss2
Mode 3
Palette of 4 colours chosen from 128
512x192 individual pixels
Each byte holds four 2-bit colour values for four pixels
Mode 3 screen byte: 76 54 32 10 =bit number 01 01 01 01 =bit number for CLUT select (%01 for Color 2) 0 1 2 3 =pixel x-position (from left to right)
Screen Data: 24576 bytes
Palette Data: min. 41 bytes (when saving as SCREEN$ only)
SCREEN$ files are a minimum of 24617 bytes in size depending on the amount of stored line palette changes.
File extension as used on other platforms .ss3
Mode 4
Palette of 16 colours chosen from 128
256x192 individual pixels
Each byte holds two 4-bit colour values for two pixels
Mode 4 screen byte: 7654 3210 =bit number 3210 3210 =bit number for CLUT select (%0001 for Color 1) 0 1 =pixel x-position (from left to right)
Screen Data: 24576 bytes
Palette Data: min. 41 bytes (when saving as SCREEN$ only)
SCREEN$ files are a minimum of 24617 bytes in size depending on the amount of stored line palette changes.
File extension as used on other platforms .ss4
Pixel and Palette Data
Code file details from Anton Javorček
Sam Screen$ mode 3 or 4:
24576 bytes -videoram data
41 bytes palettes data
where (41=16+4+16+4+0*4+1):
16 bytes Palette for Flash 0
4 bytes mode3 SwapPalette for Flash 0
16 bytes Palette for Flash 1
4 bytes mode3 SwapPalette for Flash 1
0 PaletteLine (Line, Palette, ColorFlash0, ColorFlash1)
1 EndOfPaletteLine (&FF)
These 40 bytes are from the system address &55D8 PALTAB and 1 byte is from the system address &5600 LINICOLS.
In Basic (and so also in file) is maximum 127 palette changes, because LINICOLS has only 512 bytes and every palette change has 4 bytes.
Trivia
The screen mode effects the execution time of Z80 instructions, for MODE 1 see this article from Simon Owen.