==========
psion/opl #1453, from jezar, 688 chars, Sep 29 9:41 94
----------
Getting rid of clicks

If you write games for the Series 3a, (or anything else
which involves *holding* down keys during use) then you
may be interested in this routine, which disables
key-clicks in your OPL program ONLY (not in the other apps)

PROC SetClick:(on%)
        REM Set on% to zero to turn off
        REM keyclicks. Non zero turns
        REM them back on.
     
        LOCAL ax%,bx%,pad3%
        LOCAL pad4%,pad5%,pad6%
     
        ax%=$7e02
        IF on%=0
                bx%=1
        ENDIF
        OS($8d,ADDR(ax%))
ENDP
     
NOTE: This ONLY works on the 3a, as it is a new feature
introduced in version 4 of the window server.

Jezar.

==========
psion/opl #1711, from mrudin, 1396 chars, Dec 23 2:3 94
Comment to 1710.
----------
You want the EPOC O/S call FilStatusGet, which is similar to the PLIB 
routine p_finfo.

Here's a bit of code out of my "HyPy" program for finding out 
file/directory details:

REM Set of consecutive variables representing a 16-byte
REM FileStatusEnt or P_INFO structure:
local Ver%    REM Version - ignore.
local Status% REM Various flags - see below
local Size&   REM File size in bytes
local Modst&  REM Time modified, in system-time format, i.e.
              REM seconds since 00:00:00 on 1/1/70.
local Spare&  REM unused

REM A zero-terminated string:
local Zts$(100)

REM example:
Zts$="LOC::M:\APP"+CHR$(0)
    
REM Find details of item using FilStatusGet:
CALL($0887,ADDR(Zts$)+1,ADDR(Ver%),0,0,0)
REM N.B. return failure status is ignored here, so make sure
REM you pass it a valid pathname.

if (Status% AND $10) <> 0
  print "dir"
else
  print "file size",Size&
endif

An extract from epocdefs.h:
These flags fit into the "status" field:
#define P_FAWRITE 0x01     it's writeable
#define P_FAHIDDEN 0x02    it's hidden
#define P_FASYSTEM 0x04    it's a system file
#define P_FAVOLUME 0x08    it's a volume
#define P_FADIR 0x10       it's a directory
#define P_FAMOD 0x20       it's been modified

typedef struct
    {
    UWORD version;
    UWORD status;
    ULONG size;
    ULONG modst;
    UBYTE spare[4];
    } P_INFO;


Mike.


==========
psion/opl #1811, from mrudin, 331 chars, Feb 27 20:45 95
Comment to 1810.
----------
For disk space, see my message psion/opl #1714.
For free memory:

local ax%,bx%,cx%,dx%,si%,di%,frmem&
OS($80,addr(ax%)) REM SegFreeMemory, signed int,
                  REM in 16-byte paragraphs
frmem&=ax%
if frmem&<0  REM only likely on a new 3a!
  frmem&=frmem&+&10000
endif
frmem&=frmem&*16
print frmem%

Mike.


==========
psion/opl #1846, from cwest, 750 chars, Mar 30 16:17 95
----------
Bringing a Process to the Foreground
All,

I want to be able to bring another program that is running to the 
foreground. Looking around here and on CIS, I have found two calls that 
will do this, but produce slightly different results. They are:

        CALL($998d,0,pid%)
and

        CALL($198d,0,pid%)
        
The difference is that when the first call is used, the required program 
will ALWAYS come to the foreground. However, the second call will ONLY 
work if it is followed by a command like GET or KEY.

Could some kind soul who knows about these things please explain how 
subfunction numbers differ for this interrupt call and what other useful 
function numbers there might be ??

Rgds

Chris West


==========
psion/opl #1848, from dw2, 542 chars, Mar 30 22:52 95
Comment to 1846.
----------
The difference between

>         CALL($998d,0,pid%)
> and
>         CALL($198d,0,pid%)

is in the top bit ($80) of AH.  This bit has a special meaning for the 
O/S Service called WservOpcodes (ie interrupt $8d).  When set, the Window 
Server's command buffer is flushed immediately after the command is 
executed.  That is

    $998d = $198d + $8000
    
          = wClientPosition followed by wFlush
          
A Window Server op-code without the top bit set in AH does not flush the 
command buffer.

Regards, DavidW


==========
psion/opl #1866, from jezar, 894 chars, Apr 9 15:3 95
Comment to 1863.
----------

If you ask the window server (using CALL) for a list of processes, it 
gives them to you in front to back order (ISTR). So if you're not first 
in the list then you're not in the foreground.

However, a much cleaner and nicer way of doing this, is to have your 
program listen out for "Foreground" and "Background" messages using 
GETEVENT or (more useful) the asynchronous version thereof. That way you 
can track your state dynamically rather than by doing ad hoc CALLS.

Regards,
Jezar.

P.S. Asynchronous GETEVENT is:
    IOC(-2,14,mystat%,mylong&)
The low word of mylong& is set to $401 for "Now in foreground"
and set to $402 for "Now in background". Otherwise mylong& contains
pressed keys in the low word, and modifiers in the high word. Some
people prefer to use a two-element integer array instead so that 
these two items of information are already separated.


==========
psion/opl #1876, from jezar, 693 chars, Apr 10 13:5 95
Comment to 1871.
----------

> set the screen size to 0x0, to free memory. 
That's kind of a nice idea, but you need to think carefully about what 
exactly you are going to do if you are brought to the foreground and 
there isn't enough memory to explode into life. Tom does this sort of 
thing in his Hot-key program (a forerunner to Macro), but the program 
bombs out if you task it to the front and there isn't enough memory for 
it to re-open its screen.

> Checking once a second (beforedrawing) would be sufficient.
Wellll.... Urm.... wouldn't it be nicer just to go to sleep totally until 
you hear the foreground message? It's much simpler - It's the kind of 
thing the built in apps do.

Jezar.


==========
psion/opl #1878, from ronald, 1036 chars, Apr 10 17:9 95
Comment to 1876.
----------
> That's kind of a nice idea, but you need to think carefully about what 
> exactly you are going to do if you are brought to the foreground and 
> there isn't enough memory to explode into life.

How? gSETWIN doesn't return a success flag - although if it can fail, it
ought to!!!

> Wellll.... Urm.... wouldn't it be nicer just to go to sleep totally until 
> you hear the foreground message? It's much simpler - It's the kind of 
> thing the built in apps do.

After some experimentation, I have come up with the following code:

    IF TESTEVENT
      GETEVENT e%()
      IF e%(1)=$402
        REM Go to sleep now. Any window minimizing goes here.
        DO
          GETEVENT e%()
        UNTIL e%(1)=$401
        REM Waking up. Window restore goes here.
      ENDIF
    ENDIF

I don't have a list of event codes, so I don't know whether I have to check
for any kind of qualifiers or event type id's, or if I have to mask any
bits.

Well it seems to work. (Dangerous words, I know! :-)

- Ronald.


==========
psion/opl #1880, from jezar, 1346 chars, Apr 11 11:11 95
Comment to 1878.
----------
> How? gSETWIN doesn't return a success flag - although if it can fail, it
> ought to!!!

Ah, but OPL _is_not_based_around_error_returns_
EVERY command can RAISE an error if it fails and fly back to an earlier 
part of your program (unless specified otherwise). Only a few, select 
keywords can have the keyword TRAP placed in front of them to prevent the 
flyback. That's why ONERR is so vitally important to understand _and_use_.

It is the OPL equivilent of the fabulous p_enter()/p_leave() in SIBO C 
programming. (the keywords ONERR and TRAP providing kinds of p_enter)

> After some experimentation, I have come up with the following code:
The code is good, but it still suffers from the fact that there is 
more that one point to pick up events from. That can lead to all kinds of 
deathful situations as the program becomes more complex. For example, 
if the user tasks to the background, and then asks to quit the app from 
the system screen the system command is missed because of the looping for 
"Foreground".

In these situations, IOWAIT is normally best. 
I seem to remember posting an example of this kind of Fore/Back/Timing 
stuff in the filelist a long while ago. Timers.opl?? It's not perfect - 
and probably has many of the deficiencies I've mentioned, but you might 
find it worth a look.

Jezar


==========
psion/opl #1909, from ronald, 544 chars, Apr 20 12:46 95
Comment to 1907.
----------
> Cheers, prog manual says see user manual, user manual starts at char 32!

Compile, and keep the result handy for future reference. It only takes
about 250 bytes of SSD space:

PROC Show:
  LOCAL i%,f%
  WHILE f%<13
    f%=f%+1
    gCLS :gFONT f% :gAT 32,20 :gPRINT "Font "+NUM$(f%,2)
    i%=0
    WHILE i%<32
      gAT 32+(i% AND 7)*50,40+INT(i%/8)*25
      gFONT 3  :gPRINT RIGHT$("0"+NUM$(i%,2),2)
      gFONT f% :gPRINT " "+CHR$(i%)
      i%=i%+1
    ENDWH
    BUSY "Any key" :GET :BUSY OFF
  ENDWH
ENDP

- Ronald.


==========
psion/opl #1914, from picasso, 294 chars, Apr 30 23:15 95
----------
Help Help
I'm trying to create a help file using the helpkit1 package and I get an 
'overflow' message when comiling the help file.  The source for the help 
file is about 32K, is this a know limit?

Also, how do I create multi resource help files?

Can anyone help?

Cheers,
Ken.


==========
psion/opl #1915, from jezar, 776 chars, May 1 11:45 95
Comment to 1914.
----------

32k? 
That's a fair old amount of help there!

I'm sorry but I didn't test the Help Compiler with source files that big.
You're probably going to have to modify it to make it work properly, but 
that shouldn't really be a big job. It only took me a couple of evenings 
to write it anyway.

I don't know what you mean by multi-resource help files.
If you mean having help for different languages in the one
help file that's quite easy (though I don't think it's a good idea).
You just write out several help indexes in the same help file.

You can put whatever you want in a resource file, It's just a case of 
fixing up the main .rsc table. All the code for that is in the help 
compiler, and ISTR I designed that part to be re-usable.

Regards,
Jezar.

==========
psion/opl #1925, from picasso, 417 chars, May 3 19:59 95
Comment to 1915.
----------
Thanks for the reply,

>34K That's a fair old amount of help there!

It is isn't it :-)

By multi resource help files, I actually mean multi topic resource.  In 
your sample code, you include a line for initial page, and a line for 
topic resource.  It's the latter I don't understand.  Could someone 
please explain.

Could someone also explain what .rsc & .rss files are.

Much appreciated.

Ken.


==========
psion/opl #1916, from rick, 587 chars, May 1 14:21 95
Comment to 1904.
----------
Has anyone had a go at stripping out the event-handling bits from Jezars 
demo appman.opl code to leave the progress gauge dialog as a standalone?

I tried but I don't have an SDK and got bogged down with too many Exit 55 
errors. :-(

I'd like to have the progress gauge accessible in a vanilla OPL app like:

        InitPG:(100)            REM Init the gauge.
        WHILE my_work%:
                UpdateG:        REM Update the progress gauge.
        ENDWH

Is it possible to run like this or does the progress gauge dialog require 
the event-handling functions?


==========
psion/opl #1918, from jezar, 1794 chars, May 1 17:41 95
Comment to 1916.
----------

Rick, I'm afraid there is NOTHING in that code which can be safely 
stripped out (apart from, obviously, the example procedures at the end, 
prefixed with "ex").

I put it all in, not because it is useful (which it is), but because it 
is *essential* to the operation of the "state machine" that the operating 
system expects such programs to be. Without it, your dialogs won't even 
draw.

The code is an OPL version of the system code that OPL normally hides. 
Removing bits of it would be like chopping out arbitrary sections of the 
ROM

What you have to do to get the effect that you are looking for, is to 
create the OPL equivilent of an "active object". This is really easy. 
Just set a global or something to 1 or 0 to indicate if you want to do 
your processing, and if you set it to TRUE, then call IOSIGNAL.

In the hpRun%: procedure, look to see if your global is set, and if so, 
then fire your processing, progress bar update, and call IOSIGNAL again, 
and return 1 in hpRun%:. If your global is not set then obviously you do 
nothing.

When you wish to stop processing, just set your global to zero, and, 
depending on the structure of your program, you might need to call IOWAIT 
to eat up the previous IOSIGNAL that you did.

As I think I mentioned, you *must* be very careful about random 
modifications to the code - if you play around with the contents of 
anthing other than the supplied "hook points", you can quite easilly 
crash your entire machine, and perhaps even require a hard reset.

Have you thought about just buying Volume Four of the Psion SDK?
(I think it is available seperately). Together with the #defines
database that I put in the flist, you can do all kinds of other neat 
things to dialogs and menus.

Jezar.



==========
psion/opl #1928, from jezar, 1200 chars, May 4 13:18 95
----------
Changing the text of a DTEXT

Some people have been asking how to change the text of a DTEXT 
dynamically when running under my APPMAN.OPL

Well, you can use the following routine to do this. Note that, ideally, 
you might also like to do a gINFO "Press Tab to change this item" if 
someone presses anything other than Tab, or another key the dialog cannot 
handle while the cursor is on the relevant DTEXT item.

Here is the procedure:

PROC dTXTSET%:(itm%,text$) REM Set the text
        
        LOCAL ret%
        
        REM This LOCAL data is ALL used!
        REM SE_TEXTWIN struct:
        LOCAL flags%,stat%,text%,len%
        
        LOCAL txt$(255)
        
        REM Check that the dialog box exists
        IF PEEKW($36)=0
                RAISE -85
        ENDIF
        
        txt$=text$
        text%=ADDR(txt$)+1
        len%=LEN(txt$)
        flags%=8      REM (SE_TEXTWIN_TEXT)
        CALL($0dd6,0,0,0)  REM Enable ws leaves
        REM Tell the dialog box to set item
        ret%=ENTERSEND0(PEEKW($36),10,#itm%,flags%)
        CALL($0dd6,0,0,1)  REM Disable ws leaves
        IF ret%
                RAISE ret%
        ENDIF
ENDP



==========
psion/opl #1939, from sjmartin, 206 chars, May 8 20:32 95
----------
How do I print ?
Sorry for such a simple question, and probably a FAQ but I've lost
my manual and have no examples.
I assume its the 'LPRINT' command, but this tells me 'File not open'.
TIA

Steve

==========
psion/opl #1946, from pdarnell, 306 chars, May 9 22:11 95
Comment to 1939.
----------
You have to open the port first by either:

OPEN "par:a" for a parallel printer or
OPEN "tty:a" for a serial printer.

I think the syntax is right, but I am doing this from memory. I have 
a horrible feeling that there might be some brackets involved somewhere.
I sure you can try both.

Paul.


==========
psion/opl #1943, from rick, 1011 chars, May 9 10:4 95
----------
ONERR handling in OPL.
I was playing around with the ONERR error handling over the
weekend. I didn't realise that the ONERRs are nested so that
an ONERR OFF doesn't cancel an ONERR label in a higher routine.
I thought I'd discovered something new! Then I read the manual...
Oh well. :-)

There is one thing not in the manual though...

When an OPL error occurs, the OPO run-time translator must use
something like the module name and line location to position
the cursor at the error when the OPL source is being edited.

If the error is caught with ONERR handling, is there
any way to find out (from OPL) the module & line number that
the error occurred in?

For example -

    ONERR GenErr::
        ...

    GenErr::
        REM General error handler.
        ONERR OFF
        PRINT "Error caught :";ERR$(ERR)
        PRINT "Module :"; GetErrM$: REM Show module that caused error.
        PRINT "Line :"; GetErrL&: REM Show line number of module.
        GET


TIA,
Rick.

==========
psion/opl #1953, from jezar, 255 chars, May 10 10:46 95
Comment to 1943.
----------

No there isn't. It's a real PITA. If you have an obscure error, it can be 
a real nightmare tracking down exactly where it occurred.

Having said that, the benefits of proper structured error-handling still 
outweigh the disadvantages.

Jezar.


==========
psion/opl #1945, from mark_2, 266 chars, May 9 18:30 95
----------
Choices dialog box
In plenty of apps I've seen you can choose from a list in a dialog by 
using the right and left cursor keys or by pressing the tab button the 
bring up the list which you can then select from by moving up and down. 
Can you do this in OPL?


==========
psion/opl #1948, from pdarnell, 79 chars, May 9 22:11 95
Comment to 1945.
----------
Use dCHOICE in the dialogue setup followed by the list of choices.

Paul.

==========
psion/opl #1958, from maveya, 1024 chars, May 10 17:3 95
Comment to 1945.
----------
> Choices dialog box
> In plenty of apps I've seen you can choose from a list in a dialog by 
> using the right and left cursor keys or by pressing the tab button the 
> bring up the list which you can then select from by moving up and down. 
> Can you do this in OPL?
> 

You certainly can, with dCHOICE, like this:-

LOCAL ch%               REM Set up a variable to hold the selected choice
dINIT "Demo"            REM Initialize the Dialog
dCHOICE ch%,"Select one of the following","Selection 1,Selection 2,
        Selection 3"    REM and so on for however many choices you need
DIALOG

i.e. You just add the choices to be displayed separated by commas.
ch% will then hold the value of the selected "Choice" i.e. if you select 
item 3, ch% will equal 3. You can also specify a value for ch% prior to 
the Dialog in order to default to that value i.e. in the above example, 
if ch% was set to 2 before calling the Dialog, "Selection 2" would be 
displayed first.

Hope this is useful,

Mark A.



==========
psion/opl #1954, from mark_2, 364 chars, May 10 13:11 95
Comment to 1948.
----------
Thanks for that. I did find that in the manual and whilst it works OK 
what I was hoping to do was display a text$ made of of values taken from 
elsewhere in my program. Also, a problem here is that dCHOICE lets you 
left and right cursor to select other entries. But what it doesn't do is 
let you  press the tab key to open up a vertical list. ANy ideas?


==========
psion/opl #1957, from slitchfield, 253 chars, May 10 16:22 95
Comment to 1954.
----------
But surely you can do dchoice i%,"Prompt:",mystring$

where mystring="Yes,No,Whatever" and all you've got to do is build the 
string yourself ??

And yes, Tab on dchoice certainly *does* bring up a pick list, I use 
this all the time!

Steve


==========
psion/opl #1949, from twagstaff, 1180 chars, May 10 2:24 95
Comment to 1942.
----------
>How can I find out which program has a file open, from within OPL.


>----------------
local i%, pid%(50), task$(50,15), path$(128)
local d%

 call( $d98d, 0, 0, 0, addr( pid%(1) ) ) rem wGetProcessList
 i% = 1
 while pid%( i% )
 rem what file does it have, if any
rem s3a  call($00dc, pid%(i%), 128, 0, $3e, uadd(addr(path$),1))
  call($00dc, pid%(i%), 128, 0, $3e, addr(path$)+1)

rem convert zts 
  d%=1
rem s3a while peekb(uadd(addr(path$),d%)) <> 0
  while peekb((addr(path$)+d%)) <> 0
   d%=d%+1
  endwh
  pokeb addr(path$), d%-1

rem s3a  call($0a88, pid%(i%), 0, 0, 0, uadd(addr(task$(i%)),1)) rem ProcNameB-
yId

  call($0a88, pid%(i%), 0, 0, 0, addr(task$(i%))+1) rem ProcNameById

rem convert zts 
  d%=1
rem s3a while peekb(uadd(addr(task$(i%)),d%)) <> 0
  while peekb(addr(task$(i%))+d%) <> 0
   d%=d%+1
  endwh
  pokeb addr(task$(i%)), d%-1
  
  if path$ <> "" rem if it has a file loaded
   print task$(i%),path$
  else
   print task$(i%)+" has no file open"
  endif
  i% = i% + 1
>----------------

There is an OS  call to convert zts, a lot more elegant than what 
I've used, but I can't remember what it is.

Tony



==========
psion/opl #1967, from rovoreed, 535 chars, May 11 9:42 95
Comment to 1952.
----------

Yes. OK. But I'm probably being exceptionally thick here, but I
never could understand how one converts a call in the SDK like

p_pcpyfr(HANDLE pid, VOID *pSource, VOID *pTarget, UINT nBytes)

to

call($91, pid%, len%, something_usually_0%, some_hex_number%,
          addr(source%))

Others people seem to have no problem. Is there something obvious I'm
missing ? If I could find the bit that explained how p_pcpyfr is $91,
and p_pcpyto is $92 etc no doubt I'd understand how to plug all the
other parameters.

Mike

==========
psion/opl #1968, from jezar, 561 chars, May 11 11:27 95
Comment to 1967.
----------

Ah, OK. It's the bit at the back of EPOC O/S SYSTEM SERVICES which has 
all of the interrupts listed by number (It unfortunately doesn't have the 
Window Server OP codes, but those are in a file in the flist anyway).

The way you use the interrupt depends on whether you're using CALL or OS. 
Basically CALL is only suitable for things that can never fail (like 
STRLEN). The easiest way to get the hang of it is to get hold of a 
program with a bunch of CALLs in, and map them back to the original using 
the SDK.

Hope that helps Mike,
Jezar.


==========
psion/opl #2020, from slitchfield, 776 chars, Jun 14 16:10 95
----------
OPL Reverse translation protection
I hope this doesn't sound like an advert, cos it isn't. Just a personal 
recommendation to authors who write their software in a DOS environment 
wanting to quickly and automatically 'protect' their programs against 
reverse translation. The OPLPROT program (I know, I know, there was a 
great debate about it a while ago and PLEASE don't let's start that 
again!) actually works very well and totally seamlessly. I just put it in 
my BUILD.BAT or whatever and hey presto, instant protection.

*No comments to this message please*, but if you want to get hold of the 
program by e-mail contact PUERICULTURA@genova.infn.it, who is now on-line 
properly (his e-mail went funny for a while a few months back).

Steve Litchfield

==========
psion/opl #2023, from mrudin, 372 chars, Jun 15 23:41 95
Comment to 2020.
----------
Just a reminder that no protection mechanism is foolproof.
Revtran in its present (and probably future) state is pretty easy to 
confuse, but anyone determined enough can get round OPL 
anti-reverse-translation measures.
If secrecy of your source code is what you want, programming in C is a 
better bet.

> *No comments to this message please*
Sorry.

Mike.

==========
psion/opl #2043, from slitchfield, 1165 chars, Jun 28 6:50 95
Comment to 2020.
----------
Several people have said that Marco is not answering his e-mail. Well, it 
works for me. Have a look at the message below!! 8-) So if you've been 
trying, then try again!!!

----------------------------------------------------------------------
From PUERICULTURA@genova.infn.it  Tue Jun 27 18:47:15 1995
Received: from vaxgea.ge.infn.it (vaxgea.ge.infn.it [192.84.136.3]) by 
tom.compulink.co.uk (8.6.9/8.6.9) with SMTP id SAA16907 for 
<slitchfield@cix.compulink.co.uk>; Tue, 27 Jun 1995 18:47:15 +0100
Date: Tue, 27 Jun 1995 19:47:02 +0300 (MET-DST)
To: slitchfield@cix.compulink.co.uk
Message-Id: <950627194702.490008e3@genova.infn.it>
Subject: RE: Test e-mail
From: PUERICULTURA@genova.infn.it
Apparently-To: slitchfield@cix.compulink.co.uk

Here I am, Steve!!!!

My e-mail address is the same (puericultura@ge.infn.it), and I don't know
what's going on with my e-mail.... It seems it goes lost!!!

I'm very sorry about this, trust me!!!

If users try to contact me to register (this would be great), I think I 
will
have to change to another Internet Service Provider... What do you 
think???

Thanks for contacting me!

Marco


==========
psion/opl #2021, from jbinnie, 831 chars, Jun 15 10:37 95
----------
FilManager
I'm trying to use some of the OS calls to check whether a directory 
exists or not. Problem is I keep getting an "Invalid name" error when I 
use this code. What is the standard format for passing strings to the OS? 
When should you use null-terminated ones and when shouldn't you?

As ususal, a bit confused....

Here's the code I'm using.

PROC test:
        local ax%,bx%,cx%,dx%,si%,di%
        local res%,a$(255)
        
        ax%=$0500       rem al=0 indicating sync call
                        rem ah=5 indicating FilPathTest
                        
        setpath "m:\"
        a$="\dat\"
        bx%=addr(a$)
        res%=os($87,addr(ax%))
        print (res% and 1)      rem Carry bit 0=succesful
        print err$(ax%)         rem else al carries error code
        get
ENDP


==========
psion/opl #2022, from jbinnie, 367 chars, Jun 15 10:54 95
Comment to 2021.
----------
Good grief I've sorted it!

This works....

...as above except:

a$="\dat\"+chr$(0)      rem null terminated string
bx%=uadd(addr(a$),1)    rem skip length byte used by OPL

This works, and gives a neat "Does a directoty exist?" piece of code 
(with a few changes here and there).

Hope this was of some use to someone as well as me!

Regards

Jon


==========
psion/opl #2029, from sballan, 1173 chars, Jun 22 12:41 95
----------
Flexibility/limitations in OPENing files in OPL
I have a requirement to open a normal .dbf file, using OPL and to process 
the contents of it.  I do not know at run time how many fields are 
defined within the .dbf file.

I have found that if I always use the OPEN statement with the maximum 
number of 32 (text) fields defined, then there are no problems reading 
the contents of the file, even if it was only defined with, say, 6 
fields.  The remaining 26 fields can be referenced but appear to the OPL 
code as zero length strings.

Is it safe to assume that the above is the case, rather than me having to 
ask the user for the number of fields at run time.  ie is OPEN designed 
to  work as above.

The .dbf file started life as an Excel spreadsheet, was converted to a 
.csv file using SAVE AS, within Excel, and then converted to a .dbf file 
using TEXT2DBF.  In all cases, the .dbf file is likely to have been 
supplied as an Ascii file, either .csv, .txt, etc and processed with 
TEXT2DBF to create it.  It could have originated from any database 
package, eg Access, FoxPro, Dbase, etc.


Thanks for any help here.

Regards

Stuart


==========
psion/opl #2032, from perseus, 718 chars, Jun 24 12:19 95
Comment to 2031.
----------
I think you'll find that all fields beyond those defined with the CREATE 
command are treated as text fields.  Your proble will be figuring out 
which fields are of which type, since OPL will give an error if the OPEN 
variable types are different to the CREATE variable types.

You can check the variable types by looking at the dbf header, but it 
would be very difficult to ensure the right OPEN command was used.  ie if 
you wanted to open a file where the third field is an integer, then your 
OPEN command/statement must have an integer in its third field slot.

You can use some hacks into the OS to open the file and access records as 
one block of data, but this would be a messy piece of code.


==========
psion/opl #2033, from joegriffin, 620 chars, Jun 24 22:37 95
Comment to 2032.
----------
> I think you'll find that all fields beyond those defined with the 
CREATE 
> command are treated as text fields.  Your proble will be figuring out 
> which fields are of which type, since OPL will give an error if the 
OPEN 
> variable types are different to the CREATE variable types.

The program I sent Stuart reads the .DBF header and thus reports what 
the fields are.

My understanding is that using DATA to create a .DBF file creates one 
with all 32 fields (and they're all TEXT fields). If OPL is used, it 
just creates the specific fields you request (and they can be of any 
type).

... Joe


==========
psion/opl #2068, from stevegodfrey, 621 chars, Jul 23 13:40 95
Comment to 2067.
----------
 
> Thus I need to check if SOUND is off - how might I do that
 
Use call($0f8b) in OPL to test for sound status. ie:
 
  st%=call($0f8b)
 
will return the sound flags in st% with the following meaning:
 
Bit 0: keyboard clicks enabled if set
Bit 1: beeps enabled if set
Bit 2: alarm sounds enabled if set
Bit 3: set=loud keyboard clicks, clear=quiet keyboard clicks
Bit 4: set=loud beeps, clear=soft beeps
 
Bit 15: all sounds disabled if set
 
st% will be negative if all sounds are disabled
 
You should make sure st% is positive and bit 2 is set before playing
DTMF tones.
 
Cheers
 
Steve

==========
psion/opl #2069, from stevegodfrey, 631 chars, Jul 23 14:44 95
Comment to 2067.
----------
Re: playing DTMF from OPL
 
A better idea would be to re-enable the sound system before
you dial the number, and restore the sound system afterwards.
 
You can do this as follows (requires GLOBAL st%):
 
PROC sound:(e%)
 local ax%,bx%,cx%,dx%,si%,di%
 
 if e%
   st%=call($0f8b)         rem read sound flags into st%
   bx%=(st% and 31) or 4
 else
   bx%=st%
 endif
 
 ax%=$1000
 os($8b,addr(ax%))         rem set sound flags using bx%
ENDP
 
Using sound:(1) will store the current sound setting in
st% and enable the sound, and sound:(0) will restore the
sound setting to that in st%.
 
Cheers
 
Steve

==========
psion/opl #2070, from stevegodfrey, 220 chars, Jul 23 15:22 95
Comment to 2069.
----------
Re: Sound switched off
 
The following works just as well :-)
 
PROC sound:(e%)
  local bx%
  if e%
    st%=call($0f8b)
    bx%=(st% and 31) or 4
  else
    bx%=st%
  endif
  call($108b,bx%)
ENDP
 
Steve

==========
psion/opl #2089, from bpechey, 658 chars, Aug 14 9:51 95
----------
SPEED.ZIP

I just uploaded a file (SPEED.ZIP) to the files topic which gives some 
advice on writing OPL programs so that they run faster. It is written by 
a guy from Australia. 

The information looks quite useful and I wondered if the assembled 
experts here had any comment on it or any other ideas that could be added 
to the ones in the document.

I have been writing some programs recently that do a lot of numerical 
calculations but there are hardly any suggestions in SPEED.ZIP about 
that. It takes quite a while to work out, for example, whether x*x is 
faster than x**2. Any guidance on similar issues would be welcome.

Bill.

==========
psion/opl #2092, from jezar, 1286 chars, Aug 14 17:9 95
Comment to 2089.
----------

x*x is considerably faster than x**2

I've done a fair bit of research into these issues in OPL, and have found 
that there cam be substantial gains in looped code from rearranging an 
inner expression so that OPL handles it in the most efficient way. For 
example:

        a=b*c%*d%*e%*f%*g%*h%

Is better written as:

        a=b*(c%*d%*e%*f%*g%*h%)

(provided that it doesn't overflow). If it is likely to overflow, you 
could still try:

        a=b*(INT(c%)*d%*e%*f%*g%*h%)

It's simply a matter of making sure that calculations are promoted only 
where required, and not too soon. For example, in the first line that I 
showed above, because b is a floating point variable, every variable in 
the line is converted to floating point as the calculation progresses. 
This not only slows things down, but also means that each multiplication 
operation is being performed in floating-point - very expensive.

In the second example, the bulk of the operation is kept at integer level 
- it is only at the very last multiplication that it is promoted to 
floating-point, and thus only one floating-point multiply is invoked. 
Additionally, you will find that the second example generates slightly 
less translated code (not much).

Regards,
Jezar.


==========
psion/opl #2091, from jezar, 787 chars, Aug 14 17:9 95
Comment to 2088.
----------

The current version of the OPL runtime in the ROM doesn't have the 
ability to support debugging. Lack of space/time etc. Shame really.

The way I do debugging (purely on the machine itself) is to have fairly 
characteristic debugging statements which I can then search and replace 
with REM'ed out versions of the same thing. To switch debugging back on I 
search and replace them back.

However, ODE handles this kind of stuff much better, because you can just 
#ifdef out your debugging code.

One of the best kind of debugging statements you can have in OPL is 
LPRINT. 
You can redirect LPRINT to the serial port (so you can monitor 
the output live on a terminal), redirect it to a log file, 

or with a little POKE, redirect it to the screen.

 i.e. using POKEW PEEKW($1c)+$1a,PEEKW(PEEKW($1c)+$1c)
This just copies the console handle (-2) over to the LPRINT handle (-1)

Regards,
Jezar.


==========
psion/opl #2106, from twagstaff, 300 chars, Aug 16 14:24 95
Comment to 2091.
----------
>However, ODE handles this kind of stuff much better, because you 
can just 
>#ifdef out your debugging code.

You can now do this on the Psion itself. Have a look at opp10f.zip in 
the flist. This is pretty indispensable if you're programming on the 
Psion, and only 10UKP shareware.

Tony

==========
psion/opl #2113, from rick, 662 chars, Aug 17 17:7 95
Comment to 2112.
----------
This preprocessor is incredible!!!

I'm working on an app that has 150K of OPL split over four OPL files. 
Previously, I've have to build a main .OPA file, and translate 
library .OPO files, then LOADM them.

I tried using ODE and S3ATRAN from the DOS prompt to build one huge 
.OPA file from a single 150K OPL file, but both blew with "No system 
memory left" errors. :-(

I thought I'd try OPP, and added a couple of #INCLUDEs to the main 
OPL file to drag in the library files, and guess what? It worked! I 
now have a _single_ 64K .OPA file!!! Brilliant. :-) And I used my 
S3a, not the PC. I can't believe it.

I'm registering it tonight!


==========
psion/opl #2125, from jezar, 755 chars, Aug 22 18:38 95
Comment to 2122.
----------
> 3) Does anyone know how to jump to other help topics from within a help 
> topic? (I.E. not from a help menu, but actually from within a help 
> topic (Like hypertext in Windows help files)

You can do this with the Psion Help compiler - In your help text for a 
particular subject you can have a list of related topics in bold. When 
they are selected, the relevant page pops up. I'm not sure if there is a 
limit to how nested the dialogs can go - I suspect the system simply 
relies on the person designing the help to make this a consideration - 
but I may be wrong.

This is a feature of Help that isn't used by the built in applications - 
but I have seen it in third-party apps before. It can work rather well.

Regards,
Jezar.


==========
psion/opl #2127, from picasso, 300 chars, Aug 22 22:25 95
Comment to 2125.
----------
How do I nest the help topics though?
I have the helpkit.zip that is in the flist.
I understand the #Begin & #End but I can't work out how to add nested 
topics.  Is there a special code Eg. #Sub.
I don't suppose you could show me an example text file using nested 
topics.

Regards,
Ken.


==========
psion/opl #2132, from jezar, 309 chars, Aug 23 19:46 95
Comment to 2127.
----------

You can't do it with *my* help compiler, but you can do it with the SIBO 
help compiler which comes as part of the SDK and runs on a PC. The Psion 
Help compiler is probably in the flist. If not I'll put it up.

Alternatively, you could try modifying my Help Compiler to do it.

Regards,
Jezar.



==========
psion/opl #2133, from picasso, 285 chars, Aug 23 23:40 95
Comment to 2132.
----------
Ahhh, that's why I couldn't nest them.
I'll have a look in the flist but would appreciate an upload if isn't 
there.

As for tweaking your help compiler, I'll have a look, but I doubt I could 
manage that sort of thing.

Anybody else fancy it?

Thanks for your help.
Ken.


==========
psion/opl #2134, from millar, 124 chars, Aug 24 18:7 95
Comment to 2132.
----------
Jezar - for the second time the Psion (i.e. with SDK) help compiler isn't 
in the flist, could it be "made so"?

Matt


==========
psion/opl #2139, from jezar, 321 chars, Aug 26 18:4 95
Comment to 2135.
----------
Helpkit2.zip - uploaded to psion/files

This archive contains The Psion Resource Compiler and all that is 
required to compile (using a PC), help files for use in OPL applications. 
These Help files can use cross-referencing etc., which is is currently 
beyond the scope of my little OPL help compiler.

Jezar.


==========
psion/opl #2158, from stevegodfrey, 2024 chars, Aug 30 15:7 95
----------
Faster redrawing in OPL
Here is a technique for getting:

a) Faster redrawing in OPL
b) Redrawing the screen while showing something else
c) Smooth animation

all using just the standard OPL window and OPL graphics
commands. This is very useful for having instantly
appearing or changing screens.

To do this, use the following section of code:

call($108d,wid%)
<your redraw code here>
call($04d6)
call($008d)
call($158d,wid%)
testevent

where wid% is obtained using ginfo. Your redraw code can
be as long/complicated as you like - the user sees nothing
happening - they just see the previously drawn screen.
You can even use gcls to redraw completely.

It works as follows:

call($108d,wid%) is wBeginRedrawWin.

Any following OPL graphics commands will be directed to
the backup bitmap of the window.

call($04d6) flushes the graphics buffer.

call($008d) is wEndRedraw. Returns drawing to normal.

call($158d,wid%) calls wInvalidateWin. This makes the
window server copy the backup bitmap (to which you have
just drawn) to the main window. The copying of the backup
bitmap wont occur until you use testevent (or get, getevent).

A simple demo follows. It draws a pattern while displaying
the please wait. It is far quicker than drawing directly.

I'll upload a file to cix shortly giving full details
of this and other techniques for fast graphics.

PROC demo:
 global wid%
 
 defaultwin 1
 
 wid%=getid:
 
 gat 0,80
 gfont 12
 gprintb "Please wait ... drawing screen",480,3
 
 call($108d,wid%)
 drawpat: 
 call($04d6)
 call($008d)
 call($158d,wid%)
 get
ENDP
 
PROC drawpat:
 local x%,y%
 ggrey 2
 gcls
 ggrey 0
 x%=0
 y%=0
 do
   gat x%,0
   glineto 480,y%
   glineto 480-x%,160
   glineto 0,160-y%
   glineto x%,0
   y%=y%+8
   x%=x%+24
 until x%=480
ENDP

ENDP

PROC getid:
 rem return window handle
 local gi%(31)
 
 ginfo gi%()
  
 return gi%(31)
ENDP

Hope this is useful to someone :-)

Steve Godfrey
Psion PLC


==========
psion/opl #2162, from millar, 1133 chars, Aug 30 20:27 95
----------
German 3a's
Hi,

I have recently experienced a problem with some users of my Backgammon 
prog, but it's exclusively on German S3a's.  It tests fine on my 512k 
s3a, and also fine on the "vanilla" 1Mb s3a belonging to my 
other^H^H^H^H^H better half.  I can't for the life of me reproduce the 
problem, so I was wondering:

1)  I have reason to believe that a german flavour of the S3a emulator 
does in fact exist.
2)  Is there an email address for Psion Germany?  (I'd rather try that 
first than phone Germany!)
3)  Does anyone have any idea what the problem might be?  (It's something 
to do with dir$, parse$ etc.)
4)  Is there a helpful chappie out there with a German 3a, in the UK that 
can help me reproduce the problem (ideally over the phone) and fix the 
damn thing?
5)  Can anyone think of a better way of building a list of files with a 
certain extension over multiple disks, in a certain directory (if that 
exists) than using dir$, to check for disk existence (TRAP'ing the error 
(ONERR actually) if the disk doesn't exist), directory existence, then 
file existence if appropriate?

Matt

==========
psion/opl #2168, from cporteous, 402 chars, Aug 31 23:59 95
Comment to 2162.
----------
In answer to point 3>

I recently had a problem with one of my software titles that only 
affected german machines. I eventually tracked it down to the decimal 
seperator having been set to a comma rather than a dot. This affects any 
code that tries to evaluate a floating point number using the Val 
function, causing
an invalid argument error.
Hope this helps

Regards,
        Colin 



==========
psion/opl #2166, from millar, 141 chars, Aug 31 18:12 95
Comment to 2158.
----------
Could I copy the current front screen to the backup bitmap?  Or would I 
need to copy this to a spare bitmap then copy it again?

Matt


==========
psion/opl #2167, from stevegodfrey, 537 chars, Aug 31 19:25 95
Comment to 2166.
----------
Remember that once you have drawn your screen, the backup
bitmap will always be the same as the front screen anyway,
so there should be no need to copy from the front window
to the backup bitmap.
 
For faster graphics, you can just redraw the parts of the
backup bitmap that have changed, and then copy those parts
to the main window. This is detailed in a text file I have
uploaded.
 
You can copy from a window or bitmap to the backup bitmap
of another window using gcopy inside the call statements.
 
Cheers
 
Steve


==========
psion/opl #2174, from ple, 282 chars, Sep 2 12:34 95
----------
Getting the default disk drive
Could some kind soul tell me how to find out what a users default disk is 
set to from within OPL?

I assume it will involve an OS call but I'm dammed if I can find it 
anywhere in the manual or in any of the Flisted files on CIX.

TIA, PLE


==========
psion/opl #2175, from hzk, 245 chars, Sep 2 14:51 95
Comment to 2174.
----------
To find the default path, try the following.
It will return the path in the form:  LOC::A:\

PROC getpath$:
        LOCAL pp$(129)
        CALL($0387,UADD(ADDR(pp$),1),0,0,0)
        POKEB ADDR(pp$),8
        RETURN pp$
ENDP

Roger


==========
psion/opl #2183, from jezar, 651 chars, Sep 4 13:17 95
Comment to 2174.
----------

> Could some kind soul tell me how to find out what a users default disk 
> is set to from within OPL?

Well, although this is possible, (see reply from hzk), note that none of 
the built in applications work like this. You don't need to find out the 
default drive if you want to follow their behaviour. All you do is stick 
to using the drive which you last used and all will be fine - it's more 
friendly to use the most recently accessed drive/dir than fly back to a 
"pre-set" place all the time. If you do this, then your program will be 
launched with the name of a file on the default drive to start off with 
anyway.

Jezar.


==========
psion/opl #2185, from ple, 40 chars, Sep 4 20:20 95
Comment to 2175.
----------
Worked like a dream - thanks.

PLE


==========
psion/opl #2196, from jezar, 696 chars, Sep 5 12:6 95
----------
Helpkit information

I've noticed that in some peoples applications they are calling my 
example Help Show routine every time the user presses the Help key. The 
example was meant to show the *entire* calling sequence required by an 
application, rather than just being "Slotted in" to an app as-is.

What you really should do, is to set the Help filename ONCE at the 
beginning of your application, and just do the one SEND that displays the 
help when they press the Help button.

Every time you set the help filename you are using up more and more 
memory by needlessly creating more and more resource file handling 
objects.
(It's not serious - only 8 bytes or so)

Jezar.


==========
psion/opl #2209, from jezar, 428 chars, Sep 7 11:56 95
Comment to 2200.
----------

Problem solved!

(I could have shot myself when I was told.... :-)

We've all been forgetting that OPL parses ALL filenames with ".ODB" so 
when looking for the directory "\APP" it's been checking the existence of 
a file called "\APP.ODB" and NOT for the \APP directory.

The solution is to include a full stop in the filename, as in:

        IF EXIST("\APP.")
                ..............
Regards,
Jezar.


==========
psion/opl #2221, from rick, 566 chars, Sep 8 15:32 95
Comment to 2215.
----------
> I get message "failed to load file - no system memory left" for opl 
> source files over about 70kb.

I used to get this message, so I split the app into a main .OPA with 
a LOADM .OPO 'library' file. Messy. :-(

Now I use Andy Clarksons OPP, an OPL preprocessor that runs on the 
S3a, and in the main .OPL file I just #include the other .OPL files 
and the result is a single 60-odd Kb OPA. Magic. 

The preprocessor allows macro definitions, conditional translation, 
multi-dimensional arrays and C style operators (a%++) and more, for 
only 10.


==========
psion/opl #2248, from millar, 1237 chars, Sep 17 15:47 95
Comment to 2244.
----------
Actually that's not right!  You can do it from "within" the OPD file, 
here's how:

After opening the file with CREATE or OPEN do this:

proc WrtLabel:(info%, label$)

/* odbinfo address, and a comma separated list of labels */
/* info% is info%(1) returned from a call to odbinfo */


        local len%, n%, addr%, NewLbl%, abslen%, m%, tmp$(255)
        local ax%, bx%, cx%, dx%, si%, di%
        
        addr%=alloc(257)
        if addr%=0
                raise 10
        endif
        
        NewLbl%=1
        
        while n%<=LEN(label$)
                if MID$(label$, n%+1, 1)="," or n%=LEN(label$)
                        poke$ uadd(addr%,4+len%),tmp$
                        len%=len%+1+len(tmp$)
                        tmp$=""
                else
                        tmp$=tmp$+mid$(label$, n%+1, 1)
                endif
                n%=n%+1
        endwh
        pokeb uadd(addr%,2),len%
        pokeb uadd(addr%,3),$40
        call($a1,0,len%+4,0,addr%,peekw(uadd(info%,8)))
        ax%=$1800
        bx%=peekw(info%)
        cx%=len%+2
        if os($D8, addr(ax%)) and 1
                alert(err$(ax% or $ff00))
                stop
        endif
endp


Matt


==========
psion/opl #2273, from cornelivs, 798 chars, Sep 22 8:28 95
----------
TITLE: 3Link Calls in OPL
--------------------------------
I have been trying to write some software to call the Psion 
Wordprocessor from OPL, and later to allow my PC to take the data 
down the 3Link. 

However, I have run into difficulties, as I do not know any CALLs 
to perform some of the tasks I wish, in particular:

1) How do I check if a process is still running? I have used the 
calls in Startapp.opl to start the process, but I need to know 
when the process ends, so that I can analyse the document. 
(Currently using a terrible kludge to get round this).

2) How do I check if the Link is active?

3) How do I start/stop the 3Link from OPL?

I am using Rcom for data transfer, and am writing this in OPL.

TIA

Cornelius.
------END OF MESSAGE------------

==========
psion/opl #2276, from hzk, 2029 chars, Sep 23 16:37 95
Comment to 2273.
----------
You can start an application easily -
1.      ROM application:

        pgname$="rom::WORD.APP"+CHR$(0)
        cmdl$="OWord"+CHR$(0)+".TXT $"+CHR$(0)+edfile$+CHR$(0)
        r%=CALL($0187,UADD(ADDR(pgname$),1),addr(cmdl$),0,0,addr(pid%))
        CALL($0688,pid%)

The above will open Word as a text editor, loading edfile$ (includes full 
path).

2.      Translated OPL program:

        pgname$="rom::SYS$PRGO"+CHR$(0)
        cmdl$="ORunOpl"+CHR$(0)+CHR$(0)+oponame$+CHR$(0)
        r%=CALL($0187,UADD(ADDR(pgname$),1),addr(cmdl$),0,0,addr(pid%))
        CALL($0688,pid%)
        
Here an OPO file named oponame$ (incl full path) will be launched.

You can check whether the lauched process is still running:

        status%=CALL($8c8d,pid%)
        IF status%<0      :REM editor closed
        
This assumes that the launching process is still active, i.e. pid% has 
not changed!

You can close down an APP or OPA by sending a message to it as follows:

        x$="X"
        r%=CALL($da8d,pid%,UADD(ADDR(x$),1),1)   REM send shutdown msg.
        
If closing an OPA, make sure the OPA handles close down messages 
properly, as shown on page 113 in the 3a programming manual.  i.e. the 
OPA should be waiting for an event (e.g. GETEVENT) and should interpret a 
system message "X" as a closedown request.

All this was extracted from the OPL for PocPac, my packet radio program.  
Hopefully I haven't missed anything out!  By the way, it's worth checking 
that the launched process is still active before trying to close it down. 
It's also worth checking that the process has actually been started 
before trying to close it, etc.

When launching things from OPL you run the risk of leaving them running 
after closing down the main program.  A sub process can launch another, 
and you can get into a right pickle!  So if your main program receives a 
closedown message, it should check if it has launched anything still 
active, and close it down if necessary!

Roger




==========
psion/opl #2306, from perseus, 401 chars, Sep 28 21:59 95
Comment to 2290.
----------
To start up the link, p_execc "ROM::LINK.IMG".  The examples above given 
by Roger use the OPL equivalent of p_execc,( CALL $0187,...)

The command line should be "-p<Port> -b<Speed>",
     <Port> is a value from 1 to 8 specifying the serial port to use (1 = 
TTY:A, which is what you would use on the Series3 range)
     <Speed> is a value from 300 to 19200 indicating the baud rate to use.


==========
psion/opl #2329, from psion_c, 208 chars, Oct 2 14:0 95
Comment to 2320.
----------
> stumped when I hit the 255 character limit in dCHOICE.

Try LONGLIST.OPL in psion/files which contains code which will allow you 
to circumvent this limit (a limit no longer !)

All the best

Ali


==========
psion/opl #2348, from hzk, 1911 chars, Oct 7 0:33 95
Comment to 2346.
----------
I have never seen the SIBO OPL SDK advertised in the UK.
Presumably it's expensive?

Well here is a nasty way to turn the link on and off.  Basically it just 
simulates key presses to the window server.  I think the calls probably 
came from a psionic file or similar, but I don't have the original 
details.

PROC main:
        GLOBAL wsrv%,key%,mod%   REM keep these together in this order
        LOCAL wsrv$(15)
        wsrv$="sys$shll.*"+CHR$(0)
        
        REM get the window server process id
        wsrv%=CALL($188,UADD(ADDR(wsrv$),1))
        
        REM bring window server to foreground
        CALL($998d,0,wsrv%)
        
        REM send Psion-l (link dialog) to window server
        key%=512+ASC("l")    REM Psion-l
        mod%=8               REM Psion key
        send:
        
        REM set 'remote link' choice to 'On' i.e. send 'End'
        key%=263
        mod%=0
        send:
        
        REM 'press' Enter
        key%=13
        mod%=0
        send:
        
        REM link should now be active at last used baud rate.

        REM now turn link off
        key%=512+ASC("l")
        mod%=8
        send:

        key%=262    REM 'Home' set top dialog line to 'Off'
        mod%=0
        send:
        
        key%=13
        mod%=0
        send:
        
        REM return your OPL program to the foreground
        CALL($998d,0,0) 
ENDP

PROC send:
        REM send your key and modifier to window server
        CALL($483,wsrv%,49,0,ADDR(key%))
ENDP

You should probably check the 3-Link is plugged in before doing this, see 
Psion/comms 1447 to see how I do it.  There is always the risk that 
something might go wrong during development when mucking about with the 
window server - take care!  None of this code checks for errors during 
execution, it's probably a good idea to do so!

Roger


==========
psion/opl #2374, from slitchfield, 344 chars, Oct 25 18:30 95
----------
Starting background process
hzk very helpfully posted code to start an APP or OPA or OPO module, but 
is there a simple switch/flag I can set or modify to start an OPO in 
BACKGROUND mode, i.e. asynchronously, so that the main app carries on 
on-screen while the background one scurries away unseen??

Thanks in advance guys!

Steve


==========
psion/opl #2379, from dpalmer, 933 chars, Oct 26 14:42 95
Comment to 2374.
----------
This is up to the child that is started - some cannot operate 
sensibly in the background. 

In general the child can either a) Not connect to the Window Server 
at all (a daemon process), or b) connect in background mode, or c) 
connect normally then tell the WS not to display its screen  'on 
top'.

AFAIK only option C is available to OPL progs - use 
call($998D,100,0,0,0,0) to go to backscreen and 
call($998D,0,0,0,0,0) to go forescreen. The '100' here is just a 
big number. You will always get a slight twitch to the screen when 
a child OPO is run, because it starts off forescreen.

BTW this is distinct from a/synchronous spawning of child 
processes. If you start the child with the same priority as the 
parent (the default), they will both get time-slices and run 
together. If with a higher priority than the parent then the child 
will run until it blocks (typically waiting for I/O).

David.


==========
psion/opl #2383, from perseus, 384 chars, Oct 27 11:40 95
Comment to 2380.
----------
In case you were asking how you start a process without stopping 
yourself, then you'll find that hzk's code probably includes a call to 
p_logona and an IOWAITSTAT command, which performs the function of 
waiting for the other process to finish.

Omit these, and the routine will start a new process, and carry on 
immediately.

Sorry if I'm telling you how to suck eggs.


==========
psion/opl #2386, from jbinnie, 295 chars, Oct 28 19:28 95
Comment to 2384.
----------
Steve, have you had a look at Jezar's code SEGMENTS.OPL in the file list? It 
looks like it will allow you to set up memory segments to do what you're 
looking for.

Is there any code in the FLIST which shows how to spawn the child processes 
with the same priority as the parent?

JB



==========
psion/opl #2446, from psion_c, 5085 chars, Nov 14 21:54 95
----------
Edit boxes in OPL
Hello

I have written some code which allows access to HWIM/HWIF edit boxes in 
OPL. If anybody is interested in seeing this, I have posted it to 
comp.binaries.psion (EB.ZIP). I am happy to answer questions here or by 
mail (ali-manson@psion.com) - please note that the sources rely on the 
latest version of the SIBO OPL SDK.

Here is the readme:

Edit Boxes in OPL
-----------------

In the EB.ZIP file you should find:

*  README.TXT   this file. This documentation is
                deliberately light on information.
                Full understanding will require
                reference to EB.DOC (described later).

*  EB.OPL       OPL source (requires the SIBO OPL SDK)

*  EB.OPH       header file containing constants and
                definitions

*  EB.DOC       a Word file extracted from the Psion
                SIBO C SDK which describes the edit-
                box functions from the HWIF library in
                some detail. For a completely thorough
                understanding of the techniques employed
                users are referred to the SIBO C SDK
                which includes the C sources of the
                HWIF library and associated header files.

*  EB.RTF       an RTF version of the above document.

*  EB.TXT       a text-only version of the above document


EB.OPL
------

EB.OPL is a file which contains the OPL source
to a suite of functions which allow OPL programmers to
create edit boxes for use in their applications. The suite
of functions is designed to mirror the functionality of the
hEBxxx functions in Psion's HWIF library. An edit box created
using this code can have the following features:

*  text is automatically word wrapped at the visible right margin.
   Users can start a new paragraph by pressing the <Enter> key.

*  in multi-line editors, the display is vertically scrolled
   automatically

*  the user can show or hide paragraph ends and spaces

*  the text may be displayed with different attributes (bold, etc.)
   Note that the style cannot vary word to word.

*  the width of the editor may be varied on request

*  a side cursor may easily be displayed. The width of the text cursor
   may be easily altered.

*  the value cut, copy, paste, evaluate, find and replace are all
   easily available.


The procedure
-------------

The minimum steps required to include an editor are:

*  create the editor using a call to hEBOpen

*  when appropriate, emphasise it using hEBEmphasise

*  pass relevant keys to it using hEBHandleKey

*  when the application needs the contents, they can be
   retrieved using hEBSenseText


The functions supplied
----------------------

Note that the function names used would, ordinarily
be illegal in OPL. For the sake of understanding, the
OPL function names have been replaced by symbols which
are, themselves, replaced at translate-time by the OPL
translator (either HHTRAN or ODE). The symbol definitions
are defined in EB.OPH and are:

hEBOpen                 EBOPEN%:
hEBHandleKey            EBHK%:
hEBCompleteFormat       EBCnFm%:
hEBSenseText            EBSnsT%:
hEBSetText              EBSetT%:
hEBEmphasise            EBEmph%:
hEBSetSelect            EBSetS%:
hEBSenseSelect          EBSnsS%:
hEBSenseClipText        EBSnsC%:
hEBSetClipText          EBSetC%:
hEBChangeWidth          EBChgW%:
hEBSetCWidth            EBStCW%:
hEBInsert               EBIns%:
hEBReplace              EBRpl%:
hEBEvaluate             EBEval%:
hEBCopy                 EBCopy%:
hEBPaste                EBPaste%:
hEBFind                 EBFind%:
hEBClearChanged         EBClrCh%:
hEBSenseChanged         EBSnsCh%:
hEBShowSymbols          EBShwSy%:
hEBClose                EBClos%:
hEBSenseDoc             EBSnsDc%:
hEDCapacity             EDCap%:
hEDInsert               EDIns%:
hEBDocChanged           EBDocCh%:
hEBSetMargin            EBSetMg%:
hEBSenseMargin          EBSnsMg%:
hEBPosToXL              EBPosXL%:


Example
-------

The EB.OPL module contains a function to create an
edit box (CreateEditBox:), seed the edit box with
some text (InitText:) and then a short mainloop which
offers examples of:

*  handling keys using hEBHandleKey:

*  evaluating using hEBEvaluate:

*  copying text using hEBCopy:

*  inserting text using hEBPaste:

*  finding text using hEBFind:

*  on exit, sensing the length and start of any highlighted
   text in the edit box using hEBSenseSelect:


Support
-------

This code is supplied on an as-is basis and no offer of
support is expressed or implied. Questions on the techniques
used will, in most cases, be answered by referring to the
contents of EB.DOC or the sources of HWIF.LIB as supplied
with Psion's SIBO C SDK. Questions may be directed, informally
to "ali-manson@psion.com" but, although I shall try to assist
a response cannot be guaranteed.

Prepared 11.2.95 by Alasdair Manson of Psion Inc. Technical
Support. Thanks to Steve and David.


==========
psion/opl #2509, from perseus, 1942 chars, Nov 30 14:45 95
Comment to 2507.
----------
> ... the routine in the manual it falls over with an Error: -43

That's due to the fact that only a maximum of 255 bytes is is expected 
from text lines, so the buffer is only that big.

> the line I'm looking to process may be up to 5000 charcters long.

Do you want to read all of it in at the same time?

You need to open the file without the 'text file' type flag ($0020 I 
think).  You will read the file as data, and have to process carriage 
returns and line feeds yourself.  You are likely to receive a block of 
data containing several lines at a time.

> In case anyone is wondering I'm trying to write code to take that text 
> and word wrap it (in ASCII) to lines of 76 characters.

In that case, it's fairly simple.
     1.  Read in 76 chars from a file opened as a binary file.
     2.  Scan the 76 bytes for codes of 13 or 10 (CR or LF)
     3.  If there were no code 13s or 10s :
             Scan back from Byte 76 to the first space you find
             Write the whole block of data up to the space to the output
             Write CR/LF to the output
             Copy the the rest of the data (starting at the byte after 
the space) to the start of your buffer.  'Top up' your buffer to 76 bytes 
by reading in more data.
             Go to step 2
     4.  If you found a CR or LF code :
             Write the data before the CR/LF to the output file.
             Write any CRs or LFs to the file as well
             Copy the the rest of the data (starting at the byte after 
the  CRs/LFs) to the start of your buffer.  'Top up' your buffer to 76 
bytes by reading in more data.
             Go to step 2


You should be aware that reaching the end of the file may mean that your 
buffer is not always going to be as long as 76 bytes.  In the interests 
of efficiency, it would be better to have a much larger buffer, but this 
method is simple and works.

Best of luck!


==========
psion/opl #2512, from dbrewood, 1480 chars, Nov 30 22:8 95
----------
TITLE: Word Wrapping II
Well, the diary project continues, I've now completed the first bit of 
OPL code which will indeed open a given ASCII file, will word-wrap it to 
a given number of characters, taking into account any CR/LF combinations 
found. I've got it printing the wrapped text to the screen with marker 
flags to check it's working. All well and good so far....

[Here's hoping it will work inside the macro, just testing under OPL at 
the moment for ease].

Now here is the embarrasing bit....

I can't work out how to open a new file and write my individual lines to 
it, terminating each with a CR/LF combo...

From reading the programming manual I know I can open my file, say 
FINAL.TXT, with:

mode2%=$0002
ret%=IOOPEN(handle2%,"\TXT\FINAL.TXT",mode2%)

and then use something like the following to write to the file:

ret%=IOWRITE(handle2%,address2%,length%)

but, how do I get the values of address% and length% for each string I 
wish to save, out$, that is?

Do I have to use something like 'address2%=ADDR(out$)' to get the data for 
the address2% variable??

If so, sounds right, but how do I get the length% variable, surely by not 
using len(out$)???

Any help on this final piece of the code would be greatly appreciated!

As I think you can tell I'm not much at ease with file operations in OPL 
yet, they seem somewhat complex and mystifying [g]

Looking forward to any and all replies.

Daron M. Brewood



==========
psion/opl #2557, from pdevelop, 906 chars, Dec 14 15:31 95
Comment to 2556.
----------
> Alarms
> Is there any way from an OPL program of interfacing the standard Psion 
> alarms i.e. to set one from another application ?

If you want to set an alarm from within an OPL program, the following 
code ought to do you nicely:

PROC alm:
LOCAL h%,a&(2),a$(64),b$(65),d&,t&,t2&,a%,r%,s%
r%=IOOPEN(h%,"ALM:",0)
IF r%<0 :RAISE r% :ENDIF
d&=DAYS(DAY,MONTH,YEAR) REM today
t&=DATETOSECS(1970,1,1,HOUR,MINUTE,0)
DINIT "Set alarm"
DTIME t&,"Time",0,0,DATETOSECS(1970,1,1,23,59,59)
DDATE d&,"Date",d&,DAYS(31,12,2049)
DTIME t2&,"Alarm advance time",2,0,86399
DEDIT a$,"Message"
IF DIALOG
        a&(2)=86400*(d&-25567)+t&
        a&(1)=a&(2)-t2&
        b$=a$+CHR$(0)
        a%=ADDR(b$)
        r%=IOA(h%,2,s%,a&(),#a%+1)
        IF r%<0 :RAISE r% :ENDIF
ENDIF
r%=IOCLOSE(h%)
IF r%<0 :RAISE r% :ENDIF
ENDP

Admiration and respect to Ali Manson for this code.

Anthea



==========
psion/opl #2571, from dbrewood, 487 chars, Dec 29 10:44 95
----------
TITLE: Assistance needed:
I'm looking for the following routines if anyone has them. I've been 
trying to code these routines over the past couple of days with no luck:

- Timer code to allow a count of elapsed time to be taken. Must work even 
if start time 11:58:pm and end time 00:12am.

- Code to play the fanfare sample out of the ROM for 3 seconds.

- A decent random number seed generator for RANDOMIZE.

Any assistance would be appreciated.


Daron M. Brewood



==========
psion/opl #2573, from hzk, 288 chars, Dec 29 23:25 95
Comment to 2571.
----------
To play the fanfare, try:

w%=0
wve$="ROM::SYS$AL01.WVE"
dur%=180
CALL($1e86,UADD(ADDR(wve$),1),dur%,0,0,ADDR(w%))
PAUSE -120

The PAUSE is there only to give delay so that the fanfare will complete.
It's not necessary unless the program is likely to terminate here.

Roger


==========
psion/opl #2574, from hzk, 565 chars, Dec 30 19:3 95
Comment to 2573.
----------
Hmm, how did the w% get in here?  It's not mentioned in the Psionics file 
:-(

I should have said:

dur%=96  REM duration in 1/32 second
vol%=0   REM from 0 (loudest) to 5
CALL($1e86,UADD(ADDR(wve$),1),dur%,vol%,0,0)

For elapsed time, you could call DATETOSECS(YEAR,MONTH....etc) twice, and 
the difference is the elapsed time in seconds.  You could decode this 
using SECSTODATE and discard the unwanted bits, or do a simple 
calculation.  Alternatively you could use the TIMER device - I never 
have,  so I have no idea how this works!

Roger


==========
psion/opl #2575, from dbrewood, 709 chars, Dec 31 11:23 95
Comment to 2573.
----------
>w%=0
>wve$="ROM::SYS$AL01.WVE"
>dur%=180
>CALL($1e86,UADD(ADDR(wve$),1),dur%,0,0,ADDR(w%))
>PAUSE -120

Greatly appreciated, and I thought it would take a lot of code to do it! 
Are the ROM WVE file names detailed anywhere.

>The PAUSE is there only to give delay so that the fanfare will complete.
>It's not necessary unless the program is likely to terminate here.

Got it, very clear, thanks Roger.

BTW I take it this sort of data exists in the Psionics files?

Still trying to find out what format these come in, as I'm operating on an 
Atari with no PC type doc convertors at all, so can't easilly handle RTF, 
etc docs. Are they useful to an 100% OPL coder?

Daron M. Brewood



==========
psion/opl #2576, from dbrewood, 869 chars, Dec 31 11:56 95
Comment to 2574.
----------
>Hmm, how did the w% get in here?  It's not mentioned in the Psionics file 
>:-(

Grin.

>I should have said:
>
>dur%=96  REM duration in 1/32 second
>vol%=0   REM from 0 (loudest) to 5
>CALL($1e86,UADD(ADDR(wve$),1),dur%,vol%,0,0)

Well, the original code seemed to work in any case, just testing out the 
new code now.

>For elapsed time, you could call DATETOSECS(YEAR,MONTH....etc) twice, and 
>the difference is the elapsed time in seconds.  You could decode this 
>using SECSTODATE and discard the unwanted bits, or do a simple 
>calculation.  Alternatively you could use the TIMER device - I never 
>have,  so I have no idea how this works!

Just trying it ou using DATETOSECS now and we will see if this works. 
Cross fingers.

Well both new bits of code seem to work well enough.

Thanks for the assist Roger.

Daron M. Brewood



==========
psion/opl #2577, from dbrewood, 216 chars, Dec 31 20:2 95
----------
TITLE: OPL Array sorting.
Does anyone have a fragment of OPL code to sort the values held within a 
string array? That is to sort the words held within the array in 
alphabetical order.


Daron M. Brewood

==========
psion/opl #2580, from rbenno, 4247 chars, Jan 2 0:6 96
Comment to 2577.
----------
>Does anyone have a fragment of OPL code to sort the values held within a 
>string array? That is to sort the words held within the array in 
>alphabetical order.

Its funny you should ask that as i have just this minute finished writing 
such a piece of code for a program that i am working on. This is 
something that i have just thought up and haven't really put it to the 
test, but it seems to work so i hope its useful.

--------------CUT HERE AND COPY TO PSION----------------------------

REM The program works like this .It uses three string arrays.
REM The first is the one you wish to sort, in this case b$().
REM The program starts by going through the array checking to see
REM if the first letter is "A" or "a". If it is then it copies the string
REM to the second array. If it's not "A" or "a" then it copies the string
REM to the third array. It then starts checking the third array for "B" 
or "b"
REM and copies them to the second array, and so on and so on, until the 
second
REM array ends up containing all the sorted strings.
REM It takes about 5 seconds to sort this 144 long array on my S3a.
REM Just translate it as is and it will display the sorted list on screen.
REM Produced using ODE.
    
PROC SORT:
LOCAL b$(144,1),c$(144,1),d$(144,1),b%,c%,d%,chr%,count%,num%,x%,y%

REM  this is a random string array for testing this program

b$(1)="n" :b$(2)="f" :b$(3)="n" :b$(4)="h" :b$(5)="l" :b$(6)="p"
b$(7)="p" :b$(8)="l" :b$(9)="s" :b$(10)="n" :b$(11)="O" :b$(12)="s"
b$(13)="f" :b$(14)="h" :b$(15)="p" :b$(16)="O" :b$(17)="f" :b$(18)="n"
b$(19)="a" :b$(20)="l" :b$(21)="x" :b$(22)="a" :b$(23)="o" :b$(24)="w"
b$(25)="h" :b$(26)="f" :b$(27)="s" :b$(28)="f" :b$(29)="A" :b$(30)="n"
b$(31)="l" :b$(32)="l" :b$(33)="p" :b$(34)="h" :b$(35)="h" :b$(36)="w"
b$(37)="A" :b$(38)="f" :b$(39)="n" :b$(40)="n" :b$(41)="o" :b$(42)="x"
b$(43)="p" :b$(44)="o" :b$(45)="w" :b$(46)="n" :b$(47)="O" :b$(48)="s"
b$(49)="w" :b$(50)="n" :b$(51)="f" :b$(52)="w" :b$(53)="A" :b$(54)="h"
b$(55)="p" :b$(56)="s" :b$(57)="n" :b$(58)="x" :b$(59)="h" :b$(60)="p"
b$(61)="l" :b$(62)="f" :b$(63)="w" :b$(64)="n" :b$(65)="l" :b$(66)="s"
b$(67)="x" :b$(68)="A" :b$(69)="p" :b$(70)="v" :b$(71)="o" :b$(72)="x"
b$(73)="h" :b$(74)="h" :b$(75)="s" :b$(76)="h" :b$(77)="A" :b$(78)="p"
b$(79)="O" :b$(80)="z" :b$(81)="s" :b$(82)="l" :b$(83)="h" :b$(84)="v"
b$(85)="h" :b$(86)="A" :b$(87)="x" :b$(88)="z" :b$(89)="v" :b$(90)="x"
b$(91)="p" :b$(92)="v" :b$(93)="e" :b$(94)="e" :b$(95)="y" :b$(96)="e"
b$(97)="l" :b$(98)="e" :b$(99)="y" :b$(100)="h" :b$(101)="b" :b$(102)="y"
b$(103)="b" :b$(104)="O" :b$(105)="y" :b$(106)="O" :b$(107)="O" 
:b$(108)="y"
b$(109)="q" :b$(110)="z" :b$(111)="q" :b$(112)="q" :b$(113)="q" 
:b$(114)="q"
b$(115)="Z" :b$(116)="Z" :b$(117)="Z" :b$(118)="d" :b$(119)="b" 
:b$(120)="Z"
b$(121)="d" :b$(122)="b" :b$(123)="d" :b$(124)="d" :b$(125)="c" 
:b$(126)="c"
b$(127)="Z" :b$(128)="z" :b$(129)="c" :b$(130)="p" :b$(131)="z" 
:b$(132)="p"
b$(133)="p" :b$(134)="p" :b$(135)="d" :b$(136)="d" :b$(137)="O" 
:b$(138)="d"
b$(139)="p" :b$(140)="p" :b$(141)="b" :b$(142)="c" :b$(143)="p" 
:b$(144)="O"

REM this section displays the unsorted list on screen

giprint"Unsorted array"

c%=1
b%=1
x%=1 :y%=1
DO
DO
At x%,y%
PRINT b$(b%)
b%=b%+1
c%=c%+1
y%=y%+1
UNTIL c%=17
c%=1 :x%=x%+3 :y%=1
UNTIL b%>=145


busy"Sorting"

REM this section doe's the sorting

b%=1
c%=1    
d%=1
num%=144
count%=num%
chr%=65
DO
 DO
  IF LEFT$(b$(b%),1)=CHR$(chr%) OR LEFT$(b$(b%),1)=CHR$(chr%+32)
   c$(c%)=b$(b%) 
   c%=c%+1
  else d$(d%)=b$(b%)
   d%=d%+1
  ENDIF
  b%=b%+1
 UNTIL b%=count%+1 
 count%=(num%-c%)+1
 d%=1 :b%=1 :chr%=chr%+1
 if count%=0 :goto END :endif
 DO 
  IF LEFT$(d$(d%),1)=CHR$(chr%) OR LEFT$(d$(d%),1)=CHR$(chr%+32)
   c$(c%)=d$(d%)
   c%=c%+1
  else b$(b%)=d$(d%)
   b%=b%+1
  ENDIF
  d%=d%+1
 UNTIL d%=count%+1
 count%=(num%-c%)+1
 d%=1 :b%=1 :chr%=chr%+1
until count%=0
END::
CLS

busy off

REM this section displays the sorted list on screen

b%=1
c%=1
x%=1 :y%=1
DO
DO
At x%,y%
PRINT c$(c%)
b%=b%+1
c%=c%+1
y%=y%+1
UNTIL b%=17
b%=1 :x%=x%+3 :y%=1
UNTIL c%>=145
giprint"Now sorted"
GET

ENDP


==========
psion/opl #2584, from nsands, 524 chars, Jan 4 20:29 96
----------
TITLE: Grey planes
(.....cont'd from 4_series3 topic)
Page 187 of the manual says, and I quote "For bitmap files which
contain more than one bitmap, i% specifies which one to load. For the
first bitmap, use i=0. This is also the default value. Bitmap files
saved with gSAVEBIT have only one bitmap, and this argument is not
needed for them."
Midleading or what? Because if you don't put the argument in, its
default value of 0 loads only the black plane. And if I do what you
said, it works. Spooky, huh?
Neil :)

==========
psion/opl #2586, from rick, 319 chars, Jan 5 10:15 96
Comment to 2584.
----------
Neil,

You're right, it is confusing. The problem is the sentence :

  "Bitmap files saved with gSAVEBIT have only one bitmap,
   and this argument is not needed for them."

This is incorrect for the 3a. Get a pencil and draw a line through it. 
:-) I think it's a hangover from the Series 3 manual.

Rick


==========
psion/opl #2588, from dbrewood, 412 chars, Jan 5 17:7 96
----------
TITLE: Prog queries.
I've just realised that OPL does not automate searching for files 
automatically over the various media (as mac_sys does).

Is there a recommended manner of checking:

- The current media the application is on.

- Whether to use drives A/B for data files.

- Is there a rule as to if you use M: for the application you use it for 
config files as well?


Daron M. Brewood



==========
psion/opl #2591, from twagstaff, 427 chars, Jan 6 2:37 96
Comment to 2588.
----------
>- The current media the application is on.

cmd$(1) returns the full path name used to start the running 
program.
IIRC, you need to put overlays etc into a specified dir directly 
below the program, thus if the prog is run from
LOC::A:\APP\MYPROG.OPA
Then these files will be in
LOC::A:\APP\MYFOLDER\

To find them :-
f$=CMD$(1)
f$=PARSE$(f$,f$,off%())
myovr$=left$(f$,off%(4)-1)+"MYFOLDER\MYOVR.OVR"


Tony

==========
psion/opl #2593, from hzk, 462 chars, Jan 6 16:6 96
Comment to 2588.
----------
To check the media:


LOCAL a%,n$(8),f%(32),media%
a%=ADDR(f%())
n$+"LOC::A:"    REM or just "A:"
CALL($0A87,UADD(ADDR(n$),1),a%)
media%=PEEKB(a%+2)

The 64 bit buffer, f%(), holds various bits of info about the drive.
The byte at offset +2 as read into media% is as follows:

0  ?
1  Floppy
2  HD
3  Flash
4  RAM
5  ROM
6  Read-only

Other info in f%() includes total space on device, free space, vol name, 
battery status...  

Roger


==========
psion/opl #2608, from jdawson, 1770 chars, Jan 19 19:12 96
Comment to 2604.
----------
The following program will print out the names of the fields in a DBF
file. Note this has been simplified, and doesn't  include error
handling, etc. See page 141 of the S3A programming Manual for further
info about database info.

APP dbflabel
TYPE $1004
PATH "\dat"
EXT "dbf"
ENDA
PROC dbflabel:
  LOCAL info%(4),len%,ptr%,header%
  LOCAL ax%,bx%,cx%,dx%,si%,di%
  rem 
  rem Open DBF file
  rem
  OPEN CMD$(2),A,f1$,f2$
  rem 
  rem Get DBF info
  rem
  ODBINFO info%()
  rem 
  rem DBF Handle
  rem
  bx%=PEEKW(info%(1))
  rem 
  rem Read Descriptive Record
  rem
  ax%=$1700
  OS($D8,ADDR(ax%))
  rem 
  rem Length of record returned in AX
  rem
  len%=ax%
  rem 
  rem Get pointer to start of record
  rem (skip 2 byte header)
  rem
  ptr%=UADD(PEEKW(UADD(info%(1),8)),2)
  rem 
  rem Loop until end of record
  rem
  WHILE len%
    rem
    rem Get header of next descriptive
    rem record field. Top nibble is field
    rem type, rest is field length
    rem
    header%=PEEKW(ptr%)
    rem
    rem labels are in type 4 fields
    rem
    IF header%/$1000=4
      len%=header% AND $FFF
      rem
      rem point to first field name
      rem
      ptr%=UADD(ptr%,2)
      WHILE len%
        rem
        rem Print label
        rem
        PRINT PEEK$(ptr%)
        rem
        rem Advance to next label
        rem
        len%=len%-PEEKB(ptr%)-1
        ptr%=UADD(ptr%,PEEKB(ptr%)+1)
      ENDWH
      GET
      STOP
    ELSE
      rem
      rem Skip to next field in descriptive
      rem record
      rem
      len%=len%-(header% AND $FFF)-2
      ptr%=UADD(ptr%,(header% AND $FFF)+2)
    ENDIF
  ENDWH
ENDP

Please do contact me if you would like further help or explanation.

==========
psion/opl #2616, from twagstaff, 790 chars, Jan 23 17:52 96
Comment to 2615.
----------

>Can anyone tell me how to read the date and time of a file from 
>OPL.

Not sure where I got this from, but it'll do the trick.

PROC getfatt:(fname$)
local fzts$(130) :rem ZTS version of fname$
local e% :rem error from FilStatusGet
local ver%,attrib%,size&,mdate&,spare& :rem keep together
local yr%,mo%,dy%,hr%,mn%,sc%,yrday%
fzts$=fname$+chr$(0)
e%=call($887,addr(fzts$)+1,addr(ver%),0,0,0)
cls
print fname$
if e%
    print err$(e%)
else
    print "Size",size&
    secstodate mdate&,yr%,mo%,dy%,hr%,mn%,sc%,yrday%
    print "Last modified",dy%;"/";mo%;"/";yr%
    if attrib% and $20 :print "Mod", :endif
    if attrib% and $4 :print "Sys", :endif
    if attrib% and $2 :print "Hid", :endif
    if (attrib% and $1)=0 :print "RdOnly" :endif
endif
ENDP

Tony

==========
psion/opl #2618, from msutherland, 423 chars, Jan 23 19:53 96
----------
Very low battery indicator
Yes, I know this has been covered before, but I just can't find it. I 
currently use this OS call to find main and backup battery voltages (even 
if there are only two values for main battery)

  Ptr%=addr(BatLevs%(1))
  bx%=Ptr% : ax%=HwGetSupplyStatus
  Ret%=os(HwManager,addr(ax%)) and 1

I know that there is a way of finding a V.low status, but what is it?
Thanks for any help.


==========
psion/opl #2636, from jdawson, 3075 chars, Jan 29 23:10 96
Comment to 2635.
----------
The following application will display the field labels of a DBF file
on a S3 (I borrowed a friend's S3 to do a trial translation and run.

APP dbflabel
  TYPE 4
  PATH "\dat"
  EXT "dbf"
ENDA
PROC dbflabel:
  LOCAL header$(56),hand%
  LOCAL fname$(129),mainbuf%(2048)
  LOCAL DbfHand%,DbfName%,DbfMode%,DbfHead%
  LOCAL len%,ptr%,header%
  LOCAL ax%,bx%,cx%,dx%,si%,di%
  rem
  rem Set up DbfOpenEnt struct - 1st word is
  rem ADDRESS of variable to store file handle
  rem
  DbfHand%=ADDR(hand%)
  rem
  rem 2nd word is pointer to filename
  rem (zero terminated 'C' string
  rem
  fname$=CMD$(2)
  DbfName%=ADDR(fname$)+1
  rem
  rem 3rd word is mode (as IOOPEN)
  rem (this example opens existing file
  rem for read only access)
  DbfMode%=0
  rem
  rem 4th word is address of 56 byte header
  rem 1st 16 bytes is file signature (zero
  rem terminated 'C' string)
  rem
  header$="OPLDatabaseFile"
  DbfHead%=ADDR(header$)+1
  rem
  rem BX = address of DbfOpenEnt struct
  rem
  bx%=ADDR(DbfHand%)
  rem
  rem CX = record type ('normal' records are type 1)
  rem
  cx%=1
  rem
  rem DX = length of record buffer
  rem
  dx%=4096
  rem
  rem SI = address of record buffer
  rem
  si%=ADDR(mainbuf%())
  rem
  rem DI = DbfStateDisabled, so DbfOpen
  rem will not return until complete
  rem
  di%=-1
  rem 
  rem Call DbfOpen
  rem
  ax%=$0000
  OS($D8,ADDR(ax%))
  rem 
  rem Read Descriptive Record
  rem
  bx%=hand%
  ax%=$1700
  OS($D8,ADDR(ax%))
  rem 
  rem Length of record returned in AX
  rem
  len%=ax%
  rem 
  rem Get pointer to start of record
  rem (skip 2 byte header)
  rem
  ptr%=ADDR(mainbuf%())+2
  rem 
  rem Loop until end of record
  rem
  WHILE len%
    rem
    rem Get header of next descriptive
    rem record field. Top nibble is field
    rem type, rest is field length
    rem
    header%=PEEKW(ptr%)
    rem
    rem labels are in type 4 fields
    rem
    IF header%/$1000=4
      len%=header% AND $FFF
      rem
      rem point to first field name
      rem
      ptr%=ptr%+2
      WHILE len%
        rem
        rem Print label
        rem
        PRINT PEEK$(ptr%)
        rem
        rem Advance to next label
        rem
        len%=len%-PEEKB(ptr%)-1
        ptr%=ptr%+PEEKB(ptr%)+1
      ENDWH
      GET
      STOP
    ELSE
      rem
      rem Skip to next field in descriptive
      rem record
      rem
      len%=len%-(header% AND $FFF)-2
      ptr%=ptr%+(header% AND $FFF)+2
    ENDIF
  ENDWH
ENDP

If you have previously OPENed the file then you must CLOSE it before
the call to DbfOpen. Similarly if you subsequently wish to access the
file using OPL database commands such as OPEN, READ, etc, then you
must first perform a DbfClose call:

  bx%=hand%
  ax%=$0100
  OS($D8,ADDR(ax%))

Of course things would be a lot simpler if there was a way of mimicing
ODBINFO on the S3 (an OS call?). Perhaps disassembly of the code
produced for ODBINFO on the S3A might yield some clues...

John W Dawson

==========
psion/opl #2639, from psion_c, 86 chars, Jan 30 13:56 96
Comment to 2616.
----------
Try FLFINFO%:() in the library in the latest SIBO OPL SDK ?

All the best

Ali


==========
psion/opl #2656, from jezar, 1647 chars, Feb 4 23:3 96
Comment to 2653.
----------

Hello Kevin,

There's quite a lot of difference between an OPO and an OPA. If your 
program reads and writes files, and you want it to have its own list of 
files under an icon in the system screen, then there is actually a fair 
amount of things you need to consider to turn it into a full-blown OPA.

This is because it needs to communicate properly with the system screen 
so that the business of launching the application from it's icon - or 
selecting a new file from the list - or pressing 'Del' underneath its icon 
to ask it to quit - can proceed in an identical manner to the built in 
applications. And in the moments when an application is unable to 
respond to these messages, it has to lock itself with the LOCK command.

Additionally, there's more subtle behaviour as well, such as being 
written properly to respond to aliasing - that's the business of correctly 
responding to the user choosing "Create new list" in the system screen. 
In order to be aliased properly, an OPA should have no hardcoded 
references to file directories or filename extensions, and instead, 
should simply declare its defaults for these in the APP/ENDA header 
section. In the main body of the program, the correct filename/directory 
and default extension are then picked up using CMD$(1) to CMD$(5).

However - if your program doesn't use files - and doesn't need to be 
forewarned of being exited and can just simply be stopped in its tracks, 
then turning it into an OPA is a simple matter of declaring it as being 
the right type in the APP/ENDA section and giving it a nice icon.

Hope that helps,
Jezar@psion
  


==========
psion/opl #2671, from jezar, 1898 chars, Feb 8 1:27 96
Comment to 2663.
----------

>One thing (forgive my ignorance), does simply declaring a prog as an opa 
>make it possible to exit it from CTRL-X?

Nope. In fact that's one of the nice "goodies" you get when you program 
the S3a in Object Oriented "C" - you declare your "exit" hotkey, and the 
system presses it for you when the user hits "del" on an open file under 
your icon on the System Screen - it even pumps your application with 
"Esc" keypresses to get rid of any menus or dialogs that might be showing 
at the time.

In OPL however, you've got to monitor these events yourself using 
TESTEVENT/GETEVENT and GETCMD$ (but see the manual for the full info).

Whilst we're on the subject, here's a wonderful little technique 
(very useful for applications) which I discovered recently whilst 
plumbing the innermost depths of the system. I don't know if anyone 
outside of Psion knows this (there's plenty inside who didn't) - I've 
certainly never seen it documented anywhere:

You get keypresses by using KEY, GET, GETEVENT, or whatever your 
favourite technique is. Let's say you assign it to k%. Under these 
circumstances, the following is guaranteed to always work:

        IF k% AND $200
            REM User pressed a Psion-something hotkey
        ENDIF

This might not seem significant. What's really nice about this though, is 
that (unlike looking at KMOD) this technique COMPLETELY IGNORES 
keystrokes like PageUp, PageDown, and all those symbols above the number 
keys. It's TRUE MEANING is that the user has *genuinely* attempted to 
perform a menu command - as opposed to merely entering a special symbol, 
or navigating, or adjusting the contrast whilst using the Psion key. 
It's actually the way that the operating system identifies the hot-keys 
for all the built-in apps.

But it's also of course, very useful for OPL programmers too..

Regards,
Jezar.
  

==========
psion/opl #2699, from spooley, 737 chars, Feb 14 23:18 96
Comment to 2698.
----------
I wanted to open the serial port using the parameters as set in the 
system screen serial printer dialog -- too lazy to write my own :-) -- 
and Andrew Clarkson on CompuServe provided the answer.

The serial port parameters are held in an environment variable called 
P$S.  The parameters appear to be stored in the same 6-integer format as 
described in the "Using the serial port" section of the Programming 
Manual.

 LOCAL a$(3), b%(6), r%, d%      REM For serial params

 LOPEN "TTY:A"
 REM Use serial port params from system environment variable
 a$ = "P$S"
 r% = CALL($218B, 0, 0, 3, ADDR(b%()), UADD(ADDR(a$), 1))
 IF r% = 12 :IOW(-1, 7, b%(1), d%) :ENDIF

(Can't help with the rom version number, I'm afraid.)

==========
psion/opl #2700, from rbenno, 606 chars, Feb 17 21:4 96
Comment to 2699.
----------
Thanks for that info.

I have found out how to get the ROM version number now.
After a bit of experimenting i have found that the line

PRINT HEX$(CALL($2A8B)) prints 322F to the screen which is my ROM 
version number 3.22F

The above line of code is a result of pure 'try it and see what 
happens' experimentation. I have suffered disasters in the past by 
using this approach such as wiping out my S3a's internal memory.

If anybody reading this could find the time to write a text file for 
beginners, explaining how to make OS calls then I for one would be 
very grateful.

Richard.


==========
psion/opl #2718, from rick, 240 chars, Feb 21 16:15 96
Comment to 2717.
----------
Try this...

PROC RenameP:
  REM Rename this OPL process.
  LOCAL name$(10), mypid%
  nm$="Draw2"+CHR$(0) REM Null-terminated name.
  mypid%=CALL($88) REM ProcId
  CALL($c88, mypid%, 0,0,0, UADD(ADDR(nm$),1)) REM ProcRename
ENDP


==========
psion/opl #2743, from jezar, 405 chars, Mar 2 12:49 96
Comment to 2738.
----------

Because the process name is for system use.

The "public" name of a process is given by the string held at
the Magic Static DatProcessNamePtr, and that is really the only thing 
that you should go changing.

I was told by the author of the multitasking kernel on the 3/3a that the
proc rename service is for internal use and was only put in the SDK for 
completeness.

Regards,
Jezar.

  
psion/opl #2771, from cxf, 363 chars, Mar 21 18:24 96
----------
Starting Word in text mode
How do I pass the necessary alias info to the Word app. to start it in
"Text" editor mode from OPL. I have tried a command line of:

OWord#Text.txt#LOC::M:\WRD\MYFILE.TXT#
      ^^^^
        This bit up to the full stop I thought was the alias info.

(For # read chr$(0))

but this produces Prog. mode...

TIA

Chris :-)

==========
psion/opl #2773, from psioncorp, 3700 chars, Mar 22 9:46 96
Comment to 2771.
----------
The following is taken from the the s3/3a programming guide in the C SDK. 
I hope it helps.

Regards,  Dave


Active aliasing in the built-in text editor

If the alias info is a null string, the text editor enters Word mode, 
with multi-level outline facilities, styles and emphases, and so on.
Note that it is not unreasonable for an alias to define null alias info. 
This allows the creation of aliases of the text editor that behave in 
exactly the same way as the built-in Word application, but differ from 
each other in terms of their default extensions, default directories, 
and/or public names.

If there is any non-null alias info, the text editor enters one of a 
number of other modes, with the mode depending on the first character of 
the alias info.  Some of these modes are not available on Series 3 
machines. At the time of writing, the allowed first characters and the 
corresponding modes are:

O       OPL program editor
S       Comms script program editor
$       Plain text editor (not Series 3)
/       Word processor with custom template (not Series 3)

The program editor mode is available on all machines. In this mode there 
is no access to the style and emphasis subsystems, the corresponding menu 
commands being replaced by options to "translate", "run", "show error" 
and set "indentation".

In this mode, the first letter of the alias info denotes the nature of 
the program that is being edited. It actually identifies the program to 
invoke to effect any "translate" and (possibly) "run" commands from the 
user.  The generic name of this program is sys$prg?.img, with the 
question mark being filled in from the first letter of the alias info.  
Thus the Prog alias has 'O' for the first letter of its alias info, and 
so the OPL translate/run program sys$prgo.img is used. In contrast, the 
Script editor from the communications ROM has 'S' for the first letter of 
the alias info, so that the program sys$prgs.img is used.

In program editor mode the second letter of the alias info should be 'R' 
if the program is of a type that understands "run" instructions in 
addition to "translate" ones. Any other second character disables the 
"run" command option. The following three letters (e.g. 'OPO' or 'SCO') 
denote both the expected file extension and the expected top-level 
directory where any translated output will by default be placed. (This 
information is used by the editor when offering the user a suitable 
filename to "run").

On the Series 3a a final '*' character may be added to the alias info. 
This has the effect of adding an "S3 Translate" menu option.

The remaining modes are not available on Series 3 machines.

Alias info that consists of a single '$' character selects a plain text 
editing mode. In this case the program-related menu options are 
suppressed, with only an "indentation" option being offered.

A variant on the Word mode is set by alias info that consists of a single 
'/' character. This behaves in a similar way to the Word application, 
with the exception that a specific template file is loaded whenever a new 
file is created. The template must have the same name as the aliased 
application and must be located on the current drive at the time the new 
file is created. Thus, an alias created from the following .ma file:

Letter.LET
\LET\
1083
Word
/

would, on creation of a new file, automatically load the template file 
\wdr\letter.wrt, provided it exists on the current drive. Note that, in 
this mode, the value 80 must be added into the application type number. 
If it is not, the automatic loading of the template is disabled.


==========
psion/opl #2775, from cxf, 273 chars, Mar 22 19:59 96
Comment to 2773.
----------
But what is the name of the "aliased application" and how do you add 80 to
the type when launching from OPL?

Or do I have to create (using makeals) an alias as described i.e.

Test.tst
\TST\
1083
/

and then run the alias file from OPL?

Thanks,

Chris :-)

==========
psion/opl #2776, from hzk, 412 chars, Mar 22 22:38 96
Comment to 2771.
----------
I use the following:

        pgname$="rom::WORD.APP"+CHR$(0)
        cmdl$="OWord"+CHR$(0)+".TXT $"+CHR$(0)+edfile$+CHR$(0)
        r%=CALL($0187,UADD(ADDR(pgname$),1),addr(cmdl$),0,0,addr(edpid%))
        showerr:(r%)
        CALL($0688,edpid%)

edfile$ hold the name of the file to edit.  The cmdl$ line is quite 
critical, especially the ".TXT $" bit (don't miss the space before the $.

Roger

==========
psion/opl #2794, from twagstaff, 495 chars, Apr 4 12:11 96
----------
ENTERSEND0

I'm trying to replicate ENTERSEND0 on the s3 classic thus:-

 os($d9,addr(ax%))
 if ax%<0
  return ax%
 else
  return 0
 endif

Trouble is ax% always returns negative after ENTERSEND0ing a 
O_WN_SET to the current dialog (to use a C_VAFLAT in dChoice). If I 
ignore the "error", the dialog displays fine, which I guess it 
wouldn't if the method had left.

So, how do I check if a method leaves after os($d9,addr(ax%))? Or am 
I doing something else wrong?

Tony

==========
psion/opl #2795, from jezar, 132 chars, Apr 5 8:13 96
Comment to 2794.
----------

Easy - just do a send instead of an entersend. 
If the send leaves, then your OPL program will immediately abort.

Jezar.
  

==========
psion/opl #2798, from twagstaff, 249 chars, Apr 9 1:0 96
Comment to 2795.
----------

>Easy - just do a send instead of an entersend. 
>If the send leaves, then your OPL program will immediately abort.

Isn't there anything more elegant? I'd rather be able to trap any 
errors, than be dumped back to the system screen.

Tony

==========
psion/opl #2800, from jezar, 1041 chars, Apr 13 9:45 96
Comment to 2798.
----------
Nope 'fraid not. 

I had a chat with our OPL guy on this very subject a while back.
Although OPL's RAISE owes more than a passing resemblence to the 
p_enter()/p_leave() mechanism of PLIB, the fact is that the two are 
implemented in different ways. Not enough space to go into the finer 
details here, but the practical upshot is, that OPL cannot trap 
p_leave()'s from the send mechanism, by anything other than the 
ENTERSEND/0() way. As you've no doubt figured out by now, this means that 
there are certain, unfortunate restraints on the way that OPL can 
interface with the object-oriented system (i.e. it is impossible for the 
OPL programmer to design a construct which can tell the difference 
between a p_send(...) that returns a range of values, and a p_send(...) 
which calls p_leave()'s with a similar range of values).

This is due - to a large part - on the fact that it was never expected 
that OPL programmers would really want to 'get their hands dirty' to 
quite this extent! ;-)

Regards,
Jezar.
  

==========
psion/opl #2815, from spooley, 2491 chars, Apr 28 17:30 96
Comment to 2814.
----------
This is what I do in AgnDump...

REM Try to open the Agenda file.  If it fails -40, assume it's because
REM Agenda has the file open.  Stop Agenda and retry the open.

Restart% = 0
OpenAgn::
ret% = IOOPEN(handle%, SrcAgn$, $0200)  REM binary open
IF ret% = -40           REM "File or device in use"
        GIPRINT "Stopping Agenda..."
        IF StopAgn%: <> 0
                Restart% = 1
                GOTO OpenAgn::
        ENDIF
ENDIF

REM
REM ..Whatever processing...
REM
        
IOCLOSE(handle%)
IF Restart%
        GIPRINT "Restarting Agenda..."
        StartAgn:(SrcAgn$)
ENDIF


And the StopAgn and StartAgn functions...

PROC StopAgn%:
    REM Stop the first instance of an Agenda process.
    REM Return 1 if we stopped one, else 0.
    LOCAL flags%, ax%,bx%,cx%,dx%,si%,di%
    LOCAL Srch$(16), Found$(16)     REM MaxNameESize + 2
    LOCAL i%

    srch$ = "Agenda.*" + CHR$(0)
    si% = UADD(ADDR(Found$), 1)
    di% = UADD(ADDR(Srch$), 1)
    bx% = 0
    ax% = $0b00 REM AH=0b for NmProcFind
    flags% = os($88, addr(ax%))     REM ProcManager
    IF (flags% AND 1) = 1           REM CY set => none found
        RETURN 0
    ENDIF

    bx% = ax%                       REM Copy process ID
    ax% = $0d00 REM NmProcTerminate, reason 0
    flags% = os($88, addr(ax%))     REM ProcManager
    IF (flags% AND 1) = 1           REM CY set => failed
        RETURN 0
    ENDIF
    RETURN 1
ENDP

PROC StartAgn:(file$)
    LOCAL flags%, ax%, bx%, cx%, dx%, si%, di%
    LOCAL ret%, pid%
    LOCAL cmdl$(128),img$(128)

    cmdl$="DAgenda" + CHR$(0) + ".agn" + CHR$(0) + file$ + CHR$(0)
    img$ = "rom::agenda.app" + chr$(0)

    REM
    REM Create the application
    REM
    ax% = $0100      REM set AH = 1 for "FilExecute" call
    bx% = ADDR(img$) + 1     REM set BX = ponter to application name
    cx% = ADDR(cmdl$)        REM set CX = pointer to length byte of command line
    di% = ADDR(pid%)         REM set DI = address to take pid
    flags% = OS($87, addr(ax%)) REM FileManager
    if (flags% and 1)
      ret% = (ax% AND $FF)-256 REM error returned in AL
      dError%:(ret%)
      RETURN
    ENDIF

  ax% = $0600                REM set AH = 6 for "ProcResume" call
  bx% = pid%                 REM set BX = pid
  flags% = OS($88,addr(ax%)) REM ProcManager
  if (flags% and 1)
    ret%=(ax% and $FF)-256   REM error returned in AL
      dError%:(ret%)
      RETURN
  endif
ENDP


==========
psion/opl #2817, from gbainbridge, 1124 chars, May 2 20:29 96
----------
TITLE: Editing Proportional text

I wonder if one of the experts around here can offer me any help:-

I am currently writing an OPL application where I need to have some 
editable text on what is otherwise a graphics screen. I've tried the 
suggestion in the programming manual of putting a small text window over 
the graphics window and using the EDIT command, but this has two 
problems:-

1.If I use a proportional font, EDIT gets rather confused producing 
a mixture of proportional and mono-spaced characters in the window, 
with the result that the final outcome of the edit is not 
necessarily what is displayed.

2.If I use a mono-spaced font (actually the same font - font 10, 
with the mono style set) the edit works but looks awful with the 
letters too far apart, and with a larger window than would 
otherwise be required.

Given that there are many examples of editable proportional text in the 
built in programmes (i.e. in the Agenda, dialogue boxes etc.) do I really 
have to re-invent the wheel by writing my own code to edit proportional 
text within OPL?

Thanks,
Gary.


==========
psion/opl #2819, from millar, 90 chars, May 3 18:47 96
Comment to 2817.
----------
You could bend Ali's edit box code to your will - it's EB.ZIP in 
psion/files

Matt


==========
psion/opl #2820, from gbainbridge, 469 chars, May 3 23:38 96
Comment to 2818.
----------
>Why not use dEdit in a dialogue box?

Because I want it to work like the Agenda i.e. Press the first letter and 
the edit box opens, continue typing then press return when the edit is 
finished. If I use a dialogue box, then I can open it with the first 
letter in the dEDIT field, but typing the second letter overwrites it so 
that the first letter is always lost.

If anyone knows a way of solving this problem it would be equally valid.

Thanks,
Gary.

==========
psion/opl #2822, from hzk, 3601 chars, May 6 13:20 96
Comment to 2817.
----------
I wrote a single line editor for my packet radio program a while back.
This used monospaced text, so I have modified it for proportional text.
The result is below!

Basically you can move the cursor around inside the text, and delete
and insert characters at will.  On the following extract there is no
check on whether the text goes off the display - my original program
sent the text to the transmitter before this could happen.

There may be the odd bug - I have not fully checked this proportional
text version.  Hopefully the cursor keeps in the correct place as you
type and delete - it seems OK.

You can add extras easily, like make the "Esc" key abort the action.
I also did a two line version for a series 3, and a whole page editor
(absolute nightmare)!  I threw away the code for the latter, since it
became impossible to understand after I blinked.

It may not be quite what you want, and there is bound to be something
in the Psion ROM to make it easier, but this OPL uses standard commands
which are all in the manual.  It may be possible to simplify and tidy
up the code too, especially around the code which manipulates the
cursor inside the text.

Anyway, here it is.  Hope it is some use.

Roger.


PROC main:

  GLOBAL pos%         REM number of characters from right end
  GLOBAL text$(80)    REM holds string
  LOCAL k%            REM key pressed
  gFONT 7             REM a suitable font
  gTMODE 3            REM replace mode
  gAT 0,100           REM start position

  DO                  REM get keys pressed
    k%=GET
  UNTIL sle%:(k%)=-1

  gAT 0,120 :gPRINT text$   REM print final text
  GET

ENDP


PROC sle%:(j%)
  LOCAL txtlen%          REM length of text$
  LOCAL charwid%         REM width of character

  charwid%=gTWIDTH(CHR$(j%))  REM get width of key pressed
  txtlen%=LEN(text$)
  CURSOR 1               REM cursor visible in default win

  IF j%=8                REM Delete pressed

    IF pos%=txtlen%      REM if cursor at start of text

      BEEP 2,500         REM nowt to delete!

    ELSEIF pos%<>0       REM if cursor inside text

      text$=LEFT$(text$,txtlen%-(pos%+1))+RIGHT$(text$,pos%)
      charwid%=gTWIDTH(MID$(text$,txtlen%-(pos%),1))
      gAT 0,100 :gPRINTB text$,gTWIDTH(text$)+charwid%
      gAT gTWIDTH(LEFT$(text$,txtlen%-(pos%+1))),gY

    ELSE                 REM if cursor at end od text

      charwid%=gTWIDTH(RIGHT$(text$,1))
      text$=LEFT$(text$,txtlen%-1)
      gAT 0,100 :gPRINTB text$,gTWIDTH(text$)+charwid%
      gAT gTWIDTH(text$),gY

    ENDIF

  ELSEIF j%=258   REM right arrow key pressed

    IF pos%>0

      pos%=pos%-1
      charwid%=gTWIDTH(MID$(text$,txtlen%-pos%,1))
      gAT gX+charwid%,gY

    ENDIF

  ELSEIF j%=259  REM left arrow key pressed

    IF gX<>0     REM cursor not at start of text

      charwid%=gTWIDTH(MID$(text$,txtlen%-pos%,1))
      gAT gX-charwid%,gY
      pos%=pos%+1

    ENDIF

  ELSEIF j%=262   REM "Home" key pressed

    gAT 0,100
    pos%=LEN(text$)

  ELSEIF j%=263  REM "End" key pressed

    gAT gTWIDTH(text$),gY
    pos%=0

  ELSEIF j%<>13 AND j%<256   REM a letter key pressed

    IF pos%=0   REM cursor at end of line

      text$=text$+CHR$(j%)
      gPRINT CHR$(j%)

    ELSE

      txtlen%=LEN(text$)
      text$=LEFT$(text$,txtlen%-pos%)+CHR$(j%)+RIGHT$(text$,pos%)
      gAT 0,100 :gPRINT text$
      gAT gTWIDTH(LEFT$(text$,txtlen%-(pos%-1))),gY

    ENDIF

  ELSEIF j%=13      REM "Enter" pressed

    RETURN -1

  ENDIF

ENDP




==========
psion/opl #2823, from gbainbridge, 366 chars, May 8 10:27 96
Comment to 2822.
----------
>It may not be quite what you want, 

Actually, as it's quite small it looks ideal. I didn't want to use too 
much code as the programme is getting too large already. 

>and there is bound to be something in the Psion ROM to make it easier

That's what is really annoying. I feel it should be as easy as calling up 
a dialogue.

Thanks a lot,

Gary. 


==========
psion/opl #2824, from psion_c, 307 chars, May 9 21:36 96
Comment to 2817.
----------
Hello

I wrote some code to implement edit boxes in OPL. Try downloading 
EB.ZIP from psion.files as it may well do the job for you. You should 
note that this code was written using the Psion SIBO OPL SDK Library 
and therefore you will need that SDK to make use of this code.

All the best

Ali

==========
psion/opl #2825, from hzk, 170 chars, May 9 23:11 96
Comment to 2823.
----------
I missed out a CURSOR OFF statement which should be called when you 
finish editing, otherwise the cursor gets carried through to the next 
gPRINT actions!

Roger


==========
psion/opl #2847, from fbotton, 430 chars, May 16 14:35 96
----------
TITLE: Installation icon problems...

I'm quite worried as I have problems with some applications I wrote:

I'm referring to an icon (icon.pic) using
ICON "LOC::M:\app\myapp\icon.pic" in the APP...ENDA header.
Depending on the machine it is installed on, the icon does not always
appear (sometimes just a blank square) correctly, the icon.pic file
being at the right place...

Anybody's got an idea?

TIA,
Fred.
  

==========
psion/opl #2853, from jezar, 215 chars, May 17 8:54 96
Comment to 2847.
----------

You don't need the icon once you've translated the program.
OPL copies it into the OPA itself.

Regarding the fact that the Icon doesn't always appear, 
it sounds like the icon file is corrupt.

Jezar.
  

==========
psion/opl #2854, from ple, 525 chars, May 17 10:15 96
Comment to 2847.
----------
TITLE: Installation icon problems...

Just a suggestion, I've not checked this (-8

It could be that in specifying

"ICON "LOC::M:\app\myapp\icon.pic"

as the location of the icon that you are being too specific about its 
location, if the application is installed from drive other than M: then 
maybe the location of the icon is not found.

I use

APP
  TYPE $1002 REM only one file allowed at once
  PATH "\APP\BACKG"
  EXT "BGM"
  ICON "backg"
ENDA

in Backgammon and it works fine.

Cheers, PLE


==========
psion/opl #2859, from fbotton, 125 chars, May 17 17:17 96
Comment to 2854.
----------
Ok, I'm going to try a non-specific path first, then check if my
icon's faulty if that does not cure...

TVM!
Fred.
  


==========
psion/opl #2887, from mavc, 500 chars, May 21 20:50 96
----------
Long OPL source program lines
Can anyone help? Maybe I missed this info somewhere?

If you've got a long OPL source code line, (for example when defining 
mCARDs items using text strings), is there a way of splitting it over 
several lines, to make it easier to read? (I'm using the 3a OPL 
editor). I tried <shift enter> at the end of the line, but the 
translator spits it out. I'd rather avoid predefining a whole set of 
string variables just to make the program line shorter.

Mark

==========
psion/opl #2891, from jezar, 65 chars, May 21 23:16 96
Comment to 2887.
----------

Nope.

But maybe OPP could help you out here.

Jezar.
 

==========
psion/opl #2896, from aclarkson, 325 chars, May 23 23:3 96
Comment to 2891.
----------
> But maybe OPP could help you out here.

Yes, with OPP you can use the \ character as a line continuation 
character:

        mcard "Menu",           \
                "Item 1", %n,   \
                "Item 2", %o,   \
                "Item 3", %a,

Download OPP14F.ZIP from the flist in psion/files.

Andy


==========
psion/opl #2897, from mavc, 266 chars, May 24 7:51 96
Comment to 2896.
----------
Thanks for the info. Downloaded it last night. Looks to be just the 
job, and does lots, lots more besides. My OPL code isn't very big yet 
so I'll probably stick with the OPL editor for a while, but I'm sure 
I'll need to install OPP before too long.

Mark


==========
psion/opl #2900, from jhethe, 847 chars, Jun 4 0:26 96
----------
Serial port status
Can anyone tell me how to detect if there is data waiting to be read from 
the serial port? 

I modified the example in the programming manual (p.239) to continuously 
read data from an external device (a GPS receiver).  If, however, this 
device stops sending, then the program locks up because it has not 
received a terminating character (code 13 in this case).

To prevent this lockup is there any way of setting a timeout such that if 
no characters are received for, say 5 seconds, the number of bytes read 
so far will be returned?

Also is there any way of flushing the serial input buffer at the start of 
the program?  My modified example often displays serial overrun if the 
external device is sending before the program starts, presumably because 
there is no handshaking.

Many Thanks
John



==========
psion/opl #2901, from baldwina, 318 chars, Jun 4 18:59 96
Comment to 2900.
----------
Perhaps you should consider using asynchronous IO calls (e.g. IOA) to 
talk to the serial port. That way your program will never have to stop 
and wait until it receives a certain character. You could also then use 
the TIM: device to implement a time out, again, using asynchronous calls.

AndrewB
Psion PLC

==========
psion/opl #2905, from psion_c, 1024 chars, Jun 5 13:44 96
Comment to 2900.
----------
>Can anyone tell me how to detect if there is data waiting to be read 
>from the serial port? 

The P_FTEST service of the serial driver offers this. The OPL Library 
macro SE_TEST implements this.


>To prevent this lockup is there any way of setting a timeout such that 
>if no characters are received for, say 5 seconds, the number of bytes 
>read so far will be returned?

If you read asynchronously rather than synchronously (which I assume 
you are doing now), you can have a timer running at the same time to 
implement a timeout. This is pretty standard programming in EPOC:

 queue a timer
 queue a serial read
 IOWAIT
 if (timer completed)
    do something timeout related
 else if (serial read completed)
    do something serial port related
 else
    bug
 endif
 
>Also is there any way of flushing the serial input buffer at the start 
>of the program

The P_FFLUSH service of the serial driver offers this. The OPL Library 
macro SE_FLUSH implements this.

All the best

Ali

==========
psion/opl #2903, from hzk, 1221 chars, Jun 4 23:48 96
Comment to 2901.
----------
It's not too difficult to do it using IOA.  You can set up something like:

    IOA(-1,1,sstat%,#UADD(ADDR(buffer$),1),c%)

making c% equal to 1 (byte).
Then set up an async I/O call for any system or keyboard event, like:

    IOA(-2,14,estat%,k%(1),#0)

and wait for something to happen:

   IOWAIT

When you get an event happening, the IOWAIT will return, so the next 
lines can check sstat% and estat% - if say estat% is not -46, then an 
event has happened.  k%(1) hold the value of the keyboard or system event 
- this call is like an async GETEVENT.
If sstat% is not -46, you have at least one serial byte waiting.
You can POKE ADDR(buffer$) with 1, so buffer$ now holds the first byte.  
Check for more with:

    IOW(-1,10,n%,#0)

Here n% will contain the number of bytes waiting to be read.  So you can 
read the exact number with an IOW which will return immediately (make 
sure n% is less than the buffer size - you can always put this call in a 
loop which exits when n% is zero).

I found SPY.APP very useful for developing this sort of thing - it tells 
you things like I/O calls outstanding and whether the program is waiting 
properly when nothing is happening!

Roger


==========
psion/opl #2902, from mavc, 643 chars, Jun 4 21:16 96
----------
Tricks with Dialogs
Anyone know how to achieve the following?

I'm trying to set up a DIALOG, where the dCHOICE selected by the user 
on the first line needs to alter the selection of dCHOICEs offered on 
the second line, and range of input accepted by a dLONG on the third 
line. At the moment I'm doing this using several separate single line 
DIALOGs. Is there a way of doing it with just one DIALOG? Or a way of 
automatically exiting the DIALOG as soon as the first item is changed 
(without needing to hit the Enter key)?

Also, is there a way to access the printer setup menu (normally Psion 
Y) from within OPL?

Mark

==========
psion/opl #2904, from rovoreed, 175 chars, Jun 5 8:55 96
Comment to 2902.
----------

I'm fairly sure the only way you can do this sort of thing is using 
OOP. ISTR you can't even do it in plain old 'C'.

I could be wrong.

Mike Davies

(Blinked Msg)

==========
psion/opl #2906, from psion_c, 154 chars, Jun 5 14:35 96
Comment to 2902.
----------
You can only achieve this objective by subclassing the methods which 
handle keypresses within the dialog (= object oriented C).

All the best

Ali

==========
psion/opl #2907, from psioncorp, 57 chars, Jun 6 9:14 96
Comment to 2902.
----------
APPMAN.OPL might help you out here.

Regards,  Dave


==========
psion/opl #2909, from chennings, 1025 chars, Jun 7 5:22 96
Comment to 2902.
----------
>I'm trying to set up a DIALOG, where the dCHOICE selected by the user
This requires the dialogs to be built using full OOC. That said, there's 
no reason why this can't be done and bundled up in a .DYL that can be 
accessed
from OPL or indeed non-OO C. Take a look at Mark Esposito's latest version 
of NotePad for an example of such an approach.

>Also, is there a way to access the printer setup menu
Well at it's simplest something like the below might work:

LOCAL gate%
gate%=PEEKW($38)
SEND(gate%,25) : REM O_GT_WDR_PRINT_SETUP

But in a way this merely begs the question as to how you a) sense and set 
the parameters that are controlled by the dialog and b) how you achieve 
printing from OPL on the basis of these parameters. Again MarkE has a .DYL 
that provides extensive support for WDR printing from OPL including such 
things as print preview and column printing. The .DYL can be licensed.

Mark is at 72662.3050@compuserve.com and mesposito@cix.compulink.co.uk 

Rgds
Chris Hennings


==========
psion/opl #2910, from perseus, 512 chars, Jun 7 9:28 96
Comment to 2907.
----------
As Dave says, APPMAN.OPL will allow you to alter a dialog while it's on 
the screen.  In order to find out how to actually change the items, you 
need to refer to the OOP programming guide in the SIBO 'C' SDK.  The 
details of the dialog classes are in the HWIM reference (volume 4).

Using APPMAN.OPL you should be able to intercept keypresses on the way to 
the dialog, and modify the dialog appropriately.  Building up the 
appropriate data structures might look a bit ugly in OPL though.

Simon.

==========
psion/opl #2913, from sballan, 279 chars, Jun 18 15:27 96
----------
Checking device status
Are there any tidy methods of checking if there's a device in slot A or B 
and of checking if they're read/write status, etc.

I know I can create a file and check the error, etc.  That's why I'm 
asking about a 'tidy' method!

Regards

Stuart

==========
psion/opl #2922, from hzk, 1671 chars, Jun 22 16:19 96
Comment to 2921.
----------
Here are a few simple fragments to help you.

To check whether a drive or a directory exists, you can try opening its 
root directory, i.e.  ispath%:("LOC::B:\").  You can use this to check
whether any path exists:

PROC ispath%:(cp$)
        LOCAL h%,pp$(128)
        pp$=cp$+"*.*"
        IF IOOPEN(h%,pp$,$30)   REM open directory call
                RETURN 0        REM directory does not exist
        ELSE
                IOCLOSE(h%)     REM it does exist, so close it
                RETURN -1
        ENDIF
ENDP

To check what's in a slot, and its size, etc. (You may be able to use 
this to check the existence of a device instead of ispath%:(), as 
PEEKW(a%), med%, and bt& will all return zero):

PROC free:(device$)
        LOCAL a%,bf&,bt&,med%,n$(8),f%(32),r$(40)
        n$=device$
        a%=ADDR(f%())
        CALL($0a87,UADD(ADDR(n$),1),a%)
        med%=PEEKB(a%+2)
        r$=media$:(med%)    REM  r$ = media type
        bt&=PEEKL(a%+6)     REM  bt& = total bytes on device
        bf&=PEEKL(a%+10)    REM  bf& = free space on device
        REM the 32 bytes from a%+14 hold the volume name
        REM PEEKB(a%+46) should hold 1 if device battery is OK
        REM or zero if battery low, or -4 if battery status n/a
ENDP

PROC media$:(n%)
        IF n%=0 :RETURN "Missing or not known"
        ELSEIF n%=1 :RETURN "Floppy"
        ELSEIF n%=2 :RETURN "Hard Disk"
        ELSEIF n%=3 :RETURN "Flash"
        ELSEIF n%=4 :RETURN "RAM"
        ELSEIF n%=5 :RETURN "ROM"
        ELSEIF n%=6 :RETURN "Write Protected"
        ENDIF
ENDP

All this and much more is in the PSIONICS file SYSCALLS.

Roger



==========
psion/opl #2930, from fbotton, 379 chars, Jul 5 14:53 96
----------
Sounds not being played

I'm playing a sound using the PlayA(): (async) routine in on of my
apps, and that sound actually doesn't get played most of time. Just
after this call, I'm inverting the screen 6 times (with fill). If I
remove this, sounds get played ok. If I use PlayS(): (sync), they get
played ok as well. Is there any explanation, or work around?

Fred.
  

==========
psion/opl #2931, from dpalmer, 580 chars, Jul 6 9:28 96
Comment to 2930.
----------
> Is there any explanation, or work around?

There is only one CPU after all. It looks like async sound playback 
takes place at a lower priority than your foreground prog. If you 
drive the CPU hard after starting the playback it may take a while 
to catch up. EPOC always runs the highest priority task, there is 
no round-robin scheduling or ageing. Try putting some 'pause 1' in 
the subsequent stuff. If that does the trick, make them conditional 
on the contents of the async status word (so the pauses happen only 
if playback has not yet completed).

David.


==========
psion/opl #2932, from fbotton, 209 chars, Jul 8 9:56 96
Comment to 2931.
----------
I've already tried the pause workaround. Well, that helps the sound to
be played sometimes, not always.
BTW, I'm now playing a sync sound, without any problem.
TVM for your explanations, David!

Fred.  

==========
psion/opl #2938, from fisthames, 1270 chars, Jul 16 7:24 96
Comment to 2935.
----------
> My code looks something like this

>if not exist ("\app\test\data.dat")
>        create "\app\test\data.dat",A,name$,age&
>        A.name$="Jim Bob"
>        A.age&=102736782
         APPEND           <--- try adding this !
>endif

APPEND will commit the newly created record to the end of the database.  
This new record will be the last in the file, becomes the current record.

It will then be possible to overwrite the current record with new field 
values using UPDATE.

In addition to Ali's comments, I would also like to point out that there 
may still be bugs in the OPL DBF system (as documented in the OPLSDK):-

/*
- (23/9/92) Bug in DBF system itself - ERASE and UPDATE cause POSITION to 
go to record (x-1) for:

         POSITION 1 :UPDATE :POSITION x :PRINT a.a$
         
  when x=n*16+1 or x=n*16+2 (n>0), and between n*16+1 and (n+1)*16+1 
records in file.
  Records saved with 1 field a.a$=GEN$(pos,2)+"xyz"
Solution:
  Do POSITION 1 after every UPDATE or ERASE

  You can use the following macros instead of UPDATE and ERASE bearing in
  mind the new position is then record 1
*/

#define _UPDATE UPDATE : POSITION 1
#define _ERASE ERASE   : POSITION 1



Hope this helps


Regards,

Neil @ fisthames


==========
psion/opl #2946, from art, 106 chars, Jul 17 10:24 96
----------
diamond in menu bar
How do I get a diamond in the menu bar ? As in the system menu.

TIA

-Arthur


==========
psion/opl #2947, from psion_c, 65 chars, Jul 17 16:29 96
Comment to 2946.
----------
How about this:

 mCARD CHR$(4), etc.
 
All the best

Ali

==========
psion/opl #2951, from swebb, 133 chars, Jul 19 11:34 96
Comment to 2950.
----------
> How do can display the symbol (u over _) for the Psion key ?

The Psion symbol is character code 2.

Simon Webb
SW Systems


==========
psion/opl #2965, from bpechey, 184 chars, Jul 22 15:1 96
Comment to 2956.
----------
Would it be possible to post the means here for giving an OPL program a 
different name and also the way of running an OPL program that has the 
default name?

Thanks,

Bill.


==========
psion/opl #2967, from myotis, 1226 chars, Jul 22 19:53 96
Comment to 2965.
----------
Hello Bill,

Here is the part of the thread from CIS with the information. I include 
all of it as I deserve no credit other than being persistent. I now know 
that it works as I now have 
MonthVu 1.01u installed on my Psion with this code incorporated <g>

Cheers,

Graham S



Subject: MonthVu process name
Fm: Mark Esposito (SYSOP) 72662,3050
To: C. E. Steuart Dewar 71165,1115

CESD,

    >> So to "solve" your problem I would have to rewrite the entire 
program
in C <<

 No you don't. You weren't around when Wolfgang figured out a way to do 
this,which was right under our noses. There is a system service to 
rename a process. So, at the top of your procedure, just call the proc 
Rename: Here's some code for you.

 -------------------------------------------
 Proc Rename:
 local n$(10),ret%
 local ax%,bx%,cx%,dx%,is%,di%
 bx%=call($0088)    /* or your pid if you have it already */
 n$="MonthVu"+chr$(0)
 di%=uadd(addr(n$),1)
 ax%=$0c00
 ret%=os($88,addr(ax%))
 if ret% and $1
         giprint err$((ax% and $ff)-256)
         pause 30
 endif
 Endp
 ------------------------------------------

  -Mark Esposito



Using Virtual Access
http://www.ashmount.com/va


==========
psion/opl #2981, from bpechey, 147 chars, Aug 1 17:39 96
Comment to 2980.
----------
The URLs you want are as follows:

http://www.kfs.org:80/~clive/psion/psionics/

ftp://ftp.CityScape.co.uk/pub/psion/dev/psionics/

Bill.


==========
psion/opl #2983, from gbainbridge, 402 chars, Aug 9 1:46 96
----------
TITLE: Currency Character
Just a quick question, if anyone knows the answer.

In order to make an application I'm currently writing a bit neater, is 
there any way in OPL of finding out the currency character (i.e.  or $ or 
otherwise) set in 'Number formats' in the system screen.

                         thanks,
                                 Gary.
                                 


==========
psion/opl #2984, from mcockerell, 240 chars, Aug 9 10:21 96
Comment to 2983.
----------
You can use an OS call to access the country data structure, which 
includes the currency character and position - I don't have the details 
with me but could look them out over the weekend if you're still waiting.

Martin Cockerell


==========
psion/opl #2986, from mcockerell, 2051 chars, Aug 10 11:21 96
Comment to 2984.
----------
This extract from the Psionics files should give you what you need:

Fn $8B Sub $05
GenGetCountryData
    BX: 40 byte buffer
Fills the buffer with country-specific data:
  Offset  0 (word): country code (e.g. UK is 44) of locale
  Offset  2 (word): current offset from GMT in minutes (+ is ahead)
  Offset  4 (byte): date format (0 = MDY, 1 = DMY, 2 = YMD)
  Offset  5 (byte): time format (0 = am-pm, 1 = 24 hour)
  Offset  6 (byte): currency symbol position (0 = before, 1 = after)
  Offset  7 (byte): currency symbol separated with space (0 = yes, 1 = no)
  Offset  8 (byte): currency decimal places
  Offset  9 (byte): currency negative format (0 = minus, 1 = brackets)
  Offset 10 (byte): currency triad threshold
  Offset 11 (byte): triad separator
  Offset 12 (byte): decimal separator
  Offset 13 (byte): date separator
  Offset 14 (byte): time separator
  Offset 15 to  23: currency symbol (cstr)
  Offset 24 (byte): start of week (0 = Mon, 1 = Tue, ... 6 = Sun)
  Offset 25 (byte): currently active summer times:
    Bit 0:       home
    Bit 1:       European
    Bit 2:       Northern
    Bit 3:       Southern
    Bits 4 to 7: unused, always zero
  Offset 26 (byte): clock type (0 = analogue, 1 = digital)
  Offset 27 (byte): number of letters in day abbreviation (0 to 6)
  Offset 28 (byte): number of letters in month abbreviation (0 to 255)
  Offset 29 (byte): workdays (the set bits indicate the workdays)
    Bit 0: Monday
    Bit 1: Tuesday
    Bit 2: Wednesday
    Bit 3: Thursday
    Bit 4: Friday
    Bit 5: Saturday
    Bit 6: Sunday
    Bit 7: always zero
  Offset 30 (byte): units (0 = inches, 1 = centimetres)

If the triad threshold is non-zero and there are more than that number of
digits in the integer part of an amount of money, then the triad character
should be inserted between groups of 3 digits. See ConvFloatToBuffer for a
way to do this.


The following code will fill the buffer for you:

LOCAL buff$(40)
CALL($058B,ADDR(buff$))

Hope this helps,

Martin


==========
psion/opl #2987, from gbainbridge, 854 chars, Aug 10 11:41 96
Comment to 2984.
----------
>You can use an OS call to access the country data structure, which 
>includes the currency character and position

Thanks, with some experimentation I've mamaged to work it out. For 
anyone else who needs it, here is my (rather crude) routine:-

PROC curc$:
local a%,b%,c%,d%,e%,f%,c$($28)
local char$(10),in%
b%=addr(c$)
REM OS call gengetcountrydata
call($058b,b%,0,0,0,0)
char$=mid$(c$,15,8)
in%=1
do
    in%=in%+1
until mid$(char$,in%,1)=chr$(0)
char$=left$(char$,in%-1)
if mid$(c$,6,1)=chr$(0)
    front%=1
endif
if mid$(c$,7,1)=chr$(0) and front%=1
    char$=char$+" "
elseif mid$(c$,7,1)=chr$(0) and front%=0
    char$=" "+char$
endif
return char$
ENDP

Note that front% is an external global variable so that the calling 
routine can find out whether the currency string needs to go before
or after the number.


==========
psion/opl #2996, from hzk, 1142 chars, Aug 17 17:47 96
Comment to 2994.
----------
Try the following.  This is all good stuff, I haven't had a crash yet, 
but messing about with this sort of thing can be unpredictable if you get 
it wrong!  As Jezar would say, don't do it.

This code sets the file DEMO.OPL to modified, and clears hidden, system 
and read only.

PROC main:
        LOCAL file$(128),ztfile$(130)
        LOCAL ret%,cx%,di%
        file$="LOC::M:\OPL\DEMO.OPL"
        cx%=32+4+2+1   REM change all 4 attributes
        di%=32+1       REM set Modified, clear other 3
        ztfile$=file$+CHR$(0)
        ret%=CALL($0987,UADD(ADDR(ztfile$),1),cx%,0,0,di%)
        IF ret%
                PRINT ERR$(ERR)
                PAUSE 20
        ENDIF
ENDP

REM  Attribute     Value
REM  ---------     -----
REM  ReadOnly        1
REM  Hidden          2
REM  System          4
REM  Modified        32

REM  Starting with cx% and di% set to zero:
REM  To change an attribute, add its value to cx%
REM  To set it, add its value to di%, except ReadOnly where
REM    adding 1 to di% will CLEAR this attribute
REM  To leave an attribute as it is, do NOT add it to cx% or di%

Roger


==========
psion/opl #2998, from gbainbridge, 728 chars, Aug 18 23:15 96
Comment to 2997.
----------
I don't know if it helps, but in my comms prog, STLINK, I used a routine 
which called itself if it found a directory.

Something like (in Pseudo OPL):-

PROC delete_dir:(directory_name$)
local a%,b%,file_name$(256,128)

do
    file_name$(a%)=getdir$:(directory_name$)
    a%=a%+1
until getdir$:(directory_name$)=""

do
    if entry_is_file:(file_name$(b%))
        erase (file_name$(b%))
    else
        delete_dir:(file_name$(b%))
    endif
    b%=b%+1
until b%=a%
END

I can't give you the actual code as there is much more to it, and it was 
written to run on the computer connected to the Psion, not on the Psion 
itself.

       Hope that helps,
       
                       Gary.

==========
psion/opl #3002, from hzk, 1410 chars, Aug 20 23:38 96
Comment to 3000.
----------
OK, here's a bit of 3T.  Once again, take care with the CALL()

PROC fdata:(path$,name$)
        LOCAL zts$(130),att$(20)
        LOCAL e%,off%(6)
        REM keep the next line as shown, the CALL() dumps data in all the 
vars.
        LOCAL ver%,att%,size&,date&,dunno&
        LOCAL yr%,mo%,dy%,hr%,mn%,sc%,yrday%
        zts$=path$+name$+chr$(0)
        e%=CALL($887,ADDR(zts$)+1,ADDR(ver%),0,0,0)
        REM error check goes here......
        SECSTODATE date&,yr%,mo%,dy%,hr%,mn%,sc%,yrday%
        LOCK ON
        dINIT name$
        dTEXT "Size",gen$(size&,6)
        dTEXT "Date",add0$:(dy%)+"-"+add0$:(mo%)+"-"+GEN$(yr%,4)
        dTEXT "Time",add0$:(hr%)+":"+add0$:(mn%)+":"+add0$:(sc%)
        att$=""
        IF att% AND $20
                att$=att$+"mod "
        ENDIF
        IF att% AND $4
                att$=att$+"sys "
        ENDIF
        IF att% AND $2
                att$=att$+"hid "
        ENDIF
        IF (att% AND $1)=0
                att$=att$+"rdo "
        ENDIF
        IF att$=""
                att$="none!"
        ENDIF
        dTEXT "Attributes",att$,$200
        dIALOG
        LOCK OFF
ENDP

I think the mask for the 'dir' attribute is $10.  I don't think that you 
can change it with the other bit of code, but I've never tried.
The function 'add0$:' just adds leading zeros to the date and time if 
necessary.

Roger


==========
psion/opl #3004, from dpalmer, 566 chars, Aug 21 13:59 96
Comment to 2998.
----------
> PROC delete_dir:(directory_name$)
> local a%,b%,file_name$(256,128)

It should be possible to do recursive directory deletion without 
storing the sub-directories, since the algorithm is depth-first. 
Something along the following lines:

proc zapdir:(dir$)
local sub$(128)
do
  sub$=find_subdirectory_of:(dir$)
  if sub$=""
    break
  endif
  zapdir:(dir$+"\"+sub$)
until 0
delete_all_files_in:(dir$)
rmdir dir$
endp

Where the parameter and local variable contain all the state 
information required throughout the recursions.

David.

==========
psion/opl #3022, from hzk, 2612 chars, Aug 24 14:35 96
Comment to 3004.
----------
Just for interest, this is my test code.  It pauses at each subdirectory found - you 
have to press ENTER to remove that sub, or ESC to Abort.  A dialog pops up if it 
can't delete something, and then it finds its way down to Main:

PROC main:
        LOCAL rd$(128)
        DINIT "Remove Directory Tree"
        dFILE rd$,"",4
        dIALOG
        PRINT "Remove directory tree:",rd$
        PRINT "Press Enter to continue, Esc to abort."
        IF zapdir%:(rd$)
                PRINT "Aborted."
        ELSE
                PRINT "Done"
        ENDIF
        GET
ENDP

PROC zapdir%:(folder$)
        LOCAL sub$(128)
        DO
                sub$=findir$:(folder$)
                IF sub$=""
                        BREAK             REM Exit loop when no files left
                ENDIF
                IF zapdir%:(sub$+"\")     REM If a flag was received
                        RETURN 1          REM Pass it down
                ENDIF
        UNTIL 0
        PRINT "Remove files and directory:",LEFT$(folder$,LEN(folder$)-1)
        IF GET=13
                IF DIR$(folder$)<>""   REM Check there are files to delete
                        TRAP DELETE folder$+"*.*" REM Delete  them
                ENDIF
                IF ERR                    REM If a file won't delete
                        LOCK ON
                        dINIT"Error"
                        dTEXT"","Cannot delete file in:",2
                        dTEXT"",folder$,2
                        dTEXT"",ERR$(ERR),2
                        dTEXT "","Aborting Delete",$2
                        dIALOG
                        LOCK OFF
                        RETURN 1                REM set flag
                ENDIF
                RMDIR LEFT$(folder$,LEN(folder$)-1)
        ELSE
                RETURN 1                  REM If stopped, return flag
        ENDIF
ENDP

PROC findir$:(in$)      REM function to read directory
        LOCAL file$(128)
        file$=DIR$(in$)
        DO
                IF isdir:(file$)        REM is it a dir?
                        RETURN file$    REM Yes
                ELSE
                        file$=DIR$("")  REM No, get next file
                ENDIF
        UNTIL 0
ENDP

PROC isdir:(test$)      REM function to check if a file or dir.
        LOCAL h%
        IF IOOPEN(h%, test$+"\*.*", $30)        REM Open directory call
                REM It fails, therefore it is a file
        ELSE
                REM it is a dir
                IOCLOSE(h%)
                RETURN 1
        ENDIF
ENDP


Roger


==========
psion/opl #3017, from csljohns, 276 chars, Aug 23 20:17 96
----------
Any C++ programmers here
Hi
I am having a bash at converting a C routine to OPL - (eek!)

Can anyone tell me what on earth

b = 0x00000001 & (tblidx >> 5) ;
big += (b << 4);

does?

I mean == and >= I could follow, but >> and += are a mystery
Thanks.

csljohns

==========
psion/opl #3018, from pmaud, 1234 chars, Aug 23 23:13 96
Comment to 3017.
----------
Ok the code is selecting bits from binary integer numbers. The operators 
are standard C as against this new fangled C++ stuff.

>> is the shift binary number right operator

So, 4 >> 1 becomes 2
 funnily 5 >> 1 also becomes 2
    16 >> 2 becomes 4

M >> N is equivalent to M/(2**N)
where 

<< is the shift binary number left operator

1 << 1 becomes 2 
M << N is equivalent to M * 2**N

The '&' is a bit wise AND operator;

The += is the "add value to" operator So X += Y
can be rewritten as X = X + Y

> b = 0x00000001 & (tblidx >> 5) ;

So, tblidx >> 5 shifts the variable right 5 bit positions.
The 0x00000001 & ... ANDs out everything except the lowest
bit. Storing the result 0 or 1 in the variable 'b'.

In effect the programmer has selected bit 5, the fifth bit from tblidx 
and assigned one or zero to the variable b depending on the state of this 
bit. Now 2**5 is 32 so, in opl speak the above becomes

b% = 1 AND (tblidx% / 32)

> big += (b << 4);

not  M << N is M * 2**N, so b << 4 becomes b * 2**4 = b * 16
so opl we get

big% = big% + b%*16


Probably you could recode it more efficiently by checking the bit 
directly:

IF tblidx% AND &20
    big% = big% + &10
ENDIF



==========
psion/opl #3025, from shastings, 396 chars, Aug 25 19:47 96
----------
Help with testing for DIR
Can anybody help, I need to test if a directory exists, if it doesn't 
then create it, if it does then simply go on to the next stage of the 
program.
What I've tried is;

IF NOT EXIST ("M:\ROL")
MKDIR "M:\ROL"
ENDIF

This makes the directory if it isn't there.
But if it is there it returns the error message : "file already exists"

Can anybody help ?


==========
psion/opl #3035, from millar, 288 chars, Aug 28 16:57 96
Comment to 3025.
----------
> IF NOT EXIST ("M:\ROL")
> MKDIR "M:\ROL"
> ENDIF

The EXIST keyword appends .OPD to any file unless it's specfified, try 
this:

IF NOT EXIST("M:\ROL.")
                    ^  (specifes no extension)
                    
Matt

Thanks to Jezar@Psion for working this out.

==========
psion/opl #3050, from hzk, 299 chars, Sep 2 7:15 96
Comment to 3048.
----------
There are other instances where you need the dot on a file with no extension.
Like DELETE.  So if you:

file$ = DIR$("")
DELETE file$

It won't work if your file has no extension!

But COPY does work without a dot:

file$ = DIR$("")
COPY file$,dest$

Correct me if I'm wrong!
Roger

==========
psion/opl #3054, from jezar, 934 chars, Sep 4 0:52 96
Comment to 3050.
----------
Technically speaking, (from the filesystems viewpoint)
you *always* need the extension for the file (if one exists).

However, in many circumstances, OPL automatically adds .ODB to the
filename if no extension is present using the same system call that
PARSE$() uses. It's a feature of PARSE$ - a deliberate one I guess -
(purplesoft would know for sure) that putting a dot at the end of 
the primary filespec for parsing means "no extension".

OPL automatically does the parsing in of .ODB for convenience
in circumstances where you're most likely to be using .ODB files.
In other circumstances (DELETE probably being one of them), the .ODB
extension is not automatically added.

Exactly what the criterea is for this I'm not sure. I doubt that a list
exists as to which keywords OPL does filename parsing on, and which ones 
it doesn't. I'd be the first to admit that it is a little confusing.

Regards,
Jezar  

==========
psion/opl #3043, from hshieff, 356 chars, Aug 30 15:39 96
----------
Calculating variable sizes in bytes
I am loading data-base records onto the HEAP in OPL.

The record is made up of fields of different variable types of variable 
lengths (strings, long integers, integers).

How can my program find out the lengths of these variables, in bytes, 
so that I can pre-allocate the correct amount of space. 


Dave


==========
psion/opl #3046, from dpalmer, 467 chars, Aug 31 12:43 96
Comment to 3043.
----------
Presumably you are reading the data into a pseudo-structure, e.g.

local first%, astring$(23), biggy&, total,  [...] lastone, omega%;

In which case the size of the struct is 
usub(addr(omega%),addr(first%)) where the 'omega%' variable is an 
dummy add-on for this purpose.

If you need to calculate the sizes of the various OPL data types 
manually, I have somewhere a text file detailing these - arrays and 
strings are the only tricky ones.

David.



==========
psion/opl #3053, from hshieff, 582 chars, Sep 3 21:30 96
Comment to 3046.
----------
"local first%, astring$(23), biggy&, total,  [...] lastone, omega%;

... the size of the struct is 
usub(addr(omega%),addr(first%)) where the 'omega%' variable is an 
dummy add-on for this purpose."

Are you GUARANTEED that the variables will be placed one after the other 
in memory? I have read something about fragmentation, which I don't 
really understand, but it relates to fitting data into 64K memory 
segments.

I am also reading in strings of unknown lengths from a data file. Can the 
program find out the size of these strings?

Cheers,

        Dave

==========
psion/opl #3055, from jezar, 2679 chars, Sep 4 0:52 96
Comment to 3053.
----------

OPL *does* guarantee that variables declared one after another in memory 
will be in contiguous storage (okay, I admit it's probably not documented 
anywhere - but I can assure you that this will always be the case).

But beware that some variable declarations are not quite as they seem.
For instance most people know that using ADDR() on string variables 
returns the address of an area of memory containing firstly a length 
byte, then the storage area for the string.

However, ADDR() cheats in the case of strings - in fact there is another 
byte - the one *before* the address that ADDR() returns - which contains 
the _maximum_length_ of the storage area - the length that the string was 
declared with (as opposed to the current length of the string).

In the case of declaring arrays, there is even more information tucked 
away before the address that ADDR() returns.

So in summary, declaring a bunch of variables which includes arrays 
and strings, might result in a memory layout different from what you 
might expect.

Regarding heap fragmentation, this is not a problem. OPL allocates a 
*single* heap cell for each procedure, which includes space not only for 
all the declared variables, but *also* the code for that procedure 
(strange but true). This is why the OPL manual mentions that turning on 
procedure caching might reveal bugs in your program which you were 
unaware of before (trashing of the procedures Q-code by overwriting past 
your variable declarations).

With regard to reading data files (I presume you mean OPL data files), 
you don't need to know how long the strings are in advance, because the 
OPL data file system always allocates enough space. You can find out the 
length of the string once it has been read by doing eg:

    L% = LEN(A.Thingy$)

If you then want to store this data in the heap somewhere then evidently 
you can just add up the amount of storage and POKE them in (although I 
don't know why you'd want to do this for OPL database files - you may as 
well use the file directly).

If on the other hand you are talking about a straight binary dump type of 
file, then it depends how the file was written. Without that knowledge 
it's impossible to give any guidance on how to find out the length of the 
strings - they could be terminated strings, LBC strings, or a straight 
dump of OPL strings including the maximum length byte (which would be 
what you'd get if you did a binary stream out of ordinary variable 
declarations). Apart from the hidden data in array and string 
declarations, the other data types have the length you'd expect.

Regards,
Jezar.

  

==========
psion/opl #3059, from argonaut, 348 chars, Sep 4 9:31 96
----------
TITLE: Scanning the Keyboard
I use the system call "call($288e,addr(scan%())) tons in the game i
am  writting. Its great and works in the main game loop
fantastically. However, when the game ends and you enter a hiscore,
the keyboard buffer is still full of the queued keystrokes.

So, how can I clear the keyboard buffer?

Cheers,

Nic

==========
psion/opl #3060, from dpalmer, 76 chars, Sep 4 10:56 96
Comment to 3059.
----------
> So, how can I clear the keyboard buffer?

while key :endwh

David.


==========
psion/opl #3122, from mkinga, 799 chars, Sep 23 19:54 96
----------
Help/Advice wanted :-

I would like to write an APP that basicly does the following :-

1) When started, does some "Stuff" to an .dbf file.
2) Then AUTOMATICLY starts the standard DATA app, and loads the above
modified .dbf file.
3) When the user EITHER saves the same file, or exits DATA, the
program does some more "Stuff" to the .dbf file and quits, but must
not affect any other .dbf files that the user may work on.

Bearing in mind this will be my first major program for the 3a
(Although I've written some pretty complex stuff in Basic in the past
:-), Is this possible, and how straight forward is it likely to be?
I can't find any reference to integrating with other apps in the
standard programming manual, so I assume it's a bit advanced for
that.

Cheers
Martin.
  

==========
psion/opl #3142, from gbainbridge, 984 chars, Sep 30 23:17 96
Comment to 3135.
----------
What you want to do shouldn't be too difficult. One of my programs creates 
a text file containing a heading, then opens the Word application to edit 
the rest of the document.
On quitting Word, control returns to my program.

This is the basic code I used:

PROC open:(file$)
local path$(128),comm$(128),hand%
local a%,b%,c%,d%,e%,f%
lock on
a%=$0100
if file$=""
return
else
path$="ROM::WORD.APP"+CHR$(0)
endif
b%=uadd(addr(path$),1)
comm$="O"+"Facsman"+chr$(0)+".MEM"+chr$(0)+file$+chr$(0)
c%=addr(comm$)
f%=addr(hand%)
os($87,addr(a%))
call($0688,hand%)
rem wait for return
wait::
do
getevent event%()
if (call($0288,hand%) and $00ff)=223
hand%=0
else
call($198d,0,hand%)
goto wait::
endif
until hand%=0
lock off
ENDP

I cribbed this code from an example in Palmtop.

In your case, path$ will be "ROM::DATA.APP"+chr$(0) to open the data 
application. How you 'do something with the data' is another problem!


                     Gary.

==========
psion/opl #3153, from hshieff, 479 chars, Oct 4 15:28 96
----------
Addressing Field Variables
Experts, can you help please.

The problem is that I am carrying out the same list of functions on 
different fields, and I currently must duplicate the code for each field 
(I have 25 fields to work on!)

I want a Procedure that can take a field variable as a parameter, so that 
the Procedure can alter the field variable.

How can I use database field variables other than by their actual name.

e.g. a.field1$  a.field2$

Dave

==========
psion/opl #3154, from dpalmer, 509 chars, Oct 5 11:42 96
Comment to 3153.
----------
> so that the Procedure can alter the field variable.

You cannot address a field variable, so you need something like:

  local temp$(255)
  local address%
  address%=addr(temp$)
  temp$=a.field1$ :myproc:(address%) :a.field1$=temp$
  temp$=a.field2$ :myproc:(address%) :a.field2$=temp$
  REM etc.
  
Which is better though still a bit grungy. myproc:() looks like:

  proc myproc:(a%)
  local result$(255)
  REM Calc result$ ...
  poke$ a%,result$
  endp
  
Hope this helps,

David.

==========
psion/opl #3164, from hshieff, 378 chars, Oct 7 18:3 96
Comment to 3154.
----------
oops
I've just checked my code again and realised this won't work. I didn't 
explain the problem properly.
Say I want to set up a procedure that sorts records by a field. I want to 
have: sort by field 1, or sort by field 2, etc. At the moment I still 
have to call each field by its name. For 25 fields this is going to be a 
hassle.

Is there a solution?


Dave


==========
psion/opl #3161, from rbenno, 289 chars, Oct 6 20:13 96
----------
Help files
Does anyone know how to make help files and how to call them 
from an OPA ! I have down loaded the Windows help file compiler 
from the file list but it does not seem to include any help 
itself.
Any pointers in the right direction would be appreciated.

TIA Richard.

==========
psion/opl #3165, from hzk, 918 chars, Oct 7 23:25 96
Comment to 3161.
----------
If you can generate a .RSC file using this Windows program, it is fairly easy to use 
from an OPL application.  The code below is extracted from such an application.  The 
first time you press "Help", call this procedure.  Any subsequent calls (in the same 
session) need only execute the SEND(gate%,26,#0,#0) line.

This came from a Psion based help compiler which I think was produced by Jezar.  It 
should be in Psion/files somewhere.

PROC help:
        LOCAL buf%(65),rsc$(22)
        rsc$="\app\pocpac\pp.rsc"
        IF EXIST("M:"+rsc$)
                rsc$="M:"+rsc$
        ELSEIF EXIST("A:"+rsc$)
                rsc$="A:"+rsc$
        ELSEIF EXIST("B:"+rsc$)
                rsc$="B:"+rsc$
        ELSE gIPRINT "No help available"
        ENDIF
        POKE$ ADDR(buf%(1)),"#"+rsc$
        gate%=PEEKW($38)
        SEND(gate%,27,buf%(2))
        SEND(gate%,26,#1,#1)
ENDP

Roger


==========
psion/opl #3166, from phillr, 159 chars, Oct 7 23:38 96
----------
Psion 3C
Can anyone tell me the most reliable way of determining
whether a program is running on a 3a or a 3c ?


Phillr

http://www.positioning.co.uk

==========
psion/opl #3168, from salex, 263 chars, Oct 8 10:33 96
Comment to 3166.
----------
Here is a way I found....

wid%=gWIDTH
IF wid%=480
 machtyp%=1                 REM S3a
 IF EXIST("ROM::sys$irda.img")
  machtyp%=3                REM S3c
 ENDIF
ELSEIF wid%=240
 machtyp%=2                 REM Sienna
ENDIF

David (Via ReadCIX 4.9)
 

==========
psion/opl #3170, from phillr, 301 chars, Oct 8 10:58 96
Comment to 3168.
----------
This is the OS command that I found....


    Ver%=(OS(200,100))+3577 
    
    if Ver%=0                          
    psion$="3A"                        
    elseif Ver%=63                     
    psion$="3C"                         
    Endif  

Phillr

http://www.positioning.co.uk


==========
psion/opl #3176, from psipple, 243 chars, Oct 10 0:12 96
----------
How to tell when a hotkey's pressed
Using testevent, is it possible to tell when an application button, such 
as Time is pressed?

I'd like one of my apps to deal with being multitasked out of. Anyone 
able to help?

Thanks,

Pete

==========
psion/opl #3178, from ple, 462 chars, Oct 10 13:9 96
Comment to 3176.
----------
If you are using GETEVENT to trap all types of event then I think you 
just need to test for a background message $402.

e.g.

LOCAL a%(6)
 GETEVENT a%()
 IF a%(1) = $402
   REM process or just sulk because we are
   REM being sent off into the background
 ELSEIF a%(1) = $404
   REM quit or change files event
 ENDIF

$401 is sent when a program comes into the foreground and $403 is a 
machine switch on event.

Hope this helps, Leigh
PLE


==========
psion/opl #3183, from psipple, 255 chars, Oct 11 23:23 96
Comment to 3178.
----------
Many thanks for this info - I'll give it a try over the weekend. Sounds 
like it'll do the trick nicely!

Thanks again,

Pete


Pete's Homepage: http://ourworld.compuserve.com/homepages/psipple
Palmtop Magazine: http://members.aol.com/palmtop




==========
psion/opl #3177, from rick, 986 chars, Oct 10 12:1 96
Comment to 3175.
----------
Getting a programs icon as a bitmap from an OPA

I'll dig it out. [later...]

I forget what the CALL does, but its very important! 

PROC LoadIcon:(id%)
  REM Load this applications icon to Bitmap id%
  LOCAL offset%
  LOCAL bit%

  offset% = PicOff%:
  IF offset%
    gAT 20,20
    CALL ($5f8d,1,offset%,0,0,0)
    bit%=gLOADBIT(CMD$(1),0,1)  REM Load plane 1
    IF bit%
      gUSE id%
      gGREY 1
      gCOPY bit%,0,0,48,48,3
      gCLOSE bit%
      CALL($5f8d,1,offset%,0,0,0)
      bit%=gLOADBIT(CMD$(1),0,0)        REM Load plane 0
      IF bit%
        gUSE id%
        gGREY 0
        gCOPY bit%,0,0,48,48,3
        gCLOSE bit%
      ENDIF
    ENDIF
  ENDIF
ENDP


PROC PicOff%:
  REM Gets offset of PIC icon resource within OPA file
  LOCAL ret%, h%, offset&
  ret%=IOOPEN(h%,CMD$(1),$600)
  IF ret%=0
    offset&=$14
    IOSEEK(h%,1,offset&)
    IOREAD(h%,ADDR(offset&),1)
    offset&=offset&+2
    IOSEEK(h%,3,offset&)
    IOCLOSE(h%)
    RETURN INT(offset&)
  ENDIF
ENDP




==========
psion/opl #3184, from rbenno, 591 chars, Oct 12 9:15 96
Comment to 3177.
----------
Another method of storing pic files in an opo or opa is to write 
the data as an array ie. b&(1)=&DC434950 :b&(2)=&13030 
b&(3)=&40E6C7 ect. 
To show the pic you create a temporary file in M:, iowrite this 
data to the file, gLOADBIT the bitmap and then delete the file.
There is no need to assign values to array elements that equal 
zero, so this method can actually save space if the picture 
contains a lot of white space.

This is how I produced the various icons and other pics in my 
file manager program Infowin which is in the file list.

Hope this helps

Richard.


==========
psion/opl #3189, from mharrisona, 339 chars, Oct 13 15:57 96
Comment to 3188.
----------
Steve, the syntax for LINT is

C:\ODE\OPLLINT.EXE XXX.OPL -rSSS -imc -tmcwa

Where XXX.OPL is your main module and SSS is the name of the start 
procedure for the program.
So for a module called MY.OPL starting with procedure init you would use:

C:\ODE\OPLLINT.EXE MY.OPL -rinit -imc -tmcwa

Regards, Mike. (Psion VAR)

