mirror of
https://github.com/RetroDECK/Supermodel.git
synced 2024-11-22 13:55:38 +00:00
Encryption device emulation (thanks to MAME), fixed warnings in Model3.cpp, added a string formatter helper, and updated Win32 GCC Makefile.
This commit is contained in:
parent
c0f679479a
commit
6e5c301de8
|
@ -57,7 +57,8 @@ BOOST_INCLUDEPATH = /mingw64/boost_1_55_0
|
||||||
#
|
#
|
||||||
ifeq ($(strip $(BITS)),64)
|
ifeq ($(strip $(BITS)),64)
|
||||||
SDL_LIBPATH = /mingw64/lib64
|
SDL_LIBPATH = /mingw64/lib64
|
||||||
SDL_INCLUDEPATH = /mingw64/x86_64-w64-mingw32/include/SDL
|
#SDL_INCLUDEPATH = /mingw64/x86_64-w64-mingw32/include/SDL
|
||||||
|
SDL_INCLUDEPATH = /mingw64/SDL-1.2.15/include
|
||||||
else
|
else
|
||||||
SDL_LIBPATH = /mingw/lib
|
SDL_LIBPATH = /mingw/lib
|
||||||
SDL_INCLUDEPATH = /mingw/include/SDL
|
SDL_INCLUDEPATH = /mingw/include/SDL
|
||||||
|
@ -68,6 +69,7 @@ endif
|
||||||
#
|
#
|
||||||
ifeq ($(strip $(BITS)),64)
|
ifeq ($(strip $(BITS)),64)
|
||||||
WINSDK_LIBPATH = /Program\ Files/Microsoft\ SDKs/Windows/v7.0/Lib/x64
|
WINSDK_LIBPATH = /Program\ Files/Microsoft\ SDKs/Windows/v7.0/Lib/x64
|
||||||
|
#WINSDK_LIBPATH = /Program\ Files\ (x86)/Windows\ Kits/10/Lib/10.0.10586.0/um/x64
|
||||||
else
|
else
|
||||||
WINSDK_LIBPATH = /Program\ Files/Microsoft\ SDKs/Windows/v7.0/Lib
|
WINSDK_LIBPATH = /Program\ Files/Microsoft\ SDKs/Windows/v7.0/Lib
|
||||||
endif
|
endif
|
||||||
|
@ -98,7 +100,7 @@ LD = g++
|
||||||
COMPILER_FLAGS = -I$(SDL_INCLUDEPATH) -ISrc/ -ISrc/OSD/ -ISrc/OSD/SDL/ -ISrc/OSD/Windows/ -c -Wall -DSUPERMODEL_WIN32 -DGLEW_STATIC -O3
|
COMPILER_FLAGS = -I$(SDL_INCLUDEPATH) -ISrc/ -ISrc/OSD/ -ISrc/OSD/SDL/ -ISrc/OSD/Windows/ -c -Wall -DSUPERMODEL_WIN32 -DGLEW_STATIC -O3
|
||||||
CFLAGS = $(COMPILER_FLAGS)
|
CFLAGS = $(COMPILER_FLAGS)
|
||||||
CPPFLAGS = $(COMPILER_FLAGS) -I$(BOOST_INCLUDEPATH) -std=c++11
|
CPPFLAGS = $(COMPILER_FLAGS) -I$(BOOST_INCLUDEPATH) -std=c++11
|
||||||
LFLAGS = -o $(OUTFILE) $(OBJ) -L$(SDL_LIBPATH) -lmingw32 -lSDLmain -lSDL -lopengl32 -lglu32 -ldinput8 -ldxguid -lole32 -loleaut32 -lz -l:$(WINSDK_LIBPATH)/WbemUuid.lib -s
|
LFLAGS = -o $(OUTFILE) $(OBJ) -L$(SDL_LIBPATH) -lmingw32 -lSDLmain -lSDL -lopengl32 -lglu32 -ldinput8 -ldxguid -lole32 -loleaut32 -lwbemuuid -lz -s #-l:$(WINSDK_LIBPATH)/WbemUuid.lib -s
|
||||||
|
|
||||||
#
|
#
|
||||||
# Build options...
|
# Build options...
|
||||||
|
@ -131,7 +133,9 @@ OBJ = $(OBJ_DIR)/PPCDisasm.o $(OBJ_DIR)/Games.o $(OBJ_DIR)/Config.o $(OBJ_DIR)/I
|
||||||
$(OBJ_DIR)/Outputs.o $(OBJ_DIR)/WinOutputs.o \
|
$(OBJ_DIR)/Outputs.o $(OBJ_DIR)/WinOutputs.o \
|
||||||
$(OBJ_DIR)/amp_audio.o $(OBJ_DIR)/amp_dump.o $(OBJ_DIR)/amp_getbits.o $(OBJ_DIR)/amp_getdata.o $(OBJ_DIR)/amp_huffman.o \
|
$(OBJ_DIR)/amp_audio.o $(OBJ_DIR)/amp_dump.o $(OBJ_DIR)/amp_getbits.o $(OBJ_DIR)/amp_getdata.o $(OBJ_DIR)/amp_huffman.o \
|
||||||
$(OBJ_DIR)/amp_layer2.o $(OBJ_DIR)/amp_layer3.o $(OBJ_DIR)/amp_misc2.o $(OBJ_DIR)/amp_position.o $(OBJ_DIR)/amp_transform.o \
|
$(OBJ_DIR)/amp_layer2.o $(OBJ_DIR)/amp_layer3.o $(OBJ_DIR)/amp_misc2.o $(OBJ_DIR)/amp_position.o $(OBJ_DIR)/amp_transform.o \
|
||||||
$(OBJ_DIR)/amp_util.o
|
$(OBJ_DIR)/amp_util.o \
|
||||||
|
$(OBJ_DIR)/Crypto.o \
|
||||||
|
$(OBJ_DIR)/Format.o
|
||||||
|
|
||||||
|
|
||||||
# If built-in debugger enabled, include all debugging classes
|
# If built-in debugger enabled, include all debugging classes
|
||||||
|
@ -250,6 +254,9 @@ $(OBJ_DIR)/%.o: Src/OSD/Windows/%.cpp
|
||||||
$(OBJ_DIR)/%.o: Src/Pkgs/%.c
|
$(OBJ_DIR)/%.o: Src/Pkgs/%.c
|
||||||
$(CC) $< $(CFLAGS) -o $(OBJ_DIR)/$(*F).o
|
$(CC) $< $(CFLAGS) -o $(OBJ_DIR)/$(*F).o
|
||||||
|
|
||||||
|
$(OBJ_DIR)/%.o: Src/Util/%.cpp Src/Util/%.h
|
||||||
|
$(CC) $< $(CPPFLAGS) -o $(OBJ_DIR)/$(*F).o
|
||||||
|
|
||||||
#
|
#
|
||||||
# AMP MPEG decoder library
|
# AMP MPEG decoder library
|
||||||
#
|
#
|
||||||
|
|
1031
Src/Model3/Crypto.cpp
Normal file
1031
Src/Model3/Crypto.cpp
Normal file
File diff suppressed because it is too large
Load diff
123
Src/Model3/Crypto.h
Normal file
123
Src/Model3/Crypto.h
Normal file
|
@ -0,0 +1,123 @@
|
||||||
|
/**
|
||||||
|
** Supermodel
|
||||||
|
** A Sega Model 3 Arcade Emulator.
|
||||||
|
** Copyright 2011-2016 Bart Trzynadlowski, Nik Henson
|
||||||
|
**
|
||||||
|
** This file is part of Supermodel.
|
||||||
|
**
|
||||||
|
** Supermodel 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 (at your option)
|
||||||
|
** any later version.
|
||||||
|
**
|
||||||
|
** Supermodel 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 Supermodel. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
**/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Crypto.h
|
||||||
|
*
|
||||||
|
* Header file for security board encryption device. This code was taken from
|
||||||
|
* MAME (http://mamedev.org).
|
||||||
|
*/
|
||||||
|
|
||||||
|
// license:BSD-3-Clause
|
||||||
|
// copyright-holders:David Haywood
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef __SEGA315_5881_CRYPT__
|
||||||
|
#define __SEGA315_5881_CRYPT__
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <memory>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
|
class CBlockFile;
|
||||||
|
|
||||||
|
class CCrypto
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// construction/destruction
|
||||||
|
CCrypto();
|
||||||
|
|
||||||
|
void SaveState(CBlockFile *SaveState);
|
||||||
|
void LoadState(CBlockFile *SaveState);
|
||||||
|
void Init(uint32_t encryptionKey, std::function<uint16_t(uint32_t)> ReadRAMCallback);
|
||||||
|
void Reset();
|
||||||
|
|
||||||
|
|
||||||
|
uint16_t Decrypt(uint8_t **base);
|
||||||
|
void SetAddressLow(uint16_t data);
|
||||||
|
void SetAddressHigh(uint16_t data);
|
||||||
|
void SetSubKey(uint16_t data);
|
||||||
|
|
||||||
|
std::function<uint16_t(uint32_t)> m_read;
|
||||||
|
|
||||||
|
/*
|
||||||
|
static void set_read_cb(device_t &device,sega_m2_read_delegate readcb)
|
||||||
|
{
|
||||||
|
sega_315_5881_crypt_device &dev = downcast<sega_315_5881_crypt_device &>(device);
|
||||||
|
dev.m_read = readcb;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
uint32_t key;
|
||||||
|
|
||||||
|
std::unique_ptr<uint8_t[]> buffer;
|
||||||
|
std::unique_ptr<uint8_t[]> line_buffer;
|
||||||
|
std::unique_ptr<uint8_t[]> line_buffer_prev;
|
||||||
|
uint32_t prot_cur_address;
|
||||||
|
uint16_t subkey, dec_hist;
|
||||||
|
uint32_t dec_header;
|
||||||
|
|
||||||
|
bool enc_ready;
|
||||||
|
|
||||||
|
int buffer_pos, line_buffer_pos, line_buffer_size, buffer_bit, buffer_bit2;
|
||||||
|
uint8_t buffer2[2];
|
||||||
|
uint16_t buffer2a;
|
||||||
|
|
||||||
|
int block_size;
|
||||||
|
int block_pos;
|
||||||
|
int block_numlines;
|
||||||
|
int done_compression;
|
||||||
|
|
||||||
|
struct sbox {
|
||||||
|
uint8_t table[64];
|
||||||
|
int inputs[6]; // positions of the inputs bits, -1 means no input except from key
|
||||||
|
int outputs[2]; // positions of the output bits
|
||||||
|
};
|
||||||
|
|
||||||
|
static const sbox fn1_sboxes[4][4];
|
||||||
|
static const sbox fn2_sboxes[4][4];
|
||||||
|
|
||||||
|
static const int FN1GK = 38;
|
||||||
|
static const int FN2GK = 32;
|
||||||
|
static const int fn1_game_key_scheduling[FN1GK][2];
|
||||||
|
static const int fn2_game_key_scheduling[FN2GK][2];
|
||||||
|
static const int fn1_sequence_key_scheduling[20][2];
|
||||||
|
static const int fn2_sequence_key_scheduling[16];
|
||||||
|
static const int fn2_middle_result_scheduling[16];
|
||||||
|
|
||||||
|
static const uint8_t trees[9][2][32];
|
||||||
|
|
||||||
|
int feistel_function(int input, const struct sbox *sboxes, uint32_t subkeys);
|
||||||
|
uint16_t block_decrypt(uint32_t game_key, uint16_t sequence_key, uint16_t counter, uint16_t data);
|
||||||
|
|
||||||
|
uint16_t get_decrypted_16();
|
||||||
|
int get_compressed_bit();
|
||||||
|
|
||||||
|
void enc_start();
|
||||||
|
void enc_fill();
|
||||||
|
void line_fill();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
File diff suppressed because it is too large
Load diff
|
@ -28,6 +28,7 @@
|
||||||
#ifndef INCLUDED_MODEL3_H
|
#ifndef INCLUDED_MODEL3_H
|
||||||
#define INCLUDED_MODEL3_H
|
#define INCLUDED_MODEL3_H
|
||||||
|
|
||||||
|
#include "Model3/Crypto.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* FrameTimings
|
* FrameTimings
|
||||||
|
@ -36,13 +37,13 @@
|
||||||
*/
|
*/
|
||||||
struct FrameTimings
|
struct FrameTimings
|
||||||
{
|
{
|
||||||
UINT32 ppcTicks;
|
UINT32 ppcTicks;
|
||||||
UINT32 syncSize;
|
UINT32 syncSize;
|
||||||
UINT32 syncTicks;
|
UINT32 syncTicks;
|
||||||
UINT32 renderTicks;
|
UINT32 renderTicks;
|
||||||
UINT32 sndTicks;
|
UINT32 sndTicks;
|
||||||
UINT32 drvTicks;
|
UINT32 drvTicks;
|
||||||
UINT32 frameTicks;
|
UINT32 frameTicks;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -53,34 +54,34 @@ struct FrameTimings
|
||||||
class CModel3Config
|
class CModel3Config
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
bool multiThreaded; // Multi-threaded (enabled if true)
|
bool multiThreaded; // Multi-threaded (enabled if true)
|
||||||
bool gpuMultiThreaded; // Multi-threaded rendering (enabled if true)
|
bool gpuMultiThreaded; // Multi-threaded rendering (enabled if true)
|
||||||
|
|
||||||
// PowerPC clock frequency in MHz (minimum: 1 MHz)
|
// PowerPC clock frequency in MHz (minimum: 1 MHz)
|
||||||
inline void SetPowerPCFrequency(unsigned f)
|
inline void SetPowerPCFrequency(unsigned f)
|
||||||
{
|
{
|
||||||
if ((f<1) || (f>1000))
|
if ((f<1) || (f>1000))
|
||||||
{
|
{
|
||||||
ErrorLog("PowerPC frequency must be between 1 and 1000 MHz; setting to 50 MHz.");
|
ErrorLog("PowerPC frequency must be between 1 and 1000 MHz; setting to 50 MHz.");
|
||||||
f = 50;
|
f = 50;
|
||||||
}
|
}
|
||||||
ppcFrequency = f*1000000;
|
ppcFrequency = f*1000000;
|
||||||
}
|
}
|
||||||
inline unsigned GetPowerPCFrequency(void)
|
inline unsigned GetPowerPCFrequency(void)
|
||||||
{
|
{
|
||||||
return ppcFrequency/1000000;
|
return ppcFrequency/1000000;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Defaults
|
// Defaults
|
||||||
CModel3Config(void)
|
CModel3Config(void)
|
||||||
{
|
{
|
||||||
multiThreaded = true; // enable by default
|
multiThreaded = true; // enable by default
|
||||||
gpuMultiThreaded = true; // enable by default
|
gpuMultiThreaded = true; // enable by default
|
||||||
ppcFrequency = 50*1000000; // 50 MHz
|
ppcFrequency = 50*1000000; // 50 MHz
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
unsigned ppcFrequency; // in Hz
|
unsigned ppcFrequency; // in Hz
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -97,392 +98,393 @@ private:
|
||||||
class CModel3: public CBus, public CPCIDevice
|
class CModel3: public CBus, public CPCIDevice
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/*
|
/*
|
||||||
* ReadPCIConfigSpace(device, reg, bits, offset):
|
* ReadPCIConfigSpace(device, reg, bits, offset):
|
||||||
*
|
*
|
||||||
* Handles unknown PCI devices. See CPCIDevice definition for more details.
|
* Handles unknown PCI devices. See CPCIDevice definition for more details.
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* device Device number.
|
* device Device number.
|
||||||
* reg Register number.
|
* reg Register number.
|
||||||
* bits Bit width of access (8, 16, or 32 only).;
|
* bits Bit width of access (8, 16, or 32 only).;
|
||||||
* offset Byte offset within register, aligned to the specified bit
|
* offset Byte offset within register, aligned to the specified bit
|
||||||
* width, and offset from the 32-bit aligned base of the
|
* width, and offset from the 32-bit aligned base of the
|
||||||
* register number.
|
* register number.
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* Register data.
|
* Register data.
|
||||||
*/
|
*/
|
||||||
UINT32 ReadPCIConfigSpace(unsigned device, unsigned reg, unsigned bits, unsigned width);
|
UINT32 ReadPCIConfigSpace(unsigned device, unsigned reg, unsigned bits, unsigned width);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* WritePCIConfigSpace(device, reg, bits, offset, data):
|
* WritePCIConfigSpace(device, reg, bits, offset, data):
|
||||||
*
|
*
|
||||||
* Handles unknown PCI devices. See CPCIDevice definition for more details.
|
* Handles unknown PCI devices. See CPCIDevice definition for more details.
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* device Device number.
|
* device Device number.
|
||||||
* reg Register number.
|
* reg Register number.
|
||||||
* bits Bit width of access (8, 16, or 32 only).
|
* bits Bit width of access (8, 16, or 32 only).
|
||||||
* offset Byte offset within register, aligned to the specified bit
|
* offset Byte offset within register, aligned to the specified bit
|
||||||
* width, and offset from the 32-bit aligned base of the
|
* width, and offset from the 32-bit aligned base of the
|
||||||
* register number.
|
* register number.
|
||||||
* data Data.
|
* data Data.
|
||||||
*/
|
*/
|
||||||
void WritePCIConfigSpace(unsigned device, unsigned reg, unsigned bits, unsigned width, UINT32 data);
|
void WritePCIConfigSpace(unsigned device, unsigned reg, unsigned bits, unsigned width, UINT32 data);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Read8(addr):
|
* Read8(addr):
|
||||||
* Read16(addr):
|
* Read16(addr):
|
||||||
* Read32(addr):
|
* Read32(addr):
|
||||||
* Read64(addr):
|
* Read64(addr):
|
||||||
*
|
*
|
||||||
* Read a byte, 16-bit half word, 32-bit word, or 64-bit double word from
|
* Read a byte, 16-bit half word, 32-bit word, or 64-bit double word from
|
||||||
* the PowerPC address space. This implements the PowerPC address bus. Note
|
* the PowerPC address space. This implements the PowerPC address bus. Note
|
||||||
* that it is big endian, so when accessing from a little endian device,
|
* that it is big endian, so when accessing from a little endian device,
|
||||||
* the byte order must be manually reversed.
|
* the byte order must be manually reversed.
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* addr Address to read.
|
* addr Address to read.
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* Data at the address.
|
* Data at the address.
|
||||||
*/
|
*/
|
||||||
UINT8 Read8(UINT32 addr);
|
UINT8 Read8(UINT32 addr);
|
||||||
UINT16 Read16(UINT32 addr);
|
UINT16 Read16(UINT32 addr);
|
||||||
UINT32 Read32(UINT32 addr);
|
UINT32 Read32(UINT32 addr);
|
||||||
UINT64 Read64(UINT32 addr);
|
UINT64 Read64(UINT32 addr);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Write8(addr, data):
|
* Write8(addr, data):
|
||||||
* Write16(addr, data):
|
* Write16(addr, data):
|
||||||
* Write32(addr, data):
|
* Write32(addr, data):
|
||||||
* Write64(addr, data):
|
* Write64(addr, data):
|
||||||
*
|
*
|
||||||
* Write a byte, half word, word, or double word to the PowerPC address
|
* Write a byte, half word, word, or double word to the PowerPC address
|
||||||
* space. Note that everything is stored in big endian form, so when
|
* space. Note that everything is stored in big endian form, so when
|
||||||
* accessing with a little endian device, the byte order must be manually
|
* accessing with a little endian device, the byte order must be manually
|
||||||
* reversed.
|
* reversed.
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* addr Address to write.
|
* addr Address to write.
|
||||||
* data Data to write.
|
* data Data to write.
|
||||||
*/
|
*/
|
||||||
void Write8(UINT32 addr, UINT8 data);
|
void Write8(UINT32 addr, UINT8 data);
|
||||||
void Write16(UINT32 addr, UINT16 data);
|
void Write16(UINT32 addr, UINT16 data);
|
||||||
void Write32(UINT32 addr, UINT32 data);
|
void Write32(UINT32 addr, UINT32 data);
|
||||||
void Write64(UINT32 addr, UINT64 data);
|
void Write64(UINT32 addr, UINT64 data);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* SaveState(SaveState):
|
* SaveState(SaveState):
|
||||||
*
|
*
|
||||||
* Saves an image of the current state. Must never be called while emulator
|
* Saves an image of the current state. Must never be called while emulator
|
||||||
* is running (inside RunFrame()).
|
* is running (inside RunFrame()).
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* SaveState Block file to save state information to.
|
* SaveState Block file to save state information to.
|
||||||
*/
|
*/
|
||||||
void SaveState(CBlockFile *SaveState);
|
void SaveState(CBlockFile *SaveState);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* LoadState(SaveState):
|
* LoadState(SaveState):
|
||||||
*
|
*
|
||||||
* Loads and resumes execution from a state image. Modifies data that may
|
* Loads and resumes execution from a state image. Modifies data that may
|
||||||
* be used by multiple threads -- use with caution and ensure threads are
|
* be used by multiple threads -- use with caution and ensure threads are
|
||||||
* not accessing data that will be touched, this can be done by calling
|
* not accessing data that will be touched, this can be done by calling
|
||||||
* PauseThreads beforehand. Must never be called while emulator is running
|
* PauseThreads beforehand. Must never be called while emulator is running
|
||||||
* (inside RunFrame()).
|
* (inside RunFrame()).
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* SaveState Block file to load state information from.
|
* SaveState Block file to load state information from.
|
||||||
*/
|
*/
|
||||||
void LoadState(CBlockFile *SaveState);
|
void LoadState(CBlockFile *SaveState);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* SaveNVRAM(NVRAM):
|
* SaveNVRAM(NVRAM):
|
||||||
*
|
*
|
||||||
* Saves an image of the current NVRAM state.
|
* Saves an image of the current NVRAM state.
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* NVRAM Block file to save NVRAM to.
|
* NVRAM Block file to save NVRAM to.
|
||||||
*/
|
*/
|
||||||
void SaveNVRAM(CBlockFile *NVRAM);
|
void SaveNVRAM(CBlockFile *NVRAM);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* LoadNVRAM(NVRAM):
|
* LoadNVRAM(NVRAM):
|
||||||
*
|
*
|
||||||
* Loads an NVRAM image.
|
* Loads an NVRAM image.
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* NVRAM Block file to load NVRAM state from.
|
* NVRAM Block file to load NVRAM state from.
|
||||||
*/
|
*/
|
||||||
void LoadNVRAM(CBlockFile *NVRAM);
|
void LoadNVRAM(CBlockFile *NVRAM);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ClearNVRAM(void):
|
* ClearNVRAM(void):
|
||||||
*
|
*
|
||||||
* Clears all NVRAM (backup RAM and EEPROM).
|
* Clears all NVRAM (backup RAM and EEPROM).
|
||||||
*/
|
*/
|
||||||
void ClearNVRAM(void);
|
void ClearNVRAM(void);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* RunFrame(void):
|
* RunFrame(void):
|
||||||
*
|
*
|
||||||
* Runs one frame (assuming 60 Hz video refresh rate).
|
* Runs one frame (assuming 60 Hz video refresh rate).
|
||||||
*/
|
*/
|
||||||
void RunFrame(void);
|
void RunFrame(void);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Reset(void):
|
* Reset(void):
|
||||||
*
|
*
|
||||||
* Resets the system. Does not modify non-volatile memory.
|
* Resets the system. Does not modify non-volatile memory.
|
||||||
*/
|
*/
|
||||||
void Reset(void);
|
void Reset(void);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* GetGameInfo(void):
|
* GetGameInfo(void):
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* A pointer to the presently loaded game's information structure (or
|
* A pointer to the presently loaded game's information structure (or
|
||||||
* NULL if no ROM set has yet been loaded).
|
* NULL if no ROM set has yet been loaded).
|
||||||
*/
|
*/
|
||||||
const struct GameInfo * GetGameInfo(void);
|
const struct GameInfo * GetGameInfo(void);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* LoadROMSet(GameList, zipFile):
|
* LoadROMSet(GameList, zipFile):
|
||||||
*
|
*
|
||||||
* Loads a complete ROM set from the specified ZIP archive.
|
* Loads a complete ROM set from the specified ZIP archive.
|
||||||
*
|
*
|
||||||
* NOTE: Command line settings will not have been applied here yet.
|
* NOTE: Command line settings will not have been applied here yet.
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* GameList List of all supported games and their ROMs.
|
* GameList List of all supported games and their ROMs.
|
||||||
* zipFile ZIP file to load from.
|
* zipFile ZIP file to load from.
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* OKAY if successful, FAIL otherwise. Prints errors.
|
* OKAY if successful, FAIL otherwise. Prints errors.
|
||||||
*/
|
*/
|
||||||
bool LoadROMSet(const struct GameInfo *GameList, const char *zipFile);
|
bool LoadROMSet(const struct GameInfo *GameList, const char *zipFile);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* AttachRenderers(Render2DPtr, Render3DPtr):
|
* AttachRenderers(Render2DPtr, Render3DPtr):
|
||||||
*
|
*
|
||||||
* Attaches the renderers to the appropriate device objects.
|
* Attaches the renderers to the appropriate device objects.
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* Render2DPtr Pointer to a tile renderer object.
|
* Render2DPtr Pointer to a tile renderer object.
|
||||||
* Render3DPtr Same as above but for a 3D renderer.
|
* Render3DPtr Same as above but for a 3D renderer.
|
||||||
*/
|
*/
|
||||||
void AttachRenderers(CRender2D *Render2DPtr, IRender3D *Render3DPtr);
|
void AttachRenderers(CRender2D *Render2DPtr, IRender3D *Render3DPtr);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* AttachInputs(InputsPtr):
|
* AttachInputs(InputsPtr):
|
||||||
*
|
*
|
||||||
* Attaches OSD-managed inputs.
|
* Attaches OSD-managed inputs.
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* InputsPtr Pointer to the object containing input states.
|
* InputsPtr Pointer to the object containing input states.
|
||||||
*/
|
*/
|
||||||
void AttachInputs(CInputs *InputsPtr);
|
void AttachInputs(CInputs *InputsPtr);
|
||||||
|
|
||||||
void AttachOutputs(COutputs *OutputsPtr);
|
void AttachOutputs(COutputs *OutputsPtr);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Init(void):
|
* Init(void):
|
||||||
*
|
*
|
||||||
* One-time initialization of the context. Must be called prior to all
|
* One-time initialization of the context. Must be called prior to all
|
||||||
* other members. Allocates memory and initializes device states.
|
* other members. Allocates memory and initializes device states.
|
||||||
*
|
*
|
||||||
* NOTE: Command line settings will not have been applied here yet.
|
* NOTE: Command line settings will not have been applied here yet.
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* OKAY is successful, otherwise FAILED if a non-recoverable error
|
* OKAY is successful, otherwise FAILED if a non-recoverable error
|
||||||
* occurred. Prints own error messages.
|
* occurred. Prints own error messages.
|
||||||
*/
|
*/
|
||||||
bool Init(void);
|
bool Init(void);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* GetSoundBoard(void):
|
* GetSoundBoard(void):
|
||||||
*
|
*
|
||||||
* Returns a reference to the sound board.
|
* Returns a reference to the sound board.
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* Pointer to CSoundBoard object.
|
* Pointer to CSoundBoard object.
|
||||||
*/
|
*/
|
||||||
CSoundBoard *GetSoundBoard(void);
|
CSoundBoard *GetSoundBoard(void);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* GetDriveBoard(void):
|
* GetDriveBoard(void):
|
||||||
*
|
*
|
||||||
* Returns a reference to the drive board.
|
* Returns a reference to the drive board.
|
||||||
|
|
||||||
* Returns:
|
* Returns:
|
||||||
* Pointer to CDriveBoard object.
|
* Pointer to CDriveBoard object.
|
||||||
*/
|
*/
|
||||||
CDriveBoard *GetDriveBoard(void);
|
CDriveBoard *GetDriveBoard(void);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* PauseThreads(void):
|
* PauseThreads(void):
|
||||||
*
|
*
|
||||||
* Flags that any running threads should pause and waits for them to do so.
|
* Flags that any running threads should pause and waits for them to do so.
|
||||||
* Should be used before invoking any method that accesses the internal state, eg LoadState or SaveState.
|
* Should be used before invoking any method that accesses the internal state, eg LoadState or SaveState.
|
||||||
*/
|
*/
|
||||||
bool PauseThreads(void);
|
bool PauseThreads(void);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ResumeThreads(void):
|
* ResumeThreads(void):
|
||||||
*
|
*
|
||||||
* Flags that any paused threads should resume running.
|
* Flags that any paused threads should resume running.
|
||||||
*/
|
*/
|
||||||
bool ResumeThreads(void);
|
bool ResumeThreads(void);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* DumpTimings(void):
|
* DumpTimings(void):
|
||||||
*
|
*
|
||||||
* Prints all timings for the most recent frame to the console, for debugging purposes.
|
* Prints all timings for the most recent frame to the console, for debugging purposes.
|
||||||
*/
|
*/
|
||||||
void DumpTimings(void);
|
void DumpTimings(void);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* GetTimings(void):
|
* GetTimings(void):
|
||||||
*
|
*
|
||||||
* Returns timings for the most recent frame, for debugging purposes.
|
* Returns timings for the most recent frame, for debugging purposes.
|
||||||
*/
|
*/
|
||||||
FrameTimings GetTimings(void);
|
FrameTimings GetTimings(void);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* CModel3(void):
|
* CModel3(void):
|
||||||
* ~CModel3(void):
|
* ~CModel3(void):
|
||||||
*
|
*
|
||||||
* Constructor and destructor for Model 3 class. Constructor performs a
|
* Constructor and destructor for Model 3 class. Constructor performs a
|
||||||
* bare-bones initialization of object; does not perform any memory
|
* bare-bones initialization of object; does not perform any memory
|
||||||
* allocation or any actions that can fail. The destructor will deallocate
|
* allocation or any actions that can fail. The destructor will deallocate
|
||||||
* memory and free resources used by the object (and its child objects).
|
* memory and free resources used by the object (and its child objects).
|
||||||
*/
|
*/
|
||||||
CModel3(void);
|
CModel3(void);
|
||||||
~CModel3(void);
|
~CModel3(void);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Private Property.
|
* Private Property.
|
||||||
* Tresspassers will be shot! ;)
|
* Tresspassers will be shot! ;)
|
||||||
*/
|
*/
|
||||||
private:
|
private:
|
||||||
// Private member functions
|
// Private member functions
|
||||||
UINT8 ReadInputs(unsigned reg);
|
UINT8 ReadInputs(unsigned reg);
|
||||||
void WriteInputs(unsigned reg, UINT8 data);
|
void WriteInputs(unsigned reg, UINT8 data);
|
||||||
UINT32 ReadSecurity(unsigned reg);
|
uint16_t ReadSecurityRAM(uint32_t addr);
|
||||||
void WriteSecurity(unsigned reg, UINT32 data);
|
UINT32 ReadSecurity(unsigned reg);
|
||||||
void SetCROMBank(unsigned idx);
|
void WriteSecurity(unsigned reg, UINT32 data);
|
||||||
UINT8 ReadSystemRegister(unsigned reg);
|
void SetCROMBank(unsigned idx);
|
||||||
void WriteSystemRegister(unsigned reg, UINT8 data);
|
UINT8 ReadSystemRegister(unsigned reg);
|
||||||
void Patch(void);
|
void WriteSystemRegister(unsigned reg, UINT8 data);
|
||||||
|
void Patch(void);
|
||||||
|
|
||||||
void RunMainBoardFrame(void); // Runs PPC main board for a frame
|
void RunMainBoardFrame(void); // Runs PPC main board for a frame
|
||||||
void SyncGPUs(void); // Sync's up GPUs in preparation for rendering - must be called when PPC is not running
|
void SyncGPUs(void); // Sync's up GPUs in preparation for rendering - must be called when PPC is not running
|
||||||
void RenderFrame(void); // Renders current frame
|
void RenderFrame(void); // Renders current frame
|
||||||
bool RunSoundBoardFrame(void); // Runs sound board for a frame
|
bool RunSoundBoardFrame(void); // Runs sound board for a frame
|
||||||
void RunDriveBoardFrame(void); // Runs drive board for a frame
|
void RunDriveBoardFrame(void); // Runs drive board for a frame
|
||||||
|
|
||||||
bool StartThreads(void); // Starts all threads
|
bool StartThreads(void); // Starts all threads
|
||||||
bool StopThreads(void); // Stops all threads
|
bool StopThreads(void); // Stops all threads
|
||||||
void DeleteThreadObjects(void); // Deletes all threads and synchronization objects
|
void DeleteThreadObjects(void); // Deletes all threads and synchronization objects
|
||||||
|
|
||||||
static int StartMainBoardThread(void *data); // Callback to start PPC main board thread
|
static int StartMainBoardThread(void *data); // Callback to start PPC main board thread
|
||||||
static int StartSoundBoardThread(void *data); // Callback to start sound board thread (unsync'd)
|
static int StartSoundBoardThread(void *data); // Callback to start sound board thread (unsync'd)
|
||||||
static int StartSoundBoardThreadSyncd(void *data); // Callback to start sound board thread (sync'd)
|
static int StartSoundBoardThreadSyncd(void *data); // Callback to start sound board thread (sync'd)
|
||||||
static int StartDriveBoardThread(void *data); // Callback to start drive board thread
|
static int StartDriveBoardThread(void *data); // Callback to start drive board thread
|
||||||
|
|
||||||
static void AudioCallback(void *data); // Audio buffer callback
|
static void AudioCallback(void *data); // Audio buffer callback
|
||||||
|
|
||||||
bool WakeSoundBoardThread(void); // Used by audio callback to wake sound board thread (when not sync'd with render thread)
|
bool WakeSoundBoardThread(void); // Used by audio callback to wake sound board thread (when not sync'd with render thread)
|
||||||
int RunMainBoardThread(void); // Runs PPC main board thread (sync'd in step with render thread)
|
int RunMainBoardThread(void); // Runs PPC main board thread (sync'd in step with render thread)
|
||||||
int RunSoundBoardThread(void); // Runs sound board thread (not sync'd in step with render thread, ie running at full speed)
|
int RunSoundBoardThread(void); // Runs sound board thread (not sync'd in step with render thread, ie running at full speed)
|
||||||
int RunSoundBoardThreadSyncd(void); // Runs sound board thread (sync'd in step with render thread)
|
int RunSoundBoardThreadSyncd(void); // Runs sound board thread (sync'd in step with render thread)
|
||||||
int RunDriveBoardThread(void); // Runs drive board thread (sync'd in step with render thread)
|
int RunDriveBoardThread(void); // Runs drive board thread (sync'd in step with render thread)
|
||||||
|
|
||||||
// Game and hardware information
|
// Game and hardware information
|
||||||
const struct GameInfo *Game;
|
const struct GameInfo *Game;
|
||||||
|
|
||||||
// Game inputs
|
// Game inputs and outputs
|
||||||
CInputs *Inputs;
|
CInputs *Inputs;
|
||||||
|
COutputs *Outputs;
|
||||||
|
|
||||||
// Game outputs
|
// Input registers (game controls)
|
||||||
COutputs *Outputs;
|
UINT8 inputBank;
|
||||||
|
UINT8 serialFIFO1, serialFIFO2;
|
||||||
|
UINT8 gunReg;
|
||||||
|
int adcChannel;
|
||||||
|
|
||||||
// Input registers (game controls)
|
// MIDI port
|
||||||
UINT8 inputBank;
|
UINT8 midiCtrlPort; // controls MIDI (SCSP) IRQ behavior
|
||||||
UINT8 serialFIFO1, serialFIFO2;
|
|
||||||
UINT8 gunReg;
|
|
||||||
int adcChannel;
|
|
||||||
|
|
||||||
// MIDI port
|
// Emulated core Model 3 memory regions
|
||||||
UINT8 midiCtrlPort; // controls MIDI (SCSP) IRQ behavior
|
UINT8 *memoryPool; // single allocated region for all ROM and system RAM
|
||||||
|
UINT8 *ram; // 8 MB PowerPC RAM
|
||||||
|
UINT8 *crom; // 8+128 MB CROM (fixed CROM first, then 64MB of banked CROMs -- Daytona2 might need extra?)
|
||||||
|
UINT8 *vrom; // 64 MB VROM (video ROM, visible only to Real3D)
|
||||||
|
UINT8 *soundROM; // 512 KB sound ROM (68K program)
|
||||||
|
UINT8 *sampleROM; // 8 MB samples (68K)
|
||||||
|
UINT8 *dsbROM; // 128 KB DSB ROM (Z80 program)
|
||||||
|
UINT8 *mpegROM; // 8 MB DSB MPEG ROM
|
||||||
|
UINT8 *backupRAM; // 128 KB Backup RAM (battery backed)
|
||||||
|
UINT8 *securityRAM; // 128 KB Security Board RAM
|
||||||
|
UINT8 *driveROM; // 32 KB drive board ROM (Z80 program) (optional)
|
||||||
|
|
||||||
// Emulated core Model 3 memory regions
|
// Banked CROM
|
||||||
UINT8 *memoryPool; // single allocated region for all ROM and system RAM
|
UINT8 *cromBank; // currently mapped in CROM bank
|
||||||
UINT8 *ram; // 8 MB PowerPC RAM
|
unsigned cromBankReg; // the CROM bank register
|
||||||
UINT8 *crom; // 8+128 MB CROM (fixed CROM first, then 64MB of banked CROMs -- Daytona2 might need extra?)
|
|
||||||
UINT8 *vrom; // 64 MB VROM (video ROM, visible only to Real3D)
|
|
||||||
UINT8 *soundROM; // 512 KB sound ROM (68K program)
|
|
||||||
UINT8 *sampleROM; // 8 MB samples (68K)
|
|
||||||
UINT8 *dsbROM; // 128 KB DSB ROM (Z80 program)
|
|
||||||
UINT8 *mpegROM; // 8 MB DSB MPEG ROM
|
|
||||||
UINT8 *backupRAM; // 128 KB Backup RAM (battery backed)
|
|
||||||
UINT8 *securityRAM; // 128 KB Security Board RAM
|
|
||||||
UINT8 *driveROM; // 32 KB drive board ROM (Z80 program) (optional)
|
|
||||||
|
|
||||||
// Banked CROM
|
// Security device
|
||||||
UINT8 *cromBank; // currently mapped in CROM bank
|
bool m_securityFirstRead = true;
|
||||||
unsigned cromBankReg; // the CROM bank register
|
unsigned securityPtr; // pointer to current offset in security data
|
||||||
|
|
||||||
// Security device
|
// PowerPC
|
||||||
unsigned securityPtr; // pointer to current offset in security data
|
PPC_FETCH_REGION PPCFetchRegions[3];
|
||||||
|
|
||||||
// PowerPC
|
// Multiple threading
|
||||||
PPC_FETCH_REGION PPCFetchRegions[3];
|
bool gpusReady; // True if GPUs are ready to render
|
||||||
|
bool startedThreads; // True if threads have been created and started
|
||||||
|
bool pauseThreads; // True if threads should pause
|
||||||
|
bool stopThreads; // True if threads should stop
|
||||||
|
bool syncSndBrdThread; // True if sound board thread should be sync'd in step with render thread
|
||||||
|
CThread *ppcBrdThread; // PPC main board thread
|
||||||
|
CThread *sndBrdThread; // Sound board thread
|
||||||
|
CThread *drvBrdThread; // Drive board thread
|
||||||
|
bool ppcBrdThreadRunning; // Flag to indicate PPC main board thread is currently processing
|
||||||
|
bool ppcBrdThreadDone; // Flag to indicate PPC main board thread has finished processing
|
||||||
|
bool sndBrdThreadRunning; // Flag to indicate sound board thread is currently processing
|
||||||
|
bool sndBrdThreadDone; // Flag to indicate sound board thread has finished processing
|
||||||
|
bool sndBrdWakeNotify; // Flag to indicate that sound board thread has been woken by audio callback (when not sync'd with render thread)
|
||||||
|
bool drvBrdThreadRunning; // Flag to indicate drive board thread is currently processing
|
||||||
|
bool drvBrdThreadDone; // Flag to indicate drive board thread has finished processing
|
||||||
|
|
||||||
// Multiple threading
|
// Thread synchronization objects
|
||||||
bool gpusReady; // True if GPUs are ready to render
|
CSemaphore *ppcBrdThreadSync;
|
||||||
bool startedThreads; // True if threads have been created and started
|
CSemaphore *sndBrdThreadSync;
|
||||||
bool pauseThreads; // True if threads should pause
|
CMutex *sndBrdNotifyLock;
|
||||||
bool stopThreads; // True if threads should stop
|
CCondVar *sndBrdNotifySync;
|
||||||
bool syncSndBrdThread; // True if sound board thread should be sync'd in step with render thread
|
CSemaphore *drvBrdThreadSync;
|
||||||
CThread *ppcBrdThread; // PPC main board thread
|
CMutex *notifyLock;
|
||||||
CThread *sndBrdThread; // Sound board thread
|
CCondVar *notifySync;
|
||||||
CThread *drvBrdThread; // Drive board thread
|
|
||||||
bool ppcBrdThreadRunning; // Flag to indicate PPC main board thread is currently processing
|
|
||||||
bool ppcBrdThreadDone; // Flag to indicate PPC main board thread has finished processing
|
|
||||||
bool sndBrdThreadRunning; // Flag to indicate sound board thread is currently processing
|
|
||||||
bool sndBrdThreadDone; // Flag to indicate sound board thread has finished processing
|
|
||||||
bool sndBrdWakeNotify; // Flag to indicate that sound board thread has been woken by audio callback (when not sync'd with render thread)
|
|
||||||
bool drvBrdThreadRunning; // Flag to indicate drive board thread is currently processing
|
|
||||||
bool drvBrdThreadDone; // Flag to indicate drive board thread has finished processing
|
|
||||||
|
|
||||||
// Thread synchronization objects
|
// Frame timings
|
||||||
CSemaphore *ppcBrdThreadSync;
|
FrameTimings timings;
|
||||||
CSemaphore *sndBrdThreadSync;
|
|
||||||
CMutex *sndBrdNotifyLock;
|
|
||||||
CCondVar *sndBrdNotifySync;
|
|
||||||
CSemaphore *drvBrdThreadSync;
|
|
||||||
CMutex *notifyLock;
|
|
||||||
CCondVar *notifySync;
|
|
||||||
|
|
||||||
// Frame timings
|
// Other devices
|
||||||
FrameTimings timings;
|
CIRQ IRQ; // Model 3 IRQ controller
|
||||||
|
CMPC10x PCIBridge; // MPC10x PCI/bridge/memory controller
|
||||||
// Other devices
|
CPCIBus PCIBus; // Model 3's PCI bus
|
||||||
CIRQ IRQ; // Model 3 IRQ controller
|
C53C810 SCSI; // NCR 53C810 SCSI controller
|
||||||
CMPC10x PCIBridge; // MPC10x PCI/bridge/memory controller
|
CRTC72421 RTC; // Epson RTC-72421 real-time clock
|
||||||
CPCIBus PCIBus; // Model 3's PCI bus
|
C93C46 EEPROM; // 93C46 EEPROM
|
||||||
C53C810 SCSI; // NCR 53C810 SCSI controller
|
CTileGen TileGen; // Sega 2D tile generator
|
||||||
CRTC72421 RTC; // Epson RTC-72421 real-time clock
|
CReal3D GPU; // Real3D graphics hardware
|
||||||
C93C46 EEPROM; // 93C46 EEPROM
|
CSoundBoard SoundBoard; // Sound board
|
||||||
CTileGen TileGen; // Sega 2D tile generator
|
CDSB *DSB; // Digital Sound Board (type determined dynamically at load time)
|
||||||
CReal3D GPU; // Real3D graphics hardware
|
CDriveBoard DriveBoard; // Drive board
|
||||||
CSoundBoard SoundBoard; // Sound board
|
CCrypto m_cryptoDevice; // Encryption device
|
||||||
CDSB *DSB; // Digital Sound Board (type determined dynamically at load time)
|
|
||||||
CDriveBoard DriveBoard; // Drive board
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // INCLUDED_MODEL3_H
|
#endif // INCLUDED_MODEL3_H
|
33
Src/Util/Format.cpp
Normal file
33
Src/Util/Format.cpp
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
#include "Util/Format.h"
|
||||||
|
|
||||||
|
namespace Util
|
||||||
|
{
|
||||||
|
static const char hex_digits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
|
||||||
|
|
||||||
|
const std::string Hex(uint32_t n, size_t num_digits)
|
||||||
|
{
|
||||||
|
Util::Format f;
|
||||||
|
f << "0x";
|
||||||
|
for (size_t b = num_digits * 4; b; )
|
||||||
|
{
|
||||||
|
b -= 4;
|
||||||
|
f << hex_digits[(n >> b) & 0xf];
|
||||||
|
}
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string Hex(uint32_t n)
|
||||||
|
{
|
||||||
|
return Hex(n, 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string Hex(uint16_t n)
|
||||||
|
{
|
||||||
|
return Hex(n, 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string Hex(uint8_t n)
|
||||||
|
{
|
||||||
|
return Hex(n, 2);
|
||||||
|
}
|
||||||
|
} // Util
|
68
Src/Util/Format.h
Normal file
68
Src/Util/Format.h
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
#ifndef INCLUDED_FORMAT_H
|
||||||
|
#define INCLUDED_FORMAT_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <sstream>
|
||||||
|
#include <iomanip>
|
||||||
|
|
||||||
|
namespace Util
|
||||||
|
{
|
||||||
|
class Format
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
template <typename T>
|
||||||
|
Format &operator<<(const T &data)
|
||||||
|
{
|
||||||
|
m_stream << data;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
operator std::string() const
|
||||||
|
{
|
||||||
|
return str();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string str() const
|
||||||
|
{
|
||||||
|
return m_stream.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
Format &Join(const T &collection)
|
||||||
|
{
|
||||||
|
std::string separator = m_stream.str();
|
||||||
|
clear();
|
||||||
|
for (auto it = collection.begin(); it != collection.end(); )
|
||||||
|
{
|
||||||
|
m_stream << *it;
|
||||||
|
++it;
|
||||||
|
if (it != collection.end())
|
||||||
|
m_stream << separator;
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
Format(const std::string &str)
|
||||||
|
: m_stream(str)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Format()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
std::stringstream m_stream;
|
||||||
|
|
||||||
|
void clear()
|
||||||
|
{
|
||||||
|
m_stream.str(std::string());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const std::string Hex(uint32_t n, size_t num_digits);
|
||||||
|
const std::string Hex(uint32_t n);
|
||||||
|
const std::string Hex(uint16_t n);
|
||||||
|
const std::string Hex(uint8_t n);
|
||||||
|
} // Util
|
||||||
|
|
||||||
|
#endif // INCLUDED_FORMAT_H
|
Loading…
Reference in a new issue