Oxygen Basic

Programming => Example Code => Graphics => Topic started by: JRS on February 08, 2014, 09:39:00 PM

Title: libbbc.dll - C BASIC
Post by: JRS on February 08, 2014, 09:39:00 PM
If anyone would like to give the BBC Graphics libbbc.dll a try with O2, the DLL and source are attached. I have tried it with SB & DLLC and it works great. Direct calls to SDL are also permitted. The libbbc fork of the Brandy BASIC V SDL graphics library was rewritten using C BASIC.

Note: SDL 1.2 needs to be installed for libbbc.dll to work.






.
Title: Re: libbbc.dll - C BASIC
Post by: Charles Pegge on February 09, 2014, 02:40:36 AM
Thanks John,  is it just SDL.DLL that is required?
Title: Re: libbbc.dll - C BASIC
Post by: JRS on February 09, 2014, 02:49:07 AM
I think so. Take a peek at the SB / DLLC version I posted on All BASIC.

Title: Re: libbbc.dll - C BASIC
Post by: JRS on February 11, 2014, 01:36:59 AM
Charles,

Are you able to use the libbbc5.h file with O2? It has everything in the header and only functions / subs in the libbbc5.c source file.

John
Title: Re: libbbc.dll - C BASIC
Post by: Charles Pegge on February 11, 2014, 09:53:27 AM

Hi John,
A few more header problems to solve. It's keeping me very busy, but I can get it to accept the header now.
Title: Re: libbbc.dll - C BASIC
Post by: JRS on February 11, 2014, 07:13:17 PM
Sounds great! Here is the C BASIC libbbc5.dll and polygon.c example running on Windows XP. The attached zip includes binaries and source for both.

(http://files.allbasic.info/C_BASIC/cbpolygon-xp.png)

Code: [Select]
// C BASIC Polygon

#include <stdio.h>
#include <math.h>
#include <SDL.h>
#include "libbbc5.h"
#include "cbasic.h"

#define PI 3.14159265358979323846

MAIN
BEGIN_FUNCTION
  DIM AS float64 angle, radius, x[10], y[10];
  DIM AS int32 c, t, d, side, sides, xorigin, yorigin, i, l;
  DIM AS Uint32 t1, t2, t3;
  DIM AS char strbuff[15];
  BBC_OPEN();
  BBC_MODE(32);
  t1 = SDL_GetTicks();
  SDL_WM_SetCaption("C BASIC BBC5 - polygon", 0);
  BBC_VDU(26);
  DEF_FOR (i = 1 TO i <= 1000 STEP INCR i)
  BEGIN_FOR
    xorigin = BBC_RND(1250);
    yorigin = BBC_RND(840);
    radius = BBC_RND(300) + 50;
    BBC_ORIGIN(xorigin, yorigin);
    sides = BBC_RND(8) + 2;
    BBC_MOVE(radius, 0);
    BBC_MOVE(10, 10);
    c = BBC_RND(64) - 1;
    t = BBC_SHIFT(BBC_RND(4) - 1, 6, 0);
    BBC_GCOL(0, c, t);
    DEF_FOR (side = 1 TO side <= sides STEP INCR side)
    BEGIN_FOR
      angle = (side -1) * 2 * PI / sides;
      x[side] = radius * cos(angle);
      y[side] = radius * sin(angle);
      BBC_MOVE(0, 0);
      BBC_PLOT(85, x[side], y[side]);
    NEXT
    BBC_MOVE(0, 0);
    BBC_PLOT(85, radius, 0);
    DO
      d = BBC_RND(64) - 1;
    WHILE ((d & 63) != (c & 6));
    BBC_GCOL(0, d, t);
    DEF_FOR (side = 1 TO side <= sides STEP INCR side)
    BEGIN_FOR
      DEF_FOR (l = side TO l <= sides STEP INCR l)
      BEGIN_FOR
        BBC_MOVE(x[side], y[side]);
        BBC_DRAW(x[l], y[l]);
      NEXT
    NEXT
  NEXT
  t2 = SDL_GetTicks();
  t3 = (t2 - t1) / 1000;
  sprintf(strbuff, "%d.4 Seconds.", t3);
  BBC_OFF();
  BBC_VDUSTR(strbuff, 0);
  DEF_WHILE (BBC_GETKEY() != SDLK_ESCAPE)
  BEGIN_WHILE
  WEND
//  BBC_WAITKEY();
  BBC_CLOSE();
  RETURN_FUNCTION(0);
END_FUNCTION

Code: [Select]
F:\libbbc>gcc polygon.c -o polygon.exe -I C:/MinGW32/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT -DHAVE_OPENGL -lmingw32 lSDLmain -lSDL -mwindows libbbc5.dll -lm

Here is the Android version of the above. The same (untouched) code ran on 64 bit Linux, 32 bit Windows and on ARM. (Android 32 bit Linux)

(http://files.allbasic.info/C_BASIC/polygon_android.png)



.
Title: Re: libbbc.dll - C BASIC
Post by: Emil_halim on February 12, 2014, 08:33:48 AM
Hi John,

I liked the idea of C BASIC itself, the great point that it does not need any exe to translate the Basic style to C code.

where can i fine it's site.

thanks.
Title: Re: libbbc.dll - C BASIC
Post by: Charles Pegge on February 12, 2014, 08:41:28 AM

Hi Emil,

Our board for C Basic is here:

http://www.allbasic.info/forum/index.php?board=18.0
Title: Re: libbbc.dll - C BASIC
Post by: Emil_halim on February 12, 2014, 08:54:52 AM
Hi Charles,

thank you for your reply.

i will check it.

 
Title: Re: libbbc.dll - C BASIC
Post by: JRS on February 12, 2014, 09:27:43 AM
The C preprocessor is a nice feature to help make C easier to read and use. The ScriptBasic API is a good example of this concept in use. C BASIC is still in it's early conceptual state but is useful for making existing C code more readable. It's still missing many of the BASIC language features that would allow it to be used for development. A fun project no less.

Title: Re: libbbc.dll - C BASIC
Post by: Emil_halim on February 12, 2014, 11:32:32 AM


I think i will use cbasic.h and i will add some stuff that fit my needs.

thanks.
Title: Re: libbbc.dll - C BASIC
Post by: JRS on February 12, 2014, 12:07:22 PM
Please share whatever you add to cbasic.h.

Title: Re: libbbc.dll - C BASIC
Post by: Emil_halim on February 12, 2014, 12:11:10 PM

 ofcourse i will. 
Title: Re: libbbc.dll - C BASIC
Post by: Kuron on February 12, 2014, 12:55:29 PM
where can i fine it's site.

There is not a site/forums open to the public (which is intentionally keeping people from participating and preventing a community from growing around it), but I am going to put a section on the forums I am setting up.  It does deserve some promotions and being opened to others.
Title: Re: libbbc.dll - C BASIC
Post by: JRS on February 12, 2014, 01:09:22 PM
The project site for C BASIC is HERE (https://bitbucket.org/ScriptBasic/c-basic). It has a git based file repository, wiki and incident tracking feature. It's open to the public and allows for making requests and commenting on direction.

Title: Re: libbbc.dll - C BASIC
Post by: Kuron on February 12, 2014, 02:13:54 PM
The project site for C BASIC is HERE (https://bitbucket.org/ScriptBasic/c-basic). It has a git based file repository, wiki and incident tracking feature. It's open to the public and allows for making requests and commenting on direction.

Like I said, there is NOT a community site and it can't grow without one.  I can understand wanting to keep it under wraps though, as it is still in the very early stages.  However, don't get upset that people are actually interested in the project and want to explore it.
Title: Re: libbbc.dll - C BASIC
Post by: JRS on February 12, 2014, 03:43:34 PM
The All Basic Developer forum has a mailing list and IRC/chat feature for non-developer interaction. The Bitbucket site also allows anyone to post comments and issues. Most BASIC projects and forums have less than a dozen active members. I think you would be hard pressed to find another BASIC project more active than O2 & SB. It sounds like FB is trying to stay relevant with a C emitter translator that generates 64 bit code. ASM BASIC compilers don't have the draw they once did. With the speed of PCs and the industry upside down, portability is more of a concern.

 I added BBC_MOUSE based on vovchik's BaCon routine to the libbbc5 library. (current source on Bitbucket)

Code: [Select]
#include <stdio.h>
#include <math.h>
#include <SDL.h>
#include "libbbc5.h"
#include "cbasic.h"

MAIN
BEGIN_FUNCTION
  DIM AS int m, i;
  BBC_OPEN();
  DEF_FOR (i = 1 TO i <= 3 STEP INCR i)
  BEGIN_FOR
    m = BBC_MOUSE(2);
    PRINT ("Button: = %i\n", m);
    m = BBC_MOUSE(0);
    PRINT ("X: = %i\n", m);
    m = BBC_MOUSE(1);
    PRINT ("Y: = %i\n", m);
  NEXT
  BBC_WAITKEY();
  BBC_CLOSE();
  RETURN_FUNCTION(0);
END_FUNCTION  

jrs@laptop:~/libbbc$ ./mouse
Button: = 1
X: = 426
Y: = 8
Button: = 2
X: = 461
Y: = 164
Button: = 3
X: = 173
Y: = 362
jrs@laptop:~/libbbc$
Title: Re: libbbc.dll - C BASIC
Post by: Kuron on February 12, 2014, 07:58:54 PM
Quote
The All Basic Developer forum has a mailing list
Mailing lists died back in the 20th century.

Quote
and IRC/chat feature for non-developer interaction.
Which I had to ask you to go into the one time, as nobody ever uses it.

Quote
I think you would be hard pressed to find another BASIC project more active than O2 & SB.
Yes, O2 is active, which is why CBASIC needs to move here where people using it and exploring it can actually discuss it, instead of the Chris Boss/Bob Zale tactics being used to keep it suppressed and intentionally keep everybody out.

Quote
ASM BASIC compilers don't have the draw they once did.
BASIC itself is dead.  PureBasic is the last actively developed and supported commercial BASIC.

Quote
It sounds like FB is trying to stay relevant with a C emitter translator that generates 64 bit code.
They brought out the C emitter years ago, but it never went anywhere.  But, it seems they are finally trying for 64-bit, which is a must-have.  At least FB actually has a usable forum. ;D
Title: Re: libbbc.dll - C BASIC
Post by: JRS on February 12, 2014, 08:24:33 PM
Out of the 40+ members we have here only a handful post and even less contribute. The All BASIC Developer forum with it's 10 BASIC developers is all I have time for along with managing the ScriptBasic project. I think that C BASIC needs more of an effort by others as I seem to be the only one forging a direction with it. It's not ready for hobbyist or causal interest users and needs BASIC developers and advocates to actively participate in its maturity. Feel free to roll up your sleeves and make something happen. My plate is full.
Title: Re: libbbc.dll - C BASIC
Post by: Emil_halim on February 13, 2014, 08:31:36 AM
Hi all,

Here is my approach , it is far form basic keywords , but it is more readable than c.

header add to cbasic.h
=================
Quote
#define ExportThis  __declspec(dllexport)
#define ImportThis  __declspec(dllimport)
#define DLL_MAIN ExportThis BOOL _stdcall DllMain(HINSTANCE hThisInstance,DWORD fdwReason, LPVOID lpvReserved) { return 1;}

#define int WINAPI WinMain (HINSTANCE hThisInstance,HINSTANCE hPrevInstance,LPSTR lpszArgument,int nCmdShow)
#define Currnt_Ver hThisInstance
#define Last_Ver hPrevInstance
#define Show_Win(x) ShowWindow(x, nCmdShow)
#define Events_BLock LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
#define EventsAddrBlock WindowProcedure
#define SELECT_Event switch (message)
#define If_Event case
#define Do_That :
#define Unknown_Event default:
#define End_Event break;
#define Call_def_Event DefWindowProc (hwnd, message, wParam, lParam);
#define AddrOf &


Example c
=========
Code: [Select]

#include <windows.h>
#include "cbasic.h"


Events_BLock
  begin
    SELECT_Event                            /* handle the messages */
      begin
        If_Event WM_DESTROY Do_That
               PostQuitMessage(0);          /* send a WM_QUIT to the message queue */
               End_Event
        Unknown_Event                       /* for messages that we don't deal with */
               return Call_def_Event
      end
    return 0;
  end


/*  Make the class name into a global variable  */
char szClassName[] = "CodeBlocksWindowsApp";

WinMain
 begin
    DIM AS HWND hwnd;               /* This is the handle for our window */
    DIM AS MSG messages;            /* Here messages to the application are saved */
    DIM AS WNDCLASSEX wincl;        /* Data structure for the windowclass */

    /* The Window structure */
    wincl.hInstance = Currnt_Ver;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = EventsAddrBlock;      /* This function is called by windows */
    wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
    wincl.cbSize = sizeof (WNDCLASSEX);

    /* Use default icon and mouse-pointer */
    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;                 /* No menu */
    wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
    wincl.cbWndExtra = 0;                      /* structure or the window instance */
    /* Use Windows's default colour as the background of the window */
    wincl.hbrBackground = CAST(COLOR_BACKGROUND,HBRUSH);

    /* Register the window class, and if it fails quit the program */
    if (!RegisterClassEx (AddrOf wincl))
        return 0;

    /* The class is registered, let's create the program*/
    hwnd = CreateWindowEx (
           0,                   /* Extended possibilites for variation */
           szClassName,         /* Classname */
           "Code::Blocks Template Windows App",       /* Title Text */
           WS_OVERLAPPEDWINDOW, /* default window */
           CW_USEDEFAULT,       /* Windows decides the position */
           CW_USEDEFAULT,       /* where the window ends up on the screen */
           544,                 /* The programs width */
           375,                 /* and height in pixels */
           HWND_DESKTOP,        /* The window is a child-window to desktop */
           NULL,                /* No menu */
           hThisInstance,       /* Program Instance handler */
           NULL                 /* No Window Creation data */
           );

    /* Make the window visible on the screen */
    Show_Win((hwnd);

    /* Run the message loop. It will run until GetMessage() returns 0 */
    while (GetMessage (AddrOf messages, NULL, 0, 0))
      begin
        /* Translate virtual-key messages into character messages */
        TranslateMessage(AddrOf messages);
        /* Send message to WindowProcedure */
        DispatchMessage(AddrOf messages);
      end

    /* The program return-value is 0 - The value that PostQuitMessage() gave */
    return messages.wParam;
 end

thanks.
Title: Re: libbbc.dll - C BASIC
Post by: JRS on February 13, 2014, 08:43:18 AM
If C++ is your platform, have a look at JADE (https://bitbucket.org/Airr/jade) which is Armando's (AIR) C++ version of C BASIC.

Thanks for the post and hope you expand on it more.

Title: Re: libbbc.dll - C BASIC
Post by: Kuron on February 13, 2014, 06:11:02 PM
The All BASIC Developer forum with it's 10 BASIC developers is all I have time for along with managing the ScriptBasic project. I think that C BASIC needs more of an effort by others as I seem to be the only one forging a direction with it... needs BASIC developers and advocates to actively participate in its maturity. Feel free to roll up your sleeves and make something happen. My plate is full.
No worries.  Since it is not open to more developers, I will fork it and any addons will be applied to the fork.
Title: Re: libbbc.dll - C BASIC
Post by: JRS on February 13, 2014, 08:03:10 PM
Quote
Since it is not open to more developers, I will fork it and any addons will be applied to the fork.

Brice,

I have invited you in the past to join the All BASIC Developer forum and co-develop C BASIC. At the time you said you had a BASIC of your own that you were working on. The offer still stands.

John