1. EuAllegro Help
- Posted by Icy_Viking Aug 13, 2019
- 1370 views
Hello all,
I am working on updating EuAllegro for the most current version of Allegro. I almost got it, but I'm having a little trouble with it.
C Code
#define ALLEGRO_RELEASE_NUMBER 1 #define ALLEGRO_VERSION_STR "5.2.5" #define ALLEGRO_DATE_STR "2019" #define ALLEGRO_DATE 20190224 /* yyyymmdd */ #define ALLEGRO_VERSION_INT \ ((ALLEGRO_VERSION << 24) | (ALLEGRO_SUB_VERSION << 16) | \ (ALLEGRO_WIP_VERSION << 8) | ALLEGRO_RELEASE_NUMBER | \ ALLEGRO_UNSTABLE_BIT)
Eu Code
--Wrapper Code public constant ALLEGRO_VERSION = 5, ALLEGRO_SUB_VERSION = 2, ALLEGRO_WIP_VERSION = 5 public constant ALLEGRO_RELEASE_NUMBER = 1 public constant ALLEGRO_UNSTABLE_BIT = 8589934592 public constant ALLEGRO_VERSION_INT = or_bits(ALLEGRO_VERSION * power(2, 24), or_bits(ALLEGRO_SUB_VERSION * power(2, 16), or_bits(ALLEGRO_WIP_VERSION * power(2, 8), or_bits(ALLEGRO_UNSTABLE_BIT * power (2, 4), ALLEGRO_RELEASE_NUMBER)))) --Sample Program --Display a simple window without warning include std/machine.e include EuAllegro.ew atom ret = al_install_system(ALLEGRO_VERSION_INT,0) --error comes from here, error is bad routine number -1 atom dis = al_create_display(800,600) al_set_new_window_title("Simple Window") al_flip_display() al_rest(5.0) al_destroy_display(dis)
2. Re: EuAllegro Help
- Posted by ghaberek (admin) Aug 13, 2019
- 1385 views
There are functions in std/math.e that will make those bit shifts easier. See or_all() and shift_bits().
public constant ALLEGRO_VERSION_INT = or_all({ shift_bits( ALLEGRO_VERSION, -24 ), shift_bits( ALLEGRO_SUB_VERSION, -16 ), shift_bits( ALLEGRO_WIP_VERSION, -8 ), ALLEGRO_UNSTABLE_BIT })
I don't think you should be setting ALLEGRO_UNSTABLE_BIT. AFAIK you should leave it at zero if you are using the release binaries. You should probably write your al_install_system() wrapper such that it first checks its ALLEGRO_VERSION_INT against the value returned by al_get_allegro_version(), and only proceed with calling al_install_system() if it matches.
If you're getting -1 for al_install_system() then check your output from open_dll() to make sure the library is loaded, and then check your define_c_func/proc() calls to make sure you're getting back proper function IDs (positive integers, not -1). You can load the library into Dependency Walker to make sure you're seeing the function names exported from the library. (I also recently discovered Dependencies which is a newer re-implementation of Dependency Walker for Windows 7 and up, but I haven't tried it yet. Might be worth a look.)
-Greg
3. Re: EuAllegro Help
- Posted by Icy_Viking Aug 13, 2019
- 1385 views
There are functions in std/math.e that will make those bit shifts easier. See or_all() and shift_bits().
public constant ALLEGRO_VERSION_INT = or_all({ shift_bits( ALLEGRO_VERSION, -24 ), shift_bits( ALLEGRO_SUB_VERSION, -16 ), shift_bits( ALLEGRO_WIP_VERSION, -8 ), ALLEGRO_UNSTABLE_BIT })
I don't think you should be setting ALLEGRO_UNSTABLE_BIT. AFAIK you should leave it at zero if you are using the release binaries. You should probably write your al_install_system() wrapper such that it first checks its ALLEGRO_VERSION_INT against the value returned by al_get_allegro_version(), and only proceed with calling al_install_system() if it matches.
If you're getting -1 for al_install_system() then check your output from open_dll() to make sure the library is loaded, and then check your define_c_func/proc() calls to make sure you're getting back proper function IDs (positive integers, not -1). You can load the library into Dependency Walker to make sure you're seeing the function names exported from the library. (I also recently discovered Dependencies which is a newer re-implementation of Dependency Walker for Windows 7 and up, but I haven't tried it yet. Might be worth a look.)
-Greg
Thanks for the tips. I've reformated to the new way. I've left out the UNSTABLE_BIT flag as it seems it was uneeded. However, I am now getting type_check failure ver is {83886080,131072,1280}, this is coming from the sample program al_install_system() function.
--misc flags public constant ALLEGRO_NEW_WINDOW_TITLE_MAX_SIZE = 255 public constant ALLEGRO_PI = 3.14159265358979323846 public constant ALLEGRO_VERSION_INT = ({shift_bits(ALLEGRO_VERSION,-24), shift_bits(ALLEGRO_SUB_VERSION,-16), shift_bits(ALLEGRO_WIP_VERSION,-8), ALLEGRO_RELEASE_NUMBER})
4. Re: EuAllegro Help
- Posted by ghaberek (admin) Aug 13, 2019
- 1328 views
Thanks for the tips. I've reformated to the new way. I've left out the UNSTABLE_BIT flag as it seems it was uneeded. However, I am now getting type_check failure ver is {83886080,131072,1280}, this is coming from the sample program al_install_system() function.
You left out the or_all() function.
public constant ALLEGRO_VERSION_INT = or_all({ -- or_all() goes here shift_bits(ALLEGRO_VERSION,-24), shift_bits(ALLEGRO_SUB_VERSION,-16), shift_bits(ALLEGRO_WIP_VERSION,-8), ALLEGRO_RELEASE_NUMBER })
-Greg
5. Re: EuAllegro Help
- Posted by Icy_Viking Aug 14, 2019
- 1342 views
Thanks for the tips. I've reformated to the new way. I've left out the UNSTABLE_BIT flag as it seems it was uneeded. However, I am now getting type_check failure ver is {83886080,131072,1280}, this is coming from the sample program al_install_system() function.
You left out the or_all() function.
public constant ALLEGRO_VERSION_INT = or_all({ -- or_all() goes here shift_bits(ALLEGRO_VERSION,-24), shift_bits(ALLEGRO_SUB_VERSION,-16), shift_bits(ALLEGRO_WIP_VERSION,-8), ALLEGRO_RELEASE_NUMBER })
-Greg
Thanks Greg, simple oversight. Ok, so I did an error check and it says the function is failing to register. I checked the DLL and the al_install_system() function is inside the DLL.
public constant xal_install_system = define_c_func(al,"+al_install_system",{C_INT,C_POINTER},C_BOOL) public function al_install_system(atom ver,atom x) return c_func(xal_install_system,{ver,x}) end function if xal_install_system = -1 then puts(1,"al_install_system failed!\n") --this does come up when I run the wrapper library abort(0) end if
6. Re: EuAllegro Help
- Posted by jmduro Aug 14, 2019
- 1335 views
Thanks Greg, simple oversight. Ok, so I did an error check and it says the function is failing to register. I checked the DLL and the al_install_system() function is inside the DLL.
public constant xal_install_system = define_c_func(al,"+al_install_system",{C_INT,C_POINTER},C_BOOL) public function al_install_system(atom ver,atom x) return c_func(xal_install_system,{ver,x}) end function if xal_install_system = -1 then puts(1,"al_install_system failed!\n") --this does come up when I run the wrapper library abort(0) end if
ver should always be set to ALLEGRO_VERSION_INT. x refers to a pointer. Is it set to NULL or allocated ?
Jean-Marc
7. Re: EuAllegro Help
- Posted by petelomax Aug 14, 2019
- 1342 views
There are functions in std/math.e that will make those bit shifts easier. See or_all() and shift_bits().
public constant ALLEGRO_VERSION_INT = or_all({ shift_bits( ALLEGRO_VERSION, -24 ), shift_bits( ALLEGRO_SUB_VERSION, -16 ), shift_bits( ALLEGRO_WIP_VERSION, -8 ), ALLEGRO_UNSTABLE_BIT })
fwiw, I would always prefer eg
public constant ALLEGRO_VERSION_INT = ALLEGRO_VERSION*#1000000 + ALLEGRO_SUB_VERSION*#10000 + ALLEGRO_WIP_VERSION*#100 + ALLEGRO_UNSTABLE_BIT and public constant ALLEGRO_UNSTABLE_BIT = #200000000
(I also recently discovered Dependencies which is a newer re-implementation of Dependency Walker for Windows 7 and up, but I haven't tried it yet. Might be worth a look.)
It sure is, works like a charm. Thanks for the tip.
8. Re: EuAllegro Help
- Posted by Icy_Viking Aug 14, 2019
- 1300 views
Thanks Greg, simple oversight. Ok, so I did an error check and it says the function is failing to register. I checked the DLL and the al_install_system() function is inside the DLL.
public constant xal_install_system = define_c_func(al,"+al_install_system",{C_INT,C_POINTER},C_BOOL) public function al_install_system(atom ver,atom x) return c_func(xal_install_system,{ver,x}) end function if xal_install_system = -1 then puts(1,"al_install_system failed!\n") --this does come up when I run the wrapper library abort(0) end if
ver should always be set to ALLEGRO_VERSION_INT. x refers to a pointer. Is it set to NULL or allocated ?
Jean-Marc
I have it set to 0, which I believe is basiclly the same as NULL, unless I'm mistaken.
--Display a simple window without warning include std/machine.e include EuAllegro.ew atom ret = al_install_system(ALLEGRO_VERSION_INT,0) atom dis = al_create_display(800,600) al_set_new_window_title("Simple Window") al_flip_display() al_rest(5.0) al_destroy_display(dis)
9. Re: EuAllegro Help
- Posted by ghaberek (admin) Aug 14, 2019
- 1305 views
I have it set to 0, which I believe is basiclly the same as NULL, unless I'm mistaken.
That is correct. It's defined in std/dll.e as literally public constant NULL = 0.
If you can see al_install_system in the DLL via Dependency Walker, then it should be found by define_c_func().
Check the output of open_dll() as well. Are you getting a large integer (memory address) or zero (DLL was not loaded)?
Which specific DLLs are you using? I'd like to download and test them on my system.
-Greg
10. Re: EuAllegro Help
- Posted by Icy_Viking Aug 14, 2019
- 1335 views
I have it set to 0, which I believe is basiclly the same as NULL, unless I'm mistaken.
That is correct. It's defined in std/dll.e as literally public constant NULL = 0.
If you can see al_install_system in the DLL via Dependency Walker, then it should be found by define_c_func().
Check the output of open_dll() as well. Are you getting a large integer (memory address) or zero (DLL was not loaded)?
Which specific DLLs are you using? I'd like to download and test them on my system.
-Greg
Yes I checked with the DLL dependency program, al_install_system() is included in the DLL. I'm using allegro-x86_64-w64-mingw32-gcc-8.2.1-posix-seh-dynamic-5.2.5.0 from https://github.com/liballeg/allegro5/releases/tag/5.2.5.0, the specific DLL is allegro-5.2.DLL