A: |
Do this:
void *virtual = malloc (LCD_SIZE); // Allocate the buffer
...
if (!virtual) ... // do some error handling - not enough memory!
PortSet (virtual, 239, 127); // redirect drawing routines to buffer
or, even simpler, virtual screen may be simply in any local variable which is
enough long:
char virtual[3840];
...
PortSet (virtual, 239, 127);
Note that, in this case, virtual memory will be in fact somewhere on the stack.
There is nothing bad in this, but keep in mind that the total amount of the
stack is 16K, so don't put TOO MANY data (like big arrays etc.) on the stack
(i.e. in local variables). If you really need to handle a lot of data, use
malloc instead.
After this, do any drawing you want - it will be redirected to the virtual
screen. To copy this to the regular screen (i.e. to display it) do this:
memcpy (LCD_MEM, virtual, LCD_SIZE);
or even simpler (this is the same):
LCD_restore (buffer);
And, don't forget to do PortRestore before end of the program, else TIOS will
be fooled after returning to TI-Basic!
|