Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Can DBPro call a function like an interrupt timer?

Author
Message
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 13th Jul 2011 01:32
All processors have interrupt timers. Is it possible in DBPro to set up and interrupt timer and call a DBPro function?

Pseudo code:


I'm hoping that it is possible...

Warning! May contain Nuts!
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 13th Jul 2011 02:28
Nope, there's nothing that works on a timer.

The nearest I have for you are the function pointer callbacks made available during the SYNC process. See if you think you can get them to fit your requirements.

WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 13th Jul 2011 03:14 Edited at: 13th Jul 2011 03:23
Would the callback still work as normal with auto syncing ie SYNC OFF?

This would be very interesting because all I would need to do is a simple progress animation during a huge bunch of calculations going on in the background.

EDIT: I like the WndProc callback!!! That will come in handy at some point.

Warning! May contain Nuts!
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 13th Jul 2011 14:03
It works whether you call SYNC manually, or leave it to the runtime to do for you.

I have a slightly better option for you though (IMO). You can create a function to carry out your calculations and call that via a coroutine. That allows you to switch in and out of that function at specified places, without losing your place in the function.

For example:


WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 13th Jul 2011 14:53
Thanks once again IanM. Those coroutines can be useful for quite a few things like switching on/off states of a program. I'll probably use them pretty soon.

For now I'll use the SYNC callback with a global variable. The callback function will do something depending on the value of the global variable so I can display the current state of the large calculations going on. Once it's finished I can just switch off the callback.

The coroutines are good for real-time use but the callback is ideal for just updating the progress every now and then especially now I can leave the auto syncing on.

Just a final question and sorry to bug you so much you've been a great help. When the coroutine reaches the endfunction, is it removed?

Warning! May contain Nuts!
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 13th Jul 2011 16:07
No, it's not removed.

If it has been set to restart, then that will happen automatically. Otherwise, it will switch to an inactive state,, where it will stay until you either delete it, or restart it.

WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 13th Jul 2011 16:45
A slight problem with the program freezing up. I've already set up the globals.



In between I call the various functions that do their stuff...



At first it told me that the function needs to return a value. 0 seems a safe bet as 1 caused an invalid address call.

I could upload the project, it's still not that big yet.

The program starts, after a short while it seems to call the presync callback function once, does something else and then freezes.

Warning! May contain Nuts!
Max P
16
Years of Service
User Offline
Joined: 23rd Jan 2010
Location:
Posted: 13th Jul 2011 16:56
You need to use a function ptr or name:
ptr:

name:
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 13th Jul 2011 17:59
That made it run properly, thanks Max P, although very slow. Had to switch the syncing back on to get it back up to normal speed. It's not quite like an interrupt but it works at normal speed again. Back to 1.7 seconds approx before it gets to the convert to 3D bit.

I'll be having a good nosey through the Matrix1 Utils commands again.

Warning! May contain Nuts!
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 13th Jul 2011 22:54
Just as a suggestion to the Matrix1 Utils there could be useful extra commands that make use of the Winapi timer commands. Redirecting them to a DBPro function as an interrupt controller. I know they're not deadly accurate but they have provided me with a lot of useful stuff since I've been back into programming.

timer=SetTimer(delay, function)
KillTimer(timer)

If I knew how to do this in the meantime by calling the Winapi from DBPro I'd be made up with where I'm at.

Warning! May contain Nuts!
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 14th Jul 2011 00:27
Take a look at the TICKER commands - they allow you to set periodic or one-off timers that tick at the rate you specify, and that may do the job for you.

There's almost no difference between them and using windows messages to drive timing of events in your program.

If you still want to go down the messaging route, then you can create a timer yourself via the User32.DLL, and intercept DBPro's message loop using the SET MESSAGE CALLBACK command looking for WM_TIMER messages.

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 16th Jul 2011 23:55
Here's an example:


The main downside of this method is that every message that is passed to DBPro is passed to this function - remember that DBPro is NOT fast at this stuff, so there will be a performance impact. I've also used the DLL functions built into my plug-ins to call the SetTimer/KillTimer functions, mainly because I haven't used them for a while and wanted the practice

WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 17th Jul 2011 01:58 Edited at: 17th Jul 2011 02:10
IanM, you are a god send. That will help a hell of a lot with a lot of things I'm playing about with now.

The speed will not be an issue as of yet, as I'm sure I can get around that by just keeping the callback function simple and without calling other functions. DBPro does call a function that calls a function that calls a function, etc... which decreases performance.

Straight away I'm implementing this into my library I'm starting to save up.

Thanks so much again...

(there are so many uses for interrupts like this)

Warning! May contain Nuts!

Login to post a reply

Server time is: 2026-07-10 15:31:11
Your offset time is: 2026-07-10 15:31:11