Jaap's Psion II Page

Psion II Machine Code Tutorial, Part 4

The missile routine.

The routine should look through string from right to left and move every missile to the right. If a missile is already in the right column or if it hits a non-alien object (i.e. a star), the missile is removed. If an alien is hit, the missile and alien are both removed, and points are added to your score.

The search has to be done right to left, so that we move the missiles in front first. Otherwise a missile at the back will hit a missile at the front.

The information passed is:

A%(1)=ADDR(A$) 'A$ is the screen string
A%(2)=20 'Length of a screen line on a Psion LZ.
'For a Psion CM or XP, use 16 instead.
A%(2)=A%(2)+256*10 'The score for a hit.
A%(3)=256*%-+%< 'Missile and alien shape.

Lets assign some addresses to store this data in:
 41=Score change for a hit
 43=missile shape
 44=alien shape
 45/46=Total score change so far.

EC02 LDD 2,X 'Store the information used in a more easily
DD41 STD 41 'accessible place, addresses 41 to 44.
EC04 LDD 4,X
DD43 STD 43
7F0045   CLR 45 'Clear score.
7F0046 CLR 46
EE00 LDX 0,X 'get the string address.
E600 LDAB 0,X    'Get string length.
2735 BEQ end 'Return if empty string. Shouldn't happen, but it is 'safer this way.
3A   ABX 'Go to end of string.
37 PSHB 'store B temporarily
A600 LDAA 0,X 'Get character on left.
9143 CMPA 43 'Skip if not missile.
2627 BNE skp
8620 LDAA %20 'erase it.
A700 STAA 0,X
17 TBA 'calculate which column it is in.
9042 SUBA 42
22FC BHI s
271B BEQ skp 'skip if at the right column of the screen.
A601 LDAA 1,X 'Get destination contents.
8120 CMPA %20 'Move missile if it is empty.
2711 BEQ move
9144 CMPA 44 'Skip if hit object that isn't an alien.
2611 BNE skp
8620 LDAA %20 'erase alien.
A701 STAA 1,X
D641 LDAB 41 'Add score.
D345 ADDD 45
DD45 STD 45
2004 BRA skp
9643 LDAA 43 'Move missile to right.
A701 STAA 1,X
33 PULB 'retrieve B
09 DEX 'move left.
5A DECB 'until done whole screen.
26CD BNE lp
DE45 LDX 45
39 RTS 'return total score change.

In Part 5, the conclusion of this series, I will putting all the parts of our game together.