Parameter |
Value or Description |
Lead in |
CHR$(27) CHR$(4) |
Screen # |
6 bytes |
Function |
"P" to prepare the screen cache save function |
"S" to save the screen delta |
|
"R" to restore a screen |
|
"C" to clear the cache (screen # must be "XYZZY!") |
|
"s" to set the cache version (screen # not used) |
|
"r" to retrieve the cache version (screen # not used) |
|
"u" display cache update dialog (screen # not used) |
|
"c" to close the cache update dialog (screen # not used) |
Screen Caching allows ZTERM to "remember" parts of a screen in a local disk file and then retrieve them when instructed by the host system. Obviously, this requires some programming on the host computer, however, it it well worth the effort. Once a screen or part of a screen has been cached, it's display is instantaneous giving applications much better perceived response time and also reducing the load on the host system's I/O subsystem.
Screen cache support is available when using AM62A and AM62C emulations. It is supported in ZTERM 2000 build 128 and later. The cache is persistant (i.e. doesn't get deleted between ZTERM sessions) and is stored in a seperate file for each profile.
How To Use The Cache
The key to knowing if the cache on the PC matches what is on the host is the cache version string. This is a six byte field that you exchange with ZTERM to find out which version of the cached screens are the PC. You can use the six bytes in any way you want - we suggest using the YYMMDD format, but feel free to use another scheme if you want:
PRINT CHR$(27);CHR$(4);"xxxxxxr"; ! ask for cache version
INPUT A$ ! ZTERM send a CR too
IF A$ = "000302" THEN GOTO CACHED ! cache on PC up to date
!code follows to setup cache
If the cache version doesn't match, you need to send all the screens to be cached down to the PC. This involves clearing the cache:
PRINT CHR$(27);CHR$(4);"XYZZY!C";
and then sending all of the screens you want to have cached. Each screen has a six byte screen ID. You can use any alpha-numeric string for the ID, but each screen or part of a screen must be unique. First, send a prepare command:
PRINT CHR$(27);CHR$(4);"000001P"; | ! prepare screen #1 |
!code to paint the screen follows
You then call the appropriate code to paint the form part of the screen and then tell ZTERM to save the screen:
PRINT CHR$(27);CHR$(4);"000001S"; | ! save screen #1 |
Obviously, seeing all your application's screens going zooming by might be a little confusing for an end-user, so ZTERM has a dialog that can be displayed on top of the emulation window to let them know what's going on.
To turn this dialog on and off, use this code:
PRINT CHR$(27);CHR$(4);"xxxxxxu"; | ! turn on cache update dialog |
!do cache updating
PRINT CHR$(27);CHR$(4);"xxxxxxc"; | ! close cache update dialog |
Once you know the cache is up to date on the PC, to display a screen, just use the display escape sequence rather than calling into your subroutine that paints the screen:
PRINT CHR$(27);CHR$(4);"000001R"; | ! restore screen #1 |
The Cache Delta Effect
When ZTERM writes screens into the cache file, it maintains a flag on a character by character basis indicating if the character was changed between the time the prepare and save commands were sent. If the changed flag is set, when ZTERM restores a screen from the cache, these are the characters that actually get restored to the screen. In other words, when ZTERM saves a screen into the cache, it doesn't save the entire screen, just the parts that changed.
Although this sounds a little complicated, it's actually a very useful feature since it allows you to create pop-up windows from data stored in the cache. If you want to override the delta effect, simply clear the screen after the prepare command - if you want to set a region as a pop-up area, simply use the fill area with character command.
Cache Debugger
To make debugging your screen cache code, ZTERM includes a cache debugger on the Help menu. To turn it on, go to the profile list display and click on File/Application Options and then check the box.
Clicking on "Display" will display the selected screen. Double clicking on a cache screen ID will clear the screen and then display the screen from the cache.
Example
This is a sample application that writes 100 screens into the cache and then displays them. It also has one delta screen to show how an area (and not the entire screen) can be restored from the cache. You can find this sample in the folder where ZTERM as installed as "cache.ab".
!Get cache version - if ZTERM has the right version, just display
PRINT CHR$(27);CHR$(4);"000000r";
INPUT "";A$
IF A$ = "000001" THEN GOTO DISPLAY
!Cache doesn't match - let's set it up
PRINT CHR$(27);CHR$(4);"XYZZY!C"; ! clear cache
PRINT CHR$(27);CHR$(4);"000000u"; ! update cache dialog
!We'll setup 100 test screens
FOR SCREEN = 1 TO 100
PRINT CHR$(27);CHR$(4);SCREEN USING "#ZZZZZ";"P";
PRINT TAB(-1,0);
FOR I = 1 TO 23
FOR J=1 TO 70 STEP 10
PRINT TAB(I,J);"TEST ";SCREEN USING "#ZZ";
NEXT
NEXT
PRINT CHR$(27);CHR$(4);SCREEN USING "#ZZZZZ";"S";
NEXT
!Just as an example, let's setup a screen that shows the delta effect
PRINT CHR$(27);CHR$(4);"100000P";
PRINT TAB(12,25);
PRINT TAB(-1,91);CHR$(32 + 5);CHR$(32 + 30);" ";
FOR I = 1 TO 3
PRINT TAB(12 + I, 26);"123456789.123456789.12345678";
NEXT
PRINT CHR$(27);CHR$(4);"100000S";
!Since the cache is now setup, let's set the version and turn off
!the update dialog
PRINT CHR$(27);CHR$(4);"000001s"; ! set cache version
PRINT CHR$(27);CHR$(4);"000000c"; ! clear cache dialog
PRINT TAB(-1,0);
INPUT "Now press ENTER to see the same pages from the cache ";A$
!Display pages from the cache - this part screems!
DISPLAY:
FOR SCREEN = 1 TO 100
PRINT CHR$(27);CHR$(4);SCREEN USING "#ZZZZZ";"R";
NEXT
!Show the delta effect
PRINT CHR$(27);CHR$(4);"100000R";