1. Alarm problems solved
- Posted by "Wallace B. Riley" <wryly at MINDSPRING.COM> Sep 04, 1997
- 1060 views
- Last edited Sep 05, 1997
--=====================_873426147==_ To Robert Pilkington and anyone else who is interested: I've attached several files that summarize my problems with an alarm routine. The cover letter describes the general situation; then Attachment #1 is a beep generator, from Pete Eberlein, sent to me several weeks ago. Wally Riley wryly at mindspring.com --=====================_873426147==_ Attachment #2 is a 'beeptest' that uses Pete's 'beep' generator. It beeps once a second, three times; repeats those three beeps three times with short pauses between; then makes nine more beeps twice with longer pauses; and so on for a total of 81 beeps before it gives up. There's one more 'farewell' beep just before the end. That 'beeptest' is the basis of Attachment #3, the 'alarm' routine that I wanted to incorporate in my program. That ran well a few weeks ago, I recall, but I had a lot of trouble with it today. It is supposed to stay in the second inner loop for 60 seconds, then drop out. At that point, if no key was pressed, it should repeat the outer loop indefinitely. Pressing any key would make it drop out. But it wouldn't do that at first. It would make one set of five beeps, then hang up. Nothing appeared to be wrong for a couple of minutes, when I noticed that I should be getting groups of 5 beeps 1 minute apart, and I wasn't getting them. If I pressed a key, again nothing happened, but if I didn't get antsy, the program halted normally after another minute or so. I messed around with this routine for a long time. Now it seems to work, but I'm not sure what I did. For reference, Attachment #4 is a corresponding 'alarm' routine in QBASIC that works very well. (There's one thing I can say about QBASIC: in spite of its obvious shortcomings, when I write a program in that language, it usually works; and when it doesn't, its bugs are fairly easily located.) Now, all this came up because I tried to use the basic (not BASIC) alarm routine in the program I am writing. That routine is in Attachment #5. Look at these attachments, if you wish, and if you see anything that looks shaky or out of line, I'd like to know before the thing blows up in my face. I won't take up any more of your time on this now, but I ran into trouble on another matter which wrestling with the alarm routine. I had some problems with the 'time()' command, which doesn't seem to work the way the library document says it does. It's a side issue now, but maybe I'll ask for assistance later. Wally Riley wryly at mindspring.com --=====================_873426147==_ --Attachment #1: --Pete Eberlein's beep generator include machine.e procedure beep() sequence regs regs = repeat(0, 10) --required by 'dos_interrupt' below regs[REG_AX] = #0E07 regs = dos_interrupt(#10, regs) end procedure --=====================_873426147==_ --BEEPTEST --Attachment #2 include machine.e procedure beep() sequence regs regs = repeat(0, 10) regs[REG_AX] = #0E07 regs = dos_interrupt(#10, regs) end procedure procedure beeptest() atom j, k, m, n, loop1, loop2, loop3, loop4 j = 1 while j <= 3 do loop4 = time() --interval between 27-beep clumps k = 1 while k <= 3 do loop3 = time() --interval between 9-beep sets m = 1 while m <= 3 do loop2 = time() --interval between 3-beep groups--- n = 1 -- /\ while n <= 3 do-- | loop1 = time() --interval between beeps | beep() -- | puts(1," End loop1\n") -- outer loop while time() - loop1 < 1 do -- in ROUTES end while -- program n = n + 1 -- | end while -- | puts(1," End loop2\n") -- \/ while time() - loop2 < 6 do ---------------------- end while m = m + 1 end while puts(1," End loop3\n") while time() - loop3 < 36 do end while k = k + 1 end while puts(1," End loop4\n") while time() - loop4 < 72 do end while j = j + 1 end while beep() puts(1,"End of beep test") end procedure beeptest() --=====================_873426147==_ --Attachment #3 include machine.e procedure beep() sequence regs regs = repeat(0, 10) --required by 'dos_interrupt' below regs[REG_AX] = #0E07 regs = dos_interrupt(#10, regs) end procedure procedure alarm() integer u, i atom inloop, outloop inloop = 0 outloop = 0 while 1 do outloop = time() u = 1 while u <= 5 do inloop = time() beep() while time() - inloop<1 do end while u = u+1 end while while time() - outloop < 60 do end while i = -1 i = get_key() if i != -1 then exit end if end while end procedure --alarm() alarm() --=====================_873426147==_ 'Attachment #4 (QBASIC) ALARM: 'DISABLE BEEPER BETWEEN 11:59:00 p.m. AND 12:01:00 a.m., 'THAT IS, WITHIN 1 MINUTE OF MIDNIGHT, WHEN TIMER RESETS TO 0. IF TIMER > 60 AND TIMER < 86340 THEN GOTO STARTBEEP GOTO ALARM ' STARTBEEP: FOR U = 1 TO 5 'DEFINE BURST OF BEEPS PRINT CHR$(7); 'BEEP ONCE WITHOUT LINE FEED Interval& = TIMER HOLD1: IF TIMER - Interval& > 1 THEN GOTO TRYLOOP 'WAIT 1 SECOND GOTO HOLD1 ' TRYLOOP: NEXT U Interval& = TIMER ' HOLD2: 'BEEP 5 TIMES ONCE A MINUTE IF TIMER - Interval& > 60 THEN GOTO STARTBEEP E$ = INKEY$ 'PRESS ANY KEY TO STOP THE BEEPING IF LEN(E$) <> 0 THEN GOTO STOPBEEP GOTO HOLD2 ' STOPBEEP: RETURN ' --=====================_873426147==_ --Attachment #5 include machine.e procedure beep() sequence regs regs = repeat(0, 10) regs[REG_AX] = #0E07 regs = dos_interrupt(#10, regs) end procedure procedure alarm() atom loop1, loop2 while 1 do loop2 = time() n = 1 while n <= 5 do loop1 = time() beep() while time() - loop1 < 1 do end while n = n + 1 end while while time() - loop2 < 60 do end while j = -1 j = wait_key() if j = "Q" then abort(0) else exit end if end while end procedure --=====================_873426147==_--