diff --git a/emulator/CMakeLists.txt b/emulator/CMakeLists.txt
index 95dd157..2ca4b44 100644
--- a/emulator/CMakeLists.txt
+++ b/emulator/CMakeLists.txt
@@ -6,6 +6,7 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_subdirectory(emubase)
+add_subdirectory(util)
find_package(Qt5 REQUIRED COMPONENTS Widgets LinguistTools Script Multimedia Test)
@@ -16,7 +17,6 @@ set(CMAKE_AUTORCC ON)
set(PROJECT_SOURCES
main.cpp
mainwindow.cpp
- util/WavPcmFile.cpp
Common.cpp
Emulator.cpp
qscreen.cpp
@@ -34,7 +34,6 @@ set(PROJECT_SOURCES
set(PROJECT_HEADERS
mainwindow.h
stdafx.h
- util/WavPcmFile.h
Common.h
Emulator.h
qscreen.h
@@ -65,7 +64,7 @@ add_executable(QtUkncBtl
)
target_include_directories(QtUkncBtl PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
-target_link_libraries(QtUkncBtl PRIVATE emubase Qt5::Widgets Qt5::Script Qt5::Multimedia Qt5::Test)
+target_link_libraries(QtUkncBtl PRIVATE emubase util Qt5::Widgets Qt5::Script Qt5::Multimedia Qt5::Test)
set_target_properties(QtUkncBtl PROPERTIES
${BUNDLE_ID_OPTION}
diff --git a/emulator/util/CMakeLists.txt b/emulator/util/CMakeLists.txt
new file mode 100644
index 0000000..45c229c
--- /dev/null
+++ b/emulator/util/CMakeLists.txt
@@ -0,0 +1,22 @@
+cmake_minimum_required(VERSION 3.16)
+
+project(util LANGUAGES CXX)
+
+set(CMAKE_CXX_STANDARD 17)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+
+set(UTIL_SOURCES
+ WavPcmFile.cpp
+)
+
+set(UTIL_HEADERS
+ stdafx.h
+ WavPcmFile.h
+)
+
+add_library(util STATIC
+ ${UTIL_SOURCES}
+ ${UTIL_HEADERS}
+)
+
+target_compile_definitions(util PRIVATE EMUBASE_LIBRARY)
diff --git a/emulator/util/WavPcmFile.cpp b/emulator/util/WavPcmFile.cpp
index 23bd023..96123bc 100644
--- a/emulator/util/WavPcmFile.cpp
+++ b/emulator/util/WavPcmFile.cpp
@@ -33,9 +33,9 @@ struct WAVPCMFILE
int nBitsPerSample;
int nSampleFrequency;
int nBlockAlign;
- quint32 dwDataOffset;
- quint32 dwDataSize;
- quint32 dwCurrentPosition;
+ uint32_t dwDataOffset;
+ uint32_t dwDataSize;
+ uint32_t dwCurrentPosition;
bool okWriting;
};
@@ -49,7 +49,7 @@ int WavPcmFile_GetFrequency(HWAVPCMFILE wavpcmfile)
return pWavPcm->nSampleFrequency;
}
-quint32 WavPcmFile_GetLength(HWAVPCMFILE wavpcmfile)
+uint32_t WavPcmFile_GetLength(HWAVPCMFILE wavpcmfile)
{
if (wavpcmfile == INVALID_HANDLE_VALUE)
return 0;
@@ -59,7 +59,7 @@ quint32 WavPcmFile_GetLength(HWAVPCMFILE wavpcmfile)
return pWavPcm->dwDataSize / pWavPcm->nBlockAlign;
}
-quint32 WavPcmFile_GetPosition(HWAVPCMFILE wavpcmfile)
+uint32_t WavPcmFile_GetPosition(HWAVPCMFILE wavpcmfile)
{
if (wavpcmfile == INVALID_HANDLE_VALUE)
return 0;
@@ -69,14 +69,14 @@ quint32 WavPcmFile_GetPosition(HWAVPCMFILE wavpcmfile)
return pWavPcm->dwCurrentPosition;
}
-void WavPcmFile_SetPosition(HWAVPCMFILE wavpcmfile, quint32 position)
+void WavPcmFile_SetPosition(HWAVPCMFILE wavpcmfile, uint32_t position)
{
if (wavpcmfile == INVALID_HANDLE_VALUE)
return;
WAVPCMFILE* pWavPcm = (WAVPCMFILE*) wavpcmfile;
- quint32 offsetInData = position * pWavPcm->nBlockAlign;
+ uint32_t offsetInData = position * pWavPcm->nBlockAlign;
::fseek(pWavPcm->fpFile, pWavPcm->dwDataOffset + offsetInData, SEEK_SET);
pWavPcm->dwCurrentPosition = position;
@@ -93,7 +93,7 @@ HWAVPCMFILE WavPcmFile_Create(LPCTSTR filename, int sampleRate)
return (HWAVPCMFILE) INVALID_HANDLE_VALUE; // Failed to create file
// Prepare and write file header
- quint8 consolidated_header[12 + 8 + 16 + 8];
+ uint8_t consolidated_header[12 + 8 + 16 + 8];
::memset(consolidated_header, 0, sizeof(consolidated_header));
size_t bytesWritten;
@@ -101,13 +101,13 @@ HWAVPCMFILE WavPcmFile_Create(LPCTSTR filename, int sampleRate)
memcpy(&consolidated_header[8], magic2, 4); // WAVE
memcpy(&consolidated_header[12], format_tag_id, 4); // fmt
- *((quint32*)(consolidated_header + 16)) = 16; // Size of "fmt" chunk
- *((quint16*)(consolidated_header + 20)) = WAV_FORMAT_PCM; // AudioFormat = PCM
- *((quint16*)(consolidated_header + 22)) = channels; // NumChannels = mono
- *((quint32*)(consolidated_header + 24)) = sampleRate; // SampleRate
- *((quint32*)(consolidated_header + 28)) = sampleRate * channels * bitsPerSample / 8; // ByteRate
- *((quint16*)(consolidated_header + 32)) = blockAlign;
- *((quint16*)(consolidated_header + 34)) = bitsPerSample;
+ *((uint32_t*)(consolidated_header + 16)) = 16; // Size of "fmt" chunk
+ *((uint16_t*)(consolidated_header + 20)) = WAV_FORMAT_PCM; // AudioFormat = PCM
+ *((uint16_t*)(consolidated_header + 22)) = channels; // NumChannels = mono
+ *((uint32_t*)(consolidated_header + 24)) = sampleRate; // SampleRate
+ *((uint32_t*)(consolidated_header + 28)) = sampleRate * channels * bitsPerSample / 8; // ByteRate
+ *((uint16_t*)(consolidated_header + 32)) = blockAlign;
+ *((uint16_t*)(consolidated_header + 34)) = bitsPerSample;
memcpy(&consolidated_header[36], data_tag_id, 4); // data
@@ -146,13 +146,13 @@ HWAVPCMFILE WavPcmFile_Open(LPCTSTR filename)
if (fpFileOpen == nullptr)
return (HWAVPCMFILE) INVALID_HANDLE_VALUE; // Failed to open file
- quint32 offset = 0;
+ uint32_t offset = 0;
size_t bytesRead;
::fseek(fpFileOpen, 0, SEEK_END);
- quint32 fileSize = ::ftell(fpFileOpen);
+ long fileSize = ::ftell(fpFileOpen);
::fseek(fpFileOpen, 0, SEEK_SET);
- quint8 fileHeader[12];
+ uint8_t fileHeader[12];
bytesRead = ::fread(fileHeader, 1, sizeof(fileHeader), fpFileOpen);
if (bytesRead != sizeof(fileHeader) ||
memcmp(&fileHeader[0], magic1, 4) != 0 ||
@@ -161,17 +161,17 @@ HWAVPCMFILE WavPcmFile_Open(LPCTSTR filename)
::fclose(fpFileOpen);
return (HWAVPCMFILE) INVALID_HANDLE_VALUE; // Failed to read file header OR invalid 'RIFF' tag OR invalid 'WAVE' tag
}
- offset += (quint32)bytesRead;
+ offset += (uint32_t)bytesRead;
- quint32 statedSize = *((quint32*)(fileHeader + 4)) + 8;
+ long statedSize = *((uint32_t*)(fileHeader + 4)) + 8;
if (statedSize > fileSize)
statedSize = fileSize;
- quint8 tagHeader[8];
- quint16 formatTag[8];
+ uint8_t tagHeader[8];
+ uint16_t formatTag[8];
bool formatSpecified = false;
int formatType, channels = 1, bitsPerSample, blockAlign;
- quint32 sampleFrequency, bytesPerSecond, dataOffset, dataSize = 0;
+ uint32_t sampleFrequency, bytesPerSecond, dataOffset, dataSize = 0;
while (offset < statedSize)
{
bytesRead = ::fread(tagHeader, 1, sizeof(tagHeader), fpFileOpen);
@@ -180,9 +180,9 @@ HWAVPCMFILE WavPcmFile_Open(LPCTSTR filename)
::fclose(fpFileOpen);
return (HWAVPCMFILE) INVALID_HANDLE_VALUE; // Failed to read tag header
}
- offset += (quint32)bytesRead;
+ offset += (uint32_t)bytesRead;
- quint32 tagSize = *(quint32*)(tagHeader + 4);
+ uint32_t tagSize = *(uint32_t*)(tagHeader + 4);
if (!memcmp(tagHeader, format_tag_id, 4))
{
if (formatSpecified || tagSize < sizeof(formatTag))
@@ -270,7 +270,7 @@ void WavPcmFile_Close(HWAVPCMFILE wavpcmfile)
size_t bytesWritten;
// Write data chunk size
::fseek(pWavPcm->fpFile, 4, SEEK_SET);
- quint32 chunkSize = 36 + pWavPcm->dwDataSize;
+ uint32_t chunkSize = 36 + pWavPcm->dwDataSize;
bytesWritten = ::fwrite(&chunkSize, 1, 4, pWavPcm->fpFile);
// Write data subchunk size
::fseek(pWavPcm->fpFile, 40, SEEK_SET);
@@ -293,7 +293,7 @@ bool WavPcmFile_WriteOne(HWAVPCMFILE wavpcmfile, unsigned int value)
ASSERT(pWavPcm->nBitsPerSample == 8);
ASSERT(pWavPcm->nChannels == 1);
- quint8 data = (value >> 24) & 0xff;
+ uint8_t data = (value >> 24) & 0xff;
size_t bytesWritten = ::fwrite(&data, 1, 1, pWavPcm->fpFile);
if (bytesWritten != 1)
@@ -315,9 +315,9 @@ unsigned int WavPcmFile_ReadOne(HWAVPCMFILE wavpcmfile)
return 0;
// Read one sample
- quint32 bytesToRead = pWavPcm->nBlockAlign;
+ uint32_t bytesToRead = pWavPcm->nBlockAlign;
size_t bytesRead;
- quint8 data[16];
+ uint8_t data[16];
bytesRead = ::fread(data, 1, bytesToRead, pWavPcm->fpFile);
if (bytesRead != bytesToRead)
return 0;
@@ -333,11 +333,11 @@ unsigned int WavPcmFile_ReadOne(HWAVPCMFILE wavpcmfile)
value = value << 24;
break;
case 16:
- value = *((quint16*)data);
+ value = *((uint16_t*)data);
value = value << 16;
break;
case 32:
- value = *((quint32*)data);
+ value = *((uint32_t*)data);
break;
}
diff --git a/emulator/util/WavPcmFile.h b/emulator/util/WavPcmFile.h
index 9a9a2a1..0b4281c 100644
--- a/emulator/util/WavPcmFile.h
+++ b/emulator/util/WavPcmFile.h
@@ -12,6 +12,8 @@ UKNCBTL. If not, see . */
#pragma once
+#include
+
//////////////////////////////////////////////////////////////////////
DECLARE_HANDLE(HWAVPCMFILE);
@@ -26,12 +28,12 @@ void WavPcmFile_Close(HWAVPCMFILE wavpcmfile);
// Samples per second, Hz
int WavPcmFile_GetFrequency(HWAVPCMFILE wavpcmfile);
// Length of the stream, in samples
-quint32 WavPcmFile_GetLength(HWAVPCMFILE wavpcmfile);
+uint32_t WavPcmFile_GetLength(HWAVPCMFILE wavpcmfile);
// Current position in the stream, in samples, zero-based
-quint32 WavPcmFile_GetPosition(HWAVPCMFILE wavpcmfile);
+uint32_t WavPcmFile_GetPosition(HWAVPCMFILE wavpcmfile);
// Set current position in the stream, in samples, zero-based
-void WavPcmFile_SetPosition(HWAVPCMFILE wavpcmfile, quint32 position);
+void WavPcmFile_SetPosition(HWAVPCMFILE wavpcmfile, uint32_t position);
// Read one sample scaled to int type range
unsigned int WavPcmFile_ReadOne(HWAVPCMFILE wavpcmfile);
diff --git a/emulator/util/stdafx.h b/emulator/util/stdafx.h
new file mode 100644
index 0000000..09a5e90
--- /dev/null
+++ b/emulator/util/stdafx.h
@@ -0,0 +1,71 @@
+// stdafx.h : include file for standard system include files,
+// or project specific include files that are used frequently, but
+// are changed infrequently
+//
+
+#pragma once
+
+#include
+#include
+#include
+#include
+#include
+
+#ifndef CALLBACK
+# define CALLBACK
+#endif // CALLBACK
+
+#ifndef TCHAR
+typedef char TCHAR;
+#define _tfopen fopen
+#define _tcscpy strcpy
+#define _tstat _stat
+#define _tcsrchr strrchr
+#define _tcsicmp strcasecmp
+#define _tcscmp strcmp
+#define _tcslen strlen
+#define _sntprintf _snprintf
+#define _snprintf snprintf
+#endif // TCHAR
+
+#ifndef _T
+# define _T(str) (str)
+#endif // _T
+
+#ifndef LPTSTR
+typedef TCHAR* LPTSTR;
+#endif // LCTSTR
+
+#ifndef LPCTSTR
+typedef const TCHAR* LPCTSTR;
+#endif // LPCTSTR
+
+#ifndef ASSERT
+# define ASSERT(expr) assert(expr)
+#endif // ASSERT
+
+#ifndef MAKEWORD
+# define MAKEWORD(a, b) ((uint16_t)(((uint8_t)(((uint32_t)(a)) & 0xff)) | ((uint16_t)((uint8_t)(((uint32_t)(b)) & 0xff))) << 8))
+#endif // MAKEWORD
+
+#ifndef HANDLE
+typedef void *HANDLE;
+#endif // HANDLE
+
+#ifndef DECLARE_HANDLE
+# define DECLARE_HANDLE(name) struct name##__ { int unused; }; typedef struct name##__ *name
+#endif // DECLARE_HANDLE
+
+#ifndef INVALID_HANDLE_VALUE
+# define INVALID_HANDLE_VALUE ((HANDLE)(int32_t)-1)
+#endif // INVALID_HANDLE_VALUE
+
+//////////////////////////////////////////////////////////////////////
+// DebugPrint
+
+void DebugPrint(const char* message);
+void DebugPrintFormat(const char* pszFormat, ...);
+void DebugLog(const char* message);
+void DebugLogFormat(const char* pszFormat, ...);
+
+void PrintOctalValue(char* buffer, uint16_t value);