From 3cf569b967d35dc397bc2891c27baeec28d104e0 Mon Sep 17 00:00:00 2001 From: Ignacio Sanchez Gines <863613+drhelius@users.noreply.github.com> Date: Sun, 15 Dec 2024 18:56:40 +0100 Subject: [PATCH] Update log system --- platforms/audio-shared/sound_queue.cpp | 6 +-- platforms/desktop-shared/Makefile.common | 2 +- platforms/desktop-shared/application.cpp | 9 ++-- platforms/desktop-shared/config.cpp | 20 ++++---- platforms/desktop-shared/emu.cpp | 2 +- platforms/desktop-shared/gui_debug.cpp | 2 +- platforms/libretro/Makefile | 2 +- src/AY8910.cpp | 2 +- src/AY8910.h | 1 + src/Cartridge.cpp | 8 ++-- src/Cartridge.h | 1 + src/ColecoVisionIOPorts.h | 4 +- src/GearcolecoCore.cpp | 24 +++++----- src/Memory_inline.h | 16 +++---- src/Processor.cpp | 8 ++-- src/Processor_inline.h | 2 +- src/definitions.h | 31 ------------- src/gearcoleco.h | 1 + src/log.h | 59 ++++++++++++++++++++++++ 19 files changed, 116 insertions(+), 84 deletions(-) create mode 100644 src/log.h diff --git a/platforms/audio-shared/sound_queue.cpp b/platforms/audio-shared/sound_queue.cpp index 6d2bd42..93c117b 100644 --- a/platforms/audio-shared/sound_queue.cpp +++ b/platforms/audio-shared/sound_queue.cpp @@ -26,9 +26,9 @@ static void sdl_error(const char* str) { const char* sdl_str = SDL_GetError(); if (sdl_str && *sdl_str) - str = sdl_str; - - Log("Sound Queue: %s", str); + Log("Sound Queue: %s - SDL Error: %s", str, sdl_str); + else + Log("Sound Queue: %s", str); } SoundQueue::SoundQueue() diff --git a/platforms/desktop-shared/Makefile.common b/platforms/desktop-shared/Makefile.common index 99b8012..e76f921 100644 --- a/platforms/desktop-shared/Makefile.common +++ b/platforms/desktop-shared/Makefile.common @@ -70,7 +70,7 @@ else endif all: header $(TARGET) - @echo Build complete for $(PLATFORM) \($(BUILD_CONFIG)\) + @echo Build complete: $(TARGET_NAME) \($(BUILD_CONFIG)\) - $(GIT_VERSION) - $(PLATFORM) $(TARGET): $(OBJECTS) $(CXX) -o $@ $(OBJECTS) $(LDFLAGS) diff --git a/platforms/desktop-shared/application.cpp b/platforms/desktop-shared/application.cpp index 4bbdac7..a3927b3 100644 --- a/platforms/desktop-shared/application.cpp +++ b/platforms/desktop-shared/application.cpp @@ -51,7 +51,6 @@ int application_init(const char* rom_file, const char* symbol_file) { Log("\n%s", GEARCOLECO_TITLE_ASCII); Log("%s %s Desktop App", GEARCOLECO_TITLE, GEARCOLECO_VERSION); - Log("By Ignacio Sánchez (drhelius)"); config_init(); config_read(); @@ -148,6 +147,9 @@ static int sdl_init(void) SDL_VERSION(&application_sdl_build_version); SDL_GetVersion(&application_sdl_link_version); + Log("Using SDL %d.%d.%d (build)", application_sdl_build_version.major, application_sdl_build_version.minor, application_sdl_build_version.patch); + Log("Using SDL %d.%d.%d (link) ", application_sdl_link_version.major, application_sdl_link_version.minor, application_sdl_link_version.patch); + SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); @@ -166,14 +168,13 @@ static int sdl_init(void) if (application_gamepad_mappings > 0) { - Log("Succesfuly loaded %d game controller mappings", application_gamepad_mappings); + Log("Succesfuly loaded %d game controller mappings from gamecontrollerdb.txt", application_gamepad_mappings); } else { - Log("Game controller database not found!"); + Log("ERROR: Game controller database not found (gamecontrollerdb.txt)!!"); } - int gamepads_found = 0; for (int i = 0; i < SDL_NumJoysticks(); ++i) diff --git a/platforms/desktop-shared/config.cpp b/platforms/desktop-shared/config.cpp index 76cdcbc..bd472a1 100644 --- a/platforms/desktop-shared/config.cpp +++ b/platforms/desktop-shared/config.cpp @@ -316,7 +316,7 @@ void config_read(void) config_input[1].gamepad_asterisk = read_int("InputB", "GamepadAsterisk", SDL_CONTROLLER_BUTTON_START); config_input[1].gamepad_hash = read_int("InputB", "GamepadHash", SDL_CONTROLLER_BUTTON_BACK); - Log("Settings loaded"); + Debug("Settings loaded"); } void config_write(void) @@ -476,7 +476,7 @@ void config_write(void) if (config_ini_file->write(config_ini_data, true)) { - Log("Settings saved"); + Debug("Settings saved"); } } @@ -512,7 +512,7 @@ static int read_int(const char* group, const char* key, int default_value) else ret = std::stoi(value); - Log("Load setting: [%s][%s]=%d", group, key, ret); + Debug("Load setting: [%s][%s]=%d", group, key, ret); return ret; } @@ -520,7 +520,7 @@ static void write_int(const char* group, const char* key, int integer) { std::string value = std::to_string(integer); config_ini_data[group][key] = value; - Log("Save setting: [%s][%s]=%s", group, key, value.c_str()); + Debug("Save setting: [%s][%s]=%s", group, key, value.c_str()); } static float read_float(const char* group, const char* key, float default_value) @@ -534,7 +534,7 @@ static float read_float(const char* group, const char* key, float default_value) else ret = strtof(value.c_str(), NULL); - Log("Load setting: [%s][%s]=%.2f", group, key, ret); + Debug("Load setting: [%s][%s]=%.2f", group, key, ret); return ret; } @@ -542,7 +542,7 @@ static void write_float(const char* group, const char* key, float value) { std::string value_str = std::to_string(value); config_ini_data[group][key] = value_str; - Log("Save setting: [%s][%s]=%s", group, key, value_str.c_str()); + Debug("Save setting: [%s][%s]=%s", group, key, value_str.c_str()); } static bool read_bool(const char* group, const char* key, bool default_value) @@ -556,7 +556,7 @@ static bool read_bool(const char* group, const char* key, bool default_value) else std::istringstream(value) >> std::boolalpha >> ret; - Log("Load setting: [%s][%s]=%s", group, key, ret ? "true" : "false"); + Debug("Load setting: [%s][%s]=%s", group, key, ret ? "true" : "false"); return ret; } @@ -567,18 +567,18 @@ static void write_bool(const char* group, const char* key, bool boolean) std::string value; value = converter.str(); config_ini_data[group][key] = value; - Log("Save setting: [%s][%s]=%s", group, key, value.c_str()); + Debug("Save setting: [%s][%s]=%s", group, key, value.c_str()); } static std::string read_string(const char* group, const char* key) { std::string ret = config_ini_data[group][key]; - Log("Load setting: [%s][%s]=%s", group, key, ret.c_str()); + Debug("Load setting: [%s][%s]=%s", group, key, ret.c_str()); return ret; } static void write_string(const char* group, const char* key, std::string value) { config_ini_data[group][key] = value; - Log("Save setting: [%s][%s]=%s", group, key, value.c_str()); + Debug("Save setting: [%s][%s]=%s", group, key, value.c_str()); } diff --git a/platforms/desktop-shared/emu.cpp b/platforms/desktop-shared/emu.cpp index 77e15dd..eefc658 100644 --- a/platforms/desktop-shared/emu.cpp +++ b/platforms/desktop-shared/emu.cpp @@ -368,7 +368,7 @@ void emu_save_screenshot(const char* file_path) stbi_write_png(file_path, runtime.screen_width, runtime.screen_height, 3, emu_frame_buffer, runtime.screen_width * 3); - Log("Screenshot saved!"); + Debug("Screenshot saved!"); } static void save_ram(void) diff --git a/platforms/desktop-shared/gui_debug.cpp b/platforms/desktop-shared/gui_debug.cpp index 04f72b2..9215ab9 100644 --- a/platforms/desktop-shared/gui_debug.cpp +++ b/platforms/desktop-shared/gui_debug.cpp @@ -1482,7 +1482,7 @@ static void debug_window_vram_regs(void) static void add_symbol(const char* line) { - Log("Loading symbol %s", line); + Debug("Loading symbol %s", line); DebugSymbol s; diff --git a/platforms/libretro/Makefile b/platforms/libretro/Makefile index 96317ab..1987639 100644 --- a/platforms/libretro/Makefile +++ b/platforms/libretro/Makefile @@ -341,7 +341,7 @@ CFLAGS += -DGG_DISABLE_DISASSEMBLER -Wall -D__LIBRETRO__ $(fpic) CXXFLAGS += -DGG_DISABLE_DISASSEMBLER -Wall -D__LIBRETRO__ $(fpic) all: $(TARGET) - @echo Build complete for $(platform) + @echo Build complete: $(TARGET_NAME) $(DEBUG) - $(GIT_VERSION) - $(platform) $(TARGET): $(OBJECTS) ifeq ($(STATIC_LINKING), 1) diff --git a/src/AY8910.cpp b/src/AY8910.cpp index 04d039e..dcd2eee 100644 --- a/src/AY8910.cpp +++ b/src/AY8910.cpp @@ -320,7 +320,7 @@ void AY8910::Sync() if (m_iBufferIndex >= GC_AUDIO_BUFFER_SIZE) { - Log("SGM Audio buffer overflow"); + Debug("SGM Audio buffer overflow"); m_iBufferIndex = 0; } } diff --git a/src/AY8910.h b/src/AY8910.h index d817508..3e54b8b 100644 --- a/src/AY8910.h +++ b/src/AY8910.h @@ -21,6 +21,7 @@ #define AY8910_H #include "definitions.h" +#include "log.h" class AY8910 { diff --git a/src/Cartridge.cpp b/src/Cartridge.cpp index 2c5d575..7e75eab 100644 --- a/src/Cartridge.cpp +++ b/src/Cartridge.cpp @@ -179,7 +179,7 @@ bool Cartridge::LoadFromZipFile(const u8* buffer, int size) return false; } - Log("ZIP Content - Filename: \"%s\", Comment: \"%s\", Uncompressed size: %u, Compressed size: %u", file_stat.m_filename, file_stat.m_comment, (unsigned int) file_stat.m_uncomp_size, (unsigned int) file_stat.m_comp_size); + Debug("ZIP Content - Filename: \"%s\", Comment: \"%s\", Uncompressed size: %u, Compressed size: %u", file_stat.m_filename, file_stat.m_comment, (unsigned int) file_stat.m_uncomp_size, (unsigned int) file_stat.m_comp_size); string fn((const char*) file_stat.m_filename); transform(fn.begin(), fn.end(), fn.begin(), (int(*)(int)) tolower); @@ -258,7 +258,7 @@ bool Cartridge::LoadFromFile(const char* path) if (extension == "zip") { - Log("Loading from ZIP..."); + Debug("Loading from ZIP..."); m_bReady = LoadFromZipFile(reinterpret_cast (memblock), size); } else @@ -268,7 +268,7 @@ bool Cartridge::LoadFromFile(const char* path) if (m_bReady) { - Log("ROM loaded", path); + Debug("ROM loaded", path); } else { @@ -421,6 +421,6 @@ void Cartridge::GetInfoFromDB(u32 crc) if (!found) { - Log("ROM not found in database. CRC: %X", crc); + Debug("ROM not found in database. CRC: %X", crc); } } diff --git a/src/Cartridge.h b/src/Cartridge.h index aec4ab3..e11d630 100644 --- a/src/Cartridge.h +++ b/src/Cartridge.h @@ -22,6 +22,7 @@ #include #include "definitions.h" +#include "log.h" class Cartridge { diff --git a/src/ColecoVisionIOPorts.h b/src/ColecoVisionIOPorts.h index 5357572..4090a66 100644 --- a/src/ColecoVisionIOPorts.h +++ b/src/ColecoVisionIOPorts.h @@ -83,7 +83,7 @@ inline u8 ColecoVisionIOPorts::In(u8 port) } } - Log("--> ** Attempting to read from port $%X", port); + Debug("--> ** Attempting to read from port $%X", port); return 0xFF; } @@ -141,7 +141,7 @@ inline void ColecoVisionIOPorts::Out(u8 port, u8 value) } else { - Log("--> ** Output to port $%X: %X", port, value); + Debug("--> ** Output to port $%X: %X", port, value); } } } diff --git a/src/GearcolecoCore.cpp b/src/GearcolecoCore.cpp index 0b6645f..0e4717b 100644 --- a/src/GearcolecoCore.cpp +++ b/src/GearcolecoCore.cpp @@ -54,7 +54,7 @@ GearcolecoCore::~GearcolecoCore() void GearcolecoCore::Init(GC_Color_Format pixelFormat) { - Log("--== %s %s by Ignacio Sanchez ==--", GEARCOLECO_TITLE, GEARCOLECO_VERSION); + Log("Loading %s core %s by Ignacio Sanchez", GEARCOLECO_TITLE, GEARCOLECO_VERSION); m_pixelFormat = pixelFormat; @@ -194,7 +194,7 @@ void GearcolecoCore::SaveDisassembledROM() myfile.close(); } - Log("Disassembled ROM Saved"); + Debug("Disassembled ROM Saved"); } } @@ -335,7 +335,7 @@ void GearcolecoCore::SaveState(int index) SaveState(NULL, index); - Log("Save state %d created", index); + Debug("Save state %d created", index); } void GearcolecoCore::SaveState(const char* szPath, int index) @@ -384,7 +384,7 @@ void GearcolecoCore::SaveState(const char* szPath, int index) file.close(); - Log("Save state created"); + Debug("Save state created"); } bool GearcolecoCore::SaveState(u8* buffer, size_t& size) @@ -419,7 +419,7 @@ bool GearcolecoCore::SaveState(std::ostream& stream, size_t& size) { if (m_pCartridge->IsReady()) { - Log("Gathering save state data..."); + Debug("Gathering save state data..."); m_pMemory->SaveState(stream); m_pProcessor->SaveState(stream); @@ -436,7 +436,7 @@ bool GearcolecoCore::SaveState(std::ostream& stream, size_t& size) stream.write(reinterpret_cast (&header_magic), sizeof(header_magic)); stream.write(reinterpret_cast (&header_size), sizeof(header_size)); - Log("Save state size: %d", static_cast(stream.tellp())); + Debug("Save state size: %d", static_cast(stream.tellp())); return true; } @@ -452,7 +452,7 @@ void GearcolecoCore::LoadState(int index) LoadState(NULL, index); - Log("State %d file loaded", index); + Debug("State %d file loaded", index); } void GearcolecoCore::LoadState(const char* szPath, int index) @@ -499,7 +499,7 @@ void GearcolecoCore::LoadState(const char* szPath, int index) { if (LoadState(file)) { - Log("Save state loaded"); + Debug("Save state loaded"); } } else @@ -514,7 +514,7 @@ bool GearcolecoCore::LoadState(const u8* buffer, size_t size) { if (m_pCartridge->IsReady() && (size > 0) && IsValidPointer(buffer)) { - Log("Gathering load state data [%d bytes]...", size); + Debug("Gathering load state data [%d bytes]...", size); using namespace std; @@ -543,15 +543,15 @@ bool GearcolecoCore::LoadState(std::istream& stream) size_t size = static_cast(stream.tellg()); stream.seekg(0, ios::beg); - Log("Load state stream size: %d", size); + Debug("Load state stream size: %d", size); stream.seekg(size - (2 * sizeof(u32)), ios::beg); stream.read(reinterpret_cast (&header_magic), sizeof(header_magic)); stream.read(reinterpret_cast (&header_size), sizeof(header_size)); stream.seekg(0, ios::beg); - Log("Load state magic: 0x%08x", header_magic); - Log("Load state size: %d", header_size); + Debug("Load state magic: 0x%08x", header_magic); + Debug("Load state size: %d", header_size); if ((header_size == size) && (header_magic == GC_SAVESTATE_MAGIC)) { diff --git a/src/Memory_inline.h b/src/Memory_inline.h index 2376c7a..86040c5 100644 --- a/src/Memory_inline.h +++ b/src/Memory_inline.h @@ -77,7 +77,7 @@ inline u8 Memory::Read(u16 address) { if (address >= 0xFF80) { - Log("--> ** EEPROM read: %X %X", address); + Debug("--> ** EEPROM read: %X %X", address); } return pRom[(address & 0x3FFF) + m_RomBankAddress]; } @@ -86,7 +86,7 @@ inline u8 Memory::Read(u16 address) { if (address >= (romSize + 0x8000)) { - Log("--> ** Attempting to read from outer ROM: %X. ROM Size: %X", address, romSize); + Debug("--> ** Attempting to read from outer ROM: %X. ROM Size: %X", address, romSize); return 0xFF; } @@ -131,7 +131,7 @@ inline void Memory::Write(u16 address, u8 value) case 0xA000: case 0xC000: { - Log("--> ** Attempting to write on ROM: %X %X", address, value); + Debug("--> ** Attempting to write on ROM: %X %X", address, value); break; } case 0xE000: @@ -155,18 +155,18 @@ inline void Memory::Write(u16 address, u8 value) } #ifdef DEBUG_GEARCOLECO if (address == 0xFFC0) - Log("--> ** EEPROM write SCL=0: %X %X", address, value); + Debug("--> ** EEPROM write SCL=0: %X %X", address, value); if (address == 0xFFD0) - Log("--> ** EEPROM write SCL=1: %X %X", address, value); + Debug("--> ** EEPROM write SCL=1: %X %X", address, value); if (address == 0xFFE0) - Log("--> ** EEPROM write SDA=0: %X %X", address, value); + Debug("--> ** EEPROM write SDA=0: %X %X", address, value); if (address == 0xFFF0) - Log("--> ** EEPROM write SDA=1: %X %X", address, value); + Debug("--> ** EEPROM write SDA=1: %X %X", address, value); #endif } else { - Log("--> ** Attempting to write on ROM: %X %X", address, value); + Debug("--> ** Attempting to write on ROM: %X %X", address, value); } break; } diff --git a/src/Processor.cpp b/src/Processor.cpp index b95e607..94f26a3 100644 --- a/src/Processor.cpp +++ b/src/Processor.cpp @@ -298,17 +298,17 @@ void Processor::InvalidOPCode() { case 0xCB: { - Log("--> ** INVALID CB OP Code (%X) at $%.4X -- %s", opcode, opcode_address, kOPCodeCBNames[opcode]); + Debug("--> ** INVALID CB OP Code (%X) at $%.4X -- %s", opcode, opcode_address, kOPCodeCBNames[opcode]); break; } case 0xED: { - Log("--> ** INVALID ED OP Code (%X) at $%.4X -- %s", opcode, opcode_address, kOPCodeEDNames[opcode]); + Debug("--> ** INVALID ED OP Code (%X) at $%.4X -- %s", opcode, opcode_address, kOPCodeEDNames[opcode]); break; } default: { - Log("--> ** INVALID OP Code (%X) at $%.4X -- %s", opcode, opcode_address, kOPCodeNames[opcode]); + Debug("--> ** INVALID OP Code (%X) at $%.4X -- %s", opcode, opcode_address, kOPCodeNames[opcode]); } } #endif @@ -320,7 +320,7 @@ void Processor::UndocumentedOPCode() u16 opcode_address = PC.GetValue() - 1; u8 opcode = m_pMemory->Read(opcode_address); - Log("--> ** UNDOCUMENTED OP Code (%X) at $%.4X -- %s", opcode, opcode_address, kOPCodeNames[opcode]); + Debug("--> ** UNDOCUMENTED OP Code (%X) at $%.4X -- %s", opcode, opcode_address, kOPCodeNames[opcode]); #endif } diff --git a/src/Processor_inline.h b/src/Processor_inline.h index a60d701..eed0865 100644 --- a/src/Processor_inline.h +++ b/src/Processor_inline.h @@ -140,7 +140,7 @@ inline void Processor::SetInterruptMode(int mode) } else { - Log("--> ** Attempting to set interrupt mode %d", mode); + Debug("--> ** Attempting to set interrupt mode %d", mode); } } diff --git a/src/definitions.h b/src/definitions.h index 0399f23..5ecfb8e 100644 --- a/src/definitions.h +++ b/src/definitions.h @@ -183,37 +183,6 @@ struct GC_RuntimeInfo GC_Region region; }; -#ifdef DEBUG_GEARCOLECO - -#ifdef __ANDROID__ -#include -#define printf(...) __android_log_print(ANDROID_LOG_DEBUG, "GEARCOLECO", __VA_ARGS__); -#endif - -#define Log(msg, ...) (Log_func(msg, ##__VA_ARGS__)) -#define Debug(msg, ...) (Log_func(msg, ##__VA_ARGS__)) - -inline void Log_func(const char* const msg, ...) -{ - static int count = 1; - char szBuf[512]; - - va_list args; - va_start(args, msg); - vsnprintf(szBuf, 512, msg, args); - va_end(args); - - printf("%d: %s\n", count, szBuf); - fflush(stdout); - - count++; -} - -#else -#define Log(msg, ...) -#define Debug(msg, ...) -#endif - inline u8 SetBit(const u8 value, const u8 bit) { return value | (0x01 << bit); diff --git a/src/gearcoleco.h b/src/gearcoleco.h index d596529..111421c 100644 --- a/src/gearcoleco.h +++ b/src/gearcoleco.h @@ -21,6 +21,7 @@ #define GEARCOLECO_H #include "definitions.h" +#include "log.h" #include "GearcolecoCore.h" #include "Memory.h" #include "Processor.h" diff --git a/src/log.h b/src/log.h new file mode 100644 index 0000000..f1249f8 --- /dev/null +++ b/src/log.h @@ -0,0 +1,59 @@ +/* + * Gearcoleco - ColecoVision Emulator + * Copyright (C) 2021 Ignacio Sanchez + + * 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 3 of the License, or + * 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, see http://www.gnu.org/licenses/ + * + */ + +#ifndef LOG_H +#define LOG_H + +#include +#include +#include "definitions.h" + +#if defined(DEBUG_GEARCOLECO) + #if defined(__ANDROID__) + #include + #define printf(...) __android_log_print(ANDROID_LOG_DEBUG, GG_TITLE, __VA_ARGS__); + #endif + #define Debug(msg, ...) (Log_func(true, msg, ##__VA_ARGS__)) +#else + #define Debug(msg, ...) +#endif + +#define Log(msg, ...) (Log_func(false, msg, ##__VA_ARGS__)) + +inline void Log_func(bool debug, const char* const msg, ...) +{ + static int count = 1; + char buffer[512]; + va_list args; + va_start(args, msg); + vsnprintf(buffer, 512, msg, args); + va_end(args); + + if (debug) + { + printf("%d: [DEBUG] %s\n", count, buffer); + count++; + } + else + printf("%s\n", buffer); + + fflush(stdout); +} + +#endif /* LOG_H */