Triangle Peg Game – All Solutions

Many years ago I wrote a web posting of how to solve the Cracker Barrel golf tee triangle board peg game puzzle. This is now located on this blog in a preceding post here.

In updating that blog for a solution of finish hole equals to the starting empty hole, I was troubled that the solution provided by reader Merv Eberhardt included a solution for 4 of the possible 5 starting holes, but did not include a solution for the evil hole #5

Related, I had never been able to get to the goal position or “magic diamond” from a starting position of 5, 8 or 9. Recall that once 3 moves are complete for all the other starting positions, the solution to the puzzle is the same in all cases. I mean, a solution to the puzzle is the same in all cases, there are lots of variations on the solution to the puzzle. The nice thing about the solution discussed in the prior blog is that after 3 moves, all the solutions are the same no matter where you started, except position 5 which is same as 5, 8, 9. Goal position or “magic diamond” is listed below.

I asked that if anyone could figure out how to get to the goal position from start position 5, please let me know. Today: I know there is no such solution.

Wrote a program

Troubled that I did not have a finish position equal starting position for hole #5, I wrote a program to solve the puzzle. Solve it yes, but I mean solve ALL of the variations.

From any position, you can jump up-left, up-right, left, right, down-left, down-right. The program starts with one position empty and then solves ALL of the possible solutions for that position, and then moves onto the next starting position, until all of the solutions are known. As a programmer, this was itself a good puzzle, much like playing the game.

The answers are

  1. There is no path to the magic diamond from starting position 5 (5, 8, 9)
  2. There is no finish in same hole as started for position 5 (5, 8, 9)

Some other neat stuff came out of the exercise though! Among the more interesting observations is that while there are 1,550 solutions to starting hole 5, every single one of them finishes with the last peg standing in position 13! This means that in reality there are very few solutions to starting position 5.

Statistics

Just as the starting holes of 1, 11 and 15 are really the same puzzle rotated, there are numerous methods of solving the puzzle which are just variations of the same solution. If you switch a couple jumps in sequence, or jump in opposite directions, you can produce many more solutions which are really the same solution.

How many solutions are there for each starting hole? Glad you asked!

Start-PegWinnersLosers
12976017739865
2148809213994
3148809213994
48525835180925
515504528807
68525835180925
7148809213994
815504528807
915504528807
10148809213994
112976017739865
12148809213994
138525835180925
14148809213994
152976017739865
Total438,984227,632,755228,071,739
Peg game winning solutions and losing positions

Solutions posted online

In case anyone else wants to tear this apart, I have posted in CSV form, ALL of the 438,984 solutions to the game. You can download here. This file is 45MB in size.

Joe Nord

Triangle Peg Board Game – Solutions to amaze your friends

When visiting the Cracker Barrel restaurant, you will find a 15-peg triangle board game on each table.  This page describes how to solve the puzzle from any starting position.

Update: June 2021. Moved from web page to blog and added solutions for finish position equal start position.

The game board is a triangle with 15 holes in the same shape as bowing pins, except with an extra row.  The game starts with pegs (golf tees) in all the holes except one; the goal is to jump pegs one at a time, removing the jumped peg until only one peg remains.  The instructions on the board say that if you leave only one peg, you are a genius.  I suspect that the genius title is overstated, but if you follow the instructions on this page and you’re sure to impress the family!

For the pages that follow, the puzzle is viewed in this orientation and the hole numbers referenced.   

Triangle peg game hole numbers

Photographs follow showing the board from start of game through completion.

The normal starting hole (empty hole) is hole #1.  The initial discussion on this page shows how to solve the puzzle with hole #1 empty.  That is followed by instructions on how to solve for the other starting positions, with the happy addition that most of the starting positions are just variations of the standard #1 start.  After 3 moves, they all look the same; except the evil #5!

The first 3 jumps are:  4-1, 6-4 and 1-6.  With these complete, the “magic” base follows.  This shape will be referenced later in this document as the “goal position” for the other variations of the game using different starting holes.  Learning to solve the puzzle from this point is the key to success with the game.

The next moves, 7-2, 13-4 and 2-7. This shape is not too critical, the photo just shows the puzzle progressing.

The next steps are to clear the second from bottom row (the yellow tees) and the bottom row.

First, 10-8, 7-9 clears the second row.

15-13 and 12-14 clears the bottom.  To mix it up, jump them in reverse and it won’t look like you’re solving the puzzle the same way every time.

Almost there, the diagonal jump clears all but the bottom of the puzzle and the bottom clears “easy”.

6-13, 14-12 and 11-13 ==> Winner!

Starting position (1) – Full solution

41
64
16
72
134
27
108
79
1513
1214
613
1412
1113

For the other starting positions (except position 5 which we will cover later), the same solution is used after the third jump.  The “trick” is to get to the same pattern after the first three moves, the goal shape.  From there, solve solve as if it were starting position 1.   Notice that there is only one sequence to remember as you can get to the goal position from any of the starting positions based purely on shape.

Here are the moves for “after” the goal position is reached.

72
134
27
108
79
1513
1214
613
1412
1113

How many starting positions are there?

There are 15 pegs in the board, but only 4 starting positions.  For example, all the points are position “1”, even if they are otherwise called “11” or “15” the puzzle is the same once you rotate the board; even if only mentally.   2 and 3 are really the same if you view them “mirrored”.  Even if seen backwards, after the first 3 moves, both line up for the same standard solution.  Starting positions 4/6 are also swappable; 13 is the same as 4/6 once you rotate the board.

Here are all the starting positions.

11, 11, 15
22, 3, 7, 12, 10, 14
44, 6, 13
55, 8, 9

The neat thing to observe is that start positions 1, 2 and 4 and 11, 15, 3, 7, 12, 10, 14, 6 and 13 are really the same as they have the same solution once you get past the first 3 moves!   This means that there are only 2 puzzle solutions that need to be memorized to solve all positions on the puzzle.  If someone figures out how to get to the “magic” 3rd position when start with hole 5 empty, please let me know.

  • Update June 10, 2021 – there is no set of moves to get to magic position from “5”

First three moves for starting position (1, 11, 15 — Collectively called “1”).

Starting holeMove 1Move 2Move 3Comments
1, 11, 154-16-41-6 
2, 3, 7, 12, 10, 147-213-411-13Rotate right
4, 6, 1313-410-815-13Rotate left

The middle holes

I have not found a method to get to the “same as the others” solution when start with hole #5 (aka 8, 9).  A full solution follows and interestingly, it also ends with the final peg standing in hole 13; there must be a good reason.  With practice, solving this “hard one” is really just remembering that there are only 2 possible first moves and this solution starts from the right, the next couple moves are filling the pegs just jumped over or from and the 4th is opening the middle hole on the right side of the triangle.  From there, it pretty much solves itself! ?

145
79
27
64
72
14
156
310
1214
108
413
1412
1113

Finish hole same as start hole

Feedback from reader Merv Eberhardt provides an interesting twist on the above solution. He wanted a solution where the last peg ends up in the same position which was empty at the start. Taking genius to a new level…

The solutions below achieve this goal, and I note that they all also achieve the magic diamond after 3 moves, so it is really the finish that is varied to move the ending position from hole 13 as is listed above to instead finish at the position which was empty at start.

1 (11,15) 2 (10,12) 3 (7, 14) 4 (6,13)
4172103134
641341361513
1611131513108
10314121214310
1366134131214
31012141412413
156151311131315
7227310156
1113161414
14121037272
125382964
6413413627
4172103114
Peg Game solutions finishing in same hole as start

WordPress SMTP email notifications on GoDaddy

In setting up WordPress recently on this website, I discovered that getting SMTP working for blog email notifications was more complicated than I expected. This post shows the solution.

No, I don’t have the ability for anyone to post or comment yet, but someday that will come and it will be sure welcome to get notifications. In past, before moving to WordPress, I posted some nice content on things like how to tie boats up in canal for hurricane preparation, link. People commented and I saw the comments a month or more later. I send apologies to the folks that wrote comments that seemed to go into a black hole. Having notifications now working will allow me to be more timely in response and even will allow me to respond inquiries on “contact me”, assuming robots don’t send too much spam. Yes, they will. I know.

Convincing WordPress to send email notifications though was a tricky process. For starters, GoDaddy with CPANEL has TWO email systems:

  1. The right one, which is email system which is secureserver.net and
  2. CPANEL based site hosting of own mail server – yoursite.com/cpanel email accounts

The 1st one is the one needed to get email notifications to a place you can see them, so its the one to work with. The 2nd one is a distraction and will only send emails within your own domain. An interesting note is that in my prior usage of B2evolution, the automated setup of email in that tool configured the UNIX email system in “2”. This didn’t work but once I figured it out, wow were there a lot of emails in those invisible accounts.

Build an email account for sending messages

The first step is establishing an email address dedicated to this purpose and on GoDaddy, the way to define new email addresses is on the GoDaddy account management area, not in CPANEL of an individual domain. Logon at godaddy.com and then ignore the following panel in the top right which is a distraction. Hitting the main menu on the main website is NOT the way to define new email accounts. Here is the panel that you shouldn’t use.

The right place to define email address

The right place to define a new email address is https://account.godaddy.com/products. Scroll down, way down, and find Workspace Email. Click “Manage All”.

Now in the right place, define a new email address such as wpadmin@yourname.com or similar. Emails sent from blog system will come from this address. You should also set this up in your email program to verify it works. I note that it is POP3, not IMAP in my case and this has to be correctly configured or the email send/receive will not work. Once get the email account functioning, it is time to configure WordPress to send notifications via SMTP.

Configuring WordPress to send email

You would think this is as simple as installing a plugin in WordPress that knows how to use SMTP to send email, but there is more to it. A plugin is required and I selected Easy WP SMTP. The WordPress “Add Plugins” page looks like this.

After installing the plugin, it must be activated

The next step is to configure the plugin to use the email address earlier created. The first page of the settings is straight forward.

The second page of the settings is where the issues arise and where I hope this blog can help other folks who have got caught by the same confusion as me.

For me, the critical piece of missing information was explained in this youtube video by David Repasky. In that post he covered additional items, but the key material for me was learning that the port for SMTP send via smtpout.secureserver.net should be port 80 and not 465! Thank you David.

On the GoDaddy hosting, the UNIX machine hosting your website is close to local network and can talk to smptout.secureserver.net over ports that are not correct on the external Internet network. Notice that this means that information is traveling not encrypted on GoDaddy’s internal network segments. Is that a problem? I don’t know, but I must expect that GoDaddy have evaluated this configuration.

The final step is to send yourself a test message, as here.

With Easy WP SMTP configured as above, the email comes straight through and arrives almost instantly.

This took some time for me to dig through. I hope this write up helps others.

Joe Nord

Moving into WordPress

Updated my website to use version 8.0 of PHP and B2evolution stopped working. Was able to repair it enough to see blog posts again and managed to extract the content. This was the sign I needed to retire the old blog manager and move into the times with WordPress.

Technically I used WordPress before B2evolution, but it had some security issues that inspired me to move away. See blog post on this site about LAVE is Eval spelled backwards, link, and checking the date, wow, looks like that was 2014. From there, I moved to Blogger and some time after moved everything, except one post back to personal website. That post had wide reading and lots of links to it, so left it be.

Why did I select B2evolution? It was not WordPress and wasn’t something bad actors were attacking. I had become very tired of spam comments continuously showing up on on blog in prior usage of WordPress. Yes, this is security through obscurity, but hey, it worked.

Years gone by, it is 2021 and I move back to WordPress. I must say that with 7 years of active maintenance and enhancements, WordPress is very impressive compared to the B2evolution blogging system. I’ll write some posts on the experience.

Joe Nord

Keeping computer from waking immediately after it sleeps!

Bought a new computer a couple months ago and its nagged me since, that about half the time after the machine goes to sleep, it immediately wakes up.  Windows 10.  I’ve “solved” this so far, by holding the power button down until power is removed and that makes the machine quiet and without lights, but a better answer is to figure out why this thing is waking up immediately after sleeping.  The diagnosis and fix are detailed below.

Machine is an IBuyPower gaming computer, Windows 10 64-bit.  Comes with a very good Nvidia graphics card and big quiet fans, so winner.  Generally a good box, the machine has a bad habit of waking up immediately after it goes to sleep and that’s a headache.

Machine wakes up immediately after sleeping 

Click on Start / Power / Sleep and the computer immediately wakes.  This is normally followed by me pressing the power button for 5 seconds to tell the power supply to cut power to the machine and that generally makes the computer quiet, but this is not the right solution or behavior.

Took some time today to debug it and the problem is now solved.

Step 0 – Verify the machine is configured to sleep 

Start / Settings / Power & Sleep / Additional power settings (over on the right side)  / Choose what the power buttons do

And survey says that the power buttons are configured in Windows to tell the computer to sleep, okay, good.

Power Settings – Sleep when press power button

Step 1 – Figure out why the computer woke up 

Start / cmd (run as administrator).  It runs, then elevated power, run eventvwr.msc

This launches Microsoft Management Console, event viewer.  Scroll to System tab and scroll back in time to find out when and why the computer most recently woke from sleep.  Answer in this case is that the machine went to sleep at 23:57 UTC and woke up 6 minutes and 3 seconds later.  Odd, I thought it was 3 seconds total.  No matter, the time of this is just a curiosity, the real problem is that the event viewer says that it DOES NOT KNOW why the machine woke up. 

Event Viewer wake source not helpful


 Step 2 – Never trust a GUI 

 Command line tools can ask the system the same question and here, get a more helpful answer

C:\Windows\system32>powercfg -lastwake
Wake History Count - 1
Wake History [0]
  Wake Source Count - 1
  Wake Source [0]
    Type: Device
    Instance Path: PCI\VEN_10EC&DEV_8168&SUBSYS_E0001458&REV_16\01000000684CE00000
    Friendly Name: Realtek Gaming GbE Family Controller
    Description: Realtek Gaming GbE Family Controller
    Manufacturer: Realtek

OKAY – We have a hint.  Took me a while to figure out that “Gaming” in this case was just there to confuse matters, the real key is the “GbE”, which means Gigabit Ethernet.  Off to Device Manager to find this device and see if it is configured as a “wake source” for power management.

 Step 3 – Off to device manager to fix it 

Start / devmgmt.msc (run as administrator).

Locate network adapters in Device Manager. 

Device Manager – Network adapters

Find the Realtek Gaming GbE Family Controller, select it’s properties 

Clear checkbox – do not allow this device to wake computer

And success! Clear the checkbox for “Allow this device to wake computer” and the problem is solved.  If I were an enterprise, I might have some use for wake on LAN or similar, but here, I do not want the network adapter to be able to wake my machine and certainly don’t want it to in this case as it appears the Realtek Gigabit Ethernet is waking the computer for just about no reason at all. I hope this helps other people experiencing the same.

Joe Nord

Originally posted April 16, 2021

Stop windows from relaunching applications

When Windows 10 starts and users logon, the operating system by default will automatically restart all the applications that were running when the system was rebooted including launching them to reload the documents and revisit web browser URLs.  Handy in concept this is not how I want the machine to behave.  I would like a clean desktop, that looks the same everytime the machine boots. Thankfully, there’s a setting for this, not well advertised, but it does exit.

Search internet as I could, couldn’t find the answer, but after posting the question on twitter, the  question was quickly solved by @JenMsft on the Windows shell team.  

Answer: Settings, Accounts, Sign-in options, scroll down, “Use my sign-in info to automatically finish setting up my device and reopen my apps after and update or restart”.  By default, this is enabled, click the button to turn if off and everything now works … “as it should”.

Once I knew what to search for, was able to find the online documentation.  The option exists only in machines not part of a domain.  Appears I’m more of the enterprise user even on home computer. 

Warren Simondson  @Caditc  noted that that changing this setting enables or disables the following item in registry.

Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\UserARSO\<usersid>\OptOut

DWORD setting (boolean).  1 means “opt out” => do not restart applications at machine start.

As a once upon a time programmer of User Profile code, this has just become neat!  Why the in wholly h@ll is WinLogon using a HKLM based setting to control the behavior of a per-user setting when the user registry must already be loaded before launching the applications?   I note that this makes it really difficult to place this opt out into a default user profile to make this standard policy for the machine.  If anyone has good ideas to why the machine registry was used for this per-user setting, do please add them in the comments below.

Final thought: the above prevents a machine wide default of opting out.  There “could be” a separate setting to make that global and if I had to guess, it would be in the same WinLogon space with no SIDs.  Have not had a chance to check it, but its a possibility.

Joe Nord

Originally posted July 22, 2018

Explorer shows MP4 internal date rather than date of file on disk

Among the jobs of an operating system is to maintain the disk file system including the directory structure, file names and for each file, the file size and the pertitent date information for when the file was created, modified and potentially accessed.  I have been editing some videos lately and after producing a MP4 using ffmpeg; I used PowerShell to set the file create and modified times to the date that the video was recorded.  This makes it easier to sort and allows viewing software to display timelines, good things.  MP4 files also have an internal date that is set by cameras to note the datetime of when the video was recorded.  I was surprised to learn that Windows Explorer displays the MP4 date rather than the file date and this can be problematic if the MP4 file does not contain valid date data.  This post describes the issue in detail and provides steps for adjusting all the dates to the same datetime.

Notice the use of term “datetime” rather than “date” and “time”.  In Windows and its probably an ISO standard, computers store file dates and times as one field, which on Windows NTFS is a 64-bit signed count of 100ns periods since January 1, 1600.  The point is that it can handle splitting a second up into 100 pieces intervals per second and 64-bits is a bit enough space that it can accurately store both date and time for a very long time.  As users, we never see this and as programmers, we usually don’t need to worry about the detail of the field, its a 64-bit number that represents the file’s date and time in one go, “datetime”.  Since it’s one field, comparisons of before, after and same become very easy and can be done in one operation and since its signed, you can “”subtract” datetimes to figure out how long it was between two times.

Windows stores 3 datetime fields for every file on disk

  1. Created
  2. Modified
  3. Accessed

MP4 stores its own datetime of when the file was created – normally stored by a video camera assuming you remembered to set the clock!

On Windows NT systems, the Create date is not the date that the file was first created, it is the date that this specific file was created, so if you copy the file from one location to a new location, that new file will have a fresh Create date equal to “now” and if you then edit the image/video with a program, this will update the “modified” date and all concept of when the file was created will be lost.   Image and video cameras work to solve this by storing the date that the picture was taken of video recorded directly inside the image/video file.  

As a side note, the technique in PowerShell to adjust the fle create date back to what it is supposed to be is:

$fdate = "1941-12-07 07:00"    
$dname = Get-ChildItem ("Pearl*.jpg")
foreach ($name in $dname)
{
    Write-Output $name.FullName, $fdate;
    $name.CreationTime = $fdate
    $name.LastWriteTime = $fdate
}

In my recent case, the files were MP4, videos of the kids in their younger days and I had imported these from analog camera to computer and after processing through a few different tools, the last step was using ffmpeg to convert to MP4.  This worked great!  Then I set the CreationTime to the historic datetime of the video being recorded and … though I was done.

View with Windows Explorer and … the DATE DID NOT TAKE!

Explorer is showing that the video’s datetime is 12/31/1969 7:00pm.  That isn’t right!  

Compare the GUI view to command prompt view.  Never trust a GUI!

Command prompt has the “correct” datetime.

As the explorer GUI to show file details, and we have a match!  It is listed as “Media Created” date.

And use EXIFTOOL to show the innerds of the data and we have a winner! 

The dates inside the MP4 file are all zeros!  Actually, this makes sense.  I captured the video content from one tool, plumbed it through a few others, and out the other side, ffmpeg produced the MP4 file.  By the time it got there, the only record of the datetime that the video was recorded was in the name of the file.  The MP4 file has zeros as its internal record of when the file was created.

Sometimes things try to do too much

The job of an operating system is to maintain the file structure on disk.  Esoteric concepts like what is in the files for video editing applications, is IMHO an application responsibility.  BUT – Windows Explorer is trying to help out and is displaying the MP4 internal date rather than the Create, Modified, Accessed time from the file on disk.  Explorer is trying a bit to be a video display application, something that really isn’t its job.  Then again, it can also show thumbnails for images and … people like that.  Is it something that SHOULD be in an operating system?  The lines blur and we can all have a nice debate on whose job it is to display the video content and whose job it is to display the image/video content.

Back to reality – this is not showing the date that I want it to show and the solution is to either configure Explorer to show a different date field as date or to modify the MP4 files to have datetime information embedded.  “B” is the better solution.  I went looking on the internets and found this fine post on StackOverflow, link.  Bingo!  I am not the first person to have this problem.  In the post, Edward Brey even provides Visual Basic source code to modify the MP4 datetimes to be any date you want.  Awecome.  Took a bit to compile that up and ran it and everything looked good, but I wasn’t done.

In running the VB code to adjust the MP4 datetime, the file modified date was also modified, so I ran my PowerShell bat file one more time to modify the file date times and … by magic, the MP4 datetime is now incorrect. For some files, off by 5 hours, for others, off by 4.  A bit of study concluded that the 4 vs. 5 is daylight savings time or not of the date of the files set against the create time in the file.  When PowerShell (.NET) is adjusting the CreateTime, it is also adjusting the MP4 internal create date!  What?  Why.

  1. I did not ask PowerShell to adjust the datetimes that are in the file contents, only the file “date”.  But, the embedded date in the MP4 file did change!
  2. And we’re back to the job of operating systems vs. the job of applications, but this could be a very long diversion

And its worse.  The MP4 datetime was “correct” per me in the before and after setting the datetime of the file create date, the MP4 datetime was now incorrect by a period of time equal to number of timezones away from GMT on the date that the file was recorded.

I studied this for about a day and concluded that MP4 internal datetimes are the datetime that the file was created/recorded/modified and that time shall always be ZULU!  The VB code didn’t know if the time I gave it was local time or GMT/UTC/Zulu, so it went with what it had.  When the file CreatedData was set from PowerShell, the .net runtime decided to help out and ajust the MP4 datetime to match the create date on the file itself.  

Okay, problem now understood and dates all adjusted.  What is “odd” is that if PowerShell and .NET adjust the date of the MP4 file when the internal date is concluded “wrong”, why doesn’t it also do that when the internal datetime is zeros?  Consistency here would be a win.

Please add your comments below.  If you want the compiled version of the program to adjust the MP4 internal dates, drop a line and I’ll send your way.  email to joe at this domain.

Joe Nord

Originally posted Dec 22, 2018

DOS New Executable .EXE file format

The DOS world’s need for memory grew and the 64KB available to .COM executables was no longer adequate.  The NE “new executable” executable file format was invented and uses the .EXE file extension rather than .COM.  The first 2 bytes of these files includes a tag at the front to identify the format and if you guessed that this was “NE” to denote “new executable”, you’d be incorrect.  The first 2 bytes of every .EXE file are “MZ” famously because the name of the programmer at Microsoft who wrote the code was “Mark ZbikoNwski”.

The EXE file format allowed multiple segments to be defined, and included ability for separate compilation of portions of the program, and SDKs.  That is, different parts of the program could be compiled into .OBJ files, and then a LINK step is performed to assemble the resulting EXE file.  This enabled many good things like separate compilation of varied portions of programs and the ability to purchase libraries of code from other developers without them having to provide source code.  The NE format also permitted programs to be “large”, occupying space to all the memory available on the DOS computers.

I intended to write a detailed description of this evolution of file formats here, but there’s no need, it’s been well done in detail by others and I provide here a links here

Cutting to the meat of it, the NE (MZ) format executable has these portions

  1. Header
  2. Relocation list
  3. Code

Which is really

  1. Header
  2. Relocation list
  3. <Code>
  4. [Code]
  5. […]

The Header includes information for allocating a heap and a stack.  One grows up, one grows down, when they collide, the application is out of memory.  Notice that this is still DOS so it isn’t like the operating system is going to do anything when the application collides it’s memory.  Still, the executable format is starting to grow into a real concept of an operating system, with a loader.

The Code and Relocation list can use a bit more description as there can be multiple code regions, each limited to 64-KB (size of a SEGMENT).

The executable is defined in segments, each of which is loaded into memory at a paragraph boundary (16 byte boundaries).  The SEGMENT of that paragraph of memory can be addressed using the segment registers as 16:16 segment:offset addressing converts to physical address by shifting the segment left 4 and adding the offset.  At this time in the life of Intel processors, there was no such thing as virtual addresses.  The 8086 CPU is a pretty straight forward machine.  Segment:Offset converts staight to physical and when the CPU addressed it, it actually went all the way to the ISA bus where memory would respond.

After loading each code segment into RAM, the DOS loader applies the fixup records so that code calling between segments can call the 16:16 addresses where the program segment is actually loaded at runtime.  There is NO provision for DLL’s or dynamic linking.

This file format was the primary format for DOS computers through the long life of the DOS operating system and it is still with us today.  The modern PE file format includes a NE/MZ format executable as a “DOS Stub” at the front.  This is primarily so that programs intended for Windows 3.11 or OS/2 could display a message along the lines of “this program is intended to execute under Windows” and then the stub terminates.  Creative programmers can use the DOS stub to run a DOS version of a program when on DOS and a Windows or OS/2 version of program when on those operating systems.  We’re on a journey here; PC operating systems are starting to look like “real computers”.   The next post will take us into modern times of about 1990.

DOS .COM file review

In the beginning, the DOS .COM file format was the format for executables of size less than 64KB and let’s face it, who would really need more.  I’m headed down a path to discuss PE file format executables and no good discussion is right without a foundation.  In the beginning, there was DOS; life was simple and there was nothing between you and the computer.  This post describes the early executable .COM file format showing code, data, everything that you need for small executables!

The .COM file format was simple.  The whole program had to be less that 64KB in size.  Technically less than 64KB minus 0x100 bytes, but stick with me.  To run a program, DOS allocated memory for the size of the file, loaded the entire file contents into memory and … branched to it via a “call” instruction.  Simple stuff, absolutely no runtime fix ups, no DLL records, no DLLs!, heck no linked operating systems APIs that you could call!  Need something in your program?  You should make it part of your 64KB because that’s all there is!

Going from memory today because a DOS computer is not readilly available, the offset (IP) at the start of execution was 100 hex bytes.  Notice I didn’t say into the starting segment, there was only ONE segment.  Code, data, everything in one place with absolutely no distinction between anything.  The verbatim bytes from the .COM file are placed into memory at CS:100, and DOS calls it.  Did the program work or not?  DOS didn’t care, it loaded it into memory and … “called” it.  Everything else was bonus time.  If the machine managed to not become a colored checkerboard mess during the life of the program, the program could eventually “return” and execution would go back to DOS who would put you back at the COMMAND.COM prompt.

Sample program

Though I have no DOS computer readily available, I do have old programs.  The smallest and easist for show and tell is one I wrote with some friends in 1988 to efficiently reboot a computer skipping the memory test during boot.  The program is … 16 bytes and performs the same activity as Ctrl-Alt-Delete including setting a flag to tell the BIOS to skip the memory test on boot.  Interestingly, we wrote this using debug.com and the “a’ command so there is no source and … there never was any source.  To show what does, need a disassembler that understands 16-bit intel little endian assembly language and DEBUG.COM from DOS would do it, but again, no DOS handy.  Found a suitable disassembler online at shell-storm, here, but first need hex. Using my own HexDump utility, get these hex bytes

*
* input file: boot.com
*
* OFFSET  +0       +4         +8       +C
 00000000 B840008E D8C70672 - 003412EA 5BE000F0
*
* 16 bytes converted

Feed that into the disassembler above and get the below.  I added the comments.

0x0000: mov ax, 0x40                ; Establish vision to the BIOS data area
0x0003: mov ds, ax                  ; Data segment is 40 equals physical address 400
0x0005: mov word ptr [0x72], 0x1234 ; set 40:72 to 0x1234 (BIOS Flag for fast reboot)
0x000b: ljmp 0xf000:0xe05b          ; Branch to BIOS "reboot" code

When run that, these 4 instructions are “it”. DOS loads the code into memory at offset 100h, and branches (calls) to the first byte.  That’s it.

These were simple times and it was downright impressive what could be accomplished in 64KB, or in this case, in 16 bytes.  This program reboots the machine, so there is no need for the code above to include return logic, but it could be done with a “ret” instruction or you could issue the DOS system call to terminate with a return code.

Calling runtime services

These early systems didn’t have library linkage or DLL fixups – there were no .LIBS or .DLLS and “that’s the way we liked it”.  If you wanted to call the operating system to do something useful like display a string or read a file, you loaded up some registers and kicked off an “int 21h” to call DOS.  YES – software issuing equivilant of hardware interrupts to call the operating system!  Its DOS, do what you want!  The DOS programming references told you what to put in registers before the call, issue the DOS interrupt and things happen.  Get the parameters wrong, the machine could be hosed – but hey!  It was your machine and there was very little that couldn’t be cured with a Big-Red-Switch or a Ctrl-Alt-Delete or as this program demonstrates, having a batch file call a program named “boot.com” to accomplish the same end.

Compatibilty with CPM

With a joke at the start of this post that that nobody would ever need more than 64KB, the real story of .COM in DOS is that it would provide application backward compatibility with the 16-bit (64KB is all you get) CPM operating system.  DOS was written to the abilities of the 8088/8086 Intel CPUs and these had an segment:offset based addressing limit of 20 bits equals 1MB.  The segment was shifted left 4 and offset added to get physical address.  CPM executable format was 64KB flat memory with no segments.  If you were designing DOS for an 8086/8088 and wanted backward compatibiltiy with the existing apps at the time, this made it possible.  Load an application into memory, pre-set the CS, DS, ES and SS segment registers to point to the loaded SEGMENT (paragraph boundary memory) and “call” the loaded program and it would run the whole time being blissfully unaware that the machine supported segment:offset addressing. Next, we move forward to the New Executables!

Joe Nord

Originally posted Feb 08, 2018

Outlook – Allow website to configure

Had an interesting one today when outlook 2016 prompted me to permit a website to configurre email settings for a user that isn’t me.  In this case, it was for a user that doesn’t work at my company anymore and this led me to ponder if someone in IT was trying to connect me to the no longer here user’s email inbox.  Answer, no.

There are many descriptions of this dialog on the web but they all seem to end with telling outlook to never do autodiscover; I didn’t want that, instead wanted to solve the issue and leave configuration items untouched.    Try all the easy things to get this dialog to go away, it continued to be shown on each fresh launch of Microsoft outlook, but the mystery is now solved.

The username@company.com email address presented by the dialog is 1) valid, 2) is not me, and 3) is for a user that no longer works at my company.  The email inbox link up didn’t make sense so I did some more digging and concluded that it was calendars.  Ctrl-2 to see calendars and view “shared calendars” and sure enough I have a non-checked item for this user.  I am not viewing his calendar, but I did once upon a time and outlook seems to remember that.  

Clear that user from the list of shared calendars, close outlook, reopen and … presto, problem solved.

Hopefully this helps someone else.  Enjoy.

Joe Nord

Originally posted Feb 07, 2018

2 comments

Comment from: Ian Visitor

Thanks, it seems to have done the trick. I had a work’s calendar in shared. I was reluctant to press okay as I’ve made the mistake of accepting similar before. I use my own laptop to read work’s emails and when pressing something like this in the past, meant the work’s IT took over the settings for my laptop.
So of course I was reluctant to do the same.

07/23/18 @ 02:24 pm

Comment from: Ian Visitor

spoke too soon…back again…sorry about that. 07/24/18 @ 10:19 am