Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Feb 3, 2014 19:58:16 GMT 1
Sweet!
Notice the artifacts? (random lines) David Burnard fixed Brandy's overflow issue in the RND function and BaCon looks like it has the same issue. I think the bbc_rnd will solve these BBC BASIC RND specific problems. It handles both the float and integer return values based on range.
The KEY_WAIT and ALIAS updates were a nice improvement to the BBC library support.
|
|
|
Post by vovchik on Feb 3, 2014 20:16:58 GMT 1
Dear John,
Thanks. I see the artefacts, too, so I welcome anything that might get rid of them. Are they only with RANDOM? Or is brandy not getting the right numvar type passed somewhere along the line?
With kind regards, vovchik
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Feb 3, 2014 20:34:03 GMT 1
This is the line that fixed the overflow issue.
push_int(TOINT( (randomfraction()*TOFLOAT(value))+1) );
+1 was added. David also changed the seeding to use the millisecond time value rather than a hard coded value with a twist.
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Feb 4, 2014 3:54:43 GMT 1
I'm working on a makeover of the libbbc code base. The goal is to be able to compile the library standalone without needing support from Brandy. I'm doing a C BASIC conversion to make the code more readable to BASIC programmers in an effort to promote enhancing the library by the folks that would have the most interest in doing so. Here is a peek of a few local functions that have already been converted. I plan to change the exported function names (BBC_XXXX) to eliminate the need to ALIAS them. I also plan to add a few of the SB extension module functions to make the libbc interface more like a complete BBC BASIC graphics plug-in. (keyboard, RND, RGB and other functions that make sense)
LOCAL SUB trace_edge(int32 x1, int32 y1, int32 x2, int32 y2) BEGIN_SUB DIM AS int32 dx, dy, xf, yf, a, b, t, i; IF (x1 EQ x2 AND y1 EQ y2) THEN_DO EXIT_SUB; IF (x2 > x1) THEN dx = x2 - x1; xf = 1; ELSE dx = x1 - x2; xf = -1; END_IF IF (y2 > y1) THEN dy = y2 - y1; yf = 1; ELSE dy = y1 - y2; yf = -1; END_IF IF (dx > dy) THEN a = dy + dy; t = a - dx; b = t - dx; DEF_FOR (i = 0 TO i <= dx STEP INCR i) BEGIN_FOR IF (x1 < left[y1]) THEN_DO left[y1] = x1; IF (x1 > right[y1]) THEN_DO right[y1] = x1; x1 += xf; IF (t < 0) THEN t += a; ELSE t += b; y1 += yf; END_IF NEXT ELSE a = dx + dx; t = a - dy; b = t - dy; DEF_FOR (i = 0 TO i <= dy STEP INCR i) BEGIN_FOR IF (x1 < left[y1]) THEN_DO left[y1] = x1; IF (x1 > right[y1]) THEN_DO right[y1] = x1; y1 += yf; IF (t < 0) THEN t += a; ELSE t += b; x1 += xf; END_IF NEXT END_IF END_SUB
LOCAL SUB draw_h_line(SDL_Surface PTR sr, int32 sw, int32 sh, int32 x1, int32 y, int32 x2, Uint32 col) BEGIN_SUB DIM AS int32 tt, i; IF (x1 > x2) THEN tt = x1; x1 = x2; x2 = tt; END_IF IF ( y >= 0 AND y < sh ) THEN IF (x1 < 0) THEN_DO x1 = 0; IF (x1 >= sw) THEN_DO x1 = sw-1; IF (x2 < 0) THEN_DO x2 = 0; IF (x2 >= sw) THEN_DO x2 = sw-1; DEF_FOR (i = x1 TO i <= x2 STEP INCR i) BEGIN_FOR PTR ((Uint32 PTR)sr->pixels + i + y * sw) = col; NEXT END_IF END_SUB
LOCAL SUB buff_convex_poly(SDL_Surface PTR sr, int32 sw, int32 sh, int32 n, int32 PTR x, int32 PTR y, Uint32 col) BEGIN_SUB DIM AS int32 i, iy; DIM AS int32 low = MAX_YRES, high = 0; DEF_FOR (i = 0 TO i < n STEP INCR i) BEGIN_FOR IF (y[i] > high) THEN_DO high = y[i]; IF (y[i] < low) THEN_DO low = y[i]; NEXT DEF_FOR (iy = low TO iy <= high STEP INCR iy) BEGIN_FOR left[iy] = MAX_XRES + 1; right[iy] = - 1; NEXT trace_edge(x[n - 1], y[n - 1], x[0], y[0]); DEF_FOR (i = 0 TO i < n - 1 STEP INCR i) BEGIN_FOR trace_edge(x[i], y[i], x[i + 1], y[i + 1]); NEXT DEF_FOR (iy = low TO iy <= high STEP INCR iy) BEGIN_FOR draw_h_line(sr, sw, sh, left[iy], iy, right[iy], col); NEXT END_SUB
LOCAL SUB draw_line(SDL_Surface PTR sr, int32 sw, int32 sh, int32 x1, int32 y1, int32 x2, int32 y2, Uint32 col) BEGIN_SUB DIM AS int d, x, y, ax, ay, sx, sy, dx, dy, tt; IF (x1 > x2) THEN tt = x1; x1 = x2; x2 = tt; tt = y1; y1 = y2; y2 = tt; END_IF dx = x2 - x1; ax = ABS(dx) << 1; sx = ((dx < 0) ? -1 : 1); dy = y2 - y1; ay = ABS(dy) << 1; sy = ((dy < 0) ? -1 : 1); x = x1; y = y1; IF (ax > ay) THEN d = ay - (ax >> 1); DEF_WHILE (x != x2) BEGIN_WHILE IF ((x >= 0) AND (x < sw) AND (y >= 0) AND (y < sh)) THEN_DO PTR ((Uint32 PTR)sr->pixels + x + y * sw) = col; IF (d >= 0) THEN y += sy; d -= ax; END_IF x += sx; d += ay; WEND ELSE d = ax - (ay >> 1); DEF_WHILE (y != y2) BEGIN_WHILE IF ((x >= 0) AND (x < sw) AND (y >= 0) AND (y < sh)) THEN_DO PTR ((Uint32 PTR)sr->pixels + x + y * sw) = col; IF (d >= 0) THEN x += sx; d -= ay; END_IF y += sy; d += ax; WEND END_IF IF ((x >= 0) AND (x < sw) AND (y >= 0) AND (y < sh)) THEN_DO PTR ((Uint32 PTR)sr->pixels + x + y * sw) = col; END_SUB
LOCAL SUB filled_triangle(SDL_Surface PTR sr, int32 sw, int32 sh, int32 x1, int32 y1, int32 x2, int32 y2, int32 x3, int32 y3, Uint32 col) BEGIN_SUB DIM AS int x[3], y[3]; x[0]=x1; x[1]=x2; x[2]=x3; y[0]=y1; y[1]=y2; y[2]=y3; buff_convex_poly(sr, sw, sh, 3, x, y, col); END_SUB
LOCAL SUB draw_ellipse(SDL_Surface PTR sr, int32 sw, int32 sh, int32 x0, int32 y0, int32 a, int32 b, Uint32 c) BEGIN_SUB DIM AS int32 x, y, y1, aa, bb, d, g, h; DIM AS Uint32 PTR dest; aa = a * a; bb = b * b; h = (FAST_4_DIV(aa)) - b * aa + bb; g = (FAST_4_DIV(9 * aa)) - (FAST_3_MUL(b * aa)) + bb; x = 0; y = b; DEF_WHILE (g < 0) BEGIN_WHILE IF (((y0 - y) >= 0) AND ((y0 - y) < sh)) THEN dest = ((Uint32 PTR)sr->pixels + x0 + (y0 - y) * sw); IF (((x0 - x) >= 0) AND ((x0 - x) < sw)) THEN_DO PTR (dest - x) = c; IF (((x0 + x) >= 0) AND ((x0 + x) < sw)) THEN_DO PTR (dest + x) = c; END_IF IF (((y0 + y) >= 0) AND ((y0 + y) < sh)) THEN dest = ((Uint32 PTR)sr->pixels + x0 + (y0 + y) * sw); IF (((x0 - x) >= 0) AND ((x0 - x) < sw)) THEN_DO PTR (dest - x) = c; IF (((x0 + x) >= 0) AND ((x0 + x) < sw)) THEN_DO PTR (dest + x) = c; END_IF IF (h < 0) THEN d = ((FAST_2_MUL(x)) + 3) * bb; g += d; ELSE d = ((FAST_2_MUL(x)) + 3) * bb - FAST_2_MUL((y - 1) * aa); g += (d + (FAST_2_MUL(aa))); INCR y; END_IF h += d; INCR x; WEND y1 = y; h = (FAST_4_DIV(bb)) - a * bb + aa; x = a; y = 0; DEF_WHILE (y <= y1) BEGIN_WHILE IF (((y0 - y) >= 0) AND ((y0 - y) < sh)) THEN dest = ((Uint32 PTR)sr->pixels + x0 + (y0 - y) * sw); IF (((x0 - x) >= 0) AND ((x0 - x) < sw)) THEN_DO PTR (dest - x) = c; IF (((x0 + x) >= 0) AND ((x0 + x) < sw)) THEN_DO PTR (dest + x) = c; END_IF IF (((y0 + y) >= 0) AND ((y0 + y) < sh)) THEN dest = ((Uint32 PTR)sr->pixels + x0 + (y0 + y) * sw); IF (((x0 - x) >= 0) AND ((x0 - x) < sw)) THEN_DO PTR (dest - x) = c; IF (((x0 + x) >= 0) AND ((x0 + x) < sw)) THEN_DO PTR (dest + x) = c; END_IF IF (h < 0) THEN h += ((FAST_2_MUL(y)) + 3) * aa; ELSE h += (((FAST_2_MUL(y) + 3) * aa) - (FAST_2_MUL(x - 1) * bb)); INCR x; END_IF INCR y; WEND END_SUB
LOCAL SUB filled_ellipse(SDL_Surface PTR sr, int32 sw, int32 sh, int32 x0, int32 y0, int32 a, int32 b, Uint32 c) BEGIN_SUB DIM AS int32 x, y, y1, aa, bb, d, g, h; aa = a * a; bb = b * b; h = (FAST_4_DIV(aa)) - b * aa + bb; g = (FAST_4_DIV(9 * aa)) - (FAST_3_MUL(b * aa)) + bb; x = 0; y = b; DEF_WHILE (g < 0) BEGIN_WHILE draw_h_line(sr, sw, sh, x0 - x, y0 + y, x0 + x, c); draw_h_line(sr, sw, sh, x0 - x, y0 - y, x0 + x, c); IF (h < 0) THEN d = ((FAST_2_MUL(x)) + 3) * bb; g += d; ELSE d = ((FAST_2_MUL(x)) + 3) * bb - FAST_2_MUL((y - 1) * aa); g += (d + (FAST_2_MUL(aa))); INCR y; END_IF h += d; INCR x; WEND y1 = y; h = (FAST_4_DIV(bb)) - a * bb + aa; x = a; y = 0; DEF_WHILE (y <= y1) BEGIN_WHILE draw_h_line(sr, sw, sh, x0 - x, y0 + y, x0 + x, c); draw_h_line(sr, sw, sh, x0 - x, y0 - y, x0 + x, c); IF (h < 0) THEN h += ((FAST_2_MUL(y)) + 3) * aa; ELSE h += (((FAST_2_MUL(y) + 3) * aa) - (FAST_2_MUL(x - 1) * bb)); INCR x; END_IF INCR y; WEND END_SUB
|
|
|
Post by vovchik on Feb 4, 2014 9:29:40 GMT 1
Dear John, Nice idea. Please be aware that the math lib (libm) contains many reserved varnames/macros/functions, and vars such as y1, y2 may not work as expected as a result. I would use longer var varnames just to avoid this issue. I have already been a victim of this. And libm gets linked in automatically by bacon when a function such as COS is called, as I recall, so there is probably no need to have it explicitly in PROTO, although it doesn't hurt. With kind regards, vovchik
|
|
|
Post by bigbass on Feb 4, 2014 16:36:39 GMT 1
Hey guys how about at least one simple example and it took just a few minutes just ignore the word windows when you see it ok we can get around without that www.bbcbasic.co.uk/bbcwin/manual/bbcwin3.htmlbb4w.wikispaces.com/BBC+BASIC+Languagebb4w.wikispaces.com/Tutorialscheck the MODEs Joe ' ALIAS to make coding easy and add system calls
PRAGMA INCLUDE SDL.h PRAGMA OPTIONS -I/usr/include/SDL PRAGMA LDFLAGS m SDL bbc
PROTO init_screen ALIAS SCREEN PROTO emulate_mode ALIAS MODE PROTO emulate_origin ALIAS ORIGIN PROTO emulate_off ALIAS OFF PROTO emulate_gcol ALIAS GCOLOR PROTO emulate_draw ALIAS DRAW PROTO emulate_move ALIAS MOVE PROTO end_screen ALIAS ENDSCREEN PROTO SDL_WM_SetCaption ALIAS TITLE PROTO system ALIAS SYS
SCREEN() TITLE("BaCon BBC system test", 0) MODE(9) ORIGIN(200, 100) OFF() GCOLOR(0, 10) x = 0 y = 0
SYS ("ls") MOVE ( 250,200) MOVE( 500,300) DRAW(205,150,350)
INPUT wait$
ENDSCREEN()
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Feb 4, 2014 18:27:45 GMT 1
Thanks Joe & vovchik for participating in the BaCon BBC library project. You guys make a great team! Here is screen shot of Joe's last example with a minor change. ' ALIAS to make coding easy and add system calls
PRAGMA INCLUDE SDL.h PRAGMA OPTIONS -I/usr/include/SDL PRAGMA LDFLAGS m SDL bbc
PROTO init_screen ALIAS SCREEN PROTO emulate_mode ALIAS MODE PROTO emulate_origin ALIAS ORIGIN PROTO emulate_off ALIAS OFF PROTO emulate_gcol ALIAS GCOLOR PROTO emulate_draw ALIAS DRAW PROTO emulate_move ALIAS MOVE PROTO emulate_vdustr ALIAS GPRINT PROTO end_screen ALIAS ENDSCREEN PROTO SDL_WM_SetCaption ALIAS TITLE
SCREEN() TITLE("BaCon BBC system test", 0) MODE(9) ORIGIN(200, 100) OFF() GCOLOR(0, 10) x = 0 y = 0 GPRINT ("BBC Old School Graphics", 0) MOVE ( 250,200) MOVE( 500,300) DRAW(205,150,350)
INPUT wait$
ENDSCREEN()
|
|
|
Post by vovchik on Feb 4, 2014 20:47:37 GMT 1
Dear John, Nice and simple. Reminds me of something I may have once done on my Commodore Pet (32k RAM!), although it ws monochrome. With kind regards, vovchik
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Feb 4, 2014 21:35:43 GMT 1
Changing screen MODEs is a nice feature. The text display based on MODE is also cool. This project may be the first BBC (like) BASIC C translator.
|
|
|
Post by konaexpress on Feb 4, 2014 21:41:42 GMT 1
Ummmmmm.....
Just wondering as to what you are trying to do with this idea?
Is it a "wonder if I can do this?" kind of thing?
John
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Feb 4, 2014 21:49:07 GMT 1
I was hoping that naming the library LIBBBC would make it obvious. I'm trying to make the libbbc library as friendly to use as IUP. I personally don't see any value in the core BBC BASIC as a language but the simplified graphics syntax is appealing.
|
|
|
Post by alexfish on Feb 4, 2014 22:33:25 GMT 1
Hi John As regards a BBC compiler there was or used to be a Compiler for BBC or RE BASIC5 I think Also as regards the Naming LIb/BBC as far as the Linux Community is Concerned there is on offer a BBC module from RT best read here. BBC Module . LinuxAs regards using the SDL lib Re: the aspect of a lib that used by BRANDY using BaCon with the Simplified SYNTAX is very Appealing BR Alex
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Feb 4, 2014 22:55:41 GMT 1
I purchased a copy of BBC4W and invited Richard to join the All BASIC Developer forum which he did. I gave BBC4W an objective review. I suggested the best direction for Richard was to capitalize on the RaspBerry PI / dev board craze and provide a RISC based BBC4ARM that carters to hobbyists looking for cheap fun. He could package a board and his BASIC in (E)ROM and it could be the next LEGO of dev board projects. He said I was full of shit in not so many words so I moved on.
Just a reminder, this is compilable on Android native (C4droid) with the same UI as a desktop. (no code changes required)
|
|
|
Post by vovchik on Feb 5, 2014 16:54:58 GMT 1
Dear all,
Here is a little BBC-BaCon flood fill demo:
' FloodFill - RosettaCode BBC BASIC
' *********************** ' COMPILER DIRECTIVES ' ***********************
PRAGMA INCLUDE SDL.h PRAGMA OPTIONS -I/usr/include/SDL PRAGMA LDFLAGS m SDL bbc
' *********************** ' END COMPILER DIRECTIVES ' ***********************
' *********************** ' EXTERNAL FUNCTIONS ' ***********************
PROTO init_screen ALIAS SCREEN PROTO emulate_modefn ALIAS GETMODE PROTO emulate_mode ALIAS MODE PROTO emulate_origin ALIAS ORIGIN PROTO emulate_off ALIAS OFF PROTO emulate_gcol ALIAS GCOLOR PROTO emulate_move ALIAS MOVE PROTO emulate_vdustr ALIAS GPRINT PROTO end_screen ALIAS ENDSCREEN PROTO emulate_vdu ALIAS VDU PROTO emulate_point ALIAS POINT PROTO emulate_line ALIAS LINE PROTO emulate_circle ALIAS CIRCLE PROTO SDL_WM_SetCaption ALIAS TITLE PROTO SDL_PollEvent ALIAS BBC_GETKEY PROTO SDL_GL_SetAttribute ALIAS SDL_ATTRIBUTE
' *********************** ' END EXTERNAL FUNCTIONS ' ***********************
' *********************** ' SUBS & FUNCTIONS ' ***********************
' ------------------ SUB FLOOD(int X, int Y, int C) ' ------------------ LOCAL L, R TYPE int ' PRINT POINT(X, Y) IF POINT(X, Y) <> C THEN GOTO SKIP END IF L = X R = X WHILE POINT(L - 2, Y) = C DO DECR L, 2 WEND WHILE POINT(R + 2, Y) = C DO INCR R, 2 WEND LINE(L, Y, R, Y) FOR X = L TO R STEP 2 CALL FLOOD(X, Y + 2, C) CALL FLOOD(X, Y - 2, C) NEXT LABEL SKIP END SUB
' ------------------ SUB KEY_WAIT() ' ------------------ LOCAL event TYPE SDL_Event WHILE TRUE DO WHILE BBC_GETKEY(&event) DO SELECT event.type CASE SDL_KEYUP ' If return is pressed, quit ' see http://www.libsdl.org/release/SDL-1.2.15/docs/html/sdlkey.html IF event.key.keysym.sym = SDLK_RETURN THEN OFF() ENDSCREEN() END 0 END IF CASE SDL_QUIT END 0 END SELECT WEND WEND END SUB
' ------------------ SUB ANTIALIAS() ' ------------------ SDL_ATTRIBUTE(SDL_GL_MULTISAMPLEBUFFERS, 1) SDL_ATTRIBUTE(SDL_GL_MULTISAMPLESAMPLES, 4) END SUB
' ------------------ SUB MK_DRAWING() ' ------------------ DECLARE FILL TYPE int FILL = 1 LOCAL x, y TYPE int LOCAL T1$, T2$, T3$ TYPE STRING T1$ = "BaCon BBC FLOOD FILL" T2$ = "BBC Old School Graphics" T3$ = "Press <RETURN> to quit" SCREEN() TITLE(T1$, 0) ANTIALIAS() MODE(32) VDU(5) PRINT "MODE: ", GETMODE() GCOLOR(0, 10, 5) ORIGIN(100, 120) CIRCLE(640, 512, 500, 1) GCOLOR(0, 3, 10) CIRCLE(500, 600, 200, 1) GCOLOR(0, 5, 6) FLOOD(600, 200, 15) ORIGIN(0, 0) MOVE(580, 100) GCOLOR(0, 2, 3) GPRINT(T2$, LEN(T2$)) GCOLOR(0, 2, 4) MOVE(585, 70) GPRINT(T3$, LEN(T3$)) END SUB
' *********************** ' END SUBS & FUNCTIONS ' ***********************
' *********************** ' MAIN ' ***********************
MK_DRAWING() KEY_WAIT()
' *********************** ' END MAIN ' ***********************
With kind regards, vovchik
|
|
|
Post by bigbass on Feb 5, 2014 17:37:01 GMT 1
Hey vovchik a very nice job with many things there ! you get a 100% on the rosetta challenge but you get many extra credit points for 1.)not using bbc but simulating it on bacon and having to invent some more alias 2.) for adding event handing (and before I had a chance to give it a try ) 3.) for creating a FLOOD routine 4.) just getting it ported from another language Joe
|
|