OPL Programming

For those new users and enthusiasts looking to have a go at programming the PSION Organiser II there are a few introductory worked examples contained in the links below.  For the republished Programming Manual and Information follow the links at the bottom of the page and the books above are good reading for those with time on there hands.

A simple introduction to programming example for any PSION device

This is an Introduction to Programming based around a mastermind type programme

Create a sub-menu routine that groups together your top level menu applications.

This is a routine that allows a user to  select an input item from a list or pre-prepared items

Integrating the Organiser LZ Diary with your OPL programming application.

This is a Parent and Child Introduction to Programming Project based around the YuGiOh! trading Card Game.

Tips and Tricks (Jaap Scherphuis)

Centring a line of textRather than counting the characters in a line of text, then subtracting the total from 20, dividing by 2 and adding 1 - why not let your Psion do the calculation for you?
AT 1+((20-LEN(A$))/2),y%
The above OPL positions the cursor so as to centre the text A$ on line y%.Make sure A$ does not exceed 20 characters though, as no error checking is performed!
Animating GraphicsI found out, completely by accident, that if a graphic is defined and printed to the Organiser display, to change it you don't have to re-print a new graphic character, just redefine it and it is automatically updated on screen!

The Keyboard Buffer.The organiser remembers the keys that you pressed in the keyboard buffer until that time when it is ready to process it. This is usually a good idea, but sometimes it can be a little problematic.
At the end of an action game for example, you want to be sure that all the key presses have been cleared before it asks if you want to play again. The easiest way to do this is
WHILE KEY :ENDWH
You may want to use a PAUSE instruction first though (with a positive parameter), so that when the game ends you have time to realise it and stop playing.
One final point about the PAUSE command. If you use a negative parameter, the pause will end as soon as a key is pressed. This key press remains in the buffer, so the next KEY (or GET) will still retrieve it.
Fixed Random NumbersThis procedure was developed in the days when I used a Spectrum to easily guarantee that no number was selected twice! I needed a random number generator which would produce numbers between an upper and lower limit and did not require any checking for duplicates etc.I called the procedure Fixed Random Numbers because, although the range of numbers was fixed the numbers chosen would be randomly picked from the fixed sequence.
FIXRND:LOCAL N$(10),O$(10),R$(1),S$(10),T$(10)LOCAL B%,N%N$="1234567890"          :Rem N$ is the fixed range of numbers.B%=Len(N$)DON%=INT(RND*LEN(N$))+1    :Rem N% is the randomly selected position in the                          Rem  string A$.R$=MID$(N$,N%,1)         :Rem These lines slice up N$ and remove theS$=LEFT$(N$,N%-1)        :Rem  selected number.T$=RIGHT$(N$,LEN(N$)-N%) :Rem T$=Left string A$. S$=Right string A$.N$=S$+T$                 :Rem N$ Now=Original N$ less the selected number.O$=O$+R$                 :Rem O$ ends up being equal to the original A$B%=B%-1                  :Rem  randomly shuffled up.UNTIL B%<1RETURN

The procedure Fixed random numbers can be found in Lotto XP-LZ.zip on Jaaps software page.
This procedure can be rewritten so that it only uses the string variable N$, as shown below. It uses the same method, except that the result is also stored in part of N$. It is much less clear as the program above.
FIXRND2:LOCAL N$(10),B%,N%N$="1234567890"          :Rem N$ is the fixed range of numbers.B%=Len(N$)DON%=INT(RND*B%))+1        :Rem N% is the randomly selected position in the                         :Rem  list of still unchosen numbers in N$.N$=LEFT$(N$,N%-1)+MID$(N$,N%+1,LEN(N$)-N%)+MID$(N$,N%,1)                          Rem The selected number is placed at the end.B%=B%-1UNTIL B%<1               :Rem Repeat until all have been chosen.RETURN
How can I detect the shift key?If you want to know if the shift key is being pressed on its own, the ordinary keyboard commands KEY and GET are useless. This is obviously because the shift key is treated differently to any other key.
You can use the following statement:
  IF PEEKB($7B) AND 128    REM Shift was pressed  ELSE    REM Shift was not pressed  ENDIF
A completely different method is by disabling the shift function. The command
   POKEB $20C4,0
disables it. After that, the shift key acts just like any other key, i.e. it makes a click when pressed, it auto-repeats, and generates the '?' character (code 63). To enable it again, use
   POKEB $20C4,255
Be careful with this method. As a precaution, put the enabling command on its own in a separate procedure so that you can run it if you have to. It is impossible to enable the shift otherwise if an error occurs (you can no longer type the comma of the POKEB command!)

User Manual CM/XP

Programming LZ

Developer

Comms Link

DatabaseTips.pdf

Database Files Hints and Tips

DeveloperTips.pdf

Creating  Programme Datapaks

Psion Organiser II users who would like to comment or are looking for further information can leave a message for Martin