PortSet Function (ROM Call 0x1A2)

graph.h

void PortSet (void *vm_addr, short x_max, short y_max);

Sets up the virtual screen.

PortSet allows drawing in a virtual screen. All graphic commands which are built-in into TIOS does not expect that the video memory must be at 0x4C00, and that the video memory is always 240 x 128 pixels. Using PortSet you can set up a virtual screen anywhere in a memory, and of any size. After using PortSet, all graphic commands will assume that the video memory starts at vm_addr, and that the dimensions of the video memory are (x_max+1) x (y_max+1) pixels. This allows to you to use graphic functions even when the actual LCD memory is relocated at any other address using I/O hardware ports, or to draw pictures into virtual screens (not visible on the real screen), then move them (using memcpy or some other function) to the real screen. This will enable the possibility of hiding the actual drawing process, and to display the drawn picture immediately.

Here is a code fragment which ilustrates the usage of virtual screens:

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, a virtual screen may simply be in any local variable which is long enough:
char virtual[LCD_SIZE];
...
PortSet (virtual, 239, 127);
Note that, in this case, virtual screen memory will in fact be 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 much 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 setting up the virtual screen, you can 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 (virtual);
Note: Don't forget to do PortRestore before the end of the program, otherwise TIOS will be fooled after returning to TI-Basic!


Used by: GrayOn, GraySetAMSPlane, ROM Call 0x413