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.
Modify capitalisation of MENUN itemsby default the MENUN command translates the menu items to title case. (capitalisation of the first letter)set the system variable mnb_cptz ($209C) to 1
https://www.jaapsch.net/psion/progtrks.htm#menuYou can change this with a POKEB $209C,1 (title case off) and POKEB $209C,0 (turn it back on)
I recommend you turn it 'off' and 'on' immediately before and after the MENUN command so as not to disrupt the system menu's
TEST:LOCAL M%AT 5,3 :PRINT "Place logging details here!"POKEB $209C,1AT 1,1 :M%=MENUN(1,"+,R,l,f,s,m,t,i,U,O,d,c")POKEB $209C,0REM place options here
How can I disable or change the auto-switch off?Normally the organiser switches off after not being used for 5 minutes.
POKEB $007C,0 :REM no auto turn offPOKEB $007C,255 :REM restore auto turn off
The standard switch-off time can be set by POKEW $20CD,T% where T% is the length of time in seconds (default is 5 mins=300 secs).
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!)