Author Topic: ScriptBasic SDL extension module  (Read 25081 times)

Offline John

  • Forum Support / SB Dev
  • Posts: 3570
    • ScriptBasic Open Source Project
Re: ScriptBasic SDL extension module - BBC graphics emulation
« Reply #45 on: January 22, 2014, 11:09:58 PM »
I'm going to take the time and deal with BBC BASIC at the language level rather than at the libbbc.so level with the SB SDL extension module. For example the GCOL command has a dozen variations depending how arguments are passed. Thankfully one of ScriptBasic's strong points is dealing with a variable number of arguments of any type. I will handle the (TINT,ON and OF) by passing the argument as a string. "TINT:8"

I'm still getting up to speed with BBC BASIC so a lot of research is needed on my part. Maybe I'll get lucky and Richard may find value in contributing to the libbbc.so project which in turn will generate more interest in BBC BASIC for Windows I would guess.

Code: [Select]
GCOL Syntax:

GCOL <colour expression>
GCOL <colour expression> TINT <tint expression>
GCOL <action expression> , <colour expression>
GCOL <action expression> , <colour expression> TINT <tint expression>
GCOL <red expression> , <green expression> , <blue expression>
GCOL OF <expression>
     ON <expression>
GCOL OF <action expression>, <expression>
     ON <action expression>, <expression>
GCOL OF <red expression>, <green expression>, <blue expression>
     ON <red expression>, <green expression>, <blue expression>
GCOL OF <action expression>, <red expression>, <green expression>, <blue expression>
     ON <action expression>, <red expression>, <green expression>, <blue expression>
« Last Edit: January 23, 2014, 11:44:31 AM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 3570
    • ScriptBasic Open Source Project
Re: ScriptBasic SDL extension module
« Reply #46 on: January 23, 2014, 06:38:31 PM »
I decided to go ahead with a direct wrap of the libbbc.so library rather than trying with this first past to emulate BBC BASIC at the language level. The BBC BASIC graphics are just another set of functions in the ScriptBasic SDL extension module as an option to the programmer to use. I'm not trying to turn SB in another BBC BASIC clone.

I was chatting with Richard and he brought up the point David Burnard made that his version of Brandy and the work he has done would easily port to SDL. If David would like to rejoin the group with the understanding there are multiple BBC BASIC related efforts going on, he is welcome to do so. If David could generate a DLL based on his direction, I would be overjoyed.

 
« Last Edit: January 23, 2014, 06:48:10 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 3570
    • ScriptBasic Open Source Project
Re: ScriptBasic SDL extension module - Brandy Mandelbrot
« Reply #47 on: January 25, 2014, 08:01:31 PM »
I finished interfacing to the Brandy BASIC V SDL graphics shared object I built. (libbbc.so) I'm trying to get the Brandy Mandelbrot working but I'm getting an out of range error reported by the library after the first iteration.

Quote from: BBC4W docs
Three numeric values follow the PLOT keyword: the first specifies the type of point, line, triangle, circle etc. to be drawn; the second and third give the X and Y coordinates to be used (in that order). The coordinates must be in the range −32768 to +32767.

This doesn't prevent the error even though I'm passing valid integer values.
Code: [Select]
    BBC_PLOT 69, INT(x), INT(y)
    BBC_PLOT 69, INT(x), INT(-y)

Here is what Brandy is showing.



Quote
jrs@laptop:~/sb/sb22/sdl$ scriba mandel.sb
X = 2
Y = 0
X = -2
Y = 5.000000e-03
X Error of failed request:  BadValue (integer parameter out of range for operation)
  Major opcode of failed request:  140 (MIT-SHM)
  Minor opcode of failed request:  3 (X_ShmPutImage)
  Value in failed request:  0xffff
  Serial number of failed request:  23
  Current serial number in output stream:  24
jrs@laptop:~/sb/sb22/sdl$

Here is the ScriptBasic code I'm using. Did I screw something up in the conversion? The numbers go nuts after the first iteration. ???

Code: [Select]
DECLARE SUB BBC_OPEN ALIAS "BBC_init_screen" LIB "sdl"
DECLARE SUB BBC_MODE ALIAS "BBC_emulate_mode" LIB "sdl"
DECLARE SUB BBC_ORIGIN ALIAS "BBC_emulate_origin" LIB "sdl"
DECLARE SUB BBC_GCOL ALIAS "BBC_emulate_gcol" LIB "sdl"
DECLARE SUB BBC_GCOLRGB ALIAS "BBC_emulate_gcolrgb" LIB "sdl"
DECLARE SUB BBC_OFF ALIAS "BBC_emulate_off" LIB "sdl"
DECLARE SUB BBC_PLOT ALIAS "BBC_emulate_plot" LIB "sdl"
DECLARE SUB BBC_CLOSE ALIAS "BBC_end_screen" LIB "sdl"
DECLARE SUB Ticks ALIAS "SB_Ticks" LIB "sdl"

BBC_OPEN
t1 = Ticks()
sizex = 800
sizey = 600
maxiter = 128
BBC_MODE 31
BBC_ORIGIN 0, sizey
FOR x = 0 TO 2 * sizex - 2 STEP 2
  xi = x / 400 - 2
  FOR y = 0 TO sizey - 2 STEP 2
    yi = y / 400
    x = 0
    y = 0
    i = 1
    WHILE i <= maxiter AND x * x + y * y <= 4
      xt = xi + x * x - y * y
      y = yi + 2 * x * y
      x = xt
      i = i + 1
    WEND
    IF i > maxiter THEN i = 0
    BBC_GCOLRGB 0, 0, i * 15, i * 8, 0
PRINT "X = ",x,"\n"
PRINT "Y = ",y,"\n"
    BBC_PLOT 69, x, y
    BBC_PLOT 69, x, -y
  NEXT y
NEXT x
t2 = Ticks()
t3 = (t2-t1)/1000
PRINT "Time: ",FORMAT("%.4f",t3)," seconds\n"
LINE INPUT WAIT
BBC_CLOSE
« Last Edit: January 25, 2014, 09:05:59 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 3570
    • ScriptBasic Open Source Project
Re: ScriptBasic SDL extension module - BBC BASIC Fern
« Reply #48 on: January 26, 2014, 01:19:18 PM »
I put the Mandelbrot issue aside and went on to the Fern example. Once again, the resulting time to complete mirrors the Brandy BASIC V Ubuntu 64 bit example.



Code: [Select]
' Fern

DECLARE SUB BBC_OPEN ALIAS "BBC_init_screen" LIB "sdl"
DECLARE SUB BBC_MODE ALIAS "BBC_emulate_mode" LIB "sdl"
DECLARE SUB BBC_ORIGIN ALIAS "BBC_emulate_origin" LIB "sdl"
DECLARE SUB BBC_GCOL ALIAS "BBC_emulate_gcol" LIB "sdl"
DECLARE SUB BBC_OFF ALIAS "BBC_emulate_off" LIB "sdl"
DECLARE SUB BBC_DRAW ALIAS "BBC_emulate_draw" LIB "sdl"
DECLARE SUB BBC_MOVE ALIAS "BBC_emulate_move" LIB "sdl"
DECLARE SUB BBC_PRINT ALIAS "BBC_emulate_vdustr" LIB "sdl"
DECLARE SUB BBC_CLOSE ALIAS "BBC_end_screen" LIB "sdl"
DECLARE SUB Ticks ALIAS "SB_Ticks" LIB "sdl"
DECLARE SUB BBC_RND ALIAS "BBC_RND" LIB "sdl"
DECLARE SUB GETKEY ALIAS "SB_GetKey" LIB "sdl"

BBC_OPEN
t1 = Ticks()
BBC_MODE 31
BBC_ORIGIN 200,100
BBC_OFF
BBC_GCOL 0,10
x=0
y=0
FOR i=1 TO 80000
  r = BBC_RND(1)
  IF r<=0.1 THEN
    A=0
    B=0
    C=0
    D=0.16
    E=0
    F=0
  END IF
  IF r>0.1 AND r<=0.86 THEN
    A=.85
    B=.04
    C=-.04
    D=.85
    E=0
    F=1.6
  END IF
  IF r>0.86 AND r<=0.93 THEN
    A=.2
    B=-.26
    C=.23
    D=.22
    E=0
    F=1.6
  END IF
  IF r>0.93 THEN
    A=-.15
    B =.28
    C=.26
    D=.24
    E=0
    F=.44
  END IF
  newx=A*x+B*y+E
  newy=C*x+D*y+F
  x=newx
  y=newy
  BBC_MOVE 600+96*x, 32+96*y
  BBC_DRAW 600+96*x, 32+96*y
NEXT i
t2 = Ticks()
t3 = (t2-t1)/1000
BBC_PRINT "Time: " & FORMAT("%.4f",t3) & " seconds"
WHILE GETKEY() <> "-escape"
WEND
BBC_CLOSE
« Last Edit: January 28, 2014, 06:21:28 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 3570
    • ScriptBasic Open Source Project
Re: ScriptBasic SDL extension module - BBC Graph Demo
« Reply #49 on: January 26, 2014, 02:37:45 PM »
Here is the BBC BASIC graphdemo example.



Code: [Select]
' Graph Demo

DECLARE SUB BBC_OPEN ALIAS "BBC_init_screen" LIB "sdl"
DECLARE SUB BBC_MODE ALIAS "BBC_emulate_mode" LIB "sdl"
DECLARE SUB BBC_ORIGIN ALIAS "BBC_emulate_origin" LIB "sdl"
DECLARE SUB BBC_DRAW ALIAS "BBC_emulate_draw" LIB "sdl"
DECLARE SUB BBC_MOVE ALIAS "BBC_emulate_move" LIB "sdl"
DECLARE SUB BBC_CLOSE ALIAS "BBC_end_screen" LIB "sdl"
DECLARE SUB WAITKEY ALIAS "SB_WaitKey" LIB "sdl"

BBC_OPEN
BBC_MODE 31
BBC_ORIGIN 800, 600
xlow = -10
xhigh = 10
ylow = -10
yhigh = 10
depth = 10
xscale = 30
yscale = 12
c = -4000

FOR x = xlow TO xhigh
  BBC_MOVE xscale*(x+ylow), yscale*(ylow-x)+c/(x*x+ylow*ylow+depth)
  FOR y = ylow TO yhigh
    BBC_DRAW xscale*(x+y), yscale*(y-x)+c/(x*x+y*y+depth)
  NEXT
NEXT
FOR y = ylow TO yhigh
  BBC_MOVE xscale*(xlow+y), yscale*(y-xlow)+c/(xlow*xlow+y*y+depth)
  FOR x = xlow TO xhigh
    BBC_DRAW xscale*(x+y), yscale*(y-x)+c/(x*x+y*y+depth)
  NEXT
NEXT
WAITKEY
BBC_CLOSE
« Last Edit: January 28, 2014, 05:44:03 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 3570
    • ScriptBasic Open Source Project
Re: ScriptBasic SDL extension module
« Reply #50 on: January 28, 2014, 10:04:20 PM »
This example is using the BBC Basic and SDL_draw libraries to render the example. The BBC library gives the SDL_draw library clipping features not present when used alone.



Code: [Select]
' UFO

DECLARE SUB BBC_OPEN ALIAS "BBC_init_screen" LIB "sdl"
DECLARE SUB BBC_MODE ALIAS "BBC_emulate_mode" LIB "sdl"
DECLARE SUB BBC_ORIGIN ALIAS "BBC_emulate_origin" LIB "sdl"
DECLARE SUB BBC_GCOL ALIAS "BBC_emulate_gcol" LIB "sdl"
DECLARE SUB BBC_OFF ALIAS "BBC_emulate_off" LIB "sdl"
DECLARE SUB BBC_PLOT ALIAS "BBC_emulate_plot" LIB "sdl"
DECLARE SUB BBC_PRINT ALIAS "BBC_emulate_vdustr" LIB "sdl"
DECLARE SUB BBC_CLOSE ALIAS "BBC_end_screen" LIB "sdl"
DECLARE SUB Ticks ALIAS "SB_Ticks" LIB "sdl"
DECLARE SUB GETKEY ALIAS "SB_GetKey" LIB "sdl"
DECLARE SUB Draw_FillCircle ALIAS "SB_Draw_FillCircle" LIB "sdl"
DECLARE SUB RGB ALIAS "SB_RGB" LIB "sdl"
DECLARE SUB SB_OPEN ALIAS "SB_Window" LIB "sdl"
DECLARE SUB SB_UPDATESCR ALIAS "SB_UpdateRect" LIB "sdl"

BBC_OPEN
SB_OPEN 800,600,"BBC & SDL_draw"
t1 = Ticks()
BBC_MODE 31
BBC_ORIGIN 800,600
XS=2
YS=2
BBC_GCOL 0,14
BBC_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
    END IF
    IF Y>M THEN M=Y
    IF Y<N THEN N=Y
    IF M=Y OR N=Y THEN
      BBC_PLOT 69,NOT(x),y
      BBC_PLOT 69,X,Y
    END IF
  NEXT
NEXT
Draw_FillCircle 400, 0, 30, RGB(32, 255, 255)
SB_UPDATESCR
BBC_OFF
t2 = Ticks()
t3 = (t2-t1)/1000
BBC_PRINT "Time: " & FORMAT("%.4f",t3) & " seconds"
WHILE GETKEY() <> "-escape"
WEND
BBC_CLOSE
« Last Edit: January 29, 2014, 06:50:14 PM by John »

Offline Charles Pegge

  • BASIC Developer
  • Posts: 69
Re: ScriptBasic SDL extension module
« Reply #51 on: January 29, 2014, 11:05:33 AM »
One particular problem we have with the DLLC idea is processor and platform dependency. Specific extension modules don't have this limitation, where they can be compiled entirely from C for the target platform.

Offline John

  • Forum Support / SB Dev
  • Posts: 3570
    • ScriptBasic Open Source Project
Re: ScriptBasic SDL extension module
« Reply #52 on: January 29, 2014, 11:18:57 AM »
My first attempt in that direction is to be able to have a SB extension module function do callbacks to SB functions without having to return back to SB. (like DLLC does now) Many of the DLLC features are Windows specific like BSTR, COM, ... and a cross platform SB extension module makes no sense. I see DLLC as a FFI on steroids. It gives the Windows version of SB something to compete with. As a silver lining, thinBasic benefited from your work on DLLC.

Any news on the C BASIC front?

« Last Edit: January 29, 2014, 01:48:31 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 3570
    • ScriptBasic Open Source Project
Re: ScriptBasic SDL extension module - Ubuntu 32 bit version
« Reply #53 on: January 30, 2014, 12:07:49 AM »
I was able to build a ScriptBasic SDL extension module for Ubuntu 12.04 LTS 32 bit. I will post the runtime versions for both 32/64 bit shortly. For some reason the UFO example runs very slow compared to it's 64 bit counter part. I'm thinking this is a VirtualBox issue and would appreciate if someone could try this with VMWare or a direct boot Ubuntu 32 bit system. (both 2D/3D hardware accelerator support check boxes for the VM were clicked)



I'm going to assume with the following instructions that you have not installed ScriptBasic on Ubuntu 32 bit. It is assumed you already have SDL 1.2 installed on your system.

1. Download the ScriptBasic 2.2 beta release from HERE.

2. Create a sub-directory out of your home called sb22 for this example install.

3. Unzip the ScriptBasic archive into your new sb22 directory.

4. Either add the following exports to your startup shell script or put them in a file (sbset) and use a . ./sbset command. (adjust path names accordingly)
Code: [Select]
export PATH=/home/jrs/sb22/bin:$PATH
export SCRIBACONF=/home/jrs/sb22/bin/scriba.conf

5. You need to create a ScriptBasic scriba.conf file which is built from a text file version. (scriba.conf.txt) Adjust paths for your system.

Code: [Select]
dll ".so"
module "/home/jrs/sb22/modules/"
include "/home/jrs/sb22/include/"
maxinclude 100
preproc (
  internal (
    sdbg "/home/jrs/sb22/modules/sdbg.so"
   )
 )
maxstep 0
maxlocalstep 0
maxlevel 3000
maxmem 0

If the exports have been done, type the following in the ~/sb22/bin directory where you saved the scriba.conf.txt file.
Code: [Select]
scriba -k scriba.conf.txt

This will create a scriba .conf in your ~/sb22/bin directory.

6. Download the sbsdl_u32.zip and put the lib*.so files in your /usr/lib (using sudo) and copy the sdl.so to your ~/sb22/modules directory.

That should do it for you. I also included the ufo.sb SB script which can go into a test directory inside your ~/sb22 directory.

From a console/terminal window and in your test directory, type the following to run the ufo.sb program.

Code: [Select]
scriba ufo.sb
« Last Edit: January 30, 2014, 01:50:52 AM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 3570
    • ScriptBasic Open Source Project
Re: ScriptBasic SDL extension module - Ubuntu 64 bit version
« Reply #54 on: January 30, 2014, 02:22:12 AM »
For those running Ubuntu 64 bit the SDL extension module files are attached. The install procedure remains the same but use the SB 2.2 64 bit beta release instead.

« Last Edit: January 30, 2014, 02:42:06 AM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 3570
    • ScriptBasic Open Source Project
Re: ScriptBasic SDL extension module - libbbc in C BASIC
« Reply #55 on: January 30, 2014, 04:01:26 PM »
I'm happy for the moment where I'm at with the SDL extension module. It needs to be documented so others can try it for themselves. I want to be able to compile the libbbc.so/dll without having to do it with Brandy BASIC V being involved. This means making a bbc.h that only includes what is needed for the standalone library. I will more than likely put a C BASIC face on it to promote contributions from a larger base.


Offline John

  • Forum Support / SB Dev
  • Posts: 3570
    • ScriptBasic Open Source Project
Re: ScriptBasic SDL extension module - Polygon example
« Reply #56 on: January 30, 2014, 07:29:28 PM »
I converted David's polygon.nap example to ScriptBasic to test the VDU, SHIFTLT and RND functions. I got it working but not the way it should (origin, 256 colors, ...) but no complaints about the speed of rendering. What puzzles me is how x% and y% magically gets assigned screen width and height values in the original program. (polygon.nap)

Update: I have the 256 colors working using the BBC_NEWMODE function. I'm still working on the origin issue and should have it resolved soon. The point of converting these demos is to create the documentation for the BBC BASIC graphics emulations functions. I have to say that David Daniels did a nice job with his emulation library. I don't know yet what is missing as I'm still getting up to speed with learning BBC BASIC in general.

I modified each copy of the polygon example for SB, Brandy BASIC V, Napoleon Brandy BASIC V and BBC BASIC for Windows to display polygons in a FOR/NEXT loop with an iteration of 1000.



Code: [Select]
' Polygon

DECLARE SUB BBC_OPEN ALIAS "BBC_init_screen" LIB "sdl"
DECLARE SUB BBC_MODE ALIAS "BBC_emulate_mode" LIB "sdl"
DECLARE SUB BBC_NEWMODE ALIAS "BBC_emulate_newmode" LIB "sdl"
DECLARE SUB BBC_ORIGIN ALIAS "BBC_emulate_origin" LIB "sdl"
DECLARE SUB BBC_GCOL ALIAS "BBC_emulate_gcol" LIB "sdl"
DECLARE SUB BBC_OFF ALIAS "BBC_emulate_off" LIB "sdl"
DECLARE SUB BBC_PLOT ALIAS "BBC_emulate_plot" LIB "sdl"
DECLARE SUB BBC_DRAW ALIAS "BBC_emulate_draw" LIB "sdl"
DECLARE SUB BBC_MOVE ALIAS "BBC_emulate_move" LIB "sdl"
DECLARE SUB BBC_PRINT ALIAS "BBC_emulate_vdustr" LIB "sdl"
DECLARE SUB BBC_CLOSE ALIAS "BBC_end_screen" LIB "sdl"
DECLARE SUB Ticks ALIAS "SB_Ticks" LIB "sdl"
DECLARE SUB BBC_RND ALIAS "BBC_RND" LIB "sdl"
DECLARE SUB GETKEY ALIAS "SB_GetKey" LIB "sdl"
DECLARE SUB SHIFTLT ALIAS "SB_SHIFTLT" LIB "sdl"
DECLARE SUB BBC_VDU ALIAS "BBC_emulate_vdu" LIB "sdl"
DECLARE SUB BBC_VDUFN ALIAS "BBC_emulate_vdufn" LIB "sdl"
DECLARE SUB SB_OPEN ALIAS "SB_Window" LIB "sdl"

BBC_OPEN
SB_OPEN 800,600,"ScriptBasic Polygon using BBC graphics"
t1 = Ticks()
BBC_NEWMODE 800,600,32,-1
BBC_VDU 26
Width = 800
Height = 600
SPLITA STRING(11,"0") BY "" TO X
SPLITA STRING(11,"0") BY "" TO Y
FOR i = 1 TO 1000
  count += 1
' xorigin = BBC_RND(640 * 2)
' yorigin = BBC_RND(512 * 2)
  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 = SHIFTLT((BBC_RND(4)-1), 6)
  BBC_GCOL 0,C, T
  FOR SIDE = 1 TO sides
    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 SIDE
  BBC_MOVE 0, 0
  BBC_PLOT 85, Radius, 0
  REPEAT
    D=BBC_RND(64) - 1
  UNTIL (D AND 63)<>(C AND 6)
  BBC_GCOL 0,D, T
  FOR SIDE = 1 TO sides
    FOR L = SIDE TO sides
      BBC_MOVE X[SIDE], Y[SIDE]
      BBC_DRAW X[L], Y[L]
    NEXT L
  NEXT SIDE
NEXT i
t2 = Ticks()
t3 = (t2-t1)/1000
BBC_PRINT "Time: " & FORMAT("%.4f",t3) & " seconds"
WHILE GETKEY() <> "-escape"
WEND
BBC_CLOSE

Brandy BASIC V


Code: [Select]
   10REM POLYGON
   20REM FROM AN ORIGINAL PROGRAM BY JOHN A COLL
   30REM IBM VERSION / 23 MAR 86; MODIFIED 26 SEP 98
   40CLS
   45 t1% = TIME
   50 MODE "X800 Y600 C16M"
   60CLS
   70VDU 26
   80
   90Width% = X%
  100Height% = Y%
  110
  120
  130
  140DIM X(10)
  150DIM Y(10)
  160: count=0
  170FOR i% = 1 TO 1000
  180count=count+1
  190xorigin=RND(640*2)
  200yorigin=RND(512*2)
  210Radius=RND(300)+50
  220VDU29,xorigin;yorigin;
  230sides=RND(8)+2
  240MOVE Radius,0
  250MOVE 10,10
  260:
  270C=RND(64)-1:T=(RND(4)-1)<<6:GCOL 0,C TINT T
  280FOR SIDE=1 TO sides
  290angle=(SIDE-1)*2*PI/sides
  300X(SIDE)=Radius*COS(angle)
  310Y(SIDE)=Radius*SIN(angle)
  320MOVE 0,0
  330PLOT 85,X(SIDE),Y(SIDE)
  340NEXT SIDE
  350MOVE 0,0
  360PLOT 85,Radius,0
  370:
  380REPEAT D=RND(64)-1:UNTIL (D AND 63)<>(C AND 6):GCOL 0,D TINT T
  390FOR SIDE=1 TO sides
  400FOR Line=SIDE TO sides
  410MOVE X(SIDE), Y(SIDE)
  420DRAW X(Line), Y(Line)
  430NEXT Line
  440NEXT SIDE
  441NEXT i%
  442 t2% = TIME
  444 PRINT (t2%-t1%)/100;" seconds"
  450IF count=50::count=0:delay%=10
  460K% = INKEY(1)


BBC BASIC for Windows (running under Wine - not in 32 bit color ?)


Code: [Select]
      ON ERROR MODE 3:END
      REM POLYGON
      REM FROM AN ORIGINAL PROGRAM BY JOHN A COLL
      REM IBM VERSION / 23 MAR 86; MODIFIED 26 SEP 98
      MODE 18
      DIM X(10)
      DIM Y(10)
      t1% = TIME
      FOR i% = 1 TO 1000
        xorigin=RND(1279)
        yorigin=RND(1023)
        Radius=RND(300)+50
        VDU 29,xorigin;yorigin;
        sides=RND(8)+2
        MOVE Radius,0
        MOVE 10,10
        :
        C=RND(16)-1:GCOL 0,C
        FOR SIDE=1 TO sides
          angle=(SIDE-1)*2*PI/sides
          X(SIDE)=Radius*COS(angle)
          Y(SIDE)=Radius*SIN(angle)
          MOVE 0,0
          PLOT 85,X(SIDE),Y(SIDE)
        NEXT SIDE
        MOVE 0,0
        PLOT 85,Radius,0
        :
        REPEAT D=RND(16)-1:UNTIL (D AND3)<>(C AND3):GCOL 0,D
        FOR SIDE=1 TO sides
          FOR Line=SIDE TO sides
            MOVE X(SIDE), Y(SIDE)
            DRAW X(Line), Y(Line)
          NEXT Line
        NEXT SIDE
      NEXT i%
      t2% = TIME
      END
I get a syntax error on the following line trying to run the Brandy code in BBC4W.
Code: [Select]
   50 MODE 800,600,32

Napoleon Brandy BASIC V (running under Wine - used Brandy BASIC V code above)


Quote from: David Burnard
Hello John,

Just been on your all basic site and saw the polygon demo,
I've spotted a bug in my own code based on this, so thought I'd let you know as there may be some code you want to look into yourself !!

If you look at the newmode function, in Colin Tuckleys  SDL code, you will see it accepts the parameters (including bit levels up to 32bits) it then uses the following switch statement

switch (bpp) {
  case 1: coldepth = 2; break;
  case 2: coldepth = 4; break;
  case 4: coldepth = 16; break;
  default:
    coldepth = 256;
  }

before scanning the static mode list in scrcommon.h and selecting the matching mode if it exists in the list.
The mode list only specifies modes up to 256 colours anyway.

Guess you know what I'm going to say based on this!!!

and yes! I need to fix the emulate_newmode() function in napoleon, however my emulate_modestr() function works fine though,
so in v0.00.09 please select the 32bit mode with

MODE "X800 Y600 C16M"

the SDL code also does not include RGB translations for 15,16 or 32 bit graphics and does not support the palette in non truecolour modes (part of the reason I wrote my own routines).

In addition the GCOL <ROP>,<Colour> TINT <tint> form of GCOL  is intended for 256 colour modes, and I have arranged the same RGB colours to be selected in true colour modes in napoleon, only 256 distinct colours can be selected with this command.

use

GCOL OF <ROP>,<R>,<G>,<B>                     (foreground graphics colour)

and

GCOL ON <ROP>,<R>,<G>,<B>                    (background graphics colour) 

<ROP> Raster Operation parameter is optional

in truecolour  modes to access more than the standard 256 colours, these forms of GCOL were added  to support truecolour modes in later versions of ARM BBC Basic and were implemented to work with lower bitdepths for consistency.

Hope this helps

David

MODE change made to the code and a new screen shot posted.
« Last Edit: January 31, 2014, 02:27:37 PM by John »