Can SDCC (Small Device C Compiler) be used with BCX?

Started by Wysardry, August 03, 2022, 12:11:25 PM

Previous topic - Next topic

Wysardry

I would like to be able to create several text adventures (similar to Colossal Cave Adventure), so I shouldn't need to use many commands that rely on the WinAPI.

I'm hoping that SDCC includes routines for clearing the screen etc. that I could access via inline C code if need be.

MBC looks interesting, especially as I also own a Raspberry Pi that I haven't done much with yet. Does it also run on Windows?

MrBcx

Quote from: Wysardry on August 03, 2022, 02:28:18 PM
I probably phrased that badly. I meant is it possible to use BCX with SDCC (instead of Pelles C or one of the other C compilers that are known to work) to create text only programs that will run on 8-bit computers?

I have used BCX in the past, but it was around ten years ago and only to create Windows programs. I'm fairly sure I used something called "BCX DevSuite" or similar that also installed an IDE and compiler and set them up.

I am not sure if BCX adds Windows specific code to console programs or if it can create C code that follows any of the standards that SDCC can handle (ANSI C89, ISO C99, ISO C11).

I dislike C-style syntax and am hoping to avoid working directly in C source code as much as possible.

BCX makes heavy use of the WinApi, even for console mode programs.  You won't get away with much beyond
PRINT "Hello, World!" without some call to the WinApi.  Basic keywords like: LOCATE, COLOR, CLS, etc all have
WinAPI dependencies.

If you're looking for a somewhat agnostic version of BCX, you could look at

https://github.com/Airr/MBC

but I won't be able to answer many questions about this.  There are others, including the recently returned
forum member and author of MBC ( Armando Rivera ) who might be able to provide some guidance.

HTH

Wysardry

I probably phrased that badly. I meant is it possible to use BCX with SDCC (instead of Pelles C or one of the other C compilers that are known to work) to create text only programs that will run on 8-bit computers?

I have used BCX in the past, but it was around ten years ago and only to create Windows programs. I'm fairly sure I used something called "BCX DevSuite" or similar that also installed an IDE and compiler and set them up.

I am not sure if BCX adds Windows specific code to console programs or if it can create C code that follows any of the standards that SDCC can handle (ANSI C89, ISO C99, ISO C11).

I dislike C-style syntax and am hoping to avoid working directly in C source code as much as possible.

MrBcx

Hello Wysardry and welcome to the BCX forum.

Short answer - no.

Longer answer - BCX is a code-to-code translator, not a compiler.
That means you -could- use some of the features of the BCX BASIC language to write some "c" code for you.

A simple, fictionalized version of this idea:

Demonstration.bas

$ZAP
$NOWIN
$WARNINGS_ON

#include SomeSDCCHeader.h

SUB MAIN
    DIM Foo1 AS SomeSDCCDataType
    DIM Foo2[256] AS CHAR
    DIM Foo3 AS INTEGER

    FOR INT i = 1 TO 10
        CALL SomeSDCCFunction(Foo1, Foo2, Foo3)
    NEXT

END SUB




would be translated thusly:


// *************************************************
//      Made with BCX BASIC To C/C++ Translator
//            Version 7.9.3 (07/28/2022)
// *************************************************
//    Translated for compiling with a C Compiler
// *************************************************
#define _CRT_SECURE_NO_DEPRECATE


// *************************************************
//            System Defined Constants
// *************************************************

#define BCXSTRSIZE 2048
#include SomeSDCCHeader.h

// *************************************************
//                  Compiler Defines
// *************************************************

#if defined(__cplusplus)
  #define overloaded
  #define C_EXPORT EXTERN_C __declspec(dllexport)
  #define C_IMPORT EXTERN_C __declspec(dllimport)
#else
  #define C_EXPORT __declspec(dllexport)
  #define C_IMPORT __declspec(dllimport)
#endif

// *************************************************
//                   Microsoft VC++
// *************************************************

#ifndef DECLSPEC_UUID
  #if(_MSC_VER >= 1100) && defined(__cplusplus)
    #define DECLSPEC_UUID(x)  __declspec(uuid(x))
  #else
    #define DECLSPEC_UUID(x)
  #endif
#endif
#if (_MSC_VER >= 1900)            // earlier versions untested
   #include <intrin.h>
      #ifndef _rdtsc
         #define _rdtsc __rdtsc   // MSVC uses 2 underscores
      #endif
#endif

// *************************************************
//                  GCC and CLANG
// *************************************************

#if defined(__GNUC__) || defined(__clang__)
   #ifndef __BCPLUSPLUS__
      #include <x86intrin.h>
   #endif
#endif

// *************************************************
//                  Embarcadero C++
// *************************************************

#if defined(__BCPLUSPLUS__)
      #if defined (_clang__)
          #include <mmintrin.h>
      #endif
      #define _kbhit kbhit
      #ifndef _rdtsc
         #define _rdtsc __rdtsc  // Uses 2 underscores
      #endif
#endif

// *************************************************
//                    Open Watcom
// *************************************************

#if defined(__WATCOM_CPLUSPLUS__)
    #define _fcloseall fcloseall
#endif

// *************************************************
//                     Lcc-Win32
// *************************************************

#if defined(__LCC__)
    #define _fseeki64  fseeki64
    #define _stricmp   stricmp
    #define _strnicmp  strnicmp
    #define _itoa      itoa
    #define _ltoa      ltoa
    #include <intrinsics.h>
    #include <malloc.h>  // for _msize
    #if defined(__windows_h__)
       #define COMPILE_MULTIMON_STUBS
       #include <multimon.h>
       #include <iehelper.h>
       #include <exdisp.h>
    #endif
#endif

// *************************************************
//                     Pelles C
// *************************************************

#if defined(__POCC__)
    #include <intrin.h>
    #pragma pack_stack(off)        // Pelle's fix for a v10 optimization bug
#endif


// *************************************************
//            User's Global Variables
// *************************************************

static SomeSDCCDataType Foo1;
static int     Foo3;
static char    Foo2[256];

// *************************************************
//            User's Global Initialized Arrays
// *************************************************


// *************************************************
//                 Runtime Functions
// *************************************************


// *************************************************
//                  Main Program
// *************************************************

int main(int argc, char *argv[])
{
  for(int i=1; i<=10; i++)
    {
      SomeSDCCFunction(Foo1,Foo2,Foo3);
    }
  return EXIT_SUCCESS;   // End of main program
  }


Manually removing irrelevant equates, directives, etc could reduce that output to:



// *************************************************
//      Made with BCX BASIC To C/C++ Translator
//            Version 7.9.3 (07/28/2022)
// *************************************************
//    Translated for compiling with a C Compiler
// *************************************************

#include SomeSDCCHeader.h

// *************************************************
//                  Compiler Defines
// *************************************************

#if defined(__cplusplus)
  #define overloaded
  #define C_EXPORT EXTERN_C __declspec(dllexport)
  #define C_IMPORT EXTERN_C __declspec(dllimport)
#else
  #define C_EXPORT __declspec(dllexport)
  #define C_IMPORT __declspec(dllimport)
#endif

// *************************************************
//            User's Global Variables
// *************************************************

static SomeSDCCDataType Foo1;
static int     Foo3;
static char    Foo2[256];

// *************************************************
//                  Main Program
// *************************************************

int main(int argc, char *argv[])
{
  for(int i=1; i<=10; i++)
    {
      SomeSDCCFunction(Foo1,Foo2,Foo3);
    }
  return EXIT_SUCCESS;   // End of main program
  }



some of which you might find useful.


Wysardry

Does anyone know if it would be possible to use SDCC with BCX to compile text only (console) programs for 8-bit machines?