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.

9<br />

S<br />

e<br />

E<br />

k<br />

isplay-file<br />

we can<br />

POKEing at<br />

)KE onto a<br />

it is first<br />

e a display-<br />

ccession of<br />

will not<br />

though a<br />

p PRINTing<br />

A/ill, it is very<br />

kily<br />

es a line full<br />

>rt loop can<br />

ethe<br />

if screen<br />

tweeters<br />

ill as spaces<br />

Mile. Up to<br />

inted in this<br />

J that we<br />

have a display-file we can now<br />

take a PEEK at its starting<br />

address. The following<br />

subroutine achieves this and it<br />

is used in all subsequent<br />

listings:-<br />

Of course the display-file<br />

has to exist before we can<br />

start PEEKing and POKEing at<br />

it. If we wish toi POKE onto a<br />

blank screen then it is first<br />

necessary to create a displayfile<br />

full of spaces.<br />

Unfortunately a succession of<br />

PRINT statements will not<br />

achieve this and although a<br />

FOR . . NEXT loop PRINTing<br />

individual spaces will, it is very<br />

cumbersome. Luckily<br />

PRINT . . . creates a line full of<br />

spaces so a short loop can be<br />

used to produce the required<br />

number of screen lines.<br />

Obviously characters can be<br />

used as well as spaces to<br />

create a display-file. Up to 23<br />

lines can be printed in this<br />

way.<br />

Having ensured that we<br />

have a display-file we can now<br />

take a PEEK at its starting<br />

address. The following<br />

subroutine achieves this and it<br />

is used in all subsequent<br />

listings:-<br />

500 LET P = PEEK{ 16397)<br />

510 IFP> 127<br />

THEN LET P = P — 256<br />

520 LET W = PEEK! 16396)<br />

+ P* 256<br />

530 RETURN<br />

It should now be obvious how<br />

we can use this address to<br />

POKE a character onto the<br />

screen. The following program<br />

establishes a blank displayfile,<br />

inputs a row and column<br />

number, POKEs character<br />

code 148 (inverse asterisk) at<br />

the relevant address and then<br />

inputs another "grid<br />

reference". When the program<br />

is run, inverse asterisks appear<br />

at your bidding anywhere on<br />

the screen<br />

10 LET P » 0<br />

20 LET W = 0<br />

30 FOR A = 1 TO 22<br />

40 PRINT<br />

50 NEXT A<br />

60 INPUT A<br />

70 INPUTB<br />

80 IF A>22 OR B> 32<br />

THEN GOTO 60<br />

90 LET Y = (A — 1 > * 33 + 8<br />

100 GOSUB 500<br />

110 POKE W + Y,148<br />

120 GOTO 60<br />

500 LET P = PEEK(16397)<br />

510 IF P> 127 THEN LET<br />

P = P - 256<br />

520 LET W = PEEKI16396)<br />

+ P* 256<br />

530 RETURN<br />

The following two alterations<br />

UMMER 1983 zx COMPUTING SUMMER 1982<br />

to the listing extend this<br />

simple program:-<br />

Specify character to be<br />

POKEd:-<br />

84 INPUT C<br />

110 POKE W + Y,C<br />

(C is relevant character code)<br />

POKE character taken from<br />

the keyboard:-<br />

84 INPUT C$<br />

86 LET X = CODE (C$)<br />

88 IF X> 191<br />

THEN GOTO 84<br />

110 POKE W + Y,X<br />

it will be noticed that the<br />

programs above assign<br />

variables P and W before the<br />

first PEEK. This is because, as<br />

mentioned before, any<br />

variable assignment or initial<br />

input will alter the location of<br />

the display file. If you write<br />

any screen-POKE programs<br />

and find that the characters<br />

are displaced it will almost<br />

certainly be because a variable<br />

in either PEEK or POKE has not<br />

been previously assigned. A<br />

similar case is where an initial<br />

input or an assignment is<br />

made after a previous PEEK or<br />

POKE, when it will be<br />

necessary to take another<br />

PEEK at W before POKEing<br />

again.<br />

careful POKES<br />

Another thing worth<br />

remembering is that POKEing<br />

can be a hazardous occupation<br />

if you happen to POKE in the<br />

wrong place or even if you<br />

POKE an inappropriate<br />

character code in the right<br />

place. Care should therefore<br />

be taken when writing<br />

programs to ensure that<br />

characters are not POKEd<br />

outside the boundaries of the<br />

display-file. Usually such<br />

characters seem to disappear<br />

without trace but sometimes<br />

they can find their way into<br />

your program, invariably with<br />

unpleasant consequences<br />

Some bad POKEs can cause<br />

havoc with the video control.<br />

The codes for all statements,<br />

tokens and operators should<br />

definitely be avoided (ie codes<br />

> 191).<br />

A more subtle problem is<br />

that any extensive use of<br />

screen space is very expensive<br />

in terms of memory. A 23 line<br />

"blank" screen will occupy<br />

760 bytes of RAM, which<br />

does not leave much for the<br />

program if you are using the<br />

basic model <strong>ZX</strong>80 with 1 K of<br />

memory. You therefore need<br />

to think hard about the<br />

balance of memory<br />

POKElng<br />

l l t i p<br />

I<br />

• • •<br />

• • • •<br />

• • • • • •<br />

• • • • • •<br />

• • • • • •<br />

• • • • • •<br />

• • • • • •<br />

• • • • • •<br />

• • • • • •<br />

• • • • • •<br />

- - _ _ -<br />

2 3 4 5 6 7<br />

"Z * -<br />

0 v -<br />

A<br />

~ 0 ° f ** 0 B H »<br />

cu ..cute « J<br />

mi<br />

* X C<br />

• t * « *<br />

• • • • • • • • • • • • • • • • • • • •<br />

• • • • • • i • • • • • • • • • • • •<br />

' • • • • • • • • • • • • • • • • • • a<br />

• • • •<br />

• • • •<br />

• • • • • • • • • • • • • • •<br />

• • • • • • • • • • • • • • • •<br />

• • • • • • • • •<br />

•.•.•.•.•.•.•.a •<br />

• • • • • •<br />

i • • • •<br />

• • • • • • • • • • •<br />

• • • • • • • • • • •<br />

•v.v.v.<br />

- v . v . v . ,<br />

r v u<br />

«*o mam •<br />

V fl W M ><br />

8 9 o<br />

• o ' p '<br />

K L 37<br />

• • • • • • • • • • • • • • a • • • • • • • • • • • • •<br />

• • • • • • • • • • • • • • I<br />

• • • • • • • • • • • • • • a<br />

• •<br />

• • • • • • • • • • • • • • a<br />

• • • • • • • • • • • • • • I<br />

• • • • • • • • • • • • • a<br />

• • • • • • • • • • • • • •<br />

•<br />

•<br />

• •<br />

• • • • • • • •<br />

• • • • • • • •<br />

• • •<br />

•<br />

• • • • «<br />

• • • •<br />

• • • • • •<br />

• • • • • • • • • •<br />

•<br />

• • • • i<br />

• •<br />

•<br />

•<br />

•<br />

•<br />

•<br />

•<br />

•<br />

•<br />

•<br />

•<br />

•<br />

•<br />

•<br />

•<br />

•<br />

•<br />

requirements when writing<br />

screen-POKE programs if you<br />

have no memory expansion.<br />

Having grasped the<br />

principles involved in defining<br />

and locating the display-file it<br />

is relatively simple to<br />

manipulate it. Existing<br />

characters on the screen can<br />

be replaced by POKEing an<br />

alternative code at the same<br />

address. If this is the code for<br />

a space (0) then the character<br />

already on the screen<br />

disappears. By PEEKing at the<br />

address you plan to POKE to<br />

you can see what character<br />

already occupies that location,<br />

thus opening up the possibility<br />

of a conditional response. All<br />

the relevant character codes<br />

are identified in the <strong>ZX</strong>80<br />

handbook.<br />

• • • • • • • • • • • • • •<br />

' • • • • • • • • • • • • • a<br />

• • • • • • • • • • • • • a<br />

• • • • • • • • • • • • • a<br />

Graphic Example<br />

Finally, here is a simple games<br />

program that demonstrates<br />

the features discussed and<br />

which just fits onto the 1K<br />

<strong>ZX</strong>80. The computer prints up<br />

a display consisting of black<br />

and grey squares in a pattern<br />

determined by a number input<br />

at the beginning of each series<br />

of games. The object of the<br />

game is to get the<br />

'woodworm" Ian asterisk),<br />

which first appears at tine 8<br />

column 1, to eat its way<br />

across the screen to column<br />

32 in the least number of<br />

moves. The snag is that the<br />

black squares represent a<br />

particularly tough kind of<br />

wood and each time one is<br />

51

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

Saved successfully!

Ooh no, something went wrong!