Skip to content

Commit

Permalink
Added DDE example in C and fixed a minor bug in the build process
Browse files Browse the repository at this point in the history
  • Loading branch information
pzaino committed Dec 29, 2023
1 parent 0dcdcb3 commit d198b9c
Show file tree
Hide file tree
Showing 17 changed files with 323 additions and 0 deletions.
Binary file modified !LibZVector/a/libzvector
Binary file not shown.
149 changes: 149 additions & 0 deletions !LibZVector/h/zvector_checks
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
/*
* Name: ZVector_Checks
* Purpose: Header used by ZVector Library to identify for which
* platform ZVector is being compiled.
* Author: Paolo Fabio Zaino
* Domain: General
* License: Copyright 2021 by Paolo Fabio Zaino, all rights reserved
* Distributed under MIT license
*
*/

#ifndef SRC_ZVECTOR_CHECKS_H_
#define SRC_ZVECTOR_CHECKS_H_

// Try to determine the Operating System being used:
#if defined(__APPLE__) && defined(__MACH__)
# define macOS
#endif

#if ( defined(__GNU__) || defined(__gnu_linux__) || \
defined(__linux__) || defined(macOS) )
# define OS_TYPE 1
#elif ( defined(__WIN32__) || defined(WIN32) || defined(_WIN32) )
# define OS_TYPE 2
#else
# define OS_TYPE 0
#endif

// Try to determine compiler being used:
#if defined(__GNUC__)
# define compiler gcc
# define ZVECT_COMPTYPE 1
# define COMP_MAJRELEASE (__GNUC__)
# define COMP_MINRELEASE (__GNUC_MINOR__)
# define COMP_PATRELEASE (__GNUC_PATCHLEVEL__)
#elif defined(__NORCROFT_C__) || defined(__CC_NORCROFT) || \
defined(__ARMCC_VERSION)
// For Norcroft C please remember to specify:
// -c99
# define compiler norcroftc
# define ZVECT_COMPTYPE 6
# define COMP_MAJRELEASE (__ARMCC_VERSION)
# define _MSC_VER 0
#elif defined(_MSC_VER)
# define compiler msc
# define ZVECT_COMPTYPE 2
# define COMP_MAJRELEASE (_MSC_VER)
# define COMP_MINRELEASE 0
# define COMP_PATRELEASE 0
#elif defined(__clang__)
# define compiler clang
# define ZVECT_COMPTYPE 3
# define COMP_MAJRELEASE (__clang_major__)
# define COMP_MINRELEASE (__clang_minor__)
# define COMP_PATRELEASE (__clang_patchlevel__)
#elif defined(__INTEL_COMPILER) || defined(__ICC) || \
defined(__ECC) || defined(__ICL)
// For intel c compiler please remember to specify:
// /Qstd=c99 (on Windows)
// -std=c99 on Linux and/or macOS
# define compiler intelc
# define ZVECT_COMPTYPE 4
# define COMP_MAJRELEASE (__INTEL_COMPILER)
# define COMP_MINRELEASE 0
# define COMP_PATRELEASE 0
#elif defined (__LCC__)
# define compiler lcc
# define ZVECT_COMPTYPE 5
# define COMP_MAJRELEASE (__LCC)
# define COMP_MINRELEASE 0
# define COMP_PATRELEASE 0
#elif defined(_CRAYC)
// For Cray C please remember to specify:
// -hc99
# define compiler crayc
# define ZVECT_COMPTYPE 10
# define COMP_MAJRELEASE (_RELEASE)
# define COMP_MINRELEASE (_RELEASE_MINOR)
# define COMP_PATRELEASE 0
#elif defined(__HP_cc)
// For HP CC please remember to specify:
// -ansi -std=c99
# define compiler hpc
# define ZVECT_COMPTYPE 11
# define COMP_MAJRELEASE 1
# define COMP_MINRELEASE 21
# define COMP_PATRELEASE 0
#elif defined(__IBMC__)
// For IBM C please remember to specify:
// C99 flags
# define compiler ibmc
# define ZVECT_COMPTYPE 12
#elif defined(__TINYC__)
# define compiler tinyc
# define ZVECT_COMPTYPE 6
# define COMP_MAJRELEASE 0
# define COMP_MINRELEASE 0
# define COMP_PATRELEASE 0
#else
# define compiler unknown
# define ZVECT_COMPTYPE 0
#endif
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
#pragma once
#endif

// Try to determine CPU Architecture:
#define ARM32 0
#define ARM64 1
#define x86_64 2
#define unknown -1
#if defined(__aarch64__)
# define CPU_TYPE ARM64
# define Arch64
#elif defined(__aarch32__)
# define CPU_TYPE ARM32
# define Arch32
#elif defined(__amd64__) || defined(__x86_64__) || \
defined(__ia64__) || defined(_M_IA64) || \
defined(_M_AMD64) || defined(_M_X64)
# define CPU_TYPE x86_64
# define Arch64
#else
# define CPU_TYPE unknown
# define Arch32
#endif

// Start setting up macros based on the platform we detected
// above.

#if ( OS_TYPE == 1 )
// We are on a Unix-like OS so we can use pthreads!
# define MUTEX_TYPE 1
# elif ( OS_TYPE == 2 ) && ( defined(__CYGWIN__) || \
defined(__MINGW32__) || defined(__MINGW64__) )
// We are on MS Windows using CIGWIN so we can use pthreads!
# define MUTEX_TYPE 1
# elif ( OS_TYPE == 2 ) && ( !defined(__CYGWIN__) && \
!defined(__MINGW32__) && !defined(__MINGW64__) )
// We are on MS Windows, so we need to use
// Windows stuff:
# define MUTEX_TYPE 2
#else
// I have no idea on which platform are we,
// hence I have to use fake mutexes and go with the flow!
# define MUTEX_TYPE 0
#endif

#endif // SRC_ZVECTOR_CHECKS_H_
90 changes: 90 additions & 0 deletions !LibZVector/h/zvector_config
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* Name: Vector_config
* Purpose: Base configuration for the ZVector library
* Author: Paolo Fabio Zaino
* Domain: General
* License: Copyright by Paolo Fabio Zaino, all rights reserved
* Distributed under MIT license
*
*/

#ifndef SRC_ZVECTOR_CONFIG_H_
#define SRC_ZVECTOR_CONFIG_H_
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
#pragma once
#endif

// Include some standard C lib header
#include <stdint.h>
#include <stdbool.h>

// Data alignment configuration
#if ( ZVECT_COMPTYPE == 1 )
#define ZVECT_DATAALIGN __attribute__((aligned))
#define ZVECT_PACKING __attribute__((__packed__))
#define ZVECT_ALWAYSINLINE __attribute__ ((__always_inline__))
#else
#define ZVECT_DATAALIGN
#define ZVECT_PACKING
#define ZVECT_ALWAYSINLINE
#endif

// Default vector Index type
// This is set to unsigned int of 32bit
// size (so all different architectures
// and OS behaves in a similar way)
// If you want a larger index you can
// change it to, for example, uint64_t
typedef uint32_t zvect_index;
#define zvect_index_max UINT32_MAX // If you change zvect_index type make sure you update this value
// it's the maximum number that can be stored in a zvect_index.

// Default vector return type for
// error codes.
// Generally negative numbers identify
// an error.
// 0 identify completed successful
// Positive numbers identify return
// attributes, like 1 is generally true
typedef int32_t zvect_retval;

// Default vector storage size
// This will be used when the user
// specifies 0 (zero) as data type
// size.
#define ZVECT_DEFAULT_DATA_SIZE sizeof(int)

// Default vector capacity
// This will be used when the user
// does NOT specify an Initial Capacity
// or set it to 0 (zero):
#define ZVECT_INITIAL_CAPACITY 8

// The following options are handled by Make
// So you should not need to modify them here.

// Choose which type of memory functions you want
// to use for your case:
// 0 = Use Standard memcpy and memmove
// 1 = Use Optimized memcpy and memmove
#define ZVECT_MEMX_METHOD 0

// Enable/Disable thread safe code:
#define ZVECT_THREAD_SAFE 0

// Enable/Disable reentrant code:
#define ZVECT_FULL_REENTRANT 0

// Enable/Disable DMF Extensions:
#define ZVECT_DMF_EXTENSIONS 1

// Enable/Disable SFMD Extensions:
#define ZVECT_SFMD_EXTENSIONS 1

// If you are using ZVector on a system
// that supports cooperative multitasking
// (like RISC OS or some embedded systems)
// then uncomment the following line:
//#define ZVECT_COOPERATIVE

#endif // SRC_ZVECTOR_CONFIG_H_
Binary file modified !LibZVector/so/libzvector.so.1.0.0
Binary file not shown.
2 changes: 2 additions & 0 deletions MkDDE,fd7
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ amu all_libs THROWBACK=-throwback -f MakeFileDDE
IfThere @.o.zvectorlib Then copy @.o.zvectorlib @.^.!LibZVector.o.zvectorlib ~C N
Ifthere @.o.zvectorlibzm Then copy @.o.zvectorlibzm @.^.!LibZVector.o.zvectorlibzm ~C N
Ifthere @.h.zvector Then copy @.h.zvector @.^.!LibZVector.h.zvector ~C N
Ifthere @.h.zvector_checks Then copy @.h.zvector_checks @.^.!LibZVector.h.zvector_checks ~C N
Ifthere @.h.zvector_config Then copy @.h.zvector_config @.^.!LibZVector.h.zvector_config ~C N

echo
echo ---------------------
Expand Down
3 changes: 3 additions & 0 deletions MkGCC,fd7
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ make all THROWBACK=-throwback -f MakeFileGCC
|IfThere @.libzvector/a Then copy @.libzvector/a @.^.!LibZVector.a.libzvector ~C N
|IfThere @.libzvector/so/* Then copy @.libzvector/so/* @.^.LibZVector.so.* ~C N
|IfThere @.h.libzvector Then copy @.h.ezini @.^.!LibEzINI.h.ezini ~C N
Ifthere @.h.zvector Then copy @.h.zvector @.^.!LibZVector.h.zvector ~C N
Ifthere @.h.zvector_checks Then copy @.h.zvector_checks @.^.!LibZVector.h.zvector_checks ~C N
Ifthere @.h.zvector_config Then copy @.h.zvector_config @.^.!LibZVector.h.zvector_config ~C N

echo
echo ---------------------
Expand Down
36 changes: 36 additions & 0 deletions examples/dde/CApp/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Makefile for exampleapp

COMPONENT = exampleapp

# The name of the linked file defaults to COMPONENT, which is often the case
# for single-file programs. But when the linked file lives in an application
# directory, it is normally called !RunImage.
TARGET = !RunImage

# The list of source/object files defaults to TARGET, which again is often
# the case for single-file programs. But we don't want our source file to be
# called !RunImage.
OBJS = main

INSTDIR ?= <Obey$Dir>

# The shared makefiles don't attempt to guess the application directory name
# Usually you'll want to place it inside INSTDIR, which is passed in from
# either the MkInstall file, or (for !Builder builds) the components file.
# SEP expands to the directory separator character - we use this instead of
# a literal '.' character to help with cross-compilation.
INSTAPP = ${INSTDIR}${SEP}!Example

# You need to specify all the files that go into the application directory.
# The shared makefiles handle merging the various subdirectories of the
# Resources directory for you.
INSTAPP_FILES = !Boot !Run !Sprites !Sprites11 !Sprites22 !RunImage

include CApp
CINCLUDES += -ILibZVector:zvector.h
LIBS += LibZVector:o.zvectorlib

clean::
${WIPE} ${INSTAPP} ${WFLAGS}

# Dynamic dependencies:
3 changes: 3 additions & 0 deletions examples/dde/CApp/Mk,fd7
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Dir <Obey$Dir>
WimpSlot -min 1024k
amu all THROWBACK=-throwback
3 changes: 3 additions & 0 deletions examples/dde/CApp/MkClean,fd7
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Dir <Obey$Dir>
amu clean
stripdepnd
2 changes: 2 additions & 0 deletions examples/dde/CApp/MkDebug,fd7
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Dir <Obey$Dir>
amu debug THROWBACK=-throwback
2 changes: 2 additions & 0 deletions examples/dde/CApp/MkInstall,fd7
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Dir <Obey$Dir>
amu install INSTTYPE=app INSTDIR=<Obey$Dir> USERIF=Iyonix
2 changes: 2 additions & 0 deletions examples/dde/CApp/Resources/!Boot,feb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
| !Boot files are normally locale-independent
IconSprites <Obey$Dir>.!Sprites
Binary file not shown.
Binary file not shown.
Binary file not shown.
11 changes: 11 additions & 0 deletions examples/dde/CApp/Resources/UK/!Run,feb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
| !Run files are normally locale-dependent, if only for the error messages

RMEnsure UtilityModule 3.10 Error This application requires RISC OS 3.10 or later
RMEnsure UtilityModule 5.00 RMEnsure CallASWI 0.03 RMLoad System:Modules.CallASWI
RMEnsure UtilityModule 5.00 RMEnsure CallASWI 0.03 Error This app requires CallASWI 0.03 or later
RMEnsure FPEmulator 4.03 RMLoad System:Modules.FPEmulator
RMEnsure FPEmulator 4.03 Error This application requires FPEmulator 4.03 or later
RMEnsure SharedCLibrary 5.17 RMLoad System:Modules.CLib
RMEnsure SharedCLibrary 5.34 Error This application requires SharedCLibrary 5.34 or later

Run <Obey$Dir>.!RunImage
20 changes: 20 additions & 0 deletions examples/dde/CApp/c/main
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <stdlib.h>
#include <stdio.h>
#include "LibZVector:zvector.h"

int main(void)
{
vector v = vect_create(16, sizeof(int), ZV_SEC_WIPE);

for (int i = 1; i <= 10; i++)
vect_add(v, &i);

for (int i=1; i <= 10; i++)
{
int *val = (int *)vect_pop(v);
printf ("Value %d: %d\n", i, *val);
}

vect_destroy(v);
exit(EXIT_SUCCESS);
}

0 comments on commit d198b9c

Please sign in to comment.