PROGRAM PITSTOP
from Your Sinclair #24 (December 1987)

If you'd rather program your Speccy than wibble your joystick (you'll go
blind!), just pull in to Program Pitstop, and get yourself fitted up
with the latest programming tips.


Yes, there's more! More top programmers' hints, routines and programs,
more of your own best routines and utilities, and basically more
programming than any other Sinclair mag! Why go anywhere else when
you've got the best right here in your hand?

This month we've got another bumper crop of stuff from such luminaries
as David Jones, of Magic Knight / Stormbringer fame, who's got some
natty routines for all you 128 programmers; and Raffaelle Cecco, Hewson's
Exolon supremo, with the perfect sprite routine. We've also the best in
amateur programming talent, from Craig Turner and Richard Fawley, who've
sent us a stupendous screen loading utility which allows you to load a
screen in up to 30 different ways. But more of all that in a minute.


Calling All Programmers

If you're a professional programmer we need you! Send us your favourite
routines on tape, with a mugshot and your life story, and you'll feature
in Program Pitstop. Just think of all your fans reading the Pitstop and
hanging on your every byte! (Huh? Ed) And even if you're not a famous
programmer, don't despair, you can still display your programming
prowess, by sending us your favourite routine or utility program,
shorter the better, and we'll take a look at it. If it's totally skill,
we'll print it right here in the Pitstop and you'll get all the fame and
adulation you've always dreamed of ... and who knows, you might get an
offer from a top software house to write its next smasheroo! We've
already had people phone use wanting to hire our readers as programmers,
so get in there, chum!


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


STAR TIP 7 - sprite mover
by Raffaelle Cecco
from Your Sinclair #24 (December 1987)
[files STARTIP7.*]

Hewson has been very good to use since we started the jolly old Pitstop.
You remember Dominic Robinson's Rainbow Processor program? Well, here's
another Hewson superstar, Raffaelle Cecco, with a great sprite moving
program which, apart from being really nifty, is possible the smallest
chunk of sprite code we've ever seen. And it really couldn't be easier
to use either.

Method

All you have to do is type in the tiny Basic listing ... well, the
single line, actually, and save that off to tape. Then, pass the hex
dump through the Hex Loader, and save that off. Voila! Instant sprites,
just add water. To see a sprite demo, just type:

RANDOMIZE USR 65000

and little YS-shaped sprites will bounce all over the screen. To use the
sprites in a more meaningful way, you have to POKE the following infor-
mation into memory:

POKE 65148 and 65149 with the address of the first sprite (default 65342)
POKE 65129 with X co-ordinate of sprite (0-255)
POKE 65130 with Y co-ordinate of sprite (0-191)
POKE 65131 with sprite number (0-255)
RANDOMIZE USR 65127 to print the sprite on-screen

NOTE: To POKE the address to 65148 and 65149, you need to first convert
the figure into hex (so, for example, 65342 = FF3E), cut it in two (so
you've got FF and 3E hex, or 255 and 62 decimal). Now, the FF bit is
called the 'Hi Byte', and 3E is the 'Lo Byte'. So now you have to POKE
the Lo Byte into 65148 and the Hi Byte into 65149. This way of splitting
up four digit hex numbers is the usual way of POKEing them into memory,
Lo Byte first, Hi Byte second.


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


STAR TIP 8 - 128K routines - "Program Pitstop"
by David Jones
from Your Sinclair 24 (Dec.1987)
[files STARTIP8.*]


David Jones is no stranger to these pages, having contributed a
brilliant little tip to last month's Shop. Being a generous kind of
gut, he's listed out some useful routines for 128 programmers, which
you can use to make really whizzy games. Not much explanation is
needed, because the routines are heavily commented, but here's a quick
resume of what they do.

PSWAP    - 128 page swap
PAGEA    - calls sub-routine on any page
IMODESET - sets up Interrupt Mode 2
IMODE    - Interrupt handler
MUSICON, MUSICOFF, PLAYIT - samples of how to call a sub-routine

[There was no MUSICOFF routine listed in the magazine. JimG]


RAM PAGE ALLOCATION

--- ROM ---!-- PAGE 2 --!- FIXED RAM -!--
           !- SCREEN$1 -!-- PAGE 5 --! USL
PAGE 0 - NORMALLY RESIDENT AT C000H
INTERRUPT VECTORS AND MAIN CODE
PAGE 1 -                AT C000H
PAGE 2 - FIXED RAM PAGE AT 4000H
PAGE 3 -                AT C000H
PAGE 4 -                AT C000H
PAGE 5 - FIXED RAM PAGE AT 8000H
PAGE 6 -                AT C000H
PAGE 7 - SCREEN$ 2      AT C000H


MUSICFLG: DB 0
DEFSCR:   DB 0
FIXPAGE:  DB 0
PAGENO:   DB 0

;Note: These subroutines must be placed below C000H to work properly.
;      Crashes result otherwise.

PAGEPORT: EQU 7FFDH

;This subroutine will change the page at C000H.
;Entry Conditions:
;A register = new page number
;Exit Conditions:
;FIXPAGE contains new page number
;A register = value sent to port
;All other registers preserved

PSWAP:    PUSH BC
          LD (FIXPAGE),A
          LD C,A
          LD A,(DEFSCR)
          ADD A,C         ;add 8 if alternate screen is on show
          OR 16
          LD BC,PAGEPORT  ;ensure Spectrum ROM always present
          OUT (C),A
          POP BC
          RET

;CALL a subroutine on a given page at a given address.
;Entry Conditions:
;A register = page number
;HL register pair = address of subroutine
;Exit Conditions:
;FIXPAGE contains new page number
;A register = value sent to port
;All other registers preserved

PAGEA:    LD (PAGEAV+1),HL
          CALL PSWAP
PAGEAV:   CALL 0          ;call address supplied in HL on entry at PAGEA
          PUSH AF
          XOR A
          CALL PSWAP      ;set page 0 in place (normal 48K page)
          POP AF
          RET

;Music Control Routines

MUSICON:  LD HL,MON       ;address of Music On subroutine
          LD A,MPAGE      ;page number where music is stored
          JR PAGEA

PLAYIT:   LD A,(MUSICFLG)
          OR A
          RET Z
          LD HL,MPLAY     ;address of Play Music subroutine
          LD A,MPAGE      ;page number where music is stored
          JR PAGEA


;Interrupt Mode Setup

;Top useable memory address equals 0FFF3H (65523)
;due to interrupt control code.
;FFF4H  IVECTOR:JP IMODE
;FFF7H  @BB8   :DS 8      ;(8 byte temp store buffer)
;FFFFH          JR IVECTOR

IMODESET: POP HL          ;return address
          LD SP,NEWSTACK
          PUSH HL
          XOR A
          LD (DEFSCR),A
          LD (IY+65),A    ;IMODE off
          LD (IY+87),3    ;OVER 1
          LD (IY+48),8    ;CAPS on
          LD HL,IMODETAB
IMODELP:  LD A,(HL)
          CP 255
          JR Z,IMODELX
          PUSH HL
          CALL PSWAP
          LD A,18H
          LD (0FFFFH),A
          LD A,0C3H
          LD (0FFF4H),A   ;JP IMODE
          LD HL,IMODE
          LD (0FFF5H),HL
          POP HL
          INC HL
          JR IMODELP
IMODELX:  XOR A
          CALL PSWAP
          LD HL,0BE00H
          LD A,H          ;place in I reg below
          LD DE,0BE01H
          LD BC,256
          LD (HL),255
          LDIR            ;build 257*0FFH table
          DI
          LD I,A
          EI
          HALT
          XOR A
          LD (IY+65),A
          IM 2            ;re-vectored interrupts
          RET

IMODETAB: DB 0,1,3,4,6,7,255

;Interrupt Handler
;Note that this doesn't do anything useful here except play the tune,
;which can be placed on a different page. I have included it so that
;you can place your own sub-routines below (ie. Sprites).

IMODE:    PUSH AF
          LD A,(FIXPAGE)
          LD (IMODEV+1),A
          CALL PLAYIT
;Place your sub-routines here
          LD HL,(FRAMES)
          INC HL
          LD (FRAMES),HL
          LD A,H
          OR L
          JR NZ,IMODEX
          INC (IY+64)     ;FRAMES+2
IMODEX:   CALL 02BFH      ;keyboard scan
IMODEV:   LD A,0
          CALL PSWAP
;Now POP all the registers that you pushed earlier.
          POP AF
          EI
          RET


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


SCREEN$ SAVER
by Craig Turner & Richard Fawley
from Your Sinclair #24 (December 1987)
[files SAVER.*]

SCREEN SPLITTER

After reading the August issue of Program Pitstop, Craig and Richard
decided to favour us with this amazing Screen Splitting utility. Using
the routine enables you to save a SCREEN$ in one of 30 different ways:
combinations of top pixels, middle pixels, bottom pixels, and attributes.

To show you what good value we offer you, this is two programs for the
price of one. The main program lets you LOAD a screen and SAVE it in the
different combos. The Organiser program shows you the program lines you
must include in your programs to LOAD the screen bits back again. The
two totally independent programs are menu driven, so just follow the
screen instructions.

NOTE: The loading of the screen bits is done in conjunction with the
Loader Code program - a few bits of hex that you can load with a hex
loader or just bung them into memory with a Multiface.


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


--
Another Fine Product transcribed by:
Jim Grimwood, Weardale, England (http://www.users.globalnet.co.uk/~jimg/)
--
