Spectrum Computing Hangout

This file is part of Long Island Sinclair Timex (LIST) User Group Library Tape #3.5. Download the collection to get this file.
Date: 198x
Type: Program
Platform(s): TS 2068

A page from a cassette magazine, Spectrum Computing, made up of two short articles with demonstrations. The first explains that a low RAMTOP slows a 48K Spectrum because the stack is then in the lower 16K, where the ULA holds up the CPU whenever it needs the memory for the display. To show the stack at work, a machine code routine moves part of it into the attribute area, where it flickers on screen as subroutines are called. The second explains that RND gives a repeatable pseudo-random series and demonstrates it by drawing random circles with OVER 1 and then erasing them by reseeding with the same RANDOMIZE value. The text pages are turned with a keypress.

This program is on side B of the Long Island Sinclair Timex (LIST) user group library tape #3.5, together with a two-line loader named sample, whose REM reads “Spectrum Computing”.

Program Analysis

Program Structure

  • Lines 9900-9920: “STOP THE TAPE” alarm screen, which calls machine code held in the REM at line 9910.
  • Lines 1000-1160: the RAMTOP and stack article.
  • Line 2000: calls the stack demonstration in the REM at line 2001.
  • Lines 1210-1310: the RND article and the circle demonstration.
  • Lines 1350-1380 and 3000-3020: replay or quit, and the page-turn routine called through the variable wait.

Notable Techniques

  • Both machine code routines live in REM statements and are found at run time from NXTLIN (23637/23638) plus 5, the start of the following line’s REM text, so they work wherever the program is loaded.
  • Lines 1300-1310 seed RND with RANDOMIZE i, draw twelve circles with OVER 1, then reseed with the same value and draw the same circles again to erase them.
  • GO SUB wait uses a variable holding 3000 as the target line.

Potential Issues

  • The routines in the REMs at lines 2001 and 9910 are written for the Spectrum and cannot be decoded from the listing; the RAMTOP discussion is about Spectrum memory contention and does not describe the TS2068.

Appears On

LIST user group library cassette with games, home finance, education, darkroom formulas, an OSCAR 10 satellite tracker and programming utilities across two sides.

Source Code

   10 GO SUB 9900
   15 REM  Spectrum Computing
   20 LOAD ""
  100 PAPER 7: BORDER 7: INK 9: CLS : LET wait=3000
 1000 PRINT "  Many issues ago we pointed outthat CLEARing RAMTOP below about32400 on a 48K Spectrum makes itrun more slowly than when the   RAMTOP is higher up, and we     asked if any reader knew why. Noone wrote back with the answer, not even a wrong answer."
 1010 PRINT "  What a pity. That means the   prize goes unclaimed. Just have to send the tickets back to NASAI guess. However, we do have an answer for you. It all has to dowith the microprocessor's stack.The stack is where the computer stores its current address when"
 1020 PRINT "it goes off somewhere else to   execute a subroutine call.        This does not only happen whenthe computer is running a pro-  gram written in machine code, itis going on all the time."
 1030 GO SUB wait
 1040 PRINT "  After all, a BASIC program is just a list of instructions thatis interpreted by a machine codeprogram in the ROM. Besides the 'CALL' instructions in the ROM  routines, which are constantly  stacking addresses, there is a  special part of the stack for   storing line numbers when you   use a GOSUB in BASIC."
 1050 PRINT "  When you move RAMTOP, you are moving the stack, a tricky oper-ation which has to be done just so, or the computer will forget where it is supposed to go next.The CLEAR command handles this  properly, without dropping the  important bits."
 1060 PRINT "  So why does having the stack  in the lower part of the memory make the computer run slower?   It's due to a hardware shortcut."
 1070 GO SUB wait
 1080 PRINT "  The ULA chip which converts   the screen memory contents into a TV signal (among other things)has to have access to the memorywhenever it wants. If the CPU isusing the memory, the ULA can   actually turn the CPU off so it can use the memory itself."
 1090 PRINT "  It has to be done this way    around to avoid 'snow' on the   screen. If the ULA had to wait  for the CPU, some of the signal would be missed. But the ULA    turns off the CPU whenever it isusing any memory in the lower   16K, not just the screen memory."
 1100 PRINT "  This slows the CPU down not   just when it is printing to the screen, but when it is using thestack, if the stack is in the   lower part of the RAM. If the   stack is higher up, the CPU is"
 1110 GO SUB wait
 1120 PRINT "not stopped as often, and your  program runs faster."'"  The CPU is still held up a lotwhen it is quite unnecessary as far as your telly is concerned. It would  be much better if the ULA only interfered when the CPUwas using the actual screen RAM."
 1130 PRINT "  Presumably it would have cost more to do things that way. The only way to change it would be  to completely redesign the wholecomputer. It may be that the    latest versions of the Spectrum extend this effect to the upper 32k as well, since issue 5 uses"
 1140 PRINT "a different type of memory chip.Does anyone know? (Sorry, the   tickets have gone.)"'"  Meantime, perhaps you would   like to see the stack in action?Turn the page..."
 1150 GO SUB wait
 1160 PRINT "...and we have put part of the  stack into the screen memory (inthe attribute area). You can seeit flickering below as the com- puter calls and returns from    subroutines. Try pressing a few keys and watch the effect."''"Press ENTER when you want to    leave this page."
 1200 GO SUB 2000
 1210 BORDER 1: PAPER 1: CLS : PRINT "  Have you ever wondered why theRND function is said to return  only psuedo-random numbers in-  stead of the real article? The  reason is that they come in a   predictable series. A series toolong for you to memorize, as it has 65535 numbers in it, but nottruly random."
 1220 PRINT "  This is not sloppy programmingbut very good programming. It isnot possible to calculate truly random numbers. If you can pro- gram them, they are non-random  by definition. The best that canbe managed is a nice long seriesthat can't be memorized."
 1230 PRINT "  You can improve the randomnessby using RANDOMISE. Without an  argument after it, this keyword starts off the RND series at a  point determined by the system"
 1240 GO SUB wait
 1250 PRINT "variable FRAMES. This variable  changes every 50th of a second, so you are most unlikely to be  able to predict it."'"  However, the predictability ofthe psuedo-random series can be very useful. You can start the"
 1260 PRINT "series at any point you like    with the RANDOMISE command fol- lowed by a number. And you can  start at the same point again,  by using the same number."'"  This is handy when you want todo something that looks random  without losing track of things."
 1270 PRINT "  On the next page we have a    demonstration of psuedo-random  graphic patterns being drawn andun-drawn. The un-drawing (using OVER) could not be done if RND  was truly random. LIST the pro- gram after to see how it's done."
 1280 GO SUB wait
 1285 IF INKEY$<>"" THEN GO TO 1285
 1290 PRINT #1;"    PRESS A KEY TO STOP DEMO"
 1299 REM NEXT TWO LINES PROVIDE  PSUEDO-RANDOM GRAPHICS DISPLAY 
 1300 FOR i=1 TO 100 STEP 4: RANDOMIZE i: GO SUB 1310: RANDOMIZE i: GO SUB 1310: NEXT i: GO TO 1300
 1310 FOR j=1 TO 12: CIRCLE OVER 1;RND*156+50,RND*76+50,RND*40+10: IF INKEY$="" THEN NEXT j: RETURN 
 1350 CLS : PRINT AT 10,0;"   PRESS 'R' TO RUN AGAIN OR           PRESS 'Q' TO QUIT"
 1360 IF INKEY$="Q" OR INKEY$="q" THEN STOP 
 1370 IF INKEY$="R" OR INKEY$="r" THEN GO TO 100
 1380 GO TO 1360
 1999 REM NEXT TWO LINES PUT PART OF THE STACK ON THE SCREEN 
 2000 RANDOMIZE USR (PEEK 23637+256*PEEK 23638+5): RETURN 
 2001 REM NEXT GO SUB s[1Z CLS >IN FLASH RETURN NEW PRINT STEP n LET  NEXT NEXT GO SUB {[ CLS <>.
 3000 PRINT #1;"          Press a Key"
 3005 IF INKEY$<>"" THEN GO TO 3005
 3010 IF INKEY$="" THEN GO TO 3010
 3020 CLS : RETURN 
 9900 REM *STOP TAPE ALARM*
 9909 LET woop=PEEK 23637+256*PEEK 23638+5
 9910 REM d RETURN :H\ NEW o AND g GO SUB i{= CLEAR GO SUB a{= CLEAR LIST    RETURN :H\ NEW o AND g GO SUB i{= CLEAR GO SUB a{= CLEAR LIST <>oo
 9912 BORDER 5: PAPER 5: LET a=2: LET b=7: CLS 
 9913 FOR i=0 TO 21
 9914 PRINT AT i,8; INK a; PAPER b; FLASH 1;" STOP THE TAPE "
 9915 LET c=a: LET a=b: LET b=c: NEXT i
 9916 PRINT #1;AT 1,0; INK 9;"   PRESS ANY KEY TO TURN PAGE   "
 9917 RANDOMIZE USR woop
 9918 IF INKEY$="" THEN GO TO 9917
 9920 RETURN 
 9999 SAVE "hangout" LINE 1

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