     Subj:  Programming the PSION HC         Section: Psion Programming
       To:  Paul Knott, 100673,1763          01 October 1996 20:22:00
     From:  Cade Roux (New Orleans), 73733,1014#247683

     Paul,
     >> Have anyone experiences in developing DYLs for the PSION HC 120 and
     the PSION Workabout ? <<

     Yes, for the HC.

     >1. Programming DYLs
     >----------------------------
     >1.1. The Code in DYLs may not introduce static variables by using
     quoted strings in C. Who can
     >I work with quotes strings (for example TIM:) nevertheless ?

     The following code fragment shows how Psion does it:

     LOCAL_C VOID xGetSignature(
     /*
     Copy "BlockerFile****" into given buffer.
     */
         TEXT *pName)
         {

         *((UWORD *)pName)='B'+('l'<<8);
         *((UWORD *)(pName+2))='o'+('c'<<8);
         *((UWORD *)(pName+4))='k'+('e'<<8);
         *((UWORD *)(pName+6))='r'+('F'<<8);
         *((UWORD *)(pName+8))='i'+('l'<<8);
         *((UWORD *)(pName+10))='e'+('*'<<8);
         *((UWORD *)(pName+12))='*'+('*'<<8);
         *((UWORD *)(pName+14))='*';
         }

     This is copying the characters into the buffer a WORD at a time - for
     efficiency.  There are other ways like:

     buffer[0] = 'T' ;
     buffer[1] = 'I' ;
     buffer[2] = 'M' ;
     buffer[3] = ':' ;
     buffer[4] = 0 ;


     >1.2. Is it possible to programm in C (without programming in PSION
     Object Oriented) ?

     Sure,

     >1.3. Can I call DYL-functions directly (without p_send()) and without
     Classes ?

     Not without p_send, but you can create utility classes and use the
     DatAppX reserved statics to get at them (don't use DatApp7 if you use
     ISAM.DYL - that's used by ISAM.DYL): e.g.

     TEMP.CAT:

     CLASS util root
     {
       ADD menu
       ADD etc

     }

     TEMPO.C

     METHOD INT util_menu(PR_UTIL *self, ...) {
       // Do stuff
     }

     TEMPSHEL.C

     GLDEF_C INT lib_init(VOID) {
       // load and link the DYL here
       // Create one global gateway to your class of utility functions - 
       // This is analogous to a namespace or class with no data members in C++
       DatApp1 = f_newlib...
     }

     GLDEF_C INT menu(
       return(p_entersendX(DatApp1, O_MENU, ...)) ;
     }

     Then link TEMPSHEL.C into your IMGs, and 

     >2. Overcoming the 64k code segment limit ?
     >-----------------------------------------------------
     >2.1. Is it better to use DYLs than splitting our big Image in some
     small Images ?

     It depends if your application can be split conveniently.  In our case,
     our applications use both techniques.

     When the DYL is linked in, it takes up the memory - but it is shared. 
     If the IMGs are all running at the same time, then the code in the DYL
     (which you removed from the IMGs) is then saved for every IMG after the
     first one which used to have it statically linked.  If your IMGs are
     never running at the same time, then there is no savings by using a DYL.

     >3. Programming the PSION HC 120
     >-------------------------------------------
     >3.1. Exists a compareable library (like HWIF) for the HC ?

     Not that I know of.  I guess HC/Workabout cross-platform development has
     to cater for the lowest common denominator, the HC.  We currently
     develop for the HC only, we're waiting to see what problems the
     Workabout may have.

     Cade

     Subj:  Creating Application Pwd         Section: Psion Programming
       To:  John Van Osdel, 70423,2334       06 October 1996 21:34:26
     From:  Chris Hennings, 100010,511       #248859

     >I need to create an application level password.  I must be encrypted in
     some way to protect against >unauthorized use do to the nature of the
     data.

     If it's the *data* that's sensitive then perhaps you should consider
     file (or even record) level protection rather than application level. So
     the "File open" command (or whatever) requests a password that is used
     to decrypt streams of data read from persistant store and similarly to
     encrypt on data write. Depending on context/risk you should also
     consider appropriate handling for in-memory buffers or screen displays
     that may contain plain-texts - particularly in relation to
     foreground/background events. 

     Bruce Schneier's Applied Cryptography 2nd Ed. : protocols, algorithms
     and source code in C - ISBN 0-471-11709-9 (John Wiley & Sons) is a
     truely fine book.

     Rgds
     Chris
     
     Subj:  No system Memory msg             Section: Psion Programming
       To:  Rolf Aeschbacher, 100116,3357    15 October 1996 08:08:16
     From:  Ali Manson [Psion], 73733,32     #250978

     >I think I'll have to contact the author of Spy then!

     Rolf

     Spy was written in-house by Psion and the source is supplied with the
     SDK. The source of the code to compress all heaps is, essentally:

     LOCAL_C VOID CompressAllHeaps(VOID)
         {
         p_sgcreate("t$t$",0x7FFF,E_SEGMENT_HIGH);
         }
     All the best
     Ali


     Subj:  Time Conversion Help             Section: Psion Programming
       To:  Peter Briggs, 106226,27          16 October 1996 17:46:23
     From:  Jochen Siegenthaler, 100127,3167 #251383

     << What do I need to do so I end up with hours, minutes & seconds.  >>

     You need a MOD (modulo) function - there was none supplied in OPL, so I
     wrote my own...

      PROC MOD%:(a%,b%)
             REM Returns the remainder of a%/b%
             REM same as Qbasic MOD function
             RETURN a%-(a%/b%)*b%
      ENDP

     Thus to convert 188 seconds to minutes & seconds you do...

      minutes%=INT(188/60) REM ignores anything after decimal point
      seconds%=MOD%:(188,60) REM returns just remainder

     minutes% then equals 3, and seconds% equals 8.

     You can combine this of course to get hours/minutes/seconds as you wish.
      --
      Jochen @ Zurich, Switzerland
      Written on 16/10/96 at 20:05
      This email was made from 100% recycled electrons.


     Subj:  What is Psion OOP?               Section: Psion Programming
       To:  Andrew  Robinson, 100432,1504    17 October 1996 18:35:21
     From:  Andrew Clarkson, 100661,2440     #251686

     <<I'm trying to figure out some good ways to write programs,
     and the snippets on Psion OOP are hard to figure out.

     Is it a style of C programming?  or can it be used from OPL?
     If so, where do I find out about it?>>

             OOP = Object Oriented Programming

     OOP involves using objects. An object has a set of properties (which are
     like variables) associated with it, along with a number of methods or
     functions which you can use with it. There are various languages
     designed for OOP, such as C++ and the new Psion OVAL language (which is
     essentially Visual Basic).

     Many of the applications and libraries built into the Psion ROM are
     written in C using an OOP style invented at Psion. If you want to write
     Psion applications which are compact and efficient you need to be
     looking at using the Psion OOP style with the Psion C SDK.

     The OOP you can do in OPL is very limited without facilities such as
     being able to create your own object classes. What you can do however,
     is to access the existing objects and methods in the Psion ROM
     libraries. To do this from OPL you need to use the OPL commands such as
     FINDLIB, NEWOBJH, SEND,...

     The general steps to creating and using objects with OPP and the include
     files supplied with OPP are:

     1. Get a handle to the library which contains the object using
     FINDLIB().

     2. Create a new object using NEWOBJH() and an OPP #define. Look at the
     OPP include files in the \OPP\INCLUDE\OO\ directory to find the object
     category handles which you need to use to create an object of a given
     type. These are the #defines which begin C_.

     3. Initialise the object using a SEND() and an O_*_INIT type #define.

     4. Send some messages to the object using a SEND() type call and a
     method number. You can get the method numbers from the \OPP\INCLUDE\OO\
     include files. The method numbers are the #defines which begin O_.

     5. Destroy the object using a SEND() call and the O_DESTROY method.

     The following shows how to create a VAFLAT object. This is an object
     with behaviour suitable for storing an array of fixed width data and
     which can grow in size as required...

             #include <oo\varray>

             PROC newva%:(width%, size%)

                     local h%, r%

                     /* get a handle to the library */
                     r% = FINDLIB(h%, "OLIB.DYL")
                     if r%<>0 :raise r% :endif

                     /* make a new VAFLAT object */
                     o%=newobjh(h%,C_VAFLAT)


                     if r%=0 :raise -10 :endif

                     /* send a message to object to initialise it */
                     r%=entersend0(o%,O_VA_INIT,#width%,#size%)

                     return o%

             ENDP

     ...you can then populate the VAFLAT object with data using the
     O_VA_APPEND method.

     To use OOP you need to know:

             what libraries are available,
             what objects they contain,
             how to use those objects,
             the category handles and method numbers,
             etc...

     All of this information is in the Psion C SDK. There is also some
     publically available information on OOP in the oodoc file, which is one
     of the chapters from the Psion SDK in MS Word format.

     Regards,
     Andy

     Subj:  Machine Type Flag                Section: Psion Programming
       To:  Cade Roux (New Orleans), 73733,101419 October 1996 17:49:21
     From:  Konstantin Saliy, 106062,203     #252111

     Cade,

     <<#define WS_TYPE_HCA 0x50 // Interesting! (Workabout?)
       No, but don't remember what exactly

     <<#define WS_TYPE_S3C 0x60 // Interesting! (S3c?)>>
      Just Workabout

     << I am curious as to what the S3c returns. >>

     The same as 3a, unfortunately.

      Regards
      Konstantin @ MOCKBA 19/10/96 19:07


     Subj:  Machine Type Flag                Section: Psion Programming
       To:  Programmers                      19 October 1996 00:40:22
     From:  Cade Roux (New Orleans), 73733,1014#251904

     I finally got PsiWin 1.1 and the fabled flug cable.  So I put Solipeg on
     my brother's Siena to try it out (the code already uses screen size
     dynamically, and the graphics actually fit on the Siena screen quite
     nicely - unlike Klondike!).  Of course, it didn't work, because I had
     the following code to warn S3 Classic users that this version of Solipeg
     no longer runs on the Classic:

     // This version will not run on S3 Classic, so put up an error message
         if ( (wserv_channel->conn.info.version_id & WS_TYPE_MASK) != WS_TYPE_S3A ) {
             p_exit(hErrorDialog(E_GEN_NSUP, RS_INCOMPAT)) ;
         }

     Turns out on the Siena, that wserv_channel->conn.info.version_id is
     0x72, so I modified the code to:

         // This version will not run on S3 Classic, so put up an error message
         if ( (wserv_channel->conn.info.version_id & WS_TYPE_MASK) != WS_TYPE_S3A &&
              (wserv_channel->conn.info.version_id & WS_TYPE_MASK) != WS_TYPE_SIENA ) {
             p_exit(hErrorDialog(E_GEN_NSUP, RS_INCOMPAT)) ;
         }

     And I added a suitable line to wlib.h:

     #define WS_TYPE_MASK 0xF0
     #define WS_VERSION_MASK 0x0F
     #define WS_TYPE_MC 0x00
     #define WS_TYPE_S3 0x10
     #define WS_TYPE_HC 0x20
     #define WS_TYPE_MCA 0x30 // Interesting! (MCWord?)
     #define WS_TYPE_S3A 0x40
     #define WS_TYPE_HCA 0x50 // Interesting! (Workabout?)
     #define WS_TYPE_S3C 0x60 // Interesting! (S3c?)
     #define WS_TYPE_SIENA 0x70 // I just added this one
     #define WS_VERSION_2 0x00
     #define WS_VERSION_3 0x01
     #define WS_VERSION_3_5 0x02
     #define WS_VERSION_4 0x02

     But I also found some other interesting material in the header, as you
     can see above.

     I am curious as to what the S3c returns.  I think it returns 0x42 like
     the 3a, but I'm not sure...

     Wasn't there some interim update to the headers for the S3c and Siena
     that Ali uploaded?  I can't find it in the library.

     Cade


     Subj:  Time Conversion Help             Section: Psion Programming
       To:  Peter Briggs, 106226,27          20 October 1996 22:46:02
     From:  John Van Osdel, 70423,2334       #252396

     Peter,
     Here is a proc from an OPL applcation I am working on.  You need to
     first convert your minutes to seconds or modify this proc accordingly. 
     Hope this helps.

     Example
     -----------
     PROC sec2tim$:(seconds&)
             rem convert seconds to time
             local hours&,mins&,x$(2)
             If seconds&>3600
                     hours&=Int(seconds&/3600)
             endif
             mins&=Int(seconds&-(hours&*3600))/60

             If hours&=0 : hours&=12 : x$="AM"
             elseif hours&<12 : x$="AM"
             elseif hours&=12 : x$="PM"
             elseif hours&<24 : hours&=hours&-12 : x$="PM"
             elseif hours&=24 : hours&=12 : x$="AM"
             endif

             if mins&=0
                 return gen$(hours&,2)+":"+"00"+x$
             elseif mins&<10
                 return gen$(hours&,2)+":"+"0"+gen$(mins&,2)+x$
         else
                 return gen$(hours&,2)+":"+gen$(mins&,2)+x$
             endif
     ENDP
     John

     Subj:  WSPCX and grey ?                 Section: Psion Programming
       To:  Rousseaux Jean Clau, 100346,2740 25 October 1996 07:59:05
     From:  Roger Hayman, 100240,260         #253550

     Rousseaux,
     The only way to get good grayscale tones, in my opinion, is to use my
     process for hayman tones.

     Here is some information:

     <<The solution to displaying continuous-tone photographs on your Series
     3a--Hayman tones

     I can convert your photos for use on the Series 3a and adjust the
     contrast, etc, for US$7/UK~4.50 for the first image in the batch and
     US$4.5/UK~3 for every subsequent image (minimum order is two images). I
     can accept images in most file formats including colour images and
     Casio's CAM format but they must be zipped. I can also scan images but
     there may be an extra charge. 

     Download the file PHOTOS3A.ZIP from Library 18 for samples of the
     process. I will shortly upload a  file of converted photos from the
     Casio QV-10 digital camera.

     Payment should be sent by cheque in any major currency for the
     equivalent amount to me at:

          3 Mallam Street
          Karori
          Wellington
          New Zealand

     When sending files please make it clear whether you want the whole file
     converted or just an area which matches the S3a's screen (480x160
     pixels). It does not matter what resolution you scan at so long as the
     desired object/s are within the area you want displayed on the S3a (if
     you want the whole image processed) or within the screen size of 480x160
     pixels. It is best to have large objects as the S3a's screen resolution
     is approx 100dpi.

     Hayman tones can be displayed by all drawing programs which use the gray
     plane. Steve Litchfield's SLIDE program allows you to create slide shows
     with or without sound and text to display your photos. With SLIDE you
     can create separate photo albums of your family and products/work. I
     will upload a file shortly showing what you can do with SLIDE.>>

     Please let me know if you require any further information.
     Roger Hayman

     Subj:  Macros                           Section: Psion Programming
       To:  Chris Nicholson, 100522,2324     28 October 1996 16:51:08
     From:  Wolfgang Schirmer(Sysop), 100022,1371#254526

     Chris,
     << I don't quite understand ? Could you give an example to clarify? >>

     sorry for being so encrypted.

     As far as I understood you're opening a data file in the macro you're
     writing.  To open this file you normally use a statement like this:

     open "myfile.dbf",a,f1$,f2$

     for Macsys you have to use

     open "myfile.dbf",d,f1$,f2$.

     because Macsys is using a,b, and in some cases also c a the logical
     file descriptor.

     Let me know if you need more help for your macro.
     Best wishes Wolfgang@Hamburg

     Subj:  Soft Resets                      Section: Psion Programming
       To:  Tony Denson, 100034,1643         28 October 1996 10:00:01
     From:  Konstantin Saliy, 106062,203     #254404

     Tony,
     << I have a program which is randomly causing soft resets of my Psion.
      It is fairly complex in that it's using the SMS SDK >>

     I assume it's your program and you want to fix it.
     Soft resets are usually caused by writing outside process' data segment
     or stack corruption. The former it possible by passing an invalid
     pointer to a system call, driver, DYL. Although OS is clever enough to
     check pointers, driver or DYL usually are not.

     Stack can be corrupted usually by passing a pointer to a local
     variable/buffer to a function.

     Possible sources of invalid pointers:
       1. Memory was not allocated or a call to allocate memory was
          unsuccessful and no check is implemented
       2. Size of allocated buffer is les than required
       3. Local variable was passed as status word to asynch i/o, and it
          became out of scope at the time of writing to it.
       4. Local buffer has a size less than required (stack corruption)

     It is hard to imagine all cases. You'd better check all pointers you
     pass to operating system calls, drivers, DYLs. If hardware level is
     implemented as LDD or DYL in the SMS SDK, check pointers you pass to
     them first.

      Regards
      Konstantin @ MOCKBA 28/10/96 14:14

     Subj:  Date manipulation                Section: Psion Programming
       To:  peter bennett, 100025,1165       03 November 1996 14:13:04
     From:  Chris Hennings, 100010,511       #255801

     I assume you're talking OPL, there are direct C functions for this. If
     so something like the below might be a bit less brute force.

     Rgds
     Chris

     PROC da2dt$:(di&)
         local y%,m%,d%
         y%=1900+int(di&/365)
         while days(1,1,y%)>di&
             y%=y%-1
         endwh
         while days(1,1,(y%+1))<=di&
             y%=y%+1
         endwh
         m%=12
         while days(1,m%,y%)>di&
             m%=m%-1
         endwh
         d%=di&-days(1,m%,y%)+1
         return gen$(d%,-2)+"/"+gen$(m%,-2)+"/"+gen$(y%,-4)
     ENDP


     Subj:  need help for psion 3a           Section: Psion Programming
       To:  Don Hinds, 76004,612             06 November 1996 06:53:11
     From:  Mark H J Fitzpatric, 100026,2452 #256400

     Don,
             Sorry, but the last thing I remembered was that you'd let me
     know if you wanted the code. Anyway here is an example. It happens to
     read the ICON from itself (the CMD$(1) argument to IcnOfst%). You can
     easily modify it to ask for a "From" file and a "To" file.  Hope it
     helps.

     Regards,
     Mark :~)
     @Sydney, Australia.

     >>>
     APP JWALK
             TYPE $1000
             ICON "JWALK.PIC"
     ENDA

     Proc main:
             local   offset%, id%
             offset%=IcnOfst%:(CMD$(1))          Rem Find offset of PIC's in APP
             if offset%>0
                     id%=IcnLoad%:(CMD$(1),offset%,0)   Rem Extract ICON #0
                     gUse id%
                     gSaveBit "M:\PIC\TEMP.PIC"
                     Busy "Saved M:\PIC\TEMP.PIC"
                     Get
                     Busy off
                     gClose id%
             endif
     Endp

     Proc IcnLoad%:(file$,offset%,p%)
             local idb%,idg%,idp%,w%,h%

             call ($5f8d,1,offset%,0,0,0)   Rem Set PIC Offset (You have to do this each time before calling gLoadBit)
             idb% = gLoadBit(file$,0,p%)    Rem Load Black Plane of PIC
             call ($5f8d,1,offset%,0,0,0)   Rem Set PIC Offset (You have to do this each time before calling gLoadBit)
             idg% = gloadbit(file$,0,p%+1)  Rem Load Grey Plan of PIC
             w%=gwidth
             h%=gheight
             idp%=gcreate(0,0,w%,h%,1,1)
             ggrey 0
             gcopy idb%,0,0,w%,h%,3
             ggrey 1
             gcopy idg%,0,0,w%,h%,3
             gclose idb%
             gclose idg%
             return idp%
     Endp

     PROC IcnOfst%:(appFile$)
             local picb%(500)
             local ih%, a%, l%, r%
             r%=ioopen(ih%,appFile$,$0400)   Rem Open APP for READ


             if r%<0
                     return r%       Rem Open Failed. Reason=r%
             endif
             r%=ioread(ih%,addr(picb%()),700) Rem read 700 bytes
             if r%<0
                     ioclose(ih%)
                     return r%       Rem Read Failed. Reason=r%
             endif
             ioclose(ih%)    Rem close OPA
             a%=addr(picb%())
             l%=uadd(a%,700)
             Rem Walk the buffer looking for "PIC$DC"
             do
                     a%=UADD(a%,1)
             until ((peekb(a%)=%P) and (peekb(uadd(a%,1))=%I) and (peekb(UADD(a%,2))=%C) and (peekb(uadd(a%,3))=$DC)) or (a% > l%)
             if a% > l%
                     rem Something went wrong. We didn't find a PIC in the file
                     return -1
             endif
             return USUB(a%,addr(picb%()))   Rem Return the offset in the file that we found the start of the PIC part at.
     ENDP
     <<<


     Subj:  3Fax via OPL                     Section: Psion Programming
       To:  Steve Beadle, 100443,3046        11 November 1996 19:19:06
     From:  Konstantin Saliy, 106062,203     #257802

     Steve,
     << like it to be able to use the 3fax, but the IOW (pronounced ow!)
     functions return 'device does not exist' >>

     I'm afraid you need to load C:\IMG\SYS$A550.PDD before (although never
     tried it). This is a device driver which allows Psion built-in serial
     driver to work with 3Fax hardware.

     Don't forget to unload it on exit.

      Regards
      Konstantin @ MOCKBA 12/11/96 03:07


     Subj:  Backlight bug                    Section: Psion Programming
       To:  All                              14 November 1996 19:11:09
     From:  Mark Esposito (SYSOP), 72662,3050#258495

     All,
         Here's an explanation of the backlight bug I found just last night.
     (One of those late night programming extravaganzas.<G>)

         First, to reproduce the bug, Press Psion-o from the system screen,
     (assuming you have a S3c with backlight), and type in 20 minutes for the
     switch off time. Press Enter, and come back into the dialog. First you
     will notice that it's now set to 02:36, and secondly if you try to turn
     the backlight on or off you'll find it no longer works. (Not to worry -
     type in a number below 17min, 03 seconds, and it will work again.

         I think I've got this right. I am in the process of writing a new
     app that controls the backlight in a better way. I ran into the
     following problems, and was surprised to find the S3c had the same
     problem.

         Backlight auto switch off is controlled by three system services.

         $8e - hardware manager

         $20 - hwBackLight        - reads on/off status
         $1e - hwGetBackLight     - gets state of hardware
         $1f - hwSetBackLight     - set state


         There are actually two bugs in Psion's dialog for auto switch off.
     First, note that the number sent to hwSetBackLight is (seconds * 32), or
     in 1/32 of a second increments. So, if you're setting the backlight
     control to 10 minutes, you would send (10 * 60 * 32). Also, note that if
     the MSB (top bit 16) is set, this disables the backlight. (according to
     the SDK, and proven true in this situation)

         The number is evidently saved as a signed short int.

         Bug 1:  The dialog allows for a number greater than 32767, which is
     fine. (kind of) However, when reading in the stored number, the dialog
     doesn't add 65536 to get the correct number for display, and thus
     displays the wrong number for auto switch off.

         Bug 2:  When using a number above 32767, it sets the top bit (16)
     which disables the backlight.

      Why is 17 min, 03 seconds the max?

      ((17min * 60 * 32) + (3 seconds * 32) =32640)  Adding one more second
     brings it to
      32768, which sets to top bit on, disabling the backlight.

       -Mark Esposito


     Subj:  Type 3 OPAs                      Section: Psion Programming
       To:  All                              18 November 1996 17:12:10
     From:  peter bennett, 100025,1165       #259283

     Probably a dumb question, but if I want my OPL program to operate on my
     normal data files, and I set it up as a type 3 OPA (so my DBF files are
     listed under the icon), what code do I have in the program to make it
     start operating on the file my cursor was on when I invoked the OPA? Can
     anyone help with this please?

     Subj:  Type 3 OPAs                      Section: Psion Programming
       To:  peter bennett, 100025,1165       18 November 1996 19:41:12
     From:  John Boyce (Sysop), 100014,1240  #259314

     Peter
     The filename you  wish to launch is returned in CMD$(2) so that is all
     you need to use to get the filename. You will also have to intercept
     CMD$(3) which will return "O" for opening a file and "C" for creating a
     file.

     The way I do it is something like...

         GETEVENT event%()
         IF event%(1)=$404 or event%(2)=$401
             IF CMD$(3)="C"
                 create:(CMD$(2))
             ELSEIF CMD$(3)="O"
                 open:(CMD$(2))
             ENDIF
         ENDIF

     This is very simplified but should give you an idea of how to go about
     it.

     Best wishes
     John

     Subj:  Directories                      Section: Psion Programming
       To:  Konstantin Saliy, 106062,203     21 November 1996 13:31:06
     From:  Mark Esposito (SYSOP), 72662,3050#259936

     Konstantin,
         >> trap mkdir test$ will do what you want. <<

     The problem with this is that sometimes you need to search more than
     one disk for the file. Here's some code I just wrote to do it another
     way.

      Proc main:
      local dr$(3,2),i%

      dr$(1)="M:" :dr$(2)="A:" :dr$(3)="B:"
      i%=1
      do
         if chkpath:(dr$(i%)+"\note\expand\")    rem error
             i%=i%+1
         else
             dinit"Directory found on "+dr$(i%)
             dialog
             break
         endif
      until i%>3
      Endp

      Proc chkpath:(name$)
      local ax%,bx%,cx%,dx%,si%,di%
      local r%,n$(129)
      n$=name$+chr$(0)
      ax%=$0500
      bx%=uadd(addr(n$),1)
      if OS($87,addr(ax%)) and 1
         return (ax% and $ff) -$100
      endif
      Endp

       -Mark Esposito

     Subj:  C vs. OPL                        Section: Psion Programming
       To:  John Van Osdel, 70423,2334       22 November 1996 02:44:25
     From:  Bryan Scattergood, 104312,2206   #260076

     John,
           Some more partial answers.

     <<1. Speed of application execution.>>

     C is the only way to go for some compute-intensive jobs.  Not only can
     it make the response time practical in the extreme cases, but in the
     border-line cases (C takes 0.1 seconds against 1 second for OPL, say)
     there is an 'invisible' saving in terms of battery life.  Compute-time
     keeps the CPU busy and that uses more power.

     <<2. Size of "compiled" application modules.>>

     C binaries are typically larger.  But C has features like structs and
     separate compilation which help to keep large programs tractable.  And
     using HWIM means you can leverage a lot of the existing ROM-based code.

     <<3. Resource requirements of the application.>>

     You can use DYLs to get the functionality of overlays in C.  This does
     need OO-stuff though and only seems to be effective with apps which have
     a good OO architecture.  Ports of existing programs just can't make
     effective use of DYLs in this way.  OPL handles the code much more
     effectively.

     <<1.With the C SDK, is there any "development" environment in which to
     develop (i.e. editor, compiler) or does one use an editor and standard
     ANSI C compiler of choice?>>

     You have to use the supplied JPI C compiler.  The IDE that comes with it
     is a pretty good DOS-based IDE, especially considering it hasn't been
     updated since about 1990.  (Wordstar key sequences, multiple files,
     single key project rebuild.)  You can use another editor and drive the
     compiler without the IDE if you want to.

     <<2. With previous "Object Oriented" experience in languages such as
     PowerBuilder, how dificult is it to pick up on the Object Oriented
     features of the 3a environment (Isn't this the HWIM "stuff")?>>

     HWIM is indeed the OO-stuff.  The basic object-model and library is
     actually a beautiful piece of design.  It can take a while to appreciate
     this though, since it is well hidden by Psion's OO dialect of C.

     If you can handle writing things like

         p_send5(w_ws, O_WS_DEFINE_FNBAR, MY_DIAMOND_LIST, 0, 0);

     to request that the window server load and display a diamond list, where
     using C++ you might expect

         w_ws->define_fnbar(MY_DIAMOND_LIST, 0, NULL);

     then HWIM is fine.  You also lose any type-checking of arguments to
     methods: this can involve extreme defensive programming.

     <<3. Getting to many of the functionalities (i.e. HWIM style editbox,
     Dialing interface and preferences, etc) is difficult at best.  Does C
     and the 3a environment provide a means of more readily accessing such
     features/functionality? >>

     There are some things which are only really sensible using HWIM.  The
     'Bring' functionality and dynamically-updating dialogs are typical
     examples.  They are still not trivial, but they are far easier than the
     hoops OPL programmers seem to need to go through.  I am constantly
     amazed at the lengths some OPL programmers will go to, just to implement
     these sorts of features.

     All IMHO, of course.  It's basically a question of picking the right
     tool for the job.  OPL for quick one-off jobs.  C and HWIF where OPL
     would need system calls.  C and HWIM for production software.  (And OVAL
     when hell freezes over :-)
     Bryan

     Subj:  C vs. OPL                        Section: Psion Programming
       To:  John Van Osdel, 70423,2334       21 November 1996 23:06:20
     From:  Cade Roux (New Orleans), 73733,1014#260055

      >> 1. Speed of application execution.

     C is much faster for anything compute intensive.  C is faster for highly
     modular code (lots of functions called in loops especially), since OPL
     does swap out functions.  C is faster for some I/O (like serial comms)
     simply because the interface to the ROM is thinner.

      >> 2. Size of "compiled" application modules.

     C larger in general, but if you use OLIB or other classes from the ROM
     wisely, you won't have to build many common subsystems like linked lists
     etc.

      >> 3. Resource requirements of the application.  Does either C or OPL
     require more system resources, all things equal? 

     It is possible in HWIM to use redraw windows, which reduces the screen
     memory requirements by half, since the window server does not need to
     maintain a backup bitmap of the screen.

     Mark is correct about memory usage.  This is a speed/size tradeoff. 
     However, with a little bit of work, you can simulate OPL's automatic
     loading and unloading of procedures by using DYLs for part of your
     program which are transient or even optional or uncommon for particular
     customers...  Each DYL is loaded completely into memory, but you can
     combine multiple DYLs into a larger collection of DYLs.  I've seen this
     technique used by Psion's applications.

      >> 1.With the C SDK, is there any "development" environment in which to
     develop (i.e. editor, compiler) or does one use an editor and standard
     ANSI C compiler of choice?

     The C SDK REQUIRES TopSpeed C.  TopSpeed C includes an integrated
     development environment, but I don't know anyone who uses it.  At work,
     I use Multi-Edit 6.0 for DOS and TopSpeed command-line tools.  The C SDK
     also includes an indispensible debugger.  I used to use a similar set up
     at home, but Multi-Edit 7.0 repeatedly crashes when running TopSpeed
     command-line tools.  At home, I use Multi-Edit 7.1 for Windows and it
     can call TopSpeed command-line tools and even copy the files down
     serially or to an external SSD drive (still not working good on my
     system under Win95, though).  In addition, the excellent DS3aExpl
     extensions to Explorer allow you to drag and drop files in a natural
     Explorer way, rather than the PsiWin FileMangler way.  Basically, Win95
     has really done wonders for my Psion development at home...

      >> 2. With previous "Object Oriented" experience in languages such as
     PowerBuilder, how dificult is it to pick up on the Object Oriented
     features of the 3a environment (Isn't this the HWIM "stuff")?

     Psion OO stuff does not hide anything.  Unless you already understand OO
     principles AND have some good ideas of how they are implemented in the
     underlying compiler in e.g. C++, Smalltalk or Java, you will have quite
     a bit of difficulty.  I have a Pascal, C++, C, Psion-C, C++ background
     (in that order), so I had already moved closer to the metal before I
     started with Psion-C.  Having said that, it's better than assembler ;-)

      >> 3. Getting to many of the functionalities (i.e. HWIM style editbox,
     Dialing interface and preferences, etc) is difficult at best.  Does C
     and the 3a environment provide a means of more readily accessing such
     features/functionality?

     'Easiest' with HWIM, but then you have the HWIM learning curve...

     Cade

     Subj:  C vs. OPL                        Section: Psion Programming
       To:  John Van Osdel, 70423,2334       21 November 1996 13:31:13
     From:  Mark Esposito (SYSOP), 72662,3050#259937

     John,
      I can answer some of your questions.

         >> 1. Speed of application execution.

     Depends on the application. An application that is noticably slow will
     be faster usually in C. What I mean by this is that if the application
     has enough complexity to notice it being slow, it will probably be
     faster in C. I have programs though that don't matter. I'm about to
     release Sleeper, a utility that messes with the backlighting. It
     wouldn't make a difference having it in C.

         >> 2. Size of "compiled" application modules. <<

      I'm not too sure on this. If you're OPL program has lots of code trying
     to rewrite what is easily accessible in C, I suppose the C code would be
     smaller.

         >> 3. Resource requirements of the application.  Does either C or
     OPL require more system resources, all things equal? <<

      C programs tend to use more system memory, especially if they have a
     large code segment. In C, the code is all loaded into memory, where OPL
     loads a procedure list, and doesn't load it into memory until called.

      For example, look at Psion Money vs Banker. Money uses 100k, Banker
     uses 45-50k. If you could write a database program in OPL, (even using
     ISAM), I think you could do it without using more than 50k, but in C it
     would take 100k. (JBdata, Dataview) In this case, OPL has a definate
     advantage over C, especially if you're writing an application for
     consumers that want to keep enough memory free to multitask many
     applications.

     -Mark Esposito

     Subj:  C vs. OPL                        Section: Psion Programming
       To:  All                              21 November 1996 00:54:10
     From:  John Van Osdel, 70423,2334       #259809

     I am interesting in getting feedback on the pros/cons of using C vs. OPL
     for development of apps for the 3a/3c machine.  Given a fairly
     complicated application written in both languages, how would the
     compare.

     1. Speed of application execution.
     2. Size of "compiled" application modules.
     3. Resource requirements of the application.  Does either C or OPL
     require more system resources, all things equal?

     Also, several other questions related to the C development environment. 

     1.With the C SDK, is there any "development" environment in which to
     develop (i.e. editor, compiler) or does one use an editor and standard
     ANSI C compiler of choice?

     2. With previous "Object Oriented" experience in languages such as
     PowerBuilder, how dificult is it to pick up on the Object Oriented
     features of the 3a environment (Isn't this the HWIM "stuff")?

     3. Getting to many of the functionalities (i.e. HWIM style editbox,
     Dialing interface and preferences, etc) is difficult at best.  Does C
     and the 3a environment provide a means of more readily accessing such
     features/functionality?

     Thanks,
     John Van Osdel
     Psion Developer Partner

     Subj:  IO Commands                      Section: Psion Programming
       To:  Q, 100271,2150                   20 November 1996 08:35:05
     From:  Wolfgang Schirmer(Sysop), 100022,1371#259639

     Quentin,
     <<  h%=ioopen(h%,addr(s$),mode%) return h%  >>
     my suggestion is:
     x%=ioopen(h%,addr(s$),mode%) return h%
     you don't have to return x% in this case, because it doesn't hold the
     handle.

     Best wishes
     Wolfgang@Hamburg

     Subj:  IO Commands                      Section: Psion Programming
       To:  Q, 100271,2150                   20 November 1996 08:35:15
     From:  John Boyce (Sysop), 100014,1240  #259640

     Quentin
     >> using h% as the IOOPEN and the return value, return the same handle
     >> address.

     The line:

        ret%=IOOPEN(h%,<filename>,$101)

     should give ret% equal to zero if there was no failure or a negative
     figure relating to the error if there was one, and the channel
     identification will be returned in h% (assuming that OPL uses p_open()
     as its working model).

     I notice you are not checking if there is an error in opening the file -
     this would at least narrow down your problem if you did a check on
     handle% being less than zero. Remember that the IO commands in
     themselves do not deal with errors.

     Best wishes
     John

     Subj:  IO Commands                      Section: Psion Programming
       To:  Chris Hennings, 100010,511       20 November 1996 07:20:03
     From:  Q, 100271,2150                   #259624

     Hello Chris,

     > h%=ioopen(h%,addr(s$),mode%)
     > return h%

     >You're using h% for *both* the return value of the ioopen *and* the
     file handle. The >return value will overwrite the handle - so panic 25
     "Invalid I/O Channel" is unsurprising.

     >Use a separate variable for the return value and you might like to
     think about what to do >if it's non-zero indicating that the open has
     failed.

     I don't know if you remember this one, but I tried changing the h%, but
     it still panics at the IOWRITE command. Incidentally, I used various
     different variables to test the file handle, and using h% as the IOOPEN
     and the return value, return the same handle address.

     Any other ideas?
     Quentin

     Can anyone shed some light as to why this procedure always exits with a
     25 at the IOWRITE command?

     #include <l_file.oph>
     #include <l_err.oph>
     proc start:
      write:("Test")
     ENDP

     proc write:(txt$)
      local text$(128),pt%,handle%
      local buf%(128),pb%
      onerr end::
      handle%=io:("m:\app\lgbk3a\data\logbook.fil",1)
      text$=txt$
      pt%=uadd(addr(text$),1)    /* Address of text$ + 1 , skip length byte*/
      pb%=addr(buf%())           /* Address of a buffer */
      print pt%,pb%,text$,len(text$)
      get 
      call($a1,0,len(text$),0,pt%,pb%)    /* Copy buffer - text$ to buf%() */
      IOWRITE(handle%,pb%,len(text$))   /* Fails here exit 25! */
      print pb%,text$
      get
      closeio:(handle%)
      end::
      onerr off
      alert(err$(err))
     ENDP
     PROC io:(p1$,o%)
      local s$(128),mode%,h%
      s$=p1$
      if o%
          mode%=FCREATE OR FSTREAM or FUPDATE
      else
          mode%=FOPEN OR FSTREAM or FUPDATE
      endif
      h%=ioopen(h%,addr(s$),mode%)
      return h%
     ENDP
     proc closeio:(p1%)
      ioclose(p1%)
     ENDP

     Subj:  IO Commands                      Section: Psion Programming
       To:  Q, 100271,2150                   20 November 1996 20:00:20
     From:  Cade Roux (New Orleans), 73733,1014#259786

     >>  call($a1,0,len(text$),0,pt%,pb%)    /* Copy buffer - text$ to
     buf%() */ <<

     Any particular reason you're copying from a string to an integer array
     (an integer is twice as big as a single character) and then just writing
     it out to disk?  At most, only half the integer array will be used...

     Panic 25 can often be due to memory overwrites of your handle.  One
     thing to do (and not a very wise one, but I'm the first to admit that I
     do it myself to see what's going on) is to move the handle variable in
     the order of declaration (I do it in C, not OPL, but the point is still
     valid).

     This rearranges the memory alignment/assignment of the OPL variables. 
     The problem may go away.  This is WHEN YOU MUST BE CAREFUL.  ONLY THE
     SYMPTOMS HAVE GONE AWAY - YOU MAY STILL BE OVERWRITING SOME OTHER
     MEMORY.  I only yell this because it is VERY IMPORTANT.  You could move
     the variable and get a latent bug which will come back to bite you in
     the ass something fierce.

     Cade

     Subj:  Word code                        Section: Psion Programming
       To:  Jochen Siegenthaler, 100127,3167 22 November 1996 04:54:03
     From:  Chris Nicholson, 100522,2324     #260090

     A couple of months ago you were very kind and wrote a piece of code for
     me that would switch to Word and open a text file. You wrote it in such
     a way that it would also be possible to do the same thing with Sheet. I
     now have a use for the Sheet part but it does not appear to work and
     comes up with error "Process exited - Exit number 25".
     I have included a copy of the code as I am using it and would appreciate
     it if you could shed any light on the situation.

     Kind regards
     Chris Nicholson
     Hertford, UK at 09:41 am - Friday 22 November 1996

     proc sheet1:
             local f$(128),ret%,dia%,h%,i%,off&,x$(255),g%,d%,s%,mode%
             local pt1$(30)
             f$="M:\spr\*.spr"
             dinit "Create New Sheet File"
             dfile f$,"",1+8
             dia%=dialog
             if dia%=0
             return
             endif
             Busy "Exporting..."
             ret%=IOOPEN(h%,addr(f$),$302)
             if ret%<0
                     return 0
             endif
             f$="SPREADSHEET"
             i%=0
             do
                     f$=f$+CHR$(0)
                     i%=i%+1
             until i%=12
             off&=0
             ret%=IOSEEK(h%,2,off&)
             REM write header
             ret%=IOWRITE(h%,uadd(addr(f$),1),22)
             REM default col width
             f$=chr$(4)+chr$(0)+chr$(2)+chr$(0)+chr$(8)+chr$(0)
             ret%=IOWRITE(h%,uadd(addr(f$),1),len(f$))
             pt1$="SaleTrax Sheet File"
             x$=pt1$+datim$
             d%=1
             s%=1
             strinsh: (g%,x$,d%,s%)
             busy off
             giprint "Export Completed"
             IOCLOSE(h%)
             return h%
             rem mode%=3
             rem view: (f$,mode%)
     endp

     PROC strinsh:(h%,w$,c%,r%)      REM adds a string w$ to spreadsheet, 
                                     REM at column c%, row r%
             local f$(50),lw$(80),ret%
             lw$=w$
             f$=chr$(2)+chr$(0)+chr$(len(w$)+8)+chr$(0)+

     chr$(c%-1)+chr$(0)+chr$(r%-1)+chr$(0)
             f$=f$+chr$(10)+chr$(127)
             ret%=IOWRITE(h%,uadd(addr(f$),1),len(f$))
             ret%=IOWRITE(h%,addr(lw$),len(lw$)+1)
             f$=chr$(0)
             ret%=IOWRITE(h%,uadd(addr(f$),1),1)
     ENDP

     PROC View:(file$, Mode%)
             REM Analyses a file to see what type it is,
             REM then sets a command line for that app
             REM and launches it
             LOCAL pid%, ret%, cl$(128), off%(6)
             LOCAL als$(2), app$(6), n%
             REM Set off%() so we can get the extension
             REM of the file
             PARSE$(file$,file$,off%())

             REM if Mode%=1 launch Word
             REM if Mode%=2 launch Text editor
             REM if Mode%=3 launch Auto detect
             VECTOR Mode%
             Word::,Text::
             ENDV

             REM open file
             REM read in 16 bytes and close
             IOOPEN(pid%, file$, $0400)
             IOREAD(pid%,UADD(ADDR(cl$),1),16)
             IOCLOSE(pid%)
             POKEB ADDR(cl$),16


             REM A file descriptor is normally 15 bytes
             REM terminated in 0x00, except for sheet.
             REM So we must detect 0x00 within first 16
             REM bytes to assume it is a file desciptor,
             REM otherwise show as text file in Word
             REM use pid% as a flag to indicate
             REM non-text (True) or text (False)

             ONERR Text
             POKEB ADDR(cl$),LOC(cl$,CHR$(0))-1 :rem find 0x00

             IF cl$ = "SPREADSHEET"  REM Sheet (odd one out!)
                     app$="SH3"
             ELSEIF cl$ = "AgendaFileType*"  REM Agenda
                     app$="Agenda"
             ELSEIF cl$ = "PSIONWPDATAFILE"  REM Word
                     Word::
                     app$="Word"
                     als$=""
             ELSEIF cl$ = "OPLDatabaseFile"  REM Data
                     app$="Data"
             ELSEIF cl$ = "WorldFileType**"  REM World
                     app$="World"
             ELSEIF cl$ = "ALawSoundFile**"  REM Record
                     app$="Record"
             ELSEIF cl$ = "ScriptFileType*"  REM Comms
                     app$="Comms"
             ELSEIF cl$ = "OPLObjectFile**"  REM RunOPL
                     app$="RunOPL"
             ELSE

                     REM anything we can't detect show in Word
                     Text::
                     app$="Word"
                     als$=" $"
             ENDIF
     GIPRINT "Switching to "+app$
             ONERR ViewErr
             REM build the command line cl$
             REM     1st char is O=open or C=create
             REM     then Icon to go under
             REM     then File extension and alias
             REM             for Word: ""=word, "$"=text, "O"=OPL, "S"=script
             REM     then File to open
             REM don't forget the CHR$(0) after each section
             REM pid% will contain the handle for the app launch
             cl$ = "O" + app$ + CHR$(0) +
     MID$(file$,off%(5),LEN(file$)-off%(5)+1) + als$ + CHR$(0) + file$ + CHR$(0)
             ret%=runapp2%:("ROM::"+UPPER$(app$)+".APP", ADDR(cl$), ADDR(pid%))
             IF ret% :RAISE ret% :ENDIF
             RETURN


     ViewErr::
             ONERR OFF
             ShowErr:("Cannot view """ +
     Nice$:(MID$(file$,off%(4),LEN(file$)-off%(4)+1)) + """", ret%) 
     ENDP

     PROC RunApp2%:(appname$,cmdl%,ppid%)
             LOCAL ax%,bx%,cx%,dx%,si%,di%
             LOCAL ret%,flags%
             LOCAL img$(128)
             img$=appname$+CHR$(0)
             ax%=$0100          REM set AH = 1 for "FilExecute" call
             bx%=ADDR(img$)+1   REM set BX = pointer to application name
             cx%=cmdl%          REM set CX = pointer to length of command line
             di%=ppid%          REM set DI = ADDRess to take process id
             flags%=OS(135,ADDR(ax%))  REM call "FilExecute"
             IF (flags% AND 1)
                     ret%=(ax% AND $FF)-256  REM error returned from O/S call in AL
             ELSE
                     ax%=$0600        REM set AH = 6 for "ProcResume" call
                     bx%=peekw(ppid%) REM set BX = process id
                     flags%=OS(136,ADDR(ax%))  REM call "ProcResume"
                     IF (flags% AND 1)
                             ret%=(ax% AND $FF)-256 REM error returned from O/S call in AL
                     ELSE
                             ret%=0         REM return success
                     ENDIF
             ENDIF
             RETURN ret% 
     endp

     Subj:  Word code                        Section: Psion Programming
       To:  Chris Nicholson, 100522,2324     23 November 1996 05:51:24
     From:  Jochen Siegenthaler, 100127,3167 #260349

     << "Process exited - Exit number 25".  >>

     This is an error in one of the IO commands. It was caused because you
     were calling...
              strinsh: (g%,x$,d%,s%)
     ..where g% was supposed to be the file handle. However, g% was 0, and
     the handle is actually h%. The correct code is...
              strinsh: (h%,x$,d%,s%)
     ..after which it will work. I ran the code on my machine and the Sheet
     opened up beautifully.

     As a general note, you must ensure that you trap the errors from all
     IOxxxxx commands. I now do it like this...

         ChkRet%:(IOOPEN(etc....))

     ..and the ChkRet% PROC is...

      PROC ChkRet%:(ret%)
       IF ret%<0 :RAISE ret% :ENDIF
       RETURN ret%
      ENDP

     This will cause an error to be RAISEed if the IOxxxx returns an error
     value, otherwise it'll just RETURN whatever the IOxxxx returned. It
     saves writing lots of IF ret%<0 :RAISE ret% :ENDIF etc etc.

     You should also add error trapping: place a ONERR errtrap statement at
     the very start of the sheet1 procedure, and then add this code to the
     end of the sheet1 PROC code...

      (blah blah blah etc)
      RETURN REM ensures proc returns normally when no errors

      errtrap:: REM our error trap is here
       PRINT "Error in PROC sheet1:",ERR,ERR$(ERR) REM print error
       GET REM make sure we see it
       STOP REM stop program
      endp REM your existing endp is here

     ..and then you'll see all errors cleanly. Then you can add PRINT
     staements in the code to see how far it got before an error was raised.
     This is what I do for debugging, and it works well.

     You are using f$ to hold the filename, and then afterwards to hold other
     data. Be very careful sharing a variable like this. I would change the
     IOOPEN to...
             ChkRet%:(IOOPEN(h%,f$,$302))
     ..where f$ is the filename of the Sheet file.

     You can replace...
             f$="SPREADSHEET"
             i%=0
             do
                     f$=f$+CHR$(0)
                     i%=i%+1
             until i%=12
     ..with...

             f$="SPREADSHEET"+REPT$(CHR$(0),12)

     The IOSEEK after the above statement is not necessary: as the file is
     new, the size is 0, and the pointer is already at the end of the file. I
     deleted it as it makes no difference.

     Have fun!
      --
      http://ourworld.compuserve.com/homepages/Jochen_Siegenthaler
      @ Zurich, Switzerland on 23/11/96 11:37

     Subj:  Word code                        Section: Psion Programming
       To:  Jochen Siegenthaler, 100127,3167 23 November 1996 12:40:13
     From:  Chris Nicholson, 100522,2324     #260403

     Oh dear !!!
     I have made the changes that you suggested and it is still crashing with
     the error message "Exit process 25" ?? Unfortunately this type of
     programming is really beyond me, so I am being cheeky enough to ask if
     you could have another look for me <G> I have copied below the code as
     it looks now.

     Thanks very much for all your help.

     Kind regards
     Chris Nicholson
     Hertford, UK at 05:39 pm - Saturday 23 November 1996

     proc sheet1:
             local f$(128),ret%,dia%,h%,i%,off&,x$(255),d%,s%,mode%
             onerr errtrap
             f$="M:\spr\*.spr"
             dinit "Create New Sheet File"
             dfile f$,"",1+8
             dia%=dialog
             if dia%=0
             return
             endif
             Busy "Exporting..."
             chkret%:(IOOPEN(h%,f$,$302))
             f$="Spreadsheet"+rept$(chr$(0),12)
             off&=0
             ret%=IOSEEK(h%,2,off&)
             REM write header
             ret%=IOWRITE(h%,uadd(addr(f$),1),22)
             REM default col width
             f$=chr$(4)+chr$(0)+chr$(2)+chr$(0)+chr$(8)+chr$(0)
             ret%=IOWRITE(h%,uadd(addr(f$),1),len(f$))
             x$="Saletrax Sheet File"
             d%=1
             s%=1
             strinsh: (h%,x$,d%,s%)
             mode%=3
             view:(f$,mode%)
             return
             errtrap::
             print "Error in Proc Sheet1:",err,err$(err)
             get
             stop
     endp


     PROC strinsh:(h%,w$,c%,r%)      REM adds a string w$ to spreadsheet, 
                                     REM at column c%, row r%
             local fit$(50),lw$(80),ret%
             lw$=w$
             fit$=chr$(2)+chr$(0)+chr$(len(w$)+8)+chr$(0)+
     chr$(c%-1)+chr$(0)+chr$(r%-1)+chr$(0)
             fit$=fit$+chr$(10)+chr$(127)
             ret%=IOWRITE(h%,uadd(addr(fit$),1),len(fit$))


             ret%=IOWRITE(h%,addr(lw$),len(lw$)+1)
             fit$=chr$(0)
             ret%=IOWRITE(h%,uadd(addr(fit$),1),1)
     ENDP

     proc chkret%:(ret%)
             if ret%<0 :raise ret% :endif
             return ret%
     endp



     PROC View:(file$, Mode%)
             LOCAL pid%, ret%, cl$(128), off%(6)
             LOCAL als$(2), app$(6), n%
             PARSE$(file$,file$,off%())
             REM if Mode%=1 launch Word
             REM if Mode%=2 launch Text editor
             REM if Mode%=3 launch Auto detect
             VECTOR Mode%
             Word::,Text::
             ENDV
             REM open file
             REM read in 16 bytes and close
             IOOPEN(pid%, file$, $0400)
             IOREAD(pid%,UADD(ADDR(cl$),1),16)
             IOCLOSE(pid%)
             POKEB ADDR(cl$),16
             REM A file descriptor is normally 15 bytes
             REM terminated in 0x00, except for sheet.
             REM So we must detect 0x00 within first 16
             REM bytes to assume it is a file desciptor,
             REM otherwise show as text file in Word
             REM use pid% as a flag to indicate
             REM non-text (True) or text (False)
             ONERR Text
             POKEB ADDR(cl$),LOC(cl$,CHR$(0))-1 :rem find 0x00
             IF cl$ = "SPREADSHEET"  REM Sheet (odd one out!)
                     app$="SH3"
             ELSEIF cl$ = "AgendaFileType*"  REM Agenda
                     app$="Agenda"
             ELSEIF cl$ = "PSIONWPDATAFILE"  REM Word
                     Word::
                     app$="Word"
                     als$=""
             ELSEIF cl$ = "OPLDatabaseFile"  REM Data
                     app$="Data"
             ELSEIF cl$ = "WorldFileType**"  REM World
                     app$="World"
             ELSEIF cl$ = "ALawSoundFile**"  REM Record
                     app$="Record"
             ELSEIF cl$ = "ScriptFileType*"  REM Comms
                     app$="Comms"
             ELSEIF cl$ = "OPLObjectFile**"  REM RunOPL
                     app$="RunOPL"
             ELSE
                     REM anything we can't detect show in Word
                     Text::
                     app$="Word"
                     als$=" $"
             ENDIF
     GIPRINT "Switching to "+app$
             ONERR ViewErr
             REM build the command line cl$


             REM     1st char is O=open or C=create
             REM     then Icon to go under
             REM     then File extension and alias
             REM             for Word: ""=word, "$"=text, "O"=OPL, "S"=script
             REM     then File to open
             REM don't forget the CHR$(0) after each section
             REM pid% will contain the handle for the app launch
             cl$ = "O" + app$ + CHR$(0) + MID$(file$,off%(5),LEN(file$)-off%(5)+1) + als$ + CHR$(0) + file$ + CHR$(0)
             ret%=runapp2%:("ROM::"+UPPER$(app$)+".APP", ADDR(cl$), ADDR(pid%))
             IF ret% :RAISE ret% :ENDIF
             RETURN


     ViewErr::
             ONERR OFF
             ShowErr:("Cannot view """ +
     Nice$:(MID$(file$,off%(4),LEN(file$)-off%(4)+1)) + """", ret%) 
     ENDP


     PROC RunApp2%:(appname$,cmdl%,ppid%)
             LOCAL ax%,bx%,cx%,dx%,si%,di%
             LOCAL ret%,flags%
             LOCAL img$(128)
             img$=appname$+CHR$(0)
             ax%=$0100          REM set AH = 1 for "FilExecute" call
             bx%=ADDR(img$)+1   REM set BX = pointer to application name
             cx%=cmdl%          REM set CX = pointer to length of command line
             di%=ppid%          REM set DI = ADDRess to take process id
             flags%=OS(135,ADDR(ax%))  REM call "FilExecute"
             IF (flags% AND 1)
                     ret%=(ax% AND $FF)-256  REM error returned from O/S call in AL
             ELSE
                     ax%=$0600        REM set AH = 6 for "ProcResume" call
                     bx%=peekw(ppid%) REM set BX = process id
                     flags%=OS(136,ADDR(ax%))  REM call "ProcResume"
                     IF (flags% AND 1)
                             ret%=(ax% AND $FF)-256 REM error returned from O/S call in AL
                     ELSE
                             ret%=0         REM return success
                     ENDIF
             ENDIF
             RETURN ret% 
     endp

     Subj:  Word code                        Section: Psion Programming
       To:  Jochen Siegenthaler, 100127,3167 26 November 1996 07:33:02
     From:  Chris Nicholson, 100522,2324     #260996

     Solved it !!!
     After a lot of testing etc I have found the problem. The cause was where
     I called VIEW: from within the SHEET1: procedure. Once I separated them
     it worked perfectly (thats another lesson learnt).

     Thanks very much for all your help.

     Kind regards
     Chris Nicholson
     Hertford, UK at 12:33 pm - Tuesday 26 November 1996

     
     Subj:  No dialog help key               Section: Psion Programming
       To:  Jeff Siegel, 75344,1732          02 December 1996 14:32:17
     From:  Ali Manson [Psion], 73733,32     #262561

     Jeff
     If you need to present Help as a result of a dialog, you can use the
     following code. It's a bit of a kludge but it allows you to detect the
     fact that Help was used to complete the last dialog - you can then put
     up the help you need and, if necessary, redisplay the dialog. Code
     follows:

     #define O_GT_LAST_KEY  23

     /*  This method gets the last key processed by the system
         on behalf of the application  */

     PROC main:

             LOCAL   gate%  /*  Handle of the gate object  */
             LOCAL   c%  /*  Live variable fo rthe dCHOICE  */
             LOCAL   k%  /*  Variable to receive the key  */
             LOCAL   mods%  /*  Variable to receive modifiers  */
             LOCAL   pmods%  /*  Pointer to above  */

             dINIT "Test dialog"
             dCHOICE c%, "Choice", "No, Yes, Maybe"
             DIALOG  /*  Run the dialog  */

             gate% = PEEKW($38)  /*  Find the handle of the GATE object  */
             pmods% = ADDR(mods%)  /*  Point pmods% to the right place  */
             k% = ENTERSEND(gate%, O_GT_LAST_KEY, #pmods%)  /*  Send the message  */

             PRINT "Key was   =", k%
             PRINT "Mods were =", mods%
             GET

     ENDP

     The comments should be straightforward. The only other thing you need to
     know is that the modifiers written to 'pmods%' will be:

     2 for <Shift>
     4 for <Control>
     8 for <Psion>

     and these can be combined (i.e. <Psion><Shift><Help> will return 291 in
     k% and 10 in mods%)

     All the best
     Ali

     Subj:  No dialog help key               Section: Psion Programming
       To:  Jeff Siegel, 75344,1732          05 December 1996 13:56:11
     From:  Jochen Siegenthaler, 100127,3167 #263449

     <<         It occurs to me this still won't solve the problem of getting
     the word "HELP" to display on the button in the dialog.  >>

     Bit of an overkill anyway! The Help button on your Psion is nicely
     labelled and it is a simple matter to make it work on any DIALOG or
     MENU. I have example code if you wish...
      --
      http://ourworld.compuserve.com/homepages/Jochen_Siegenthaler
      @ Zurich, Switzerland on 05/12/96 19:33


     Subj:  Launch sheet from an.opa         Section: Psion Programming
       To:  Craig Penfold, 100715,1274       06 December 1996 15:11:14
     From:  Ali Manson [Psion], 73733,32     #263747

     Hello
     Try the following. I didn't write it and it is a little inelegant but
     you should be able to work it out from the code here

     All the best, Ali

     PROC menu:

                       /* --------------------------- */
                       /* Local Variable Declarations */ 
                       /* --------------------------- */

             local menu%             REM  variable hot key keypress returned to
             local ppid%             REM  process id which is handled by the OS
             local ret%              REM  variable errors returned to
             local cmdl$(128)        REM  full command line odf application
             local appn$(128)        REM  full apllication name

                       /* ---------------------------- */
                       /* Global Variable Declarations */ 
                       /* ---------------------------- */

             global linkon%          REM  variable to show LINK status

                       /* --------------------------- */
                       /*       Procedure Code        */
                       /* --------------------------- */

             DO
               gBORDER $200
               mINIT
               mCARD "Applications","Database",%d,"Word Processor",%w,"Agenda",%a,"Time",%t,"Calculator",%c,"Spreadsheet",%s
               mCARD "...","Finance",%f,"World",%g,"Biorhythm",%b
               mCARD "Games","Tetris",%e,"Chess",%h,"Invaders",%i
               mCARD "Link","On",%l,"Off",%o,"Run Script",%r
               mCARD "Special","Exit",%x
               menu%=MENU                                          

               IF menu%=%x                           REM  exit selected
                 STOP
               ELSEIF menu%=%l AND linkon%=0         REM  link selected
                 appn$="C:\IMG\Link.IMG"
                 cmdl$="-b9600"
                 ret%=runapp%:(appn$,cmdl$,addr(ppid%))
                 IF ret%=-62
                    GIPRINT "Remote link not plugged in"
                    PRINT chr$(7)
                    PAUSE 20
                  ELSEIF ret%=0
                    GIPRINT "Remote link running"
                    linkon%=1
                    PAUSE 20
                  ENDIF
               ELSEIF menu%=%l AND linkon%=1


                 GIPRINT "Remote link running"
                 PAUSE 20
               ELSEIF menu%=%o AND linkon%=1         REM  link off
                  ret%=appterm%:(ppid%)
                  IF ret%=0
                    GIPRINT "Remote link off"
                    linkon%=0
                  ELSEIF ret%=-62
                    GIPRINT "Remote link not plugged in"             
                    PRINT chr$(7)
                  ENDIF
               ELSEIF menu%=%o AND linkon%=0
                  GIPRINT "Remote link not on"
                  PAUSE 20
               ELSEIF menu%=%d                       REM  data selected
                 appn$="ROM::Data.APP"
                
                 cmdl$="OData"+CHR$(0)+".DBF"+CHR$(0)+"LOC::A:\DAT\BUSINESS.DBF"+CHR$(0)
                 ret%=runapp%:(appn$,cmdl$,addr(ppid%))
               ELSEIF menu%=%s                       REM  sheet selected
                 appn$="LOC::a:\APP\Sh3.APP"
                
                 cmdl$="OSh3"+CHR$(0)+".SPR"+CHR$(0)+"LOC::M:\SPR\SHEET.SPR"+CHR$(0)
                 ret%=runapp%:(appn$,cmdl$,addr(ppid%))
               ELSEIF menu%=%b                       REM  biorhythm OPA selected
                 appn$="ROM::SYS$PRGO.IMG"
                 cmdl$="OBiorythm"+CHR$(0)+CHR$(0)+CHR$(0)
                 cmdl$=cmdl$+"LOC::B:\APP\BIORYTHM.OPA"
                 ret%=runapp%:(appn$,cmdl$,addr(ppid%))              
               ELSEIF menu%=%f                       REM  bank OPA selected
                 appn$="ROM::SYS$PRGO.IMG"
                
                 cmdl$="OBank"+CHR$(0)+".ODB"+CHR$(0)+"LOC::M:\OPD\BND\FINS_3.BND"
                 cmdl$=cmdl$+CHR$(0)+"LOC::B:\APP\BANK.OPA"
                 ret%=runapp%:(appn$,cmdl$,addr(ppid%))              
               ELSEIF menu%=%e
                 appn$="LOC::A:\APP\Tetris.APP"      REM  tetris selected
                 cmdl$="OTetris"+CHR$(0)+CHR$(0)+CHR$(0)
                 cmdl$=cmdl$+"LOC::A:\APP\TETRIS.APP"
                 ret%=runapp%:(appn$,cmdl$,addr(ppid%))              
               ELSEIF menu%=%r                       REM  run script selected
                 appn$="LOC::C:\APP\COMMS.APP"
                
                 cmdl$="OComms"+CHR$(0)+".SCO"+CHR$(0)+"LOC::B:\SCO\PABX.SCO"+CHR$(0)
                 ret%=runapp%:(appn$,cmdl$,addr(ppid%))              
               ENDIF
             UNTIL 0
     ENDP

     /*
     -------------------------------------------------------------------------
     -
         Name        : RUNAPP%
      
     ------------------------------------------------------------------------     ----
         Description : Runs a named application.

         Parameters  : appname$ = full path name of application image file.
                       cmdline$ = command line to the application
                       ppid%    = pointer to integer to receive process id

         Returned    : zero for success, else -ve error number
         Conditions  : The file must exist and be a valid image.

         Effects     : None

         Errors      : File not found
                       Invalid file
         Panics      : None
      
     ------------------------------------------------------------------------     -- */

     PROC runapp%:(appname$,cmdline$,ppid%)

                       /* --------------------------- */
                       /* Local Variable Declarations */ 
                       /* --------------------------- */

       local ax%,bx%,cx%,dx%,si%,di%
       local ret%,flags%
       local cmdl$(128),img$(128)

                       /* --------------------------- */
                       /*       Procedure Code        */
                       /* --------------------------- */

       cmdl$=cmdline$+chr$(0)         REM must be zero terminated
       img$=appname$+chr$(0)

       REM -- first create the application --
       REM
       ax%=$0100                   REM set AH = 1 for "FilExecute" call
       bx%=addr(img$)+1            REM set BX = pointer to application name
       cx%=addr(cmdl$)             REM set CX = pointer to legth byte of command line
       di%=ppid%                   REM set DI = address to take process id
       flags%=os(135,addr(ax%))    REM call "FilExecute"
       if (flags% and 1)
         ret%=(ax% and $FF)-256    REM error returned from O/S call in AL
       else
         REM -- now run the created application --
         REM
         ax%=$0600                   REM set AH = 6 for "ProcResume" call
         bx%=peekw(ppid%)            REM set BX = process id
         flags%=os(136,addr(ax%))    REM call "ProcResume"
         if (flags% and 1)
           ret%=(ax% and $FF)-256    REM error returned from O/S call in AL
         else
           ret%=0                    REM return success
         endif
       endif
       return ret%
     ENDP

     /*
     --------------------------------------------------------------------------
         Name        : APPTERM%
     ------------------------------------------------------------------------     ----
         Description : Term an existing application.

         Parameters  : pid% = process id of appliction to term

         Returned    : zero for success, else -ve error number
         Conditions  : None
         Effects     : None

         Errors      : Process does not exist
         Panics      : None
      
     ------------------------------------------------------------------------     -- */

     PROC appterm%:(pid%)

                       /* --------------------------- */
                       /* Local Variable Declarations */ 
                       /* --------------------------- */

       local ax%,bx%,cx%,dx%,si%,di%
       local ret%,flags%

                       /* --------------------------- */
                       /*       Procedure Code        */
                       /* --------------------------- */

       ax%=$0D00                   :REM set AH = 8 set AH to 0D00 for ProcTerm
       bx%=pid%                    :REM set BX = process id
       flags%=os(136,addr(ax%))    :REM call "ProcTerm"
       if (flags% and 1)
         ret%=(ax% and $FF)-256    :REM error returned from O/S call in AL
       else
         ret%=0                    :REM signal success
       endif
       return ret%
     ENDP


     Subj:  OPL: serial interface            Section: Psion Programming
       To:  Klaus Mueller, 100754,1006       08 December 1996 11:10:00
     From:  Cade Roux (New Orleans), 73733,1014#264180

      >> I want to program a full duplex communication (2 way simultanious).

     Can anyone help? <<
     The routines you want to use are the IOA, IOWAIT etc. routines.  You
     want to open a channel to the TTY:A device, queue a read AND a write
     using IOA (and possible some other requests like a timer and a keyboard
     check), and then IOWAIT to see which completes.  The Psion O/S provides
     excellent support for non-blocking (asynchronous) I/O.  I've done a lot
     of it in C, but my OPL is very poor...

     IrDA is the same, the device is SIR:A, I think.  However, it is not
     currently documented, and I believe it implements only some lower levels
     of the IrDA protocol stack, so you may have to build some checking on
     top of SIR:.

     BTW the Series 3 range only has one TTY:A, but other Psion machines like
     the HC with suitable expansion ports can have e.g. on the HC TTY:A
     through TTY:I, where A-C are RS-232, D-F are TTL, G-I are inverted TTL.

     Cade

     Subj:  VAL in OPL                       Section: Psion Programming
       To:  All                              12 December 1996 07:58:24
     From:  Ian Ford, 101765,2712            #265249

     I'm working on a program where I use VAL on a string field in a
     database. The database file is generated from a tab separated file
     originating on a PC and I can't guarantee that the relevant string field
     will always contain a valid "numerical" string. eg it might be "" or
     possibly "1.oo".

     I think I can use error handling to deal with this but is there another
     way?

      Regards,
      Ian
      (United Kingdom)


     Subj:  VAL in OPL                       Section: Psion Programming
       To:  Ian Ford, 101765,2712            12 December 1996 21:33:03
     From:  Mark Esposito (SYSOP), 72662,3050#265508

     Ian,
         I use a simple proc to do it. There is no other way that I know of.

      Proc val:(n$)
      onerr z
      return val(n$)
      z::
      return 0    REM or bring up an error here
      Endp

      -Mark Esposito


     Subj:  More than Two BITMAPS...         Section: Psion Programming
       To:  ...                              14 December 1996 17:43:00
     From:  Bressy, 100726,776               #266007

     How can I record more than two bitmaps in a file (the OPL command
     "gSAVEBIT" can only record 2 btmaps).

                     Thanks for your help


     Subj:  More than Two BITMAPS...         Section: Psion Programming
       To:  Bressy, 100726,776               16 December 1996 22:53:30
     From:  Leigh Edwards (UK), 100533,1726  #266776

     You can't easily using OPL. You need a DOS utility program called
     wspcx.exe which will concatenate multiple bitmaps into one file. I don't 
     know whether it is in the libraries here or not. You can then load
     the one you want using the gLOADBIT(name$,write%,i%) command where i%
     loads the one you want ( starting at 0 for the 1st).

     Hope that helps - Leigh


     Subj:  World Data                       Section: Psion Programming
       To:  All                              16 December 1996 15:14:23
     From:  John Boyce (Sysop), 100014,1240  #266585

     Has anyone ever been able to get the WR_CALC data out of World (the
     stuff that shows sunrise and sunset)? There seems to be some errors in
     the file available with the information in (WLD.ZIP) as the
     Get_City_Data doesn't return the expected array (WR_CITY_DATA) but
     something that looks like CO_DIAL. I also have been unable to get the
     call to WR_CALC to work - it goes into an endless loop.

     It must be something I'm doing wrong but I've tried all the likely
     alternatives with no success (BTW, this is writing in OPL, not 'C').

     Thanks in advance for any help.
     Best wishes
     John  (United Kingdom)


     Subj:  World Data                       Section: Psion Programming
       To:  John Boyce (Sysop), 100014,1240  16 December 1996 16:53:11
     From:  John Boyce (Sysop), 100014,1240  #266618

     Further to my previous posting, I have confirmed that everything seems
     to work OK apart from the WR_CALC system - Get_City_Data does return the
     correct array (it was the way I looked at it that was flawed).

     So the only problem I have is trying to get WR_CALC to work - I've had a
     Psion running for 15 minutes now and it still doesn't say it has
     finished (and if I force a finish the data isn't there).

     Best wishes
     John  (United Kingdom)

     Subj:  World Data                       Section: Psion Programming
       To:  Ali Manson [Psion], 73733,32     19 December 1996 10:45:27
     From:  John Boyce (Sysop), 100014,1240  #267471

     Ali
     Konstantin has got to the bottom of the problem with the world data -
     after the first call to IOW you need to seed state% with the return
     value of IOW - doing this and everything works as it should.

     Thank you for your time.
     Best wishes
     John  (United Kingdom)


     Subj:  File Locking                     Section: Psion Programming
       To:  All                              21 December 1996 22:51:00
     From:  John Wojcik, 100041,1711         #268011

     Can anyone help me,
     I am writing a program in OPL (well.. its actually OPP). It accesses a
     lot of files which I access using IOOPEN,IOREAD and IOCLOSE. 
     If another application has the file locked my program gets a system
     error message and ends.
     I have tried wrapping ONERR code around these commands but it doesnt
     seem to have helped.
     Is this right ?... can this error not be trapped ?.. or did I just code
     my ONERR blocks wrong.
     If this error cannot be trapped is there some way I can check for a file
     being locked ?

     I hope someone can help
     Thanx 
     John  (United Kingdom)


     Subj:  File Locking                     Section: Psion Programming
       To:  John Wojcik, 100041,1711         22 December 1996 00:55:00
     From:  John Boyce (Sysop), 100014,1240  #268038

     John
     << I have tried wrapping ONERR code around these commands  >>

     With IO commands the error is returned by the command (e,g,
     ret%=IOOPEN(...  - check ret% for an error - a negative number) - you
     can't trap errors around the IO commands. To check if another program is
     using the file then check the ret% in IOOPEN - if it is less than zero
     then the file hasn't been opened - you can see what  the error is by
     using RAISE ret% .

     Best wishes
     John  (United Kingdom)


     Subj:  File Locking                     Section: Psion Programming
       To:  John Wojcik, 100041,1711         22 December 1996 05:47:12
     From:  Mark Esposito (SYSOP), 72662,3050#268070

     John,

     >>  If this error cannot be trapped is there some way I can check
     for a file being locked ? <<

     Your IO command should be returning the error. When you do IOOPEN(),
     are you getting the return value?

         ret%=IOOPEN()

     The value of ret% will give you the error, and not the ONERR statement.

     -Mark Esposito


     Subj:  File Locking                     Section: Psion Programming
       To:  John Wojcik, 100041,1711         22 December 1996 19:24:14
     From:  Jochen Siegenthaler, 100127,3167 #268152

     << tried wrapping ONERR code around these commands  >>

     As the other two replies have mentioned, you need to RAISE any value
     returned by the IOxxxx command.

     I use this...

      ONERR ErrTrap
      ChkRet%:(IOOPEN(xxxxxxx))

     etc, and any error returned by the IO command is RAISEd by my ChkRet
     routine...

      PROC ChkRet%:(ret%)
      IF ret%<0
       RAISE ret%
      ENDIF
      RETURN ret%
      ENDP

     ..which will RAISE ret% if less than 0 or else RETURN it.
      --
      http://ourworld.compuserve.com/homepages/Jochen_Siegenthaler/
      @ Auckland, New Zealand on 23/12/96 08:17


