2068 Windows

Author(s): Paul Bingham; Jim Rodlin
Pub Details: Sinclair Timex User Group Newsletter v7 n1 (Volume 7, Issue 1)
Date: January 1988
Pages: 5-7

As computer hardware technology progressed, software improved as well, although at a slower pace. Program front-ends (the program’s display) have become more sophisticated, evolving from simple prompts and menus, to pull-down menus, icons, and now split screens and windows. Today, it is not uncommon to see computer displays with multiple, independant, scrolling windows running different programs in each. While the unexpanded T/S 2068 has insufficient memory to support the complicated windowing and graphics you see on the newest computers, it is capable of some very impressive displays.

Did you know that the 2068 is capable of 80 column displays? Or dual screen mode? These are advanced video modes of the T/S 2068 which we will explore in future articles.

The 2068 is quite capable of manipulating windows, too.

Windows may be implemented in several ways but there is one requirement for any windowing system: A window must preserve any underlying text when it opens. The simplest way is to copy the entire display file to a place in memory before it is opened. After the window is ready to be closed, you can copy the stored data back to the display file and restore the screen. This is the method that the program below uses. In fact, the key to the whole program is in the M/C routine DATA statement in line 5. The disassembly of the routine is in Figure 1.

The instruction “LDIR” does the actual copying. The BC register holds the number of bytes to move (1800 hex = 6144, which is the number of bytes in D_FILE, the area of RAM where the screen is kept). DE holds the destination address (E757 hex = 59223, the first byte after the end of the code! This is where we copy the screen to), and HL points to the start of D_FILE. So LDIR copies BC bytes from HL to DE. RET sends us back to basic.

The second part, beginning at 59211, does the same thing – but in reverse order. The data that we saved to E757 the first time is now copied back into the display file (You may have noticed that the addresses in DE and HL were switched).

If you don’t understand any of this, don’t worry. It is not necessary to know how the routine works in order to use it! All you need to know is that RANDOMIZE USR 59199 will save the current screen, and RANDOMIZE USR 59211 will copy it back. Try this: LIST, RANDOMIZE USR 59199, CLS, then RANDOMIZE USR 59211.

Address HEX Addr Bytes   Mnemonics      Notes
59199   E73F     010018  LD BC, 1800    How many bytes to copy
59202   E742     1157E7  LD DE, E757    E757 = destination
59205   E745     210040  LD HL, 4000    4000 = start of D_FILE
59208   E748     EDB0    LDIR           Copy from HL to DE
59210   E74A     C9      RET            RETurn to basic
59211   E74B     010018  LD BC, 1800    # Bytes to copy
59214   E74E     110040  LD DE, 4000    Destination = screen
59217   E751     2157E7  LD HL, E757    Where scr is stored
59220   E754     EDB0    LDIR           Move bytes back again
59222   E756     C9      RET            RETurn to basic

-Note: All numbers are hexadecimal except first column-

Figure 1
  1 REM      2068 WINDOWS  by Paul Bingham
2 REM From SYNCWARE NEWS 4:2
4 REM The program shows three examples of windows. The key
routine is the GOSUB 9000. E.G. line 120 gives the width, depth,
row and column of the window. Any text we want in the window can
be done in BASIC as usual as in lines 140, 180 and 220.
5 CLEAR 59198: DIM w$(3,11): LET a$="WINDOW": LET b$="press":
LET store=59199: LET renew=59211: LET lower=23659:
FOR t=store TO 59222: READ f: POKE t,f: NEXT t
6 DATA 1,0,24,17,87,231,33,0,64,237,176,201,1,0,24,17,0,64,33,
87,231,237,176,201: REM (sets up LDIR code)
10 FOR t=65368 TO 65431: READ a: POKE t,a: NEXT t
11 DATA 15,8,8,8,232,232,232,232,255,0,0,0,0,0,0,0,255,1,1,1,1,
1,1,1,232,232,232,232,232,232,232,232,1,1,1,1,1,1,1,1,232,
232,232,239,224,255,255,255,0,0,0,255,0,255,255,255,1,1,1,
255,0,224,224,224
100 POKE lower,0: FOR f=1 TO 76: PRINT "1234567890";: NEXT f:
PRINT "12345678": POKE lower,2
110 LET k=USR store
120 LET n=1: LET w$(n)="11,12,02,03": GO SUB 9000
140 PRINT AT 4,6;a$;AT 6,8;"#1";AT 11,5;b$;"2"
150 IF INKEY$<>"2" THEN GO TO 150
160 LET k=USR renew
170 LET n=2: LET w$(n)="13,20,02,17": GO SUB 9000
180 PRINT AT 5,21;a$;AT 7,23;"#2";AT 19,20;b$;"3"
190 IF INKEY$<>"3" THEN GO TO 190
200 LET k=USR renew
210 LET n=3: LET w$(n)="10,08,16,04": GO SUB 9000
220 POKE lower,0: PRINT AT 17,6;a$;AT 19,8;"#3";AT 22,6;
b$;"E": POKE lower,2
230 IF INKEY$<>"E" THEN GO TO 230
240 CLS: PRINT AT 8,6;"";: FOR t=1 TO 20: READ a:
PRINT CHR$ a;: NEXT t
245 DATA 77,111,118,101,32,111,118,101,114,32,77,65,67,105,110,
116,111,115,104,33
250 GO TO 9999
9000 LET w=VAL w$(n, TO 2): LET d=VAL w$(n, 4 TO 5):
LET r=VAL w$(n, 7 TO 8): LET c=VAL w$(n, 10 TO 11)
9010 IF r+d>24 OR c+w>32 THEN PRINT AT 21,10;
"Window's too big!": STOP
9020 IF r+d>22 THEN LET low=0: let r3=24-r-d: GO TO 9040
9030 LET low=2: LET r3=2
9040 LET rd=r+d-2: LET cw=c+w-3
9050 POKE lower,low: PRINT AT r,c;CHR$ 144;: FOR t=c TO cw:
PRINT CHR$ 145;: NEXT t: PRINT CHR$ 146
9060 FOR t=r+1 TO rd: PRINT AT t,c;CHR$ 147;
9070 FOR f=c TO cw: PRINT " ";: NEXT f: PRINT CHR$ 148;: NEXT t
9080 IF r3=0 THEN OVER 1: FOR t=1 to 32-w: PRINT " ";: NEXT t:
OVER 0: PRINT CHR$ 149;: FOR t=c TO cw: PRINT CHR$ 150;:
NEXT t: PRINT CHR$ 151: POKE lower,2: RETURN
9090 PRINT AT rd+1,c;CHR$ 149;: FOR t=c TO cw: PRINT CHR$ 150;:
NEXT t: PRINT CHR$ 151: POKE lower,2: RETURN

Listing 1

In the listing, STORE is the address of the first routine, RENEW is the second, and LOWER is a system variable that controls the lower part of the screen (the 2068’s edit line). Line 10 redefines some UDG characters for the window borders.

W$ holds the window width, depth, row, and column position for a window. GOSUB 9000 checks that your window will fit on the screen, blanks out that part of the screen, prints a nice looking border around the window, and returns. At this point, your program can print what it wants to in the window; however, it is up to the programmer to keep the text within the borders of the window by printing at the right locations!

When you are through with a window, RANDOMIZE USR renew will recall the original screen.

In the next issue, we will take a look at what is required to implement a more sophisticated windowing utility that can handle wraparound, scrolling within a window, and multiple windows.

-Jim Rodlin

Comments? Questions? Write to me! My address is [address omitted].

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.