PROGRAM PITSTOP
Your Sinclair, March 1989

[Not too much wrong this month - except that McCandless got the wrong way    ]
[around all the references to up/down and top/bottom for both programs, there]
[were some incorrect labels in the Screen FX 2 assembler listings, and the   ]
[scroll up/down routines had the descriptions the wrong way around.      JimG]

Oo-er! It's that rubbery time again as we pour into the Pitstop
with David McCandless.

Hi! Most of you out there will be glad to know that this month sees a
return to normal stability after my punctuation of the last few months
with "specials". There won't be any more for a while now, but during
those long dreary months in between if you have an idea for a special
then drop me a line at the normal address.

Anyway, onto this month, and first up this issue, there's an
introduction to Z80 man extraordinaire Damian Scattergood with his
sensational simple, learning aids in pure assembly language. And to
end with is Thurstan Felstead with his - I hate to admit it -
brilliant explosion program.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

SCREEN FX 2
by Damian Scattergood

Damian Scattergood, the Z80 Project Leader of Emerald Software,
nominated as Mr. Benevolence for three years in succession, was so
impressed with my screen effects special a few months back (swell)
that he decided to submit a compendium of routines himself. I was so
impressed I printed them.

Lines
The Spectrum screen display is a complicated beast, using all manner
of confusing and downright irritating structural nuances that can make
it a major hurdle for a novice. I won't go into detaiLs but briefly
there are 192 pixel lines, divided into three blocks of 64 lines,
covering memory locations 16384 to 22527; the screen addresses go in
batches of eight so that logically the address you want is never in
the right place. Well, something like that anyway.

These two routines are used to calculate the screen address of the
next scan line up or down. You'll need an assembler to enter them in,
and they'll go in any address.

Next Line Down

;Execute this routine with HL
;pointing to the screen address
;and HL will return with the
;next line down

NXTC   ld   a,h
       and  7
       cp   7
       jr   z,LINEE
       inc  h
       ret
LINEE  ld   a,l
       and  224
       cp   224
       jr   z,NCHAR
       ld   de,1760
       and  a
       sbc  hl,de
       ret
NCHAR  ld   de,32
       add  hl,de
       ret

Next Line Up

LSTC   ld   a,h
       and  7
       jr   z,SALI
       dec  h
       ret
SALI   ld   a,l
       and  224
       jr   z,SASE
       ld   de,1760
       and  a
       adc  hl,de
       ret
SASE   ld   de,32
       and  a
       sbc  hl,de
       ret

Nibbling
The next program is one big demo, split up into five easily digestible
parts. It combines the two previous/next scan-line routines into a
mammoth scrolling demo, shifting windows all over the place, up, down,
left and right! And to boot, it scrolls by four pixels (or "nibbles"
if you want to be confused by jargon). Very useful for faster than
fast scrolls.

The Huge Demo

;This whopper (fnurk!) is the
;demo, using the previous two
;routines

DEMO   call FILL
       ld   b,20
LOOP1  push bc
       ld   hl,16384+15
       ld   bc,10c0h
       call SLEFT
       ld   hl,16384+16
       ld   bc,10c0h
       call SRIGHT
       pop  bc
       djnz LOOP1
       ld   b,20
LOOP2  push bc
       ld   hl,16384
       ld   bc,6020h
       call SUP4
       pop  bc
       djnz LOOP2
       ld   b,20
LOOP3  push bc
       ld   hl,20640
       ld   bc,6020h
       call SDOWN4
       pop  bc
       djnz LOOP3
       ret
This is the main stem of the program and addresses sub-routines with
CALL statements (rather like GOSUBs in Basic). The register HL holds
the top right screen address of the window to be scrolled, and BC
holds the height and width of that window.

FILL   ld   hl,16384
       ld   bc,6143
LOOP4  ld   (hl),l
       inc  hl
       dec  bc
       ld   a,b
       or   c
       jr   nz,LOOP4
       ret
So there's something there to scroll, this small routine simply fills
the screen with garbage. Not just any old garbage though, strategic garbage.

SLEFT  push hl
DEEP   push bc
       xor  a
LOOP5  rld
       dec  hl
       djnz LOOP5
       pop  bc
       pop  hl
       call NXTC
       push hl
       dec  c
       jr   nz,DEEP
       pop  hl
       ret
This sub-routine shifts the contents of a window left by four pixels,
using the specific instruction 'RLD'.

SRIGHT push hl
DEEP1  push bc
       xor  a
LOOP6  rrd
       inc  hl
       djnz LOOP6
       pop  bc
       pop  hl
       call NXTC
       push hl
       dec  c
       jr   nz,DEEP1
       pop  hl
       ret
This similar sub-routine shifts the contents of the window right by
four pixels, using the specific instruction 'RRD'.

[This scrolls up, not down. JimG]
SDOWN4 push hl
       call LSTC
       call LSTC
       call LSTC
       call LSTC
       ex   de,hl
       pop  hl
       ex   de,hl
LOOP7  push bc
       push de
       push hl
       ld   b,0
       ldir
       pop  hl
       call LSTC
       pop  de
       ex   de,hl
       push de
       call LSTC
       pop  de
       ex   de,hl
       pop  bc
       djnz LOOP7
       ret
The down scroll routine works in a different way. It calculates the
address four bytes below and block moves everything in the window to
that address, creating a "scrolling" illusion.

[This scrolls down, not up. JimG]
SUP4   push hl
       call NXTC
       call NXTC
       call NXTC
       call NXTC
       ex   de,hl
       pop  hl
       ex   de,hl
LOOP8  push bc
       push de
       push hl
       ld   b,0
       ldir
       pop  hl
       call NXTC
       pop  de
       ex   de,hl
       push de
       call NXTC
       pop  de
       ex   de,hl
       pop  bc
       djnz LOOP8
       ret
This up scroll routine is almost identical as the previous one, but
calculates the address four bytes above instead.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

EXPLODE!
by Thurstan Felstead
from Your Sinclair, March 1989

BANG!

Don't you just love explosions (you were wondering what that title was
about weren't you)? I like explosions. Especially those gorgeous, big,
noisy ones with lots of debris you see on posh games. Thurstan "insane"
Felstead seems to like them too. Nice man. He's written a routine so
you can appreciate them. BANG! he called it. (Oo-er!) [Well, he called
it Explode!, actually, but never mind. JimG]

Kaboom!
The routine is in machine code, starts at 61440 and is 912 bytes long.
Not particularly enormous considering the startling and, one might
say, splendiferous effect of the aforementioned routine. Use the Hex
Loader (which is now drawing its pension) to enter the hexadecimal
block and then save the result to tape with SAVE "explode" CODE 61440,912.
But wait! Before you RANDOMIZE USR 61456, examine the following
parameters for information on how to set up your conflagration.

Explode!
There are five variables which must be set up before you can run the
program:

1) The Explosion Window
This is the rectangular area in which the object detonates. It's outer
edges must not touch the edge of the screen in any direction and it
must be larger than the object window (see next reference). To create
a window, you need to POKE the top left co-ordinates and bottom right
co-ordinates in the following way:
POKE 61440, top left x co-ordinate (4-251)
POKE 61442, top left y co-ordinate (4-171)
POKE 61441, bottom right x co-ordinate (4-251)
POKE 61443, bottom right y co-ordinate (4-171)

2) The Object Window
This is the rectangular area that contains the object to be ignited.
It is set up in the same way as the explosion window but it must be
smaller. POKE its variables like this:
POKE 61445, top left x co-ordinate
POKE 61447, top left y co-ordinate
POKE 61446, bottom right x co-ordinate
POKE 61448, bottom right y co-ordinate

3) Gravity
This factor governs the amount of weight attributed to the exploding
pixels. POKE 61444 with the following factors of your choice:
0 - no gravity whatsoever
1 - pretty damn strong gravity
2 - slightly weaker
3 - getting weaker
4 - shuffling toward wimpiness
5 - Phil South

4) Explosion Speed
This variable affects the speed the object fulminates (good word, eh?)
at. Choose the numbers to POKE into the address 61449:
0 - normal explosion speed
1 - slow
2 - slower
3 - slower still
4 - barely moving
5 - as stiff as a board

5) Velocity
This cunning parameter decides the speed at which the particle erupt.
Choose a speed from 1 to 255 and then:
POKE 61450, INT (velocity/2)
POKE 61451, velocity

Now if all that isn't simple then I wear a toupee. And there's a
demonstration as well to eradicate your confusion completely. But
remember BANG! can only handle a maximum of eight hundred pixels or
else it goes gah-gah (just like its author).

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Byeee!
Well that's it for yet another month. Next issue you can look forward
to a Star-Tip [Except that there wasn't one, of course, just another
catalogue of McCandless cock-ups. JimG], some more snazzy border
effects [Nope, none of those either. JimG], a background scroller
[Errm ... I'll let you guess if that appeared in next month's issue.
JimG] ... well, you'll just have to wait and see. In the meantime,
however, if you feel like running the risk of winning #50 for your
best programming effect [sic] then drop me a line at Program Pitstop,
YS, 14 Rathbone Place, London W1P 1DE. Until then, happy programming.
