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 / Address of subroutine or function

Author
Message
TheLion
19
Years of Service
Recently Online
Joined: 30th Jun 2004
Location:
Posted: 24th Aug 2004 06:50
Hi,
I've had a quick look, carn't find anything about
returning a pointer address of a DB subroutine or function.

Is it possible to find such an address of a function or subroutine ??

Cheers Leo
OSX Using Happy Dude
20
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 24th Aug 2004 06:59
No, not possible.


Come to the UK Convention on the 23rd & 24th of October
TheLion
19
Years of Service
Recently Online
Joined: 30th Jun 2004
Location:
Posted: 24th Aug 2004 20:23
Hmmmm,
Well then, is Bass just Fmod wrapped up or is it
a complete separate sound engine ?

cheers Leo
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 24th Aug 2004 21:33
As far as I'm aware, BASSMOD and FMod are completely separate libraries.

In answer to your original question - maybe, possibly, but don't expect any details until I get interested in looking at it again ... which to be honest, may never happen

*** Coming soon - Network Plug-in - Check my site for info ***
For free Plug-ins, source and the Interface library for Visual C++ 6, .NET and now for Dev-C++ http://www.matrix1.demon.co.uk
OSX Using Happy Dude
20
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 24th Aug 2004 22:11
Yes, BASS & FMOD are completely seperate - designed to be used with C


Come to the UK Convention on the 23rd & 24th of October
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 25th Aug 2004 02:03
Damn - I got interested. I've worked out a possibility, so I'll try it out tonight and see what happens.

*** Coming soon - Network Plug-in - Check my site for info ***
For free Plug-ins, source and the Interface library for Visual C++ 6, .NET and now for Dev-C++ http://www.matrix1.demon.co.uk
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 25th Aug 2004 04:48
Current working code - things are looking quite good ATM



*** Coming soon - Network Plug-in - Check my site for info ***
For free Plug-ins, source and the Interface library for Visual C++ 6, .NET and now for Dev-C++ http://www.matrix1.demon.co.uk
OSX Using Happy Dude
20
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 25th Aug 2004 04:56
You might be onto something...


Come to the UK Convention on the 23rd & 24th of October
APEXnow
Retired Moderator
20
Years of Service
User Offline
Joined: 15th Apr 2003
Location: On a park bench
Posted: 25th Aug 2004 08:16
That's interesing...


Home of the Cartography Shop - DarkBASIC Professional map importer
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 25th Aug 2004 16:35
I've been looking at getting arguments passed on to the called function - I think I've got that straight in my head now. I just need to code it.

Then I need to work out a way to change an OS STDCALL callback to a DBPro CDECL system - that may be a little harder to arrange, but I'm hopeful.

*** Coming soon - Network Plug-in - Check my site for info ***
For free Plug-ins, source and the Interface library for Visual C++ 6, .NET and now for Dev-C++ http://www.matrix1.demon.co.uk
walaber
20
Years of Service
User Offline
Joined: 22nd Oct 2003
Location: Los Angeles, CA
Posted: 25th Aug 2004 16:58
very cool stuff... this opens some possibilities...

Go Go Gadget DBPRO!

Athlon XP 2400+ || DDR-SDRAM 1GB || Nvidia GeForce 4 Ti4200 AGP 8x 128MB
TheLion
19
Years of Service
Recently Online
Joined: 30th Jun 2004
Location:
Posted: 25th Aug 2004 21:48
Hi again,
firstly, thanks for having a look at creating
a way to achieve CallBack functions in DB pro, appreciate it!

I don't understand your cammands in the code snippet

RE: CALL FUNCTION PTR MyFN2_ptr

MyFN_ptr = GET CALLING FN()

both the above seem to throw errors out, are you just
looking at the logic?

Just a thought, since the CallBack functions are mainly
for Fmod or Bass to do you own DSP stuff on samples, I
suppose you could write it in assembler, load the code
into a memblock with pointers to the DSP buffers at the
start or the end of the code and just index into the
buffers as required to adjust and maniplate the samples,
the memblock buffers are accessible within DB pro so, should
have no trouble I think. I'm also sure this way would work
with Fmod, not sure about Bass only heard of the Bass sound engine since getting DB pro but hey! They both seem to be very similar from what I've read.

Regards Leo
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 25th Aug 2004 21:57
It won't run for anyone until they have the plug-in I'm writing. That code actually compiles and runs without error only on my machine.

If you knew what you were doing, then putting assembly into a memblock is a possible way of implementing a call-back.

The point of what I'm trying to do though is to make it possible for a BASIC programmer to do this, without also having to be an assembly guru as well.

*** Coming soon - Network Plug-in - Check my site for info ***
For free Plug-ins, source and the Interface library for Visual C++ 6, .NET and now for Dev-C++ http://www.matrix1.demon.co.uk
empty
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: 3 boats down from the candy
Posted: 25th Aug 2004 22:50
So does DBpro use the CPU stack and CDECL for internal function calls?

Quote: "Then I need to work out a way to change an OS STDCALL callback to a DBPro CDECL system - that may be a little harder to arrange, but I'm hopeful."

A way to change a stdcall callback?

Play Nice! Play Basic! Out now.

nFinity Emulator. Coming soon.
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 26th Aug 2004 03:27
Quote: " So does DBpro use the CPU stack and CDECL for internal function calls?"


It does indeed. Once your app is compiled, the system used to call your functions and to call DBPro functions/commands is identical.

It's technically possible to set things up so that you can switch from STDCALL to CDECL on the fly ... just not easy, and it's stretching my understanding of windows architecture to the limits

*** Coming soon - Network Plug-in - Check my site for info ***
For free Plug-ins, source and the Interface library for Visual C++ 6, .NET and now for Dev-C++ http://www.matrix1.demon.co.uk
empty
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: 3 boats down from the candy
Posted: 26th Aug 2004 04:03
Quote: "It does indeed. Once your app is compiled, the system used to call your functions and to call DBPro functions/commands is identical."

Interesting.


Quote: "It's technically possible to set things up so that you can switch from STDCALL to CDECL on the fly ... just not easy, and it's stretching my understanding of windows architecture to the limits "

Certainly it's technically possible (although hooking/injecting is the only method I can think of atm). But unless DBpro is doing something with the stack it shouldn't do when it returns from a routine, a little plugin function that manipulates the stack should do (you need to know the number function parameters though).

Play Nice! Play Basic! Out now.

nFinity Emulator. Coming soon.
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 26th Aug 2004 07:43
Currently, I've managed to call the function with 0 or more arguments correctly - next, I need to get return values working

The system that I've put in place *may* mean that working out the number of bytes to remove from the stack is relatively easy to calculate ... I hope.

A single function for STDCALL translation would do the job, if I knew ahead of time what function it is supposed to forward to, if I knew how much to readjust the stack by on return, and if I only wanted to have a single routine callable ... but I don't.

I'm trying to put together a system where you can have as many callbacks of as many different types as you like. Only time will tell if I can get there. If I can't, at least we'll still have internal function pointers

*** Coming soon - Network Plug-in - Check my site for info ***
For free Plug-ins, source and the Interface library for Visual C++ 6, .NET and now for Dev-C++ http://www.matrix1.demon.co.uk
empty
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: 3 boats down from the candy
Posted: 26th Aug 2004 07:49
Well if you know how many arguments have been passed to the function you could clean up the stack before it returns.

Play Nice! Play Basic! Out now.

nFinity Emulator. Coming soon.
Dave J
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Feb 2003
Location: Secret Military Pub, Down Under
Posted: 26th Aug 2004 15:02
Sweeet... I've been wondering how to do that for a long time! Although, the only reason I wanted the function's pointer was so I could call it from within my DLL... I don't suppose you'd be willing to tell us how...


"Computers are useless they can only give you answers."
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 26th Aug 2004 17:42
Once I've got it all worked out I'll be offering the DLL for free download. I might even pass on some of the detail to those who are interested - it's all pretty nasty stuff, because it takes certain liberties with the system but it seems solid enough. I'm not sure it'll survive a change to the compiler ... but I'll cross that bridge when we get to it.

I got the parameter stack-size calculation working for use in STDCALL routines last night. I just need to test it under a few more different conditions to make sure that its bullet-proof.

I've still got to get return values working properly, then I'll jump back to STDCALL again, putting together the 'alias' routines (don't know what else to call them), and *then* I'll work on a few more bits that are sort-of connected I thought of last night

*** Coming soon - Network Plug-in - Check my site for info ***
For free Plug-ins, source and the Interface library for Visual C++ 6, .NET and now for Dev-C++ http://www.matrix1.demon.co.uk
Jess T
Retired Moderator
20
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 26th Aug 2004 23:53
Heh, Really nice work Ian

You're an asset to the Community, and I thank you for this wonderfull effort put into a great DLL that can help so many, in so many ways

In summary:
Great Job!

Jess.


Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy
empty
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: 3 boats down from the candy
Posted: 27th Aug 2004 07:45
Well I had a quick try and came as far as this
http://members.lycos.co.uk/sotmailings/stuff/funcref.htm
Download the zip file, it contains
TPC, Keyword file, example "callback DLL" and a DBP example file included that looks like this:




Unfortunately I don't have more time for that currently.

Play Nice! Play Basic! Out now.

nFinity Emulator. Coming soon.
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 27th Aug 2004 21:44
Nice one

I was stalled on a compiler bug for a while, that I got over last thing last night (if returning an X type, you can't have a D parameter - the arglist gets screwed).

Have you implemented the STDCALL stuff yet, or is that still to do? I've sketched out the assembly for it so far, but haven't had a chance to try it.

*** Coming soon - Network Plug-in - Check my site for info ***
For free Plug-ins, source and the Interface library for Visual C++ 6, .NET and now for Dev-C++ http://www.matrix1.demon.co.uk
empty
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: 3 boats down from the candy
Posted: 27th Aug 2004 23:01
Quote: "Have you implemented the STDCALL stuff yet, or is that still to do? I've sketched out the assembly for it so far, but haven't had a chance to try it."


There's CONVERT TO STDCALL command although I'm not sure if I implemented it in this version. It's a bit dodgy anyway. Sometimes it works, sometimes it crashes, sometimes the DBP function returns wrong values- as I said it was a quick try. Since most compilers do frame the stack, you can usually get along without cleaning the stack. That's why the included callback.dll returns properly even though it uses stdcall to call the DB function. According to the debugger the stack is cleaned by the Delphi when the Delphi function exits, so you shouldn't get overflows. Haven't tried it with other compilers though.
Basically it uses the "Number of Argument" parameter to calculate where and how many stack entries it needs to delete. The problems is that you need to restore the local variables on the stack, and take care of the return value that DBP seems to push on the stack before it calls the TPC function (although DBP doesn't optimize local var storage, so it should be rather easy).
Anyways, will take a look at it when I have time.

Another thing is that I don't properly save and restore the registers. So this won't work
for i = 1 to 4
Call Function i
next i
but this will
for i = 1 to 4
a = i
Call Function a
next i

That might also be partly responsible for the other problems.

Play Nice! Play Basic! Out now.

nFinity Emulator. Coming soon.
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 28th Aug 2004 07:01
I did wonder how you managed to put out this DLL so fast. Although I can't claim to be an assembly coder, I thought I was going quite fast for my experience level.

Now that I've got the CDECL stuff working well, I thought I'd work on the STDCALL stuff

*** Coming soon - Network Plug-in - Check my site for info ***
For free Plug-ins, source and the Interface library for Visual C++ 6, .NET and now for Dev-C++ http://www.matrix1.demon.co.uk
empty
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: 3 boats down from the candy
Posted: 28th Aug 2004 16:56
Quote: "I did wonder how you managed to put out this DLL so fast. Although I can't claim to be an assembly coder, I thought I was going quite fast for my experience level."

After you told me that DBP uses CDECL too, I knew were to look, so to speak. I used Delphi with it's inline assembler. So I could code the internal management faster; and thanks to madshi's components analyse the DBpro function code on the fly. The disadvantage was that Delphi procedures do stuff automatically like stack framing, ignoring the ret commands under certain circumstances, and even if you turn off optimization it still optimizes several things. Working these things out took most of the time. All in all I spend around two hours on it- and that's why it still has quirks.

Play Nice! Play Basic! Out now.

nFinity Emulator. Coming soon.
empty
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: 3 boats down from the candy
Posted: 28th Aug 2004 22:33
I posted a little update on the WIP board. Convert to Stdcall now seems to work better.

Play Nice! Play Basic! Out now.

nFinity Emulator. Coming soon.
Rob K
Retired Moderator
21
Years of Service
User Offline
Joined: 10th Sep 2002
Location: Surrey, United Kingdom
Posted: 29th Aug 2004 01:27
Very clever Ian & Empty.

This has some very useful possibilities.

Whilst you're working on this, can you think of any way of getting pointers to variables or is that not possible at the moment?


BlueGUI:Windows UI Plugin - All the power of the windows interface in your DBPro games.
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 29th Aug 2004 03:57
@Empty,

I got external calls to both stdcall and cdecl routines running perfectly last night for up to 9 arguments being passed to the routine. You don't even need to worry about whether it is stdcall or cdecl either - a single function deals with both

Next, is to allow external windows routines to place callbacks into DBPro ... a little harder this one, but I have a system designed. I just need to implement it.

After that, I move onto optimisation - once a routine has been called once via the pointer, I could work out whether it is stdcall or cdecl routine that I've returned from, and I might be able to optimise the next call to the routine through a faster route.

@Rob,
I don't know just yet. I can't rule it out, but it certainly be a lot more difficult than what we have ATM.


Now I know why I didn't take up assembly language programming as a hobby - I shall be glad to return to straight C++ programming after this.

*** Coming soon - Network Plug-in - Check my site for info ***
For free Plug-ins, source and the Interface library for Visual C++ 6, .NET and now for Dev-C++ http://www.matrix1.demon.co.uk
empty
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: 3 boats down from the candy
Posted: 29th Aug 2004 05:24
Quote: "I got external calls to both stdcall and cdecl routines running perfectly last night for up to 9 arguments being passed to the routine. You don't even need to worry about whether it is stdcall or cdecl either - a single function deals with both

Next, is to allow external windows routines to place callbacks into DBPro ... a little harder this one, but I have a system designed. I just need to implement it.

After that, I move onto optimisation - once a routine has been called once via the pointer, I could work out whether it is stdcall or cdecl routine that I've returned from, and I might be able to optimise the next call to the routine through a faster route."

Good luck. I simply don't have the time to continue this journey. Too many open PlayWrite / PlayBasic tasks...


Quote: "Now I know why I didn't take up assembly language programming as a hobby - I shall be glad to return to straight C++ programming after this."

Well it's the x86 assembly. Compared to 68k (I miss you!) it's really several steps backwards.



@RobK
Quote: "Whilst you're working on this, can you think of any way of getting pointers to variables or is that not possible at the moment?"

Well, I'm sure there is away to either read the address of a variable or at least to change it. There are a few commands in DBpro that need an address, like "Read" or "Input". I have yet to investigate that further, though. A good disassembler might help... or Lee or Mike give us some hints. .

Play Nice! Play Basic! Out now.

nFinity Emulator. Coming soon.
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 29th Aug 2004 06:32
Unfortunately, the READ and INPUT type commands don't use an address. They are just a slightly different form of a function call returning a value

One of the INPUT resource strings:
INPUT%O*%?InputO@@YANXZ%Variable

The prototype for the mangled name converts to this:
double __cdecl InputO(void)

*** Coming soon - Network Plug-in - Check my site for info ***
For free Plug-ins, source and the Interface library for Visual C++ 6, .NET and now for Dev-C++ http://www.matrix1.demon.co.uk
empty
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: 3 boats down from the candy
Posted: 29th Aug 2004 06:35
Ah, pitty.

Play Nice! Play Basic! Out now.

nFinity Emulator. Coming soon.
Jess T
Retired Moderator
20
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 10th Sep 2004 21:46
Sorry to dig up an old post...

Any progress on either of the DLL's?

Both of these could be quite usefull!
I've had a look at empty's, but the documentation is a bit... lacking... so it's hard to understand what is to be passed to some of the commands

Jess.


Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 10th Sep 2004 21:52
I'm still having problems with both STDCALL callbacks, and with finding the time to fix it.

I could certainly look at releasing it tonight if you don't need windows to call internal routines - there won't be muh documentation for mine either, except for the readme.txt I always include.

*** Coming soon - Network Plug-in - Check my site for info ***
For free Plug-ins, source and the Interface library for Visual C++ 6, .NET and now for Dev-C++ http://www.matrix1.demon.co.uk
Jess T
Retired Moderator
20
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 10th Sep 2004 22:02
How do you mean if I don't need window's to call internal routines? Do you mean, if I don't need it to call API etc functions, or if I don't need it to call internal DBP commands?

If you could release what you have though, 'twould be nice to have a look at what you've got

Much appreciated,
Jess.


Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 11th Sep 2004 02:27
I mean if you don't need windows to call your DBPro routines ... the other way around. For example, you can't write your own WndProc yet, but I still aim to get that working sometime.

I'm just packaging up what I have, then I'll email it to you - I don't want to distribute it to the world yet, because I still have a lot of work to do on it ... and a lot more ideas to implement.

*** Coming soon - Network Plug-in - Check my site for info ***
For free Plug-ins, source and the Interface library for Visual C++ 6, .NET and now for Dev-C++ http://www.matrix1.demon.co.uk
empty
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: 3 boats down from the candy
Posted: 11th Sep 2004 02:52
Quote: "I've had a look at empty's, but the documentation is a bit... lacking... so it's hard to understand what is to be passed to some of the commands"

I'll add a readme later tonight.

Play Nice! Play Basic! Out now.

nFinity Emulator. Coming soon.
empty
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: 3 boats down from the candy
Posted: 11th Sep 2004 04:59
Before I upload a modified archive here's the readme (make sure you also read the remarks in the DBA source code)



Play Nice! Play Basic! Out now.

nFinity Emulator. Coming soon.
Jess T
Retired Moderator
20
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 11th Sep 2004 19:28
Props to both of you!

This is much appreciated, thanks guys

Now, off to test them

Jess.


Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy

Login to post a reply

Server time is: 2024-03-29 14:17:22
Your offset time is: 2024-03-29 14:17:22