home *** CD-ROM | disk | FTP | other *** search
Wrap
REM PsiOn V1.4.2 by Paul Hargreaves REM Please do not distribute modified REM versions of this program REM ╕1996, ╕1997 Paul Hargreaves REM Changes for 1.4.2 REM Undo the reduced processor mode and REM the immediate response added in REM 1,4, as they would sometimes set REM the machine on, and the password REM wouldn't rearm. I intend to add REM them back again, but next time REM it'll be tested as a focal point REM Changes for 1,4 REM Reduced processor usage from once REM every 2.5 seconds to just once REM every 60 seconds REM Improved speed of keyboard/event so REM that they get handled straight REM away rather than after 2.5 REM seconds REM Allow sound to be re-enabled when REM the password is being turned on. REM Ideally, this should be at 4am REM but it means a rewrite of the REM bottom half of the code REM Added a new hotkey - Time. This REM will allow you to change your REM Switched Off time temporarily. REM Pressing any other key when REM activated will turn it off just REM like Pause mode REM Allowed all hotkeys to be pressed REM without the Psion key as well as REM with REM Withdrew support for 1.2 and below REM settings files, as so many of the REM old settings have vanished REM Merged back in the extra procedures REM as they were unneeded and were REM taking up /valuable/ space REM Changes for 1.3.3 and below have REM been moved to the end of this OPL APP PsiOn EXT "ODB" PATH "\OPD" ICON "\OPL\PSI-ON.ICO" TYPE $1000 ENDA PROC PsiOn: LOCAL shand%, sstat% :REM Handle for TIM:, status flag - both for the long time sleep LOCAL passwd$(8) :REM Current unlock password LOCAL event%(6) :REM Checking for system events LOCAL oscalls%(6) :REM For OS calls LOCAL wakeagn% :REM 1 if next login should check time/date, 2 if should display immediately LOCAL currday% :REM Holds the current day LOCAL rearmtm& :REM Julian time to re-arm password LOCAL runtk& :REM 60 Second time delay LOCAL integer% :REM General integer LOCAL text$(30) :REM General text LOCAL pause% :REM 0 for normal, 1 while PsiOn is pausing LOCAL pid% :REM Process ID of agenda LOCAL srearm& :REM Stores rearm& as entered from screen LOCAL clr$(30) :REM A clear bit of text LOCAL toback% :REM 0 if PsiOn should go to the back, 1 if it has LOCAL rearm& :REM Rearm ticks LOCAL agn% :REM 1 if agenda not controlled, 2 if auto view after 4am, 3 to always show LOCAL view$(1) :REM Char to send to Agenda (e.g. w for Week view) LOCAL snd% :REM 2 for sound re-arming, 1 if not REM Rename this process to "PsiOn" for SPY etc to list text$="PsiOn"+CHR$(0) CALL($0c88,CALL($0088),0,0,0,UADD(ADDR(text$),1)) REM Set a nice font, then display the header FONT 7,0 gFONT 7 REM Disable PSION-ESC to exit program ESCAPE OFF REM Mark program as in-active CALL($138b) REM Throw away first starting event GETEVENT event%() REM Set all defaults in-case file cannot be read rearm& = 900 :REM Quarter of an hour 15*60 view$ = "W" :REM Week view REM Get the user settings from "\opd\psi-on.opd REM Try to read a V1.3 to V1.3.3 file text$="\OPD\PSI-ON.ODB" TRAP OPENR text$, A, rearm&, agn%, view$ IF ERR = 0 rearm& = A.rearm& agn% = A.agn% view$ = A.view$ ENDIF TRAP CLOSE REM Try to read a V1.4.2 file TRAP OPENR text$, A, rearm&, agn%, view$, snd% IF ERR = 0 REM rearm& = A.rearm& REM agn% = A.agn% REM view$ = A.view$ snd% = A.snd% ENDIF TRAP CLOSE REM Prompt for new settings LOCK ON DO dINIT "PsiOn 1.4.2 ╕Paul Hargreaves" dXINPUT passwd$,"Power on password" dTIME rearm& ,"Switched off time",3,120,32000 :REM 32000 is over 8 hours dCHOICE agn% ,"Control Agenda","No,Each morning,Every login" dEDIT view$ ,"Agenda view key" dCHOICE snd% ,"Control sound on","No,Yes" REM Quit if escape pressed IF DIALOG = 0 STOP ENDIF REM Check password is valid integer% = CALL($2f8b, 0, 0, 0, ADDR(passwd$)) IF integer% <> 0 GIPRINT "Wrong password" ENDIF UNTIL integer% = 0 : REM Until dialog is OK. LOCK OFF srearm& = rearm& REM Save away new settings if they have changed 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 TRAP OPENR text$, A, rearm&, agn%, view$, snd% integer% = ERR :REM Will be 0 if read ok or <> otherwise IF ERR = 0 IF rearm& <> A.rearm& OR agn% <> A.agn% OR view$ <> A.view$ OR snd% <> A.snd% integer% = 1 ENDIF ENDIF IF integer% <> 0 TRAP CLOSE TRAP DELETE text$ TRAP MKDIR "\OPD" TRAP CREATE text$, A, rearm&, agn%, view$, snd% IF ERR = 0 A.rearm& = rearm& A.agn% = agn% A.view$ = view$ A.snd% = snd% APPEND ENDIF ENDIF TRAP CLOSE REM Reduce the screen size and save LOTS of memory gSETWIN (gWIDTH - 240) / 2, 65, 240, 31 gCLS gAT 1, 14 clr$ = GEN$(1, -30) gXPRINT "PsiOn V1.4.2 ╕Paul Hargreaves"+ clr$ ,1 WHILE 1 : REM Main loop REM Trap someone changing the password. This isn't ideal, but it's a bit silly changing your password while PsiOn is runing anyway! IF CALL($2f8b, 0, 0, 0, ADDR(passwd$)) <> 0 ALERT("PASSWORD HAS BEEN CHANGED!") STOP ENDIF REM Turn off the power-on password oscalls%(1) = $3000 REM oscalls%(2,3,4 and 6)=0 oscalls%(5) = ADDR(passwd$) OS($8b, ADDR(oscalls%())) REM Open the time device for the power off time IF IOOPEN(shand%, "TIM:", 0) < 0 RAISE -3 :REM Quit - error ENDIF REM Now wait for some action! WHILE 1 : REM Waiting Loop REM Fire TIM: to wake us up if switched off IF pause% = 0 rearmtm& = DATETOSECS(YEAR, MONTH, DAY, HOUR, MINUTE, SECOND) + rearm& ENDIF IOC(shand%, 2, sstat%, rearmtm&, #0) REM Ask the system for Power On events REM Send the program to the background IF toback% = 0 CALL($198d, 100, 0): gUPDATE CALL($6c8d) toback% = 1 GETEVENT event%() ENDIF REM Display the current status AT 1, 2 IF srearm& <> rearm& PRINT "Temporary Switched off time" + clr$ ELSEIF pause% = 1 PRINT "Paused until next morning" + clr$ ELSE PRINT CHR$(2) + "A Arm now " + CHR$(2) + "P Pause " + CHR$(2) + "T Time" ENDIF REM Display agenda screen if required IF wakeagn% = 2 :REM 2=Display now wakeagn% = 0 text$ = "AGENDA" + CHR$(0) oscalls%(1) = $0100 oscalls%(2) = UADD(ADDR(text$), 1) IF (OS($88, ADDR(oscalls%())) AND 1) = 0 AND oscalls%(1) <> 0 :REM Found Agenda? pid% = oscalls%(1) CALL($198d, 0, pid%) :gUPDATE :REM Now view agenda screen event%(2) = 4 :REM Control-Space - Move to today in Day view event%(1) = 32 CALL($0483, pid%, 49, 0, ADDR(event%())) IF view$ <> "" AND view$ <> " " :REM Any other view wanted? event%(2) = 10 :REM Send Key + 512(psion), and flags (Shift+Psion) event%(1) = 512 + ASC(view$) CALL($0483, pid%, 49, 0, ADDR(event%())) ENDIF ENDIF :REM OS = 0 ENDIF :REM wakeagn% = 2 REM Check if agenda will need attn currday% = DAY IF HOUR < 4 wakeagn% = 1 :REM 1=go on alert, and always check time at login ENDIF REM Wait for 60 seconds or an event integer% = 24 :REM 60 seconds WHILE integer% > 0 AND sstat% = -46 AND NOT TESTEVENT integer% = integer% - 1 PAUSE 50 :REM 2.5 seconds ENDWH REM Woke up - time to rearm pwd? If so, break IF sstat% <> -46 IOWAITSTAT sstat% BREAK : REM Waiting loop ENDIF REM Check for any system messages + quit if required WHILE TESTEVENT GETEVENT event%() IF event%(1) = 609 OR event%(1) = $404 OR event%(1) = 632 OR event%(1) = %a OR (event%(1) = 27 AND (event%(2) AND $FF) = 8) :REM Event QUIT or key Psion-X or Psion-Escape, or Psion-A, or lowercase a IF event%(1) <> 609 AND event%(1) <> %a :REM Not Psion-A or lowercase a event%(1) = $404 ENDIF BREAK : REM TESTEVENT Loop ENDIF REM Change default time IF event%(1) = 628 OR event%(1) = %t :REM Psion + t or t rearm& = srearm& :REM Restore default off time pause% = 0 :REM Disable pause mode LOCK ON dINIT dTIME rearm& ,"Switched off time",3,120,32000 :REM 32000 is over 8 hours DIALOG LOCK OFF event%(1) = 0 CONTINUE :REM Around testevent loop ENDIF REM Start pause if required, or cancel if not IF event%(1) = 624 OR event%(1) = %p :REM Psion-P (512+112) or lowercase p rearm& = srearm& :REM Restore default off time IF pause% = 0 pause% = 1 REM Work out what 04:00 is on the next day IF HOUR >= 4 SECSTODATE DATETOSECS(YEAR, MONTH, DAY, HOUR, MINUTE, SECOND) + 86400, event%(1), event%(2), event%(3), event%(4), event%(5), event%(6), integer% ELSE SECSTODATE DATETOSECS(YEAR, MONTH, DAY, HOUR, MINUTE, SECOND), event%(1), event%(2), event%(3), event%(4), event%(5), event%(6), integer% ENDIF rearmtm& = DATETOSECS(event%(1), event%(2), event%(3), 4, 0, 0) event%(1) = 0 CONTINUE :REM Around the while testevent again ENDIF :REM Pause = 0 ENDIF :REM Event = 624 REM Cancel pause or temp switched off if not required IF pause% = 1 OR srearm& <> rearm& IF event%(1) < $400 pause% = 0 rearm& = srearm& ENDIF :REM Event = key ENDIF :REM Pause = 1 or srearm& <> rearm& event%(1) = 0 ENDWH :REM WHILE TESTEVENT REM Cancel TIM: so we can start new TIM: IOCANCEL(shand%) IOWAITSTAT sstat% IF event%(1) = $404 OR event%(1) = 609 OR event%(1) = %a :REM Event QUIT or Key Psion-X or Psion-A (Re-arm now) or lowercase a (Re-arm now) BREAK : REM Waiting Loop ENDIF ENDWH : REM Waiting loop REM Turn password back on oscalls%(1) = $3001 REM oscalls%(2,3,4 and 6)=0 oscalls%(5) = ADDR(passwd$) OS($8b, ADDR(oscalls%())) REM Disable pause mode pause% = 0 toback% = 0 REM Turn on sounds if required IF snd% = 2 CALL($108b,CALL($0f8b) AND 32767) ENDIF REM Close both TIM: IOCLOSE(shand%) REM Turn off PSION, when switched on, run again IF event%(1) = $404 :REM Event QUIT or Psion-X BEEP 5, 300 STOP ENDIF CALL($198d, 100, 0) :gUPDATE :REM Make sure PsiOn is in the background CALL($198d, 0, 0) :gUPDATE :REM Now bring PsiOn to the front! REM Catch the new "To Front" message DO GETEVENT event%() UNTIL event%(1) = $401 :REM Event TO FRONT WHILE TESTEVENT GETEVENT event%() ENDWH REM Switch the machine off OFF REM Run again when PsiOn notices that the password is entered event%(1) = 0 WHILE event%(1) <> $401 :REM Event TO FRONT CALL($198d, 0, 0) :gUPDATE :REM Put PsiOn to the front! GETEVENT event%() IF event%(1) = $404 :REM Event QUIT STOP ENDIF ENDWH :REM Event TO FRONT REM See if agenda needs looking at IF currday% <> DAY wakeagn% = 1 :REM 1=check time on turn on ENDIF IF ((wakeagn% <> 0 AND HOUR >= 4) OR agn% = 3) AND agn% > 1 wakeagn% = 2 :REM 2=Display agenda ENDIF REM Loop and Re-arm !! ENDWH : REM Main loop ENDP REM Continuation of change log REM Changes for 1.3.3 REM If Pause mode was used, next day the REM screen showed Pause mode was REM running in error REM If Pause mode was used, and you use REM the machine past midnight, Pause REM sets itself up for the Next day REM instead of today REM Changed text label for Pause mode REM Changes for 1.3.2 REM Sorted out issue where Agenda just REM ignores any events first thing in REM the morning. REM (appears that if Agenda isn't in REM view, that it ignores key presses) REM Changes for 1.3 REM Press Psion-A in the screen, and REM PsiOn will turn on the password REM and will switch the Psion off - REM just as if the time-out had REM occured. Useful if you leave your REM machine lying around at lunch etc. REM Press Psion-P in the screen, and REM PsiOn will suspend it's auto REM re-arm of the password until REM 04:00 hours the next day rather REM than your normal time REM PsiOn will quit if Psion-Escape is REM pressed REM Agenda control. If selected, PsiOn REM will look for 1 and only 1 running REM task called Agenda. When you next REM log in, Agenda will be pushed to REM the front, in the view of your REM choice REM Instant response to Events - e.g. REM a quit will quit in a couple of REM seconds rather than 15 REM Break the program up into different REM procedures (slightly) REM Upgrades that change the psi-on.opd REM file will keep your old settings REM Learned how to spell Siena <g> REM Low memory mode - removed all the REM unneeded displays! PsiOn uses REM 9/10k when working rather than 19k REM Removed Prompt Option, as no-one REM seems to need it - the Auto option REM added in 1.2 more than replaces it REM Removed Beep Option, as it isn't REM useful and it's now obvious when REM you log in that PsiOn is runing REM Removed New Auto-Off time, as PsiOn REM /should/ be running all the time REM the user will have the value set REM in the standard place REM Changed all dialogs so that no REM special dialogs or code are needed REM for Siena's. REM Changes for 1.2 REM Auto rearm when password is entered REM More beep options REM Rename running program to PsiOn REM Siena (emulator) compatable! REM Tidy up the source a little