PROGRAM PITSTOP
from Your Sinclair #32 (August 1988)

Your name please? David McCandless. And your specialist subject? The
contents of this month's Program Pitstop. Correct!


Hello, good evening and welcome to another edition of everyone's
favourite programming column. This column gets better and better every
month and why shouldn't it? It's simply the best. But enough of this
self-appreciation and on with the show ...

This month we have an absolutely brilliant Spite Editor by Simon Owen,
and then the second instalment of our star-routine series by Neil
Hopkinson. After that, check out the energy, tears and hair saving
utility from Tom Baker himself. And finally, there's Star Tip numero 11
from his programmingness Andrew Whittaker. Good show eh?

Don't forget, folks, keep those contributions coming. And just to show
how much I appreciate them, each routine printed wins a game, and the
best routine printed each month receives a cash reward of #50! Mega-
wow-wows! So don't delay, mail today. The name is David McCandless and
the address is Program Pitstop, Your Sinclair, London W1P 1DE. Be here
or be squeere! (What? Ed).


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


Sprite Editor - Simon Owen (Your Sinclair-August 88-Page 80)
[files SPRITE-E.*]

It's been ages since we had a sprite designer, and out of the lot that I've
collected Simon Owen's really caught my eye (ouch!). Why did it catch my eye,
you may ask? Because it's utterly and totally brilliant of course. For an 
amateur attempt, this program is distinctly professional. It's really, really,
really good and well worth the 2682 bytes of typing.
 "The Editor is a 100 percent machine code, high quality, user friendly, grap-
hics utility, which has many extra features to make designing and editing easy
and enjoyable." says Simon and I couldn't have put it better myself, so I 
haven't!
 Got the message? Good, on with the show...

METHOD

 As normal, type in the endless list of hex using the Hex Loader. The code be-
gins at 25000 and is 2688 bytes long so save it with SAVE "editor"CODE 25000,
2688. Then just RANDOMIZE USR 25000 to get it running.

WHAT'S WHAT

 After running, the following is shown on screen:
 - the current examine address in the top left (initially 27904)
 - the current sprite (actual size), in the top right
 - the current mode in the bottom left (VIEWING, EDITING, SAVING or LOADING)
 - the magnified sprite in a grid (you can't miss it!)
 - confirmation instructions between the viewing window and the current ad-
   dress (in all cases, answer either "Y" or "N")

VIEWING MODE

 The Editor works in two main modes. Viewing mode is used to search through
memory to locate sprites or to find a free space:

*Q       - Increase by 2 window width 
*A       - Decrease by 2 window width 
*O       - Decrease by 1 
*P       - Increase by 1 
*W       - Increase by 32 window size
*S       - Decrease by 32 window size
 H       - Decrease by 1000
 J       - Increase by 1000
 E       - Enter EDIT mode
 ss      - Return to Basic
 G       - Toggle grid On/Off
 L       - Load file (headerless)
 K       - Intelligent save (saves what was last loaded)
 F/T     - Window copy
 F       - Move to window to be copied
 T       - Move to place to be copied
 9/0     - Save block
 9       - Move to first character
 0       - Move to last character
 1,2,3,4 - Change grid width

EDITING MODE

 The other mode is the mode for changing or designing your own sprites:

 Q - Cursor up
 A - Cursor down
 O - Cursor left
 P - Cursor right
 M - Set/Reset pixel
 Z - Return to VIEWING mode
 I - Invert window
 V - Flip vertical
 B - Flip horizontal
 C - Clear window
 7 - Scroll window up
*8 - Scroll window right

 And for this superb contribution, Simon receives a cash reward and a free 
game of his choice.

THE CODE

 Mammoth, but worth it if you're serious about graphic design or game program-
ming.

------------------------------------------------------------------------------
TYPE: Utility  

COMMENT: Keys in Viewing Mode and Editing Mode marked '*' were mistypes in
the text in Your Sinclair, and Miodrag Stancevic helped correcting this.


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


MILKY WAY
by Neil Hopkinson
from Your Sinclair #32 (August 1988)
[files MILKYWAY.*]

Yes, the routine which doesn't ruin your appetite (though it might make
you feel space-sick). Here as promised last month is a four-directional,
3D, interrupt driven, sit up and beg star routine, courtesy of a very
able Neil Hopkinson. And what's more, the whole program he's sent in is
self-contained, which makes my job easier and your job simpler.

Points

Ouch! They're sharp. Nope, seriously folks, here are some points I feel
I must make concerning this fabbaroony routine:
1. If you've got a 128K, ask yourself why and then remember to use this
program in 48K mode only.
2. Printing, clearing the screen, or making funny noises is not
recommended while this program is running, unless accompanied by a
responsible adult.
3. The program uses Interrupt Mode 2, so interrupts should not be
disabled.

They were the warnings and now for the hi-tech, brain-blending info:
a) The 45 stars are stored from 64376 to 64468 in the format: X co-ord,
Y co-ord.
b) The code starts at 64000 and is 512 bytes long.
c) To get the stars going, either use a korma curry or RANDOMIZE USR 64000.
d) To stop the stars going, either use a bung or RANDOMIZE USR 64003.
e) You can change the amount of stars per field (currently fifteen), by
POKEing 64334, number of stars. But don't put in more than 15.

Interrupts? What The - ?

Again, it's time for me to adopt my machine code drone voice and tell
you what interrupts are. Interrupts are specialised instructions that,
when used correctly, can enable you to run two programs simultaneously.
What you see is actually an illusion; the computer is just jumping
between the two routines every 50th of a second, so it only seems like
the two are running together. They are especially useful when used with
Basic as they allow the user to run a machine code routine and type in
Basic or whatever.

The Program

Here it is, and there it isn't. It's not that long considering the
effect it gives. Save it with: SAVE "stars" LINE 10 and you're awayyy!


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


STAR TIP 11
by Andrew Whittaker

Huraayyhhh! Yet another Star Tip for you to drool over this month.
Number eleven too. I wonder if we'll get into the twenties by the end
of the year. Who knows? I certainly don't. This Star Tip is by Andrew
Whittaker and it's a simple, but essential print routine.

Andrew
Until Christmas, Andrew was a member of the highly skilled and
prolific Graftgold programming team at Firebird. He helped in the
coding of such fruit-cakes as Flying Shark and Magnetron. He's
currently working freelance (I love that word), on arcade titles.
Thanks billions Andrew and keep them coming whenever you feel the urge.

Method
This is the first source code listing we've had for yonks, mainly
because its un-documented ones that I receive all the time. To use it
you must use an assembler (any one will do), and then save the source
off to tape.

Printing
The character print routine in the ROM (rst 10), is notoriously slow,
so this routine replaces that snail of a program, at the expense of
error handling and control code handling. To print a character you
must load the accumulator with the ASCII code of the character and
then call the print routine.

	LD A,"B"
	CALL PRINT

This'll print a "B" on the screen. To specify PRINT AT co-ordinates,
you must use the code 22, followed by a row and a column value. So to
print the letter "B" at screen co-ords 7,10 use:

	LD A,22
	CALL PRINT
	LD A,7
	CALL PRINT
	LD A,10
	CALL PRINT
	LD A,"B"
	CALL PRINT

Alternatively a direct screen address can be passed to the routine by using:

	LD HL,screen addr
	LD (XYPOS), HL

There's also a string print routine which prints the string pointed to
by HL, and with the byte 255 as an end marker:

	LD HL,MESSAGE
	CALL STRPRNT
	RET
MESSAGE DEFM 22,11,6,"Your Sinclair",255

This is the equivalent to PRINT AT 11,6;"Your Sinclair" in Basic. [I
changed STRPRNT to save and restore HL', to avoid a crash on returning
to BASIC. JimG] So there you are.

Source Code Listing
0000            00000  ;Star Tip 11
0000            00000  ;Text Print Handler
0000            00000  ;by Andrew Whittaker
0000            00000  ;from Your Sinclair, Aug'88
0000            00000  ;
0000            00000  ;Using OCP Editor/Assembler
0000            00000  ;
0000            00000  ;!! WARNING !!
0000            00000  ;The PRINT routine corrupts HL'
0000            00000  ;and so causes a crash on return
0000            00000  ;to BASIC. Anything using PRINT
0000            00000  ;needs to save HL' and restore
0000            00000  ;it before returning to BASIC.
0000            00000  ;                         [JimG]
0000            00000  ;
0000            00000  ; input: character code in A
0000            00000  ;output: chr to screen
0000            00000  ;        print pos advanced
0000            00000  ;alternate registers corrupted
0000            00000         org  65000
FDE8 D9         00000  PRINT  exx
FDE9 6F         00000         ld   l,a
FDEA            00000  ;
FDEA            00000  ;test for x-y update
FDEA            00000  ;
FDEA 3A47FE     00000         ld   a,(PFLAG)
FDED A7         00000         and  a
FDEE 2034       00000         jr   nz,CONTRL
FDF0 7D         00000         ld   a,l
FDF1            00000  ;
FDF1            00000  ;test for CHR$ 22
FDF1            00000  ;
FDF1 FE16       00000         cp   22
FDF3 2828       00000         jr   z,GETXY
FDF5            00000  ;
FDF5            00000  ;find char definition
FDF5            00000  ;
FDF5 2600       00000         ld   h,0
FDF7 29         00000         add  hl,hl
FDF8 29         00000         add  hl,hl
FDF9 29         00000         add  hl,hl
FDFA ED5B48FE   00000         ld   de,(FONT)
FDFE 19         00000         add  hl,de
FDFF ED5B4AFE   00000         ld   de,(XYPOS)
FE03            00000  ;
FE03            00000  ;print the character
FE03            00000  ;
FE03 0608       00000         ld   b,8
FE05 7E         00000  PRLOOP ld   a,(hl)
FE06 12         00000         ld   (de),a
FE07 14         00000         inc  d
FE08 23         00000         inc  hl
FE09 10FA       00000         djnz PRLOOP
FE0B            00000  ;
FE0B            00000  ;increment the print position
FE0B            00000  ;
FE0B 15         00000         dec  d
FE0C 7A         00000         ld   a,d
FE0D 0F         00000         rrca
FE0E 0F         00000         rrca
FE0F 0F         00000         rrca
FE10 57         00000         ld   d,a
FE11 13         00000         inc  de
FE12 7A         00000         ld   a,d
FE13 87         00000         add  a
FE14 87         00000         add  a
FE15 87         00000         add  a
FE16 57         00000         ld   d,a
FE17 ED534AFE   00000         ld   (XYPOS),de
FE1B            00000  ;
FE1B            00000  ;exit the calling routine
FE1B            00000  ;
FE1B D9         00000         exx
FE1C C9         00000         ret
FE1D            00000  ;
FE1D            00000  ;signal next two bytes are
FE1D            00000  ;x-y coordinates
FE1D            00000  ;
FE1D 3E02       00000  GETXY  ld   a,2
FE1F 3247FE     00000         ld   (PFLAG),a
FE22 D9         00000         exx
FE23 C9         00000         ret
FE24            00000  ;
FE24            00000  ;update row and column (x+y)
FE24            00000  ;
FE24 3D         00000  CONTRL dec  a
FE25 3247FE     00000         ld   (PFLAG),a
FE28 2812       00000         jr   z,COL
FE2A            00000  ;
FE2A            00000  ;set new row value
FE2A            00000  ;
FE2A 7D         00000  GETROW ld   a,l
FE2B E618       00000         and  0011000b
FE2D F640       00000         or   1000000b
FE2F 67         00000         ld   h,a
FE30 7D         00000         ld   a,l
FE31 E607       00000         and  0000111b
FE33 0F         00000         rrca
FE34 0F         00000         rrca
FE35 0F         00000         rrca
FE36 6F         00000         ld   l,a
FE37 224AFE     00000         ld   (XYPOS),hl
FE3A D9         00000         exx
FE3B C9         00000         ret
FE3C            00000  ;
FE3C            00000  ;get new column value
FE3C            00000  ;
FE3C 3A4AFE     00000  COL    ld   a,(XYPOS)
FE3F E6E0       00000         and  11100000b
FE41 B5         00000         or   l
FE42 324AFE     00000         ld   (XYPOS),a
FE45 D9         00000         exx
FE46 C9         00000         ret
FE47            00000  ;
FE47            00000  ;variables
FE47            00000  ;
FE47 00         00000  PFLAG  defb 0
FE48 003C       00000  FONT   defw 3c00h
FE4A 0040       00000  XYPOS  defw 16384
FE4C            00000  ;
FE4C            00000  ;PRINT A STRING
FE4C            00000  ;entry:- addr of string in HL
FE4C            00000  ;terminated by a FF byte
FE4C            00000  ;exit:- string printed to screen
FE4C            00000  ;accepts xy pos via CHR$ 22,x,y
FE4C            00000  ;corrupts HL,A,alternate set
FE4C            00000  ;
FE4C 2161FE     00000  MESPRT ld   hl,MESSGE
FE4F D9         00000  STRPRT exx
FE50 E5         00000         push hl
FE51 D9         00000         exx
FE52 7E         00000  STRPR2 ld   a,(hl)
FE53 FEFF       00000         cp   255
FE55 2806       00000         jr   z,STRPR3
FE57 CDE8FD     00000         call PRINT
FE5A 23         00000         inc  hl
FE5B 18F5       00000         jr   STRPR2
FE5D D9         00000  STRPR3 exx
FE5E E1         00000         pop  hl
FE5F D9         00000         exx
FE60 C9         00000         ret
FE61            00000  ;
FE61 160B06     00000  MESSGE defb 22,11,6
FE64 596F7572   00000         defm 'Your Sinclair'
FE68 2053696E
FE6C 636C6169
FE70 72
FE71 FF         00000         defb 255


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


