#ifndef GLOB_CONST_H
#define GLOB_CONST_H

#include <string>
#include <cstring>
#include <chrono>

//audio buffer length
extern const int BUFFER_LEN;

//location for storing save files
extern std::string config_dir;
//directory separator for OS
extern char sep;
extern int web;

// get time in milliseconds since epoch
inline long long epoch() {
    auto currentTimePoint = std::chrono::system_clock::now();
    auto durationSinceEpoch = currentTimePoint.time_since_epoch();
    auto millisecondsSinceEpoch = std::chrono::duration_cast<std::chrono::milliseconds>(durationSinceEpoch);
    return millisecondsSinceEpoch.count();
}

inline long long epoch_nano() {  //1*10^9
    auto currentTimePoint = std::chrono::system_clock::now();
    auto durationSinceEpoch = currentTimePoint.time_since_epoch();
    auto nanosecondsSinceEpoch = std::chrono::duration_cast<std::chrono::nanoseconds>(durationSinceEpoch);
    return nanosecondsSinceEpoch.count();
}

inline void get_filename(char** path) {
    int l = strlen(*path);
    bool end_set = false;
    for (int i=l-1; i>=0; i--) {
        if ((*path)[i]=='.' && !end_set) {
            (*path)[i] = '\0';
            end_set = true;
        } else if ((*path)[i]=='/' || (*path)[i]=='\\') {
            *path = &(*path)[i+1];
            return;
        }
    }
}

static uint8_t NTSC_TO_RGB[192] = {
            0x60,0x60,0x60, //0x00
            0x00,0x1c,0xa1, //0x01
            0x24,0x04,0xc8, //0x02
            0x53,0x00,0xb2, //0x03
            0x73,0x00,0x76, //0x04
            0x80,0x00,0x24, //0x05
            0x73,0x0c,0x00, //0x06
            0x50,0x28,0x00, //0x07
            0x25,0x44,0x00, //0x08
            0x00,0x57,0x00, //0x09
            0x01,0x5c,0x00, //0x0A
            0x00,0x53,0x24, //0x0B
            0x00,0x3c,0x76, //0x0C
            0x00,0x00,0x00, //0x0D apparently you shouldnt use this one
            0x00,0x00,0x00, //0x0E
            0x00,0x00,0x00, //0x0F
            0xab,0xab,0xab, //0x10
            0x0d,0x57,0xff, //0x11
            0x4b,0x30,0xff, //0x12
            0x8a,0x13,0xff, //0x13
            0xbc,0x09,0xd6, //0x14
            0xd2,0x12,0x69, //0x15
            0xc7,0x2e,0x00, //0x16
            0x9d,0x54,0x00, //0x17
            0x5f,0x7b,0x00, //0x18
            0x21,0x98,0x00, //0x19
            0x00,0xa3,0x00, //0x1A
            0x00,0x99,0x42, //0x1B
            0x02,0x7d,0xb4, //0x1C
            0x00,0x00,0x00, //0x1D
            0x00,0x00,0x00, //0x1E
            0x00,0x00,0x00, //0x1F
            0xff,0xff,0xff, //0x20
            0x53,0xae,0xff, //0x21
            0x90,0x85,0xff, //0x22
            0xd3,0x65,0xff, //0x23
            0xff,0x57,0xff, //0x24
            0xff,0x5d,0xcf, //0x25
            0xff,0x77,0x57, //0x26
            0xfa,0x9e,0x00, //0x27
            0xbd,0xc7,0x00, //0x28
            0x7a,0xe7,0x01, //0x29
            0x42,0xf6,0x0f, //0x2A
            0x24,0xef,0x7e, //0x2B
            0x2b,0xd5,0xf6, //0x2C
            0x4e,0x4e,0x4e, //0x2D
            0x00,0x00,0x00, //0x2E
            0x00,0x00,0x00, //0x2F
            0xff,0xff,0xff, //0x30
            0xb6,0xe1,0xff, //0x31
            0xcf,0xd1,0xff, //0x32
            0xe9,0xc3,0xff, //0x33
            0xff,0xbc,0xff, //0x34
            0xff,0xbd,0xf4, //0x35
            0xff,0xc6,0xc3, //0x36
            0xff,0xd5,0x9a, //0x37
            0xe8,0xe6,0x81, //0x38
            0xcd,0xf4,0x81, //0x39
            0xb7,0xfb,0x9a, //0x3A
            0xa9,0xfa,0xc3, //0x3B
            0xa9,0xf0,0xf4, //0x3C
            0xb8,0xb8,0xb8, //0x3D
            0x00,0x00,0x00, //0x3E
            0x00,0x00,0x00  //0x3F
        }; //lookup nesoutput*3 for the r,g,b for that value.

#endif