Author Topic: AllegroBASIC  (Read 20559 times)

Tomaaz

  • Guest
Re: AllegroBASIC
« Reply #30 on: January 24, 2016, 10:44:34 PM »
Hm, very strange. You can be sure that I tested everything on Windows 10 and all works on my rather slow Netbook.

I'm pretty sure Win 10 is to blame. It wasn't pre-installed. I did an upgrade on this machine and you know - I heard a lot of stories about upgrading to Win 10.

Even stranger you can't open the Github page with the documentation...

Yeah. This is really strange. It was probably a problem with the website itself (on Linux I got a message that something went wrong etc.), but still - it shouldn't have crashed the browsers. Anyway. Linux version of AllegroBASIC seems to work fine.

wang renxin

  • Guest
Re: AllegroBASIC
« Reply #31 on: January 25, 2016, 04:33:28 AM »
Hi Markus,

I do feel excited to see your distribution. Works fine on my Win7 64bit, didn't get a Win10 and it seems it doesn't deserve to upgrade to it for the moment.

The referenced usertype was not enough documented, until now I added some detail in the Wiki.

I have a few questions with AllegroBASIC. How did you implemented resources, I tried following code but it crashed the IDE:

Code: [Select]
image=loadimage ("sprite.bmp")
back=loadbmp ("grass.bmp")
print image;
print back;

It shall use a customized mb_fmt_func_t ft functor to serialize a referenced usertype; or just prints "USERTYPE" for a (non-referenced) usertype generated as following:

Code: [Select]
mb_value_t ret;
mb_make_usertype(ret, 0);
mb_check(mb_push_value(s, l, ret));

Does it need to manually release resources which were loaded with following functions to avoid leakage:

Code: [Select]
loadsound
loadimage
loadbmp

I noticed it includes a "tickcount" function, is there another time utilitity function which returns elapsed time within a "sync" cycle? That would be useful for real time games to implement CPU frequency independent motion and animation.

Furthermore, it's able to import a common "keycodes.bas" file for key code definitions, and so on other common code. It's also probably useful to print the "char* f" parameter to tell the file name which an error occurs, eg:

Code: [Select]
static void _on_error(struct mb_interpreter_t* s, mb_error_e e, char* m, char* f, int p, unsigned short row, unsigned short col, int abort_code) {
mb_unrefvar(s);
mb_unrefvar(p);
if(SE_NO_ERR != e) {
if(f) {
_printf("Error:\n    [LINE] %d, [COL] %d, [FILE] %s,\n    [CODE] %d, [MESSAGE] %s, [ABORT CODE] %d.\n", row, col, f, e, m, abort_code);
} else {
_printf("Error:\n    [LINE] %d, [COL] %d,\n    [CODE] %d, [MESSAGE] %s, [ABORT CODE] %d.\n", row, col, e, m, abort_code);
}
}
}
« Last Edit: January 25, 2016, 04:55:40 AM by wang renxin »

Aurel

  • Guest
Re: AllegroBASIC
« Reply #32 on: January 25, 2016, 07:43:14 AM »
OK i download Allegro on my win7
run Tiny IDE and open examples folder then I try
Every program first open console window then open output standard system window
but you cannot close this output window then you must close
console window to exit program.
also something is wrong with parent definition because every time you run any
sample you see flash desktop window problem with HWND_DESKTOP
inside main window procedure
also when output window runing IDE content dissapear ?
(ps work little bit faster on my old XP comp  :o )
« Last Edit: January 25, 2016, 07:47:42 AM by Aurel »

jj2007

  • Guest
Re: AllegroBASIC
« Reply #33 on: January 25, 2016, 08:17:44 AM »
Runs fine on Win7-64, but as Aurel said,
- you can't close the main window
- it is unresponsive while the program is running
- and it's irritating that you get an exception when you close the console (the only way to end the program)

But the result looks very nice, compliments!

ScriptBasic

  • Guest
Re: AllegroBASIC
« Reply #34 on: January 25, 2016, 08:21:24 AM »
Pressing ESC when the program ends will return you back to the IDE which closes normally with the system title/tool bar exit method.

Aurel

  • Guest
Re: AllegroBASIC
« Reply #35 on: January 25, 2016, 09:09:07 AM »
Quote
Pressing ESC when the program ends will return you back to the IDE which closes normally with the system title/tool bar exit method
well yes but this is  a poor method ...
i think that someone need to learn better how to properly work with windows API

Aurel

  • Guest
Re: AllegroBASIC
« Reply #36 on: January 25, 2016, 09:11:54 AM »
Quote
I noticed it includes a "tickcount" function, is there another time utilitity function which returns elapsed time within a "sync" cycle?
yes of course this one:

Declare Function QueryPerformanceCounter   Lib "kernel32.dll" (ByRef lpPerformanceCount As LARGE_INTEGER) As Long
Declare Function QueryPerformanceFrequency Lib "kernel32.dll" (ByRef lpFrequency As LARGE_INTEGER) As Long

well how you don't know that?
experience with windows api functions wrappers helps a lot..
« Last Edit: January 25, 2016, 09:14:26 AM by Aurel »

wang renxin

  • Guest
Re: AllegroBASIC
« Reply #37 on: January 25, 2016, 10:28:46 AM »
I know that, anyway, thanks Aurel for copying and pasting _ticks from my_basic/shell/main.c here.
« Last Edit: January 25, 2016, 10:34:58 AM by wang renxin »

Aurel

  • Guest
Re: AllegroBASIC
« Reply #38 on: January 25, 2016, 05:15:19 PM »
Quote
I know that, anyway, thanks Aurel for copying and pasting _ticks from my_basic/shell/main

no need for thanks and this is  NOT copy/paste from your file then from mine
written in awinh.inc - Oxygen basic include file

also you can view it here:
http://www.oxygenbasic.org/forum/index.php?topic=307.45

« Last Edit: January 25, 2016, 05:19:59 PM by Aurel »

Cybermonkey

  • Administrator
  • *****
  • Posts: 0
Re: AllegroBASIC
« Reply #39 on: January 25, 2016, 07:22:54 PM »
Hi Markus,

I do feel excited to see your distribution. Works fine on my Win7 64bit, didn't get a Win10 and it seems it doesn't deserve to upgrade to it for the moment.

The referenced usertype was not enough documented, until now I added some detail in the Wiki.

I have a few questions with AllegroBASIC. How did you implemented resources, I tried following code but it crashed the IDE:

Code: [Select]
image=loadimage ("sprite.bmp")
back=loadbmp ("grass.bmp")
print image;
print back;

It shall use a customized mb_fmt_func_t ft functor to serialize a referenced usertype; or just prints "USERTYPE" for a (non-referenced) usertype generated as following:

Code: [Select]
mb_value_t ret;
mb_make_usertype(ret, 0);
mb_check(mb_push_value(s, l, ret));

Does it need to manually release resources which were loaded with following functions to avoid leakage:

Code: [Select]
loadsound
loadimage
loadbmp

I noticed it includes a "tickcount" function, is there another time utilitity function which returns elapsed time within a "sync" cycle? That would be useful for real time games to implement CPU frequency independent motion and animation.

Furthermore, it's able to import a common "keycodes.bas" file for key code definitions, and so on other common code. It's also probably useful to print the "char* f" parameter to tell the file name which an error occurs, eg:

Code: [Select]
static void _on_error(struct mb_interpreter_t* s, mb_error_e e, char* m, char* f, int p, unsigned short row, unsigned short col, int abort_code) {
mb_unrefvar(s);
mb_unrefvar(p);
if(SE_NO_ERR != e) {
if(f) {
_printf("Error:\n    [LINE] %d, [COL] %d, [FILE] %s,\n    [CODE] %d, [MESSAGE] %s, [ABORT CODE] %d.\n", row, col, f, e, m, abort_code);
} else {
_printf("Error:\n    [LINE] %d, [COL] %d,\n    [CODE] %d, [MESSAGE] %s, [ABORT CODE] %d.\n", row, col, e, m, abort_code);
}
}
}

Oh, I think I did that wrong because I didn't reference any usertype. I just "pushed" a usertype back:
Code: [Select]
static int bas_loadbmp (struct mb_interpreter_t* s, void** l) {
int result = MB_FUNC_OK;
char *filename;
BITMAP *image;

mb_assert(s && l);
mb_check(mb_attempt_open_bracket(s, l));
mb_check(mb_pop_string(s, l, &filename));
mb_check(mb_attempt_close_bracket(s, l));

image=load_bitmap (filename, NULL);

if (image) {
mb_check(mb_push_usertype(s,l,image));
}
else {
allegro_message ("Error reading image file %s", filename);
exit (1);
}

return result;
}

But if I use the ret value to assign a bitmap I got the following compile error:
Quote
allegrobasic.c:972: warning: assignment from incompatible pointer type
allegrobasic.c:989: warning: assignment from incompatible pointer type
allegrobasic.c:1008: error: cannot cast 'struct BITMAP *' to 'struct mb_value_t'
What did I wrong?

I will of course change the error message, so one can see in which module the error occured.

@jj2007: I totally forgot that people always want to click on the red "x" to close windows. I will add that soon. (But how do you close fullscreen windows?  ;))

@aurel: Of course I could compile AllegroBASIC that it does not need a console but it is intended because the PRINT and INPUT functions work with the CMD.exe.
Furthermore I do not use the WinAPI directly, the editor is done with Lazarus/Freepascal the graphics  output with Allegro. I don't use any WinAPI function directly because both programs are primarily developed on Linux. I also use TCC as the compiler for AllegroBASIC. You should wait for RETROBASIC which will use SDL2 (better window handling) and GCC as the main compiler. However, this won't change the behaviour of the editor, it just waits until the BASIC sctript execution has ended.

ScriptBasic

  • Guest
Re: AllegroBASIC
« Reply #40 on: January 25, 2016, 08:02:24 PM »
Markus,

Maybe you should give it a go in Script BASIC. It's multi-threaded and really easy to use. The C extension API makes the BASIC expansion unlimited on all platforms.

Just food for thought.


wang renxin

  • Guest
Re: AllegroBASIC
« Reply #41 on: January 26, 2016, 01:45:48 AM »
Markus,

That would be fine. The following two usage perform the same thing:

Code: [Select]
1. Yours
image = load_bitmap(filename, NULL);
mb_check(mb_push_usertype(s, l, image));

2. Same as
image = load_bitmap(filename, NULL);
mb_value_t ret;
mb_make_usertype(ret, image);
mb_check(mb_push_value(s, l, ret));

After that, it's able to retrieve a bitmap as:

Code: [Select]
1.
BITMAP* image = NULL;
mb_check(mb_pop_usertype(s, l, (void**)&image));

2.
BITMAP* image = NULL;
mb_value_t arg;
mb_check(mb_pop_value(s, l, &arg));
image = (BITMAP*)arg.value.usertype;

You don't need to call mb_ref_value or ??_ref_?? things for usertypes created from above, only mb_make_ref_value generates a referenced usertype. So I think you need some releasing functions for non-referenced usertype.

BTW. if you use the BITMAP* or other resources directly as the usertype data, it won't carry any type information representing for if it's a BITMAP, or an IMAGE, or something else... Why not use a struct wrapper:

Code: [Select]
// Pseudo code
struct AllegroBASICObject {
enum type;
void* data;
};

Then you could do different things according to different type.

Best.

jj2007

  • Guest
Re: AllegroBASIC
« Reply #42 on: January 26, 2016, 08:34:43 AM »
@jj2007: I totally forgot that people always want to click on the red "x" to close windows.

Markus,

Windows gives you three standard options to close a window: the "x", the system menu in the upper left corner, and pressing Alt F4. Part of the success story of Microsoft Windows is that the user gets a uniform interface, and therefore does not have to dig into the source code to discover the "inkey", which btw does not react to Alt F4 for some reason.

Similar for the IDE: If the source is not saved, it gives you an idiosyncratic prompt. Standard would be "Save changes?", "Yes/No/Cancel", and instead of clicking, you could press y, n or Escape without any risk to take a wrong decision.

Don't take this as a criticism, more as an observation. Quite often I noticed in the old bp.org that people (especially with Linux experience) do not follow the Windows logic. For example, there was a long thread about CPU usage going up with BASIC programs because of a bad implementation of GetMessage(). I do hate Windows, and wish Mr Gates should go to jail to pay for the damage he has done, but standardisation is one of the few positive aspects...

Aurel

  • Guest
Re: AllegroBASIC
« Reply #43 on: January 26, 2016, 05:42:17 PM »
Quote
The mandelbrot sample code came along with AllegroBASIC takes ~63 seconds on my i7 PC
hi wang
i cannot believe 63 seconds on i7  :o

Cybermonkey

  • Administrator
  • *****
  • Posts: 0
Re: AllegroBASIC
« Reply #44 on: January 26, 2016, 09:02:35 PM »
Markus,

That would be fine. The following two usage perform the same thing:

Code: [Select]
1. Yours
image = load_bitmap(filename, NULL);
mb_check(mb_push_usertype(s, l, image));

2. Same as
image = load_bitmap(filename, NULL);
mb_value_t ret;
mb_make_usertype(ret, image);
mb_check(mb_push_value(s, l, ret));

After that, it's able to retrieve a bitmap as:

Code: [Select]
1.
BITMAP* image = NULL;
mb_check(mb_pop_usertype(s, l, (void**)&image));

2.
BITMAP* image = NULL;
mb_value_t arg;
mb_check(mb_pop_value(s, l, &arg));
image = (BITMAP*)arg.value.usertype;

You don't need to call mb_ref_value or ??_ref_?? things for usertypes created from above, only mb_make_ref_value generates a referenced usertype. So I think you need some releasing functions for non-referenced usertype.

BTW. if you use the BITMAP* or other resources directly as the usertype data, it won't carry any type information representing for if it's a BITMAP, or an IMAGE, or something else... Why not use a struct wrapper:

Code: [Select]
// Pseudo code
struct AllegroBASICObject {
enum type;
void* data;
};

Then you could do different things according to different type.

Best.

Hi Wang,

I changed the "retrieving" functions and added the (void**) cast. It's now possible to print the bitmap, sound or whatever. The result is USERTYPE.  This will be part of the next upload.
And a question: Is it possible to interrupt a script and exit the program? I want to implement  a check if the window close button was clicked. In Allegro it looks like that:
Code: [Select]
void close_button_handler(void)   {
 
 exit (EXIT_SUCCESS);
 }
END_OF_FUNCTION(close_button_handler)

And in the init part:
Code: [Select]
LOCK_FUNCTION(close_button_handler);
set_close_button_callback(close_button_handler);

But if I close the window I always get a  segementation fault ...

My atexit() function looks like this:
Code: [Select]
static void _on_exit(void) {

  mb_close(&bas);
  mb_dispose();
  remove_sound();
  allegro_exit();
}