Skip to content

Commit

Permalink
no longer using chrono namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael-MD committed Mar 1, 2024
1 parent 878e26b commit 402af7b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
18 changes: 9 additions & 9 deletions gbEmu/MBC3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ MBC3::MBC3(std::string gbFilename, uint8_t ROMSize, uint8_t RAMSize) : MBC(gbFil
RTCSelect = 0x00;
HaltTimer = false;

StartTime = system_clock::now();
StartTime = std::chrono::system_clock::now();
}

void MBC3::write(uint16_t addr, uint8_t data)
Expand Down Expand Up @@ -68,17 +68,17 @@ void MBC3::write(uint16_t addr, uint8_t data)
if(!HaltTimer)
{
// Get time elapsed since last write
auto ElapsedTime = system_clock::now() - StartTime;
auto ElapsedTime = std::chrono::system_clock::now() - StartTime;

// Convert time stored into chrono object
seconds RTCTime(RTC[0] * 1 + RTC[1] * 60 + RTC[2] * 3600 + RTC[3] * 86400);
std::chrono::seconds RTCTime(RTC[0] * 1 + RTC[1] * 60 + RTC[2] * 3600 + RTC[3] * 86400);

// Add time elapsed to time in RTC
auto UpdatedTime = RTCTime + ElapsedTime;

RTC[0] = duration_cast<seconds>(UpdatedTime).count() % 60; // Seconds 0-59
RTC[1] = duration_cast<minutes>(UpdatedTime).count() % 60; // Minutes 0-59
RTC[2] = duration_cast<hours>(UpdatedTime).count(); // Hours 0-23
RTC[0] = std::chrono::duration_cast<std::chrono::seconds>(UpdatedTime).count() % 60; // Seconds 0-59
RTC[1] = std::chrono::duration_cast<std::chrono::minutes>(UpdatedTime).count() % 60; // Minutes 0-59
RTC[2] = std::chrono::duration_cast<std::chrono::hours>(UpdatedTime).count(); // Hours 0-23
RTC[2] %= 24;
RTC[3] /= 24; // days 0x00-0xFF

Expand All @@ -87,7 +87,7 @@ void MBC3::write(uint16_t addr, uint8_t data)
RTC[3] = 0x00; // Days low 0x00 - 0xFF;
RTC[4] = HaltTimer << 6;

StartTime = system_clock::now();
StartTime = std::chrono::system_clock::now();
}
}

Expand All @@ -101,7 +101,7 @@ void MBC3::write(uint16_t addr, uint8_t data)
RAM[(RAMBankCode * 0x2000) + (addr % 0xA000)] = data;
}
else {
StartTime = system_clock::now();
StartTime = std::chrono::system_clock::now();

RTC[RTCSelect] = data;

Expand Down Expand Up @@ -132,7 +132,7 @@ void MBC3::write(uint16_t addr, uint8_t data)
HaltTimer = (data >> 6) == 1;
if (HaltTimer == 0)
{
StartTime = system_clock::now();
StartTime = std::chrono::system_clock::now();
}
}
else
Expand Down
4 changes: 1 addition & 3 deletions gbEmu/MBC3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#include <chrono>
#include "MBC.hpp"

using namespace std::chrono;

class MBC3 : public MBC
{
public:
Expand Down Expand Up @@ -33,7 +31,7 @@ class MBC3 : public MBC
uint8_t RTCSelect;

// Stores unix timestamp since last reset or halt
std::chrono::time_point<system_clock> StartTime;
std::chrono::time_point<std::chrono::system_clock> StartTime;

// Timer Halt
bool HaltTimer;
Expand Down

0 comments on commit 402af7b

Please sign in to comment.