VirtualC64 v5.0 beta
Commodore 64 Emulator
Loading...
Searching...
No Matches
CoreObject.h
1// -----------------------------------------------------------------------------
2// This file is part of VirtualC64
3//
4// Copyright (C) Dirk W. Hoffmann. www.dirkwhoffmann.de
5// This FILE is dual-licensed. You are free to choose between:
6//
7// - The GNU General Public License v3 (or any later version)
8// - The Mozilla Public License v2
9//
10// SPDX-License-Identifier: GPL-3.0-or-later OR MPL-2.0
11// -----------------------------------------------------------------------------
12
13#pragma once
14
15#include "Error.h"
16#include "Dumpable.h"
17
18namespace vc64 {
19
20/* Object model:
21 *
22 * ------------------
23 * | CoreObject |
24 * ------------------
25 * |
26 * ------------------
27 * | CoreComponent |
28 * ------------------
29 * |
30 * | ------------------ ----------------
31 * |-->| Thread |-->| C64 |
32 * | ------------------ ----------------
33 * | ------------------
34 * |-->| SubComponent |
35 * ------------------
36 *
37 * CoreObject is the base class for all C64 related classes. It provides a
38 * a textual description for the object as well as various functions for
39 * printing debug information.
40 *
41 * CoreComponent defines the base functionality of all hardware components. It
42 * comprises functions for initializing, configuring, and serializing the
43 * object, as well as functions for powering up and down, running and
44 * pausing. Furthermore, a 'SYNCHRONIZED' macro is provided to prevent mutual
45 * execution of certain code blocks.
46 *
47 * Thread adds the ability to run the component asynchroneously. It implements
48 * the emulator's state model.
49 */
50
51class CoreObject : public Dumpable {
52
53protected:
54
55 // Set to false to disable all debug messages
56 static bool verbose;
57
58 //
59 // Initializing
60 //
61
62public:
63
64 virtual ~CoreObject() = default;
65
66 // Returns the name for this component (e.g., "CPU" or "VICII")
67 virtual const char *objectName() const = 0;
68
69 // Returns a textual description for this component
70 virtual const char *description() const { return ""; }
71
72 // Called by debug() and trace() to produce a detailed debug output
73 virtual void prefix() const;
74};
75
76/* This file provides multiple macros for printing messages:
77 *
78 * - msg Information message (Shows up in all builds)
79 * - warn Warning message (Shows up in all builds)
80 * - fatal Error message + Exit (Shows up in all builds)
81 * - debug Debug message (Shows up in debug builds only)
82 * - plain Plain debug message (Shows up in debug builds only)
83 * - trace Detailed debug output (Shows up in debug builds only)
84 *
85 * Debug messages are prefixed by the component name and a line number. Trace
86 * messages are prefixed by a more detailed string description produced by the
87 * prefix() function.
88 *
89 * Debug, plain, and trace messages are accompanied by an optional 'enable'
90 * parameter. If 0 is passed in, no output will be generated. In addition,
91 * variable 'verbose' is checked which is set to true by default. By setting
92 * this variable to false, debug output can be silenced temporarily.
93 *
94 * Sidenote: In previous releases the printing macros were implemented in form
95 * of variadic functions. Although this might seem to be superior at first
96 * glance, it is not. Using macros allows modern compilers to verify the format
97 * strings against the data types of the provided arguments. This check can't
98 * be performed when variadic functions are used.
99 */
100
101#define msg(format, ...) \
102fprintf(stderr, format __VA_OPT__(,) __VA_ARGS__);
103
104#define warn(format, ...) \
105fprintf(stderr, "Warning: " format __VA_OPT__(,) __VA_ARGS__);
106
107#define fatal(format, ...) \
108{ fprintf(stderr, "Fatal: " format __VA_OPT__(,) __VA_ARGS__); exit(1); }
109
110#define debug(enable, format, ...) \
111if (enable) { if (verbose) { \
112fprintf(stderr, "%s:%d " format, objectName(), __LINE__ __VA_OPT__(,) __VA_ARGS__); }}
113
114#define plain(enable, format, ...) \
115if (enable) { if (verbose) { \
116fprintf(stderr, format __VA_OPT__(,) __VA_ARGS__); }}
117
118#define trace(enable, format, ...) \
119if (enable) { if (verbose) { \
120prefix(); \
121fprintf(stderr, "%s:%d " format, objectName(), __LINE__ __VA_OPT__(,) __VA_ARGS__); }}
122
123#define xfiles(format, ...) \
124if (XFILES) { if (verbose) { \
125prefix(); \
126fprintf(stderr, "XFILES: " format __VA_OPT__(,) __VA_ARGS__); }}
127
128}
VirtualC64 project namespace.
Definition CmdQueue.cpp:16