#include "c2rw.h"

HWND            hMain = NULL;
HINSTANCE       hInst = NULL;
HANDLE          hThr = NULL;

DWORD           cport = 0;
DWORD           cbr = 0;

C2RW_SET        c2rw_set = {
    1,                                                              // type
    false,                                                          // rw
    0,                                                              // block
    { 0 },                                                          // mfd_ac: active flags
    { 0 },                                                          // mfd_cl: classic dump
    { 0 } };                                                        // mfd_ul: ultralight dump

C2RW_DSC        c2rw_dsc[MAX_CCTYPE + 1] = {
    { SCD_UL,       0,  TEXT("UL") },
    { SCD_CL1K,     15, TEXT("CL1K") },
    { SCD_CL4K,     63, TEXT("CL4K") },
    { SCD_PL2S1,    31, TEXT("PL2S1") },
    { SCD_PL4S1,    63, TEXT("PL4S1") } };

WORD            bitsh[16] = {
    0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
    0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000, 0x8000 };

BOOL            updif = FALSE;                  // disable gui update flag
TCHAR           filepath[MAX_PATH + 1];

void gvar_init(void)
{
    DWORD       cnt;
    memset(filepath, 0, sizeof(filepath));      // clear filename
    memset(&c2rw_set, 0, sizeof(c2rw_set));     // clear data
    c2rw_set.flg = MASK_NRWMSG | MASK_ALLDATA;  // non-RW message on
    c2rw_set.tp = 1;                            // CL1K type
    c2rw_set.cl_en[0] = 7;                      // sector 0 enable
    memcpy(c2rw_set.mfd_cl, "\x11\x22\x33\x44\x44\x08\x04\x00", 8);             // setup UID for CL
    c2rw_set.ul_en = 0xFFF8;
    memcpy(c2rw_set.mfd_ul, "\x04\x11\x22\xBF\x33\x44\x55\x66\x44\x81", 10);    // setup UID for UL
    // trailer setting
    for (cnt = 0; cnt != 40; cnt++)
    {
        memcpy(&c2rw_set.mfd_cl[(cnt < 32) ? ((cnt << 2) | 3) << 4 : ((cnt - 24) << 4 | 0x0F) << 4],
            "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x07\x80\x69\xFF\xFF\xFF\xFF\xFF\xFF", 16);
    }
}