home *** CD-ROM | disk | FTP | other *** search
/ PDA Software Library / pdasoftwarelib.iso / PSION / 1997 / 981.ZIP / Psi-on.opl < prev    next >
Encoding:
Text File  |  1997-04-01  |  17.7 KB  |  525 lines

  1. REM PsiOn V1.4.3 by Paul Hargreaves
  2. REM Please do not distribute modified
  3. REM versions of this program
  4. REM ╕1996, ╕1997 Paul Hargreaves
  5.  
  6. REM Changed for 1.4.3
  7. REM Added back the reduced processor
  8. REM   mode and the immediate response
  9. REM   that was removed in 1.4.2. It's
  10. REM   now been fixed.
  11. REM Added new quit key Psion-Q for
  12. REM   French users
  13.  
  14. REM Changes for 1.4.2
  15. REM Undo the reduced processor mode and
  16. REM   the immediate response added in
  17. REM   1.4, as they would sometimes set
  18. REM   the machine on, and the password
  19. REM   wouldn't rearm.
  20.  
  21. REM Changes for 1.4
  22. REM Reduced processor usage from once
  23. REM   every 2.5 seconds to just once
  24. REM   every 60 seconds
  25. REM Improved speed of keyboard/event so
  26. REM   that they get handled straight
  27. REM   away rather than after 2.5
  28. REM   seconds
  29. REM Allow sound to be re-enabled when
  30. REM   the password is being turned on.
  31. REM   Ideally, this should be at 4am 
  32. REM   but it means a rewrite of the 
  33. REM   bottom half of the code
  34. REM Added a new hotkey - Time.  This
  35. REM   will allow you to change your
  36. REM   Switched Off time temporarily.
  37. REM   Pressing any other key when 
  38. REM   activated will turn it off just
  39. REM   like Pause mode
  40. REM Allowed all hotkeys to be pressed
  41. REM   without the Psion key as well as
  42. REM   with
  43. REM Withdrew support for 1.2 and below
  44. REM   settings files, as so many of the
  45. REM   old settings have vanished
  46. REM Merged back in the extra procedures
  47. REM   as they were unneeded and were
  48. REM   taking up /valuable/ space
  49.  
  50. REM Changes for 1.3.3 and below have
  51. REM been moved to the end of this OPL
  52.  
  53.  
  54. APP PsiOn
  55.    EXT "ODB"
  56.    PATH "\OPD"
  57.    ICON "\OPL\PSI-ON.ICO"
  58.    TYPE $1000
  59. ENDA
  60.  
  61. PROC PsiOn:  
  62.    LOCAL whand%, wstat% :REM Handle for TIM:, status flag - both for the 60 second pause
  63.    LOCAL shand%, sstat% :REM Handle for TIM:, status flag - both for the long time sleep
  64.    LOCAL kstat%         :REM Keyboard handler status
  65.    LOCAL passwd$(8)     :REM Current unlock password
  66.    LOCAL event%(6)      :REM Checking for system events
  67.    LOCAL kevent%(2)     :REM Holds keys in main loop
  68.    LOCAL oscalls%(6)    :REM For OS calls
  69.    LOCAL wakeagn%       :REM 1 if next login should check time/date, 2 if should display immediately
  70.    LOCAL currday%       :REM Holds the current day
  71.    LOCAL rearmtm&       :REM Julian time to re-arm password
  72.    LOCAL runtk&         :REM 60 Second time delay
  73.    LOCAL integer%       :REM General integer   
  74.    LOCAL text$(30)      :REM General text
  75.    LOCAL pause%         :REM 0 for normal, 1 while PsiOn is pausing
  76.    LOCAL pid%           :REM Process ID of agenda
  77.    LOCAL srearm&        :REM Stores rearm& as entered from screen
  78.    LOCAL clr$(30)       :REM A clear bit of text
  79.    LOCAL toback%     :REM 0 if PsOn should go to the back, 1 if it has
  80.    
  81.    LOCAL rearm&      :REM Rearm ticks
  82.    LOCAL agn%        :REM 1 if agenda not controlled, 2 if auto view after 4am, 3 to always show
  83.    LOCAL view$(1)    :REM Char to send to Agenda (e.g. w for Week view)
  84.    LOCAL snd%        :REM 2 for sound re-arming, 1 if not
  85.  
  86.    REM Rename this process to "PsiOn" for SPY etc to list
  87.    rem log:("prog start",0,0,0)
  88.    text$="PsiOn"+CHR$(0)
  89.    CALL($0c88,CALL($0088),0,0,0,UADD(ADDR(text$),1))
  90.  
  91.    REM Set a nice font, then display the header
  92.    FONT 7,0  
  93.    gFONT 7
  94.    
  95.    REM Disable PSION-ESC to exit program
  96.    ESCAPE OFF
  97.    
  98.    REM Mark program as in-active
  99.    CALL($138b)
  100.  
  101.    REM Throw away the first starting event
  102.    GETEVENT event%()
  103.          
  104.    REM Set all defaults in-case file cannot be read
  105.    rearm& = 900 :REM Quarter of an hour 15*60
  106.    view$  = "W" :REM Week view
  107.    
  108.    REM Get the user settings from "\opd\psi-on.opd
  109.    REM Try to read a V1.3 to V1.3.3 file
  110.    text$="\OPD\PSI-ON.ODB"
  111.    rem log:("reading files",0,0,0)
  112.    TRAP OPENR text$, A, rearm&, agn%, view$
  113.    IF ERR = 0
  114.       rearm& = A.rearm& 
  115.       agn%   = A.agn%
  116.       view$  = A.view$
  117.    ENDIF
  118.    TRAP CLOSE
  119.  
  120.    REM Try to read a V1.4 file
  121.    TRAP OPENR text$, A, rearm&, agn%, view$, snd%
  122.    IF ERR = 0
  123.       REM rearm& = A.rearm& 
  124.       REM agn%   = A.agn%
  125.       REM view$  = A.view$
  126.       snd%   = A.snd%
  127.    ENDIF
  128.    TRAP CLOSE
  129.  
  130.    REM Prompt for new settings
  131.    rem log:("prompt for settings",0,0,0)
  132.    LOCK ON
  133.    DO
  134.       dINIT "PsiOn 1.4.3 ╕Paul Hargreaves"
  135.       dXINPUT passwd$,"Power on password"
  136.       dTIME   rearm& ,"Switched off time",3,120,32000 :REM 32000 is over 8 hours
  137.       dCHOICE agn%   ,"Control Agenda","No,Each morning,Every login"
  138.       dEDIT   view$  ,"Agenda view key"
  139.       dCHOICE snd%   ,"Control  sound on","No,Yes"
  140.  
  141.       REM Quit if escape pressed
  142.       IF DIALOG = 0
  143.          STOP
  144.       ENDIF      
  145.       
  146.       REM Check password is valid
  147.       integer% = CALL($2f8b, 0, 0, 0, ADDR(passwd$))
  148.       IF integer% <> 0 
  149.          GIPRINT "Wrong password"
  150.       ENDIF
  151.            
  152.    UNTIL integer% = 0 : REM Until dialog is OK.
  153.  
  154.    LOCK OFF
  155.  
  156.    srearm& = rearm&
  157.  
  158.    REM Save away new settings if they have changed
  159.    REM Open the file for the current version.  If this fails, or any of the contents are different to the screen setting, then recreate the file
  160.    rem log:("save settings",0,0,0)      
  161.    TRAP OPENR text$, A, rearm&, agn%, view$, snd%
  162.    integer% = ERR :REM Will be 0 if read ok or <> otherwise
  163.    IF ERR = 0
  164.       IF rearm& <> A.rearm& OR agn% <> A.agn% OR view$ <> A.view$ OR snd% <> A.snd%
  165.          integer% = 1
  166.       ENDIF
  167.    ENDIF
  168.    IF integer% <> 0
  169.       TRAP CLOSE
  170.       TRAP DELETE text$
  171.       TRAP MKDIR  "\OPD"
  172.       TRAP CREATE text$, A, rearm&, agn%, view$, snd%
  173.       IF ERR = 0
  174.          A.rearm& = rearm&
  175.          A.agn%   = agn%
  176.          A.view$  = view$
  177.          A.snd%   = snd%
  178.          APPEND
  179.       ENDIF
  180.    ENDIF
  181.    TRAP CLOSE
  182.  
  183.    REM Reduce the screen size and save LOTS of memory
  184.    rem log:("prep screen",gwidth,gheight,0)
  185.    gSETWIN (gWIDTH - 240) / 2, 65, 240, 31
  186.    gCLS
  187.    gAT 1, 14
  188.    clr$ = GEN$(1, -30)
  189.    gXPRINT "PsiOn V1.4.3 ╕Paul Hargreaves"+ clr$ ,1
  190.  
  191.    WHILE 1 : REM Main loop
  192.  
  193.       rem log:("in main loop",0,0,0)         
  194.       REM Trap someone changing the password.  This isn't ideal, but it's a bit silly changing your password while PsiOn is runing anyway!
  195.       IF CALL($2f8b, 0, 0, 0, ADDR(passwd$)) <> 0
  196.          ALERT("PASSWORD HAS BEEN CHANGED!")
  197.          STOP
  198.       ENDIF
  199.  
  200.       REM Turn off the power-on password
  201.       rem log:("turn off password",0,0,0)            
  202.       oscalls%(1) = $3000
  203.       REM oscalls%(2,3,4 and 6)=0
  204.       oscalls%(5) = ADDR(passwd$)
  205.       OS($8b, ADDR(oscalls%()))
  206.          
  207.       REM Open the time device for the power off time and for the 60 sec times
  208.       IF IOOPEN(shand%, "TIM:", 0) < 0 OR  IOOPEN(whand%, "TIM:", 0) < 0
  209.          RAISE -3 :REM Quit - error
  210.       ENDIF
  211.  
  212.       REM Now wait for some action!
  213.       WHILE 1 : REM Waiting Loop
  214.  
  215.          rem log:("in waiting loop:pause",pause%,0,0)
  216.          REM Fire TIM: to wake us up if switched off
  217.          IF pause% = 0
  218.             rearmtm& = DATETOSECS(YEAR, MONTH, DAY, HOUR, MINUTE, SECOND) + rearm&
  219.          ENDIF         
  220.          IOC(shand%, 2, sstat%, rearmtm&, #0)
  221.  
  222.          rem log:("display current stat",0,0,0)
  223.  
  224.          REM Ask the system for Power On events
  225.          REM Also send the program to the background
  226.          IF toback% = 0
  227.             CALL($198d, 100, 0): gUPDATE
  228.             CALL($6c8d)
  229.             toback% = 1
  230.             GETEVENT event%()
  231.             IOC(-2, 14, kstat%, event%(1), #0) :REM Same as GETEVENT but async
  232.  
  233.          ENDIF
  234.          
  235.          REM Display the current status
  236.          AT 1, 2
  237.          IF srearm& <> rearm&
  238.             PRINT "Temporary Switched off time" + clr$
  239.          ELSEIF pause% = 1
  240.             PRINT "Paused until next morning" + clr$
  241.          ELSE
  242.             PRINT CHR$(2) + "A Arm now   " + CHR$(2) + "P Pause   " + CHR$(2) + "T Time"
  243.          ENDIF
  244.  
  245.          REM Display agenda screen if required
  246.          IF wakeagn% = 2 :REM 2=Display now
  247.             wakeagn% = 0
  248.             text$ = "AGENDA" + CHR$(0)
  249.             oscalls%(1) = $0100
  250.             oscalls%(2) = UADD(ADDR(text$), 1)
  251.             IF (OS($88, ADDR(oscalls%())) AND 1) = 0 AND oscalls%(1) <> 0 :REM Found Agenda?
  252.                pid% = oscalls%(1)
  253.  
  254.                CALL($198d, 0, pid%) :gUPDATE :REM Now view agenda screen 
  255.  
  256.                event%(2) = 4 :REM Control-Space - Move to today in Day view
  257.                event%(1) = 32 
  258.                CALL($0483, pid%, 49, 0, ADDR(event%()))
  259.  
  260.                IF view$ <> "" AND view$ <> " " :REM Any other view wanted?
  261.  
  262.                   event%(2) = 10 :REM Send Key + 512(psion), and flags (Shift+Psion)
  263.                   event%(1) = 512 + ASC(view$)
  264.                   CALL($0483, pid%, 49, 0, ADDR(event%()))
  265.                ENDIF
  266.                   
  267.             ENDIF :REM OS = 0
  268.          ENDIF :REM wakeagn% = 2
  269.       
  270.          REM Check if agenda will need attn
  271.          currday% = DAY
  272.          IF HOUR < 4
  273.             wakeagn% = 1 :REM 1=go on alert, and always check time at login
  274.          ENDIF         
  275.  
  276.          REM Wait for 60 seconds or an event
  277.          runtk& = 600 :REM 60 * .10 of a second
  278.          IOC(whand%, 1, wstat%, runtk&, #0)
  279.          rem log:("events on:key,wait,sleep",kstat%,wstat%,sstat%)
  280.  
  281.          REM Ask the system to let us know about events
  282. RDKEY::  IOWAIT
  283.          IOSIGNAL :REM Replace our signal
  284.          rem log:("replenished sig.",kstat%,wstat%,sstat%)
  285.  
  286.          IF kstat% <> -46 AND (event%(1) = $401 OR event%(1) = $402 OR event%(1) = $405)
  287.          rem log:("throw away event",kstat%,event%(1),event%(2))
  288.             IOWAITSTAT kstat%
  289.             IOC(-2, 14, kstat%, event%(1), #0) :REM Same as GETEVENT but async
  290.             GOTO RDKEY :REM Throw away to front and to back messages
  291.          ENDIF
  292.          
  293.          IOCANCEL(whand%)
  294.          IOWAITSTAT wstat%
  295.  
  296.          REM Check for any system messages + quit if required
  297.          rem log:("check for keys",kstat%,kevent%(1),kevent%(2))
  298.          IOYIELD
  299.          WHILE kstat% <> -46
  300.             rem log:("start key loop",event%(1),event%(2),kstat%)
  301.             IOWAITSTAT kstat%
  302.             kevent%(1) = event%(1)
  303.             kevent%(2) = event%(2)
  304.             IOC(-2, 14, kstat%, event%(1), #0) :REM Same as GETEVENT but async
  305.             IF kevent%(1) = 609 OR kevent%(1) = 625 OR kevent%(1) = $404 OR kevent%(1) = 632 OR kevent%(1) = %a OR (kevent%(1) = 27 AND (kevent%(2) AND $FF) = 8) :REM Event QUIT or key Psion-X or Psion-Escape, or Psion-A, or lowercase a, or Psion-Q
  306.                IF kevent%(1) <> 609 AND kevent%(1) <> %a :REM Not Psion-A or lowercase a
  307.                   kevent%(1) = $404
  308.                ENDIF
  309.                BREAK : REM TESTEVENT Loop
  310.             ENDIF
  311.  
  312.             REM Change default time
  313.             IF kevent%(1) = 628 OR kevent%(1) = %t :REM Psion + t or t
  314.                rearm& = srearm& :REM Restore default off time
  315.                pause% = 0 :REM Disable pause mode
  316.                LOCK ON
  317.                dINIT
  318.                dTIME rearm& ,"Switched off time",3,120,32000 :REM 32000 is over 8 hours
  319.                DIALOG
  320.                LOCK OFF
  321.                CONTINUE :REM Around testevent loop     
  322.             ENDIF
  323.  
  324.             REM Start pause if required, or cancel if not    
  325.             IF kevent%(1) = 624 OR kevent%(1) = %p :REM Psion-P (512+112) or lowercase p
  326.                rearm& = srearm& :REM Restore default off time
  327.                IF pause% = 0
  328.                   pause% = 1
  329.                   REM Work out what 04:00 is on the next day
  330.                   IF HOUR >= 4
  331.                      SECSTODATE DATETOSECS(YEAR, MONTH, DAY, HOUR, MINUTE, SECOND) + 86400, event%(1), event%(2), event%(3), event%(4), event%(5), event%(6), integer%
  332.                   ELSE
  333.                      SECSTODATE DATETOSECS(YEAR, MONTH, DAY, HOUR, MINUTE, SECOND), event%(1), event%(2), event%(3), event%(4), event%(5), event%(6), integer%
  334.                   ENDIF
  335.                   
  336.                   rearmtm& = DATETOSECS(event%(1), event%(2), event%(3), 4, 0, 0)               
  337.                   CONTINUE :REM Around the while testevent again
  338.                ENDIF :REM Pause = 0
  339.             ENDIF :REM Event = 624
  340.  
  341.             REM Cancel pause or temp switched off if not required             
  342.             IF pause% = 1 OR srearm& <> rearm&
  343.                IF kevent%(1) < $400
  344.                   pause% = 0
  345.                   rearm& = srearm&
  346.                ENDIF :REM Event = key
  347.             ENDIF :REM Pause = 1 or srearm& <> rearm&
  348.             rem log:("bot of key loop",kstat%,0,0)
  349.          ENDWH :REM WHILE TESTEVENT
  350.  
  351.          REM Woke up - time to rearm pwd?  If so, break
  352.          PAUSE 5
  353.          IOYIELD
  354.          IF sstat% <> -46
  355.             rem log:("rearm!",sstat%,0,0)
  356.             IOWAITSTAT sstat%
  357.  
  358.             BREAK : REM Waiting loop
  359.          ENDIF
  360.  
  361.          REM Cancel TIM: so we can start new TIM:
  362.          rem log:("cancel tim:",0,0,0)
  363.          IOCANCEL(shand%)
  364.          IOWAITSTAT sstat%
  365.  
  366.          IF kevent%(1) = $404 OR kevent%(1) = 609 OR kevent%(1) = %a :REM Event QUIT or Key Psion-X or Psion-A (Re-arm now) or lowercase a (Re-arm now)
  367.             BREAK : REM Waiting Loop
  368.          ENDIF
  369.  
  370.       ENDWH : REM Waiting loop
  371.  
  372.       REM Turn password back on
  373.       rem log:("turn pwd on",0,0,0)
  374.       oscalls%(1) = $3001
  375.       REM oscalls%(2,3,4 and 6)=0
  376.       oscalls%(5) = ADDR(passwd$)
  377.       OS($8b, ADDR(oscalls%()))
  378.  
  379.       REM Disable pause mode
  380.       pause% = 0
  381.       toback% = 0
  382.  
  383.       REM Turn on sounds if required
  384.       IF snd% = 2
  385.          CALL($108b,CALL($0f8b) AND 32767)
  386.       ENDIF
  387.  
  388.       REM Close both TIM:
  389.       rem log:("close tims",0,0,0)            
  390.       IOCLOSE(shand%)
  391.       IOCLOSE(whand%)
  392.  
  393.       REM Turn off PSION, when switched on, run again
  394.       IF kevent%(1) = $404 :REM Event QUIT or Psion-X
  395.          BEEP 5, 300
  396.          STOP
  397.       ENDIF
  398.       CALL($198d, 100, 0) :gUPDATE :REM Make sure PsiOn is in the background
  399.       CALL($198d, 0, 0)   :gUPDATE :REM Now bring PsiOn to the front!
  400.  
  401.       REM Catch the new "To Front" message
  402.       rem log:("wait for new to front",0,0,0)
  403.       DO   
  404.          IOWAITSTAT kstat%
  405.          kevent%(1) = event%(1)
  406.          IOC(-2, 14, kstat%, event%(1), #0) :REM Same as GETEVENT but async
  407.       UNTIL kevent%(1) = $401 :REM Event TO FRONT
  408.       kevent%(1) = 0
  409.  
  410.       REM Switch the machine off
  411.       rem log:("mac off",0,0,0)
  412.       OFF
  413.       rem log:("mac on",0,0,0)
  414.  
  415.       REM Run again when PsiOn notices that the password is entered
  416.       WHILE kevent%(1) <> $401 :REM Event TO FRONT
  417.          
  418.          CALL($198d, 0, 0) :gUPDATE :REM Put PsiOn to the front!
  419.  
  420.          IOWAITSTAT kstat%
  421.          kevent%(1) = event%(1)
  422.  
  423.          IF kevent%(1) = $404 :REM Event QUIT
  424.             STOP
  425.          ENDIF
  426.  
  427.          IF kevent%(1) <> $401 :REM Event TO FRONT
  428.             IOC(-2, 14, kstat%, event%(1), #0) :REM Same as GETEVENT but async
  429.          ENDIF
  430.  
  431.       ENDWH :REM Event TO FRONT
  432.       rem log:("back to front",0,0,0)     
  433.  
  434.       REM See if agenda needs looking at
  435.       IF currday% <> DAY
  436.          wakeagn% = 1 :REM 1=check time on turn on
  437.       ENDIF
  438.       IF ((wakeagn% <> 0 AND HOUR >= 4) OR agn% = 3) AND agn% > 1
  439.          wakeagn% = 2 :REM 2=Display agenda
  440.       ENDIF
  441.          
  442.       REM Loop and Re-arm !!
  443.  
  444.    ENDWH : REM Main loop
  445. ENDP 
  446.  
  447. rem PROC log:(s$,a%,b%,c%)
  448. rem   beep 1,300
  449. rem  trap lopen "\wrd\debug.wrd"
  450. rem lprint datim$;" ";s$,a%,b%,c%
  451. rem ENDP   
  452.  
  453.  
  454. REM Continuation of change log
  455.  
  456. REM Changes for 1.3.3
  457. REM If Pause mode was used, next day the
  458. REM   screen showed Pause mode was
  459. REM   running in error
  460. REM If Pause mode was used, and you use
  461. REM   the machine past midnight, Pause
  462. REM   sets itself up for the Next day
  463. REM   instead of today
  464. REM Changed text label for Pause mode
  465.  
  466. REM Changes for 1.3.2
  467. REM Sorted out issue where Agenda just
  468. REM   ignores any events first thing in
  469. REM   the morning.  
  470. REM   (appears that if Agenda isn't in
  471. REM   view, that it ignores key presses)
  472.  
  473. REM Changes for 1.3
  474. REM Press Psion-A in the screen, and
  475. REM   PsiOn will turn on the password 
  476. REM   and will switch the Psion off - 
  477. REM   just as if the time-out had 
  478. REM   occured.  Useful if you leave your
  479. REM   machine lying around at lunch etc.
  480. REM Press Psion-P in the screen, and
  481. REM   PsiOn will suspend it's auto
  482. REM   re-arm of the password until
  483. REM   04:00 hours the next day rather
  484. REM   than your normal time
  485. REM PsiOn will quit if Psion-Escape is
  486. REM   pressed
  487. REM Agenda control.  If selected, PsiOn
  488. REM   will look for 1 and only 1 running
  489. REM   task called Agenda.  When you next
  490. REM   log in, Agenda will be pushed to
  491. REM   the front, in the view of your
  492. REM   choice
  493. REM Instant response to Events - e.g.
  494. REM   a quit will quit in a couple of
  495. REM   seconds rather than 15
  496. REM Break the program up into different
  497. REM   procedures (slightly)
  498. REM Upgrades that change the psi-on.opd
  499. REM   file will keep your old settings
  500. REM Learned how to spell Siena <g>
  501. REM Low memory mode - removed all the
  502. REM   unneeded displays!  PsiOn uses
  503. REM   9/10k when working rather than 19k
  504. REM Removed Prompt Option, as no-one 
  505. REM   seems to need it - the Auto option
  506. REM   added in 1.2 more than replaces it
  507. REM Removed Beep Option, as it isn't
  508. REM   useful and it's now obvious when 
  509. REM   you log in that PsiOn is runing
  510. REM Removed New Auto-Off time, as PsiOn
  511. REM   /should/ be running all the time
  512. REM   the user will have the value set
  513. REM   in the standard place
  514. REM Changed all dialogs so that no
  515. REM   special dialogs or code are needed
  516. REM   for Siena's.
  517.  
  518. REM Changes for 1.2
  519. REM Auto rearm when password is entered
  520. REM More beep options
  521. REM Rename running program to PsiOn
  522. REM Siena (emulator) compatable!
  523. REM Tidy up the source a little
  524.  
  525.