Time, Relativity and Distributed Companies

“The only reason for time is so that everything doesn’t happen at once.”
-Albert Einstein

One of the most difficult parts of communication within a fully distributed company is dealing with timezones. I can’t count the number of times that someone has emailed me asking “Can we have a meeting at 10 a.m.?” The obvious question here is which 10 a.m. are you asking about? Are you asking about your 10 a.m. or my 10 a.m.?  Unfortunately, it feels pedantic to ask the person to clarify what they mean, but it matters if you want everyone to show up at the same moment in time!

As I’ve mentioned before, we use Slack in place of meetings for a lot of internal communication, but we do still need to jump on phone calls from time to time. One of the skills that I’ve had to learn when trying to setup meetings is to be very explicit about the time that you mean. Think it’s easy? Try this quick little quiz. Figure out what time it is right now in the following U.S. cities, without using a map:

  1. Las Vegas
  2. Nashville
  3. New Orleans
  4. Phoenix
  5. Detroit
  6. Cleveland
  7. Louisville
  8. Pittsburgh
  9. Milwaukee
  10. Boise

I’m betting that while you might have fairly reasonable guesses, you’re not 100% positive on all of them. A few of them (like Phoenix) are particularly tricky! My recommendation is that when working with people in different timezones, it’s best if you declare the time and timezone not only for yourself but for the person you’re trying to invite. For example, let’s say that you are located in Austin, Texas and I am located in Portland, Oregon, and I want us to have a meeting at 11 in the morning. (Portland is in the Pacific Time Zone and Austin is in the Central Time Zone). I would probably ask you something like this:

     “Are you available for a call at 11:00 a.m. Pacific (1:00 p.m. Central)?”

By communicating it this way, I’m communicating to you that:

  1. We are not both in the same timezone
  2. I would like to talk to you at 1:00 in the afternoon
  3. It will still be 11:00 in the morning for me

This might seem like an obvious thing, but by being explicit, it helps remove any ambiguity and improves the overall quality of the communication. It also removes any assumption that the person you’re communicating with understands what timezones different cities are located in. The most important skill that you can develop in a distributed organization is your ability to communicate, and one of the easiest ways to improve is to become better at communicating time and timezones when talking to people.

Distributed Companies Are Real

When we first set out to build Silverpine, we didn’t really have much of a plan. All we knew was that the fates had aligned, and that it was our time to set out on our own. From our very first day, we have managed to bootstrap the business which was ultimately very beneficial, however, bootstrapping is hard. Very hard. While we grappled with unknown cashflows and even more unknown project pipelines, we knew we had to scrimp and save and keep our costs as low as we possibly could. One major way we were able to do that was by making Silverpine a “virtual” business in that we had no physical office space. It also didn’t hurt that neither my partner Ryan nor I wanted a commute, so it definitely felt like a win/win situation.

For the first few years of our existence, our staff consisted of only Ryan and myself and an occasional subcontractor or two. Working remote became an unstated, simple to implement company policy that we grew to appreciate implicitly, and the freedom that it lent to us quickly became a de facto benefit. As we grew as a company, however, the true value began to emerge.

When we finally hired our first full time employee, working remotely was still an implied benefit. At the same time, we started noticing a trend that many of the best engineers and developers that we knew were explicitly looking for new positions with significant remote work opportunities. However, when our first employee notified us that she was going to move to a rural area, it truly started to dawn on us what it meant for recruiting and retainment. Suddenly, this quirky company policy, that had just organically happened, had become an important pillar of our company culture.

At that point, Ryan and I decided that we were going to commit to Silverpine being a fully distributed organization. We abandoned any intention of developing a physical footprint and started viewing our evolving company through that lens. As we continued to grow and hire, I had to unlearn some of the things that had been ingrained in me from my time in the corporate world and from my MBA classes. I had to really dig in to understanding the tradeoffs of being distributed, partially because we needed to adopt tools and policies that would work well for remote employees, but also because we needed to be able to speak to our clients about how we were different from similar agencies and ultimately, why our distributed nature would benefit them.

For a long time, whenever a prospective client would ask us where we were located, I would make some sort of joke that we were following the “IBM model” even though it wasn’t really an accurate comparison. I would then do some general hand waving about what that meant, but more often than not, I was left with the distinct feeling that we were sometimes viewed as not being a legitimate company. Because of my approach to communicating our structure, I’m certain that we lost more than a couple bids on projects because of this.

Fortunately, as time progressed, many other companies started to legitimize remote work. Companies like Automattic, Basecamp, InVision and Zapier have literally written the book on how to have a remote team, and they have shown that it can work at scale. People have started to notice how these companies operate and thrive, and maybe most importantly, many of the best engineers and developers have started to view remote opportunities as a non-negotiable job requirement. I have run into people time and again at conferences and other work-related events where they explain that having a remote position is often times more important than a salary bump. That means that there is an actual, tangible economic value to a company that embraces remote work.

For Silverpine, we have become better at articulating the legitimacy of our remote nature in a way that better portrays it as a competitive advantage. We talk about the engagement and happiness levels of our employees. We talk about the quality of communication that our team practices on a daily basis. And, we talk about lower base costs which translates to lower project costs. We also occasionally talk about the tools and the processes and the intentionality of it that helps craft our company culture. All of this is important in explaining our story and our organization because there are still plenty of people with an incorrect understanding of remote companies.

I am convinced that the model we stumbled upon (but ultimately embraced) is a blueprint for long term success. It allows us a flexibility and nimbleness that other corporations simply can’t match, and in the ever-changing world that we live in, flexibility is a survival trait. As the Japanese proverb states: “The Bamboo that bends is stronger than the Oak that resists.”

We are definitely still learning and adapting how we function and operate, but I no longer act sheepish or apologize for being a remote company. I am proud of what we are building and what Silverpine has become. (It also doesn’t hurt that our track record is pretty great!) So, if you are thinking about working at a remote company or thinking about adopting remote-friendly policies, don’t approach it as some odd-ball thing. Take some time and read about what/how other companies that are doing it, and recognize that distributed companies are real.

Tools for a Distributed Software Agency

One of the things that I am most proud of is that Silverpine is a 100% distributed company. Often when people find out that we are fully remote, they will ask curiously about what tools we use to work together. This is completely understandable because the importance of having the right tool set is magnified for remote companies. We understand this innately and as such we are constantly evaluating our software stack. The following list represents the software that powers our business. (I have intentionally omitted some of the lower level development tools like Xcode and Android Studio.) The list is broken into four primary classifications: communication, development, project execution, and finance.

Communication

Slack 

Before Slack, we used a hodge lodge of messaging tools like AIM, Google Chat and even old school SMS. It was horrible. Slack is the single most important tool that we use to communicate with each other and with our clients. All of our employees and contractors use it extensively every day, and even though I think that there should be some middle ground in their pricing between the paid and the pro plans, I can’t imagine trying to work remotely without it.

Webex

Let me just preface this by clarifying that I think that every single conference calling platform is terrible. I have used them all. From Zoom.io to Google Hangouts to AT&T Connect, they are just barely workable. Besides the all too common call drops they also all seem to suffer from ridiculous installation processes and byzantine user interfaces (Does this yellow button state mean my microphone is on mute or can they hear me?)

That being said, we have been using Webex for a very long time; not because it is good, but because it is better than the alternatives. And for our enterprise clients, it is somewhat of a known entity so we seem to spend less time per call doing the “can you hear me” dance. I wouldn’t say that I recommend Webex. It’s just what we use.

Dropbox Pro

We have been using Dropbox on personal plans for quite a while, but we recently decided to standardize on Dropbox Pro for file sharing. All of our projects have quite a bit of documentation, graphical assets and other large files that aren’t well suited for source control tools. Dropbox allows us to create per project file drops that we can easily access as well as share with other people when appropriate. We almost switched to Box.com because their pro plans have unlimited storage but ultimately decided it would be less transitional headache to just upgrade our existing Dropbox plans.

G Suite

We have been using Google for our email and calendar services for so long that our silverpinesoftware.com domain is still functioning under the original beta operating agreement. If G Suite disappeared I honestly wouldn’t even know where to start looking for a replacement. File this one under “it just works.”

Development

InVision

One of Silverpine’s guiding design principles is that every user interface needs to have a beautiful “feel” to it, and that you simply can’t judge the feel of an app until you can hold it in your hand and interact with it. Because of this philosophy,  we have refined our development process over time to rely heavily on InVision to prototype the UI and UX of our apps before we ever even start writing code. The amount of time and pain it saves both us and our clients cannot be overstated. If you design for mobile, you really should be using InVision or something like it.

GitHub

If you write software, you should be using a source control platform. If you need a source control platform you should be using GitHub. If you’re using something else, I’m sure you have a reason for it, but it’s probably not a very good reason. (All of our projects use GitHub repositories so when they changed their pricing model to be per user rather than per repository, it made our lives a lot easer.)

Azure DevOps

This one might surprise some people, but a couple years ago we transitioned to what is now known as Microsoft Azure DevOps for our automated build system and have been using it ever since. Prior to Azure DevOps we had used a variety of tools including TestFlight (bought by Apple), Fabric (bought by Twitter, then bought by Google), and BuddyBuild (ran out of money). Due to intense consolidation in that particular sector, we were frequently having to retroactively change our toolset which was both time consuming and costly. A friend of mine who works on the Microsoft tools team encouraged us to give Azure DevOps a try, and we have been extremely happy with that decision. Azure DevOps supports both iOS and Android, is massively configurable, has 24/7 support and most importantly, is backed by one of the largest companies in the world so it won’t be disappearing any time soon. If you need an automated build system and haven’t taken a look at Azure, I highly recommend at least kicking its tires.

Project Execution

Basecamp

For many years, we wandered in the desert of project management, largely piggybacking on whatever project management tools our clients happened to be using at the time. As such, we have used everything from Jira to Asana to Microsoft Excel to track projects and tasks. However, in the past year we have implemented Basecamp as our standard internal project tracking tool. One of the things I like best about Basecamp is that it has clearly been thoughtfully designed. Not only is it powerful, but its design somehow works to ensure that it doesn’t become overly burdensome in the same way that other similarly complex tools do.

Lighthouse

If there was one piece of web software that I would invest internal Silverpine resources on, it would be a lightweight bug tracking tool. There just aren’t many platforms out there that can strike a balance of utility and ease of use that errs on the side of ease of use. For now, Lighthouse foots the bill for us in that regard, however, I’m not sure how much longer it will be around. There hasn’t been any significant development done on it in the 6+ years that we’ve been using it, so I’m not sure I would necessarily recommend it. That being said, it does what we need bug tracking software to do, and it does it well, and I haven’t found a replacement. If you have any personal favorites, please let me know.

Finance

Blinksale

Silverpine is a services business and sending invoices to our customers is literally how we are able to make money. Blinksale is the tool we use to send those invoices and look like we are professionals in the process. While it isn’t a complex tool, it expertly does what we need it to do: send and track professional looking invoices. If you send invoices to clients, you really should be using a tool like Blinksale because people can tell when you don’t.

Quickbooks

Nobody really loves Intuit. They have created not one, but two near monopolies with TurboTax and Quickbooks. However, if you run a business, you need to track your finances in a way that your CPA can help you with your taxes at the end of the year, and if you tell your CPA that you use anything other than Quickbooks, they will not be happy with you and they will very likely take longer to do your taxes which means you will end up with a higher bill from them. That is the reality of Quickbooks and that is why we use it.

Gusto

If you have employees or sub-contractors that you need to pay, you really should be using Gusto. The folks at Gusto are wizards when it comes to dealing with payroll taxes and W-9’s and a great deal more things that I simply don’t have to worry about because we use their service. Not only is the Gusto platform super easy to use, but their customer service team is actually pro-active in notifying us of upcoming tax law changes that might affect us. I am continually in awe of how great Gusto is and cannot say enough good things about them.

 

Unintended Consequences

Disclaimer:
This post comes from my old blog back in 2004. I’m reposting it here so that I don’t lose the content. The source was hand-written HTML so the formatting probably appears a bit off.

About seven years ago I wrote some code to do Mu-Law and A-Law compression. About six years ago, I decided to publish an article along with the source code for it. You can find it here. Anyway, the other day I received an email from someone who had taken it and modified it for what he was doing. In doing so, he found a piece of misinformation that has been in my article since I originally published it. Not a big deal, and I intend to rectify the issue. However, as we chatted over email, I asked him what he was using Mu-Law/A-Law compression for. Here is a clip from our email:

> So if you don’t mind me asking, what are you working on that has 13 bit

> unsigned audio input?

Sure. I am designing a system that monitors lots of radio stations to capture and

detect Emergency Alert System activations – those ugly tones and occasional

voice messages you hear on the radio. The system has some rather incredible

shortcomings for a critical system in 2005. When the emergency management

office triggers an alert they have no way of knowing whether or not radio stations

actually broadcast the alert. Sometimes the system fails – too often. So our

system listens to the stations and sends a report back to Emergency HQ. In

most cases an exception report that shows which stations did not properly

send out the alert. So if the dam is breaking or the nuke is going critical they

can try again, use the phone, send a helicopter or something.

 

Whoa. Code that I originally wrote to compress audio in children’s games is now being used to help monitor Emergency situations. Talk about your unintended consequences!

-Jon

Translating Hardware Exceptions to C++ Exceptions

Disclaimer:
This post comes from my old blog back in 2004. I’m reposting it here so that I don’t lose the content. The source was hand-written HTML so the formatting probably appears a bit off.

No matter how careful of a programmer you are, there will always be times when a hardware
exception will occur in your code. Perhaps it was a third party component that was the
culprit. Perhaps, it was a fellow co-worker that broke something. Or maybe it was
Microsoft itself not playing fair with its documentation and/or implementations.
Whatever the case, it is often very useful to be able to capture a run-time exception
that was generated by the CPU. Sure, you can use a catch(…) to be your fail-safe, but
wouldn’t it be great to be able to convert that exception that was generated by the hardware
into a C++ exception? I created this class in order to do that very thing. In fact,
this class was the basis for my super assert that I created, because I found that I could
cause a hardware exception any time I wanted, and by using this C++ hardware exception container,
I could access each thread’s stack frame at run-time. This would eventually enable me to
perform a stack trace inside of an assert, but I will explain that more in a different
tutorial.

Anyway, I hope that this is useful to someone. I spent a while digging around in the
mire that is Microsoft’s documentation before I put this together. Perhaps this will save
someone else time in the future.

Enjoy.

-BossHogg

#ifndef HARDWARE_EXCEPTION
#define HARDWARE_EXCEPTION 1


enum HWExceptionType
{
	eIllegalMemoryAccess	= EXCEPTION_ACCESS_VIOLATION,
	eUnexpectedBreakpoint 	= EXCEPTION_BREAKPOINT,
	eDataTypeMisalignment 	= EXCEPTION_DATATYPE_MISALIGNMENT,
	eSingleStepInstruction 	= EXCEPTION_SINGLE_STEP,
	eArrayBoundsExceeded	= EXCEPTION_ARRAY_BOUNDS_EXCEEDED,
	eDenormalFloat 		= EXCEPTION_FLT_DENORMAL_OPERAND,
	eFloatDivideByZero 	= EXCEPTION_FLT_DIVIDE_BY_ZERO,
	eFloatInexactResult	= EXCEPTION_FLT_INEXACT_RESULT,
	eFloatInvalidOperation 	= EXCEPTION_FLT_INVALID_OPERATION,
	eFloatOverflow 		= EXCEPTION_FLT_OVERFLOW,
	eFloatStackCorrupted 	= EXCEPTION_FLT_STACK_CHECK,
	eFloatUnderflow 	= EXCEPTION_FLT_UNDERFLOW,
	eIntDivideByZero 	= EXCEPTION_INT_DIVIDE_BY_ZERO,
	eIntOverflow 		= EXCEPTION_INT_OVERFLOW,
	ePrivelegedInstruction 	= EXCEPTION_PRIV_INSTRUCTION,
	eUncontinuableException = EXCEPTION_NONCONTINUABLE_EXCEPTION
};


class HWException
{
     public:
          HWException(HWExceptionType aType,
                      EXCEPTION_POINTERS* pExp):
	       itsCategory(aType),
	       itsPointers(pExp),
	       itsLocation(pExp->ExceptionRecord->ExceptionAddress)
          {
	  }

	  HWExceptionType     GetCategory()  const {return itsCategory;}
	  DWORD		      GetLocation()  const {return itsLocation;}
	  EXCEPTION_POINTERS* GetSysPointer()const {return itsPointers;}

     protected:
          HWExceptionType	itsCategory;
	  DWORD			itsLocation;
	  EXCEPTION_POINTERS*	itsPointers;
};


static void HWTranslateException(unsigned int u, 
                                 EXCEPTION_POINTERS* pExp)
{
	throw HWException((HWExceptionType)u,pExp);
}

#endif



///////////////////////////////////////////////////////////////////////
Example usage:
///////////////////////////////////////////////////////////////////////

#include "windows.h"
#include "HWException.h"


int main()
{
	//Note, setting the exception translator must be done 
	//on a per thread basis.
	_set_se_translator(HWTranslateException);

	try {
		//This will cause an access violation
		char* ptr = NULL;
		*ptr = 5; 	
	}
	catch (HWException& e)
	{
		//We can now know both the type and the
		//memory location of the instruction that
		//caused the exception.  Cool!

		HWExceptionType exceptionType = e.GetCategory();
		DWORD address = e.GetLocation();
	}
	catch (...)
	{
		//If we got here, then it was some other kind
		//of C++ exception...
	}

	return 0;
}


CPU Detection Code

Disclaimer:
This post comes from my old blog back in 2004. I’m reposting it here so that I don’t lose the content. The source was hand-written HTML so the formatting probably appears a bit off.

CPU Detection Code

I dug this code up from a project that I worked on a long time ago. Unfortunately,
it is woefully out of date, especially with any of the latest P4 processors.
Also unfortunately, I don’t have a large suite of machines on which to test this,
however, I have verified a large number of these, but not all.
Also missing from the list are any AMD processors since my old companies didn’t
explicitly support AMD. Oh, well. As always, this code is to be used at your own
expense, and I guess with this particular set of code, that means a little more.
Anyway, I hope someone finds this interesting, and if you have any questions,
feel free to ask.

-BossHogg



#include “windows.h”

bool QueryCPUID();

bool QueryMMX();

bool QueryHyperThreading();

void QueryVendorString(char* string);

bool QuerySerialNumber(char* string);

void GetCPUInfoString(char* string);

unsigned long QueryCacheSize();

unsigned long QueryCPUCount();

unsigned char QueryCPUModel();

unsigned char QueryCPUFamily();

unsigned char QueryCPUStepping();

unsigned char QueryCPUType();

bool Is8086()

{

int is8086=0;

__asm {

pushf

pop ax

mov cx, ax

and ax, 0fffh

push ax

popf

pushf

pop ax

and ax, 0f000h

cmp ax, 0f000h

mov is8086, 0

jne DONE_8086_CHECK

mov is8086, 1

DONE_8086_CHECK:

};

return !!is8086;

}

bool Is80286()

{

int is80286=0;

__asm {

smsw ax

and ax, 1

or cx, 0f000h

push cx

popf

pushf

pop ax

and ax, 0f000h

mov is80286, 1

jz DONE_80286_CHECK

mov is80286, 0

DONE_80286_CHECK:

};

return !!is80286;

}

bool Is80386()

{

int is80386=0;

__asm {

pushfd

pop eax

mov ecx, eax

xor eax, 40000h

push eax

popfd

pushfd

pop eax

xor eax, ecx

mov is80386, 1

jz DONE_80386_CHECK

mov is80386, 0

DONE_80386_CHECK:

};

return !!is80386;

}

bool QueryCPUID()

{

int hasCPUID=0;

__asm

{

pushfd

pop eax

mov ecx, eax

and ecx, 0x00200000

xor eax, 0x00200000

push eax

popfd

pushfd

pop eax

and eax, 0x00200000

xor eax, ecx

mov hasCPUID, eax

};

return !!hasCPUID;

}

bool QueryMMX()

{

bool canDoMMX=false;

__asm

{

mov eax, 1 ; request for feature flags

_emit 0x0F ; CPUID on Pentiums is 0f,a2

_emit 0xA2

test edx, 0x00800000 ; is MMX technology Bit(bit 23)in feature

jz DONE_MMX_CHECK ; flags equal to 1

mov canDoMMX,1

DONE_MMX_CHECK:

};

return canDoMMX;

}

bool QueryHyperThreading()

{

unsigned int regEdx = 0;

unsigned int regEax = 0;

unsigned int vendorId[3] = {0, 0, 0};

if (!QueryCPUID())

return false;

__asm

{

xor eax, eax // call cpuid with eax = 0

cpuid // Get vendor id string

mov vendorId, ebx

mov vendorId + 4, edx

mov vendorId + 8, ecx

mov eax, 1 // call cpuid with eax = 1

cpuid

mov regEax, eax // eax contains family processor type

mov regEdx, edx // edx has info about the availability of hyper-Threading

}

if (((regEax & 0x0F00) == 0x0F00) || (regEax & 0x0F00000))

{

if (vendorId[0] == ‘uneG’ && vendorId[1] == ‘Ieni’ && vendorId[2] == ‘letn’)

{

return !!(regEdx & 0x10000000);

}

}

return false;

}

void QueryVendorString(char* string)

{

char vendorId[12];

__asm{

mov eax, 0 ; request for feature flags

_emit 0x0F ; CPUID on Pentiums is 0f,a2

_emit 0xA2

mov dword ptr vendorId, ebx

mov dword ptr vendorId[+4], edx

mov dword ptr vendorId[+8], ecx

};

memcpy(string,vendorId,12);

string[12]=0;

}

unsigned char QueryCPUStepping()

{

unsigned char _stepping;

__asm{

mov eax, 1 ; request for feature flags

_emit 0x0F ; CPUID on Pentiums is 0f,a2

_emit 0xA2

and eax, 0x0F

mov _stepping, al

};

return _stepping;

}

unsigned char QueryCPUModel()

{

unsigned char _model;

__asm{

mov eax, 1 ; request for feature flags

_emit 0x0F ; CPUID on Pentiums is 0f,a2

_emit 0xA2

shr eax, 4

and eax, 0x0F

mov _model, al

};

return _model;

}

unsigned char QueryCPUFamily()

{

unsigned char _family;

__asm{

mov eax, 1 ; request for feature flags

_emit 0x0F ; CPUID on Pentiums is 0f,a2

_emit 0xA2

shr eax, 8

and eax, 0x0F

mov _family, al

};

return _family;

}

unsigned char QueryCPUType()

{

char _type;

__asm{

mov eax, 1 ; request for feature flags

_emit 0x0F ; CPUID on Pentiums is 0f,a2

_emit 0xA2

shr eax, 12

and eax, 0x03

mov _type, al

};

return _type;

}

unsigned long QueryCPUCount()

{

SYSTEM_INFO info;

GetSystemInfo(&info;);

return info.dwNumberOfProcessors;

}

bool LookUpL2CacheSize(int infoFlag, unsigned long& cacheSize)

{

int cacheFlag = infoFlag;

cacheFlag &= 0xFF;

while (infoFlag > 0)

{

switch (cacheFlag)

{

case 0x80:

case 0x40:

cacheSize = 0;

return true;

case 0x81:

case 0x41:

cacheSize = 128;

return true;

case 0x82:

case 0x42:

cacheSize = 256;

return true;

case 0x83:

case 0x43:

cacheSize = 512;

return true;

case 0x84:

case 0x44:

cacheSize = 1024;

return true;

case 0x85:

case 0x45:

cacheSize = 2048;

return true;

}

infoFlag = infoFlag >> 8;

cacheFlag = infoFlag & 0xFF;

}

return false;

}

unsigned long QueryCacheSize()

{

char cacheRepeatCount=0;

int eaxCacheDescriptor=0;

int ebxCacheDescriptor=0;

int ecxCacheDescriptor=0;

int edxCacheDescriptor=0;

unsigned long cacheSize=0;

__asm{

//Let’s find out the amount of the cache.

//That will help us later on figure out which processor we are running…

mov eax, 2

_emit 0x0f

_emit 0xa2

mov cacheRepeatCount, al

cmp al, 1

je DONE_CACHE_CHECK

REPEAT_CACHE_DETECT:

mov eax, 2

_emit 0x0f

_emit 0xa2

dec cacheRepeatCount

jnz REPEAT_CACHE_DETECT

DONE_CACHE_CHECK:

mov eaxCacheDescriptor, eax

mov ebxCacheDescriptor, ebx

mov ecxCacheDescriptor, ecx

mov edxCacheDescriptor, edx

};

if (LookUpL2CacheSize(eaxCacheDescriptor,cacheSize))

return cacheSize;

if (LookUpL2CacheSize(ebxCacheDescriptor,cacheSize))

return cacheSize;

if (LookUpL2CacheSize(ecxCacheDescriptor,cacheSize))

return cacheSize;

if (LookUpL2CacheSize(edxCacheDescriptor,cacheSize))

return cacheSize;

return 0;

}

bool QuerySerialNumber(char* string)

{

char serialString[32];

bool isValid=false;

unsigned long one=0;

unsigned long two=0;

unsigned long three=0;

if (QueryCPUID())

{

__asm {

mov eax, 0

_emit 0x0f

_emit 0xa2

cmp eax, 3

jl DONE

mov eax, 1

_emit 0x0f

_emit 0xa2

and edx, 0x20000

jz DONE

mov one, eax

mov eax, 3

_emit 0x0f

_emit 0xa2

mov two, edx

mov three, ecx

mov isValid, 1

DONE:

};

}

if (isValid)

{

wsprintf(serialString,”%04x-%04x-%04x-%04x-%04x-%04x”,

one >> 16, one & 0x0000FFFF,

two >> 16, two & 0x0000FFFF,

three >> 16, three & 0x0000FFFF);

}

else

strcpy(serialString,”###DISABLED OR NOT PRESENT###”);

strcpy(string,serialString);

return isValid;

}

//If type==0x10, then it’s a dual processor system…

//Also, if it’s a P2, you need to check the L2 cache size to see if

//it’s a celeron or a real P2. If it’s zero, it’s a Celery.

const int cCPULookupTableSize=28;

#define MakeFingerprint(a,b,c)           ((((unsigned long)a) << 24) | \

(((unsigned long)b) << 16) | (((unsigned long)c) << 8) | ((unsigned long)0))

struct CPUFingerprint

{

//Fingerprint is (family | model | type )

unsigned long fingerprint;

char vendorID[16];

char description[64];

};

CPUFingerprint cpuLookupTable[cCPULookupTableSize]=

{

//The first four entries in the table are reserved for special processors.

{ MakeFingerprint(0x00, 0x00, 0x00), “Unknown vendor”, “Unknown processor”},

{ MakeFingerprint(0x00, 0x00, 0x00), “Unknown vendor”, “Intel8086”},

{ MakeFingerprint(0x00, 0x00, 0x00), “Unknown vendor”, “Intel80286”},

{ MakeFingerprint(0x00, 0x00, 0x00), “Unknown vendor”, “Intel80386”},

//These are the ones that support CPUID, so we start the “real”

//lookup here. Currently, this is offset number 4 in the array.

{ MakeFingerprint(0x04, 0x00, 0x00), “Unknown vendor”, “Intel486 DX”},

{ MakeFingerprint(0x04, 0x01, 0x00), “Unknown vendor”, “Intel486 DX”},

{ MakeFingerprint(0x04, 0x02, 0x00), “Unknown vendor”, “Intel486 SX”},

{ MakeFingerprint(0x04, 0x03, 0x00), “Unknown vendor”, “Intel487 or DX2”},

{ MakeFingerprint(0x04, 0x04, 0x00), “Unknown vendor”, “Intel486 SL”},

{ MakeFingerprint(0x04, 0x05, 0x00), “Unknown vendor”, “IntelSX2”},

{ MakeFingerprint(0x04, 0x07, 0x00), “Unknown vendor”, “Write-Back Enhanced IntelDX2”},

{ MakeFingerprint(0x04, 0x08, 0x00), “Unknown vendor”, “IntelDX4”},

{ MakeFingerprint(0x04, 0x08, 0x00), “Unknown vendor”, “IntelDX4 OverDrive”},

{ MakeFingerprint(0x05, 0x01, 0x00), “Unknown vendor”, “Pentium (60,66)”},

{ MakeFingerprint(0x05, 0x02, 0x00), “Unknown vendor”, “Pentium (75 – 200)”},

{ MakeFingerprint(0x05, 0x01, 0x00), “Unknown vendor”, “Pentium Overdrive (60,66)”},

{ MakeFingerprint(0x05, 0x02, 0x00), “Unknown vendor”, “Pentium Overdrive (75 – 133)”},

{ MakeFingerprint(0x05, 0x03, 0x00), “Unknown vendor”, “Pentium Overdrive for Intel486”},

{ MakeFingerprint(0x05, 0x01, 0x00), “Unknown vendor”, “Pentium Overdrive (60,66)”},

{ MakeFingerprint(0x05, 0x04, 0x00), “Unknown vendor”, “Pentium with MMX (166,200)”},

{ MakeFingerprint(0x05, 0x04, 0x00), “Unknown vendor”, “Pentium MMX Overdrive (75 – 133)”},

{ MakeFingerprint(0x06, 0x01, 0x00), “Unknown vendor”, “PentiumPro”},

{ MakeFingerprint(0x06, 0x03, 0x00), “Unknown vendor”, “PentiumII model 3”},

{ MakeFingerprint(0x06, 0x05, 0x00), “Unknown vendor”, “PentiumII model 5 or Celeron”},

{ MakeFingerprint(0x06, 0x08, 0x00), “Unknown vendor”, “PentiumII or Celeron”},

{ MakeFingerprint(0x0F, 0x00, 0x08), “Unknown vendor”, “Pentium 4” },

{ MakeFingerprint(0x0F, 0x01, 0x08), “Unknown vendor”, “Pentium 4” },

{ MakeFingerprint(0x0F, 0x02, 0x09), “Unknown vendor”, “Pentium 4” }

};

void GetCPUInfoString(char* string)

{

long tableEntry=0;

if (Is8086())

tableEntry=1;

else if (Is80286())

tableEntry=2;

else if (Is80386())

tableEntry=3;

else if (QueryCPUID())

{

unsigned char family=QueryCPUFamily();

unsigned char model=QueryCPUModel();

unsigned char type=QueryCPUType();

//unsigned char stepping=QueryCPUStepping();

unsigned long fingerprint = MakeFingerprint(family, model, type);

//Start the lookup at four to skip the reserved entries…

for (int x=4; x < cCPULookupTableSize; x++)

{

if (fingerprint == cpuLookupTable[x].fingerprint)

tableEntry=x;

}

//Fill in the vendor string…

QueryVendorString(cpuLookupTable[tableEntry].vendorID);

}

unsigned long cacheSize = QueryCacheSize();

bool hasMMX = QueryMMX();

unsigned long cpuCount=QueryCPUCount();

char serialId[64];

QuerySerialNumber(serialId);

bool hyperThreading = QueryHyperThreading();

wsprintf(string,”———————————————————\n”

“Primary cpu = %s\n”

“CPUs present: %d\n”

“Vendor string: %s\n”

“L2 cache size: %d\n”

“MMX capable: %d\n”

“Serial ID: %s\n”

“HyperThread: %d\n”

“———————————————————\n”,

cpuLookupTable[tableEntry].description,

cpuCount,

cpuLookupTable[tableEntry].vendorID,

cacheSize,

hasMMX,

serialId,

hyperThreading);

}

Disclaimer:
This post comes from my old blog back in 2004. I’m reposting it here so that I don’t lose the content. The source was hand-written HTML so the formatting probably appears a bit off.


MCI CD Control

This is the MCI control code that I wrote for my UglyCD
player
. It is fairly full featured, but if you need more, feel free to modify it to your needs. I
have neglected the error checking code, and every call to mciSendCommand should really be checked for
its return value. As usual, this code is usable at your own risk. If you have any questions, you are
always free to ask.

-BossHogg

#ifndef MCI_CONTROL
#define MCI_CONTROL 1

class MCIControl
{
     public:
          MCIControl();
          ~MCIControl();

          int     GetNumberOfTracks();
          void    Resume();
          void    Pause();
          void    Play();
          void    Stop();
          void    OpenDoor();
          void    CloseDoor();

          void    Goto(int track,int minute, int second);
		
          int     GetCurrentTrack();
          int     GetCurrentMinute();
          int     GetCurrentSecond();

     protected:
          void    Init();
          void    SetTimeFormat();
          void    GetPosition(BYTE* track,BYTE* min,BYTE* sec);

     private:
          MCIDEVICEID   itsMCIDevice;
};

#endif

#include “windows.h”

#include “MCIControl.h”

MCIControl::MCIControl() :

itsMCIDevice(0)

{

Init();

SetTimeFormat();

}

MCIControl::~MCIControl()

{

MCI_GENERIC_PARMS Info;

Info.dwCallback=0;

mciSendCommand(itsMCIDevice, MCI_CLOSE, MCI_NOTIFY, DWORD(&Info;));

}

void MCIControl::Resume()

{

MCI_PLAY_PARMS Info;

BYTE track,minute,second;

GetPosition(&track;,&minute;,&second;);

Info.dwTo=0;

Info.dwCallback=0;

Info.dwFrom = MCI_MAKE_TMSF(track,minute,second,0);

mciSendCommand(itsMCIDevice, MCI_PLAY, MCI_FROM|MCI_NOTIFY, DWORD(&Info;));

}

void MCIControl::Pause()

{

MCI_GENERIC_PARMS Info;

Info.dwCallback = 0;

mciSendCommand(itsMCIDevice, MCI_PAUSE, MCI_NOTIFY, DWORD(&Info;));

}

void MCIControl::Goto(int track,int minute, int second)

{

MCI_PLAY_PARMS Info;

Info.dwCallback=0;

Info.dwTo=0;

Info.dwFrom = MCI_MAKE_TMSF(track,minute,second,0);

mciSendCommand(itsMCIDevice, MCI_PLAY, MCI_FROM|MCI_NOTIFY, DWORD(&Info;));

}

void MCIControl::Play()

{

MCI_PLAY_PARMS Info;

Info.dwCallback=0;

Info.dwTo=0;

Info.dwFrom = MCI_MAKE_TMSF(0,0,0,0);

mciSendCommand(itsMCIDevice, MCI_PLAY, MCI_FROM|MCI_NOTIFY, DWORD(&Info;));

}

void MCIControl::Stop()

{

MCI_GENERIC_PARMS Info;

Info.dwCallback = 0;

mciSendCommand(itsMCIDevice, MCI_STOP, MCI_NOTIFY, DWORD(&Info;));

}

void MCIControl::OpenDoor()

{

MCI_STATUS_PARMS Info;

Info.dwCallback=0;

Info.dwItem=0;

Info.dwReturn=0;

Info.dwTrack=0;

mciSendCommand(itsMCIDevice, MCI_SET, MCI_SET_DOOR_OPEN, DWORD(&Info;));

}

void MCIControl::CloseDoor()

{

MCI_STATUS_PARMS Info;

Info.dwCallback=0;

Info.dwItem=0;

Info.dwReturn=0;

Info.dwTrack=0;

mciSendCommand(itsMCIDevice, MCI_SET, MCI_SET_DOOR_CLOSED, DWORD(&Info;));

}

int MCIControl::GetCurrentTrack()

{

BYTE track;

GetPosition(&track;,NULL,NULL);

return track;

}

int MCIControl::GetCurrentMinute()

{

BYTE minute;

GetPosition(NULL,&minute;,NULL);

return minute;

}

int MCIControl::GetCurrentSecond()

{

BYTE second;

GetPosition(NULL,NULL,&second;);

return second;

}

int MCIControl::GetNumberOfTracks()

{

MCI_STATUS_PARMS Info;

Info.dwCallback = 0;

Info.dwReturn = 0;

Info.dwItem = MCI_STATUS_NUMBER_OF_TRACKS;

Info.dwTrack = 0;

mciSendCommand(itsMCIDevice,MCI_STATUS,MCI_STATUS_ITEM,DWORD(&Info;));

return (int)Info.dwReturn;

}

void MCIControl::GetPosition(BYTE* track,BYTE* min,BYTE* sec)

{

MCI_STATUS_PARMS Info;

DWORD MSF;

Info.dwCallback=0;

Info.dwReturn=0;

Info.dwTrack=0;

Info.dwItem = MCI_STATUS_POSITION;

mciSendCommand(itsMCIDevice, MCI_STATUS, MCI_STATUS_ITEM, DWORD(&Info;));

MSF = Info.dwReturn;

if (track)

*track = MCI_MSF_MINUTE(MSF);

if (min)

*min = MCI_MSF_SECOND(MSF);

if (sec)

*sec = MCI_MSF_FRAME(MSF);

}

void MCIControl::SetTimeFormat()

{

MCI_SET_PARMS Info;

Info.dwCallback=0;

Info.dwTimeFormat=MCI_FORMAT_TMSF;

Info.dwAudio=0;

mciSendCommand(itsMCIDevice, MCI_SET, MCI_SET_TIME_FORMAT, DWORD(&Info;));

}

void MCIControl::Init()

{

MCI_OPEN_PARMS Info;

Info.dwCallback=0;

Info.lpstrAlias=0;

Info.lpstrElementName=0;

Info.wDeviceID=0;

Info.lpstrDeviceType=MAKEINTRESOURCE(MCI_DEVTYPE_CD_AUDIO);

mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE|MCI_OPEN_TYPE_ID, DWORD(&Info;));

itsMCIDevice = Info.wDeviceID;

}