PROGRAM PITSTOP
from Your Sinclair #26 (February 1988)

Hello everybody, it's me, David Jones. I'm doing Program Pitstop this
month to give Phil a break. (Preferably his legs. Ed) Amongst your
programs are an odd screen load, a simple Basic key define and a rather
natty border printing routine.


First item this month is a very nice screen load utility from Lopez
Figueira. A lot of other attempts at this trick were in the same mail-
bag, but this one was the most interesting to watch. Honourable mention
goes to T Thackstone for his fairly fast sideways load routine, but I'd
already decided that the object here is to have the screen load in an
interesting way, and Lopez' routine does that best. The screen loads in
three areas at once (coo-er-gosh) split into three 2K blocks and loading
left, right, left as you look down the screen. It isn't as sophisticated
as the Alcatraz loading system that appears on some commercial tapes,
but what do you want for your money, value?

= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =


SHIFTED SCREEN LOAD
by Lopez Figueira
from Your Sinclair #26 (February 1988)
[files SHIFTSC1.*]

[NOTE: For this routine to work correctly with an emulator, the screen]
[must be saved as TZX format. Although the save routine will save to a]
[TAP file, the load routine will not recognise it as it uses its own  ]
[loading code and does not call the standard ROM routine.         JimG]

Lopez has sent both Basic and assembly code listings to help you under-
stand what's going on. The Basic listing is really designed for demon-
stration purposes, but can also be used to save a working sub-routine to
tape or microdrive by changing line 50 and adding lines 51 to 54:

50 SAVE "SHIFTSCR" CODE 65000,244
51 PRINT "REWIND TAPE TO VERIFY, THEN PRESS ANY KEY"
52 PAUSE 1: PAUSE 0
53 VERIFY "SHIFTSCR" CODE
54 STOP

The assembly listing has two entry points, LOADER to load the code and
BUILD to save a screen (BUILD a specially saved unit).


= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =


KEY DEFINE
by Thurstan Felstead
from Your Sinclair #26 (February 1988)
[files KEYDEFIN.*]

This was an odd program to look at. For a start, the accompanying
'documentation' was written on the back of a Shredded Wheat packet! And
secondly the programmer signed himself "Monsignor Thurstan S Coolman
Felstead", with an OBE crossed out. (Undoubtedly the Order of Breakfast
cereal Empties!) But anyway, I loaded up the tape and found a neat Basic
key define program. The program is very simple, but I reckon all
programs should have key define options so I decided to include it here.
Also, it occurred to me that you may not all be machine code programmers,
so a pure Basic program might be of some use.

The program consists mainly of checking K$ for different values obtained
via INKEY$. The program should not be too difficult to understand, which
is just as well, as my Spectrum printer is on the blink and I can't give
you a blow-by-blow variable description. Still, you can't win 'em all.


= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =


BORDER PATTERNS
by Ben Machin & Fred O'Rourke
from Your Sinclair #26 (February 1988)
[files BORDPATT.*]

[NOTE: This is unlikely to work on many emulators, because of timing   ]
[problems, and also because they don't have a border as wide as a real ]
[Spectrum in order to show a legible border display. Using WinZ80 with ]
[the "wide borders" setting gives some idea of what should appear,     ]
[although even that is not very good.                              JimG]

I liked this program from Ben and Fred (sounds like a couple of Flint-
stones), partly because it was so well presented, and also because it
was so frivolous. By well presented I mean that they supplied a tape,
hex dump, assembly listing, a page of information about the program, and
demo listing. (If all the submissions were as well presented it would
make this job so much easier!) The demo program shows border graphic
units zooming along above normal screen limits.

The routine occupies RAM from 50000-50213 and 64980-65281. [This doesn't
tally with the printed listings, which end at 50215 and 65027. JimG] The
latter of the two addresses holds the interrupt handler and the vector
table, whereas the first area is the border display handler. Borderprint
is compatible with the 48K and 128K/+2 Spectrums. It automatically works
out which computer it is running on, and modifies itself to run on the
slightly faster 128k/+2 processor.

POKE 50005, lo-byte of display file start
POKE 50006, hi-byte of display file start
POKE 50008, (1-64) amount of pixel lines to be printed
POKE 50107, (1-255) scroll speed, 255=fast, 1=slow
POKE 50141, (1-8) size of chars printed by routine 50131
POKE 50168, (1-7) ink colour of chars
POKE 50176, (1-7) paper colour of chars
POKE 50212, 0=scroll on, 1=scroll off
POKE 50167,237: POKE 50168,95 multicolour chars
POKE 50167,62: POKE 50168,0 normal black chars
RANDOMIZE USR 50131 when scroll is off captures character at 0,0
RANDOMIZE USR 64980 turns the border display off
RANDOMIZE USR 65000 turns the border display on

The Basic listing of the demo program below requires a few lines of
modification, 'cos as it stands it doesn't load the machine code. Add
these lines for full operation:

140 STOP
150 CLEAR 49999
160 LOAD "BLOCK1" CODE
170 LOAD "BLOCK2" CODE
180 GO TO 5

When you save the Basic use SAVE "demo" LINE 150. The reason for this
omission was that there was a short program on the tape that loaded the
CODE before the Basic demo. 

I haven't bothered to give you the assembly listing for three reasons:
1) There were no comments anyway; 2) It would have taken up space, and
finally; 3) Disassembling code is a good way to learn about it!

The authors add this small note: "If this routine is published in
Program Pitstop, please mention that readers can use it in their own
programs, but not in any commercial or published programs / games. Thank
you." Well, thank YOU, Ben and Fred.


= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =


ROUND OFF
by Paul Taylor & Carl Whitwell

This letter must have taken a while to reach me 'cos it was addressed
to Task Force! But I'm going to print it anyway, 'cos it gives us two
useful rounding functions. Function one rounds off a number to the
nearest integer and takes account of numbers such as 2.5 where it
gives a result of three. The functions should be included in your
programs like this:

100 DEF FN r(v)=INT v+CODE CHR$ (v-INT(v))
110 DEF FN p(v,n)=FN r(v*10^n)/10^n

Function two, which uses Function one, rounds off a number to a
required number of decimal places. Have a butchers at the examples
below:

Command			Output
PRINT FN r(2.4)		2
PRINT FN r(2.5)		3
PRINT FN p(123.0678,3)	123.068
PRINT FN p(123.0674,3)	123.067

These routines should speed up of almost any program which uses lots
of floating point maths, and needs to round off numbers. Yes, at last
you can write that Basic spreadsheet program you've always dreamed of
... (Oh brother! Ed)


= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =


SCREEN COMPRESS
by Luca Rasca

The only listing I received was this assembly listing, so rather than
work it out as a hex dump (argh! all those swirling bytes!), I am
setting this month's challenge to improve the screen packing of this
routine. You can write your own one from scratch if you want. Send
these and any other brilliant programs and routines to: Program
Pitstop, Your Sinclair, 14 Rathbone Place, London W1P 1DE. That's it!
See you soon!

Screen Compress
Here is a fairly simple screen compression sub-routine from Luca
Rasca. It scans through your screen and stores a compressed version at
50000. It does this by taking note of all the zeros and recording how
many it finds. Since it scans across the screen it doesn't find 255s
which are frequently as common as zeros. But here it is:

Assembly Listing
0000            00000  ;Screen Compress
0000            00000  ;by Luca Rasca
0000            00000  ;from Your Sinclair, Feb'88
0000            00000  ;
0000            00000  ;I added the FINISH step to
0000            00000  ;load BC with the end address,
0000            00000  ;so that USR 65200-50000 will
0000            00000  ;give the compressed screen
0000            00000  ;length.               [JimG]
0000            00000         org  65200
FEB0 210040     00000  COMP   ld   hl,16384
FEB3 1150C3     00000         ld   de,50000
FEB6 7E         00000  LOOP1  ld   a,(hl)
FEB7 A7         00000         and  a
FEB8 12         00000         ld   (de),a
FEB9 280A       00000         jr   z,ZERO
FEBB 23         00000         inc  hl
FEBC 13         00000  CONT   inc  de
FEBD 3E5B       00000         ld   a,91
FEBF BC         00000         cp   h
FEC0 20F4       00000         jr   nz,LOOP1
FEC2 42         00000  FINISH ld   b,d
FEC3 4B         00000         ld   c,e
FEC4 C9         00000         ret
FEC5 4F         00000  ZERO   ld   c,a
FEC6 13         00000         inc  de
FEC7 23         00000  LOOP2  inc  hl
FEC8 3E5B       00000         ld   a,91
FECA BC         00000         cp   h
FECB 79         00000         ld   a,c
FECC 12         00000         ld   (de),a
FECD 28F3       00000         jr   z,FINISH
FECF AF         00000         xor  a
FED0 BE         00000         cp   (hl)
FED1 20E9       00000         jr   nz,CONT
FED3 0C         00000         inc  c
FED4 20F1       00000         jr   nz,LOOP2
FED6 18E4       00000         jr   CONT
FED8            00000  ;
FED8            00000         org  65248
FEE0 F3         00000  EXPAND di
FEE1 110040     00000         ld   de,16384
FEE4 2150C3     00000         ld   hl,50000
FEE7 7E         00000  LOOP3  ld   a,(hl)
FEE8 A7         00000         and  a
FEE9 12         00000         ld   (de),a
FEEA 2009       00000         jr   nz,RICONT
FEEC 23         00000         inc  hl
FEED 46         00000         ld   b,(hl)
FEEE B8         00000         cp   b
FEEF 2804       00000         jr   z,RICONT
FEF1 13         00000  LOOP4  inc  de
FEF2 12         00000         ld   (de),a
FEF3 10FC       00000         djnz LOOP4
FEF5 13         00000  RICONT inc  de
FEF6 23         00000         inc  hl
FEF7 3E5B       00000         ld   a,91
FEF9 BA         00000         cp   d
FEFA 20EB       00000         jr   nz,LOOP3
FEFC FB         00000         ei
FEFD C9         00000         ret


= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =


