Author Topic: ScriptBasic SDL extension module project  (Read 5051 times)

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
ScriptBasic SDL extension module project
« on: January 29, 2014, 03:36:48 PM »
Here is the code and compiled binaries for the ScriptBasic SDL extension module project. I'm working on getting a Windows 32 bit version of this going. Feedback, improvements and just letting me know you do / don't have any interest in this would be appreciated.

This is the interface.c file that that makes up the main SDL extension module.

Code: [Select]
// ScriptBasic SDL extension module

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <time.h>
#include "SDL.h"
#include "SDL_draw.h"
#include "SDL_terminal.h"
#include "SDL_image.h"
#include "screen.h"
#include "cbasic.h"
#include "../../basext.h"

DIM AS SDL_Surface PTR screen;
DIM AS SDL_Terminal PTR terminal;


/**************************
 Extension Module Functions
**************************/

besVERSION_NEGOTIATE
  RETURN_FUNCTION((int)INTERFACE_VERSION);
besEND

besSUB_START
  DIM AS long *p;
  besMODULEPOINTER = besALLOC(sizeof(long));
  IF (besMODULEPOINTER EQ NULL) THEN_DO RETURN_FUNCTION(0);
  p = (long*)besMODULEPOINTER;
  RETURN_FUNCTION(0);
besEND

besSUB_FINISH
  DIM AS long *p;
  p = (long*)besMODULEPOINTER;
  IF (p EQ NULL) THEN_DO RETURN_FUNCTION(0);
  RETURN_FUNCTION(0);
besEND


/*****************
 SDL API Functions
*****************/

// Window
besFUNCTION(SB_Window)
  DIM AS int width, height;
  DIM AS Uint8  video_bpp;
  DIM AS Uint32 videoflags;
  DIM AS const char *title;
  SDL_Init(SDL_INIT_VIDEO);
  atexit(SDL_Quit);
  videoflags = SDL_SWSURFACE | SDL_ANYFORMAT;
  besARGUMENTS("ii[z]")
    AT width, AT height, AT title
  besARGEND
  IF (title EQ NULL) THEN_DO title = "";
  screen = SDL_SetVideoMode(width, height, video_bpp, videoflags);
  SDL_WM_SetCaption(title, 0);
  besRETURNVALUE = NULL;
besEND

// RGB
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


/******************
 SDL Draw Functions
******************/

// Pixel
besFUNCTION(SB_Draw_Pixel)
  DIM AS Sint16 x, y;
  DIM AS Uint32 color;
  besARGUMENTS("iii")
    AT x, AT y, AT color
  besARGEND
  Draw_Pixel(screen, x, y, color);
  besRETURNVALUE = NULL;
besEND

// Line
besFUNCTION(SB_Draw_Line)
  DIM AS Sint16 x1, y1, x2, y2;
  DIM AS Uint32 color;
  besARGUMENTS("iiiii")
    AT x1, AT y1, AT x2, AT y2, AT color
  besARGEND
  Draw_Line(screen, x1, y1, x2, y2, color);
  besRETURNVALUE = NULL;
besEND

// Circle
besFUNCTION(SB_Draw_Circle)
  DIM AS Sint16 x0, y0;
  DIM AS Uint16 r;
  DIM AS Uint32 color;
  besARGUMENTS("iiii")
    AT x0, AT y0, AT r, AT color
  besARGEND
  Draw_Circle(screen, x0, y0, r, color);
  besRETURNVALUE = NULL;
besEND

// FillCircle
besFUNCTION(SB_Draw_FillCircle)
  DIM AS Sint16 x0, y0;
  DIM AS Uint16 r;
  DIM AS Uint32 color;
  besARGUMENTS("iiii")
    AT x0, AT y0, AT r, AT color
  besARGEND
  Draw_FillCircle(screen, x0, y0, r, color);
  besRETURNVALUE = NULL;
besEND

// HLine
besFUNCTION(SB_Draw_HLine)
  DIM AS Sint16 x0, y0, x1;
  DIM AS Uint32 color;
  besARGUMENTS("iiii")
    AT x0, AT y0, AT x1, AT color
  besARGEND
  Draw_HLine(screen, x0, y0, x1, color);
  besRETURNVALUE = NULL;
besEND

// VLine
besFUNCTION(SB_Draw_VLine)
  DIM AS Sint16 x0, y0, y1;
  DIM AS Uint32 color;
  besARGUMENTS("iiii")
    AT x0, AT y0, AT y1, AT color
  besARGEND
  Draw_VLine(screen, x0, y0, y1, color);
  besRETURNVALUE = NULL;
besEND

// Rect
besFUNCTION(SB_Draw_Rect)
  DIM AS Sint16 x, y;
  DIM AS Uint16 w, h;
  DIM AS Uint32 color;
  besARGUMENTS("iiiii")
    AT x, AT y, AT w, AT h, AT color
  besARGEND
  Draw_Rect(screen, x, y, w, h, color);
  besRETURNVALUE = NULL;
besEND

// FillRect
besFUNCTION(SB_Draw_FillRect)
  DIM AS Sint16 x, y;
  DIM AS Uint16 w, h;
  DIM AS Uint32 color;
  besARGUMENTS("iiiii")
    AT x, AT y, AT w, AT h, AT color
  besARGEND
  Draw_FillRect(screen, x, y, w, h, color);
  besRETURNVALUE = NULL;
besEND

// Ellipse
besFUNCTION(SB_Draw_Ellipse)
  DIM AS Sint16 x0, y0;
  DIM AS Uint16 Xradius, Yradius;
  DIM AS Uint32 color;
  besARGUMENTS("iiiii")
    AT x0, AT y0, AT Xradius, AT Yradius, AT color
  besARGEND
  Draw_Ellipse(screen, x0, y0, Xradius, Yradius, color);
  besRETURNVALUE = NULL;
besEND

// FillEllipse
besFUNCTION(SB_Draw_FillEllipse)
  DIM AS Sint16 x0, y0;
  DIM AS Uint16 Xradius, Yradius;
  DIM AS Uint32 color;
  besARGUMENTS("iiiii")
    AT x0, AT y0, AT Xradius, AT Yradius, AT color
  besARGEND
  Draw_FillEllipse(screen, x0, y0, Xradius, Yradius, color);
  besRETURNVALUE = NULL;
besEND

// Round
besFUNCTION(SB_Draw_Round)
  DIM AS Sint16 x0, y0;
  DIM AS Uint16 w, h, corner;
  DIM AS Uint32 color;
  besARGUMENTS("iiiiii")
    AT x0, AT y0, AT w, AT h, AT corner, AT color
  besARGEND
  Draw_Round(screen, x0, y0, w, h, corner, color);
  besRETURNVALUE = NULL;
besEND

// FillRound
besFUNCTION(SB_Draw_FillRound)
  DIM AS Sint16 x0, y0;
  DIM AS Uint16 w, h, corner;
  DIM AS Uint32 color;
  besARGUMENTS("iiiiii")
    AT x0, AT y0, AT w, AT h, AT corner, AT color
  besARGEND
  Draw_FillRound(screen, x0, y0, w, h, corner, color);
  besRETURNVALUE = NULL;
besEND


/**********************
 SDL Terminal Functions
**********************/

// Create
besFUNCTION(SB_CreateTerminal)
  terminal =  SDL_CreateTerminal ();
  besRETURNVALUE = NULL;
besEND

// Destroy
besFUNCTION(SB_DestroyTerminal)
  SDL_DestroyTerminal(terminal);
  besRETURNVALUE = NULL;
besEND

// Blit
besFUNCTION(SB_TerminalBlit)
  DIM AS int rtnval;
  rtnval = SDL_TerminalBlit(terminal);
  besRETURN_LONG(rtnval);
besEND

// Refresh
besFUNCTION(SB_TerminalRefresh)
  DIM AS int rtnval;
  rtnval = SDL_TerminalRefresh(terminal);
  besRETURN_LONG(rtnval);
besEND

// Clear
besFUNCTION(SB_TerminalClear)
  DIM AS int rtnval;
  rtnval = SDL_TerminalClear(terminal);
  besRETURN_LONG(rtnval);
besEND

// Print
besFUNCTION(SB_TerminalPrint)
  DIM AS char PTR text;
  DIM AS int rtnval;
  besARGUMENTS("z")
    AT text
  besARGEND
  rtnval = SDL_TerminalPrint(terminal, text);
  besRETURN_LONG(rtnval);
besEND

// Print At
besFUNCTION(SB_TerminalPrintAt)
  DIM AS int row, column, rtnval;
  DIM AS char PTR text;
  besARGUMENTS("iiz")
    AT row, AT column, AT text
  besARGEND
  rtnval = SDL_TerminalPrintAt(terminal, row, column, text);
  besRETURN_LONG(rtnval);
besEND

// Reset
besFUNCTION(SB_TerminalReset)
  DIM AS int rtnval;
  rtnval = SDL_TerminalReset(terminal);
  besRETURN_LONG(rtnval);
besEND

// Set Font
besFUNCTION(SB_TerminalSetFont)
  DIM AS char PTR font_filename;
  DIM AS int size, rtnval;
  besARGUMENTS("zi")
    AT font_filename, AT size
  besARGEND
  rtnval = SDL_TerminalSetFont(terminal, font_filename, size);
  besRETURN_LONG(rtnval);
besEND

// Set Size
besFUNCTION(SB_TerminalSetSize)
  DIM AS int row, column, rtnval;
  besARGUMENTS("ii")
    AT row, AT column
  besARGEND
  rtnval = SDL_TerminalSetSize(terminal, row, column);
  besRETURN_LONG(rtnval);
besEND

// Set Position
besFUNCTION(SB_TerminalSetPosition)
  DIM AS int x, y, rtnval;
  besARGUMENTS("ii")
    AT x, AT y
  besARGEND
  rtnval = SDL_TerminalSetPosition(terminal, x, y);
  besRETURN_LONG(rtnval);
besEND

// Set Color
besFUNCTION(SB_TerminalSetColor)
  DIM AS int red, green, blue, alpha, rtnval;
  besARGUMENTS("iiii")
    AT red, AT green, AT blue, AT alpha
  besARGEND
  rtnval = SDL_TerminalSetColor(terminal, red, green, blue, alpha);
  besRETURN_LONG(rtnval);
besEND

// Set Border Color
besFUNCTION(SB_TerminalSetBorderColor)
  DIM AS int red, green, blue, alpha, rtnval;
  besARGUMENTS("iiii")
    AT red, AT green, AT blue, AT alpha
  besARGEND
  rtnval = SDL_TerminalSetBorderColor(terminal, red, green, blue, alpha);
  besRETURN_LONG(rtnval);
besEND

// Set Border Size
besFUNCTION(SB_TerminalSetBorderSize)
  DIM AS int size, rtnval;
  besARGUMENTS("i")
    AT size
  besARGEND
  rtnval = SDL_TerminalSetBorderSize(terminal, size);
  besRETURN_LONG(rtnval);
besEND

// Set Default FG Color
besFUNCTION(SB_TerminalSetDefaultForeground)
  DIM AS int red, green, blue, alpha, rtnval;
  besARGUMENTS("iiii")
    AT red, AT green, AT blue, AT alpha
  besARGEND
  rtnval = SDL_TerminalSetDefaultForeground(terminal, red, green, blue, alpha);
  besRETURN_LONG(rtnval);
besEND

// Set Default BG Color
besFUNCTION(SB_TerminalSetDefaultBackground)
  DIM AS int red, green, blue, alpha, rtnval;
  besARGUMENTS("iiii")
    AT red, AT green, AT blue, AT alpha
  besARGEND
  rtnval = SDL_TerminalSetDefaultBackground(terminal, red, green, blue, alpha);
  besRETURN_LONG(rtnval);
besEND

// Set FG Color
besFUNCTION(SB_TerminalSetForeground)
  DIM AS int red, green, blue, alpha, rtnval;
  besARGUMENTS("iiii")
    AT red, AT green, AT blue, AT alpha
  besARGEND
  rtnval = SDL_TerminalSetForeground(terminal, red, green, blue, alpha);
  besRETURN_LONG(rtnval);
besEND

// Set BG Color
besFUNCTION(SB_TerminalSetBackground)
  DIM AS int red, green, blue, alpha, rtnval;
  besARGUMENTS("iiii")
    AT red, AT green, AT blue, AT alpha
  besARGEND
  rtnval = SDL_TerminalSetBackground(terminal, red, green, blue, alpha);
  besRETURN_LONG(rtnval);
besEND

// Enable Bold
besFUNCTION(SB_TerminalEnableBold)
  DIM AS int rtnval;
  rtnval = SDL_TerminalEnableBold(terminal);
  besRETURN_LONG(rtnval);
besEND

// Enable Underline
besFUNCTION(SB_TerminalEnableUnderline)
  DIM AS int rtnval;
  rtnval = SDL_TerminalEnableUnderline(terminal);
  besRETURN_LONG(rtnval);
besEND

// Enable Italic
besFUNCTION(SB_TerminalEnableItalic)
  DIM AS int rtnval;
  rtnval = SDL_(terminal);
  besRETURN_LONG(rtnval);
besEND

// Disable Bold
besFUNCTION(SB_TerminalDisableBold)
  DIM AS int rtnval;
  rtnval = SDL_TerminalDisableBold(terminal);
  besRETURN_LONG(rtnval);
besEND

// Disable Underline
besFUNCTION(SB_TerminalDisableUnderline)
  DIM AS int rtnval;
  rtnval = SDL_TerminalDisableUnderline(terminal);
  besRETURN_LONG(rtnval);
besEND

// Disable Italic
besFUNCTION(SB_TerminalDisableItalic)
  DIM AS int rtnval;
  rtnval = SDL_TerminalDisableItalic(terminal);
  besRETURN_LONG(rtnval);
besEND

// Event
besFUNCTION(SB_TerminalProcessEvent)
  DIM AS const SDL_Event PTR event;
  DIM AS int rtnval;
  rtnval = SDL_TerminalProcessEvent(terminal, event);
  besRETURN_LONG(rtnval);
besEND


/*******************
 SDL Image Functions
*******************/

// Load Image
besFUNCTION(SB_LoadImage)
  DIM AS SDL_Surface PTR image;
  DIM AS char PTR filename;
  besARGUMENTS("z")
    AT filename
  besARGEND
  image = IMG_Load(filename);
  besRETURN_POINTER(image);
besEND

// Delete Image
besFUNCTION(SB_DeleteImage)
  DIM AS SDL_Surface PTR this_image;
  besARGUMENTS("p")
    AT this_image
  besARGEND
  SDL_FreeSurface(this_image);
  besRETURNVALUE = NULL;
besEND

// Show Image
besFUNCTION(SB_ShowImage)
  DIM AS SDL_Surface PTR this_image;
  DIM AS SDL_Rect dest;
  DIM AS int x, y;
  besARGUMENTS("pii")
    AT this_image, AT x, AT y
  besARGEND
  dest.x = x;
  dest.y = y;
  dest.w = this_image->w;
  dest.h = this_image->h;
  SDL_BlitSurface(this_image, NULL, screen, AT dest);
  SDL_UpdateRects(screen, 1, AT dest);
  besRETURNVALUE = NULL;
besEND


/*********************
 BBC Graphic Functions
*********************/

#define TOFLOAT(x) ((float64)(x))
#define TOINT(x) ((int32)(x))

DIM AS static int32 lastrandom;
DIM AS static int32 randomoverflow;
DIM AS static float64 floatvalue;

FUNCTION LOCAL float64 randomfraction(void)
BEGIN_FUNCTION
  uint32 reversed = ((lastrandom>>24)&0xFF)|((lastrandom>>8)&0xFF00)|((lastrandom<<8)&0xFF0000)|((lastrandom<<24)&0xFF000000);
  RETURN_FUNCTION(TOFLOAT(reversed) / 4294967296.0);
END_FUNCTION

LOCAL SUB nextrandom(void)
BEGIN_SUB
  DIM AS int n;
  FOR (n = 0 TO n < 32 STEP INCR n)
  BEGIN_FOR
    int newbit = ((lastrandom>>19) ^ randomoverflow) & 1;
    randomoverflow = lastrandom>>31;
    lastrandom = (lastrandom<<1) | newbit;
  NEXT
END_SUB

// BBC_OPEN
besFUNCTION(BBC_init_screen)
  DIM AS int rtnval;
  srand((unsigned)time(NULL));
  lastrandom=rand();
  randomoverflow = 0;
  rtnval = init_screen();
  besRETURN_LONG(rtnval);
besEND

// BBC_CLOSE
besFUNCTION(BBC_end_screen)
  end_screen();
  besRETURNVALUE = NULL;
besEND

// BBC_MODE
besFUNCTION(BBC_emulate_mode)
  DIM AS int32 mode;
  besARGUMENTS("i")
    AT mode
  besARGEND
  emulate_mode(mode);
  besRETURNVALUE = NULL;
besEND

// BBC_MODESTR
besFUNCTION(BBC_emulate_modestr)
  DIM AS int32 xres, yres, colours, greys, xeig, yeig, rate;
  besARGUMENTS("iiiiiii")
    AT xres, AT yres, AT colours, AT greys, AT xeig, AT yeig, AT rate
  besARGEND
  emulate_modestr(xres, yres, colours, greys, xeig, yeig, rate);
  besRETURNVALUE = NULL;
besEND

// BBC_NEWMODE
besFUNCTION(BBC_emulate_newmode)
  DIM AS int32 xres, yres, bpp, rate;
  besARGUMENTS("iiiiiii")
    AT xres, AT yres, AT bpp, AT rate
  besARGEND
  emulate_newmode(xres, yres, bpp, rate);
  besRETURNVALUE = NULL;
besEND

// BBC_MODEFN
besFUNCTION(BBC_emulate_modefn)
  DIM AS int rtnval;
  rtnval = emulate_modefn();
  besRETURN_LONG(rtnval);
besEND

// BBC_ORIGIN
besFUNCTION(BBC_emulate_origin)
  DIM AS int32 x, y;
  besARGUMENTS("ii")
    AT x, AT y
  besARGEND
  emulate_origin(x, y);
  besRETURNVALUE = NULL;
besEND

// BBC_GCOL
besFUNCTION(BBC_emulate_gcol)
  DIM AS int32 action, colour, tint;
  besARGUMENTS("ii[i]")
    AT action, AT colour, AT tint
  besARGEND
  emulate_gcol(action, colour, tint);
  besRETURNVALUE = NULL;
besEND

// BBC_GCOLRGB
besFUNCTION(BBC_emulate_gcolrgb)
  DIM AS int32 action, background, red, green, blue;
  besARGUMENTS("iiiii")
    AT action, AT background, AT red, AT green, AT blue
  besARGEND
  emulate_gcolrgb(action, background, red, green, blue);
  besRETURNVALUE = NULL;
besEND

// BBC_GCOLNUM
besFUNCTION(BBC_emulate_gcolnum)
  DIM AS int32 action, background, colnum;
  besARGUMENTS("iii")
    AT action, AT background, AT colnum
  besARGEND
  emulate_gcolnum(action, background, colnum);
  besRETURNVALUE = NULL;
besEND

// BBC_COLOURFN
besFUNCTION(BBC_emulate_colourfn)
  DIM AS int32 red, green, blue, rtnval;
  besARGUMENTS("iii")
    AT red, AT green, AT blue
  besARGEND
  rtnval = emulate_colourfn(red, green, blue);
  besRETURN_LONG(rtnval);
besEND

// BBC_MAPCOLOUR
besFUNCTION(BBC_emulate_mapcolour)
  DIM AS int32 colour, physcolour;
  besARGUMENTS("ii")
    AT colour, AT physcolour
  besARGEND
  emulate_mapcolour(colour, physcolour);
  besRETURNVALUE = NULL;
besEND

// BBC_SETCOLOUR
besFUNCTION(BBC_emulate_setcolour)
  DIM AS int32 background, red, green, blue;
  besARGUMENTS("iiii")
    AT background, AT red, AT green, AT blue
  besARGEND
  emulate_setcolour(background, red, green, blue);
  besRETURNVALUE = NULL;
besEND

// BBC_SETCOLNUM
besFUNCTION(BBC_emulate_setcolnum)
  DIM AS int32 background, colnum;
  besARGUMENTS("ii")
    AT background, AT colnum
  besARGEND
  emulate_setcolnum(background, colnum);
  besRETURNVALUE = NULL;
besEND

// BBC_DEFCOLOUR
besFUNCTION(BBC_emulate_defcolour)
  DIM AS int32 colour, red, green, blue;
  besARGUMENTS("iiii")
    AT colour, AT red, AT green, AT blue
  besARGEND
  emulate_defcolour(colour, red, green, blue);
  besRETURNVALUE = NULL;
besEND

// BBC_COLOURTINT
besFUNCTION(BBC_emulate_colourtint)
  DIM AS int32 colour, tint;
  besARGUMENTS("ii")
    AT colour, AT tint
  besARGEND
  emulate_colourtint(colour, tint);
  besRETURNVALUE = NULL;
besEND

// BBC_TINT
besFUNCTION(BBC_emulate_tint)
  DIM AS int32 action, tint;
  besARGUMENTS("ii")
    AT action, AT tint
  besARGEND
  emulate_tint(action, tint);
  besRETURNVALUE = NULL;
besEND

// BBC_TINTFN
besFUNCTION(BBC_emulate_tintfn)
  DIM AS int32 x, y, rtnval;
  besARGUMENTS("ii")
    AT x, AT y
  besARGEND
  rtnval = emulate_tintfn(x, y);
  besRETURN_LONG(rtnval);
besEND

// BBC_PLOT
besFUNCTION(BBC_emulate_plot)
  DIM AS int32 code, x, y;
  besARGUMENTS("iii")
    AT code, AT x, AT y
  besARGEND
  emulate_plot(code, x, y);
  besRETURNVALUE = NULL;
besEND

// BBC_POINTFN
besFUNCTION(BBC_emulate_pointfn)
  DIM AS int32 x, y, rtnval;
  besARGUMENTS("ii")
    AT x, AT y
  besARGEND
  rtnval = emulate_pointfn(x, y);
  besRETURN_LONG(rtnval);
besEND

// BBC_MOVE
besFUNCTION(BBC_emulate_move)
  DIM AS int32 x, y;
  besARGUMENTS("ii")
    AT x, AT y
  besARGEND
  emulate_move(x, y);
  besRETURNVALUE = NULL;
besEND

// BBC_MOVEBY
besFUNCTION(BBC_emulate_moveby)
  DIM AS int32 x, y;
  besARGUMENTS("ii")
    AT x, AT y
  besARGEND
  emulate_moveby(x, y);
  besRETURNVALUE = NULL;
besEND

// BBC_DRAW
besFUNCTION(BBC_emulate_draw)
  DIM AS int32 x, y;
  besARGUMENTS("ii")
    AT x, AT y
  besARGEND
  emulate_draw(x, y);
  besRETURNVALUE = NULL;
besEND

// BBC_DRAWBY
besFUNCTION(BBC_emulate_drawby)
  DIM AS int32 x, y;
  besARGUMENTS("ii")
    AT x, AT y
  besARGEND
  emulate_drawby(x, y);
  besRETURNVALUE = NULL;
besEND

// BBC_POINT
besFUNCTION(BBC_emulate_point)
  DIM AS int32 x, y;
  besARGUMENTS("ii")
    AT x, AT y
  besARGEND
  emulate_point(x, y);
  besRETURNVALUE = NULL;
besEND

// BBC_POINTBY
besFUNCTION(BBC_emulate_pointby)
  DIM AS int32 x, y;
  besARGUMENTS("ii")
    AT x, AT y
  besARGEND
  emulate_pointby(x, y);
  besRETURNVALUE = NULL;
besEND

// BBC_POINTTO
besFUNCTION(BBC_emulate_pointto)
  DIM AS int32 x, y;
  besARGUMENTS("ii")
    AT x, AT y
  besARGEND
  emulate_pointto(x, y);
  besRETURNVALUE = NULL;
besEND

// BBC_LINE
besFUNCTION(BBC_emulate_line)
  DIM AS int32 x1, y1, x2, y2;
  besARGUMENTS("iiii")
    AT x1, AT y1, AT x2, AT y2
  besARGEND
  emulate_line(x1, y1, x2, y2);
  besRETURNVALUE = NULL;
besEND

// BBC_CIRCLE
besFUNCTION(BBC_emulate_circle)
  DIM AS int32 x, y, radius, isfilled;
  besARGUMENTS("iiii")
    AT x, AT y, AT radius, AT isfilled
  besARGEND
  emulate_circle(x, y, radius, isfilled);
  besRETURNVALUE = NULL;
besEND

// BBC_ELLIPSE
besFUNCTION(BBC_emulate_ellipse)
  DIM AS int32 x, y, majorlen, minorlen, isfilled;
  DIM AS float64 angle;
  besARGUMENTS("iiiiri")
    AT x, AT y, AT majorlen, AT minorlen, AT angle, AT isfilled
  besARGEND
  emulate_ellipse(x, y, majorlen, minorlen, angle, isfilled);
  besRETURNVALUE = NULL;
besEND

// BBC_DRAWRECT
besFUNCTION(BBC_emulate_drawrect)
  DIM AS int32 x1, y1, width, height, isfilled;
  besARGUMENTS("iiiii")
    AT x1, AT y1, AT width, AT height, AT isfilled
  besARGEND
  emulate_drawrect(x1, y1, width, height, isfilled);
  besRETURNVALUE = NULL;
besEND

// BBC_MOVERECT
besFUNCTION(BBC_emulate_moverect)
  DIM AS int32 x1, y1, width, height, x2, y2, ismove;
  besARGUMENTS("iiiiiii")
    AT x1, AT y1, AT width, AT height, AT x2, AT y2, AT ismove
  besARGEND
  emulate_moverect(x1, y1, width, height, x2, y2, ismove);
  besRETURNVALUE = NULL;
besEND

// BBC_FILL
besFUNCTION(BBC_emulate_fill)
  DIM AS int32 x, y;
  besARGUMENTS("ii")
    AT x, AT y
  besARGEND
  emulate_fill(x, y);
  besRETURNVALUE = NULL;
besEND

// BBC_FILLBY
besFUNCTION(BBC_emulate_fillby)
  DIM AS int32 x, y;
  besARGUMENTS("ii")
    AT x, AT y
  besARGEND
  emulate_fillby(x, y);
  besRETURNVALUE = NULL;
besEND

// BBC_OFF
besFUNCTION(BBC_emulate_off)
  emulate_off();
  besRETURNVALUE = NULL;
besEND

// BBC_ON
besFUNCTION(BBC_emulate_on)
  emulate_on();
  besRETURNVALUE = NULL;
besEND

// BBC_SETCURSOR
besFUNCTION(BBC_set_cursor)
  DIM AS int32 underline;
  besARGUMENTS("i")
    AT underline
  besARGEND
  set_cursor(underline);
  besRETURNVALUE = NULL;
besEND

// BBC_VDU
besFUNCTION(BBC_emulate_vdu)
  DIM AS int32 charvalue;
  besARGUMENTS("i")
    AT charvalue
  besARGEND
  emulate_vdu(charvalue);
  besRETURNVALUE = NULL;
besEND

// BBC_PRINT
besFUNCTION(BBC_emulate_vdustr)
  DIM AS char PTR vdustr;
  besARGUMENTS("s")
    AT vdustr
  besARGEND
  emulate_vdustr(vdustr, strlen(vdustr));
  besRETURNVALUE = NULL;
besEND

// BBC_VDUFN
besFUNCTION(BBC_emulate_vdufn)
  DIM AS int vduvar, rtnval;
  besARGUMENTS("i")
    AT vduvar
  besARGEND
  rtnval = emulate_vdufn(vduvar);
  besRETURN_LONG(rtnval);
besEND

// BBC_NEWLINE
besFUNCTION(BBC_emulate_newline)
  emulate_newline();
  besRETURNVALUE = NULL;
besEND

// BBC_POS
besFUNCTION(BBC_emulate_pos)
  DIM AS int32 rtnval;
  rtnval = emulate_pos();
  besRETURN_LONG(rtnval);
besEND

// BBC_VPOS
besFUNCTION(BBC_emulate_vpos)
  DIM AS int32 rtnval;
  rtnval = emulate_vpos();
  besRETURN_LONG(rtnval);
besEND

// BBC_TAB
besFUNCTION(BBC_emulate_tab)
  DIM AS int32 x, y;
  besARGUMENTS("ii")
    AT x, AT y
  besARGEND
  emulate_tab(x, y);
  besRETURNVALUE = NULL;
besEND

// BBC_RND
besFUNCTION(BBC_RND)
  DIM AS int32 value;
  besARGUMENTS("i")
    AT value
  besARGEND
  IF (value < 0) THEN
    lastrandom = value;
    srand((unsigned)time(NULL));
    value=rand();
    randomoverflow = 0;
    besRETURN_LONG(value);
  ELSE_IF (value EQ 0) THEN
    besRETURN_DOUBLE(randomfraction());
  ELSE_IF (value EQ 1) THEN
    nextrandom();
    besRETURN_DOUBLE(randomfraction());
  ELSE
  nextrandom();
  besRETURN_LONG(TOINT((randomfraction()*TOFLOAT(value))+1));
  END_IF
besEND 
 

/**********************
 Exported Function List
**********************/

START_FUNCTION_TABLE(SDL_SLFST)
// Ext. module
  EXPORT_MODULE_FUNCTION(versmodu)
  EXPORT_MODULE_FUNCTION(bootmodu)
  EXPORT_MODULE_FUNCTION(finimodu)
// SDL API
  EXPORT_MODULE_FUNCTION(SB_Window)
  EXPORT_MODULE_FUNCTION(SB_RGB)
  EXPORT_MODULE_FUNCTION(SB_WaitKey)
  EXPORT_MODULE_FUNCTION(SB_Ticks)
  EXPORT_MODULE_FUNCTION(SB_UpdateRect)
  EXPORT_MODULE_FUNCTION(SB_CLS)
  EXPORT_MODULE_FUNCTION(SB_GetKey)
// SDL_Draw
  EXPORT_MODULE_FUNCTION(SB_Draw_Pixel)
  EXPORT_MODULE_FUNCTION(SB_Draw_Line)
  EXPORT_MODULE_FUNCTION(SB_Draw_Circle)
  EXPORT_MODULE_FUNCTION(SB_Draw_FillCircle)
  EXPORT_MODULE_FUNCTION(SB_Draw_HLine)
  EXPORT_MODULE_FUNCTION(SB_Draw_VLine)
  EXPORT_MODULE_FUNCTION(SB_Draw_Rect)
  EXPORT_MODULE_FUNCTION(SB_Draw_FillRect)
  EXPORT_MODULE_FUNCTION(SB_Draw_Ellipse)
  EXPORT_MODULE_FUNCTION(SB_Draw_FillEllipse)
  EXPORT_MODULE_FUNCTION(SB_Draw_Round)
  EXPORT_MODULE_FUNCTION(SB_Draw_FillRound)
// SDL Terminal
  EXPORT_MODULE_FUNCTION(SB_CreateTerminal)
  EXPORT_MODULE_FUNCTION(SB_DestroyTerminal)
  EXPORT_MODULE_FUNCTION(SB_TerminalBlit)
  EXPORT_MODULE_FUNCTION(SB_TerminalRefresh)
  EXPORT_MODULE_FUNCTION(SB_TerminalClear)
  EXPORT_MODULE_FUNCTION(SB_TerminalPrint)
  EXPORT_MODULE_FUNCTION(SB_TerminalPrintAt)
  EXPORT_MODULE_FUNCTION(SB_TerminalReset)
  EXPORT_MODULE_FUNCTION(SB_TerminalSetFont)
  EXPORT_MODULE_FUNCTION(SB_TerminalSetSize)
  EXPORT_MODULE_FUNCTION(SB_TerminalSetPosition)
  EXPORT_MODULE_FUNCTION(SB_TerminalSetColor)
  EXPORT_MODULE_FUNCTION(SB_TerminalSetBorderColor)
  EXPORT_MODULE_FUNCTION(SB_TerminalSetBorderSize)
  EXPORT_MODULE_FUNCTION(SB_TerminalSetDefaultForeground)
  EXPORT_MODULE_FUNCTION(SB_TerminalSetDefaultBackground)
  EXPORT_MODULE_FUNCTION(SB_TerminalSetForeground)
  EXPORT_MODULE_FUNCTION(SB_TerminalSetBackground)
  EXPORT_MODULE_FUNCTION(SB_TerminalEnableBold)
  EXPORT_MODULE_FUNCTION(SB_TerminalEnableUnderline)
  EXPORT_MODULE_FUNCTION(SB_TerminalEnableItalic)
  EXPORT_MODULE_FUNCTION(SB_TerminalDisableBold)
  EXPORT_MODULE_FUNCTION(SB_TerminalDisableUnderline)
  EXPORT_MODULE_FUNCTION(SB_TerminalDisableItalic)
  EXPORT_MODULE_FUNCTION(SB_TerminalProcessEvent)
// SDL Image
  EXPORT_MODULE_FUNCTION(SB_LoadImage)
  EXPORT_MODULE_FUNCTION(SB_DeleteImage)
  EXPORT_MODULE_FUNCTION(SB_ShowImage)
// BBC Graphics
  EXPORT_MODULE_FUNCTION(BBC_init_screen)
  EXPORT_MODULE_FUNCTION(BBC_end_screen)
  EXPORT_MODULE_FUNCTION(BBC_emulate_mode)
  EXPORT_MODULE_FUNCTION(BBC_emulate_modestr)
  EXPORT_MODULE_FUNCTION(BBC_emulate_newmode)
  EXPORT_MODULE_FUNCTION(BBC_emulate_modefn)
  EXPORT_MODULE_FUNCTION(BBC_emulate_origin)
  EXPORT_MODULE_FUNCTION(BBC_emulate_gcol)
  EXPORT_MODULE_FUNCTION(BBC_emulate_gcolrgb)
  EXPORT_MODULE_FUNCTION(BBC_emulate_gcolnum)
  EXPORT_MODULE_FUNCTION(BBC_emulate_colourfn)
  EXPORT_MODULE_FUNCTION(BBC_emulate_mapcolour)
  EXPORT_MODULE_FUNCTION(BBC_emulate_setcolour)
  EXPORT_MODULE_FUNCTION(BBC_emulate_setcolnum)
  EXPORT_MODULE_FUNCTION(BBC_emulate_defcolour)
  EXPORT_MODULE_FUNCTION(BBC_emulate_colourtint)
  EXPORT_MODULE_FUNCTION(BBC_emulate_tint)
  EXPORT_MODULE_FUNCTION(BBC_emulate_tintfn)
  EXPORT_MODULE_FUNCTION(BBC_emulate_plot)
  EXPORT_MODULE_FUNCTION(BBC_emulate_pointfn)
  EXPORT_MODULE_FUNCTION(BBC_emulate_move)
  EXPORT_MODULE_FUNCTION(BBC_emulate_moveby)
  EXPORT_MODULE_FUNCTION(BBC_emulate_drawby)
  EXPORT_MODULE_FUNCTION(BBC_emulate_draw)
  EXPORT_MODULE_FUNCTION(BBC_emulate_point)
  EXPORT_MODULE_FUNCTION(BBC_emulate_pointby)
  EXPORT_MODULE_FUNCTION(BBC_emulate_pointto)
  EXPORT_MODULE_FUNCTION(BBC_emulate_line)
  EXPORT_MODULE_FUNCTION(BBC_emulate_circle)
  EXPORT_MODULE_FUNCTION(BBC_emulate_ellipse)
  EXPORT_MODULE_FUNCTION(BBC_emulate_drawrect)
  EXPORT_MODULE_FUNCTION(BBC_emulate_moverect)
  EXPORT_MODULE_FUNCTION(BBC_emulate_fill)
  EXPORT_MODULE_FUNCTION(BBC_emulate_fillby)
  EXPORT_MODULE_FUNCTION(BBC_emulate_off)
  EXPORT_MODULE_FUNCTION(BBC_emulate_on)
  EXPORT_MODULE_FUNCTION(BBC_set_cursor)
  EXPORT_MODULE_FUNCTION(BBC_emulate_vdu)
  EXPORT_MODULE_FUNCTION(BBC_emulate_vdustr)
  EXPORT_MODULE_FUNCTION(BBC_emulate_vdufn)
  EXPORT_MODULE_FUNCTION(BBC_emulate_newline)
  EXPORT_MODULE_FUNCTION(BBC_emulate_pos)
  EXPORT_MODULE_FUNCTION(BBC_emulate_vpos)
  EXPORT_MODULE_FUNCTION(BBC_emulate_tab)
  EXPORT_MODULE_FUNCTION(BBC_RND)
END_FUNCTION_TABLE

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: ScriptBasic SDL extension module project
« Reply #1 on: January 31, 2014, 09:25:10 PM »
Here is an update of the interface.c and a Ubuntu 64 bit sdl.so SDL extension module. This release fixed a typo with BBC_NEWMODE and the addition of SB_shifts (bit shifting functions) contributed by Charles.