Plotting in Screen 13

Plotting in SCREEN 13 is easy. As you may know, the graphics memory "window" measures 64 Kb (if not, check ). In the mode 13h (SCREEN 13) you have 320x200 pixels, and you just need one byte per pixel to store colour info (256 colours fit in the 256 different possible vaues of a byte), so the whole screen takes 320x200=64000 bytes, which is less than 64K.

Moreover, these pixels are ordered from top to bottom, left to right. That way, pixel #0 is at position (0,0), and pixel #63999 is at position (319,199).The last pixel in the 1st line (319,0) is pixel #319, and the first pixel in the 2nd line (0,1) is pixel #320. That way, we can calculate the pixel number just by

pixel% = y%*320 + x%

To plot a pixel, we just change the data segment to point the screen area (with DEF SEG = &HA000) and POKE the pixel with the colour of our choice.

There is a problem: INTEGER math (fast) operates with numbers of 16 bits which range is from -32768 to 32767. For that reason, we need a LONG int 'cause address can be higher than 32767:

POKE address&,value%

This is slower than plain INTEGER math, but there is a trick, use:

address% = x% + 320 * y%
POKE address%, value%

It won't work within the IDE (overflow), 'cause % means Integer and integer cannot handle values higher than 32767 (and 320*y% can produce them), but it works if you compile your program and run it from the DOS prompt. Reason: the compiled code doesn't check for overflow errors. It doesn't overflow but wraps around:


Negative numbers in "POKE address%, value%" are actually bigger than non-negative numbers and thus everything turns out OK.

PlottingInScreenThirteen - page last edited 2004-01-18 17:01:12 by (home) (edit)
Blast WIKI - by RoboticBoy - edited and tweaked for our evil purposes by Hexadecimal Disaster