Personal Computer News


Tennis

 
Published in Personal Computer News #106

Make sense of machine code with this bouncey game, courtesy of Keith Hook and M. Gaut. The program can be altered to illustrate how the MTX's assembler works.

Anyone For Tennis?

Make sense of machine code with this bouncy code with this bouncey game, courtesy of Keith Hook and M. Gaut. The program can be altered to illustrate how the MTX's assembler works.

The Memotech MTX's in-built assembler/debugger is ideal for programming in Basic with 'in-line' machine code subroutines. However, once Basic has been mastered, most users get the urge to write in assembler: the routines run faster and allow certain special effects which are impossible in Basic.

Unfortunately, very little has been written about getting the best from the MTX assembler, and many users abandon the idea of attempting machine code as a result.

This listing is a game of practice tennis which allows you to alter any section of the code and experiment to see how it affects the game. For example it is quite easy to create a two player version, or to alter the angle at which the ball bounces off the walls or the bat.

Even the novice programmer can experiment and gain some ideas for future use. The source listing is fully documented for those of you who have graphic functions. Basic screen routines use these ROM calls, and because of the way the Operating System is structured, it is easier to take advantage of the routines rather than write your own.

The RST 10 instruction expects certain information to follow the call, and depending upon this, the call will follow a certain course of action. These calls can draw lines, plot lines, create sprites, move sprites, print text and graphics to the screen, and much more.

The format for using RST 10 is:

RST 10
DB £83
DB "TRY"

The above examples will print TRY on the screen, at the current cursor position. The function decides which command is to be executed by the bit pattern of the first byte (£83) which is the command byte:

Bit 7 6 5 4 3 2 1 0 Patt 1 0 cs Number of bytes

Here, bit 7 is set [£80 = 1000 0000], and we are printing three characters, so RST 10 DB £83 tells the MTX to print 3 characters at the current cursor location. Bit 3 is the Carry:Stop bit. If this bit is set (1) the RST 10 call executes the immediate command and then carries on to look for another command byte:

RST 10
DB £A3,"TRY"
DB £86,"AGAIN"

The above code will result in RST 10 printing TRY AGAIN on the screen at the current cursor location before it returns to the calling program. (For a complete explanation of these calls see PCN issue 64).

The program uses 16 by 16 sprites and this mode is selected by setting bit 1 of VDP Register 1. In order that this register can also carry out its other functions, a value of £C2 must be sent to this register.

RST 10 followed by DB £4C will select Virtual Screen 4 and clear it on entry.

LD A,R is an easy way of getting a random number in the range 0 - 127. The Refresh register is constantly counting up to 127, so you get the same number twice in a row.

Finally, under MTX Basic, the sprite attribute table is located at 16128 decimal and each entry consists of four bytes:

Byte 1 Vertical distance from top of screen
Byte 2 Horizontal distance from left hand edge
Byte 3 Pointer to sprite number
Byte 4 Sprite colour

M. Gaut