MZ-800 course Chapter 5
|5. Pokes, Peeks, tricks, tips and things like that|
In this chapter you will see that a lot of funny stuff can be done with the computer and that you can figure out lots of this stuff for yourself in a simple way.
With the POKE-instruction the value of a certain address or a block of addresses can be altered. So in principle, you can poke every address, this means that in total 65,535 pokes are possible. Unfortunately 99% of those pokes have an effect that is not worth mentioning. For example, there are a few thousands of pokes that crash BASIC, but of what use is that? We can also disable all BASIC instructions by poking the value C9 to the right address, but why would we do that?
With the BASIC-monitor you can discover a few nice pokes for yourself, but you have to know where to look and what to look for. You could, for example, find out that output to the screen has to do with register B and DE amongst others. One line contains 40 ( 28 hexadecimal ) characters and that number is stored in DE. The corresponding memory will read 11 28 00. The exact memory location can be found with F ( Find ). Furthermore you need to know that the main part of the direct functions of the computer reside in the area from 0000H up to 1000H. So we will look for 11 28 00 in that area and that goes as follows:
BYE <cr> ( to enter the BASIC-MONITOR )
This results in:
:05E5=11 28 00 /.(. :071F=11 28 00 /.(. :07C2=11 28 00 /.(. :0829=11 28 00 /.(. :0897=11 28 00 /.(.
Now we can experiment a little by changing 28 with 50 for example and watching if something happens. If nothing happens then we undo our changes.
If we change 28 to 50 and type a few letters afterwards then we see that those letters appear on the screen in double size. So we have already found an interesting POKE. Now all we have to do is imbed this in a program and that could for example result in the following piece of code:
10 INIT "CRT:M1" 20 PRINT "NORMAL SIZE." 30 POKE $5E6,$50 40 PRINT 50 PRINT "DOUBLE SIZE." 60 POKE $5E6,$28:CURSOR 0,6
Of course you can find a lot more POKEs in a similar way, but this idea occurred to us, the writers of this book, also and we have already found most of the interesting Pokes On top of them all is the following:
With two Pokes it is possible to scroll the screen up in a similar way the hardware does this in VIDEO-RAM. To show the effect of these pokes, we have embedded them in a program.
10 INIT "CRT:M1" 20 LIST:LIST 30 WAIT 2000 40 CURSOR 0,24 50 POKE $898,$5 60 POKE $97E,$01 70 FOR T=1 TO 2000:PRINT:NEXT T 80 POKE $898,$28 90 POKE $97E,$00 100 WAIT 2000:INIT "CRT:M1"
These Pokes work in QD-BASIC as well as in tape BASIC, the same goes for the previous POKE. To avoid confusion, we shall give the QDBASIC variant as well as the tape BASIC one for all subsequent Pokes, even if they are equal.
And there are lots and lots of POKES. A few will follow below and on the next couple of pages. After that a list of useless POKES will be given. The pokes discussed here are more or less the most interesting and useful POKES known at this time. Of course there are many more, but not all of them are known or not worth mentioning. There are for example anti-BREAK pokes that are nice, but useless because a BASIC-program can not be secured for the full 100%. ( Unless the program resides on QD. In that case it can be secured against copying, but it will be rather expensive ).
POKES to speed up the saving and loading process of the tape recorder:
POKE $3B91,$23:POKE $3B97,$B:POKE $3B9B,$31
Original: POKE $3B91,$4C:POKE $3B97,$18:POKE $3B9B,$69
POKES for CURSOR X,Y:
The POKES below work in QD- as well as in tape BASIC and show that we can use two POKES instead of CURSOR X,Y.
10 INIT "CRT:M1" 20 FOR B=0 TO 23 30 FOR A=0 TO 39 40 WAIT 25 50 POKE 4226,A:POKE 4227,B:PRINT " NEPTUNES,":NEXT A,B
POKES to change the cursor sign:
Original: POKE $1391,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
POKES to change the tabstop:
10 INIT "CRT:M1" 20 INPUT "WHAT SHOULD THE NEW TABSTOP BE (1-39)";A 30 IF A<1 OR A>39 THEN 20 40 POKE $A2D,A:POKE $A32,A:POKE $A49,A:POKE $A5F,A:POKE $A63,A 50 PRINT:PRINT "NOW PRESS THE TAB KEY!"
A couple of useless POKES ANTI-BREAK POKES:
POKE $F4C,$6E,$60:POKE $6403,$C3,$0,$0
Original: POKE $F4C,$DA,$0:POKE $6403,$ED,$7B,$64
Other useless pokes for both BASICS:
And there are many more POKES that are as useless as these ones. That is the reason we do not publish them.
After having given a whole list of POKES, we have now arrived at the PEEKS. The PEEK instruction is to read the contents of a certain address.
So like POKE, the same applies to PEEK, all addresses are PEEK-able. There are only a few really useful PEEKS and the important ones can be found on this page.
PEEKS to see which DEVICE you use:
10 IF PEEK($106A)=$5A AND PEEK($106B)=$37 THEN PRINT "YOU ARE CURRENTLY WORKING WITH THE CASSETTE." 20 IF PEEK($106A)=$D0 AND PEEK($106B)=$2F THEN PRINT "YOU ARE CURRENTLY WORKING WITH THE QD."
PEEKS to see if the expansion ICs are present in your computer:
1 if the ICs are present.
PEEKS to read what is displayed on the screen:
From address $2000 on the contents of the screen is stored. If you for example would like to know if there is something on the first column of the second row, you enter: PRINT PEEK($2000+1*40+0) and if something is present, the corresponding ASCII code of the character will be shown.
PEEKS to see how many BYTES a program occupies on QD and how many BYTES
10 DIR:NO=$27D0:P=0:CLS:PRINT "DIR QD:":PRINT "_______" 30 N=NO+1:IF PEEK(NO)=0 THEN PRINT TAB(23);CHR$(17);65454-P;" Bytes free":END 40 IF PEEK(NO)=1 THEN PRINT "OBJ ";:ELSE PRINT "BTX "; 50 IF PEEK(N)<>13 THEN PRINT CHR$(PEEK(N));:N=N+1:GOTO 50 60 B=PEEK(N0+21)*256+PEEK(NO+20) :PRINT TAB(23);B;" Bytes":NO=NP+32:P=P+B:GOTO 30