Skip to content

Commit

Permalink
work on assembler
Browse files Browse the repository at this point in the history
  • Loading branch information
gulrak committed Aug 26, 2023
1 parent 47d8e7b commit 147dbd9
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 2 deletions.
87 changes: 87 additions & 0 deletions external/stdendian/cdendian.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
//---------------------------------------------------------------------------------------
// src/emulation/c8capturehost.hpp
//---------------------------------------------------------------------------------------
//
// Copyright (c) 2023, Steffen Schümann <s.schuemann@pobox.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
//---------------------------------------------------------------------------------------
#pragma once

#include <cstdint>
#include <type_traits>

template <typename T, typename std::enable_if<std::is_integral<T>::value, int>::type = 0>
inline T be_dec(uint8_t*& data)
{
T value{};

if constexpr (sizeof(T) == 1) {
return static_cast<T>(*data++);
}
else if constexpr (sizeof(T) == 2) {
value = static_cast<T>((static_cast<uint32_t>(data[0]) << 8) | data[1]);
data += 2;
return value;
}
else if constexpr (sizeof(T) == 4) {
value = static_cast<T>((static_cast<uint32_t>(data[0]) << 24) | (static_cast<uint32_t>(data[1]) << 16) | (static_cast<uint32_t>(data[2]) << 8) | data[3]);
data += 4;
return value;
}
else if constexpr (sizeof(T) == 8) {
value = static_cast<T>((static_cast<uint64_t>(data[0]) << 56) | (static_cast<uint64_t>(data[1]) << 48) | (static_cast<uint64_t>(data[2]) << 40) | (static_cast<uint64_t>(data[3]) << 32) | (static_cast<uint32_t>(data[4]) << 24) |
(static_cast<uint32_t>(data[5]) << 16) | (static_cast<uint32_t>(data[6]) << 8) | data[7]);
data += 8;
return value;
}
else {
return 0;
}
}

template <typename T, typename std::enable_if<std::is_integral<T>::value, int>::type = 0>
inline T le_dec(uint8_t*& data)
{
T value{};

if constexpr (sizeof(T) == 1) {
return static_cast<T>(*data++);
}
else if constexpr (sizeof(T) == 2) {
value = static_cast<T>((static_cast<uint32_t>(data[1]) << 8) | data[0]);
data += 2;
return value;
}
else if constexpr (sizeof(T) == 4) {
value = static_cast<T>((static_cast<uint32_t>(data[3]) << 24) | (static_cast<uint32_t>(data[2]) << 16) | (static_cast<uint32_t>(data[1]) << 8) | data[0]);
data += 4;
return value;
}
else if constexpr (sizeof(T) == 8) {
value = static_cast<T>((static_cast<uint64_t>(data[7]) << 56) | (static_cast<uint64_t>(data[6]) << 48) | (static_cast<uint64_t>(data[5]) << 40) | (static_cast<uint64_t>(data[4]) << 32) | (static_cast<uint32_t>(data[3]) << 24) |
(static_cast<uint32_t>(data[2]) << 16) | (static_cast<uint32_t>(data[1]) << 8) | data[0]);
data += 8;
return value;
}
else {
return 0;
}
}
1 change: 1 addition & 0 deletions external/stdendian/stdendian.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* stdendian.h
*
* Declared public domain at https://gist.github.com/michaeljclark/3b4fd912f6fa8bb598b3
* new home at: https://github.com/michaeljclark/stdendian
*
* This header defines the following endian macros as defined here:
*
Expand Down
4 changes: 2 additions & 2 deletions src/cadmium.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2769,12 +2769,12 @@ int main(int argc, char* argv[])
chip8->executeInstruction();
lastCycles = cycles;
}
auto durationChip8 = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - startChip8);
auto durationChip8 = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now() - startChip8);
if(screenDump) {
std::cout << chip8EmuScreenANSI(*chip8);
}
std::cout << "Executed instructions: " << chip8->getCycles() << std::endl;
std::cout << "Cadmium: " << durationChip8.count() << "ms, " << int(double(chip8->getCycles())/durationChip8.count()/1000) << "MIPS" << std::endl;
std::cout << "Cadmium: " << durationChip8.count() << "us, " << int(double(chip8->getCycles())/durationChip8.count()) << "MIPS" << std::endl;
}
else if(traceLines >= 0) {
do {
Expand Down

0 comments on commit 147dbd9

Please sign in to comment.