This commit is contained in:
Brad Hughes 2016-11-15 16:19:52 -05:00
commit 7cd5e850f5
4 changed files with 97 additions and 105 deletions

View File

@ -7,104 +7,100 @@
#ifndef PFMT_H_
#define PFMT_H_
//#include <cstdarg>
//#include <cstddef>
#include <limits>
#include "pconfig.h"
#include "pstring.h"
#include "ptypes.h"
namespace plib {
template <typename T>
struct ptype_treats
struct ptype_traits_base
{
static T cast(T x) { return x; }
static const bool is_signed = std::numeric_limits<T>::is_signed;
};
template<>
struct ptype_treats<bool>
template <>
struct ptype_traits_base<bool>
{
static unsigned int cast(bool x) { return static_cast<unsigned int>(x); }
static const bool is_signed = false;
static const bool is_signed = std::numeric_limits<bool>::is_signed;
};
template <typename T>
struct ptype_traits;
template<>
struct ptype_traits<bool> : ptype_traits_base<bool>
{
static const char *size_specifier() { return ""; }
};
template<>
struct ptype_treats<char>
struct ptype_traits<char> : ptype_traits_base<char>
{
static short cast(char x) { return x; }
static const bool is_signed = true;
static const char *size_specifier() { return "h"; }
};
template<>
struct ptype_treats<short>
struct ptype_traits<short> : ptype_traits_base<short>
{
static short cast(short x) { return x; }
static const bool is_signed = true;
static const char *size_specifier() { return "h"; }
};
template<>
struct ptype_treats<int>
struct ptype_traits<int> : ptype_traits_base<int>
{
static int cast(int x) { return x; }
static const bool is_signed = true;
static const char *size_specifier() { return ""; }
};
template<>
struct ptype_treats<long>
struct ptype_traits<long> : ptype_traits_base<long>
{
static long cast(long x) { return x; }
static const bool is_signed = true;
static const char *size_specifier() { return "l"; }
};
template<>
struct ptype_treats<long long>
struct ptype_traits<long long> : ptype_traits_base<long long>
{
static long long cast(long long x) { return x; }
static const bool is_signed = true;
static const char *size_specifier() { return "ll"; }
};
template<>
struct ptype_treats<unsigned char>
struct ptype_traits<signed char> : ptype_traits_base<signed char>
{
static unsigned short cast(unsigned char x) { return x; }
static const bool is_signed = false;
static const char *size_specifier() { return "h"; }
};
template<>
struct ptype_treats<unsigned short>
struct ptype_traits<unsigned char> : ptype_traits_base<unsigned char>
{
static unsigned short cast(unsigned short x) { return x; }
static const bool is_signed = false;
static const char *size_specifier() { return "h"; }
};
template<>
struct ptype_treats<unsigned int>
struct ptype_traits<unsigned short> : ptype_traits_base<unsigned short>
{
static const char *size_specifier() { return "h"; }
};
template<>
struct ptype_traits<unsigned int> : ptype_traits_base<unsigned int>
{
static unsigned int cast(unsigned int x) { return x; }
static const bool is_signed = false;
static const char *size_specifier() { return ""; }
};
template<>
struct ptype_treats<unsigned long>
struct ptype_traits<unsigned long> : ptype_traits_base<unsigned long>
{
static unsigned long cast(unsigned long x) { return x; }
static const bool is_signed = false;
static const char *size_specifier() { return "l"; }
};
template<>
struct ptype_treats<unsigned long long>
struct ptype_traits<unsigned long long> : ptype_traits_base<unsigned long long>
{
static unsigned long long cast(unsigned long long x) { return x; }
static const bool is_signed = false;
static const char *size_specifier() { return "ll"; }
};
@ -127,29 +123,28 @@ public:
P &operator ()(char *x, const char *f = "") { format_element(f, "", "s", x); return static_cast<P &>(*this); }
P &operator ()(const void *x, const char *f = "") { format_element(f, "", "p", x); return static_cast<P &>(*this); }
P &operator ()(const pstring &x, const char *f = "") { format_element(f, "", "s", x.cstr() ); return static_cast<P &>(*this); }
P &operator ()(const pstring_t<putf8_traits> &x, const char *f = "") { format_element(f, "", "s", x.cstr() ); return static_cast<P &>(*this); }
template<typename T>
P &operator ()(const T x, const char *f = "")
{
if (ptype_treats<T>::is_signed)
format_element(f, ptype_treats<T>::size_specifier(), "d", ptype_treats<T>::cast(x));
if (ptype_traits<T>::is_signed)
format_element(f, ptype_traits<T>::size_specifier(), "d", ptype_traits<T>::cast(x));
else
format_element(f, ptype_treats<T>::size_specifier(), "u", ptype_treats<T>::cast(x));
format_element(f, ptype_traits<T>::size_specifier(), "u", ptype_traits<T>::cast(x));
return static_cast<P &>(*this);
}
template<typename T>
P &x(const T x, const char *f = "")
{
format_element(f, ptype_treats<T>::size_specifier(), "x", x);
format_element(f, ptype_traits<T>::size_specifier(), "x", x);
return static_cast<P &>(*this);
}
template<typename T>
P &o(const T x, const char *f = "")
{
format_element(f, ptype_treats<T>::size_specifier(), "o", x);
format_element(f, ptype_traits<T>::size_specifier(), "o", x);
return static_cast<P &>(*this);
}

View File

@ -17,11 +17,6 @@
#include "palloc.h"
#include "plists.h"
template<>
pstr_t pstring_t<putf8_traits>::m_zero = pstr_t(0);
template<>
pstr_t pstring_t<pu8_traits>::m_zero = pstr_t(0);
template<typename F>
pstring_t<F>::~pstring_t()
{
@ -528,3 +523,7 @@ void pstring_t<F>::resetmem()
template struct pstring_t<pu8_traits>;
template struct pstring_t<putf8_traits>;
const unsigned pu8_traits::MAXCODELEN;
const unsigned putf8_traits::MAXCODELEN;
const int pstringbuffer::DEFAULT_SIZE;

View File

@ -20,27 +20,27 @@
// It uses reference counts and only uses new memory when a string changes.
// ----------------------------------------------------------------------------------------
struct pstr_t
struct pstr_t
{
//str_t() : m_ref_count(1), m_len(0) { m_str[0] = 0; }
pstr_t(const std::size_t alen)
{
//str_t() : m_ref_count(1), m_len(0) { m_str[0] = 0; }
pstr_t(const std::size_t alen)
{
init(alen);
}
void init(const std::size_t alen)
{
m_ref_count = 1;
m_len = alen;
m_str[0] = 0;
}
char *str() { return &m_str[0]; }
unsigned char *ustr() { return reinterpret_cast<unsigned char *>(&m_str[0]); }
std::size_t len() const { return m_len; }
int m_ref_count;
private:
std::size_t m_len;
char m_str[1];
};
init(alen);
}
void init(const std::size_t alen)
{
m_ref_count = 1;
m_len = alen;
m_str[0] = 0;
}
char *str() { return &m_str[0]; }
unsigned char *ustr() { return reinterpret_cast<unsigned char *>(&m_str[0]); }
std::size_t len() const { return m_len; }
int m_ref_count;
private:
std::size_t m_len;
char m_str[1];
};
template <typename F>
@ -61,9 +61,9 @@ public:
~pstring_t();
// construction with copy
pstring_t(const mem_t *string) {init(); if (string != nullptr && *string != 0) pcopy(string); }
pstring_t(const pstring_t &string) {init(); pcopy(string); }
pstring_t(pstring_t &&string) : m_ptr(string.m_ptr) {string.m_ptr = nullptr; }
pstring_t(const mem_t *string) { init(); if (string != nullptr && *string != 0) pcopy(string); }
pstring_t(const pstring_t &string) { init(); pcopy(string); }
pstring_t(pstring_t &&string) : m_ptr(string.m_ptr) { string.m_ptr = nullptr; }
// assignment operators
pstring_t &operator=(const mem_t *string) { pcopy(string); return *this; }
@ -77,11 +77,11 @@ public:
iterator(const iterator &rhs) noexcept = default;
iterator(iterator &&rhs) noexcept { p = rhs.p; }
iterator &operator=(const iterator &it) { p = it.p; return *this; }
iterator& operator++() noexcept {p += traits::codelen(p); return *this;}
iterator operator++(int) noexcept {iterator tmp(*this); operator++(); return tmp;}
bool operator==(const iterator& rhs) noexcept {return p==rhs.p;}
bool operator!=(const iterator& rhs) noexcept {return p!=rhs.p;}
const code_t operator*() noexcept {return traits::code(p);}
iterator& operator++() noexcept { p += traits::codelen(p); return *this; }
iterator operator++(int) noexcept { iterator tmp(*this); operator++(); return tmp; }
bool operator==(const iterator& rhs) noexcept { return p==rhs.p; }
bool operator!=(const iterator& rhs) noexcept { return p!=rhs.p; }
const code_t operator*() noexcept { return traits::code(p); }
iterator& operator+=(size_type count) { while (count>0) { --count; ++(*this); } return *this; }
friend iterator operator+(iterator lhs, const size_type &rhs) { return (lhs += rhs); }
};
@ -154,7 +154,7 @@ public:
const pstring_t substr(const iterator start, const iterator end) const ;
const pstring_t substr(const iterator start) const { return substr(start, end()); }
const pstring_t substr(size_type start) const { if (start>=len()) return pstring_t(""); else return substr(begin() + start, end()); }
const pstring_t substr(size_type start) const { return (start >= len()) ? pstring_t("") : substr(begin() + start, end()); }
const pstring_t left(iterator leftof) const { return substr(begin(), leftof); }
const pstring_t right(iterator pos) const { return substr(pos, end()); }
@ -175,7 +175,6 @@ public:
static void resetmem();
protected:
pstr_t *m_ptr;
private:
@ -209,6 +208,8 @@ private:
static pstr_t m_zero;
};
template <typename F> pstr_t pstring_t<F>::m_zero(0);
struct pu8_traits
{
static const unsigned MAXCODELEN = 1; /* in memory units */
@ -317,21 +318,10 @@ struct putf8_traits
}
};
// FIXME: "using pstring = pstring_t<putf8_traits>" is not understood by eclipse
extern template struct pstring_t<pu8_traits>;
extern template struct pstring_t<putf8_traits>;
struct pstring : public pstring_t<putf8_traits>
{
public:
typedef pstring_t<putf8_traits> type_t;
// simple construction/destruction
pstring() : type_t() { }
// construction with copy
pstring(const mem_t *string) : type_t(string) { }
pstring(const type_t &string) : type_t(string) { }
};
typedef pstring_t<putf8_traits> pstring;
// ----------------------------------------------------------------------------------------
// pstringbuffer: a string buffer implementation

View File

@ -328,6 +328,7 @@ Game on cart IC22# # of SOP56 IC3
----------------------------------------------------------------------------------------------------------------------------------
Club Kart: European Session (2003, prototype) no cart * 21 (64Mb) present 315-6206 not present * instead of EPROM have tiny PCB with 2 flashroms on it
Crackin' DJ part 2 840-0068C 23674 20 (64Mb) present 315-6206 317-0311-COM PCB have label 840-0068B-01 837-14124, requires regular 837-13551 and 837-13938 rotary JVS boards, and turntable simulation
Crazy Taxi 840-0002C ? 13 (64Mb) ? 315-6206 ? not dumped, likely same as regular 171-7919A cart
Ferrari F355 Challenge (twin/deluxe, prototype) no cart 22848P* 21 (64Mb) present 315-6206 317-0267-COM * flash-PCB have CRC 330B A417, the rest is the same as regular cart, not dumped but known to exist
/Ferrari F355 Challenge 2 - International
\Course Edition (twin/deluxe, prototype) no cart 23399 21 (64Mb) present 315-6206 317-0287-COM content is the same as regular 171-7919A cart
@ -7923,7 +7924,7 @@ ROM_START( lupinsho )
DISK_IMAGE_READONLY( "gds-0018", 0, BAD_DUMP SHA1(0633a99a666f363ab30450a76b9753685d6b1f57) )
ROM_REGION( 0x4000, "pic", ROMREGION_ERASEFF)
ROM_LOAD("317-0332-jpn.pic", 0x00, 0x4000, CRC(f71cb2fc) SHA1(281b3b3b03edf9a39e380976de528b7c9674de53) )
ROM_LOAD("317-0325-jpn.pic", 0x00, 0x4000, CRC(f71cb2fc) SHA1(281b3b3b03edf9a39e380976de528b7c9674de53) )
ROM_END
ROM_START( vathlete )
@ -8087,13 +8088,12 @@ ROM_START( puyofev )
ROM_END
/*
note:
both Dragon Treasure game binaries have only first 16MB encrypted using DES key from security PIC provided with GD-ROMs.
the rest of data encrypted using some other key, same in both game versions.
presumably this data uploaded via network to satellite units and decrypted using DES key from their own security PICs.
Dragon Treasure 2 and 3 game binaries have only first 16MB encrypted using key from main unit security PIC.
data starting from 0x1000000 uploaded via network to satellite units and later decrypted using keys from satellite security PICs.
Dragon Treasure 2 binary also contain DIMM firmware updater ver 3.13 at 0x19000000
*/
// requires 837-14381 "G2 EXPANSION BD" I/O board
// requires 837-14381 "G2 EXPANSION BD" I/O board, NetDIMM, IC Card reader (unknown model) and coin mechanics
ROM_START( dragntr2 )
NAOMIGD_BIOS
NAOMI_DEFAULT_EEPROM
@ -8102,11 +8102,15 @@ ROM_START( dragntr2 )
DISK_IMAGE_READONLY( "gds-0037a", 0, SHA1(ce65fe84cabaa1ac3f40bff9535a42c2055b5f1c) )
ROM_REGION( 0x4000, "pic", ROMREGION_ERASEFF)
//PIC is missing
ROM_LOAD("317-xxxx-xxx.pic", 0x00, 0x4000, NO_DUMP )
//PIC16C621A (317-0389-COM)
ROM_LOAD("317-0389-com.pic", 0x00, 0x4000, CRC(35c511f9) SHA1(13073d6076d8b771f52a9cf461ed335471762574) )
ROM_REGION( 0x4000, "satl_pic", ROMREGION_ERASEFF)
//PIC16C621A (317-0390-COM)
ROM_LOAD("317-0390-com.pic", 0x00, 0x4000, CRC(92183b60) SHA1(1345a35ee4a3a02acc060f69d4faec5b72b7894b) )
ROM_END
// requires 837-14381 "G2 EXPANSION BD" I/O board
// requires 837-14381 "G2 EXPANSION BD" I/O board, NetDIMM, IC Card reader (unknown model) and coin mechanics
ROM_START( dragntr3 )
NAOMIGD_BIOS
NAOMI_DEFAULT_EEPROM
@ -8117,7 +8121,11 @@ ROM_START( dragntr3 )
ROM_REGION( 0x4000, "pic", ROMREGION_ERASEFF)
//PIC16F628A
// copy, original labels unknown
ROM_LOAD("317-xxxx-xxx.pic", 0x00, 0x4000, CRC(8df4d33a) SHA1(0d27ec46a64af60b1e46ad4b3d34b6df5448f81a) )
ROM_LOAD("317-xxxx-com.pic", 0x00, 0x4000, CRC(8df4d33a) SHA1(0d27ec46a64af60b1e46ad4b3d34b6df5448f81a) )
ROM_REGION(0x4000, "satl_pic", ROMREGION_ERASEFF)
//PIC16C621A (317-0390-COM)
ROM_LOAD("317-0390-com.pic", 0x00, 0x4000, CRC(92183b60) SHA1(1345a35ee4a3a02acc060f69d4faec5b72b7894b) )
ROM_END
ROM_START( ndcfboxa )
@ -8881,8 +8889,8 @@ ROM_START( wccf116 )
DISK_IMAGE_READONLY( "cdp-10001c", 0, SHA1(efa6ef20f278c99efbf7c3630b1c8e2cad0a05c0) ) // CD-R
ROM_REGION( 0x4000, "pic", ROMREGION_ERASEFF)
//PIC is missing
ROM_LOAD("wccf1.pic", 0x00, 0x4000, NO_DUMP )
//PIC16C621A (317-0329-JPN)
ROM_LOAD("317-0329-jpn.pic", 0x00, 0x4000, CRC(097f5f92) SHA1(ffe7df06007bd99908db15c300dd53bbd321bdb8) )
ROM_END
ROM_START( wccf1dup )
@ -8893,8 +8901,8 @@ ROM_START( wccf1dup )
DISK_IMAGE_READONLY( "cdp-10003", 0, SHA1(13064b6e03527f1222b6bd01c0ba9a063d7be949) )
ROM_REGION( 0x4000, "pic", ROMREGION_ERASEFF)
//PIC is missing, same as CDP-10001C
ROM_LOAD("wccf1.pic", 0x00, 0x4000, NO_DUMP )
//PIC16C621A (317-0329-JPN)
ROM_LOAD("317-0329-jpn.pic", 0x00, 0x4000, CRC(097f5f92) SHA1(ffe7df06007bd99908db15c300dd53bbd321bdb8) )
ROM_END
ROM_START( wccf212e )