Author Topic: ScriptBasic BBC extension module  (Read 3333 times)

Offline John

  • Forum Support / SB Dev
  • Posts: 2747
    • ScriptBasic Open Source Project
ScriptBasic BBC extension module
« on: February 13, 2014, 10:07:01 PM »
I have gone as far as I can with the BBC BASIC graphics extension using C BASIC. It became painfully obvious that as soon as I needed string support, C is limited what it provides. (without additional libraries and a memory manager) I gathered what I did in the SDL extension module and the libbbc5 project and built a BBC specific extension module with the goal of ease of use. My thought is folks that would be interested in BBC BASIC programming are not API experts and are looking for a high level language that is fun to program in. From what I've seen using Brandy BASIC V, ScriptBasic is a far superior BASIC language that is extensible using the C BASIC / SB extension module feature. The following has been added to the Brandy BASIC V graphics API in the ScriptBasic BBC extension module.

  • BBC_OPEN - optional window title string as an argument
  • BBC_TIME - millisecond timer that is initialized when the SDL window is opened
  • BBC_RND - the Brandy RND function seems to work best with BBC based code so it was added to the library
  • BBC_SHIFT - Charles Pegge's bit/arithmetic shifting function
  • BBC_ROTATE - Charles Pegge's bit rotating function
  • BBC_MOUSE(0) - Waits for mouse movement and returns X position.
  • BBC_MOUSE(1) - Waits for mouse movement and returns Y position.
  • BBC_MOUSE(2) - Polls for a mouse button press event and returns.
  • BBC_MOUSE(3) - Waits for a mouse button to be pressed then returns.
  • BBC_GETKEY(0) - Polls for a key press event and returns a unicode value
  • BBC_GETKEY(1) - Waits for a key to be pressed then returns a unicode value
  • BBC_GETKEY(2) - Polls for a key press event and returns a keycode value
  • BBC_GETKEY(3) - Waits for a key to be pressed then returns a keycode value
  • BBC_GETKEY(4) - Polls for a key press event and returns a scancode value
  • BBC_GETKEY(5) - Waits for a key to be pressed then returns a scancode value
  • BBC_KEYNAME(0) - Polls for key up/down events and returns the key name
  • BBC_KEYNAME(1) -  Waits for a key up/down event and returns the key name




Code: [Select]
' UFO

IMPORT bbc.inc

BBC::OPEN "ScriptBasic BBC UFO"
t1 = BBC::TIME()
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
t2 = BBC::TIME()
t3 = (t2 - t1) / 1000
BBC::OFF
BBC::VDUSTR "Time: " & FORMAT("%.4f", t3) & " seconds."
WHILE BBC::KEYNAME(1) <> "-escape"
WEND
BBC::CLOSE

« Last Edit: February 15, 2014, 12:38:53 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 2747
    • ScriptBasic Open Source Project
Re: ScriptBasic BBC extension module
« Reply #1 on: February 13, 2014, 11:16:57 PM »


Code: [Select]
' Fern

IMPORT bbc.inc

BBC::OPEN "ScriptBasic BBC fern"
t1 = BBC::TIME()
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 = BBC::TIME()
t3 = (t2-t1)/1000
BBC::VDUSTR "Time: " & FORMAT("%.4f",t3) & " seconds"
BBC::WAITKEY
BBC::CLOSE
« Last Edit: February 15, 2014, 12:33:33 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 2747
    • ScriptBasic Open Source Project
Re: ScriptBasic BBC extension module
« Reply #2 on: February 14, 2014, 12:24:13 AM »


Code: [Select]
' Graph Demo

IMPORT bbc.inc

CONST SDLK_ESCAPE = 27

BBC::OPEN "ScriptBasic BBC graphdemo"
t1 = BBC::TIME()
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
t2 = BBC::TIME()
t3 = (t2 - t1) / 1000
BBC::OFF
BBC::VDUSTR "Time: " & FORMAT("%.4f", t3) & " seconds."
WHILE BBC::GETKEY(1) <> SDLK_ESCAPE
WEND
BBC::CLOSE
« Last Edit: February 15, 2014, 12:27:23 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 2747
    • ScriptBasic Open Source Project
Re: ScriptBasic BBC extension module
« Reply #3 on: February 14, 2014, 12:55:39 AM »


Code: [Select]
' Polygon

IMPORT bbc.inc

BBC::OPEN "ScriptBasic BBC polygon"
t1 = BBC::TIME()
BBC::MODE 32
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
  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)
  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
  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 ln = side TO sides
      BBC::MOVE x[side], y[side]
      BBC::DRAW x[ln], y[ln]
    NEXT
  NEXT
NEXT i
t2 = BBC::TIME()
t3 = (t2 - t1) / 1000
BBC::VDUSTR "Time: " & FORMAT("%.4f",t3) & " seconds."
BBC::WAITKEY
BBC::CLOSE
« Last Edit: February 15, 2014, 12:23:58 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 2747
    • ScriptBasic Open Source Project
Re: ScriptBasic BBC extension module
« Reply #4 on: February 14, 2014, 12:51:26 PM »


Code: [Select]
' ScriptBasic BBC COLOURS Demo - original by vovchik

IMPORT bbc.inc

t1 = "ScriptBasic BBC colours"
t2 = "BBC MODE 32"
t3 = "Any key to quit"

BBC::OPEN t1
BBC::MODE 32
BBC::VDU 5
BBC::OFF
PRINT "Mode: ", BBC::MODEFN(),"\n"
PRINT "Depth: ", BBC::VDUFN(3),"\n"
PRINT "Width: ", BBC::VDUFN(11) + 1, " Height: ", BBC::VDUFN(12) + 1,"\n"
PRINT "OriginX: ", BBC::VDUFN(136), " OriginY: ", BBC::VDUFN(137),"\n"
PRINT "FGcolor: ", BBC::VDUFN(153), " BGcolor: ", BBC::VDUFN(154),"\n"
PRINT "OriginX: ", BBC::VDUFN(136), " OriginY: ", BBC::VDUFN(137),"\n"
BBC::GCOL 0, 63, 192
BBC::MOVE 400, 1160
BBC::VDUSTR "0"
BBC::MOVE 400 + 256 - 5, 1160
BBC::VDUSTR "64"
BBC::MOVE 400 + (2 * 256) - 15, 1160
BBC::VDUSTR "128"
BBC::MOVE 400 + (3 * 256) - 20, 1160
BBC::VDUSTR "192"
BBC::ORIGIN 200, 100
FOR col = 0 TO 63
  BBC::MOVE 10, (col * 16) + 16
  BBC::VDUSTR FORMAT("%~## ~", col)
NEXT
BBC::ORIGIN 270, 100
FOR col = 0 TO 63
  FOR tint = 0 TO 192 STEP 64
    BBC::GCOL 0, col, tint
    BBC::DRAWRECT tint * 4, col * 16, 256, 16, 1
    PRINT RIGHT("   " & col, 3), ". BBC::GCOL(0, ", col, ", ", tint, ")\n"
  NEXT
NEXT
PRINT "OriginX: ", BBC::VDUFN(136), " OriginY: ", BBC::VDUFN(137),"\n"
PRINT "FGcolor: ", BBC::VDUFN(153), " BGcolor: ", BBC::VDUFN(154),"\n"
BBC::ORIGIN 0, 0
BBC::MOVE 685, 80
BBC::GCOL 0, 2, 3
PRINT "OriginX: ", BBC::VDUFN(136), " OriginY: ", BBC::VDUFN(137),"\n"
PRINT "FGcolor: ", BBC::VDUFN(153), " BGcolor: ", BBC::VDUFN(154)
BBC::VDUSTR t2
BBC::GCOL 0, 63, 192
BBC::MOVE 655, 40
BBC::VDUSTR t3
BBC::WAITKEY
BBC::CLOSE

Console Output
Code: [Select]
jrs@laptop:~/sb/sb22/sdl$ scriba colours.sb
Mode: 32
Depth: 255
Width: 800 Height: 600
OriginX: 0 OriginY: 0
FGcolor: 63 BGcolor: 0
OriginX: 0 OriginY: 0
  0. BBC_GCOL(0, 0, 0)
  0. BBC_GCOL(0, 0, 64)
  0. BBC_GCOL(0, 0, 128)
  0. BBC_GCOL(0, 0, 192)
  1. BBC_GCOL(0, 1, 0)
  1. BBC_GCOL(0, 1, 64)
  1. BBC_GCOL(0, 1, 128)
  1. BBC_GCOL(0, 1, 192)
  2. BBC_GCOL(0, 2, 0)
  2. BBC_GCOL(0, 2, 64)
  2. BBC_GCOL(0, 2, 128)
  2. BBC_GCOL(0, 2, 192)
  3. BBC_GCOL(0, 3, 0)
  3. BBC_GCOL(0, 3, 64)
  3. BBC_GCOL(0, 3, 128)
  3. BBC_GCOL(0, 3, 192)
  4. BBC_GCOL(0, 4, 0)
  4. BBC_GCOL(0, 4, 64)
  4. BBC_GCOL(0, 4, 128)
  4. BBC_GCOL(0, 4, 192)
  5. BBC_GCOL(0, 5, 0)
  5. BBC_GCOL(0, 5, 64)
  5. BBC_GCOL(0, 5, 128)
  5. BBC_GCOL(0, 5, 192)
  6. BBC_GCOL(0, 6, 0)
  6. BBC_GCOL(0, 6, 64)
  6. BBC_GCOL(0, 6, 128)
  6. BBC_GCOL(0, 6, 192)
  7. BBC_GCOL(0, 7, 0)
  7. BBC_GCOL(0, 7, 64)
  7. BBC_GCOL(0, 7, 128)
  7. BBC_GCOL(0, 7, 192)
  8. BBC_GCOL(0, 8, 0)
  8. BBC_GCOL(0, 8, 64)
  8. BBC_GCOL(0, 8, 128)
  8. BBC_GCOL(0, 8, 192)
  9. BBC_GCOL(0, 9, 0)
  9. BBC_GCOL(0, 9, 64)
  9. BBC_GCOL(0, 9, 128)
  9. BBC_GCOL(0, 9, 192)
 10. BBC_GCOL(0, 10, 0)
 10. BBC_GCOL(0, 10, 64)
 10. BBC_GCOL(0, 10, 128)
 10. BBC_GCOL(0, 10, 192)
 11. BBC_GCOL(0, 11, 0)
 11. BBC_GCOL(0, 11, 64)
 11. BBC_GCOL(0, 11, 128)
 11. BBC_GCOL(0, 11, 192)
 12. BBC_GCOL(0, 12, 0)
 12. BBC_GCOL(0, 12, 64)
 12. BBC_GCOL(0, 12, 128)
 12. BBC_GCOL(0, 12, 192)
 13. BBC_GCOL(0, 13, 0)
 13. BBC_GCOL(0, 13, 64)
 13. BBC_GCOL(0, 13, 128)
 13. BBC_GCOL(0, 13, 192)
 14. BBC_GCOL(0, 14, 0)
 14. BBC_GCOL(0, 14, 64)
 14. BBC_GCOL(0, 14, 128)
 14. BBC_GCOL(0, 14, 192)
 15. BBC_GCOL(0, 15, 0)
 15. BBC_GCOL(0, 15, 64)
 15. BBC_GCOL(0, 15, 128)
 15. BBC_GCOL(0, 15, 192)
 16. BBC_GCOL(0, 16, 0)
 16. BBC_GCOL(0, 16, 64)
 16. BBC_GCOL(0, 16, 128)
 16. BBC_GCOL(0, 16, 192)
 17. BBC_GCOL(0, 17, 0)
 17. BBC_GCOL(0, 17, 64)
 17. BBC_GCOL(0, 17, 128)
 17. BBC_GCOL(0, 17, 192)
 18. BBC_GCOL(0, 18, 0)
 18. BBC_GCOL(0, 18, 64)
 18. BBC_GCOL(0, 18, 128)
 18. BBC_GCOL(0, 18, 192)
 19. BBC_GCOL(0, 19, 0)
 19. BBC_GCOL(0, 19, 64)
 19. BBC_GCOL(0, 19, 128)
 19. BBC_GCOL(0, 19, 192)
 20. BBC_GCOL(0, 20, 0)
 20. BBC_GCOL(0, 20, 64)
 20. BBC_GCOL(0, 20, 128)
 20. BBC_GCOL(0, 20, 192)
 21. BBC_GCOL(0, 21, 0)
 21. BBC_GCOL(0, 21, 64)
 21. BBC_GCOL(0, 21, 128)
 21. BBC_GCOL(0, 21, 192)
 22. BBC_GCOL(0, 22, 0)
 22. BBC_GCOL(0, 22, 64)
 22. BBC_GCOL(0, 22, 128)
 22. BBC_GCOL(0, 22, 192)
 23. BBC_GCOL(0, 23, 0)
 23. BBC_GCOL(0, 23, 64)
 23. BBC_GCOL(0, 23, 128)
 23. BBC_GCOL(0, 23, 192)
 24. BBC_GCOL(0, 24, 0)
 24. BBC_GCOL(0, 24, 64)
 24. BBC_GCOL(0, 24, 128)
 24. BBC_GCOL(0, 24, 192)
 25. BBC_GCOL(0, 25, 0)
 25. BBC_GCOL(0, 25, 64)
 25. BBC_GCOL(0, 25, 128)
 25. BBC_GCOL(0, 25, 192)
 26. BBC_GCOL(0, 26, 0)
 26. BBC_GCOL(0, 26, 64)
 26. BBC_GCOL(0, 26, 128)
 26. BBC_GCOL(0, 26, 192)
 27. BBC_GCOL(0, 27, 0)
 27. BBC_GCOL(0, 27, 64)
 27. BBC_GCOL(0, 27, 128)
 27. BBC_GCOL(0, 27, 192)
 28. BBC_GCOL(0, 28, 0)
 28. BBC_GCOL(0, 28, 64)
 28. BBC_GCOL(0, 28, 128)
 28. BBC_GCOL(0, 28, 192)
 29. BBC_GCOL(0, 29, 0)
 29. BBC_GCOL(0, 29, 64)
 29. BBC_GCOL(0, 29, 128)
 29. BBC_GCOL(0, 29, 192)
 30. BBC_GCOL(0, 30, 0)
 30. BBC_GCOL(0, 30, 64)
 30. BBC_GCOL(0, 30, 128)
 30. BBC_GCOL(0, 30, 192)
 31. BBC_GCOL(0, 31, 0)
 31. BBC_GCOL(0, 31, 64)
 31. BBC_GCOL(0, 31, 128)
 31. BBC_GCOL(0, 31, 192)
 32. BBC_GCOL(0, 32, 0)
 32. BBC_GCOL(0, 32, 64)
 32. BBC_GCOL(0, 32, 128)
 32. BBC_GCOL(0, 32, 192)
 33. BBC_GCOL(0, 33, 0)
 33. BBC_GCOL(0, 33, 64)
 33. BBC_GCOL(0, 33, 128)
 33. BBC_GCOL(0, 33, 192)
 34. BBC_GCOL(0, 34, 0)
 34. BBC_GCOL(0, 34, 64)
 34. BBC_GCOL(0, 34, 128)
 34. BBC_GCOL(0, 34, 192)
 35. BBC_GCOL(0, 35, 0)
 35. BBC_GCOL(0, 35, 64)
 35. BBC_GCOL(0, 35, 128)
 35. BBC_GCOL(0, 35, 192)
 36. BBC_GCOL(0, 36, 0)
 36. BBC_GCOL(0, 36, 64)
 36. BBC_GCOL(0, 36, 128)
 36. BBC_GCOL(0, 36, 192)
 37. BBC_GCOL(0, 37, 0)
 37. BBC_GCOL(0, 37, 64)
 37. BBC_GCOL(0, 37, 128)
 37. BBC_GCOL(0, 37, 192)
 38. BBC_GCOL(0, 38, 0)
 38. BBC_GCOL(0, 38, 64)
 38. BBC_GCOL(0, 38, 128)
 38. BBC_GCOL(0, 38, 192)
 39. BBC_GCOL(0, 39, 0)
 39. BBC_GCOL(0, 39, 64)
 39. BBC_GCOL(0, 39, 128)
 39. BBC_GCOL(0, 39, 192)
 40. BBC_GCOL(0, 40, 0)
 40. BBC_GCOL(0, 40, 64)
 40. BBC_GCOL(0, 40, 128)
 40. BBC_GCOL(0, 40, 192)
 41. BBC_GCOL(0, 41, 0)
 41. BBC_GCOL(0, 41, 64)
 41. BBC_GCOL(0, 41, 128)
 41. BBC_GCOL(0, 41, 192)
 42. BBC_GCOL(0, 42, 0)
 42. BBC_GCOL(0, 42, 64)
 42. BBC_GCOL(0, 42, 128)
 42. BBC_GCOL(0, 42, 192)
 43. BBC_GCOL(0, 43, 0)
 43. BBC_GCOL(0, 43, 64)
 43. BBC_GCOL(0, 43, 128)
 43. BBC_GCOL(0, 43, 192)
 44. BBC_GCOL(0, 44, 0)
 44. BBC_GCOL(0, 44, 64)
 44. BBC_GCOL(0, 44, 128)
 44. BBC_GCOL(0, 44, 192)
 45. BBC_GCOL(0, 45, 0)
 45. BBC_GCOL(0, 45, 64)
 45. BBC_GCOL(0, 45, 128)
 45. BBC_GCOL(0, 45, 192)
 46. BBC_GCOL(0, 46, 0)
 46. BBC_GCOL(0, 46, 64)
 46. BBC_GCOL(0, 46, 128)
 46. BBC_GCOL(0, 46, 192)
 47. BBC_GCOL(0, 47, 0)
 47. BBC_GCOL(0, 47, 64)
 47. BBC_GCOL(0, 47, 128)
 47. BBC_GCOL(0, 47, 192)
 48. BBC_GCOL(0, 48, 0)
 48. BBC_GCOL(0, 48, 64)
 48. BBC_GCOL(0, 48, 128)
 48. BBC_GCOL(0, 48, 192)
 49. BBC_GCOL(0, 49, 0)
 49. BBC_GCOL(0, 49, 64)
 49. BBC_GCOL(0, 49, 128)
 49. BBC_GCOL(0, 49, 192)
 50. BBC_GCOL(0, 50, 0)
 50. BBC_GCOL(0, 50, 64)
 50. BBC_GCOL(0, 50, 128)
 50. BBC_GCOL(0, 50, 192)
 51. BBC_GCOL(0, 51, 0)
 51. BBC_GCOL(0, 51, 64)
 51. BBC_GCOL(0, 51, 128)
 51. BBC_GCOL(0, 51, 192)
 52. BBC_GCOL(0, 52, 0)
 52. BBC_GCOL(0, 52, 64)
 52. BBC_GCOL(0, 52, 128)
 52. BBC_GCOL(0, 52, 192)
 53. BBC_GCOL(0, 53, 0)
 53. BBC_GCOL(0, 53, 64)
 53. BBC_GCOL(0, 53, 128)
 53. BBC_GCOL(0, 53, 192)
 54. BBC_GCOL(0, 54, 0)
 54. BBC_GCOL(0, 54, 64)
 54. BBC_GCOL(0, 54, 128)
 54. BBC_GCOL(0, 54, 192)
 55. BBC_GCOL(0, 55, 0)
 55. BBC_GCOL(0, 55, 64)
 55. BBC_GCOL(0, 55, 128)
 55. BBC_GCOL(0, 55, 192)
 56. BBC_GCOL(0, 56, 0)
 56. BBC_GCOL(0, 56, 64)
 56. BBC_GCOL(0, 56, 128)
 56. BBC_GCOL(0, 56, 192)
 57. BBC_GCOL(0, 57, 0)
 57. BBC_GCOL(0, 57, 64)
 57. BBC_GCOL(0, 57, 128)
 57. BBC_GCOL(0, 57, 192)
 58. BBC_GCOL(0, 58, 0)
 58. BBC_GCOL(0, 58, 64)
 58. BBC_GCOL(0, 58, 128)
 58. BBC_GCOL(0, 58, 192)
 59. BBC_GCOL(0, 59, 0)
 59. BBC_GCOL(0, 59, 64)
 59. BBC_GCOL(0, 59, 128)
 59. BBC_GCOL(0, 59, 192)
 60. BBC_GCOL(0, 60, 0)
 60. BBC_GCOL(0, 60, 64)
 60. BBC_GCOL(0, 60, 128)
 60. BBC_GCOL(0, 60, 192)
 61. BBC_GCOL(0, 61, 0)
 61. BBC_GCOL(0, 61, 64)
 61. BBC_GCOL(0, 61, 128)
 61. BBC_GCOL(0, 61, 192)
 62. BBC_GCOL(0, 62, 0)
 62. BBC_GCOL(0, 62, 64)
 62. BBC_GCOL(0, 62, 128)
 62. BBC_GCOL(0, 62, 192)
 63. BBC_GCOL(0, 63, 0)
 63. BBC_GCOL(0, 63, 64)
 63. BBC_GCOL(0, 63, 128)
 63. BBC_GCOL(0, 63, 192)
OriginX: 270 OriginY: 100
FGcolor: 63 BGcolor: 0
OriginX: 0 OriginY: 0
FGcolor: 2 BGcolor: 0
jrs@laptop:~/sb/sb22/sdl$

« Last Edit: February 15, 2014, 12:35:04 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 2747
    • ScriptBasic Open Source Project
Re: ScriptBasic BBC extension module
« Reply #5 on: February 14, 2014, 09:01:11 PM »
I think I have the keyboard and mouse interface syntax defined and working. You can either poll SDL for events or wait within SDL for an event. We have four ways to return key values.

  • UNICODE
  • KeyCode
  • ScanCode
  • SDL Key Name

The BBC_GETKEY function has been enhanced to return one of the three possibilities.

BBC_GETKEY(0) - unicode poll
BBC_GETKEY(1) - unicode wait
BBC_GETKEY(2) - keycode poll
BBC_GETKEY(3) - keycode wait
BBC_GETKEY(4) - scancode poll
BBC_GETKEY(5) - scancode wait

BBC_KEYNAME(0) - keyname poll
BBC_KEYNAME(1) - keyname wait

ScriptBasic keyboard test program
Code: [Select]
DECLARE SUB BBC_OPEN ALIAS "BBC_OPEN" LIB "bbc"
DECLARE SUB BBC_GETKEY ALIAS "BBC_GETKEY" LIB "bbc"
DECLARE SUB BBC_KEYNAME ALIAS "BBC_KEYNAME" LIB "bbc"
DECLARE SUB BBC_CLOSE ALIAS "BBC_CLOSE" LIB "bbc"

BBC_OPEN "Test BBC_GETKEY"
REPEAT
' k = BBC_GETKEY(5)
  k = BBC_KEYNAME(1)
' PRINT "Unicode:  ",k,"  Character: ",CHR(k),"\n"
' PRINT "Keycode:  ",k,"  Character: ",CHR(k),"\n"
' PRINT "Scancode: ",k,"  Character: ",CHR(k),"\n"
  PRINT "Key Name: ",k,"\n"
UNTIL k = "-escape"
BBC_CLOSE

UNICODE
jrs@laptop:~/sb/sb22/sdl$ scriba getkey.sb
Unicode:  97  Character: a
Unicode:  98  Character: b
Unicode:  99  Character: c
Unicode:  0  Character:
Unicode:  65  Character: A
Unicode:  66  Character: B
Unicode:  67  Character: C
Unicode:  27  Character: 
jrs@laptop:~/sb/sb22/sdl$

KeyCode
jrs@laptop:~/sb/sb22/sdl$ scriba getkey.sb
Keycode:  97  Character: a
Keycode:  98  Character: b
Keycode:  99  Character: c
Keycode:  304  Character: 0
Keycode:  97  Character: a
Keycode:  98  Character: b
Keycode:  99  Character: c
Keycode:  27  Character: 
jrs@laptop:~/sb/sb22/sdl$

ScanCode
jrs@laptop:~/sb/sb22/sdl$ scriba getkey.sb
Scancode: 38  Character: &
Scancode: 56  Character: 8
Scancode: 54  Character: 6
Scancode: 50  Character: 2
Scancode: 38  Character: &
Scancode: 56  Character: 8
Scancode: 54  Character: 6
Scancode: 9  Character:    
jrs@laptop:~/sb/sb22/sdl$

BBC_KEYNAME (SDL_GetKeyName  +down / -up  key events)
jrs@laptop:~/sb/sb22/sdl$ scriba getkey.sb
Key Name: +a
Key Name: -a
Key Name: +b
Key Name: -b
Key Name: +c
Key Name: -c
Key Name: +left shift
Key Name: +a
Key Name: -a
Key Name: +b
Key Name: -b
Key Name: +c
Key Name: -c
Key Name: -left shift
Key Name: +escape
Key Name: -escape
jrs@laptop:~/sb/sb22/sdl$
« Last Edit: February 14, 2014, 09:21:28 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 2747
    • ScriptBasic Open Source Project
Re: ScriptBasic BBC extension module
« Reply #6 on: February 15, 2014, 09:49:03 AM »
I have created the ScriptBasic BBC include file for the extension module. This encapsulates the BBC interface into a ScriptBasic MODULE. (name space)  The default name space is MAIN:: which the prefix is optional for obvious reasons. Here is an example of using an expanded MAIN::.

Code: [Select]
MAIN::i = 1
MAIN::s = "Hello"
FOR MAIN::i TO 5
  PRINT MAIN::s, MAIN::i, "\n"
NEXT MAIN::i


Note: The IMPORT directive makes sure the module is only added once where INCLUDE inserts the code whenever used.

bbi.inc
Code: [Select]
MODULE BBC

DECLARE SUB    ::OPEN         ALIAS     "BBC_OPEN"          LIB "bbc"
DECLARE SUB    ::CLOSE        ALIAS     "BBC_CLOSE"         LIB "bbc"
DECLARE SUB    ::MODE         ALIAS     "BBC_MODE"          LIB "bbc"
DECLARE SUB    ::MODESTR      ALIAS     "BBC_MODESTR"       LIB "bbc"
DECLARE SUB    ::NEWMODE      ALIAS     "BBC_NEWMODE"       LIB "bbc"
DECLARE SUB    ::MODEFN       ALIAS     "BBC_MODEFN"        LIB "bbc"
DECLARE SUB    ::ORIGIN       ALIAS     "BBC_ORIGIN"        LIB "bbc"
DECLARE SUB    ::GCOL         ALIAS     "BBC_GCOL"          LIB "bbc"
DECLARE SUB    ::GCOLRGB      ALIAS     "BBC_GCOLRGB"       LIB "bbc"
DECLARE SUB    ::GCOLNUM      ALIAS     "BBC_GCOLNUM"       LIB "bbc"
DECLARE SUB    ::COLOURFN     ALIAS     "BBC_COLOURFN"      LIB "bbc"
DECLARE SUB    ::MAPCOLOUR    ALIAS     "BBC_MAPCOLOUR"     LIB "bbc"
DECLARE SUB    ::SETCOLOUR    ALIAS     "BBC_SETCOLOUR"     LIB "bbc"
DECLARE SUB    ::SETCOLNUM    ALIAS     "BBC_SETCOLNUM"     LIB "bbc"
DECLARE SUB    ::DEFCOLOUR    ALIAS     "BBC_DEFCOLOUR"     LIB "bbc"
DECLARE SUB    ::COLOURTINT   ALIAS     "BBC_COLOURTINT"    LIB "bbc"
DECLARE SUB    ::TINT         ALIAS     "BBC_TINT"          LIB "bbc"
DECLARE SUB    ::TINTFN       ALIAS     "BBC_TINTFN"        LIB "bbc"
DECLARE SUB    ::PLOT         ALIAS     "BBC_PLOT"          LIB "bbc"
DECLARE SUB    ::POINTFN      ALIAS     "BBC_POINTFN"       LIB "bbc"
DECLARE SUB    ::MOVE         ALIAS     "BBC_MOVE"          LIB "bbc"
DECLARE SUB    ::MOVEBY       ALIAS     "BBC_MOVEBY"        LIB "bbc"
DECLARE SUB    ::DRAWBY       ALIAS     "BBC_DRAWBY"        LIB "bbc"
DECLARE SUB    ::DRAW         ALIAS     "BBC_DRAW"          LIB "bbc"
DECLARE SUB    ::POINT        ALIAS     "BBC_POINT"         LIB "bbc"
DECLARE SUB    ::POINTBY      ALIAS     "BBC_POINTBY"       LIB "bbc"
DECLARE SUB    ::POINTTO      ALIAS     "BBC_POINTTO"       LIB "bbc"
DECLARE SUB    ::LINE         ALIAS     "BBC_LINE"          LIB "bbc"
DECLARE SUB    ::CIRCLE       ALIAS     "BBC_CIRCLE"        LIB "bbc"
DECLARE SUB    ::ELLIPSE      ALIAS     "BBC_ELLIPSE"       LIB "bbc"
DECLARE SUB    ::DRAWRECT     ALIAS     "BBC_DRAWRECT"      LIB "bbc"
DECLARE SUB    ::MOVERECT     ALIAS     "BBC_MOVERECT"      LIB "bbc"
DECLARE SUB    ::FILL         ALIAS     "BBC_FILL"          LIB "bbc"
DECLARE SUB    ::FILLBY       ALIAS     "BBC_FILLBY"        LIB "bbc"
DECLARE SUB    ::OFF          ALIAS     "BBC_OFF"           LIB "bbc"
DECLARE SUB    ::ON           ALIAS     "BBC_ON"            LIB "bbc"
DECLARE SUB    ::SETCURSOR    ALIAS     "BBC_SETCURSOR"     LIB "bbc"
DECLARE SUB    ::VDU          ALIAS     "BBC_VDU"           LIB "bbc"
DECLARE SUB    ::VDUSTR       ALIAS     "BBC_VDUSTR"        LIB "bbc"
DECLARE SUB    ::VDUFN        ALIAS     "BBC_VDUFN"         LIB "bbc"
DECLARE SUB    ::NEWLINE      ALIAS     "BBC_NEWLINE"       LIB "bbc"
DECLARE SUB    ::POS          ALIAS     "BBC_POS"           LIB "bbc"
DECLARE SUB    ::VPOS         ALIAS     "BBC_VPOS"          LIB "bbc"
DECLARE SUB    ::TAB          ALIAS     "BBC_TAB"           LIB "bbc"
DECLARE SUB    ::RND          ALIAS     "BBC_RND"           LIB "bbc"
DECLARE SUB    ::SHIFT        ALIAS     "BBC_SHIFT"         LIB "bbc"
DECLARE SUB    ::ROTATE       ALIAS     "BBC_ROTATE"        LIB "bbc"
DECLARE SUB    ::GETKEY       ALIAS     "BBC_GETKEY"        LIB "bbc"
DECLARE SUB    ::WAITKEY      ALIAS     "BBC_WAITKEY"       LIB "bbc"
DECLARE SUB    ::KEYNAME      ALIAS     "BBC_KEYNAME"       LIB "bbc"
DECLARE SUB    ::MOUSE        ALIAS     "BBC_MOUSE"         LIB "bbc"
DECLARE SUB    ::TIME         ALIAS     "BBC_TIME"          LIB "bbc"

END MODULE

« Last Edit: February 15, 2014, 12:35:47 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 2747
    • ScriptBasic Open Source Project
Re: ScriptBasic BBC extension module
« Reply #7 on: February 15, 2014, 10:37:05 PM »
I have posted the source for the ScriptBasic BBC extension module on Bitbucket. I will try to get Linux and Windows binaries posted soon.


Offline John

  • Forum Support / SB Dev
  • Posts: 2747
    • ScriptBasic Open Source Project
Re: ScriptBasic BBC extension module
« Reply #8 on: February 15, 2014, 11:20:03 PM »
I was pleased to find out that I could combine the BBC and SDL_draw extension modules and get clipping support from BBC. One strange anomaly is that it clips fine vertically but shows the clipped portion on the opposite side horizontally.  :o 



Code: [Select]
' UFO

IMPORT bbc.inc
IMPORT draw.inc

BBC::OPEN "ScriptBasic BBC UFO"
Draw::Window 800, 600
t1 = BBC::TIME()
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, 60, Draw::RGB(32, 255, 255)
Draw::Update
t2 = BBC::TIME()
t3 = (t2 - t1) / 1000
BBC::OFF
BBC::VDUSTR "Time: " & FORMAT("%.4f", t3) & " seconds."
WHILE BBC::KEYNAME(1) <> "-escape"
WEND
BBC::CLOSE
« Last Edit: February 16, 2014, 11:11:01 AM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 2747
    • ScriptBasic Open Source Project
Re: ScriptBasic BBC extension module - Linux 32/64 bit binaries
« Reply #9 on: February 16, 2014, 02:15:24 PM »
I have attached the binaries and example programs presented here on the forum if you would like to give it a try. I will try to get a 32 bit version built for Linux and Windows when I find some time. The source has been posted on the C BASIC bitbucket site if you would like to compile it yourself. You can use the ScriptBasic 2.1 source as all the extension module is requiring is header files that haven't changed in SB 2.2.

Installation (assuming you have SB already installed)

1. copy the bbc.so file to your SB modules directory.
2. sudo copy (cp) the libbbc.so to your /usr/lib directory.
3. copy the bbc.inc to your SB include directory.
4. copy the *.sb example programs to your choice of location.



« Last Edit: February 16, 2014, 04:03:58 PM by John »