User Tools

Site Tools


redirecting_20the_20vdu_20commands_20to_20a_20sprite

This is an old revision of the document!


<!– This is incomplete –> (Based on the code posted by Richard Rusell at Stardot forums - https://stardot.org.uk/forums/viewtopic.php?f=54&t=19564&p=272049#p272049)

When writing programs that are likely to use the same graphics repeatedly, it can be avdanatagous to plot the graphics once, and reproduce it many times. Thus the situation may arise where it is desired to redirect the VDU drivers to plot somewhere other than the main output window. On RISC OS it was possible to define a “sprite area” and redirect the VDU drivers to use the sprite area instead of screen memory.

This can be also be done in both BBC BASIC for Windows and BBC BASIC for SDL, by selecting an appropriate 'alternative' bitmap (BB4W) or Texture (BBC Basic for SDL) into the relevant device/rendering context (@memhdc%). BB4W uses a Windows “device context”, wheres as BBC Basic for SDL uses an SDL “rendering context”.). SYS calls are be used, and the calls used differ between the two dialects. (INKEY(-256) can be used to determine which dialect is in use.

Under Windows, “CreateCompatibleBitmap” is used to create the new bitmap, and “SelectObject” is used to select it into the device context, and later to restore the standard output. A program will need to keep track of the former 'screen' handle returned by “Select Object” to enable restoration of the normal

Under SDL, “SDL_CreateTexture” is used to create a new texture, with “SDL_GetRenderTarget” being used to get the current screen output location, “SDL_SetRenderTarget” is then used to change the location to the “sprite” and later to restore the normal output location.

Once switched, normal print and graphics commands such as PLOT, DRAW and CIRCLE can be used to draw the sprite.

Once completed, an appropriate SYS call is used to restore the normal screen location, using the handle recovered and preserved.

If multiple “sprites” are to be created, or updated during program execution, the VDU context will also need to be preserved by code in the program when switching between “sprite” and “screen” memory areas.

<!– The Example Code –>

This website uses cookies for visitor traffic analysis. By using the website, you agree with storing the cookies on your computer.More information
redirecting_20the_20vdu_20commands_20to_20a_20sprite.1591357779.txt.gz · Last modified: 2020/06/05 11:49 by alex_farlie