Jump to content
IGNORED

Real time clock in Turbo Basic


Recommended Posts

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.

Link to comment
Share on other sites

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}

Link to comment
Share on other sites

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 by psychonaut25
Link to comment
Share on other sites

Doh, yes, you're right, I forgot. TBB already supports this, by using the TIME command :roll:

 

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...