//  Copyright (c) 2020-2026 Jakub Filipowicz <jakubf@gmail.com>
//
//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation; either version 2 of the License, or
//  (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc.,
//  51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

#ifndef _CFG_H_
#define _CFG_H_

#include "external/iniparser/iniparser.h"
#include "cfg.h"

typedef dictionary em400_cfg;

#define CFG_DEFAULT_LOG_FILE "em400.log"
#define CFG_DEFAULT_LOG_COMPONENTS "lib,app"
#define CFG_DEFAULT_LOG_LINE_BUFFERED 1
#define CFG_DEFAULT_LOG_ENABLED 0

#define CFG_DEFAULT_CPU_MODIFICATIONS 0
#define CFG_DEFAULT_CPU_AWP 1
#define CFG_DEFAULT_CPU_IO_USER_ILLEGAL 0
#define CFG_DEFAULT_CPU_STOP_ON_NOMEM 1
#define CFG_DEFAULT_TIMING "all"
#define CFG_DEFAULT_CPU_EMULATION_QUANTUM_US 100
#define CFG_DEFAULT_CPU_CLOCK_PERIOD_MS 10

#define CFG_DEFAULT_MEMORY_ELWRO_MODULES 1
#define CFG_DEFAULT_MEMORY_MEGA_MODULES 0
#define CFG_DEFAULT_MEMORY_HARDWIRED_SEGMENTS 2
#define CFG_DEFAULT_MEMORY_MEGA_PROM NULL
#define CFG_DEFAULT_MEMORY_PRELOAD NULL

#define CFG_DEFAULT_SOUND_ENABLED 1
#define CFG_DEFAULT_SOUND_BACKEND "auto"
#define CFG_DEFAULT_SOUND_DEVICE NULL
#define CFG_DEFAULT_SOUND_VOLUME 14
#define CFG_DEFAULT_SOUND_RATE 48000
#define CFG_DEFAULT_SOUND_LATENCY 20
#define CFG_DEFAULT_SOUND_BUFFER_LEN 128

#define cfg_getdouble iniparser_getdouble
#define cfg_getint iniparser_getint
#define cfg_getstr iniparser_getstring
#define cfg_getbool iniparser_getboolean
#define cfg_contains iniparser_find_entry
#define cfg_set iniparser_set
#define cfg_load iniparser_load
#define cfg_free iniparser_freedict

// CFG_DEFAULT_LOG_FILE resolved to a usable path: bare name (CWD) on POSIX,
// %APPDATA%\em400\em400.log on Windows
const char * cfg_default_log_file();

const char * cfg_fgetstr(em400_cfg *cfg, const char *key_format, ...);
int cfg_fgetint(em400_cfg *cfg, const char *key_format, ...);
double cfg_fgetdouble(em400_cfg *cfg, const char *key_format, ...);
int cfg_fgetbool(em400_cfg *cfg, const char *key_format, ...);
int cfg_fcontains(em400_cfg *cfg, const char *key_format, ...);

// like cfg_fgetint/cfg_fgetbool but return the caller's default when absent,
// instead of the -1 not-found sentinel
int cfg_fgetint_def(em400_cfg *cfg, int def, const char *key_format, ...);
int cfg_fgetbool_def(em400_cfg *cfg, int def, const char *key_format, ...);

#endif
