Individual cell paper and pen in MODE 2 and MODE 4 via BASIC

Hello all,

I'm usually a Spectrum user, but with more time on my hands I have been looked at the SAM Coupe, and looking at the four screen modes and was was wondering how you set the individual cell paper and pen in MODE 2 and MODE 4 via BASIC?

The screenshot of the manual page and my very simple example code is on my Spectrum Computing Forum.  

https://spectrumcomputing.co.uk/forums/viewtopic.php?f=31&t=4091

Thank you.

For character printing just setting the PEN and PAPER before printing a character will do it in any mode but only for the character, MODE4 is has no attribute cells as it is bitmapped with a nibble per pixel (2 pixels per byte) [EDIT: same for MODE3 but with 2 bits per pixel, 4 pixels per byte)] and MODE2 behaves as it does on the speccy so you the cells will inherit the attribute of the last plotted pixel or you can POKE them directly.

From the Technical Manual:

 

- MODE 1 -
32 cells x 24 lines in 2 colours from 16 out of a palette of 128 colours, giving 768 character cells (8 x e) using 6 kilobytes of bit-mapped memory and 0.75 kilo-bytes of attribute memory. This mode emulates Spectrum memory mapping.

- MODE 2 -

32 cells x 192 lines in 2 colours from 16 out of a palette of 128 colours, giving 6144 character cells (8 x 1) using 6 kilobytes of bit-mapped memory and 6 kilobytes of attribute memory. This mode has contiguous memory addressing in two blocks.

- MODE 3 -

512 pixels x 192 lines in 4 colours out of a palette of 128 colours, giving 98304 dots using 24 kilo-bytes of memory. This mode, when used with a character set 6 pixels wide, will give 85 characters per line.

- MODE 4 -

256 pixels x 192 lines in 16 colours out of a palette of 128 colours, giving 49252 dots using 24 kilo-bytes of memory. This mode is ideal for graphic display, and when used in conjunction with LINE INTerrupt register can display the full 128 colours on screen.
 

 

You can see how the POKEing the screen memory works in different modes with something like this, this one pokes the upper nibble with 16 so in MODE4 you get alternate bright white and black pixels - or for somthing more fun POKE it with RND*255 which will affect more pixels depending on the mode and get nice and trippy when you hit the attribute area in MODE1 and 2 :)

   10 CLS #
   20 LET SCAD=((IN 252 BAND 31)+1)*16384,MEM=0
   30 DO
   40  PRINT AT 0,0;MEM
   50  POKE SCAD+MEM,BIN 11110000
   60  LET MEM=MEM+1
   70 LOOP

Thanks Dan,

Most useful. I read with Mode 2 the ATTR command just looks at the top row of the equivalent 8x8 cell, but you can peek the screen memory to find the attribute at any 8x1 section in mode 2.  Where does that screen memory start?

Please see text here (sorry, can't see how to include images in post.  Tried the <img> html tag.

https://i.ibb.co/G0y7jP2/Mode2.png

 

The variable SCAD in Dan's example stands for 'SCreen ADdress', it reads the value of the video memory page register (port 252), discards the upper non-page bits with band (= Binary AND) 31 (= binary %00011111) leaving only the page part. Subsequently 1 is added (since BASIC maps addresses 0-16383 to ROM0) and this is multiplied by 16384 to get the address that BASIC uses.

To get to the attributes you then need to add 8192 (as per the manual) to get to the attributes section.