terug.gif
#include "windows.h" /* required for all Windows applications */
#include "windowsx.h" /* required for all Windows applications */
#include <shellapi.h>
#include <mmsystem.h>
#include <string.h>
#include <stdlib.h>
#include <sys\stat.h>
#include <sys\timeb.h> // For extended timer definitions
#include <time.h>
#include <stdio.h>
#include <io.h>
#include "select.h"
#include <ddeml.h>
#include "wat.h"
#include "watom.h"
#include "midiout.h"
#include "midi_cb.h" // header file for DLL containing callback
#define min(a,b) (((a) < (b)) ? (a) : (b))
#define max(a,b) (((a) > (b)) ? (a) : (b))
#define PRINTING // needed so constants are defined
// 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
#define SPACE " "
#ifndef _GLOBALINC
#include "global.h"
#endif
#include <drivinit.h> // contains printing constants
BOOL bKey = FALSE;
unsigned char regels; // aantal afgedrukte regels in pagemode
BOOL bSchermstatus; // controle voor tekst naar scherm sturen
BOOL bPrinterstatus; // controle voor teken naar printer sturen
BOOL bPagemode = TRUE; // controle voor pagemode aan/uit
BOOL bCapsstatus; // status van de caps lock toets
BOOL bClear0;
BOOL		bJoystick = FALSE;
BOOL		bMidi = FALSE;
JOYCAPS 	jc;			// karakeristieken van het ding
JOYINFO 	ji, JoyRev; // huidige waarde en referentiewaarde
BOOL		bJoy;			// status of er een joystick is
unsigned char commandonr; // gebruikt voor opslag van commando nummer
unsigned char msb = 0xff; // controle bit voor bit7 wel of niet strippen
unsigned char kleur = 7; // tekst atribuut bij opstarten
unsigned char rvenster_ylo; // waarde in ini files
unsigned char rvenster_xrb; // waarde in de ini files
unsigned char venster_xlo =0; // coordinaten tekstvenster
unsigned char venster_ylo = 16; //
unsigned char venster_xrb=64; //
unsigned char venster_yrb = 0; //
unsigned int gwindow_xlo = 0; // coordinaten grafisch venster
unsigned int gwindow_ylo = 0; //
unsigned int gwindow_xrb = -1; //
unsigned int gwindow_yrb = -1; //
unsigned int oorsprong_x = 0; // offset voor grafische oorsprong
unsigned int oorsprong_y = 0; //
unsigned char schermpag = 0; // schermpagina nummer voor bewerking
unsigned char prnnr = 0; // nummer van geselecteerde printerpoort
unsigned char joystat; // de status van de bits als B000
unsigned char cenr; // critical errornummer
unsigned char adres_b000; // emulatie adres
unsigned char bEnd = FALSE; // nee, we zijn nog niet klaar
unsigned char bCursor = TRUE; // default wel een cursor
unsigned char scale_x=1, scale_y=1; // default vergroting
int rb_xco, rb_yco;
unsigned int iobase;
int xco=0, yco=0; // actuele cursor positie
BOOL bShift, bCaps, bCtrl;
BYTE bscan, bascii;
BYTE BitMapBits[24][1024];
HBITMAP hBitmap[24];
BITMAPINFOHEADER Bi;
LPBITMAPINFOHEADER lpbi;
HANDLE hDIB[24];
LPSTR lpstBitmap, lpstTemp;
BOOL bGraph = FALSE;
WORD		j_l, j_r, j_b, j_o;
BOOL		bPlane[24] = {
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE
};
// waarden voor de externe printroutine
extern PRINTINFOSTRUCT pis;
// waarden voor de handeling van de windows
HINSTANCE hInst; /* current instance */
PAINTSTRUCT ps ;
TEXTMETRIC tm ;
HFONT hFont;
HBRUSH hBrush;
RECT hRect;
HFONT hOldFont;
RECT Rect;
int Shape = SL_BLOCK; // shape to use for the selection
FARPROC lpProcAbout; // pointer to the "About" function
int cxIcon, cyIcon; // size of the icon
// waarden voor het bewerken van de ingekomen pagina
unsigned long kleurtbl[] = {
RGB( 0, 0, 0), // zwart
RGB(255, 0, 0), // rood
RGB( 0, 255, 0), // groen
RGB(255, 255, 0), // geel
RGB( 0, 0, 255), // blauw
RGB(255, 0, 255), // magenta
RGB( 0, 255, 255), // cyaan
RGB(255, 255, 255), // oewit
RGB(191, 191, 191), // oewit na twee keer in de dreft
};
// waarden voor het afhandelen van de cursor en de cursor positie
int cxChar, cyChar, cxClient, cyClient;
int x, y, i ;
// variabelen tbv DDE
char szAppName [] = "Watom";
char szTopic [] = "WATOM" ;
DWORD idInst ;
char scherm[50][99];
// variabelen voor de clipboard besturing
int xco_sto, yco_sto, xco_sta, yco_sta;
HDC hdcMem;
BITMAP Bitmap; // bitmap structure
BOOL bTrack;
int nHeight,
nWidth,
index;
unsigned int result;
int defver, defhor, defwidth, defheight;
// div zaken voor font
ABC abc[26];
int dHeight, dWidth;
HCURSOR		hCursor;
int a=0x20;
FILE		*prnfile;
HMIDIOUT hMidiOut ;
TIMECAPS tc ;
UINT nTimerID, nTimerRes ;
LPMIDISONG lpMidiSong ;
LPMIDIDATA lpMidiData, lpmd ;
HANDLE hGmem1 = NULL, hGmem2 = NULL ;
BYTE		resettype=0; 
long FAR PASCAL _export WndProc (HWND, UINT, UINT, LONG) ;
HWND hwnd ;
#pragma argsused
int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance,
		 LPSTR lpszCmdLine, int nCmdShow)
{
MSG msg ;
WNDCLASS wndclass ;
HMENU hMenu;
ReadProfile();
hInst = hInstance;
if (!hPrevInstance) {
wndclass.style = CS_CLASSDC;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInst ;
wndclass.hIcon = LoadIcon (hInst, IDI_APPLICATION) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH) ;
wndclass.lpszMenuName = "AtomMenu";
wndclass.lpszClassName = szAppName ;
RegisterClass (&wndclass) ;
}
hwnd = CreateWindow (szAppName, "Atom Outside", WS_OVERLAPPEDWINDOW,
defhor, defver, defwidth, defheight,
// CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,
NULL, NULL, hInstance, NULL) ;
if (hwnd) {
hMenu = GetSystemMenu (hwnd, FALSE); // Handle to sysmenu copy
AppendMenu (hMenu, MF_SEPARATOR, 0, NULL); // Append a separator line
AppendMenu (hMenu, MF_STRING, IDM_ABOUT, "&About..."); // Last item is About Box
hCursor = LoadCursor(hInstance, "Cursor_4");
ShowWindow (hwnd, nCmdShow) ;
bPrinterstatus = FALSE;
bSchermstatus = FALSE;
bPagemode = FALSE;
schermpag = 0;
RESET(iobase); // reset the atom
initerror(); // init de error tabellen
UpdateWindow (hwnd) ;
while (TRUE) {
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
if (msg.message == WM_QUIT)
break;
	 TranslateMessage (&msg) ;
	 DispatchMessage (&msg) ;
}
	 else {
result = READBYTE(iobase);
if (HIBYTE(result) == 0xff) {
Process(LOBYTE(result));
	 }
}
}
return msg.wParam ;
}
else
return FALSE;
}
#pragma argsused
long FAR PASCAL _export WndProc (HWND hWnd, UINT msg, UINT wParam, LONG lParam)
{
static POINT org;
static POINT len;
// var voor textcopyclipboard
int xx, yy;
HANDLE hGlobalMemory;
LPSTR lpGlobalMemory;
int wLength = 100;
HBITMAP hBitmap;
HDC hdc;
HMENU hMenu;
int nFiles, aantal;
char cBuf[128];
MSG usermsg;
DWORD bkcolor, fgcolor;
UINT nThreshold;
POINT ptCurrent;
JOYINFO ji;
static BOOL	bJoyFirst = FALSE;
static JOYINFO jir ;
static unsigned long joyX, joyY;
switch (msg) {
case WM_CREATE:
	 Watom_OnCreate(hWnd, msg, wParam, lParam);
	 return 0 ;
case WM_DROPFILES:
nFiles = DragQueryFile((HDROP) wParam, (UINT) -1, NULL, 0);
for (i=0; i<nFiles; i++) {
	 char cmd[50];
	 char del = '"';
	 int j;
	 DragQueryFile((HDROP) wParam, i, cBuf, 128);
	 sprintf(cmd, "*LOAD %c%s%c", del, cBuf, del);
/*	 for (j=0; j< strlen(cmd); j++) {
	 SendMessage (hWnd, WM_KEYDOWN, cmd[j], 1L) ;
	 SendMessage (hWnd, WM_KEYUP, cmd[j], 1L) ;
	 Sendkeys
	 } */
	 MessageBox(hWnd, cmd, "debug", MB_OK);
	 }
DragFinish((HDROP) wParam);
return 0;
case WM_SIZE:
Watom_OnSize(hWnd, msg, wParam, lParam);
return 0 ;
case MM_JOY1MOVE:
if (bJoyFirst == FALSE) {
	 joyGetPos(JOYSTICKID1, &jir);		// plaats referentiewaarde
	 joyX = jir.wXpos / 2;
	 joyY = jir.wYpos / 2;
	 bJoyFirst = TRUE;
	 }
joyGetPos(JOYSTICKID1, &ji);	// kan ook vanuit wParam
joystat = 0xff;			// alle bits aan
if (ji.wXpos < jir.wXpos - joyX) {
	 joystat &= 0xfd;		// schoon als deze richting op
	 }
else if (ji.wXpos > jir.wXpos + joyX) {
	 joystat &= 0xf7;
	 }
if (ji.wYpos < jir.wYpos - joyY) {
	 joystat &= 0xef;
	 }
else if (ji.wYpos > jir.wYpos + joyY) {
	 joystat &= 0xfb;
	 }
if ((ji.wButtons & JOY_BUTTON1) == 1)
	 joystat &= 0xfe;
return 0;
case MM_JOY1BUTTONDOWN:
if (wParam & JOY_BUTTON1)
	 joystat |= 0x01;
return 0;
case MM_JOY1BUTTONUP:
if (!wParam & JOY_BUTTON1)
	 joystat &= 0xfe;
return 0;
case WM_PAINT:
Watom_OnPaint(hWnd, msg, wParam, lParam);
return 0 ;
case WM_MIDI: // convenient place to free memory blocks
if (hGmem1)
	GlobalFree (hGmem1) ;
if (hGmem2)
	GlobalFree (hGmem2) ;
hGmem1 = hGmem2 = NULL ;
return 0;
case WM_USER_CHAR:
aantal = (int) LOWORD (lParam);
for (i = 0 ; i < aantal; i++) {
	 if (bSchermstatus == TRUE) {
	 switch (wParam) {
		 case CTRL_H: // backspace
		 if (xco > venster_xlo) {
			xco-- ;
			}
		 else {
			if (yco > venster_yrb) {
			 yco--;
			 xco = venster_xlo;
			 }
			}
		 break ;
		 case CTRL_I: // stap naar rechts
if (xco < (venster_xrb-venster_xlo-1)) {
			xco++;
			break;
}
else
			xco = venster_xlo;
// fall trhough
		 case CTRL_J: // stap naar beneden
		 if (yco < venster_ylo) {
yco++;
regels++;
}
		 else {
if (bPagemode == TRUE) {
if (regels >= (venster_ylo-venster_yrb)) {
			 // wacht op toest
			 while (TRUE) {
if (PeekMessage(&usermsg, NULL, 0, 0, PM_REMOVE)) {
if (usermsg.message == WM_CHAR)
					break;
				 TranslateMessage (&usermsg) ;
DispatchMessage (&usermsg) ;
}
				}
regels = 0;
}
}
			for (y=venster_yrb+1; y<=venster_ylo; y++) {
			 memcpy(scherm[y-1], scherm[y], (venster_xrb-venster_xlo)+2);
}
memset(scherm[venster_ylo], ' ', (venster_xrb-venster_xlo)+1);
regels++;
			HideCaret (hWnd) ;
hdc = GetDC(hWnd);
			hOldFont =(HFONT)SelectObject(hdc, hFont);
			bkcolor = GetBkColor(hdc);
			fgcolor = GetTextColor(hdc);
			SetBkColor(hdc, kleurtbl[0]);
			SetTextColor(hdc, kleurtbl[7]);
			for (i=0; i<=venster_ylo; i++) {
TextOut(hdc, 0, (i*dHeight), scherm[i], (venster_xrb-venster_xlo)+0);
}
			SetBkColor(hdc, bkcolor);
SetTextColor(hdc, fgcolor);
SelectObject(hdc, hOldFont);
ShowCaret (hWnd) ;
			ReleaseDC(hWnd, hdc);
}
break ;
		 case CTRL_K: // stap naar boven
if (yco > venster_yrb)
yco--;
		 break;
case CTRL_L: // schoon schip
	 memset(scherm[0], ' ', sizeof(scherm));
xco = 0 ;
	 yco = 0 ;
venster_xrb=rvenster_xrb;
venster_yrb=0;
	 venster_ylo=rvenster_ylo;
venster_xlo=0;
regels=0;
bClear0 = FALSE;
	 bGraph = FALSE;
//	 resettimers(hWnd);
	 PostMessage(hWnd, WM_SETFOCUS, 0, 0L);
	 InvalidateRect (hWnd, NULL, FALSE) ;
break ;
		 case CTRL_M : // carriage return
xco = venster_xlo;
break ;
		 case CTRL_N:
		 bPagemode=TRUE;
		 regels=0;
break;
		 case CTRL_O:
bPagemode=FALSE;
break;
		 case CTRL_P:
xco = venster_xlo;
yco = venster_ylo;
break;
		 case CTRL_U:
		 bSchermstatus=FALSE;
break;
case HOME:
		 xco = 0 ;
yco = 0 ;
break ;
		 default: // character codes
if (wParam >= ' ' && wParam !=127) {
		 scherm[yco][xco] = (char) wParam ;
		 HideCaret (hWnd) ;
		 hdc = GetDC (hWnd) ;
		 bkcolor = GetBkColor(hdc);
		 fgcolor = GetTextColor(hdc);
		 SetBkColor(hdc, kleurtbl[0]);
		 SetTextColor(hdc, kleurtbl[7]);
		 hOldFont =(HFONT)SelectObject(hdc, hFont);
		 TextOut (hdc, xco * dWidth, yco * dHeight, &scherm[yco] [xco], 1);
		 if (!bGraph) {
			ShowCaret (hWnd) ;
			}
SetBkColor(hdc, bkcolor);
SetTextColor(hdc, fgcolor);
		 SelectObject(hdc, hOldFont);
ReleaseDC (hWnd, hdc) ;
SendMessage (hWnd, WM_USER_CHAR, CTRL_I, 1L) ;
		 }
	 break;
}
	 }
if (bPrinterstatus) {
	 if (wParam > 31 || wParam == 0x0a || wParam == 0x0d)
	 fputc((char) wParam, prnfile);
	 }
SetCaretPos (xco * dWidth, yco * dHeight) ;
}
return 0 ;
case WM_TIMER:
case WM_TIMECHANGE:
Watom_OnTimer(hWnd, msg, wParam, lParam);
return 0 ;
case WM_SYSCOMMAND:
Watom_OnSysCommand(hWnd, msg, wParam, lParam);
return 0 ;
case WM_COMMAND:
Watom_OnCommand(hWnd, msg, wParam, lParam);
return 0 ;
case WM_DESTROY:
joyReleaseCapture(JOYSTICKID1);
Watom_OnDestroy(hWnd, msg, wParam, lParam);
return 0 ;
case WM_CHAR:
Watom_OnChar(hWnd, msg, wParam, lParam);
return 0 ;
case WM_KEYDOWN:
Watom_OnKeyDown(hWnd, msg, wParam, lParam);
return 0 ;
case WM_KEYUP:
Watom_OnKeyUp(hWnd, msg, wParam, lParam);
return 0 ;
	case WM_INITMENU:
	 Watom_OnInitMenu(hWnd, msg, wParam, lParam);
	 return 0 ;
	case WM_SETFOCUS:
// create and show the caret
	 if (!bGraph) {
	 hdc = GetDC(hWnd);
	 SetBkColor(hdc, kleurtbl[0]);
	 SetTextColor(hdc, kleurtbl[7]);
	 CreateCaret (hWnd, NULL, cxChar, cyChar) ;
	 SetCaretPos (xco * dWidth, yco * dHeight) ;
	 ShowCaret (hWnd) ;
	 ReleaseDC(hWnd, hdc);
	 }
	 if (bJoy) {
	 joySetCapture(hWnd, JOYSTICKID1, 100, TRUE);
	 }
	 return 0 ;
case WM_KILLFOCUS:
											 // hide and destroy the caret
	 HideCaret (hWnd) ;
	 if (bJoy)
	 joyReleaseCapture(JOYSTICKID1);
	 return 0 ;
case WM_LBUTTONDOWN: // message: left mouse button pressed
	 // Start selection of region
	 if (!bTrack) {
	 bTrack = TRUE;
	 org = MAKEPOINT(lParam);
	 SetCursor(hCursor);
	 SetRectEmpty(&Rect);
	 StartSelection(hWnd, MAKEPOINT(lParam), &Rect, (wParam & MK_SHIFT) );
													 }
	 return 0 ;
case WM_MOUSEMOVE: // message: mouse movement
	 // Update the selection region
	 if (bTrack) {
	 SetCursor(hCursor);
	 UpdateSelection(hWnd, MAKEPOINT(lParam), &Rect,
			 (wParam & MK_SHIFT) ? (SL_EXTEND | Shape) : Shape);
	 len = MAKEPOINT(lParam);
	 len.x -= org.x;
	 len.y -= org.y;
	 upd_status(hWnd);
	 }
	 return 0 ;
case WM_RBUTTONUP: // message: right mouse button released
	 ptCurrent = MAKEPOINT(lParam);
	 rb_xco = ptCurrent.x / dWidth + 0;
	 rb_yco = ptCurrent.y / dHeight + 0;
	 return 0;
case WM_LBUTTONUP: // message: left mouse button released
	 if (bTrack) {
	 SetCursor(LoadCursor(NULL, IDC_ARROW));
	 EndSelection(MAKEPOINT(lParam), &Rect);
	 ClearSelection(hWnd, &Rect, FALSE);
	 bTrack = FALSE;
	 }
	 hMenu = GetMenu(hWnd);
	 if (GetMenuState(hMenu, IDM_COPYSPEC, MF_CHECKED) ) {
	 if (xco_sta - xco_sto > 0) {
	 wLength = xco_sto;
	 xco_sto = xco_sta;
	 xco_sta = wLength;
	 }
	 if (yco_sta - yco_sto > 0) {
	 wLength = yco_sto;
yco_sto = yco_sta;
yco_sta = wLength;
}
wLength = (xco_sto - xco_sta + 1) * (yco_sto - yco_sta + 1)
		 + (2 * (yco_sto - yco_sta+1));
	 hGlobalMemory = GlobalAlloc(GHND, (DWORD) wLength + 1);
lpGlobalMemory = GlobalLock(hGlobalMemory);
for (yy = yco_sta; yy<=yco_sto; yy++) {
for (xx = xco_sta; xx<=xco_sto; xx++) {
char ch;
		 ch = scherm[yy][xx] &0x7f;
if (ch<0x20)
ch = 0x20;
*lpGlobalMemory++ = ch;
}
*lpGlobalMemory++ = 0x0d;
*lpGlobalMemory++ = 0x0a;
}
GlobalUnlock(hGlobalMemory);
if (OpenClipboard(hWnd)) {
EmptyClipboard();
	 SetClipboardData(CF_TEXT, hGlobalMemory);
CloseClipboard();
InvalidateRect(hWnd, NULL, TRUE);
	 }
	 }
else {
int absx;
int absy;
int orgx;
	 int orgy;
int lenx;
int leny;
hdc = GetDC(hWnd);
if (xco_sta - xco_sto > 0) {
wLength = xco_sto;
xco_sto = xco_sta;
xco_sta = wLength;
}
if (yco - yco_sto > 0) {
wLength = yco_sto;
yco_sto = yco_sta;
yco_sta = wLength;
	 }
	 absx = abs(xco_sto-xco_sta) * dWidth;
	 absy = abs(yco_sto-yco_sta) * dHeight;
orgx = (xco_sta) * dWidth;
orgy = (yco_sta) * dHeight;
lenx = (xco_sto-xco_sta) * dWidth;
leny = (yco_sto-yco_sta) * dHeight;
	 if (lenx == 0 || leny == 0)
break;
hdcMem = CreateCompatibleDC(hdc);
hBitmap = CreateCompatibleBitmap(hdc, absx, absy);
if (hBitmap) {
SelectObject(hdcMem, hBitmap);
StretchBlt(hdcMem, 0, 0, absx, absy, hdc, orgx, orgy, lenx, leny, SRCCOPY);
OpenClipboard(hWnd);
EmptyClipboard();
SetClipboardData(CF_BITMAP, hBitmap);
CloseClipboard();
InvalidateRect(hWnd, NULL, TRUE);
}
else
	 MessageBox(hWnd, "Bitmap Error", "Memory", MB_OK);
	 DeleteDC(hdcMem);
ReleaseDC(hWnd, hdc);
}
return 0;
}
return (DefWindowProc(hWnd, msg, wParam, lParam));
}
#pragma argsused
BOOL FAR PASCAL About(HWND hWnd, unsigned message, WORD wParam, LONG lParam)
{
switch (message) {
case WM_INITDIALOG: /* message: initialize dialog box */
return (TRUE);
case WM_COMMAND: /* message: received a command */
if (wParam == IDOK /* "OK" box selected? */
|| wParam == IDCANCEL) { /* System menu close command? */
EndDialog(hWnd, TRUE); /* Exits the dialog box */
	 return (TRUE);
	 }
break;
}
return (FALSE); /* Didn't process a message */
}
#pragma argsused
void Watom_OnDestroy(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
OFSTRUCT of;
WORD wReturn;
char szBuf[144];
char szWorkpath[160];
wReturn = GetWindowsDirectory( (LPSTR) szBuf, sizeof (szBuf));
if (wReturn == 0)
MessageBox (hWnd, "function failed", "get Windows Directory", MB_OK);
else if (wReturn > sizeof(szBuf))
MessageBox (hWnd, "buffer is to small", "get Windows Directory", MB_OK);
strcpy(szWorkpath, szBuf);
strcat(szWorkpath, "\\atom.fot");
// had to keep around until app is done using the info
if (pis.hCurrDevMode != NULL)
GlobalFree(pis.hCurrDevMode);
// had to keep around until app is done using the info
if (pis.hCurrDevNames != NULL)
GlobalFree(pis.hCurrDevNames);
WriteProfile(GetActiveWindow());
DeleteObject(hFont);
RemoveFontResource((LPSTR) szWorkpath);
SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);
OpenFile(szWorkpath, &of, OF_DELETE);
resettimer(hWnd);
if (bMidi == TRUE) {
SendMessage (hWnd, WM_MIDI, 0, 0L) ; // free memory
midiOutClose (hMidiOut) ;
}
PostQuitMessage(0);
}
#pragma argsused
void Watom_OnTimer(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
int	i;
HDC	hdc;
if (!bTrack) {
if (bGraph == TRUE) {
	 hdc = GetDC(hwnd);
	 for (i=0; i<24; i++) {
	 if (bPlane[i] == TRUE) {
		SetDIBits(hdc, hBitmap[i], 0, 192, (LPSTR) BitMapBits[i], (LPBITMAPINFO) lpbi, DIB_RGB_COLORS);
		DrawBitmap(hdc, hBitmap[i], 10, 10+(8*(24-i)));
		bPlane[i]=FALSE;
		}
	 }
	 }
ReleaseDC(hwnd, hdc);
}
return;
}
BOOL Watom_OnSysCommand(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (wParam) {
case IDM_ABOUT:
lpProcAbout = MakeProcInstance(About, hInst);
DialogBox(hInst, // current instance
"About", // resource to use 
	 hWnd, // parent handle
lpProcAbout); // About() instance address 
InvalidateRect(hWnd, NULL, FALSE);
UpdateWindow(hWnd);
FreeProcInstance(lpProcAbout);
return 0;
case SC_MAXIMIZE:
Watom_OnSize(hWnd, msg, wParam, lParam);
	 // fall through
}
return (DefWindowProc(hWnd, msg, wParam, lParam));
}
#pragma argsused
BOOL Watom_OnCommand(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
HMENU hMenu;
switch (wParam) {
case 202:
			// allocate global blocks to hold data
	 hGmem1 = GlobalAlloc (GMEM_FIXED | GMEM_SHARE,	sizeof (MIDISONG)) ;
	 hGmem2 = GlobalAlloc (GMEM_FIXED | GMEM_SHARE,	6 * sizeof (MIDIDATA)) ;
	 if (hGmem1 == NULL || hGmem2 == NULL) {
	 MessageBox (hWnd, "Could not allocate memory",
	 "Memory Error", MB_ICONHAND | MB_OK) ;
	 return 0 ;
	 }
	 lpMidiSong = (MIDISONG FAR *) GlobalLock (hGmem1) ;
	 lpMidiData = (MIDIDATA FAR *) GlobalLock (hGmem2) ;
	 lpmd = lpMidiData ;
	 for (i = 0 ; i < 6 ; i++) { // copy in some data
	 lpmd->dwTimeMs = MidiData[i].dwTimeMs ;
	 lpmd->dwMidiData = MidiData[i].dwMidiData ;
	 lpmd++ ;
	 }
	 lpMidiSong->dwEvents = 6 ; // init MIDISONG
	 lpMidiSong->dwLastEvent = 0 ;
	 lpMidiSong->dwTime = 0 ;
	 lpMidiSong->lpMidiData = lpMidiData ;
	 lpMidiSong->hMidiOut = hMidiOut ;
	 // start timer - callback does MIDI output
	 timeBeginPeriod (nTimerRes) ;
	 nTimerID = timeSetEvent (nTimerRes, nTimerRes, TimeCallback, (DWORD) (LPSTR) lpMidiSong,
	 TIME_PERIODIC) ;
	 if (nTimerID == NULL) {
	 MessageBox (hWnd, "Could not start timer.", "Message", MB_OK) ;
	 }
	 break;
case IDM_COPYSPEC:
	hMenu=GetMenu(hWnd);
	if (GetMenuState(hMenu, IDM_COPYSPEC, MF_CHECKED) ) {
	 CheckMenuItem(hMenu, IDM_COPYSPEC, MF_UNCHECKED);
	 }
	else {
	 CheckMenuItem(hMenu, IDM_COPYSPEC, MF_CHECKED);
	 }
	break;
case IDM_PRINT:
	ShowPrintBox(hWnd);
	break;
case IDM_PRINTSETUP:
	ShowPrintSetup(hWnd);
	break;
case IDM_EXIT:
SendMessage(hWnd, WM_CLOSE, 0, 0L);
break;
case IDM_RESET:
RESET(iobase);
break;
}
return TRUE;
}
#pragma argsused
void Watom_OnPaint(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
RECT hRect, hBox;
HBRUSH hBrush;
DWORD bkcolor, fgcolor;
HDC hdc;
if (!bTrack) {
hdc = BeginPaint(hWnd, &ps);
if (IsIconic(hWnd) ) {
	 nWidth = 3; // cxIcon / (venster_xrb) + 1; // grootte van het icon
nHeight = 3; // cyIcon / (venster_ylo+1) + 1; // idem
DeleteObject(hFont);
	 Createfnt(hWnd);
}
else {
hBrush = CreateSolidBrush(kleurtbl[8]);
GetClientRect(hWnd, &hRect);
hRect.top = hRect.bottom - 26;
FillRect(hdc, &hRect, hBrush);
DeleteObject(hBrush);
hBox.top = hRect.top +1;
hBox.bottom = hRect.bottom -1;
hBox.left = hRect.left +1;
hBox.right = hRect.right +1;
MakeBox(hdc, hBox);
hBox.left = hRect.left + 105;
	 hBox.right = hRect.left + 1;
	 MakeBox(hdc, hBox);
hBox.left = hRect.left + 150;
hBox.right = hRect.right- 1;
MakeBox(hdc, hBox);
upd_status(hWnd);
}
if (bGraph) {
	 int i;
	 for (i=0; i<24; i++) {
	 DrawBitmap(ps.hdc, hBitmap[i], 10, 10+(8*(24-i)));
}
}
else {
	 hOldFont =(HFONT)SelectObject(hdc, hFont);
bkcolor = GetBkColor(hdc);
fgcolor = GetTextColor(hdc);
SetBkColor(hdc, kleurtbl[0]);
	 SetTextColor(hdc, kleurtbl[7]);
for (i=0; i<=venster_ylo; i++) {
TextOut(hdc, 0, (i*dHeight), scherm[i], (venster_xrb-venster_xlo)+0);
}
SetBkColor(hdc, bkcolor);
SetTextColor(hdc, fgcolor);
SelectObject(hdc, hOldFont);
if (!IsIconic(hWnd) ) {
	 SelectObject (hdc, hFont) ;
SetBkColor(hdc, kleurtbl[0]);
SetTextColor(hdc, kleurtbl[7]);
}
}
EndPaint(hWnd, &ps);
}
}
#pragma argsused
void Watom_OnSize(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
hdc = GetDC(hWnd);
SetBkColor(hdc, kleurtbl[0]);
SetTextColor(hdc, kleurtbl[7]);
cxClient = LOWORD (lParam) ;
cyClient = HIWORD (lParam) ;
GetWindowRect(hWnd, &hRect);
defver = hRect.left;
defhor = hRect.top;
defwidth = hRect.right;
defheight = hRect.bottom;
cxChar = nWidth = cxClient / venster_xrb;
cyChar = nHeight = (cyClient-30) / (venster_ylo + 1);
DeleteObject(hFont);
Createfnt(hWnd);
// calculate window size in characters
if (hWnd == GetFocus ()) {
CreateCaret (hWnd, NULL, cxChar, cyChar) ;
SetCaretPos (xco * cxChar, yco * cyChar) ;
}
PostMessage(hWnd, WM_SETFOCUS, 0, 0L);
ReleaseDC(hWnd, hdc);
InvalidateRect(hWnd, NULL, TRUE);
}
#pragma argsused
void Watom_OnCreate(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
int nFontload;
BOOL bStatus;
OFSTRUCT of;
WORD wReturn;
char szBuf[144];
char szFontpath[160];
char szWorkpath[160];
HDC hdc;
DragAcceptFiles(hWnd, TRUE);
if (bJoystick == TRUE) {
if (joyGetNumDevs() >=1 && joyGetPos(JOYSTICKID1, &ji) != JOYERR_UNPLUGGED) {
	 joyGetDevCaps(JOYSTICKID1, &jc, sizeof(JOYCAPS));
	 bJoy = TRUE;
	 joySetThreshold(JOYSTICKID1, 128);
	 if (jc.wXmax > 32000 || jc.wYmax > 32000) {
	 jc.wXmax = 16000;
	 jc.wYmax = 16000;
	 }
	 }
else {
	 MessageBox(hWnd, "Geen joystick aanwezig op het systeem", "Melding", MB_ICONHAND | MB_OK);
	 bJoy = FALSE;
	 }
}
if (bMidi == TRUE) {
int nStatus;
HINSTANCE hInstance;
char cBuf[90];
if (midiOutGetNumDevs () == 0) { // check if MIDI OK
	 MessageBox (hWnd, "No MIDI output device found.",
	 "Not Installed?", MB_ICONHAND | MB_OK) ;
	 return ;
	 }
hInstance = (HINSTANCE)GetWindowWord (hWnd, GWW_HINSTANCE) ;
nStatus = midiOutOpen (&hMidiOut, (UINT) MIDI_MAPPER,
		(DWORD) MidiOutCall, (DWORD) hInstance,	CALLBACK_FUNCTION) ;
if (nStatus != 0) {
	 midiOutGetErrorText (nStatus, cBuf, 256) ;
	 MessageBox (hWnd, cBuf, "MIDI Error", MB_ICONHAND | MB_OK) ;
	 return ;
	 }
nStatus = timeGetDevCaps (&tc, sizeof (TIMECAPS)) ;
if (nStatus == TIMERR_NOCANDO) {
	 MessageBox (hWnd, "MM timer not found - terminating.",
	 "Error", MB_OK | MB_ICONHAND) ;
	 DestroyWindow (hWnd) ;
	 }
		 // find resolution closest to 1 millisecond
nTimerRes = min (max (tc.wPeriodMin, 1), tc.wPeriodMax) ;
} // einde bMidi
wReturn = GetSystemDirectory( (LPSTR) szBuf, sizeof (szBuf));
if (wReturn == 0)
MessageBox (hWnd, "function failed", "get System Directory", MB_OK);
else if (wReturn > sizeof(szBuf))
MessageBox (hWnd, "buffer is to small", "get System Directory", MB_OK);
strcpy(szFontpath, szBuf);
strcat(szFontpath, "\\atom.ttf");
wReturn = GetWindowsDirectory( (LPSTR) szBuf, sizeof (szBuf));
if (wReturn == 0)
MessageBox (hWnd, "function failed", "get Windows Directory", MB_OK);
else if (wReturn > sizeof(szBuf))
MessageBox (hWnd, "buffer is to small", "get Windows Directory", MB_OK);
settimers(hWnd);
strcpy(szWorkpath, szBuf);
strcat(szWorkpath, "\\atom.fot");
pis.hCurrDevMode = NULL;
pis.hCurrDevNames = NULL;
pis.hPrinterFont = NULL;
GetClientRect(hWnd, &hRect);
hdc 			= GetDC (hWnd) ;
Bi.biSize 		= sizeof(BITMAPINFOHEADER);
Bi.biWidth 		= 256;
Bi.biHeight 		= 8;
Bi.biPlanes 		= 1;
Bi.biBitCount 	= 4;
Bi.biCompression 	= BI_RGB;
Bi.biSizeImage 	= 256 * 8;
Bi.biXPelsPerMeter 	= 0;
Bi.biYPelsPerMeter 	= 0;
Bi.biClrUsed 	= 0;
Bi.biClrImportant 	= 0;
for (i=0; i<24; i++) {
hBitmap[i] = CreateDIBitmap(hdc, &Bi, 0L, NULL, NULL, 0);
hDIB[i] = GlobalAlloc(GHND, sizeof(BITMAPINFOHEADER) + 16 * sizeof(RGBQUAD));
lpbi = (BITMAPINFOHEADER FAR *)GlobalLock(hDIB[i]);
*lpbi = Bi;
GetDIBits(hdc, hBitmap[i], 0, 50, NULL, (LPBITMAPINFO) lpbi, DIB_RGB_COLORS);
GlobalUnlock(hDIB[i]);
}
// SetMapMode(hdc, MM_ANISOTROPIC);
// SetWindowExt(hdc, 1440, 1440);
// SetViewportExt(hdc, GetDeviceCaps(hdc, LOGPIXELSX), GetDeviceCaps(hdc, LOGPIXELSY));
nWidth = hRect.right / venster_xrb;
nHeight = (hRect.bottom-30) / (venster_ylo + 1);
GetClientRect(hWnd, &hRect);
OpenFile(szWorkpath, &of, OF_DELETE);
bStatus = CreateScalableFontResource(0, szWorkpath, szFontpath, NULL);
if (!bStatus)
MessageBox(hWnd, "Scalable Font niet te laden", "Warning", MB_ICONHAND | MB_OK);
else {
nFontload = AddFontResource((LPSTR) szWorkpath);
if (!nFontload)
	 MessageBox(hWnd, "Font niet te laden", "Warning", MB_ICONHAND | MB_OK);
else
	 SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);
}
Createfnt(hWnd);
SelectObject (hdc, hFont) ;
GetTextMetrics (hdc, &tm) ;
cxChar = tm.tmAveCharWidth;
cyChar = (cyClient-30) / (venster_ylo+1);
cxIcon = GetSystemMetrics(SM_CXICON);
cyIcon = GetSystemMetrics(SM_CYICON);
ReleaseDC(hWnd, hdc) ;
}
#pragma argsused
void Watom_OnChar(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	bKey = TRUE;
bascii = LOWORD(wParam);
bscan = HIWORD(lParam) & 0xff;
}
#pragma argsused
void Watom_OnInitMenu(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
HMENU hMenu = (HMENU) wParam;
if (hMenu == GetMenu(hWnd)) {
if ((yco == yco_sto)&& yco_sto !=0)
EnableMenuItem(hMenu, IDM_DDE, MF_ENABLED);
else
EnableMenuItem(hMenu, IDM_DDE, MF_GRAYED);
}
}
#pragma argsused
void Watom_OnKeyDown(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (wParam) {
case VK_END:
break ;
case VK_LEFT:
	 SendMessage (hWnd, WM_USER_CHAR, CTRL_H, 1L) ;
break ;
case VK_RIGHT:
SendMessage (hWnd, WM_USER_CHAR, CTRL_I, 1L) ;
break ;
case VK_DOWN:
SendMessage (hWnd, WM_USER_CHAR, CTRL_J, 1L) ;
break ;
case VK_UP:
SendMessage (hWnd, WM_USER_CHAR, CTRL_K, 1L) ;
break ;
case VK_BACK:
	 if (xco >0) {
	 SendMessage (hWnd, WM_USER_CHAR, CTRL_H, 1L) ;
	 SendMessage (hWnd, WM_USER_CHAR, ' ', 1L) ;
	 SendMessage (hWnd, WM_USER_CHAR, CTRL_H, 1L) ;
	 }
break;
}
readkeys();
upd_status(hWnd);
}
#pragma argsused
void Watom_OnKeyUp(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
readkeys();
upd_status(hWnd);
}
void Createfnt(HWND hWnd)
{
TEXTMETRIC tm;
HFONT hTmpfnt;
LOGFONT hLogFont;
HDC			hdc;
if (nHeight==0)
nHeight=3;
hTmpfnt = CreateFont( nHeight,
	 0,
	 0, // no sloping
	 0, // no escaping
	 FW_NORMAL, // dik is in
	 FALSE, // geen italic
	 FALSE, // geen streep er onder
	 FALSE, // geen doorhaling
	 0,
	 OUT_RASTER_PRECIS,
	 CLIP_STROKE_PRECIS,
	 PROOF_QUALITY,
	 FIXED_PITCH,
	 "RLatom"
	 );
hdc = GetDC(hWnd);
hOldFont =(HFONT)SelectObject(hdc, hTmpfnt);
GetTextMetrics(hdc, &tm);
hLogFont.lfHeight = -tm.tmHeight;
hLogFont.lfWidth = nWidth;
hLogFont.lfWeight = tm.tmWeight;
hLogFont.lfEscapement = 0;
hLogFont.lfOrientation = 0;
hLogFont.lfItalic = FALSE;
hLogFont.lfUnderline = FALSE;
hLogFont.lfStrikeOut = FALSE;
hLogFont.lfCharSet = ANSI_CHARSET;
hLogFont.lfOutPrecision = OUT_RASTER_PRECIS,
hLogFont.lfClipPrecision = CLIP_STROKE_PRECIS,
hLogFont.lfQuality = PROOF_QUALITY;
hLogFont.lfPitchAndFamily = FIXED_PITCH,
strcpy(hLogFont.lfFaceName, "RLatom");
hFont = CreateFontIndirect(&hLogFont);
DeleteObject(hTmpfnt);
SelectObject(hdc, hFont);
GetTextMetrics(hdc, &tm);
dHeight = tm.tmDescent + tm.tmAscent - tm.tmInternalLeading;
GetCharABCWidths(hdc, (UINT) 'a', (UINT) 'z', (LPABC) &abc);
dWidth = nWidth = (abc['b' - 'a'].abcA + abc['b' - 'a'].abcB + abc['b' - 'a'].abcC);
SelectObject(hdc, hOldFont);
ReleaseDC(hWnd, hdc);
}
void ReadProfile()
{
defver = GetPrivateProfileInt("Position", "defver", -1, "WinAtom.ini");
defhor = GetPrivateProfileInt("Position", "defhor", -1, "WinAtom.ini");
defwidth = GetPrivateProfileInt("Position", "defwidth", -1, "WinAtom.ini");
defheight = GetPrivateProfileInt("Position", "defheight", -1, "WinAtom.ini");
rvenster_xrb = GetPrivateProfileInt("TermSize", "Xwidth", -1, "WinAtom.ini");
rvenster_ylo = GetPrivateProfileInt("TermSize", "Yheight", -1, "WinAtom.ini");
iobase = GetPrivateProfileInt("BaseAdress", "IO", -1, "WinAtom.ini");
bJoystick = GetPrivateProfileInt("MultiMed", "joy", -1, "WinAtom.ini");
bMidi = GetPrivateProfileInt("MultiMed", "midi", -1, "WinAtom.ini");
if (rvenster_ylo > 50) rvenster_ylo = 25;
if (rvenster_xrb > 132) rvenster_xrb = 64;
if (rvenster_ylo<1) rvenster_ylo = 25;
if (rvenster_xrb <20) rvenster_xrb = 64;
venster_xrb = rvenster_xrb;
venster_ylo = rvenster_ylo;
}
void WriteProfile()
{
char ascii[9];
itoa(defver, ascii, 10);
WritePrivateProfileString("Position", "defver", ascii, "WinAtom.ini");
itoa(defhor, ascii, 10);
WritePrivateProfileString("Position", "defhor", ascii, "WinAtom.ini");
itoa(defwidth, ascii, 10);
WritePrivateProfileString("Position", "defwidth", ascii, "WinAtom.ini");
itoa(defheight, ascii, 10);
WritePrivateProfileString("Position", "defheight", ascii, "WinAtom.ini");
itoa(venster_xrb, ascii, 10);
WritePrivateProfileString("TermSize", "Xwidth", ascii, "WinAtom.ini");
itoa(venster_ylo, ascii, 10);
WritePrivateProfileString("TermSize", "Yheight", ascii, "WinAtom.ini");
itoa(iobase, ascii, 10);
WritePrivateProfileString("BaseAdress", "IO", ascii, "WinAtom.ini");
itoa(bJoystick, ascii, 10);
WritePrivateProfileString("MultiMed", "joy", ascii, "WinAtom.ini");
itoa(bMidi, ascii, 10);
WritePrivateProfileString("MultiMed", "midi", ascii, "WinAtom.ini");
}
void MakeBox(HDC hdc, RECT hRect)
{
HBRUSH hBrush;
hRect.top +=3;
hRect.left +=3;
hRect.bottom -=2;
hRect.right -=2;
hBrush = CreateSolidBrush(kleurtbl[0]);
FrameRect(hdc, &hRect, hBrush);
DeleteObject(hBrush);
hRect.top -=1;
hRect.left -=1;
hBrush = CreateSolidBrush(kleurtbl[7]);
FrameRect(hdc, &hRect, hBrush);
hRect.top -=1;
hRect.left -=1;
hRect.bottom -=1;
hRect.right -=1;
FrameRect(hdc, &hRect, hBrush);
DeleteObject(hBrush);
}
void upd_status(HWND hWnd)
{
RECT hRect;
char s[99];
char t[99]; // 12345678901
char space[] = " ";
HDC hdc;
DWORD bkcolor, fgcolor;
if (!IsIconic(hWnd) ) {
sprintf (s, "%2d.%2d:%2d.%2d", xco_sta, yco_sta, xco_sto, yco_sto);
GetClientRect(hWnd, &hRect);
hdc = GetDC(hWnd);
bkcolor = GetBkColor(hdc);
fgcolor = GetTextColor(hdc);
SelectObject (hdc, GetStockObject (SYSTEM_FIXED_FONT)) ;
SetBkMode(hdc, OPAQUE);
SetBkColor(hdc, kleurtbl[8]);
SetTextColor(hdc, kleurtbl[0]);
if (bTrack)
TextOut(hdc, hRect.left+4, hRect.bottom - 20, s, strlen(s));
else
TextOut(hdc, hRect.left+4, hRect.bottom - 20, space, strlen(space));
readkeys();
if (bShift) strcpy(t, "SHIFT ");
else strcpy(t, "shift ");
if (bPagemode) strcat(t, "PAGEMODE ");
else strcat(t, "pagemode ");
if (bCaps) strcat(t, "CAPS ");
		else strcat(t, "caps ");
if (bPrinterstatus) strcat(t, "PRINTER ");
else strcat(t, "printer ");
		if (bSchermstatus) strcat(t, "SCHERM ");
		else strcat(t, "scherm ");
		if (bJoystick) strcat(t, "JOY ");
		else strcat(t, "joy ");
		if (bMidi) strcat(t, "MIDI");
		else strcat(t, "midi");
		// sprintf(s, "regels: %d", regels);
		// strcat(t, s);
		TextOut(hdc, hRect.left+170, hRect.bottom - 20, t, strlen(t));
		SetBkColor(hdc, bkcolor);
		SetTextColor(hdc, fgcolor);
ReleaseDC(hWnd, hdc);
}
}
void Process(char result)
{
int result1;
static int k = 32;
// result = k++;
if (k>255) k=32;
switch (result) {
case 0:
result1=READBYTEW(iobase);
/* if (result1 != DRUKAF && result1 != 0x5d) {
char tekst[80];
sprintf(tekst, "commando: %02x", result1);
MessageBox(0, tekst, "debug", MB_OK);
} */
	 switch (result1) {
	 case DRUKAF:
	 drukaf();
	 break;
	 case KEY:
	 keyb();
	 break;
	 case COPY:
	 copy();
	 break;
	 case GPLOT:
	 gplot();
	 break;
	 case IGRAPH:
	 igraph();
	 break;
	 case SIMULATE4:
	 simulate4();
	 break;
	 case RAMFNT:
	 ramfnt();
	 break;
	 case SCHRIJF:
	 schrijf();
	 break;
	 case SCHAAL:
	 schaal();
	 break;
	 case CURSOR_ON:
	 cursor_on();
	 break;
	 case CURSOR_OFF:
	 cursor_off();
	 break;
	 case LOADFILE:
	 loadfile();
	 break;
	 case SAVEFILE:
	 savefile();
	 break;
	 case CAT:
	 cat();
	 break;
	 case ACHDIR:
	 achdir();
	 break;
	 case ARMDIR:
	 armdir();
	 break;
	 case AMKDIR:
	 amkdir();
	 break;
	 case DELETE:
	 delete();
	 break;
	 case LOCK:
	 alock();
	 break;
	 case UNLOCK:
	 aunlock();
	 break;
	 case ADRIVE:
	 adrive();
	 break;
	 case MSDOS:
	 PostQuitMessage(0);
	 // msdos();
	 break;
	 case HIDE:
	 hide();
	 break;
	 case UNHIDE:
	 unhide();
	 break;
	 case INFO:
	 info();
	 break;
	 case GELUID:
	 geluid();
	 break;
	 case BLIEP:
	 bliep();
	 break;
	 case ERRMSG:
	 errmsg();
	 break;
	 case KNAAGDIER:
	 knaagdier();
	 break;
	 case DEFMUISMASKER:
	 defmuismasker();
	 break;
	 case CURSORPOS:
	 cursorpos();
	 break;
	 case VIDEO:
	 video();
	 break;
	 case SERPORT:
	 serport();
	 break;
	 case PRINTIT:
	 printit();
	 break;
	 case DOSFUNCTIE:
	 dosfunctie();
	 break;
	 case PORT_IN:
	 port_in();
	 break;
	 case PORT_OUT:
	 port_out();
	 break;
	 case UDS:
	 uds();
	 break;
	 case MOUSE_MOT:
	 mouse_mot();
	 break;
	 case WHOAMI:
	 whoami();
	 break;
	 case CLEAR0:
	 clear0();
	 break;
	 case PALET:
	 palet();
	 break;
	 case CLEAR1:
	 clear1();
	 break;
	 case CLEAR1A:
	 clear1a();
	 break;
	 case CLEAR2:
	 clear2();
	 break;
	 case CLEAR2A:
	 clear2a();
	 break;
	 case CLEAR3:
	 clear3();
	 break;
	 case CLEAR3A:
	 clear3a();
	 break;
	 case CLEAR4:
	 clear4();
	 break;
	 case CLEAR4A:
	 clear4a();
	 break;
	 case VIDEOMOD:
	 videomod();
	 break;
	 case VIDEOCOL:
	 videocol();
	 break;
	 case SCHRIJFPIX:
	 schrijfpix();
	 break;
	 case WINDOW:
	 windowd();
	 break;
	 case WINDOW_OFF:
	 window_off();
	 break;
	 case JOYSTICK:
	 joystick();
	 break;
	 case CALLIBRATE:
	 callibrate();
	 break;
	 case BIT7:
	 bit7();
	 break;
	 case BIOSKEY:
	 bioskey();
	 break;
	 case SHELL:
		shell();
	 break;
	 case ZOEKFILE:
	 cat();
//	 zoekfile();
	 break;
	 case ZOEKNEXT:
	 zoeknext();
	 break;
	 case LPT:
	 lpt();
	 break;
	 case RAF_OPEN:
	 raf_open();
	 break;
	 case RAF_SLUIT:
	 raf_sluit();
	 break;
	 case RAF_SCHRIJF:
	 raf_schrijf();
	 break;
	 case RAF_LEZEN:
	 raf_lezen();
	 break;
	 case RAF_MOVE_PTR:
	 raf_move_ptr();
	 break;
	 case RAF_LEES_EXT:
	 raf_lees_ext();
	 break;
	 case MOUSEKAR:
	 mousekar();
	 break;
	 case VERSIE:
	 versie();
	 break;
	 case TEKEN2LPT:
	 teken2lpt();
	 break;
	 case CGABITMAP:
	 cgabitmap();
	 break;
	 case HFILL:
	 hfill();
	 break;
	 case VFILL:
	 vfill();
	 break;
	 case ROEP61:
	 roep61();
	 break;
	 case GWINDOW:
	 gwindow();
	 break;
	 case GWOFF:
	 gwoff();
	 break;
	 case OORSPRONG:
	 oorsprong();
	 break;
	 case VIEWSCHERM:
	 viewscherm();
	 break;
	 case WERKSCHERM:
	 werkscherm();
	 break;
	 case CURSORDEF:
	 cursordef();
	 break;
case READ_B001:
	 read_b001(0x00);
	 break;
case READ_B002:
read_b002();
break;
case WRITE_B000:
write_b000();
	 break;
	 case EGAFONT:
	 egafont();
	 break;
	 case EGA8X14:
	 ega8x14();
	 break;
	 case EGA8X8:
	 ega8x8();
	 break;
	 case PUTWIN: // putwin
	 putwin();
	 break;
	 case GETWIN:
	 getwin();
	 break;
	 case SHAPES: // shapes
	 shapes();
	 break;
	 case DIR_VID_ACC: // dir_vid_acc
	 dir_vid_acc();
	 break;
	 case KOPYPAGE:
	 kopypage();
	 break;
	 case ASCII_SCAN:
	 ascii_scan();
	 break;
	 case WAIT:
	 wait();
	 break;
	 case PAINT:
	 paint();
	 break;
	 case INIT0:
	 init0();
	 break;
	 default:
	 PrintError(result);
	 break;
	 }
	 break;
	 case CTRL_A:
	 teken2lpt();
	 break;
	 case CTRL_B:
	 if (bPrinterstatus == FALSE) {
	 if ((prnfile = fopen("pc-atom.spl", "ab+")) == NULL) {
		 MessageBox(0, "Error", "Cannot open spoolfile", MB_OK);
		 }
	 else {
		 bPrinterstatus = TRUE;
		 }
	 }
	 break;
	 case CTRL_C:
	 if (bPrinterstatus == TRUE) {
	 fclose(prnfile);
	 bPrinterstatus = FALSE;
	 }
	 break;
	 case CTRL_D:
	 viewscherm();
	 break;
	 case CTRL_E:
	 werkscherm();
	 break;
	 case CTRL_F:
	 bSchermstatus = TRUE;
	 upd_status(hwnd);
	 break;
	 case CTRL_G:
	 MessageBeep(0);
	 break;
	 case CTRL_H:
	 // STAPJE TERUG
	 SendMessage (hwnd, WM_USER_CHAR, CTRL_H, 1L) ;
	 break;
	 case CTRL_I:
	 // stapje naar rechts
	 SendMessage (hwnd, WM_USER_CHAR, CTRL_I, 1L) ;
	 break;
	 case CTRL_J:
	 // stapje naar beneden
// regels++;
	 SendMessage (hwnd, WM_USER_CHAR, CTRL_J, 1L) ;
	 break;
	 case CTRL_K:
	 // stapje naar boven
	 SendMessage (hwnd, WM_USER_CHAR, CTRL_K, 1L) ;
	 break;
	 case CTRL_L:
	 // wash my window
	 SendMessage (hwnd, WM_USER_CHAR, CTRL_L, 1L) ;
	 break;
	 case CTRL_M:
	 // next line
	 SendMessage (hwnd, WM_USER_CHAR, CTRL_M, 1L) ;
	 break;
	 case CTRL_N:
	 // pagemode aan
	 bPagemode = TRUE;
	 regels = 0;
	 break;
	 case CTRL_O:
	 // pagemode uit
	 bPagemode = FALSE;
	 break;
	 case CTRL_P:
	 xco = venster_xlo;
	 yco = venster_ylo;
	 // gotoxy(sdf.asdf);
	 break;
	 case CTRL_Q:
	 videocol();
	 break;
	 case CTRL_U:
	 // scherm uit
	 bSchermstatus = FALSE;
	 upd_status(hwnd);
	 break;
	 case CTRL_V:
	 videomod();
	 break;
	 case CTRL_W:
	 cgabitmap();
	 break;
	 case CTRL_X:
	 gwindow();
	 break;
	 case CTRL_Z:
// gwindowoff();
	 windowd();
	 break;
	 case CTRL_KM:
	 windowd();
	 break;
	 case CTRL_MN:
	 oorsprong();
	 break;
	 case HOME:
	 SendMessage (hwnd, WM_USER_CHAR, HOME, 1L) ;
	 break;
	 case CTRL_SL:
	 // heel verhaal
// zetcursor();
	 break;
	 default:
	 SendMessage (hwnd, WM_USER_CHAR, result, 1L) ;
	 break;
	 }
}
void readkeys()
{
unsigned int nShift, nCaps, nCtrl;
nShift = GetKeyState(VK_SHIFT);
	nCtrl = GetKeyState(VK_CONTROL);
nCaps = GetKeyState(VK_CAPITAL);
if ((nShift & 0x8000) == 0x8000)
bShift = TRUE;
	else
bShift = FALSE;
if ((nCtrl & 0x8000) == 0x8000)
bCtrl = TRUE;
else
bCtrl = FALSE;
if ((nCaps & 0x8000) == 0x8000) {
bCaps = nCaps & 0x0001;
}
}
void DrawBitmap(HDC hdc, HBITMAP hBitmap, short xStart, short yStart)
{
BITMAP bm;
HDC hMemDC;
POINT ptSize, ptOrg;
hMemDC 	= CreateCompatibleDC(hdc);
SelectObject(hMemDC, hBitmap);
SetMapMode(hMemDC, GetMapMode(hdc));
GetObject(hBitmap, sizeof(BITMAP), (LPSTR) &bm);
ptSize.x 	= bm.bmWidth;
ptSize.y 	= bm.bmHeight;
DPtoLP(hdc, &ptSize, 1);
ptOrg.x 	= 0;
ptOrg.y 	= 0;
DPtoLP(hMemDC, &ptOrg, 1);
BitBlt(hdc, xStart, yStart, ptSize.x, ptSize.y, hMemDC, ptOrg.x, ptOrg.y, SRCCOPY);
DeleteDC(hMemDC);
}
void paintclear0(int xco, int yco, BYTE waarde)
{
HDC hdc;
DWORD bkcolor, fgcolor;
scherm[yco][xco] = waarde;
hdc = GetDC (hwnd) ;
bkcolor = GetBkColor(hdc);
fgcolor = GetTextColor(hdc);
SetBkColor(hdc, kleurtbl[0]);
SetTextColor(hdc, kleurtbl[7]);
hOldFont =(HFONT)SelectObject(hdc, hFont);
TextOut (hdc, xco * dWidth, yco * dHeight, &waarde, 1);
SetBkColor(hdc, bkcolor);
SetTextColor(hdc, fgcolor);
SelectObject(hdc, hOldFont);
ReleaseDC (hwnd, hdc) ;
}
terug.gif