Skip to content

Commit

Permalink
Move log and fileops (#100)
Browse files Browse the repository at this point in the history
Move Log to core and split Fileops
  • Loading branch information
petschau authored Oct 14, 2023
1 parent 6ae4fdc commit a5fc7cd
Show file tree
Hide file tree
Showing 73 changed files with 6,022 additions and 6,519 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ fellow/SRC/WinFellow/Windows/versioninfo.h
fellow/SRC/WinFellow/GUI_versioninfo.rc
**/Debug/
**/Release/
**/.vscode/
*.lyx~
fellow/doxygen/WinFellow-doxygen.*
fellow/doxygen/WinFellow-doxygen.pdf
Expand Down
3 changes: 0 additions & 3 deletions fellow/SRC/WinFellow.Core.Tests/WinFellow.Core.Tests.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,6 @@
<ClCompile Include="CustomChipset\RegistersUtilityTest.cpp" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\WinFellow.Core\WinFellow.Core.vcxproj">
<Project>{4de2d749-c890-4c60-847d-fed10c4dad40}</Project>
</ProjectReference>
<ProjectReference Include="..\WinFellow.Test.Infrastructure\WinFellow.Test.Infrastructure.vcxproj">
<Project>{04390558-960c-4acb-b98b-87a2047cd69d}</Project>
</ProjectReference>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,63 +1,60 @@
#pragma once

#include "DEFS.H"
#include <string>

class UART
{
private:
std::string _outputFileName;
FILE *_outputFile;

uint16_t _serper;

uint16_t _transmitBuffer;
uint16_t _transmitShiftRegister;
uint32_t _transmitDoneTime;
bool _transmitBufferEmpty;
bool _transmitShiftRegisterEmpty;

uint16_t _receiveBuffer;
uint16_t _receiveShiftRegister;
uint32_t _receiveDoneTime;
bool _receiveBufferFull;
bool _receiveBufferOverrun;

void InstallIOHandlers();

void ClearState();
void LoadState(FILE *F);
void SaveState(FILE *F);

void OpenOutputFile();
void CloseOutputFile();

bool Is8BitMode();
uint16_t GetBitPeriod();

void CopyReceiveShiftRegisterToBuffer();
void CopyTransmitBufferToShiftRegister();
uint32_t GetTransmitDoneTime();

public:
static void wserper(uint16_t data, uint32_t address);
static void wserdat(uint16_t data, uint32_t address);
static uint16_t rserdat(uint32_t address);

uint16_t ReadSerdatRegister();
void WriteSerdatRegister(uint16_t data);
void WriteSerperRegister(uint16_t data);

void NotifyInterruptRequestBitsChanged(uint16_t intreq);

void EndOfLine();
void EndOfFrame();

void EmulationStart();
void EmulationStop();

UART();
~UART();
};

extern UART uart;
#pragma once

#include <string>

class Uart
{
private:
std::string _outputFileName;
FILE *_outputFile;

uint16_t _serper;

uint16_t _transmitBuffer;
uint16_t _transmitShiftRegister;
uint32_t _transmitDoneTime;
bool _transmitBufferEmpty;
bool _transmitShiftRegisterEmpty;

uint16_t _receiveBuffer;
uint16_t _receiveShiftRegister;
uint32_t _receiveDoneTime;
bool _receiveBufferFull;
bool _receiveBufferOverrun;

void InstallIOHandlers();

void ClearState();
void LoadState(FILE *F);
void SaveState(FILE *F);

void OpenOutputFile();
void CloseOutputFile();

bool Is8BitMode();
uint16_t GetBitPeriod();

void CopyReceiveShiftRegisterToBuffer();
void CopyTransmitBufferToShiftRegister();
uint32_t GetTransmitDoneTime();

public:
static void wserper(uint16_t data, uint32_t address);
static void wserdat(uint16_t data, uint32_t address);
static uint16_t rserdat(uint32_t address);

uint16_t ReadSerdatRegister();
void WriteSerdatRegister(uint16_t data);
void WriteSerperRegister(uint16_t data);

void NotifyInterruptRequestBitsChanged(uint16_t intreq);

void EndOfLine();
void EndOfFrame();

void EmulationStart();
void EmulationStop();

Uart();
~Uart();
};
26 changes: 26 additions & 0 deletions fellow/SRC/WinFellow.Core/Service/IFileops.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once

#include <cstdint>

namespace Service
{
constexpr auto FILEOPS_MAX_FILE_PATH = 260;

class IFileops
{
public:

virtual bool GetFellowLogfileName(char*) = 0;
virtual bool GetGenericFileName(char*, const char*, const char*) = 0;
virtual bool GetDefaultConfigFileName(char*) = 0;
virtual bool ResolveVariables(const char*, char*) = 0;
virtual bool GetWinFellowPresetPath(char*, const uint32_t) = 0;
virtual bool GetScreenshotFileName(char*) = 0;
virtual char* GetTemporaryFilename() = 0;
virtual bool GetWinFellowInstallationPath(char*, const uint32_t) = 0;
virtual bool GetKickstartByCRC32(const char*, const uint32_t, char*, const uint32_t) = 0;

IFileops() = default;
virtual ~IFileops() = default;
};
}
19 changes: 19 additions & 0 deletions fellow/SRC/WinFellow.Core/Service/ILog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

#include <string>
#include <list>

namespace Service
{
class ILog
{
public:
virtual void AddLogDebug(const char* format, ...) = 0;
virtual void AddLog(const char*, ...) = 0;
virtual void AddLogList(const std::list<std::string>& messages) = 0;
virtual void AddLog2(char* msg) = 0;

ILog() = default;
virtual ~ILog() = default;
};
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
#include <time.h>
#include <cstdarg>
#include <string>
#include <list>
#include "fellow/service/Log.h"
#include "fileops.h"

#define WRITE_LOG_BUF_SIZE 512
#include "Service/Log.h"
#include "VirtualHost/Core.h"

constexpr auto WRITE_LOG_BUF_SIZE = 512;

using namespace std;

namespace fellow::service
namespace Service
{
Log::Log() :
_new_line(true), _first_time(true), _enabled(true),
_new_line(true), _first_time(true), _enabled(true),
#ifdef _DEBUG
_level(LogLevelDebug)
_level(LogLevelDebug)
#else
_level(LogLevelInformation)
_level(LogLevelInformation)
#endif
{
}

void Log::AddLogDebug(const char *format, ...)
Log::~Log() = default;

void Log::AddLogDebug(const char* format, ...)
{
if (!_enabled)
{
Expand All @@ -31,7 +35,7 @@ namespace fellow::service
{
va_list parms;
char buffer[WRITE_LOG_BUF_SIZE];
char *buffer2 = LogTime(buffer);
char* buffer2 = LogTime(buffer);

va_start(parms, format);
vsprintf_s(buffer2, WRITE_LOG_BUF_SIZE - 1 - strlen(buffer), format, parms);
Expand All @@ -45,7 +49,7 @@ namespace fellow::service
}
}

void Log::AddLog(const char *format, ...)
void Log::AddLog(const char* format, ...)
{
if (!_enabled)
{
Expand All @@ -54,7 +58,7 @@ namespace fellow::service

va_list parms;
char buffer[WRITE_LOG_BUF_SIZE];
char *buffer2 = LogTime(buffer);
char* buffer2 = LogTime(buffer);

va_start(parms, format);
vsprintf_s(buffer2, WRITE_LOG_BUF_SIZE - 1 - strlen(buffer), format, parms);
Expand All @@ -66,7 +70,7 @@ namespace fellow::service
}
va_end(parms);
}

void Log::AddLogList(const list<string>& messages)
{
if (!_enabled)
Expand All @@ -87,28 +91,28 @@ namespace fellow::service
CloseLogFile(F);
}

void Log::AddLog2(char *msg)
void Log::AddLog2(char* msg)
{
if (!_enabled)
{
return;
}

FILE *F = OpenLogFile();
FILE* F = OpenLogFile();
if (F != nullptr)
{
AddLogInternal(F, msg);
CloseLogFile(F);
}
}

void Log::AddLogInternal(FILE *F, char* msg)
void Log::AddLogInternal(FILE* F, char* msg)
{
fprintf(F, "%s", msg);
_new_line = (msg[strlen(msg) - 1] == '\n');
}

char *Log::LogTime(char* buffer)
char* Log::LogTime(char* buffer)
{
if (_new_line)
{
Expand All @@ -132,8 +136,8 @@ namespace fellow::service

if (_first_time)
{
char logfilename[MAX_PATH];
fileopsGetFellowLogfileName(logfilename);
char logfilename[FILEOPS_MAX_FILE_PATH];
_core.Fileops->GetFellowLogfileName(logfilename);
_logfilename = logfilename;
fopen_s(&F, _logfilename.c_str(), "w");
_first_time = false;
Expand All @@ -145,7 +149,7 @@ namespace fellow::service
return F;
}

void Log::CloseLogFile(FILE *F)
void Log::CloseLogFile(FILE* F)
{
fflush(F);
fclose(F);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#pragma once

#include <string>
#include "fellow/api/service/ILog.h"
#include "ILog.h"

namespace fellow::service
{
class Log : public fellow::api::service::ILog
namespace Service
{
class Log : public ILog
{
private:
static const unsigned int LogLevelError = 0;
Expand All @@ -24,11 +23,12 @@ namespace fellow::service
void AddLogInternal(FILE* F, char* msg);

public:
void AddLogDebug(const char *format, ...) override;
void AddLog(const char *, ...) override;
void AddLogList(const std::list<std::string>& messages) override;
void AddLog2(char *msg) override ;
void AddLogDebug(const char* format, ...);
void AddLog(const char*, ...);
void AddLogList(const std::list<std::string>& messages);
void AddLog2(char* msg);

Log();
virtual ~Log();
};
}
2 changes: 1 addition & 1 deletion fellow/SRC/WinFellow.Core/VirtualHost/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// For the time being this has to be a singleton
Core _core = Core();

Core::Core() : Registers(), RegisterUtility(Registers), Drivers()
Core::Core() : Registers(), RegisterUtility(Registers), Sound(nullptr), Uart(nullptr), Drivers(), Log(nullptr), Fileops(nullptr)
{
}

Expand Down
10 changes: 8 additions & 2 deletions fellow/SRC/WinFellow.Core/VirtualHost/Core.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
#pragma once

#include "Driver/Drivers.h"
#include "Service/ILog.h"
#include "Service/IFileops.h"
#include "CustomChipset/Sound/Sound.h"
#include "CustomChipset/Registers.h"
#include "CustomChipset/RegisterUtility.h"
#include "IO/Uart.h"

class Core
{
public:
CustomChipset::Registers Registers;
CustomChipset::RegisterUtility RegisterUtility;
Drivers Drivers;
Sound* Sound;
Uart* Uart;

Sound *Sound;
Drivers Drivers;
Service::ILog* Log;
Service::IFileops* Fileops;

Core();
~Core();
Expand Down
Loading

0 comments on commit a5fc7cd

Please sign in to comment.