Coding
2025/07/19
Posted Tag: #Personal
Other Tags: #Linux, #Windows, #All
I have used Assembly , 'C', JavaScript, Perl and Windows Batch and Linux Bash. I realize Assembly and 'C' are the only programing languages with the rest being scripting. But I was watching a video today about the guidance computers on the Apollo 11 mission to the moon and how the program they used was written in Assembly. That got me remembering things.
I was working for a defense contractor in Virgina when we lost a contract for a period of time. I do not know the specifics of what happened but they paid me for months with no contract. But they needed to keep us employed to get another contact. I had a Windows computer on my desk and found a 'C ' complier in a cabinet. I installed it on my computer. Nobody objected to me doing this since I was keeping myself busy. I bought a book entitled "C By Example" and still have it here on my desk. It is well worn because I went through the entire book to learn 'C'.
But before I starting to learn 'C', in Windows there was a file named debug.exe. You could type assembly language in a .asm
text file and use debug.exe to compile it to a .com
file. So I actually started coding in assembly language in Windows. I wrote an assembly program where I placed the resulting .com
file in the autoexe.bat file of a work associates computer. When his computer booted he got a one line display in the lower left of his screen with nothing else of about 10 alphanumeric characters that started off with 'X' characters. They began rotating as though it was trying to break a code or something. The file took a word as input. Random characters of this word would start appearing till the entire word was shown. I do not remember the word I used with his computer but if he pressed the Enter key his computer shutdown.
As far as 'C ', I wrote a little program for Windows 3.1 that placed an icon on the Desktop. If you double-clicked it a dialog would display with Options, Cancel, Restart and Exit buttons. I had a dialog for options. I released it as shareware and a librarian at the University of Kentucky sent me an email thanking me for it saying they had placed it on all the computers they had. Here is the 1997 code.
#define strict
#include <windows.h>
#include <stdlib.h>
#include "quickx.h"
//Definitions ---------------------------------------------
#define IDM_OPTIONS 1
#define IDM_ABOUT 2
//Globals -------------------------------------------------
static char szAppName[] = "QuickX"; //Program name
static char szINI_fName[128]; // INI file name
static int Dis_Prompt; //Prompt display status
static int Restart; //Restart status
//*********************************************************
// WinMain
//*********************************************************
#pragma argsused
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpszCmdLine, int nCmdShow)
{
int i; //Used during the hunt for the INI file
HWND hWnd;
HMENU hMenu; //Used for system menu handle
MSG msg;
WNDCLASS wndclass;
if(hPrevInstance) //If a program instance exist, stop and return
{ return 0; }
wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(hInstance, "QUICKX");
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;
!RegisterClass(&wndclass);
hWnd = CreateWindow(szAppName, "QuickX", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
//Get handle to the window's system menu and add items to it
hMenu = GetSystemMenu(hWnd, 0);
AppendMenu(hMenu, MF_SEPARATOR, 0, NULL);
AppendMenu(hMenu, MF_STRING, IDM_OPTIONS, "&Options...");
AppendMenu(hMenu, MF_STRING, IDM_ABOUT, "&About...");
//Find program directory
i = GetModuleFileName(hInstance, szINI_fName, sizeof(szINI_fName));
//Find INI file
while(szINI_fName[i--] != '.');
lstrcpy(&szINI_fName[i+2], "INI");
//Read Dis_Prompt and Restart status from the INI file
Dis_Prompt = GetPrivateProfileInt(szAppName, "Dis_Prompt", 1,
szINI_fName);
Restart = GetPrivateProfileInt(szAppName, "Restart", 0,
szINI_fName);
ShowWindow(hWnd, SW_SHOWMINNOACTIVE); //Show the window as an icon
UpdateWindow(hWnd);
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
//*********************************************************
// Window procedure
//*********************************************************
#pragma argsused
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam,
LPARAM lParam)
{
static HINSTANCE hInstance; //Instance for use by dialog boxes
switch(message)
{
case WM_CREATE:
{
//Get pointer to program instance / store in hInstance
hInstance = ((LPCREATESTRUCT)lParam) -> hInstance;
return 0;
}
// Respond to About and Options menu selections
case WM_SYSCOMMAND:
{
switch(wParam)
{
case IDM_ABOUT:
{
static DLGPROC lpfnAboutProc;
lpfnAboutProc = MakeProcInstance((DLGPROC)AboutProc,
hInstance);
DialogBox(hInstance, "ABOUT" , hWnd, lpfnAboutProc);
FreeProcInstance((DLGPROC)lpfnAboutProc);
return 0;
}
case IDM_OPTIONS:
{
static DLGPROC lpfnOptionsProc;
lpfnOptionsProc = MakeProcInstance((DLGPROC)
OptionsProc, hInstance);
DialogBox(hInstance, "OPTIONS" , hWnd, lpfnOptionsProc);
FreeProcInstance((DLGPROC)lpfnOptionsProc);
return 0;
}
}
break;
}
/* Capture QUERYOPEN so that the window will remain an icon
when double-clicked / post a double-click message in the
message queue and direct it to this window procedure */
case WM_QUERYOPEN:
{
PostMessage(hWnd, WM_LBUTTONDBLCLK, 0, 0);
return 0;
}
/* Process double-click message from QUERYOPEN / display or
don't display prompt box / exit or restart Windows */
case WM_LBUTTONDBLCLK:
{
static int XCode = 1;
if(Dis_Prompt) //Display prompt if Dis_Prompt = True
{
if(Restart) //Display Restart prompt if Restart = True
{
static DLGPROC lpfnR_Prompt;
lpfnR_Prompt = MakeProcInstance((DLGPROC)R_Prompt,
hInstance);
//Set XCode for value returned from dialog
XCode = DialogBox(hInstance, "R_PROMPT" , hWnd,
lpfnR_Prompt);
FreeProcInstance((DLGPROC)lpfnR_Prompt);
//Fall to XCode switch
}
else //Display Exit prompt if Restart = False
{
static DLGPROC lpfnE_Prompt;
lpfnE_Prompt = MakeProcInstance((DLGPROC)E_Prompt,
hInstance);
//Set XCode for value returned from dialog
XCode = DialogBox(hInstance, "E_PROMPT" , hWnd,
lpfnE_Prompt);
FreeProcInstance((DLGPROC)lpfnE_Prompt);
//Fall to XCode switch
}
}
else //Don't display prompt if Dis_Prompt = False
{
if(Restart) //Set for restart of Windows if Restart = True
{
XCode = 3; //Set XCode for restart of Windows
//Fall to XCode switch
}
else //Exit Windows if Dis_Prompt and Restart = False
{
ExitWindows(0, 0);
return 0;
}
}
// Exit Windows as per value of XCode
switch(XCode)
{
case 1: //OK button
{
ExitWindows(0, 0);
return 0;
}
case 3: //Restart button or Restart value in INI file
{
ExitWindows(EW_RESTARTWINDOWS, 0);
return 0;
}
}
return 0;
}
case WM_DESTROY:
{
PostQuitMessage(0); //Close program
return 0;
}
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
//---------------------------------------------------------
// About dialog box procedure
//---------------------------------------------------------
#pragma argsused
BOOL CALLBACK AboutProc(HWND hWnd, UINT message, WPARAM wParam,
LPARAM lParam)
{
switch(message)
{
case WM_INITDIALOG:
{
int xPos, yPos;
RECT rectBox;
/*Arrive at an x and y position to center upper left corner
of the dialog on the desktop */
//Get size of desktop / split vertical in half to find center
GetWindowRect(GetDesktopWindow(), &rectBox);
xPos = (rectBox.right - rectBox.left) / 2;
yPos = (rectBox.bottom - rectBox.top) / 2;
//Get size of window / find center / x = upper left corner horizontal
GetWindowRect(hWnd, &rectBox);
xPos = max(0, xPos - (rectBox.right - rectBox.left)/2);
yPos = max(0, yPos - (rectBox.bottom - rectBox.top)/2);
//Position dialog as per xPos and yPos
SetWindowPos(hWnd, 0, xPos, yPos, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
ShowWindow(hWnd, SW_SHOW);
return 1;
}
case WM_COMMAND:
{
switch(wParam)
{
case IDOK:
{
EndDialog(hWnd, 0);
return 1;
}
}
break;
}
}
return 0;
}
//---------------------------------------------------------
// Options dialog box procedure
//---------------------------------------------------------
#pragma argsused
BOOL CALLBACK OptionsProc(HWND hWnd, UINT message, WPARAM wParam,
LPARAM lParam)
{
static int OldDis_Prompt;
static int OldRestart;
switch(message)
{
case WM_INITDIALOG:
{
int xPos, yPos;
RECT rectBox;
/*Arrive at an x and y position to center upper left corner
of the dialog on the desktop */
//Get size of desktop / split vertical in half to find center
GetWindowRect(GetDesktopWindow(), &rectBox);
xPos = (rectBox.right - rectBox.left) / 2;
yPos = (rectBox.bottom - rectBox.top) / 2;
//Get size of window / find center / x,y = upper left corner
GetWindowRect(hWnd, &rectBox);
xPos = max(0, xPos - (rectBox.right - rectBox.left)/2);
yPos = max(0, yPos - (rectBox.bottom - rectBox.top)/2);
//Position dialog as per xPos and yPos
SetWindowPos(hWnd, 0, xPos, yPos, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
ShowWindow(hWnd, SW_SHOW);
//Save present status just in case dialog box is canceled
OldDis_Prompt = Dis_Prompt;
OldRestart = Restart;
//Set radiobuttons as per INI file entry
switch(Dis_Prompt)
{
case 0:
{
SendDlgItemMessage(hWnd, IDC_NO_DISPLAY, BM_SETCHECK,
1, 0);
break;
}
case 1:
{
SendDlgItemMessage(hWnd, IDC_DISPLAY, BM_SETCHECK,
1, 0);
break;
}
}
if(Restart) //Set Restart button if Restart = True
{
SendDlgItemMessage(hWnd, IDC_RESTART, BM_SETCHECK, 1, 0);
}
return 1;
}
case WM_COMMAND:
{
switch(wParam)
{
case IDOK:
{
char szVer[] = "2.0, 2/15/97, Dale Roberts";
char szEntry[2];
char szEntry2[2];
//Convert Dis_Prompt and Restart into strings
itoa(Dis_Prompt, szEntry, 10);
itoa(Restart, szEntry2, 10);
//Write Dis_Prompt / Version to INI file
WritePrivateProfileString(szAppName, "Version",
szVer, szINI_fName);
WritePrivateProfileString(szAppName, "Dis_Prompt",
szEntry, szINI_fName);
WritePrivateProfileString(szAppName, "Restart",
szEntry2, szINI_fName);
EndDialog(hWnd, 0);
return 1;
}
case IDCANCEL:
{
//Revert back to previous Dis_Prompt and Restart status
Dis_Prompt = OldDis_Prompt;
Restart = OldRestart;
EndDialog(hWnd, 0);
return 1;
}
case IDC_DISPLAY:
{
Dis_Prompt = 1;
if(Restart) //Set Restart button to Restart status
{
SendDlgItemMessage(hWnd, IDC_RESTART, BM_SETCHECK, 1, 0);
}
else
{
SendDlgItemMessage(hWnd, IDC_RESTART, BM_SETCHECK, 0, 0);
}
return 1;
}
case IDC_NO_DISPLAY:
{
Dis_Prompt = 0;
if(Restart) //Set Restart button to Restart status
{
SendDlgItemMessage(hWnd, IDC_RESTART, BM_SETCHECK, 1, 0);
}
else
{
SendDlgItemMessage(hWnd, IDC_RESTART, BM_SETCHECK, 0, 0);
}
return 1;
}
case IDC_RESTART:
{
if(Restart) //Set Restart button to Restart status
{
Restart = 0;
SendDlgItemMessage(hWnd, IDC_RESTART, BM_SETCHECK, 0, 0);
}
else
{
Restart = 1;
SendDlgItemMessage(hWnd, IDC_RESTART, BM_SETCHECK, 1, 0);
}
return 1;
}
}
return 1;
}
}
return 0;
}
//---------------------------------------------------------
// Exit Prompt dialog box procedure
//---------------------------------------------------------
#pragma argsused
BOOL CALLBACK E_Prompt(HWND hWnd, UINT message, WPARAM wParam,
LPARAM lParam)
{
switch(message)
{
case WM_INITDIALOG:
{
int xPos, yPos;
RECT rectBox;
/*Arrive at an x and y position to center upper left corner
of the dialog on the desktop */
//Get size of desktop / split vertical in half to find center
GetWindowRect(GetDesktopWindow(), &rectBox);
xPos = (rectBox.right - rectBox.left) / 2;
yPos = (rectBox.bottom - rectBox.top) / 2;
//Get size of window / find center / x,y = upper left corner
GetWindowRect(hWnd, &rectBox);
xPos = max(0, xPos - (rectBox.right - rectBox.left)/2);
yPos = max(0, yPos - (rectBox.bottom - rectBox.top)/2);
//Position dialog as per xPos and yPos
SetWindowPos(hWnd, 0, xPos, yPos, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
ShowWindow(hWnd, SW_SHOW);
return 1;
}
case WM_COMMAND:
{
switch(wParam)
{
case IDEXIT: //If EXIT return 1 to WndProc
{
EndDialog(hWnd, 1);
return 1;
}
case IDCANCEL:
{
EndDialog(hWnd, 0);
return 1;
}
case IDRESTART: //If RESTART return 3 to WndProc
{
EndDialog(hWnd, 3);
return 1;
}
}
break;
}
}
return 0;
}
//---------------------------------------------------------
// Restart Prompt dialog box procedure
//---------------------------------------------------------
#pragma argsused
BOOL CALLBACK R_Prompt(HWND hWnd, UINT message, WPARAM wParam,
LPARAM lParam)
{
switch(message)
{
case WM_INITDIALOG:
{
int xPos, yPos;
RECT rectBox;
}