Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Feb 1, 2014 19:09:03 GMT 1
I created a shared object (.so) of the Brandy BASIC V (BBC BASIC) SDL graphics library and plan to show how it can be used with BaCon. Keeping with Peter's initial intent of BaCon, I think the BBC graphics library will be interesting to those looking for a Linux BASIC with an old school graphics theme. This is not to be viewed as competing with the the fine work the guys have done with advanced topics like Gtk embedding, Goo and other efforts you would normally see on the GNOME Gtk project site.
I will be posting a few BaCon BBC graphics examples soon.
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Feb 2, 2014 3:21:08 GMT 1
I think I'm close but something isn't working right in BaCon (2.5.1 beta) and the output is wrong. Update It isn't a 2.5.1 issue. It does the same thing in 2.4.0. I attached a Ubuntu 12.04 LTS 64 bit code for this example if you want to give it a try. I don't think the bbc.h is required for this example but it can't hurt. This same library works fine under ScriptBasic. FYI SDL 1.2 is a requirement. bacon_ufo.zip (26.25 KB) BaConThis is what is suppose to look like. (without half circle at top, time and window title) This is the BaCon code for the first image that is wrong. If you see something I missed, please let me know. ' UFO
PRAGMA INCLUDE bbc.h SDL.h PRAGMA OPTIONS -I/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT -DHAVE_OPENGL PRAGMA LDFLAGS m SDL bbc PROTO init_screen, emulate_origin, emulate_gcol, emulate_off, emulate_plot, end_screen
init_screen() emulate_origin(800, 600) xs = 2 ys = 2 emulate_gcol(0, 14) emulate_off() a = 700 b = a * a c = 600 FOR x = 0 TO a STEP xs s = x * x p = SQR(b - s) FOR i = -p TO p STEP 6 * ys r = SQR(s + i * i) / a q = (r - 1) * SIN(24 * r) y = INT(i / 3 + q * c) IF i = -p THEN m = y n = y ENDIF IF y > m THEN m = y IF y < n THEN n = y IF m = y OR n = y THEN emulate_plot(69, NOT(x), y) emulate_plot(69, x, y) ENDIF NEXT NEXT INPUT wait$ end_screen()
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Feb 2, 2014 5:45:21 GMT 1
There really is something weird going on with the UFO example. I was able to get the graphdemo working first shot and do a direct call to the SDL iibrary to assign the window title. Another nice benefit of using the BBC library (SDL and soon to be introduced, SDL_draw) is that I can compile this on Android. ' Graph Demo
PRAGMA INCLUDE bbc.h SDL.h PRAGMA OPTIONS -I/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT -DHAVE_OPENGL PRAGMA LDFLAGS m SDL bbc PROTO init_screen, emulate_mode, emulate_origin, emulate_move, emulate_draw, end_screen, SDL_WM_SetCaption
init_screen() SDL_WM_SetCaption("BaCon BBC graphdemo", 0) emulate_mode(31) emulate_origin(800, 600) xlow = -10 xhigh = 10 ylow = -10 yhigh = 10 depth = 10 xscale = 30 yscale = 12 c = -4000
FOR x = xlow TO xhigh emulate_move(xscale*(x+ylow), yscale*(ylow-x)+c/(x*x+ylow*ylow+depth)) FOR y = ylow TO yhigh emulate_draw(xscale*(x+y), yscale*(y-x)+c/(x*x+y*y+depth)) NEXT NEXT FOR y = ylow TO yhigh emulate_move(xscale*(xlow+y), yscale*(y-xlow)+c/(xlow*xlow+y*y+depth)) FOR x = xlow TO xhigh emulate_draw(xscale*(x+y), yscale*(y-x)+c/(x*x+y*y+depth)) NEXT NEXT INPUT wait$ end_screen()
|
|
|
Post by alexfish on Feb 2, 2014 6:15:03 GMT 1
Hi John
think this may be a logical problem as regards the NOT(*0) , in bacon it is generally used as is NOT so if *value = positive then result will = 0 if *value = 1 then result will = 0
have Brandy basic on my sys . and original ufo demo runs , + chechecked the values of x looks to start at -1 then gets less / did not wait for the loop to finish
as q test use this to give the -value
xs = 2 ys = 2 'emulate_gcol(0, 14) 'emulate_off() a = 700 b = a * a c = 600 FOR x = 0 TO a STEP xs s = x * x p = SQR(b - s) FOR i = -p TO p STEP 6 * ys r = SQR(s + i * i) / a q = (r - 1) * SIN(24 * r) y = INT(i / 3 + q * c) IF i = -p THEN m = y n = y ENDIF IF y > m THEN m = y IF y < n THEN n = y IF m = y OR n = y THEN PRINT " m n y " PRINT -x 'emulate_plot(69, NOT(x), y) 'emulate_plot(69, x, y) ENDIF NEXT NEXT
HTH Alex
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Feb 2, 2014 6:36:14 GMT 1
Alex,
It's nice to have an interactive version of the BASIC that drives this to debug the library code. I still need to create a translation document (BBC BASIC to libbbc.so) so it's easier to use when converting BBC BASIC code.
I tried the -x substitution for NOT(x) as my first attempt to fix this. I does display the left half but still a problem with Y. (along with anything else I could think of) Gut tells me there is a bug in BaCon but I can't put my finger on it yet. I moved on to the other demos I'm converting to see if I can find a pattern or this problem unique to the UFO demo?
Thanks for helping out!
|
|
|
Post by bigbass on Feb 2, 2014 6:55:04 GMT 1
Hey John I have to do some testing with this in BaCon but I just compiled this for linux mint 16 and packaged it it works with the package with the original demo graphdemo as is brandy examples/graphdemo dependency apt-get install libsdl1.2-dev /brandy_1.20-1_i386.debexamples.tar.gzwill take a poke at it and see what happens its late now will try tomorrow (a long day today) Joe
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Feb 2, 2014 7:44:55 GMT 1
I'll get the 32 bit Ubuntu binaries and source for libbbc.so posted in the morning. (long day) BaCon is going to remove the interpretive aspect and flush out how lame the SDL library is compared to David Burnhard's Windows version of Brandy. (as Richard & David claims) It would be nice to come up with a way to ALIAS the function names like I do in SB to make it look more BBC BASIC like.
Thanks for the help Joe!
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Feb 2, 2014 8:40:31 GMT 1
Attached is the source to libbbc.so. Place this file in the Brandy BASIC V src directory and use the following to create the shared object. libbbc.c.zip (25.11 KB) gcc -shared -fPIC -o libbbc.so libbbc.c -I/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT -DHAVE_OPENGL -lSDL -lm
Enjoy!
|
|
|
Post by bitvast on Feb 2, 2014 10:54:40 GMT 1
Thanks John, this looks cool.
|
|
|
Post by Pjot on Feb 2, 2014 13:35:10 GMT 1
Hi John,
Nice! For the first program, there are two reasons why it is not drawing correctly.
(1) As mentioned, the 'NOT(x)' construct doesn't work like you would like to. It just returns a '0' or '1'. So, in the program you have to say '-x' instead.
(2) More importantly, when it comes to numeric values, BaCon by default considers numerical variables to be of 'long' type. Therefore, if you want to use floating numbers, you explicitly must declare this.
In an earlier post (can't find it anymore) I proposed to have floating type as a default, as it covers both floating and integer numbers. Also it would solve some nasty internal BaCon issues. Maybe worth considering again?
Anyway, below the corrected program.
BR, Peter
PRAGMA INCLUDE bbc.h SDL.h PRAGMA OPTIONS -I/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT -DHAVE_OPENGL -L. PRAGMA LDFLAGS SDL bbc PROTO init_screen, emulate_mode, emulate_origin, emulate_gcol, emulate_off, emulate_plot, end_screen
DECLARE p, i, r, q TYPE FLOATING
init_screen() emulate_mode(31) emulate_origin(800, 600) xs = 2 ys = 2 emulate_gcol(0, 14) emulate_off() a = 700 b = a * a c = 600 FOR x = 0 TO a STEP xs s = x * x p = SQR(b - s) FOR i = -p TO p STEP 6 * ys r = SQR(s + i * i) / a q = (r - 1) * SIN(24 * r) y = INT(i / 3 + q * c) IF i = -p THEN m = y n = y ENDIF IF y > m THEN m = y IF y < n THEN n = y IF m = y OR n = y THEN emulate_plot(69, -x, y) emulate_plot(69, x, y) ENDIF NEXT NEXT INPUT wait$ end_screen()
|
|
|
Post by bigbass on Feb 2, 2014 17:59:45 GMT 1
Hey guys I uploaded a new deb for linux mint 16 32 bit with the libbbc.so included in the package this way just install and everything goes where it should be to keep it easy BTW where did you get that file libbb.c ? I couldn't locate a source brandy_1.20-1_i386.debI had to modify just the header path for it to work in mint ? PRAGMA INCLUDE /usr/include/SDL/SDL.h PRAGMA INCLUDE /usr/src/linux-headers-3.11.0-12/arch/sparc/include/asm/bbc.h using Peter's fixed code example it compiles and works correctly ! Thanks Joe
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Feb 2, 2014 18:16:36 GMT 1
I was a victim of the SB typeless conversion. In BBC BASIC if the variable doesn't have a % after it then it's a floating point value. If I would of use the Brandy UFO code instead of the SB code I converted, it would of worked for me. Thanks Peter for being there! One thing we need to address real soon is keyboard support. I wrote functions for this in the SB extension module for GETKEY and WAITKEY which isn't included in the libbbc.so library. SDL 2.1 doesn't support UNICODE so it's a little messy but manageable. ' UFO
PRAGMA INCLUDE bbc.h SDL.h PRAGMA OPTIONS -I/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT -DHAVE_OPENGL PRAGMA LDFLAGS m SDL bbc PROTO init_screen, emulate_mode, emulate_origin, emulate_gcol, emulate_off, emulate_plot, end_screen, SDL_WM_SetCaption
DECLARE p, i, r, q TYPE FLOATING
init_screen() SDL_WM_SetCaption("BaCon BBC UFO", 0) emulate_mode(31) emulate_origin(800, 600) xs = 2 ys = 2 emulate_gcol(0, 14) emulate_off() a = 700 b = a * a c = 600 FOR x = 0 TO a STEP xs s = x * x p = SQR(b - s) FOR i = -p TO p STEP 6 * ys r = SQR(s + i * i) / a q = (r - 1) * SIN(24 * r) y = INT(i / 3 + q * c) IF i = -p THEN m = y n = y ENDIF IF y > m THEN m = y IF y < n THEN n = y IF m = y OR n = y THEN emulate_plot(69, -x, y) emulate_plot(69, x, y) ENDIF NEXT NEXT INPUT wait$ end_screen()
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Feb 2, 2014 19:04:13 GMT 1
libbbc.c was created from the Brandy graphsdl.c file to make the BBC shared object. It is one of the libraries I use in the ScriptBasic SDL extension module which also includes, SDL_draw, SDL_image and SDL_terminal along with a few SDL functions I wrote to fill in the holes. I attached my bbc.h I created / hacked but at this point it doesn't look like it's needed for the demos being posted. The value will be the BBC #define's. bbc.h.zip (2.56 KB)
|
|
|
Post by bitvast on Feb 2, 2014 20:06:22 GMT 1
In an earlier post (can't find it anymore) I proposed to have floating type as a default, as it covers both floating and integer numbers. Also it would solve some nasty internal BaCon issues. Maybe worth considering again?
Peter, I for one would be in favour of having float as default. I'm still sometimes caught out by numbers being 'long'. Besides, it seems more "BASIC like" to have numbers be either floating or integer (or both). You still have the flexibility of using DECLARE, and it's one less thing for the programmer to think about!
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Feb 2, 2014 20:22:31 GMT 1
My vote is for BaCon to follow BBC's lead and use % for longs and default non-declared variables to float.
Here are a few routines from the ScriptBasic SDL extension module that may help with the BaCon BBC project. The bit rotates/shifts functions were contributions from Charles Pegge. (OxygenBasic author) The code looks like BASIC due to the SB native extension module macro / define API Peter Verhas implemented early on in the initial design and the C BASIC icing to finish the job.
besFUNCTION(SB_RGB) DIM AS const SDL_PixelFormat PTR const format; DIM AS const Uint8 r, g, b; DIM AS Uint32 color; besARGUMENTS("iii") AT r, AT g, AT b besARGEND color = SDL_MapRGB(screen->format, r, g, b); besRETURN_LONG(color); besEND
// WaitKey besFUNCTION(SB_WaitKey) DIM AS int done ; DIM AS SDL_Event event; done = 0; WHILE (NOT done) BEGIN_WHILE WHILE (SDL_WaitEvent(AT event)) BEGIN_WHILE SELECT_CASE (event.type) BEGIN_SELECT CASE SDL_KEYDOWN: CASE SDL_QUIT: done = 1; SDL_Quit(); END_CASE CASE_ELSE END_CASE END_SELECT WEND WEND besRETURNVALUE = NULL; besEND
// GetKey besFUNCTION(SB_GetKey) DIM AS int done ; DIM AS SDL_Event event; DIM AS char tmpstr[80]; done = 0; WHILE (NOT done) BEGIN_WHILE WHILE (SDL_WaitEvent(AT event)) BEGIN_WHILE SELECT_CASE (event.type) BEGIN_SELECT CASE SDL_KEYDOWN: strcpy (tmpstr,"+"); strcat (tmpstr,SDL_GetKeyName(event.key.keysym.sym)); besRETURN_STRING(tmpstr); done = 1; END_CASE CASE SDL_KEYUP: strcpy (tmpstr,"-"); strcat (tmpstr,SDL_GetKeyName(event.key.keysym.sym)); besRETURN_STRING(tmpstr); done = 1; END_CASE CASE SDL_QUIT: done = 1; SDL_Quit(); END_CASE CASE_ELSE END_CASE END_SELECT WEND WEND besEND
// Ticks besFUNCTION(SB_Ticks) DIM AS Uint32 ticks; ticks = SDL_GetTicks(); besRETURN_LONG(ticks); besEND
// UpdateRect besFUNCTION(SB_UpdateRect) SDL_UpdateRect(screen, 0, 0, 0, 0); besRETURNVALUE = NULL; besEND
// CLS besFUNCTION(SB_CLS) DIM AS Uint32 color; besARGUMENTS("i") AT color besARGEND SDL_FillRect(screen, AT screen->clip_rect, color); SDL_UpdateRect(screen, 0, 0, 0, 0); besRETURNVALUE = NULL; besEND
besFUNCTION(SB_shifts) DIM AS int bp, co, v, x, y, d, p, ar; besARGUMENTS("ii[i]") AT v, AT p, AT ar besARGEND IF (ar EQ NULL) THEN_DO ar = 0; x = 0xffffffff & v; IF (p >= 0) THEN y = x << p; // bit shift left ELSE y = x >> (-p); // bit shift right END_IF // // SUPPORT FOR ARITHMETIC RIGHT SHIFTS // IF ((ar) AND (p < 0) AND (x & 0x80000000)) THEN d = 31 + p; IF (d < 0) THEN_DO d = 0; // LIMIT bp = 0x80000000; FOR (co = 31 TO co >= d STEP DECR co) BEGIN_FOR y = y | bp; bp = bp >> 1; NEXT END_IF besRETURN_LONG(y); besEND
besFUNCTION(SB_rotates) DIM AS int co, v, x, y, d, p; besARGUMENTS("ii") AT v, AT p besARGEND x = 0xffffffff & v; d = p & 0x1f; FOR (co = 1 TO co <= d STEP INCR co) BEGIN_FOR y = x << 1; IF (x & 0x80000000) THEN_DO y |= 1; x = y; NEXT besRETURN_LONG(x & 0xffffffff); besEND
|
|