psychonaut25 Posted January 27, 2011 Share Posted January 27, 2011 Is there a possibilty of real time clock in Turbo basic? Like it will be counting from for example from 4 minutes to zero. And if so, can it be running on background of other processes? Thanks. Quote Link to comment Share on other sites More sharing options...
+Stephen Posted January 27, 2011 Share Posted January 27, 2011 You can use locations 18,19,20 (the OS maintains them). To have it run in the background will require you to code in assembly and "inject" the code into the Vertical Blank Interrupt. I can post an example when I get home if someone else doesn't beat me to it. Quote Link to comment Share on other sites More sharing options...
analmux Posted January 28, 2011 Share Posted January 28, 2011 Well, there's no easy way to interrupt turbobasic by an external (Machine Language) process. So, you'd need to do a regular check of some memory register now and then. I'd say, indeed the registers 18,19,20 are already managed by the operating system, so all you need to do is check these registers now and then. This 18,19,20 is a 24-bit value, so runs from 0 to 16777215. If you want to wait 4 minutes, then that's 4*60 = 240 sec. Depending on PAL/NTSC machine, multiply with 50 or 60. Let's say 50, then 240 * 50 = 12000 frames. Now compute 16777216-12000. The result is 16765216. Now express this as a 3-byte quantity: 10 N=16765216 20 HI=INT(N/65536):N=N-65536*HI 30 MID=INT(N/256):N=N-256*MID 40 LO=N 50 POKE 54286,0:REM THIS FREEZES THE SYSTEM TIMER 60 POKE 18,LO:POKE 19,MID:POKE 20,HI 70 POKE 54286,192:REM THIS STARTS THE SYSTEM TIMER Then, all you need to do is a check once in while: 100 IF PEEK(20)=0 THEN GOTO {EXIT PROCESS} OK, this approach will not exactly work, but here's a short explanation. You write this 24-bit value 16777216-{X=number of frames to wait} to addr 18,19,20, then start timer. The 24-bit register will start to increment every frame, and will get an overflow after X frames. Then the Hi-byte (MSB = Most significant byte) will be zero again. Another approach is just do poke 18,0 poke 19,0 poke 20,0 and wait until these 3 registers contain the desired values, but then you need to check 3 registers everytime. The last check (see line 100) can also be done by using the BIT instruction in ML: BIT z 20 BEQ {exit} Quote Link to comment Share on other sites More sharing options...
psychonaut25 Posted February 2, 2011 Author Share Posted February 2, 2011 (edited) Little corrections, worked perfectly. 10 N=16765216 20 HI=INT(N/65536):N=N-65536*HI 30 MID=INT(N/256):N=N-256*MID 40 LO=N 50 POKE 54286,0:REM THIS FREEZES THE SYSTEM TIMER 60 POKE 18,LO:POKE 19,MID:POKE 20,HI 70 POKE 54286,192:REM THIS STARTS THE SYSTEM TIMER 100 TIME=TIME+1 110 ? INT(TIME/60) 120 IF INT(TIME/60)=240 THEN ? "4 minutes" 130 GOTO 100 [/code] thanks, helped!! the timer wasn't really needed. Edited February 2, 2011 by psychonaut25 Quote Link to comment Share on other sites More sharing options...
analmux Posted February 2, 2011 Share Posted February 2, 2011 Doh, yes, you're right, I forgot. TBB already supports this, by using the TIME command So, in TBB it's simple. I did a second check however, and I was also mistaken in my 1st post here. Suppose you use normal basic, then it's still some kind-of-solution. My mistake: I wrote 18,19,20 = low,mid,high Correction: 20,19,18 = low,mid,high Quote Link to comment Share on other sites More sharing options...
analmux Posted February 2, 2011 Share Posted February 2, 2011 OK, another "help". The line 100 100 TIME=TIME+1 is not needed, as the TIME variable runs by itself. Actually it really IS the same as registers 18,19,20. Check it: ? TIME,PEEK(20)+256*PEEK(19)+65536*PEEK(18) So, in Turbobasic it's already integrated. So, how to start the timer, and how to check for 4 minutes waiting loop on an NTSC machine? See here: 100 POKE 54286,0:POKE 18,0:DPOKE 19,0:POKE 54286,192:REM THIS RESETS & STARTS THE TIMER 110 IF TIME>14400 THEN GOTO {EXIT PROCESS}:REM THIS WAITS UNTIL AT LEAST 4 MINUTES PASSED 120 {DO SOMETHING ELSE IN THE MEANTIME} 130 GOTO 110 OK, does this sound better? Sorry for the confusion in my 1st reply here. Quote Link to comment Share on other sites More sharing options...
psychonaut25 Posted February 3, 2011 Author Share Posted February 3, 2011 Ok. works fine. No problem with that reply. Helped. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.