Specifications
5
dynamically as necessary to fill the screen. This facet is useful for games in which drawing the entire virtual world at
once requires too much memory.
plane 3 of
logical view
plane 2 of
logical view
plane 1 of
logical view
plane 0 of
logical view
build buffer
planes shift in
the build buffer
as the logical view
moves within the
room photo
mapped into
build buffer
using photo
coordinates for
mode X planes
logical
view
window
size of
scrolling
portion of
video screen
(0,0)
(show_x,show_y)
room photo pixels
We use a build buffer to keep the pixel data relevant to the screen organized in a form convenient for moving into video
memory in mode X. However, in order to avoid having to move the data around a lot in the build buffer (or redraw
the whole screen each time we move the logical view window by one pixel), we break the room photo into 4x1 pixel
chunks using the mode X mapping illustrated in the previous section. The address of the logical view window in the
room photo is used to decide where to place the image planes within the build buffer, and moves around within the
build buffer as the logical window moves in the room photo, as shown in the figure below.
planes 1, 2, and 3
the window for
this address is in plane 0
the window for
this address is in
window
logical view
3210
3210
The mapping that we have described has a subtle detail: the address range used for the different planes within the
logical view window may not be the same. Consider the case shown above, in which show x & 3 == 1. As we
move the logical view window around in the room photo, we need to keep each address block at a fixed plane in the
build buffer (again to avoid having to copy data around). If we were to keep the planes in the order 0 to 3 and not put
any extra space between them, the image of plane 0 would in this case overlap with the image of plane 1 in the build
buffer. By reversing the order, we can avoid this problem (alternatively, we could have used a one-byte buffer zone
between consecutive planes).
The next problem is mapping the build buffer into the video memory. We use two buffers in video memory and map
into the non-displayed buffer, then change the VGA register to show the new screen. You can read about this double-
buffering technique in the code and see how it works. The complexity with regard to the plane mapping is that we
must map the build buffer planes, which are defined in terms of the room photo coordinates, into the video planes,
which are defined in terms of the screen coordinates. The picture below illustrates this problem. In general, a cyclic
shift of the planes suffices for the mapping.
0 1 2 3
video screen
memory
build
buffer
video
(a cyclic shift of planes)
3
2
1
3
2
1
00
memory
0 1 2 3
0 1
3210
build buffer layout
window
logical view
32