Core: Add missing files

This commit is contained in:
Jeffrey Pfau 2016-01-28 21:29:55 -08:00
parent 2290dd6781
commit 2716a0f64f
3 changed files with 109 additions and 0 deletions

38
src/core/core.h Normal file
View File

@ -0,0 +1,38 @@
/* Copyright (c) 2013-2016 Jeffrey Pfau
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef M_CORE_H
#define M_CORE_H
#include "util/common.h"
struct VFile;
struct mCore {
void* cpu;
void* board;
bool (*init)(struct mCore*);
void (*deinit)(struct mCore*);
void (*desiredVideoDimensions)(struct mCore*, unsigned* width, unsigned* height);
void (*setVideoBuffer)(struct mCore*, void* buffer, size_t stride);
bool (*isROM)(struct mCore*, struct VFile* vf);
bool (*loadROM)(struct mCore*, struct VFile* vf, struct VFile* save, const char* fname);
void (*unloadROM)(struct mCore*);
bool (*loadBIOS)(struct mCore*, struct VFile* vf, int biosID);
bool (*selectBIOS)(struct mCore*, int biosID);
void (*reset)(struct mCore*);
void (*runFrame)(struct mCore*);
void (*runLoop)(struct mCore*);
void (*step)(struct mCore*);
void (*setKeys)(struct mCore*, uint32_t keys);
};
#endif

16
src/core/log.c Normal file
View File

@ -0,0 +1,16 @@
/* Copyright (c) 2013-2016 Jeffrey Pfau
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "log.h"
struct mLogger* mLogGetContext(void) {
return NULL; // TODO
}
int mLogGenerateCategory(void) {
static int category = 0;
++category;
return category;
}

55
src/core/log.h Normal file
View File

@ -0,0 +1,55 @@
/* Copyright (c) 2013-2016 Jeffrey Pfau
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef M_LOG_H
#define M_LOG_H
#include "util/common.h"
enum mLogLevel {
mLOG_FATAL = 0x01,
mLOG_ERROR = 0x02,
mLOG_WARN = 0x04,
mLOG_INFO = 0x08,
mLOG_DEBUG = 0x10,
mLOG_STUB = 0x20,
mLOG_GAME_ERROR = 0x40
};
struct mLogger {
ATTRIBUTE_FORMAT(printf, 4, 5)
void (*log)(struct mLogger*, int category, enum mLogLevel level, const char* format, ...);
};
struct mLogger* mLogGetContext(void);
int mLogGenerateCategory(void);
ATTRIBUTE_FORMAT(printf, 3, 4)
static inline void _mLog(int (*category)(void), enum mLogLevel level, const char* format, ...) {
struct mLogger* context = mLogGetContext();
va_list args;
va_start(args, format);
if (context) {
context->log(context, category(), level, format, args);
} else {
vprintf(format, args);
printf("\n");
}
va_end(args);
}
#define mLOG(CATEGORY, LEVEL, ...) _mLog(_mLOG_CAT_ ## CATEGORY, mLOG_ ## LEVEL, __VA_ARGS__)
#define mLOG_DECLARE_CATEGORY(CATEGORY) int _mLOG_CAT_ ## CATEGORY (void);
#define mLOG_DEFINE_CATEGORY(CATEGORY) \
int _mLOG_CAT_ ## CATEGORY (void) { \
static int category = 0; \
if (!category) { \
category = mLogGenerateCategory(); \
} \
return category; \
}
#endif