20.02.2013 Views

ZX Computings - OpenLibra

ZX Computings - OpenLibra

ZX Computings - OpenLibra

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

sves<br />

ile<br />

sre insect is<br />

ion*t<br />

n<br />

lsect<br />

s<br />

k square in<br />

snalty<br />

xt location<br />

jf game<br />

j far<br />

nother<br />

for another<br />

setting W<br />

tart of<br />

The display file is a block of<br />

addresses that contain the<br />

CHR$ codes that form the<br />

display on the TV screen. At<br />

the beginning of the file we<br />

find a Newline CHR$, and<br />

there are also Newline CHR$<br />

at the end of each line. As we<br />

can print up to 32 CHR$ per<br />

line, every 33rd CHR$ = a<br />

Newline CHRS. These are<br />

used by the <strong>ZX</strong>81 ROM as<br />

references and should not be<br />

altered.<br />

To find the position of the<br />

display file we can use: 5 LET<br />

Z= 1 + PEEK 16396 + 256 *<br />

PEEK 16397. "Z" will now be<br />

the address of the first print<br />

position on the screen. If we<br />

POKE Z with any CHR$ code<br />

then this CHR$ will be printed<br />

n the first position on the<br />

position, and so on, as shown<br />

on the chart.<br />

To prevent printing, or<br />

should I say POKEing, to the<br />

33rd CHR$ there are generally<br />

three different approaches.<br />

1. To use a dedicated POKE<br />

routine that can never work<br />

out to hit a 33rd CHR$.<br />

2. To peek at the position on the<br />

screen before POKEing, ie if<br />

PEEK (position) = 118<br />

(Newline CHR$) then don't<br />

POKE here.<br />

3. To use a formula that will<br />

automatically skip every 33rd<br />

CHR$, ie let us say X is the<br />

position we wish to poke then<br />

we can use POKE<br />

(Z + X + INT(X/32),(CHR$<br />

code) this will automatically<br />

add one after every 32nd<br />

CHR$ making 33 = 34<br />

effectively, and so on for<br />

every line. A simple program<br />

using this formula :-<br />

5 LET Z= 1 + PEEK 16396<br />

+ 256*PEEK 16397<br />

10 FOR X='TO 763 STEP 7<br />

20 POKE (Z + X + INT(X/32)),8<br />

30 NEXT X<br />

40 STOP<br />

(Note:- That this formula<br />

automatically adds one to<br />

every 33rd position. The<br />

memory map chart must be<br />

read as (position) — (line<br />

number on left) to give the<br />

correct number per position).<br />

ANOTHER SHORT PROGRAM<br />

5 LET Z = 1 + PEEK 16396<br />

+ 256*PEEK 16397<br />

10 LET A = 0<br />

20 LET B = 33<br />

25 IF A< 0 OR A> 767<br />

THEN GOTO 35<br />

30 POKE Z + A + INT/A/32),<br />

128<br />

35 LET A = A + B<br />

40 IF A>0 THEN LET B - 33<br />

50 fF A>767<br />

THEN LET B = -31<br />

60 IF A = 27 THEN CIS<br />

-70 GOTO 25<br />

POKEing<br />

<strong>ZX</strong>8t<br />

One thing to remember is that<br />

the display file is using the<br />

memory immediately after the<br />

BASIC program. This means<br />

that if the BASIC program is<br />

altered then "run" is required<br />

to find the new value for "Z",<br />

or at least the new value for<br />

"Z" must be calculated.<br />

An idea of a simple program<br />

may be as follows. We have a<br />

gun at the bottom left-hand<br />

side of the screen. Pressing<br />

any key from 0 to 9 will fire<br />

the gun at a target at the to<br />

line on the screen, "0" to fire<br />

straight up, "9" to fire<br />

farthest right, we will also<br />

need to PEEK at the top line in<br />

the relevant place to see if we<br />

- D H O l V f<br />

- PROGRAMMING<br />

have hit the target.<br />

Looking at this idea we can<br />

see that system 1 can be used<br />

as we don't intend to POKE<br />

over the edges of the screen,<br />

and the plotting involved has a<br />

limited path.<br />

After the normal line 5 to<br />

find "2" we then POKE<br />

Z + 726,1 28 to put a square<br />

block for the gun. Then to fire<br />

straight up to the top line is<br />

easy, we simply POKE<br />

Z + 693,23 then successively<br />

- 33 from this, poking all the<br />

way up to 0. Taking the top<br />

line to equal 32 CHR$ wide<br />

and the number of lines down<br />

to the gun being 22 we must<br />

shift to the right 32 + 22 =<br />

1.5 positions per line to hit the<br />

top right-hand corner.<br />

Considering we have 9 shifted<br />

to the right options (0 to 9) if<br />

we use 1.5 + 9 = 0.166*<br />

(the INKEY$ number) this will<br />

give us the right amount of<br />

shift per line to plot our gun<br />

fire. I've rounded down to<br />

0.16 so there is no chance of<br />

over-stepping the corner if 9 is<br />

selected. So the basic program<br />

is shown as, an INKEYS input,<br />

followed by the fire routine.<br />

(Note: - The line numbering<br />

should be followed to leave<br />

room for the rest of the<br />

program).<br />

UMMER 1983 z x COMPUTING SUMMER 1982 53

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!