summaryrefslogtreecommitdiff
path: root/plugins/sid/sidplay-libs/libsidplay/src/sidtune
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/sid/sidplay-libs/libsidplay/src/sidtune')
-rw-r--r--plugins/sid/sidplay-libs/libsidplay/src/sidtune/IconInfo.cpp34
-rw-r--r--plugins/sid/sidplay-libs/libsidplay/src/sidtune/InfoFile.cpp49
-rw-r--r--plugins/sid/sidplay-libs/libsidplay/src/sidtune/PSID.cpp2
-rw-r--r--plugins/sid/sidplay-libs/libsidplay/src/sidtune/SidTune.cpp56
-rw-r--r--plugins/sid/sidplay-libs/libsidplay/src/sidtune/SidTuneTools.cpp35
-rw-r--r--plugins/sid/sidplay-libs/libsidplay/src/sidtune/SidTuneTools.h9
6 files changed, 78 insertions, 107 deletions
diff --git a/plugins/sid/sidplay-libs/libsidplay/src/sidtune/IconInfo.cpp b/plugins/sid/sidplay-libs/libsidplay/src/sidtune/IconInfo.cpp
index 30df20b4..03faf1b4 100644
--- a/plugins/sid/sidplay-libs/libsidplay/src/sidtune/IconInfo.cpp
+++ b/plugins/sid/sidplay-libs/libsidplay/src/sidtune/IconInfo.cpp
@@ -37,7 +37,6 @@
# include <new>
#endif
#include <string.h>
-#include <sstream>
// Amiga Workbench specific structures.
@@ -359,12 +358,13 @@ bool SidTune::INFO_fileSupport(const void* dataBuffer, uint_least32_t dataLength
// Now check all possible keywords.
if ( SidTuneTools::myStrNcaseCmp(cmpBuf,_sidtune_keyword_address) == 0 )
{
- std::string s (cmpBuf + strlen(_sidtune_keyword_address), toolLen - strlen(_sidtune_keyword_address));
- std::istringstream addrIn(s);
- info.loadAddr = (uint_least16_t)SidTuneTools::readHex( addrIn );
- info.initAddr = (uint_least16_t)SidTuneTools::readHex( addrIn );
- info.playAddr = (uint_least16_t)SidTuneTools::readHex( addrIn );
- if ( !addrIn )
+ const char *addrIn= cmpBuf + strlen(_sidtune_keyword_address);
+ int len = toolLen - strlen(_sidtune_keyword_address);
+ int pos = 0;
+ info.loadAddr = (uint_least16_t)SidTuneTools::readHex( addrIn, len, pos );
+ info.initAddr = (uint_least16_t)SidTuneTools::readHex( addrIn, len, pos );
+ info.playAddr = (uint_least16_t)SidTuneTools::readHex( addrIn, len, pos );
+ if ( pos >= len )
{
return false;
}
@@ -372,25 +372,27 @@ bool SidTune::INFO_fileSupport(const void* dataBuffer, uint_least32_t dataLength
}
else if ( SidTuneTools::myStrNcaseCmp(cmpBuf,_sidtune_keyword_songs) == 0 )
{
- std::string s ( cmpBuf + strlen(_sidtune_keyword_songs), toolLen - strlen(_sidtune_keyword_songs));
- std::istringstream numIn(s);
- if ( !numIn )
+ const char *numIn = cmpBuf + strlen(_sidtune_keyword_songs);
+ int len = toolLen - strlen(_sidtune_keyword_songs);
+ int pos = 0;
+ if ( !pos >= len )
{
return false;
}
- info.songs = (uint_least16_t)SidTuneTools::readDec( numIn );
- info.startSong = (uint_least16_t)SidTuneTools::readDec( numIn );
+ info.songs = (uint_least16_t)SidTuneTools::readDec( numIn, len, pos );
+ info.startSong = (uint_least16_t)SidTuneTools::readDec( numIn, len, pos );
hasSongs = true;
}
else if ( SidTuneTools::myStrNcaseCmp(cmpBuf,_sidtune_keyword_speed) == 0 )
{
- std::string s (cmpBuf + strlen(_sidtune_keyword_speed), toolLen - strlen(_sidtune_keyword_speed));
- std::istringstream speedIn (s);
- if ( !speedIn )
+ const char *speedIn = cmpBuf + strlen(_sidtune_keyword_speed);
+ int len = toolLen - strlen(_sidtune_keyword_speed);
+ int pos = 0;
+ if ( pos >= len )
{
return false;
}
- oldStyleSpeed = SidTuneTools::readHex(speedIn);
+ oldStyleSpeed = SidTuneTools::readHex(speedIn, len, pos);
hasSpeed = true;
}
else if ( SidTuneTools::myStrNcaseCmp(cmpBuf,_sidtune_keyword_name) == 0 )
diff --git a/plugins/sid/sidplay-libs/libsidplay/src/sidtune/InfoFile.cpp b/plugins/sid/sidplay-libs/libsidplay/src/sidtune/InfoFile.cpp
index 0c03b23c..6ddb77f5 100644
--- a/plugins/sid/sidplay-libs/libsidplay/src/sidtune/InfoFile.cpp
+++ b/plugins/sid/sidplay-libs/libsidplay/src/sidtune/InfoFile.cpp
@@ -23,9 +23,6 @@
#ifdef HAVE_EXCEPTIONS
# include <new>
#endif
-#include <iostream>
-#include <iomanip>
-#include <sstream>
#include <ctype.h>
#include <string.h>
@@ -135,35 +132,27 @@ bool SidTune::SID_fileSupport(const void* dataBuffer, uint_least32_t dataBufLen,
}
// Create whitespace eating (!) input string stream.
- std::string s (pParseBuf, restLen);
-
- std::istringstream parseStream (s);
- // A second one just for copying.
- std::istringstream parseCopyStream (s);
- if ( !parseStream || !parseCopyStream )
- {
- break;
- }
+ const char *s = pParseBuf;
+ int pos = 0;
+ int posCopy = 0;
// Now copy the next X characters except white-spaces.
for ( uint_least16_t i = 0; i < parseChunkLen; i++ )
{
- char c;
- parseCopyStream >> c;
- pParseChunk[i] = c;
+ pParseChunk[i] = s[i];
}
pParseChunk[parseChunkLen]=0;
// Now check for the possible keywords.
// ADDRESS
if ( SidTuneTools::myStrNcaseCmp( pParseChunk, keyword_address ) == 0 )
{
- SidTuneTools::skipToEqu( parseStream );
- info.loadAddr = (uint_least16_t)SidTuneTools::readHex( parseStream );
- if ( !parseStream )
+ SidTuneTools::skipToEqu( s, restLen, pos );
+ info.loadAddr = (uint_least16_t)SidTuneTools::readHex( s, restLen, pos );
+ if ( pos>=restLen )
break;
- info.initAddr = (uint_least16_t)SidTuneTools::readHex( parseStream );
- if ( !parseStream )
+ info.initAddr = (uint_least16_t)SidTuneTools::readHex( s, restLen, pos );
+ if ( pos>=restLen )
break;
- info.playAddr = (uint_least16_t)SidTuneTools::readHex( parseStream );
+ info.playAddr = (uint_least16_t)SidTuneTools::readHex( s, restLen, pos );
hasAddress = true;
}
// NAME
@@ -197,16 +186,16 @@ bool SidTune::SID_fileSupport(const void* dataBuffer, uint_least32_t dataBufLen,
// SONGS
else if ( SidTuneTools::myStrNcaseCmp( pParseChunk, keyword_songs ) == 0 )
{
- SidTuneTools::skipToEqu( parseStream );
- info.songs = (uint_least16_t)SidTuneTools::readDec( parseStream );
- info.startSong = (uint_least16_t)SidTuneTools::readDec( parseStream );
+ SidTuneTools::skipToEqu( s, restLen, pos );
+ info.songs = (uint_least16_t)SidTuneTools::readDec( s, restLen, pos );
+ info.startSong = (uint_least16_t)SidTuneTools::readDec( s, restLen, pos );
hasSongs = true;
}
// SPEED
else if ( SidTuneTools::myStrNcaseCmp( pParseChunk, keyword_speed ) == 0 )
{
- SidTuneTools::skipToEqu( parseStream );
- oldStyleSpeed = SidTuneTools::readHex(parseStream);
+ SidTuneTools::skipToEqu( s, restLen, pos );
+ oldStyleSpeed = SidTuneTools::readHex( s, restLen, pos );
hasSpeed = true;
}
// SIDSONG
@@ -217,10 +206,10 @@ bool SidTune::SID_fileSupport(const void* dataBuffer, uint_least32_t dataBufLen,
// RELOC
else if ( SidTuneTools::myStrNcaseCmp( pParseChunk, keyword_reloc ) == 0 )
{
- info.relocStartPage = (uint_least8_t)SidTuneTools::readHex( parseStream );
- if ( !parseStream )
+ info.relocStartPage = (uint_least8_t)SidTuneTools::readHex( s, restLen, pos );
+ if ( pos >= restLen )
break;
- info.relocPages = (uint_least8_t)SidTuneTools::readHex( parseStream );
+ info.relocPages = (uint_least8_t)SidTuneTools::readHex( s, restLen, pos );
}
// CLOCK
else if ( SidTuneTools::myStrNcaseCmp( pParseChunk, keyword_clock ) == 0 )
@@ -307,6 +296,7 @@ bool SidTune::SID_fileSupport(const void* dataBuffer, uint_least32_t dataBufLen,
}
+#if 0
bool SidTune::SID_fileSupportSave( std::ofstream& toFile )
{
toFile << keyword_id << std::endl
@@ -396,3 +386,4 @@ bool SidTune::SID_fileSupportSave( std::ofstream& toFile )
return true;
}
}
+#endif
diff --git a/plugins/sid/sidplay-libs/libsidplay/src/sidtune/PSID.cpp b/plugins/sid/sidplay-libs/libsidplay/src/sidtune/PSID.cpp
index 0cc96969..a6322c36 100644
--- a/plugins/sid/sidplay-libs/libsidplay/src/sidtune/PSID.cpp
+++ b/plugins/sid/sidplay-libs/libsidplay/src/sidtune/PSID.cpp
@@ -242,6 +242,7 @@ bool SidTune::PSID_fileSupport(const void* buffer, const uint_least32_t bufLen)
}
+#if 0
bool SidTune::PSID_fileSupportSave(std::ofstream& fMyOut, const uint_least8_t* dataBuffer)
{
psidHeader myHeader;
@@ -311,3 +312,4 @@ bool SidTune::PSID_fileSupportSave(std::ofstream& fMyOut, const uint_least8_t* d
else
return true;
}
+#endif
diff --git a/plugins/sid/sidplay-libs/libsidplay/src/sidtune/SidTune.cpp b/plugins/sid/sidplay-libs/libsidplay/src/sidtune/SidTune.cpp
index 29638775..4dfba1d7 100644
--- a/plugins/sid/sidplay-libs/libsidplay/src/sidtune/SidTune.cpp
+++ b/plugins/sid/sidplay-libs/libsidplay/src/sidtune/SidTune.cpp
@@ -24,12 +24,11 @@
#include "SidTuneTools.h"
#include "sidendian.h"
#include "PP20.h"
+#include <stdio.h>
#ifdef HAVE_EXCEPTIONS
# include <new>
#endif
-#include <iostream>
-#include <iomanip>
#include <string.h>
#include <limits.h>
@@ -100,6 +99,7 @@ inline void SidTune::setFileNameExtensions(const char **fileNameExt)
{
fileNameExtensions = ((fileNameExt!=0)?fileNameExt:defaultFileNameExt);
}
+#define SIDTUNE_NO_STDIN_LOADER
SidTune::SidTune(const char* fileName, const char **fileNameExt,
const bool separatorIsSlash)
@@ -252,39 +252,18 @@ bool SidTune::loadFile(const char* fileName, Buffer_sidtt<const uint_least8_t>&
Buffer_sidtt<uint_least8_t> fileBuf;
uint_least32_t fileLen = 0;
- // This sucks big time
- //openmode createAtrr = std::ios::in;
- std::_Ios_Openmode createAtrr = std::ios::in;
-#ifdef HAVE_IOS_NOCREATE
- createAtrr |= std::ios::nocreate;
-#endif
- // Open binary input file stream at end of file.
-#if defined(HAVE_IOS_BIN)
- createAtrr |= std::ios::bin;
-#else
- createAtrr |= std::ios::binary;
-#endif
+ FILE *fp = fopen (fileName, "rb");
- std::fstream myIn(fileName,createAtrr);
- // As a replacement for !is_open(), bad() and the NOT-operator don't seem
- // to work on all systems.
-#if defined(DONT_HAVE_IS_OPEN)
- if ( !myIn )
-#else
- if ( !myIn.is_open() )
-#endif
+ if (!fp)
{
info.statusString = SidTune::txt_cantOpenFile;
return false;
}
else
{
-#if defined(HAVE_SEEKG_OFFSET)
- fileLen = (myIn.seekg(0,std::ios::end)).offset();
-#else
- myIn.seekg(0,std::ios::end);
- fileLen = (uint_least32_t)myIn.tellg();
-#endif
+ fseek (fp, 0, SEEK_END);
+ fileLen = ftell (fp);
+ rewind (fp);
#ifdef HAVE_EXCEPTIONS
if ( !fileBuf.assign(new(std::nothrow) uint_least8_t[fileLen],fileLen) )
#else
@@ -294,19 +273,9 @@ bool SidTune::loadFile(const char* fileName, Buffer_sidtt<const uint_least8_t>&
info.statusString = SidTune::txt_notEnoughMemory;
return false;
}
- myIn.seekg(0,std::ios::beg);
uint_least32_t restFileLen = fileLen;
- // 16-bit compatible loading. Is this really necessary?
- while ( restFileLen > INT_MAX )
- {
- myIn.read((char*)fileBuf.get()+(fileLen-restFileLen),INT_MAX); // !cast!
- restFileLen -= INT_MAX;
- }
- if ( restFileLen > 0 )
- {
- myIn.read((char*)fileBuf.get()+(fileLen-restFileLen),restFileLen); // !cast!
- }
- if ( myIn.bad() )
+ int res = fread((char*)fileBuf.get()+(fileLen-restFileLen),1,restFileLen,fp);
+ if ( res != restFileLen )
{
info.statusString = SidTune::txt_cantLoadFile;
return false;
@@ -316,7 +285,7 @@ bool SidTune::loadFile(const char* fileName, Buffer_sidtt<const uint_least8_t>&
info.statusString = SidTune::txt_noErrors;
}
}
- myIn.close();
+ fclose(fp);
if ( fileLen==0 )
{
info.statusString = SidTune::txt_empty;
@@ -443,6 +412,7 @@ void SidTune::cleanup()
status = false;
}
+#define SIDTUNE_NO_STDIN_LOADER
#if !defined(SIDTUNE_NO_STDIN_LOADER)
void SidTune::getFromStdIn()
@@ -839,7 +809,8 @@ void SidTune::convertOldStyleSpeedToTables(uint_least32_t speed, int clock)
//
// File format conversion ---------------------------------------------------
//
-
+
+#if 0
bool SidTune::saveToOpenFile(std::ofstream& toFile, const uint_least8_t* buffer,
uint_least32_t bufLen )
{
@@ -984,6 +955,7 @@ bool SidTune::savePSIDfile( const char* fileName, bool overWriteFlag )
}
return success;
}
+#endif
bool SidTune::checkRealC64Info (uint_least32_t speed)
{
diff --git a/plugins/sid/sidplay-libs/libsidplay/src/sidtune/SidTuneTools.cpp b/plugins/sid/sidplay-libs/libsidplay/src/sidtune/SidTuneTools.cpp
index 450795b9..6a100062 100644
--- a/plugins/sid/sidplay-libs/libsidplay/src/sidtune/SidTuneTools.cpp
+++ b/plugins/sid/sidplay-libs/libsidplay/src/sidtune/SidTuneTools.cpp
@@ -101,15 +101,16 @@ char* SidTuneTools::fileExtOfPath(char* s)
// Parse input string stream. Read and convert a hexa-decimal number up
// to a ``,'' or ``:'' or ``\0'' or end of stream.
-uint_least32_t SidTuneTools::readHex( std::istringstream& hexin )
+uint_least32_t SidTuneTools::readHex( const char *s, int size, int &pos)
{
uint_least32_t hexLong = 0;
char c;
do
{
- hexin >> c;
- if ( !hexin )
+ if (pos >= size) {
break;
+ }
+ c = s[pos++];
if (( c != ',') && ( c != ':' ) && ( c != 0 ))
{
// machine independed to_upper
@@ -120,25 +121,27 @@ uint_least32_t SidTuneTools::readHex( std::istringstream& hexin )
}
else
{
- if ( c == 0 )
- hexin.putback(c);
+ if ( c == 0 ) {
+ pos--;
+ }
break;
}
- } while ( hexin );
+ } while ( pos < size );
return hexLong;
}
// Parse input string stream. Read and convert a decimal number up
// to a ``,'' or ``:'' or ``\0'' or end of stream.
-uint_least32_t SidTuneTools::readDec( std::istringstream& decin )
+uint_least32_t SidTuneTools::readDec( const char *s, int size, int &pos )
{
uint_least32_t hexLong = 0;
char c;
do
{
- decin >> c;
- if ( !decin )
+ if (pos >= size) {
break;
+ }
+ c = s[pos++];
if (( c != ',') && ( c != ':' ) && ( c != 0 ))
{
c &= 0x0f;
@@ -147,11 +150,12 @@ uint_least32_t SidTuneTools::readDec( std::istringstream& decin )
}
else
{
- if ( c == 0 )
- decin.putback(c);
+ if ( c == 0 ) {
+ pos--;
+ }
break;
}
- } while ( decin );
+ } while ( pos < size);
return hexLong;
}
@@ -187,12 +191,15 @@ const char* SidTuneTools::returnNextLine(const char* s)
}
// Skip any characters in an input string stream up to '='.
-void SidTuneTools::skipToEqu( std::istringstream& parseStream )
+void SidTuneTools::skipToEqu( const char *s, int size, int &pos )
{
char c;
do
{
- parseStream >> c;
+ if (pos >= size) {
+ break;
+ }
+ c = s[pos++];
}
while ( c != '=' );
}
diff --git a/plugins/sid/sidplay-libs/libsidplay/src/sidtune/SidTuneTools.h b/plugins/sid/sidplay-libs/libsidplay/src/sidtune/SidTuneTools.h
index 5a06046b..7c3fabfa 100644
--- a/plugins/sid/sidplay-libs/libsidplay/src/sidtune/SidTuneTools.h
+++ b/plugins/sid/sidplay-libs/libsidplay/src/sidtune/SidTuneTools.h
@@ -26,8 +26,6 @@
#include <string.h>
-#include <sstream>
-
#define MYSTRICMP stricmp
#if defined(HAVE_STRCASECMP)
#undef MYSTRICMP
@@ -66,18 +64,17 @@ class SidTuneTools
// Parse input string stream. Read and convert a hexa-decimal number up
// to a ``,'' or ``:'' or ``\0'' or end of stream.
- static uint_least32_t readHex(std::istringstream& parseStream);
+ static uint_least32_t readHex(const char *parseStream, int size, int &pos);
// Parse input string stream. Read and convert a decimal number up
// to a ``,'' or ``:'' or ``\0'' or end of stream.
- static uint_least32_t readDec(std::istringstream& parseStream);
-
+ static uint_least32_t readDec(const char *parseStream, int size, int &pos);
// Search terminated string for next newline sequence.
// Skip it and return pointer to start of next line.
static const char* returnNextLine(const char* pBuffer);
// Skip any characters in an input string stream up to '='.
- static void skipToEqu(std::istringstream& parseStream);
+ static void skipToEqu(const char *parseStream, int size, int &pos);
// Start at first character behind '=' and copy rest of string.
static void copyStringValueToEOL(const char* pSourceStr, char* pDestStr, int destMaxLen);