ft2-clone

Fasttracker 2 clone
Log | Files | Refs | README | LICENSE

ft2_header.h (2600B)


      1 #pragma once
      2 
      3 #include <SDL2/SDL.h>
      4 #include <stdint.h>
      5 #include <stdbool.h>
      6 #include <assert.h>
      7 #ifdef _WIN32
      8 #define WIN32_MEAN_AND_LEAN
      9 #include <windows.h>
     10 #else
     11 #include <limits.h> // also has PATH_MAX
     12 #endif
     13 #include "ft2_replayer.h"
     14 
     15 #define PROG_VER_STR "1.95"
     16 
     17 // do NOT change these! It will only mess things up...
     18 
     19 #define FT2_VBLANK_HZ 70.086302895323 /* nominal, 640x400 @ 70Hz */
     20 #define SCREEN_W 632
     21 #define SCREEN_H 400
     22 #define VBLANK_HZ 60
     23 
     24 // 70Hz (FT2 vblank) delta -> 60Hz vblank delta (rounded)
     25 #define SCALE_VBLANK_DELTA(x) (int32_t)(((x) * (FT2_VBLANK_HZ / (double)VBLANK_HZ)) + 0.5)
     26 #define SCALE_VBLANK_DELTA_REV(x) (int32_t)(((x) * (VBLANK_HZ / (double)FT2_VBLANK_HZ)) + 0.5)
     27 
     28 /* Amount of extra bytes to allocate for every instrument sample,
     29 ** this is used for a hack for resampling interpolation to be
     30 ** branchless in the inner channel mixer loop.
     31 ** Warning: Do not change this!
     32 */
     33 #define SMP_DAT_OFFSET ((MAX_LEFT_TAPS*2)+1)
     34 #define SAMPLE_PAD_LENGTH (SMP_DAT_OFFSET+(MAX_RIGHT_TAPS*2))
     35 
     36 #ifndef _WIN32
     37 #define _stricmp strcasecmp
     38 #define _strnicmp strncasecmp
     39 #define DIR_DELIMITER '/'
     40 #else
     41 #define DIR_DELIMITER '\\'
     42 #define PATH_MAX MAX_PATH
     43 #endif
     44 
     45 #ifndef PI
     46 #define PI 3.14159265358979323846264338327950288
     47 #endif
     48 
     49 #define SGN(x) (((x) >= 0) ? 1 : -1)
     50 #define ABS(a) (((a) < 0) ? -(a) : (a))
     51 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
     52 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
     53 #define CLAMP(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
     54 
     55 #define DROUND(x) \
     56 	     if (x < 0.0) x -= 0.5; \
     57 	else if (x > 0.0) x += 0.5
     58 
     59 #define FROUND(x) \
     60 	     if (x < 0.0f) x -= 0.5f; \
     61 	else if (x > 0.0f) x += 0.5f
     62 
     63 // fast 32-bit -> 8-bit clamp
     64 #define CLAMP8(i) if ((int8_t)(i) != i) i = 0x7F ^ (i >> 31)
     65 
     66 // fast 32-bit -> 16-bit clamp
     67 #define CLAMP16(i) if ((int16_t)(i) != i) i = 0x7FFF ^ (i >> 31)
     68 
     69 #define SWAP16(x) \
     70 ( \
     71 	(((uint16_t)((x) & 0x00FF)) << 8) | \
     72 	(((uint16_t)((x) & 0xFF00)) >> 8)   \
     73 )
     74 
     75 #define SWAP32(x) \
     76 ( \
     77 	(((uint32_t)((x) & 0x000000FF)) << 24) | \
     78 	(((uint32_t)((x) & 0x0000FF00)) <<  8) | \
     79 	(((uint32_t)((x) & 0x00FF0000)) >>  8) | \
     80 	(((uint32_t)((x) & 0xFF000000)) >> 24)   \
     81 )
     82 
     83 #define SWAP64(x) \
     84 ( \
     85 	(((x) << 56) & 0xFF00000000000000ULL) | \
     86 	(((x) << 40) & 0x00FF000000000000ULL) | \
     87 	(((x) << 24) & 0x0000FF0000000000ULL) | \
     88 	(((x) <<  8) & 0x000000FF00000000ULL) | \
     89 	(((x) >>  8) & 0x00000000FF000000ULL) | \
     90 	(((x) >> 24) & 0x0000000000FF0000ULL) | \
     91 	(((x) >> 40) & 0x000000000000FF00ULL) | \
     92 	(((x) >> 56) & 0x00000000000000FFULL)  \
     93 )
     94 
     95 typedef struct smpPtr_t
     96 {
     97 	int8_t *origPtr, *ptr;
     98 } smpPtr_t;