Skip to content

Commit

Permalink
Fix C-style rand(); use our Random class instead.
Browse files Browse the repository at this point in the history
  • Loading branch information
sa666666 committed Aug 7, 2024
1 parent 6614a22 commit 4c53cb9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
5 changes: 3 additions & 2 deletions src/emucore/elf/BusTransactionQueue.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ void BusTransactionQueue::Transaction::setBusState(bool& bs_drive, uInt8& bs_val
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
BusTransactionQueue::BusTransactionQueue(size_t capacity) : myQueueCapacity(capacity)
BusTransactionQueue::BusTransactionQueue(size_t capacity)
: myQueueCapacity{capacity},
myQueue{make_unique<Transaction[]>(myQueueCapacity)}
{
myQueue = make_unique<Transaction[]>(myQueueCapacity);
reset();
}

Expand Down
14 changes: 9 additions & 5 deletions src/emucore/elf/ElfLinker.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ namespace {
} // namespace

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ElfLinker::ElfLinker(uInt32 textBase, uInt32 dataBase, uInt32 rodataBase, const ElfFile& elf)
: myTextBase(textBase), myDataBase(dataBase), myRodataBase(rodataBase), myElf(elf)
{}
ElfLinker::ElfLinker(uInt32 textBase, uInt32 dataBase, uInt32 rodataBase,
const ElfFile& elf)
: myTextBase{textBase}, myDataBase{dataBase}, myRodataBase{rodataBase}, myElf{elf}
{
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ElfLinker& ElfLinker::setUndefinedSymbolDefault(uInt32 defaultValue)
Expand Down Expand Up @@ -162,13 +164,15 @@ ElfLinker::RelocatedSymbol ElfLinker::findRelocatedSymbol(string_view name) cons
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
const vector<optional<ElfLinker::RelocatedSection>>& ElfLinker::getRelocatedSections() const
const vector<optional<ElfLinker::RelocatedSection>>&
ElfLinker::getRelocatedSections() const
{
return myRelocatedSections;
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
const vector<optional<ElfLinker::RelocatedSymbol>>& ElfLinker::getRelocatedSymbols() const
const vector<optional<ElfLinker::RelocatedSymbol>>&
ElfLinker::getRelocatedSymbols() const
{
return myRelocatedSymbols;
}
Expand Down
5 changes: 3 additions & 2 deletions src/emucore/elf/VcsLib.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ namespace {
} // namespace

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
VcsLib::VcsLib(BusTransactionQueue& transactionQueue) : myTransactionQueue(transactionQueue)
VcsLib::VcsLib(BusTransactionQueue& transactionQueue)
: myTransactionQueue{transactionQueue}
{
}

Expand Down Expand Up @@ -366,7 +367,7 @@ CortexM0::err_t VcsLib::fetch16(uInt32 address, uInt16& value, uInt8& op, Cortex
}

case ADDR_RANDINT:
cortex.setRegister(0, rand()); // FIXME: use C++11 random library instead
cortex.setRegister(0, myRand.next());
return returnFromStub(value, op);

case ADDR_VCS_TXS2:
Expand Down
3 changes: 3 additions & 0 deletions src/emucore/elf/VcsLib.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#define VCSLIB_H

#include "bspf.hxx"
#include "Random.hxx"
#include "CortexM0.hxx"
#include "BusTransactionQueue.hxx"

Expand Down Expand Up @@ -71,6 +72,8 @@ class VcsLib: public CortexM0::BusTransactionDelegate {
uInt16 myCurrentAddress{0};
uInt8 myCurrentValue{0};

Random myRand;

private:
VcsLib(const VcsLib&) = delete;
VcsLib(VcsLib&&) = delete;
Expand Down

0 comments on commit 4c53cb9

Please sign in to comment.