CMM2 graphics examples and explanation


Author Message
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 11175
Posted: 10:42am 09 May 2020      

Graphics pages

In the previous post we saw that writing to the memory identified by MM.INFO(PAGE ADDRESS 0) displays immediately on the screen. In fact the CMM2 always and only ever shows on its display the information in the memory starting at MM.INFO(PAGE ADDRESS 0) (NB: not true in 12-bit colour depth but that is a subject for a much later post). This is important as it underpins the explanations below.

Drawing the line using POKE in the previous example took 12mSec on my 400MHz CMM2. This is fast enough that the act of drawing didn't create any strange visual effects.

However, if we slow it down by adding a pause we can see the line drawing across the screen as it now takes 614mSec.

pix%=mm.info(page address 0)
for i%=0 to 599
  j%=i%*800+i%
  poke byte pix%+j%,255
  pause 1
next i%


This is a trivial example but lots of graphically intensive activities do take "real" time to complete and it may be that we don't want to see the update taking place but would rather move from one static image to another.

A rather better example would be displaying a BMP image. BMP files are uncompressed so they are large and take time to load as they wait for the SDcard to read. They also load from the bottom up which is slightly strange. A full colour 800x600 BMP takes just less than a second to load.

If we type

? MM.INFO(MAX PAGES)


we get the answer 6. This says that in our current 800x600 resolution the 3.5MB of video memory is being split into 7 chunks, numbered 0 to 6.

We know that Page 0 is what is being displayed on the screen and it will always be page 0 that is displayed. However, we don't need to write to page 0. MM.INFO(MAX PAGES) tells us that in 800x600x8 video mode we have 7 video pages at our disposal.

We can see where they are in memory using MM.INFO(PAGE ADDRESS n)

for i=0 to 6:print hex$(mm.info(page address i)):next i


24000000
D0000000
D0080000
D0100000
D0180000
D0200000
D0280000

We can tell the CMM2 which page to use for writing using the command

PAGE WRITE n


So lets type PAGE WRITE 1 at the command line

OH NO!!!! The status line just disappeared, the cursor disappeared, when I type nothing happens

All console output is now being directed to a different area of memory starting at &HD0000000. Luckily any error or typing Ctrl-C will bring things back. PAGE WRITE isn't very useful at the command line but can be used.

How about?

PAGE WRITE 1:LOAD BMP "mybmp":PAGE WRITE 0


This time my cursor came back OK after about a second but no picture

Now type:

PAGE COPY 1 TO 0


Instantly the picture will appear (actually it takes about 4mSec)

Now we can use this to create a BMP slideshow where each image instantaneously replaces the previous one.

page write 1
a$=dir$("*.bmp")
do
   load bmp a$
   page copy 1 to 0
   pause 1000
   a$=dir$()
loop while a$<>""


The PAGE COPY command is very highly optimised to run as fast as possible. It also has an optional parameter which is documented in the user manual

I: means do the copy immediately.  It is the defualt and most efficient but risks causing screen artefacts
B: means wait until the next frame blanking and then do the copy.  It is the least efficient but is absolutely determinate in its effect and no screen artefacts will ever be seen.
D: means carry on processing the next command and do the copy in the background when the next frame blanking occurs.  This is efficient but must be used with care as subsequent drawing commands may or may not be included in the copy depending on the timing of the next screen blanking

In a future post I will improve the slideshow program by having one image replace the previous by slowly scrolling in from the right hand side using another of the PAGE command functions but to summarize:

Multiple pages allow you to store and/or construct complex images without any visible screen artifacts. PAGE COPY allows you to pretty much instantaneously replace what is being seen with a new image with no artifacts. PAGE COPY is very fast. For example in 320x240x8 graphics mode it takes less than 0.3mSec
Edited 2020-05-09 20:47 by matherp