Massive dump of xenia-info required code.
This is a working xenia-info for xex files (no gdfs files yet).
This commit is contained in:
59
src/xenia/logging.cc
Normal file
59
src/xenia/logging.cc
Normal file
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* Xenia : Xbox 360 Emulator Research Project *
|
||||
******************************************************************************
|
||||
* Copyright 2013 Ben Vanik. All rights reserved. *
|
||||
* Released under the BSD license - see LICENSE in the root for more details. *
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#include <xenia/logging.h>
|
||||
|
||||
#include <xenia/common.h>
|
||||
|
||||
|
||||
void xe_log_line(const xechar_t* file_path, const uint32_t line_number,
|
||||
const xechar_t* function_name, const xechar_t level_char,
|
||||
const xechar_t* fmt, ...) {
|
||||
const int kLogMax = 2048;
|
||||
|
||||
// Strip out just the filename from the path.
|
||||
const xechar_t* filename = xestrrchr(file_path, XE_PATH_SEPARATOR);
|
||||
if (filename) {
|
||||
// Slash - skip over it.
|
||||
filename++;
|
||||
} else {
|
||||
// No slash, entire thing is filename.
|
||||
filename = file_path;
|
||||
}
|
||||
|
||||
// Scribble args into the print buffer.
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
xechar_t buffer[kLogMax];
|
||||
int buffer_length = xevsnprintf(buffer, XECOUNT(buffer), fmt, args);
|
||||
va_end(args);
|
||||
if (buffer_length < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Format string - add a trailing newline if required.
|
||||
const xechar_t* outfmt;
|
||||
if ((buffer_length >= 1) && buffer[buffer_length - 1] == '\n') {
|
||||
outfmt = XT("XE[%c] %s:%d: %s");
|
||||
} else {
|
||||
outfmt = XT("XE[%c] %s:%d: %s\n");
|
||||
}
|
||||
|
||||
#if defined(OutputDebugString)
|
||||
xechar_t full_output[kLogMax];
|
||||
if (xesnprintf(full_output, XECOUNT(buffer), outfmt, level_char,
|
||||
filename, line_number, buffer) >= 0) {
|
||||
OutputDebugString(full_output);
|
||||
}
|
||||
#elif defined(XE_WCHAR)
|
||||
XEIGNORE(fwprintf(stdout, outfmt, level_char, filename, line_number, buffer));
|
||||
#else
|
||||
XEIGNORE(fprintf(stdout, outfmt, level_char, filename, line_number, buffer));
|
||||
#endif // OutputDebugString
|
||||
}
|
||||
137
src/xenia/malloc.cc
Normal file
137
src/xenia/malloc.cc
Normal file
@@ -0,0 +1,137 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* Xenia : Xbox 360 Emulator Research Project *
|
||||
******************************************************************************
|
||||
* Copyright 2013 Ben Vanik. All rights reserved. *
|
||||
* Released under the BSD license - see LICENSE in the root for more details. *
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#include <xenia/malloc.h>
|
||||
|
||||
#include <xenia/common.h>
|
||||
|
||||
|
||||
void *xe_malloc(const size_t size) {
|
||||
// Some platforms return NULL from malloc with size zero.
|
||||
if (!size) {
|
||||
return malloc(1);
|
||||
}
|
||||
return malloc(size);
|
||||
}
|
||||
|
||||
void *xe_calloc(const size_t size) {
|
||||
// Some platforms return NULL from malloc with size zero.
|
||||
if (!size) {
|
||||
return calloc(1, 1);
|
||||
}
|
||||
return calloc(1, size);
|
||||
}
|
||||
|
||||
void* xe_realloc(void *ptr, const size_t old_size, const size_t new_size) {
|
||||
if (!ptr) {
|
||||
// Support realloc as malloc.
|
||||
return malloc(new_size);
|
||||
}
|
||||
if (old_size == new_size) {
|
||||
// No-op.
|
||||
return ptr;
|
||||
}
|
||||
if (!new_size) {
|
||||
// Zero-size realloc, return a dummy buffer for platforms that don't support
|
||||
// zero-size allocs.
|
||||
void *dummy = malloc(1);
|
||||
if (!dummy) {
|
||||
return NULL;
|
||||
}
|
||||
xe_free(ptr);
|
||||
return dummy;
|
||||
}
|
||||
|
||||
return realloc(ptr, new_size);
|
||||
}
|
||||
|
||||
void* xe_recalloc(void *ptr, const size_t old_size, const size_t new_size) {
|
||||
if (!ptr) {
|
||||
// Support realloc as malloc.
|
||||
return calloc(1, new_size);
|
||||
}
|
||||
if (old_size == new_size) {
|
||||
// No-op.
|
||||
return ptr;
|
||||
}
|
||||
if (!new_size) {
|
||||
// Zero-size realloc, return a dummy buffer for platforms that don't support
|
||||
// zero-size allocs.
|
||||
void *dummy = calloc(1, 1);
|
||||
if (!dummy) {
|
||||
return NULL;
|
||||
}
|
||||
xe_free(ptr);
|
||||
return dummy;
|
||||
}
|
||||
|
||||
void *result = realloc(ptr, new_size);
|
||||
if (!result) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Zero out new memory.
|
||||
if (new_size > old_size) {
|
||||
xe_zero_memory(result, new_size, old_size, new_size - old_size);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void xe_free(void *ptr) {
|
||||
if (ptr) {
|
||||
free(ptr);
|
||||
}
|
||||
}
|
||||
|
||||
xe_aligned_void_t *xe_malloc_aligned(const size_t size) {
|
||||
// TODO(benvanik): validate every platform is aligned to XE_ALIGNMENT.
|
||||
return xe_malloc(size);
|
||||
}
|
||||
|
||||
void xe_free_aligned(xe_aligned_void_t *ptr) {
|
||||
xe_free((void*)ptr);
|
||||
}
|
||||
|
||||
int xe_zero_struct(void *ptr, const size_t size) {
|
||||
return xe_zero_memory(ptr, size, 0, size);
|
||||
}
|
||||
|
||||
int xe_zero_memory(void *ptr, const size_t size, const size_t offset,
|
||||
const size_t length) {
|
||||
// TODO(benvanik): validate sizing/clamp.
|
||||
if (!ptr || !length) {
|
||||
return 0;
|
||||
}
|
||||
if (offset + length > size) {
|
||||
return 1;
|
||||
}
|
||||
memset((uint8_t*)ptr + offset, 0, length);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int xe_copy_struct(void *dest, const void *source, const size_t size) {
|
||||
return xe_copy_memory(dest, size, source, size);
|
||||
}
|
||||
|
||||
int xe_copy_memory(void *dest, const size_t dest_size, const void *source,
|
||||
const size_t source_size) {
|
||||
// TODO(benvanik): validate sizing.
|
||||
if (!source_size) {
|
||||
return 0;
|
||||
}
|
||||
if (!dest || !source) {
|
||||
return 1;
|
||||
}
|
||||
if (dest_size < source_size) {
|
||||
return 1;
|
||||
}
|
||||
memcpy(dest, source, source_size);
|
||||
return 0;
|
||||
}
|
||||
7
src/xenia/sources.gypi
Normal file
7
src/xenia/sources.gypi
Normal file
@@ -0,0 +1,7 @@
|
||||
# Copyright 2013 Ben Vanik. All Rights Reserved.
|
||||
{
|
||||
'sources': [
|
||||
'logging.cc',
|
||||
'malloc.cc',
|
||||
],
|
||||
}
|
||||
Reference in New Issue
Block a user