'
' SWITCH - routines and small library for usage of a doublebuffered screen
' (c) 2005 by Simon Sunnyboy / Paradize http://paradize.atari.org/
'
' This routine gives you two additional screens in memory so you
' can draw a picture on one screen while displaying another.
' Additionally you get a third screen as a buffer for a background
' or to scroll things around.
'
' I used similar routines for about 10 years but I never bothered
' to make a library or include file out of it.
' USE AT YOUR OWN RISK!
'
' call initpage23 once at the start of your program
' make sure to call reset23 even in case of error (ON ERROR GOSUB ...)
' or you probably will disturb normal screen management
'
> PROCEDURE initpage23
LOCAL hilf2%,hilf3%
' get address of current screen, it is reused by our routines!
physbase%=XBIOS(2)
oldphysbase%=physbase%
' get memory for two additional screens
' feel free to rewrite it to use MALLOC() :)
res32s2$=STRING$(32256,"0")
res32s3$=res32s2$
hilf2%=VARPTR(res32s2$)
hilf3%=VARPTR(res32s3$)
logbase%=(hilf2%+256) AND &HFFFFFF00
background%=(hilf3%+256) AND &HFFFFFF00
'
CLS
scopy(physbase%,logbase%)
scopy(physbase%,background%)
RETURN
' scopy(src%,dest%)
' coyp contents of screen src% to screen dest%
> PROCEDURE scopy(pagea%,pageb%)
BMOVE pagea%,pageb%,32000
RETURN
' switch()
' use this to flip screens
' screen physbase% is displayed, draw things to logbase%
' GFA commands will from now on automatically draw to logbase%
> PROCEDURE switch
VSYNC
SWAP physbase%,logbase%
~XBIOS(5,L:logbase%,L:physbase%,L:-1)
RETURN
' switch_background()
' use this to flip screens and copy your third background to the
' new workscreen in one go
> PROCEDURE switch_background
VSYNC
SWAP physbase%,logbase%
~XBIOS(5,L:logbase%,L:physbase%,L:-1)
scopy(background%,logbase%)
RETURN
' draw_hidden()
' show screen physbase% but draw to screen logbase%
> PROCEDURE draw_hidden
~XBIOS(5,L:logbase%,L:physbase%,L:-1)
RETURN
' draw_normal()
' show and draw to physbase% (all GFA output is directly visible)
> PROCEDURE draw_normal
~XBIOS(5,L:physbase%,L:physbase%,L:-1)
RETURN
' reset23()
' clean up and go back to the initial screen
> PROCEDURE reset23
~XBIOS(5,L:oldphysbase%,L:oldphysbase%,L:-1)
RETURN