Sharp logo

MZ-800 course Chapter 5 
5. Pokes, Peeks, tricks, tips and things like that

5.3 Calls in BASIC

In chapter 3 a couple of CALLS in machine language were discussed. An instruction like this also exists for BASIC and this instruction is named USR($xxxx). This instruction is similar to the GOTO xx" or RUN xx instructions, except that we do not jump to a line number, but to a memory address and everything from that memory address on will be executed. When a RET code is encountered, control will return to BASIC. It can be that the computer crashes. CTRL/reset might help, but sometimes BASIC must be reloaded.

For USR the same rules apply as for POKE and PEEK. We can jump to all addresses, but it is mostly useless. Finding useful USRs is not as easy as finding POKEs. Most USRs were discovered by accident, others by turning BASIC inside-out.

Useful USRs could also be used in a small machine code program. An example will be given later on, but we will first give a list of USRs of which some are really useful and others just funny.

USR($3B68) - Turn off the cassette motor.

USR($38C5) - Start the cassette motor.

A$="D000" :USR($16C6,A$) - HEX-DUMP from address D000. The address can be modified easily by changing A$. The advantage in this is that we return to BASIC.

A$="A000" :USR($1738,A$) - MA000. Of course we can change the address again by changing A$.

USR($0419) - CLS.

USR($0A1B) - Switch to small letter type.

USR($0A19) - Switch back to normal mode.

USR($0A1E) - Switch to graphic mode.

USR($0992) - Put the cursor in the upper left corner.

A$="NEPTUNES SOFTWARE." :USR($0015,A$) - Print the text at the position of the cursor.

10 USR($0003,A$):REM First you must enter a text, which is stored in A$ and printed.
20 CLS
30 USR($0015,A$)

USR($003E) - BEEP.

USR($0006) - Skip one line.

CALL to put a pixel with a certain color on the screen Unfortunately, this CALL can not be issued with the instruction USR alone. This CALL must be incorporated in a program to show how it works. First we will give the program and then we will give a short explanation.

10 INIT "CRT:M1"
20 POKE $FD00,$6,$0,$21,$0,$0,$11,$0,$0,$3E,$2,$32,$9F,$10,$CD,$94,$46,$2A,$6,
30 USR($FD00)

The CALL in question (CALL 4694H) puts a pixel at the coordinates in registers DE and HL in the color at the address 109FH.

DE will be the x-coordinate.

HL will be the y-coordinate.

At address 109FH the value of the palette or the color will reside (this only applies to mode M2).

If HL and DE are incremented each time, as happens here, you will see a diagonal line. Actually, this program should be in the chapter about Video-RAM. Because the CALL is the most important part of the program, this program is placed in this chapter.

CALL to read the keyboard and show the typed text on the screen:

First the program, then the explanation.

10 INIT "CRT:M1"
20 PAL 3,0 :PRINT "The character ";
30 POKE $FD00,$CD,$1B,$0,$FE,$C2,$12,$0,$C3,$0,$FD :USR($FD00)
40 PAL 3,15 :PRINT " was typed by you."

These two CALLs also had to be incorporated in a program to show the usage.

CALL 001BH - This CALL reads the keyboard and puts the result in register A.

CALL 0012H - This CALL puts the value of register A on the screen at the position of the cursor.

When a key is pressed, the program will jump to 0012H and puts the pressed key on the screen at the position of the cursor.

Of course there are a lot more CALLs in BASIC, but most of them are not as funny or interesting as the ones published here. The CALL for coloring a pixel for example can be used to speed up a program, as is done in the program PICTURESHOW.

Previous page
Next page

Go to the top of this page Home

last updated March 22, 2006
Arjan Habing, Mark de Rover, Jeroen F. J. Laros,