// The top-level API for managed applications.
#pragma once
#if defined(_WINDOWS) && !defined(BREAKS_CORE_STATIC)
#define DLL_EXPORT __declspec(dllexport)
#else
#define DLL_EXPORT
#endif
extern "C"
{
///
/// Creates a motherboard instance with all the hardware (APU/PPU/cartridge connector). The cartridge defaults to the Ejected state.
/// The board contains one PPU (see CreateBoardEx for several PPUs).
///
/// Revision name of the motherboard. If the board is not supported, a `BogusBoard` will be created.
/// APU revision
/// PPU revision
/// The form factor of the cartridge connector.
DLL_EXPORT void CreateBoard(char* boardName, char* apu, char* ppu, char* p1);
///
/// Creates a motherboard instance with the hardware (APU/PPUs/cartridge connector). The cartridge defaults to the Ejected state.
/// The board may contain several PPUs (up to 2), each of which is bound to its own
/// virtual TV Set by default (TV[i] shows PPU[i]). The binding can be changed via BindPPUToTV.
///
/// Revision name of the motherboard. If the board is not supported, a `BogusBoard` will be created.
/// APU revision
/// Array of PPU revision names (one per PPU on the board)
/// Number of PPUs
/// The form factor of the cartridge connector.
DLL_EXPORT void CreateBoardEx(char* boardName, char* apu, char** ppus, int ppuCount, char* p1);
///
/// Destroys the motherboard instance and all the resources it occupies.
///
DLL_EXPORT void DestroyBoard();
///
/// Insert the cartridge. The CartPcb path identifies the board by the PRG/CHR
/// CRC32 via the nescartdb database; on failure it falls back to the legacy
/// iNES mapper path. In addition, a mapper instance will be created if it is supported.
///
/// .nes ROM image.
/// Image size (bytes)
DLL_EXPORT int InsertCartridge(uint8_t* nesImage, size_t size);
///
/// Set the Nescartdb data directory (contains index.json and boards/).
/// Must be called before InsertCartridge.
///
DLL_EXPORT void SetNescartdbDir(char* dir);
///
/// Set a user directory with custom board JSONs (JSONES subset, may be empty).
/// Must be called before InsertCartridge.
///
DLL_EXPORT void SetUserBoardsDir(char* dir);
///
/// Force a board type for every cartridge (JSONES hook for custom PCBs that
/// are not in the nescartdb index). Empty string disables the override.
/// Must be called before InsertCartridge.
///
DLL_EXPORT void SetForcedBoardType(char* type);
///
/// Free the cartridge connector from the ROM/mapper and all resources.
///
DLL_EXPORT void EjectCartridge();
///
/// Simulate 1 half cycle of the board. The simulation of the signal edge is not supported, this is overkill.
///
DLL_EXPORT void Step();
///
/// Make the board /RES pins = 0 for a few CLK half cycles so that the APU/PPU resets all of its internal circuits.
///
DLL_EXPORT void Reset();
///
/// The parent application can check that the board is in the reset process and ignore the audio/video signal for that time.
///
///
DLL_EXPORT bool InResetState();
///
/// Get the values of the ACLK cycle counter.
///
///
DLL_EXPORT size_t GetACLKCounter();
///
/// Get the value of the 6502 core cycle counter (PHI Counter)
///
///
DLL_EXPORT size_t GetPHICounter();
///
/// Get the current resulting AUX value in normalized [0.0; 1.0] format.
///
///
DLL_EXPORT void SampleAudioSignal(float* sample);
///
/// Load APU/PPU registers dump (APUPlayer/PPUPlayer only)
///
/// RegDumpEntry records
/// Dump size (bytes)
DLL_EXPORT void LoadRegDump(uint8_t* data, size_t data_size);
///
/// Enable/disable saving the history of PPU register accesses.
///
DLL_EXPORT void EnablePpuRegDump(bool enable, char* regdump_dir);
///
/// Enable/disable saving the history of APU register accesses.
///
DLL_EXPORT void EnableApuRegDump(bool enable, char* regdump_dir);
///
/// Enable/disable writing the Nintendulator-compatible instruction trace log
/// to the "Nintendulator.log" file in the working directory.
///
DLL_EXPORT void EnableNintendulatorLog(bool enable);
///
/// Get audio signal settings that help with its rendering on the consumer side.
///
///
DLL_EXPORT void GetApuSignalFeatures(APUSim::AudioSignalFeatures* features);
///
/// Get the "pixel" counter. Keep in mind that pixels refers to an abstract entity representing the visible or invisible part of the video signal.
///
///
DLL_EXPORT size_t GetPCLKCounter();
///
/// Get the number of PPUs on the current board.
///
///
DLL_EXPORT int GetPPUCount();
///
/// Bind the video signal of a PPU to a virtual TV Set (up to 2 TVs).
/// `bind == false` disconnects the TV (it shows black).
/// By default TV[i] is bound to PPU[i]. For debugging one PPU can be bound to both TVs.
///
/// PPU index on the board
/// TV index (0..1)
/// true: connect, false: disconnect
DLL_EXPORT void BindPPUToTV(int ppu_index, int tv_index, bool bind);
///
/// Get the PPU index currently bound to the TV, or -1 if the TV is disconnected.
///
/// TV index (0..1)
///
DLL_EXPORT int GetTVBinding(int tv_index);
///
/// Get the number of connected (bound) TVs. Unbound trailing TVs are not counted.
///
///
DLL_EXPORT int GetTVCount();
///
/// Get 1 sample of the video signal displayed on the given TV.
///
/// TV index (0..1)
///
DLL_EXPORT void SampleVideoSignalEx(int tv_index, PPUSim::VideoOutSignal* sample);
///
/// Get 1 sample of the video signal (of the TV bound to the primary PPU).
///
///
DLL_EXPORT void SampleVideoSignal(PPUSim::VideoOutSignal* sample);
///
/// Get the direct value from the PPU H counter.
///
///
DLL_EXPORT size_t GetHCounter();
///
/// Get the direct value from the PPU V counter.
///
///
DLL_EXPORT size_t GetVCounter();
///
/// Forcibly enable rendering ($2001[3] = $2001[4] always equals 1).
/// Used for debugging PPU signals, when the CPU I/F register dump is limited, or when you want to get faster simulation results.
/// Keep in mind that with permanently enabled rendering the PPU becomes unstable and this hack should be applied when you know what you're doing.
///
///
DLL_EXPORT void RenderAlwaysEnabled(bool enable);
///
/// Get video signal settings of the given PPU that help with its rendering on the consumer side.
///
/// PPU index
///
DLL_EXPORT void GetPpuSignalFeaturesEx(int ppu_index, PPUSim::VideoSignalFeatures* features);
///
/// Get video signal settings of the primary PPU that help with its rendering on the consumer side.
///
///
DLL_EXPORT void GetPpuSignalFeatures(PPUSim::VideoSignalFeatures* features);
///
/// Convert the raw color of the given PPU to RGB. Can be used for palette generation or PPU video output in RAW mode.
/// The SYNC level (RAW.Sync) check must be done from the outside.
///
/// PPU index
DLL_EXPORT void ConvertRAWToRGBEx(int ppu_index, uint16_t raw, uint8_t* r, uint8_t* g, uint8_t* b);
///
/// Convert the raw color of the primary PPU to RGB. Can be used for palette generation or PPU video output in RAW mode.
/// The SYNC level (RAW.Sync) check must be done from the outside.
///
DLL_EXPORT void ConvertRAWToRGB(uint16_t raw, uint8_t* r, uint8_t* g, uint8_t* b);
///
/// Use RAW color output.
/// RAW color refers to the Chroma/Luma combination that comes to the video generator and the Emphasis bit combination.
///
///
DLL_EXPORT void SetRAWColorMode(bool enable);
///
/// Set one of the ways to decay OAM cells.
///
DLL_EXPORT void SetOamDecayBehavior(PPUSim::OAMDecayBehavior behavior);
///
/// Set the noise for the composite video signal (in volts).
///
///
DLL_EXPORT void SetNoiseLevel(float volts);
///
/// Use externally set DAC signal levels.
///
/// true: Use externally set table, false: Use internal values (see video_out.cpp class constructor)
/// signal value table
DLL_EXPORT void PpuUseExternalDacLevels(bool use, PPUSim::DacLevels* tab);
///
/// Return all core debugging information for BreaksDebug.
///
///
DLL_EXPORT void GetAllCoreDebugInfo(M6502Core::DebugInfo* info);
///
/// Create an IO instance of the device with the specified DeviceID. Return handle
///
DLL_EXPORT size_t IOCreateInstance(uint32_t device_id);
///
/// Delete the device instance by handle.
///
DLL_EXPORT void IODisposeInstance(size_t handle);
///
/// Connect the device to the port.
///
DLL_EXPORT void IOAttach(size_t port, size_t handle);
///
/// Disconnect the device from the port.
///
DLL_EXPORT void IODetach(size_t port, size_t handle);
///
/// Set the IOState state of the device. For example, the state of the controller buttons.
///
DLL_EXPORT void IOSetState(size_t handle, size_t io_state, uint32_t value);
///
/// Get the state of the specified device IOState.
///
DLL_EXPORT uint32_t IOGetState(size_t handle, size_t io_state);
///
/// Get the number of IO device states. For example, the number of buttons of the controller.
///
DLL_EXPORT size_t IOGetNumStates(size_t handle);
///
/// Return the IOState name of the device.
///
DLL_EXPORT void IOGetStateName(size_t handle, size_t io_state, char* name, size_t name_size);
// ---------------------------------------------------------------------
// Logging API (issue #517)
//
// The log sources are controlled by a bitmask (one bit per source); each
// source has its own category mask (one bit per category). The names of the
// sources and categories are registered when the first board is created and
// can be queried for the user interface.
// ---------------------------------------------------------------------
///
/// Master runtime switch of the logging facility.
///
DLL_EXPORT void SetLogEnabled(bool enabled);
///
/// Enable/disable log sources by a bitmask (bit n = Log source n).
///
DLL_EXPORT void SetLogSourceMask(uint64_t mask);
///
/// Get the current log source mask.
///
DLL_EXPORT uint64_t GetLogSourceMask();
///
/// Set the category mask of one log source (one bit per category of that source).
///
DLL_EXPORT void SetLogCategoryMask(int source, uint64_t mask);
///
/// Get the current category mask of one log source.
///
DLL_EXPORT uint64_t GetLogCategoryMask(int source);
///
/// Route the log to the given file ("w"). When `enable` is false the log file is closed.
///
DLL_EXPORT void SetLogToFile(bool enable, char* path);
///
/// Route the log to stdout.
///
DLL_EXPORT void SetLogToStdout(bool enable);
///
/// Get the number of log sources.
///
DLL_EXPORT size_t GetLogSourceCount();
///
/// Get the display name of a log source.
///
DLL_EXPORT void GetLogSourceName(int source, char* name, size_t name_size);
///
/// Get the number of categories of a log source.
///
DLL_EXPORT size_t GetLogCategoryCount(int source);
///
/// Get the category bit of the `category_index`-th category of a log source.
///
DLL_EXPORT uint64_t GetLogCategoryBit(int source, size_t category_index);
///
/// Get the display name of the `category_index`-th category of a log source.
///
DLL_EXPORT void GetLogCategoryName(int source, size_t category_index, char* name, size_t name_size);
};