Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Boilerplate #1

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open

Boilerplate #1

wants to merge 9 commits into from

Conversation

r41k0u
Copy link
Collaborator

@r41k0u r41k0u commented Aug 15, 2022

No description provided.

@burnerlee
Copy link

add newlines at end of files

@burnerlee
Copy link

break header files into header (only function signatures/declarations) and cpp files for logic (function definitions)

Copy link

@burnerlee burnerlee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very well drafted PR. Awesome work!!

// Similar to ferror() and clearerr()

virtual bool err() const { return false; }
virtual void clearError() {}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make this a purely virtual function

Comment on lines +12 to +21
typedef unsigned char byte;
typedef unsigned char uint8;
typedef signed char int8;
typedef unsigned short uint16;
typedef signed short int16;
typedef unsigned int uint32;
typedef signed int int32;
typedef unsigned int uint;
typedef signed long long int64;
typedef unsigned long long uint64;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kinda risky, use https://cplusplus.com/reference/cstdint/ for full portability

Comment on lines +36 to +39
inline uint16 READ_UINT16(const void *ptr) {
const uint8 *b = (const uint8 *)ptr;
return (b[1] << 8) | b[0];
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you're writing for little endian, why not do:

inline uint16 READ_UINT16(const void *ptr) {
	const uint16 *b = (const uint16 *)ptr;
	return *b;
}

you can even do this

template<typename T>
static inline T READ(const void *ptr) {
	const uint16 *b = (const uint16 *)ptr;
	return *b;
}

// And if you don't want to use READ<uint32> everywhere:
static inline uint32 READ_UINT32(const void *ptr) {
       return READ<uint32>(ptr);
}
...

(try using static inline as much as you can)

Also please avoid using void* in cpp, typedef or string typedef to signify that this is a stream.

Using constexprs you can even write a common definition for loading LE values on a BE and LE system:

template<typename T>
constexpr static inline T READ(const void *ptr) {
        // set isBigEnding somewhere using constexpers to detect
        if constexpr (isBigEndian) {
                constexpr size_t byteCount = sizeof(T);
		T res = 0;
		// This will be unrolled easily
		for(size_t i = byteCount - 1; i >= 0; i-- ) {
		        res |= (((T*)ptr)[i] << (i * 8));
                }
                return res;
        }
        else {
	        const uint16 *b = (const uint16 *)ptr;
		return *b;
        }
}

^ This can very easily be extended to get support BE values on a BE and LE system as well with a couple of more if branches and is pretty idiomatic.

@@ -0,0 +1,99 @@
#include "emusys.h"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in general, try to use constexpr as much as possible and macros as a last resort, you can even use constexpr to determine if the platform is big endian or little endian at compiletime

Comment on lines +11 to +20
// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started:
// 1. Use the Solution Explorer window to add/manage files
// 2. Use the Team Explorer window to connect to source control
// 3. Use the Output window to see build output and other messages
// 4. Use the Error List window to view errors
// 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove kek

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants