2024-03-19 22:22:29 +01:00
|
|
|
/*
|
|
|
|
* kml.c
|
|
|
|
*
|
|
|
|
* This file is part of Emu48
|
|
|
|
*
|
|
|
|
* Copyright (C) 1995 Sebastien Carlier
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include "pch.h"
|
|
|
|
#include "resource.h"
|
|
|
|
#include "Emu48.h"
|
|
|
|
#include "kml.h"
|
|
|
|
|
2024-03-19 22:37:54 +01:00
|
|
|
static VOID FatalError(VOID);
|
|
|
|
static VOID InitLex(LPTSTR szScript);
|
|
|
|
static VOID CleanLex(VOID);
|
|
|
|
static VOID SkipWhite(UINT nMode);
|
|
|
|
static TokenId ParseToken(UINT nMode);
|
|
|
|
static DWORD ParseInteger(VOID);
|
|
|
|
static LPTSTR ParseString(VOID);
|
|
|
|
static TokenId Lex(UINT nMode);
|
|
|
|
static KmlLine* ParseLine(TokenId eCommand);
|
|
|
|
static KmlLine* IncludeLines(LPCTSTR szFilename);
|
|
|
|
static KmlLine* ParseLines(VOID);
|
|
|
|
static KmlBlock* ParseBlock(TokenId eBlock);
|
|
|
|
static KmlBlock* IncludeBlocks(LPCTSTR szFilename);
|
|
|
|
static KmlBlock* ParseBlocks(VOID);
|
|
|
|
static VOID FreeLines(KmlLine* pLine);
|
|
|
|
static VOID PressButton(UINT nId);
|
|
|
|
static VOID ReleaseButton(UINT nId);
|
|
|
|
static VOID PressButtonById(UINT nId);
|
|
|
|
static VOID ReleaseButtonById(UINT nId);
|
|
|
|
static LPTSTR GetStringParam(KmlBlock* pBlock, TokenId eBlock, TokenId eCommand, UINT nParam);
|
|
|
|
static DWORD GetIntegerParam(KmlBlock* pBlock, TokenId eBlock, TokenId eCommand, UINT nParam);
|
|
|
|
static KmlLine* SkipLines(KmlLine* pLine, TokenId eCommand);
|
|
|
|
static KmlLine* If(KmlLine* pLine, BOOL bCondition);
|
|
|
|
static KmlLine* RunLine(KmlLine* pLine);
|
|
|
|
static KmlBlock* LoadKMLGlobal(LPCTSTR szFilename);
|
|
|
|
|
2024-03-19 23:33:35 +01:00
|
|
|
KmlBlock* pKml = NULL;
|
2024-03-19 22:37:54 +01:00
|
|
|
static KmlBlock* pVKey[256];
|
|
|
|
static BYTE byVKeyMap[256];
|
|
|
|
static KmlButton pButton[256];
|
|
|
|
static KmlAnnunciator pAnnunciator[6];
|
|
|
|
static UINT nButtons = 0;
|
|
|
|
static UINT nScancodes = 0;
|
|
|
|
static UINT nAnnunciators = 0;
|
|
|
|
static BOOL bDebug = TRUE;
|
|
|
|
static UINT nLexLine;
|
|
|
|
static UINT nLexInteger;
|
|
|
|
static UINT nBlocksIncludeLevel;
|
|
|
|
static UINT nLinesIncludeLevel;
|
|
|
|
static DWORD nKMLFlags = 0;
|
|
|
|
static LPTSTR szLexString;
|
|
|
|
static LPTSTR szText;
|
2024-03-19 22:38:33 +01:00
|
|
|
static LPCTSTR szLexDelim[] =
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
2024-03-19 23:35:29 +01:00
|
|
|
_T(" \t\n\r"), // valid whitespaces for LEX_BLOCK
|
|
|
|
_T(" \t\n\r"), // valid whitespaces for LEX_COMMAND
|
|
|
|
_T(" \t\r") // valid whitespaces for LEX_PARAM
|
2024-03-19 22:22:29 +01:00
|
|
|
};
|
|
|
|
|
2024-03-19 22:37:54 +01:00
|
|
|
static KmlToken pLexToken[] =
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
2024-03-19 22:37:03 +01:00
|
|
|
{TOK_ANNUNCIATOR,000001,11,_T("Annunciator")},
|
|
|
|
{TOK_BACKGROUND, 000000,10,_T("Background")},
|
|
|
|
{TOK_IFPRESSED, 000001, 9,_T("IfPressed")},
|
|
|
|
{TOK_RESETFLAG, 000001, 9,_T("ResetFlag")},
|
|
|
|
{TOK_SCANCODE, 000001, 8,_T("Scancode")},
|
2024-03-19 22:38:33 +01:00
|
|
|
{TOK_HARDWARE, 000002, 8,_T("Hardware")},
|
2024-03-19 22:37:03 +01:00
|
|
|
{TOK_MENUITEM, 000001, 8,_T("MenuItem")},
|
|
|
|
{TOK_SETFLAG, 000001, 7,_T("SetFlag")},
|
|
|
|
{TOK_RELEASE, 000001, 7,_T("Release")},
|
|
|
|
{TOK_VIRTUAL, 000000, 7,_T("Virtual")},
|
|
|
|
{TOK_INCLUDE, 000002, 7,_T("Include")},
|
|
|
|
{TOK_NOTFLAG, 000001, 7,_T("NotFlag")},
|
|
|
|
{TOK_GLOBAL, 000000, 6,_T("Global")},
|
|
|
|
{TOK_AUTHOR, 000002, 6,_T("Author")},
|
|
|
|
{TOK_BITMAP, 000002, 6,_T("Bitmap")},
|
|
|
|
{TOK_OFFSET, 000011, 6,_T("Offset")},
|
|
|
|
{TOK_BUTTON, 000001, 6,_T("Button")},
|
|
|
|
{TOK_IFFLAG, 000001, 6,_T("IfFlag")},
|
|
|
|
{TOK_ONDOWN, 000000, 6,_T("OnDown")},
|
|
|
|
{TOK_NOHOLD, 000000, 6,_T("NoHold")},
|
2024-03-19 23:35:29 +01:00
|
|
|
{TOK_TOPBAR, 000001, 6,_T("Topbar")}, // for PPC compatibility reasons
|
2024-03-19 22:37:03 +01:00
|
|
|
{TOK_TITLE, 000002, 5,_T("Title")},
|
|
|
|
{TOK_OUTIN, 000011, 5,_T("OutIn")},
|
|
|
|
{TOK_PATCH, 000002, 5,_T("Patch")},
|
|
|
|
{TOK_PRINT, 000002, 5,_T("Print")},
|
|
|
|
{TOK_DEBUG, 000001, 5,_T("Debug")},
|
|
|
|
{TOK_COLOR, 001111, 5,_T("Color")},
|
|
|
|
{TOK_MODEL, 000002, 5,_T("Model")},
|
|
|
|
{TOK_CLASS, 000001, 5,_T("Class")},
|
|
|
|
{TOK_PRESS, 000001, 5,_T("Press")},
|
|
|
|
{TOK_TYPE, 000001, 4,_T("Type")},
|
|
|
|
{TOK_SIZE, 000011, 4,_T("Size")},
|
|
|
|
{TOK_ZOOM, 000001, 4,_T("Zoom")},
|
|
|
|
{TOK_DOWN, 000011, 4,_T("Down")},
|
|
|
|
{TOK_ELSE, 000000, 4,_T("Else")},
|
|
|
|
{TOK_ONUP, 000000, 4,_T("OnUp")},
|
|
|
|
{TOK_MAP, 000011, 3,_T("Map")},
|
|
|
|
{TOK_ROM, 000002, 3,_T("Rom")},
|
2024-03-19 23:35:29 +01:00
|
|
|
{TOK_VGA, 000001, 3,_T("Vga")}, // for PPC compatibility reasons
|
2024-03-19 22:37:03 +01:00
|
|
|
{TOK_LCD, 000000, 3,_T("Lcd")},
|
|
|
|
{TOK_END, 000000, 3,_T("End")},
|
|
|
|
{0, 000000, 0,_T("")},
|
2024-03-19 22:22:29 +01:00
|
|
|
};
|
|
|
|
|
2024-03-19 23:35:29 +01:00
|
|
|
static CONST TokenId eIsGlobalBlock[] =
|
|
|
|
{
|
|
|
|
TOK_GLOBAL,
|
|
|
|
TOK_BACKGROUND,
|
|
|
|
TOK_LCD,
|
|
|
|
TOK_ANNUNCIATOR,
|
|
|
|
TOK_BUTTON,
|
|
|
|
TOK_SCANCODE
|
|
|
|
};
|
|
|
|
|
2024-03-19 23:33:35 +01:00
|
|
|
static CONST TokenId eIsBlock[] =
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
|
|
|
TOK_IFFLAG,
|
|
|
|
TOK_IFPRESSED,
|
|
|
|
TOK_ONDOWN,
|
2024-03-19 23:33:35 +01:00
|
|
|
TOK_ONUP
|
2024-03-19 22:22:29 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static BOOL bClicking = FALSE;
|
|
|
|
static UINT uButtonClicked = 0;
|
|
|
|
|
2024-03-19 22:25:45 +01:00
|
|
|
static BOOL bPressed = FALSE; // no key pressed
|
|
|
|
static UINT uLastPressedKey = 0; // var for last pressed key
|
2024-03-19 22:24:30 +01:00
|
|
|
|
2024-03-19 22:22:29 +01:00
|
|
|
//################
|
|
|
|
//#
|
|
|
|
//# Compilation Result
|
|
|
|
//#
|
|
|
|
//################
|
|
|
|
|
|
|
|
static UINT nLogLength = 0;
|
2024-03-19 22:37:03 +01:00
|
|
|
static LPTSTR szLog = NULL;
|
2024-03-19 22:22:29 +01:00
|
|
|
|
|
|
|
static VOID ClearLog()
|
|
|
|
{
|
|
|
|
nLogLength = 0;
|
|
|
|
if (szLog != NULL)
|
|
|
|
{
|
2024-03-19 22:38:33 +01:00
|
|
|
HeapFree(hHeap,0,szLog);
|
2024-03-19 22:22:29 +01:00
|
|
|
szLog = NULL;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-03-19 23:33:35 +01:00
|
|
|
static VOID AddToLog(LPCTSTR szString)
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
2024-03-19 23:33:35 +01:00
|
|
|
UINT nLength = lstrlen(szString) + 2; // CR+LF
|
2024-03-19 22:22:29 +01:00
|
|
|
if (szLog == NULL)
|
|
|
|
{
|
2024-03-19 23:33:35 +01:00
|
|
|
nLogLength = nLength + 1; // \0
|
2024-03-19 22:38:33 +01:00
|
|
|
szLog = HeapAlloc(hHeap,0,nLogLength*sizeof(szLog[0]));
|
2024-03-19 22:22:29 +01:00
|
|
|
if (szLog==NULL)
|
|
|
|
{
|
|
|
|
nLogLength = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
lstrcpy(szLog,szString);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-03-19 23:33:35 +01:00
|
|
|
LPTSTR szLogTmp = HeapReAlloc(hHeap,0,szLog,(nLogLength+nLength)*sizeof(szLog[0]));
|
2024-03-19 22:37:03 +01:00
|
|
|
if (szLogTmp == NULL)
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
2024-03-19 22:37:03 +01:00
|
|
|
ClearLog();
|
2024-03-19 22:22:29 +01:00
|
|
|
return;
|
|
|
|
}
|
2024-03-19 22:37:03 +01:00
|
|
|
szLog = szLogTmp;
|
|
|
|
lstrcpy(&szLog[nLogLength-1],szString);
|
2024-03-19 23:33:35 +01:00
|
|
|
nLogLength += nLength;
|
2024-03-19 22:22:29 +01:00
|
|
|
}
|
2024-03-19 22:37:03 +01:00
|
|
|
szLog[nLogLength-3] = _T('\r');
|
|
|
|
szLog[nLogLength-2] = _T('\n');
|
2024-03-19 22:22:29 +01:00
|
|
|
szLog[nLogLength-1] = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VOID __cdecl PrintfToLog(LPCTSTR lpFormat, ...)
|
|
|
|
{
|
2024-03-19 23:33:35 +01:00
|
|
|
TCHAR cOutput[1024];
|
2024-03-19 22:22:29 +01:00
|
|
|
va_list arglist;
|
|
|
|
|
|
|
|
va_start(arglist,lpFormat);
|
2024-03-19 23:33:35 +01:00
|
|
|
wvsprintf(cOutput,lpFormat,arglist);
|
|
|
|
AddToLog(cOutput);
|
2024-03-19 22:22:29 +01:00
|
|
|
va_end(arglist);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL CALLBACK KMLLogProc(HWND hDlg, UINT message, DWORD wParam, LONG lParam)
|
|
|
|
{
|
2024-03-19 23:33:35 +01:00
|
|
|
LPCTSTR szString;
|
2024-03-19 22:22:29 +01:00
|
|
|
|
|
|
|
switch (message)
|
|
|
|
{
|
|
|
|
case WM_INITDIALOG:
|
|
|
|
// set OK
|
2024-03-19 23:33:35 +01:00
|
|
|
EnableWindow(GetDlgItem(hDlg,IDOK),lParam);
|
2024-03-19 22:22:29 +01:00
|
|
|
// set IDC_TITLE
|
|
|
|
szString = GetStringParam(pKml, TOK_GLOBAL, TOK_TITLE, 0);
|
2024-03-19 22:37:03 +01:00
|
|
|
if (szString == NULL) szString = _T("Untitled");
|
2024-03-19 22:22:29 +01:00
|
|
|
SetDlgItemText(hDlg,IDC_TITLE,szString);
|
|
|
|
// set IDC_AUTHOR
|
|
|
|
szString = GetStringParam(pKml, TOK_GLOBAL, TOK_AUTHOR, 0);
|
2024-03-19 22:37:03 +01:00
|
|
|
if (szString == NULL) szString = _T("<Unknown Author>");
|
2024-03-19 22:22:29 +01:00
|
|
|
SetDlgItemText(hDlg,IDC_AUTHOR,szString);
|
|
|
|
// set IDC_KMLLOG
|
2024-03-19 23:33:35 +01:00
|
|
|
szString = szLog;
|
|
|
|
if (szString == NULL) szString = _T("Memory Allocation Failure.");
|
|
|
|
SetDlgItemText(hDlg,IDC_KMLLOG,szString);
|
2024-03-19 22:22:29 +01:00
|
|
|
// set IDC_ALWAYSDISPLOG
|
|
|
|
CheckDlgButton(hDlg,IDC_ALWAYSDISPLOG,bAlwaysDisplayLog);
|
|
|
|
return TRUE;
|
|
|
|
case WM_COMMAND:
|
2024-03-19 22:38:33 +01:00
|
|
|
wParam = LOWORD(wParam);
|
|
|
|
if ((wParam==IDOK)||(wParam==IDCANCEL))
|
|
|
|
{
|
|
|
|
bAlwaysDisplayLog = IsDlgButtonChecked(hDlg, IDC_ALWAYSDISPLOG);
|
|
|
|
EndDialog(hDlg, wParam);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2024-03-19 22:22:29 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL DisplayKMLLog(BOOL bOkEnabled)
|
|
|
|
{
|
2024-03-19 23:33:35 +01:00
|
|
|
return IDOK == DialogBoxParam(hApp,
|
|
|
|
MAKEINTRESOURCE(IDD_KMLLOG),
|
|
|
|
hWnd,
|
|
|
|
(DLGPROC)KMLLogProc,
|
|
|
|
bOkEnabled);
|
2024-03-19 22:22:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//################
|
|
|
|
//#
|
|
|
|
//# Choose Script
|
|
|
|
//#
|
|
|
|
//################
|
|
|
|
|
|
|
|
typedef struct _KmlScript
|
|
|
|
{
|
2024-03-19 22:37:03 +01:00
|
|
|
LPTSTR szFilename;
|
|
|
|
LPTSTR szTitle;
|
2024-03-19 23:33:35 +01:00
|
|
|
DWORD nId;
|
2024-03-19 22:22:29 +01:00
|
|
|
struct _KmlScript* pNext;
|
|
|
|
} KmlScript;
|
|
|
|
|
2024-03-19 23:33:35 +01:00
|
|
|
static KmlScript* pKmlList = NULL;
|
2024-03-19 22:22:29 +01:00
|
|
|
static CHAR cKmlType;
|
|
|
|
|
2024-03-19 22:38:33 +01:00
|
|
|
static VOID DestroyKmlList(VOID)
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
|
|
|
KmlScript* pList;
|
|
|
|
|
|
|
|
while (pKmlList)
|
|
|
|
{
|
|
|
|
pList = pKmlList->pNext;
|
2024-03-19 22:38:33 +01:00
|
|
|
HeapFree(hHeap,0,pKmlList->szFilename);
|
|
|
|
HeapFree(hHeap,0,pKmlList->szTitle);
|
|
|
|
HeapFree(hHeap,0,pKmlList);
|
2024-03-19 22:22:29 +01:00
|
|
|
pKmlList = pList;
|
|
|
|
}
|
2024-03-19 22:38:33 +01:00
|
|
|
return;
|
2024-03-19 22:22:29 +01:00
|
|
|
}
|
|
|
|
|
2024-03-19 22:38:33 +01:00
|
|
|
static VOID CreateKmlList(VOID)
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
|
|
|
HANDLE hFindFile;
|
|
|
|
WIN32_FIND_DATA pFindFileData;
|
2024-03-19 23:33:35 +01:00
|
|
|
UINT nKmlFiles;
|
2024-03-19 22:22:29 +01:00
|
|
|
|
2024-03-19 23:33:35 +01:00
|
|
|
_ASSERT(pKmlList == NULL); // KML file list must be empty
|
2024-03-19 22:38:33 +01:00
|
|
|
SetCurrentDirectory(szEmuDirectory);
|
2024-03-19 22:37:03 +01:00
|
|
|
hFindFile = FindFirstFile(_T("*.KML"),&pFindFileData);
|
2024-03-19 22:22:29 +01:00
|
|
|
SetCurrentDirectory(szCurrentDirectory);
|
|
|
|
if (hFindFile == INVALID_HANDLE_VALUE) return;
|
2024-03-19 23:33:35 +01:00
|
|
|
nKmlFiles = 0;
|
2024-03-19 22:22:29 +01:00
|
|
|
do
|
|
|
|
{
|
|
|
|
KmlScript* pScript;
|
2024-03-19 22:37:54 +01:00
|
|
|
KmlBlock* pBlock;
|
2024-03-19 22:37:03 +01:00
|
|
|
LPTSTR szTitle;
|
2024-03-19 22:22:29 +01:00
|
|
|
|
|
|
|
pBlock = LoadKMLGlobal(pFindFileData.cFileName);
|
|
|
|
if (pBlock == NULL) continue;
|
2024-03-19 22:38:33 +01:00
|
|
|
// check for correct KML script platform
|
|
|
|
szTitle = GetStringParam(pBlock,TOK_GLOBAL,TOK_HARDWARE,0);
|
|
|
|
if (szTitle && lstrcmpi(_T(HARDWARE),szTitle) != 0)
|
|
|
|
{
|
|
|
|
FreeBlocks(pBlock);
|
|
|
|
continue;
|
|
|
|
}
|
2024-03-19 22:22:29 +01:00
|
|
|
if (cKmlType)
|
|
|
|
{
|
|
|
|
szTitle = GetStringParam(pBlock,TOK_GLOBAL,TOK_MODEL,0);
|
|
|
|
if ((!szTitle)||(szTitle[0]!=cKmlType))
|
|
|
|
{
|
|
|
|
FreeBlocks(pBlock);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2024-03-19 23:33:35 +01:00
|
|
|
VERIFY(pScript = HeapAlloc(hHeap,0,sizeof(KmlScript)));
|
2024-03-19 22:22:29 +01:00
|
|
|
pScript->szFilename = DuplicateString(pFindFileData.cFileName);
|
|
|
|
szTitle = GetStringParam(pBlock,TOK_GLOBAL,TOK_TITLE,0);
|
2024-03-19 23:33:35 +01:00
|
|
|
if (szTitle == NULL) szTitle = pScript->szFilename;
|
2024-03-19 22:22:29 +01:00
|
|
|
pScript->szTitle = DuplicateString(szTitle);
|
|
|
|
FreeBlocks(pBlock);
|
|
|
|
pScript->nId = nKmlFiles;
|
|
|
|
pScript->pNext = pKmlList;
|
|
|
|
pKmlList = pScript;
|
|
|
|
nKmlFiles++;
|
|
|
|
} while (FindNextFile(hFindFile,&pFindFileData));
|
|
|
|
FindClose(hFindFile);
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
|
2024-03-19 22:38:33 +01:00
|
|
|
static INT CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lp, LPARAM pData)
|
|
|
|
{
|
|
|
|
TCHAR szDir[MAX_PATH];
|
|
|
|
|
|
|
|
switch(uMsg)
|
|
|
|
{
|
|
|
|
case BFFM_INITIALIZED:
|
|
|
|
SendMessage(hwnd,BFFM_SETSELECTION,TRUE,pData);
|
|
|
|
break;
|
|
|
|
case BFFM_SELCHANGED:
|
|
|
|
// Set the status window to the currently selected path.
|
2024-03-19 23:35:29 +01:00
|
|
|
if (SHGetPathFromIDList((LPITEMIDLIST) lp,szDir))
|
2024-03-19 22:38:33 +01:00
|
|
|
{
|
|
|
|
SendMessage(hwnd,BFFM_SETSTATUSTEXT,0,(LPARAM) szDir);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VOID BrowseFolder(HWND hDlg)
|
|
|
|
{
|
|
|
|
TCHAR szDir[MAX_PATH];
|
|
|
|
BROWSEINFO bi;
|
|
|
|
LPITEMIDLIST pidl;
|
|
|
|
LPMALLOC pMalloc;
|
|
|
|
|
|
|
|
// gets the shell's default allocator
|
|
|
|
if (SUCCEEDED(SHGetMalloc(&pMalloc)))
|
|
|
|
{
|
|
|
|
GetDlgItemText(hDlg,IDC_EMUDIR,szDir,ARRAYSIZEOF(szDir));
|
|
|
|
|
|
|
|
ZeroMemory(&bi,sizeof(bi));
|
|
|
|
bi.hwndOwner = hDlg;
|
|
|
|
bi.pidlRoot = NULL;
|
|
|
|
bi.pszDisplayName = NULL;
|
|
|
|
bi.lpszTitle = _T("Choose a folder:");
|
|
|
|
bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT;
|
|
|
|
bi.lpfn = BrowseCallbackProc;
|
|
|
|
bi.lParam = (LPARAM) szDir; // current setting
|
|
|
|
|
|
|
|
pidl = SHBrowseForFolder(&bi);
|
|
|
|
if (pidl)
|
|
|
|
{
|
|
|
|
if (SHGetPathFromIDList(pidl,szDir))
|
|
|
|
{
|
|
|
|
SetDlgItemText(hDlg,IDC_EMUDIR,szDir);
|
|
|
|
}
|
|
|
|
// free the PIDL allocated by SHBrowseForFolder
|
|
|
|
pMalloc->lpVtbl->Free(pMalloc,pidl);
|
|
|
|
}
|
|
|
|
// release the shell's allocator
|
|
|
|
pMalloc->lpVtbl->Release(pMalloc);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-03-19 22:22:29 +01:00
|
|
|
static BOOL CALLBACK ChooseKMLProc(HWND hDlg, UINT message, DWORD wParam, LONG lParam)
|
|
|
|
{
|
|
|
|
HWND hList;
|
|
|
|
KmlScript* pList;
|
|
|
|
UINT nIndex;
|
|
|
|
|
|
|
|
switch (message)
|
|
|
|
{
|
|
|
|
case WM_INITDIALOG:
|
2024-03-19 22:38:33 +01:00
|
|
|
SetDlgItemText(hDlg,IDC_EMUDIR,szEmuDirectory);
|
2024-03-19 22:22:29 +01:00
|
|
|
hList = GetDlgItem(hDlg,IDC_KMLSCRIPT);
|
|
|
|
SendMessage(hList, CB_RESETCONTENT, 0, 0);
|
|
|
|
pList = pKmlList;
|
|
|
|
while (pList)
|
|
|
|
{
|
|
|
|
nIndex = SendMessage(hList, CB_ADDSTRING, 0, (LPARAM)pList->szTitle);
|
|
|
|
SendMessage(hList, CB_SETITEMDATA, nIndex, (LPARAM)pList->nId);
|
|
|
|
pList = pList->pNext;
|
|
|
|
}
|
|
|
|
SendMessage(hList, CB_SETCURSEL, 0, 0);
|
|
|
|
return TRUE;
|
|
|
|
case WM_COMMAND:
|
2024-03-19 22:38:33 +01:00
|
|
|
switch (LOWORD(wParam))
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
2024-03-19 22:38:33 +01:00
|
|
|
case IDC_EMUDIRSEL:
|
|
|
|
BrowseFolder(hDlg); // select new folder for IDC_EMUDIR
|
2024-03-19 23:35:29 +01:00
|
|
|
// fall into IDC_UPDATE to search for KML files in new folder
|
2024-03-19 22:38:33 +01:00
|
|
|
case IDC_UPDATE:
|
2024-03-19 22:22:29 +01:00
|
|
|
DestroyKmlList();
|
2024-03-19 22:38:33 +01:00
|
|
|
GetDlgItemText(hDlg,IDC_EMUDIR,szEmuDirectory,ARRAYSIZEOF(szEmuDirectory));
|
2024-03-19 22:22:29 +01:00
|
|
|
CreateKmlList();
|
|
|
|
hList = GetDlgItem(hDlg,IDC_KMLSCRIPT);
|
|
|
|
SendMessage(hList, CB_RESETCONTENT, 0, 0);
|
|
|
|
pList = pKmlList;
|
|
|
|
while (pList)
|
|
|
|
{
|
|
|
|
nIndex = SendMessage(hList, CB_ADDSTRING, 0, (LPARAM)pList->szTitle);
|
|
|
|
SendMessage(hList, CB_SETITEMDATA, nIndex, (LPARAM)pList->nId);
|
|
|
|
pList = pList->pNext;
|
|
|
|
}
|
|
|
|
SendMessage(hList, CB_SETCURSEL, 0, 0);
|
2024-03-19 22:38:33 +01:00
|
|
|
return TRUE;
|
|
|
|
case IDOK:
|
|
|
|
GetDlgItemText(hDlg,IDC_EMUDIR,szEmuDirectory,ARRAYSIZEOF(szEmuDirectory));
|
2024-03-19 22:22:29 +01:00
|
|
|
hList = GetDlgItem(hDlg,IDC_KMLSCRIPT);
|
|
|
|
nIndex = SendMessage(hList, CB_GETCURSEL, 0, 0);
|
|
|
|
nIndex = SendMessage(hList, CB_GETITEMDATA, nIndex, 0);
|
|
|
|
pList = pKmlList;
|
|
|
|
while (pList)
|
|
|
|
{
|
2024-03-19 23:33:35 +01:00
|
|
|
if (pList->nId == nIndex)
|
|
|
|
{
|
|
|
|
lstrcpy(szCurrentKml, pList->szFilename);
|
|
|
|
EndDialog(hDlg, IDOK);
|
|
|
|
break;
|
|
|
|
}
|
2024-03-19 22:22:29 +01:00
|
|
|
pList = pList->pNext;
|
|
|
|
}
|
2024-03-19 22:38:33 +01:00
|
|
|
return TRUE;
|
|
|
|
case IDCANCEL:
|
2024-03-19 22:22:29 +01:00
|
|
|
EndDialog(hDlg, IDCANCEL);
|
2024-03-19 22:38:33 +01:00
|
|
|
return TRUE;
|
2024-03-19 22:22:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
2024-03-19 22:38:33 +01:00
|
|
|
UNREFERENCED_PARAMETER(lParam);
|
2024-03-19 22:22:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL DisplayChooseKml(CHAR cType)
|
|
|
|
{
|
|
|
|
BOOL bResult;
|
|
|
|
cKmlType = cType;
|
|
|
|
CreateKmlList();
|
|
|
|
bResult = DialogBox(hApp, MAKEINTRESOURCE(IDD_CHOOSEKML), hWnd, (DLGPROC)ChooseKMLProc);
|
|
|
|
DestroyKmlList();
|
|
|
|
return (bResult == IDOK);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-03-19 22:37:03 +01:00
|
|
|
//################
|
|
|
|
//#
|
|
|
|
//# KML File Mapping
|
|
|
|
//#
|
|
|
|
//################
|
|
|
|
|
|
|
|
static LPTSTR MapKMLFile(HANDLE hFile)
|
|
|
|
{
|
|
|
|
DWORD lBytesRead;
|
|
|
|
DWORD dwFileSizeLow;
|
|
|
|
DWORD dwFileSizeHigh;
|
|
|
|
LPTSTR lpBuf = NULL;
|
|
|
|
|
|
|
|
dwFileSizeLow = GetFileSize(hFile, &dwFileSizeHigh);
|
|
|
|
if (dwFileSizeHigh != 0)
|
|
|
|
{
|
|
|
|
AddToLog(_T("File is too large."));
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2024-03-19 22:38:33 +01:00
|
|
|
lpBuf = HeapAlloc(hHeap,0,(dwFileSizeLow+1)*sizeof(lpBuf[0]));
|
2024-03-19 22:37:03 +01:00
|
|
|
if (lpBuf == NULL)
|
|
|
|
{
|
|
|
|
PrintfToLog(_T("Cannot allocate %i bytes."), (dwFileSizeLow+1)*sizeof(lpBuf[0]));
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
#if defined _UNICODE
|
|
|
|
{
|
2024-03-19 22:38:33 +01:00
|
|
|
LPSTR szTmp = HeapAlloc(hHeap,0,dwFileSizeLow+1);
|
2024-03-19 22:37:03 +01:00
|
|
|
if (szTmp == NULL)
|
|
|
|
{
|
2024-03-19 22:38:33 +01:00
|
|
|
HeapFree(hHeap,0,lpBuf);
|
2024-03-19 22:37:03 +01:00
|
|
|
lpBuf = NULL;
|
|
|
|
PrintfToLog(_T("Cannot allocate %i bytes."), dwFileSizeLow+1);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
ReadFile(hFile, szTmp, dwFileSizeLow, &lBytesRead, NULL);
|
|
|
|
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, szTmp, lBytesRead, lpBuf, dwFileSizeLow+1);
|
2024-03-19 22:38:33 +01:00
|
|
|
HeapFree(hHeap,0,szTmp);
|
2024-03-19 22:37:03 +01:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
{
|
|
|
|
ReadFile(hFile, lpBuf, dwFileSizeLow, &lBytesRead, NULL);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
lpBuf[dwFileSizeLow] = 0;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
CloseHandle(hFile);
|
|
|
|
return lpBuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-03-19 22:22:29 +01:00
|
|
|
//################
|
|
|
|
//#
|
|
|
|
//# Script Parsing
|
|
|
|
//#
|
|
|
|
//################
|
|
|
|
|
2024-03-19 22:37:54 +01:00
|
|
|
static VOID FatalError(VOID)
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
2024-03-19 22:37:03 +01:00
|
|
|
PrintfToLog(_T("Fatal Error at line %i"), nLexLine);
|
2024-03-19 22:22:29 +01:00
|
|
|
szText[0] = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-03-19 22:37:03 +01:00
|
|
|
static VOID InitLex(LPTSTR szScript)
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
|
|
|
nLexLine = 1;
|
|
|
|
szText = szScript;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-03-19 22:37:54 +01:00
|
|
|
static VOID CleanLex(VOID)
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
|
|
|
nLexLine = 0;
|
|
|
|
nLexInteger = 0;
|
|
|
|
szLexString = NULL;
|
|
|
|
szText = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-03-19 23:35:29 +01:00
|
|
|
static BOOL IsGlobalBlock(TokenId eId)
|
|
|
|
{
|
|
|
|
UINT i;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAYSIZEOF(eIsGlobalBlock); ++i)
|
|
|
|
{
|
|
|
|
if (eId == eIsGlobalBlock[i]) return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2024-03-19 22:22:29 +01:00
|
|
|
static BOOL IsBlock(TokenId eId)
|
|
|
|
{
|
2024-03-19 23:33:35 +01:00
|
|
|
UINT i;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAYSIZEOF(eIsBlock); ++i)
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
2024-03-19 23:33:35 +01:00
|
|
|
if (eId == eIsBlock[i]) return TRUE;
|
2024-03-19 22:22:29 +01:00
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LPCTSTR GetStringOf(TokenId eId)
|
|
|
|
{
|
|
|
|
UINT i = 0;
|
|
|
|
while (pLexToken[i].nLen)
|
|
|
|
{
|
|
|
|
if (pLexToken[i].eId == eId) return pLexToken[i].szName;
|
|
|
|
i++;
|
|
|
|
}
|
2024-03-19 22:37:03 +01:00
|
|
|
return _T("<Undefined>");
|
2024-03-19 22:22:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static VOID SkipWhite(UINT nMode)
|
|
|
|
{
|
|
|
|
UINT i;
|
|
|
|
loop:
|
|
|
|
i = 0;
|
|
|
|
while (szLexDelim[nMode][i])
|
|
|
|
{
|
|
|
|
if (*szText == szLexDelim[nMode][i]) break;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
if (szLexDelim[nMode][i] != 0)
|
|
|
|
{
|
2024-03-19 22:37:03 +01:00
|
|
|
if (szLexDelim[nMode][i]==_T('\n')) nLexLine++;
|
2024-03-19 22:22:29 +01:00
|
|
|
szText++;
|
|
|
|
goto loop;
|
|
|
|
}
|
2024-03-19 22:37:03 +01:00
|
|
|
if (*szText==_T('#'))
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
2024-03-19 23:35:29 +01:00
|
|
|
do szText++; while (*szText != _T('\n') && *szText != 0);
|
2024-03-19 22:22:29 +01:00
|
|
|
if (nMode != LEX_PARAM) goto loop;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static TokenId ParseToken(UINT nMode)
|
|
|
|
{
|
|
|
|
UINT i, j, k;
|
|
|
|
i = 0;
|
|
|
|
while (szText[i])
|
|
|
|
{
|
|
|
|
j = 0;
|
|
|
|
while (szLexDelim[nMode][j])
|
|
|
|
{
|
|
|
|
if (szLexDelim[nMode][j] == szText[i]) break;
|
|
|
|
j++;
|
|
|
|
}
|
2024-03-19 22:37:03 +01:00
|
|
|
if (szLexDelim[nMode][j] == _T('\n')) nLexLine++;
|
2024-03-19 22:22:29 +01:00
|
|
|
if (szLexDelim[nMode][j] != 0) break;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
if (i==0)
|
|
|
|
{
|
|
|
|
return TOK_NONE;
|
|
|
|
}
|
|
|
|
j = 0;
|
|
|
|
while (pLexToken[j].nLen)
|
|
|
|
{
|
|
|
|
if (pLexToken[j].nLen>i)
|
|
|
|
{
|
|
|
|
j++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (pLexToken[j].nLen<i) break;
|
|
|
|
k = 0;
|
2024-03-19 22:37:03 +01:00
|
|
|
if (_tcsncmp(pLexToken[j].szName, szText, i)==0)
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
|
|
|
szText += i;
|
|
|
|
return pLexToken[j].eId;
|
|
|
|
}
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
szText[i] = 0;
|
|
|
|
if (bDebug)
|
|
|
|
{
|
2024-03-19 22:37:03 +01:00
|
|
|
PrintfToLog(_T("%i: Undefined token %s"), nLexLine, szText);
|
2024-03-19 22:22:29 +01:00
|
|
|
return TOK_NONE;
|
|
|
|
}
|
|
|
|
return TOK_NONE;
|
|
|
|
}
|
|
|
|
|
2024-03-19 22:37:54 +01:00
|
|
|
static DWORD ParseInteger(VOID)
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
|
|
|
DWORD nNum = 0;
|
2024-03-19 22:37:03 +01:00
|
|
|
while (_istdigit(*szText))
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
2024-03-19 22:37:03 +01:00
|
|
|
nNum = nNum * 10 + ((*szText) - _T('0'));
|
2024-03-19 22:22:29 +01:00
|
|
|
szText++;
|
2024-03-19 23:35:29 +01:00
|
|
|
}
|
2024-03-19 22:22:29 +01:00
|
|
|
return nNum;
|
|
|
|
}
|
|
|
|
|
2024-03-19 22:37:54 +01:00
|
|
|
static LPTSTR ParseString(VOID)
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
2024-03-19 23:33:35 +01:00
|
|
|
LPTSTR lpszString;
|
2024-03-19 22:37:03 +01:00
|
|
|
UINT nLength;
|
|
|
|
UINT nBlock;
|
2024-03-19 22:22:29 +01:00
|
|
|
|
2024-03-19 23:33:35 +01:00
|
|
|
szText++; // skip leading '"'
|
2024-03-19 22:22:29 +01:00
|
|
|
nLength = 0;
|
2024-03-19 23:33:35 +01:00
|
|
|
nBlock = 256;
|
|
|
|
lpszString = HeapAlloc(hHeap,0,nBlock * sizeof(lpszString[0]));
|
2024-03-19 22:37:03 +01:00
|
|
|
while (*szText != _T('"'))
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
2024-03-19 23:33:35 +01:00
|
|
|
if (nLength == nBlock - 1) // ran out of buffer space
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
2024-03-19 23:33:35 +01:00
|
|
|
nBlock += 256;
|
|
|
|
lpszString = HeapReAlloc(hHeap,0,lpszString,nBlock * sizeof(lpszString[0]));
|
2024-03-19 22:22:29 +01:00
|
|
|
}
|
2024-03-19 23:33:35 +01:00
|
|
|
|
|
|
|
if (*szText == _T('\\')) szText++; // skip '\' escape char
|
|
|
|
if (*szText == 0) // EOS found inside string
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
2024-03-19 23:33:35 +01:00
|
|
|
HeapFree(hHeap,0,lpszString);
|
|
|
|
FatalError();
|
|
|
|
return NULL;
|
2024-03-19 22:22:29 +01:00
|
|
|
}
|
2024-03-19 23:33:35 +01:00
|
|
|
lpszString[nLength++] = *szText++; // save char
|
2024-03-19 22:22:29 +01:00
|
|
|
}
|
2024-03-19 23:33:35 +01:00
|
|
|
szText++; // skip ending '"'
|
|
|
|
lpszString[nLength] = 0; // set EOS
|
|
|
|
|
|
|
|
// release unnecessary allocated bytes
|
|
|
|
return HeapReAlloc(hHeap,0,lpszString,(nLength+1) * sizeof(lpszString[0]));
|
|
|
|
}
|
2024-03-19 22:22:29 +01:00
|
|
|
|
|
|
|
static TokenId Lex(UINT nMode)
|
|
|
|
{
|
2024-03-19 23:35:29 +01:00
|
|
|
_ASSERT(nMode >= LEX_BLOCK && nMode <= LEX_PARAM);
|
|
|
|
_ASSERT(nMode >= 0 && nMode < ARRAYSIZEOF(szLexDelim));
|
|
|
|
|
2024-03-19 22:22:29 +01:00
|
|
|
SkipWhite(nMode);
|
2024-03-19 22:37:03 +01:00
|
|
|
if (_istdigit(*szText))
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
|
|
|
nLexInteger = ParseInteger();
|
|
|
|
return TOK_INTEGER;
|
|
|
|
}
|
2024-03-19 22:37:03 +01:00
|
|
|
if (*szText == _T('"'))
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
|
|
|
szLexString = ParseString();
|
|
|
|
return TOK_STRING;
|
|
|
|
}
|
2024-03-19 22:37:03 +01:00
|
|
|
if ((nMode == LEX_PARAM) && (*szText == _T('\n')))
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
|
|
|
nLexLine++;
|
|
|
|
szText++;
|
|
|
|
return TOK_EOL;
|
|
|
|
}
|
|
|
|
return ParseToken(nMode);
|
|
|
|
}
|
|
|
|
|
2024-03-19 22:37:54 +01:00
|
|
|
static KmlLine* ParseLine(TokenId eCommand)
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
2024-03-19 22:37:54 +01:00
|
|
|
UINT i, j;
|
|
|
|
DWORD nParams;
|
|
|
|
TokenId eToken;
|
|
|
|
KmlLine* pLine;
|
2024-03-19 22:22:29 +01:00
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (pLexToken[i].nLen)
|
|
|
|
{
|
|
|
|
if (pLexToken[i].eId == eCommand) break;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
if (pLexToken[i].nLen == 0) return NULL;
|
|
|
|
|
|
|
|
j = 0;
|
2024-03-19 22:38:33 +01:00
|
|
|
pLine = HeapAlloc(hHeap,HEAP_ZERO_MEMORY,sizeof(KmlLine));
|
2024-03-19 22:22:29 +01:00
|
|
|
pLine->eCommand = eCommand;
|
|
|
|
nParams = pLexToken[i].nParams;
|
|
|
|
loop:
|
|
|
|
eToken = Lex(LEX_PARAM);
|
|
|
|
if ((nParams&7)==TYPE_NONE)
|
|
|
|
{
|
|
|
|
if (eToken != TOK_EOL)
|
|
|
|
{
|
2024-03-19 22:37:03 +01:00
|
|
|
PrintfToLog(_T("%i: Too many parameters (%i expected)."), nLexLine, j);
|
2024-03-19 22:25:45 +01:00
|
|
|
goto errline; // free memory of arguments
|
2024-03-19 22:22:29 +01:00
|
|
|
}
|
|
|
|
return pLine;
|
|
|
|
}
|
|
|
|
if ((nParams&7)==TYPE_INTEGER)
|
|
|
|
{
|
|
|
|
if (eToken != TOK_INTEGER)
|
|
|
|
{
|
2024-03-19 22:37:03 +01:00
|
|
|
PrintfToLog(_T("%i: Parameter %i of %s must be an integer."), nLexLine, j+1, pLexToken[i].szName);
|
2024-03-19 22:25:45 +01:00
|
|
|
goto errline; // free memory of arguments
|
2024-03-19 22:22:29 +01:00
|
|
|
}
|
|
|
|
pLine->nParam[j++] = nLexInteger;
|
|
|
|
nParams >>= 3;
|
|
|
|
goto loop;
|
|
|
|
}
|
|
|
|
if ((nParams&7)==TYPE_STRING)
|
|
|
|
{
|
|
|
|
if (eToken != TOK_STRING)
|
|
|
|
{
|
2024-03-19 22:37:03 +01:00
|
|
|
PrintfToLog(_T("%i: Parameter %i of %s must be a string."), nLexLine, j+1, pLexToken[i].szName);
|
2024-03-19 22:25:45 +01:00
|
|
|
goto errline; // free memory of arguments
|
2024-03-19 22:22:29 +01:00
|
|
|
}
|
|
|
|
pLine->nParam[j++] = (DWORD)szLexString;
|
|
|
|
nParams >>= 3;
|
|
|
|
goto loop;
|
|
|
|
}
|
2024-03-19 22:37:03 +01:00
|
|
|
AddToLog(_T("Oops..."));
|
2024-03-19 22:24:30 +01:00
|
|
|
errline:
|
|
|
|
// if last argument was string, free it
|
2024-03-19 22:38:33 +01:00
|
|
|
if (eToken == TOK_STRING) HeapFree(hHeap,0,szLexString);
|
2024-03-19 22:24:30 +01:00
|
|
|
|
|
|
|
nParams = pLexToken[i].nParams; // get argument types of command
|
|
|
|
for (i=0; i<j; i++) // handle all scanned arguments
|
|
|
|
{
|
|
|
|
if ((nParams&7) == TYPE_STRING) // string type
|
|
|
|
{
|
2024-03-19 22:38:33 +01:00
|
|
|
HeapFree(hHeap,0,(LPVOID)pLine->nParam[i]);
|
2024-03-19 22:24:30 +01:00
|
|
|
}
|
2024-03-19 22:25:45 +01:00
|
|
|
nParams >>= 3; // next argument type
|
2024-03-19 22:24:30 +01:00
|
|
|
}
|
2024-03-19 22:38:33 +01:00
|
|
|
HeapFree(hHeap,0,pLine);
|
2024-03-19 22:22:29 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2024-03-19 22:37:54 +01:00
|
|
|
static KmlLine* IncludeLines(LPCTSTR szFilename)
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
2024-03-19 22:37:54 +01:00
|
|
|
HANDLE hFile;
|
|
|
|
LPTSTR lpbyBuf;
|
|
|
|
UINT uOldLine;
|
|
|
|
LPTSTR szOldText;
|
|
|
|
KmlLine* pLine;
|
2024-03-19 22:22:29 +01:00
|
|
|
|
2024-03-19 22:38:33 +01:00
|
|
|
SetCurrentDirectory(szEmuDirectory);
|
2024-03-19 23:33:35 +01:00
|
|
|
hFile = CreateFile(szFilename,
|
|
|
|
GENERIC_READ,
|
|
|
|
FILE_SHARE_READ,
|
|
|
|
NULL,
|
|
|
|
OPEN_EXISTING,
|
|
|
|
FILE_FLAG_SEQUENTIAL_SCAN,
|
|
|
|
NULL);
|
2024-03-19 22:22:29 +01:00
|
|
|
SetCurrentDirectory(szCurrentDirectory);
|
|
|
|
if (hFile == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
2024-03-19 22:37:03 +01:00
|
|
|
PrintfToLog(_T("Error while opening include file %s."), szFilename);
|
2024-03-19 22:22:29 +01:00
|
|
|
FatalError();
|
|
|
|
return NULL;
|
|
|
|
}
|
2024-03-19 22:37:03 +01:00
|
|
|
if ((lpbyBuf = MapKMLFile(hFile)) == NULL)
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
|
|
|
FatalError();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
uOldLine = nLexLine;
|
|
|
|
szOldText = szText;
|
|
|
|
|
|
|
|
nLinesIncludeLevel++;
|
2024-03-19 22:37:03 +01:00
|
|
|
PrintfToLog(_T("l%i:Including %s"), nLinesIncludeLevel, szFilename);
|
2024-03-19 22:22:29 +01:00
|
|
|
InitLex(lpbyBuf);
|
|
|
|
pLine = ParseLines();
|
|
|
|
CleanLex();
|
|
|
|
nLinesIncludeLevel--;
|
|
|
|
|
|
|
|
nLexLine = uOldLine;
|
|
|
|
szText = szOldText;
|
2024-03-19 22:38:33 +01:00
|
|
|
HeapFree(hHeap,0,lpbyBuf);
|
2024-03-19 22:22:29 +01:00
|
|
|
|
|
|
|
return pLine;
|
|
|
|
}
|
|
|
|
|
2024-03-19 22:37:54 +01:00
|
|
|
static KmlLine* ParseLines(VOID)
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
2024-03-19 22:37:54 +01:00
|
|
|
KmlLine* pFirst = NULL;
|
2024-03-19 22:38:33 +01:00
|
|
|
KmlLine* pLine = NULL;
|
2024-03-19 22:37:54 +01:00
|
|
|
TokenId eToken;
|
|
|
|
UINT nLevel = 0;
|
2024-03-19 22:22:29 +01:00
|
|
|
|
2024-03-19 22:37:03 +01:00
|
|
|
while ((eToken = Lex(LEX_COMMAND)))
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
2024-03-19 23:35:29 +01:00
|
|
|
if (IsGlobalBlock(eToken)) // check for block command
|
|
|
|
{
|
|
|
|
PrintfToLog(_T("%i: Invalid Command %s."), nLexLine, GetStringOf(eToken));
|
|
|
|
goto abort;
|
|
|
|
}
|
2024-03-19 22:22:29 +01:00
|
|
|
if (IsBlock(eToken)) nLevel++;
|
|
|
|
if (eToken == TOK_INCLUDE)
|
|
|
|
{
|
2024-03-19 22:37:03 +01:00
|
|
|
LPTSTR szFilename;
|
2024-03-19 22:24:30 +01:00
|
|
|
eToken = Lex(LEX_PARAM); // get include parameter in 'szLexString'
|
|
|
|
if (eToken != TOK_STRING) // not a string (token don't begin with ")
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
2024-03-19 22:37:03 +01:00
|
|
|
AddToLog(_T("Include: string expected as parameter."));
|
2024-03-19 22:25:45 +01:00
|
|
|
FatalError();
|
2024-03-19 22:22:29 +01:00
|
|
|
goto abort;
|
|
|
|
}
|
2024-03-19 22:25:45 +01:00
|
|
|
szFilename = szLexString; // save pointer to allocated memory
|
2024-03-19 22:22:29 +01:00
|
|
|
if (pFirst)
|
|
|
|
{
|
|
|
|
pLine->pNext = IncludeLines(szLexString);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pLine = pFirst = IncludeLines(szLexString);
|
|
|
|
}
|
2024-03-19 22:38:33 +01:00
|
|
|
HeapFree(hHeap,0,szFilename); // free memory
|
2024-03-19 22:25:45 +01:00
|
|
|
if (pLine == NULL) // parsing error
|
2024-03-19 22:24:30 +01:00
|
|
|
goto abort;
|
2024-03-19 22:22:29 +01:00
|
|
|
while (pLine->pNext) pLine=pLine->pNext;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (eToken == TOK_END)
|
|
|
|
{
|
|
|
|
if (nLevel)
|
|
|
|
{
|
|
|
|
nLevel--;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (pLine) pLine->pNext = NULL;
|
|
|
|
return pFirst;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (pFirst)
|
|
|
|
{
|
|
|
|
pLine = pLine->pNext = ParseLine(eToken);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pLine = pFirst = ParseLine(eToken);
|
|
|
|
}
|
2024-03-19 22:25:45 +01:00
|
|
|
if (pLine == NULL) // parsing error
|
2024-03-19 22:24:30 +01:00
|
|
|
goto abort;
|
2024-03-19 22:22:29 +01:00
|
|
|
}
|
|
|
|
if (nLinesIncludeLevel)
|
|
|
|
{
|
|
|
|
if (pLine) pLine->pNext = NULL;
|
|
|
|
return pFirst;
|
2024-03-19 23:35:29 +01:00
|
|
|
}
|
2024-03-19 22:22:29 +01:00
|
|
|
abort:
|
|
|
|
if (pFirst)
|
|
|
|
{
|
|
|
|
FreeLines(pFirst);
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2024-03-19 22:37:54 +01:00
|
|
|
static KmlBlock* ParseBlock(TokenId eType)
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
2024-03-19 22:37:54 +01:00
|
|
|
UINT u1;
|
|
|
|
KmlBlock* pBlock;
|
|
|
|
TokenId eToken;
|
2024-03-19 22:22:29 +01:00
|
|
|
|
|
|
|
nLinesIncludeLevel = 0;
|
|
|
|
|
2024-03-19 22:38:33 +01:00
|
|
|
pBlock = HeapAlloc(hHeap,HEAP_ZERO_MEMORY,sizeof(KmlBlock));
|
2024-03-19 22:22:29 +01:00
|
|
|
pBlock->eType = eType;
|
|
|
|
|
|
|
|
u1 = 0;
|
|
|
|
while (pLexToken[u1].nLen)
|
|
|
|
{
|
|
|
|
if (pLexToken[u1].eId == eType) break;
|
|
|
|
u1++;
|
|
|
|
}
|
|
|
|
if (pLexToken[u1].nParams)
|
|
|
|
{
|
|
|
|
eToken = Lex(LEX_COMMAND);
|
|
|
|
switch (eToken)
|
|
|
|
{
|
|
|
|
case TOK_NONE:
|
2024-03-19 22:37:03 +01:00
|
|
|
AddToLog(_T("Open Block at End Of File."));
|
2024-03-19 22:38:33 +01:00
|
|
|
HeapFree(hHeap,0,pBlock);
|
2024-03-19 22:22:29 +01:00
|
|
|
FatalError();
|
|
|
|
return NULL;
|
|
|
|
case TOK_INTEGER:
|
|
|
|
if ((pLexToken[u1].nParams&7)!=TYPE_INTEGER)
|
|
|
|
{
|
2024-03-19 22:37:03 +01:00
|
|
|
AddToLog(_T("Wrong block argument."));
|
2024-03-19 22:38:33 +01:00
|
|
|
HeapFree(hHeap,0,pBlock);
|
2024-03-19 22:22:29 +01:00
|
|
|
FatalError();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
pBlock->nId = nLexInteger;
|
|
|
|
break;
|
|
|
|
default:
|
2024-03-19 22:37:03 +01:00
|
|
|
AddToLog(_T("Wrong block argument."));
|
2024-03-19 22:38:33 +01:00
|
|
|
HeapFree(hHeap,0,pBlock);
|
2024-03-19 22:22:29 +01:00
|
|
|
FatalError();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pBlock->pFirstLine = ParseLines();
|
|
|
|
|
2024-03-19 22:25:45 +01:00
|
|
|
if (pBlock->pFirstLine == NULL) // break on ParseLines error
|
2024-03-19 22:24:30 +01:00
|
|
|
{
|
2024-03-19 22:38:33 +01:00
|
|
|
HeapFree(hHeap,0,pBlock);
|
2024-03-19 22:24:30 +01:00
|
|
|
pBlock = NULL;
|
|
|
|
}
|
|
|
|
|
2024-03-19 22:22:29 +01:00
|
|
|
return pBlock;
|
|
|
|
}
|
|
|
|
|
2024-03-19 22:37:54 +01:00
|
|
|
static KmlBlock* IncludeBlocks(LPCTSTR szFilename)
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
2024-03-19 22:37:54 +01:00
|
|
|
HANDLE hFile;
|
|
|
|
LPTSTR lpbyBuf;
|
|
|
|
UINT uOldLine;
|
|
|
|
LPTSTR szOldText;
|
|
|
|
KmlBlock* pFirst;
|
2024-03-19 22:22:29 +01:00
|
|
|
|
2024-03-19 22:38:33 +01:00
|
|
|
SetCurrentDirectory(szEmuDirectory);
|
2024-03-19 23:33:35 +01:00
|
|
|
hFile = CreateFile(szFilename,
|
|
|
|
GENERIC_READ,
|
|
|
|
FILE_SHARE_READ,
|
|
|
|
NULL,
|
|
|
|
OPEN_EXISTING,
|
|
|
|
FILE_FLAG_SEQUENTIAL_SCAN,
|
|
|
|
NULL);
|
2024-03-19 22:22:29 +01:00
|
|
|
SetCurrentDirectory(szCurrentDirectory);
|
|
|
|
if (hFile == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
2024-03-19 22:37:03 +01:00
|
|
|
PrintfToLog(_T("Error while opening include file %s."), szFilename);
|
2024-03-19 22:22:29 +01:00
|
|
|
FatalError();
|
|
|
|
return NULL;
|
|
|
|
}
|
2024-03-19 22:37:03 +01:00
|
|
|
if ((lpbyBuf = MapKMLFile(hFile)) == NULL)
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
|
|
|
FatalError();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
uOldLine = nLexLine;
|
|
|
|
szOldText = szText;
|
|
|
|
|
|
|
|
nBlocksIncludeLevel++;
|
2024-03-19 22:37:03 +01:00
|
|
|
PrintfToLog(_T("b%i:Including %s"), nBlocksIncludeLevel, szFilename);
|
2024-03-19 22:22:29 +01:00
|
|
|
InitLex(lpbyBuf);
|
|
|
|
pFirst = ParseBlocks();
|
|
|
|
CleanLex();
|
|
|
|
nBlocksIncludeLevel--;
|
|
|
|
|
|
|
|
nLexLine = uOldLine;
|
|
|
|
szText = szOldText;
|
2024-03-19 22:38:33 +01:00
|
|
|
HeapFree(hHeap,0,lpbyBuf);
|
2024-03-19 22:22:29 +01:00
|
|
|
|
|
|
|
return pFirst;
|
|
|
|
}
|
|
|
|
|
2024-03-19 22:37:54 +01:00
|
|
|
static KmlBlock* ParseBlocks(VOID)
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
|
|
|
TokenId eToken;
|
2024-03-19 22:37:54 +01:00
|
|
|
KmlBlock* pFirst = NULL;
|
2024-03-19 22:38:33 +01:00
|
|
|
KmlBlock* pBlock = NULL;
|
2024-03-19 22:22:29 +01:00
|
|
|
|
|
|
|
while ((eToken=Lex(LEX_BLOCK))!=TOK_NONE)
|
|
|
|
{
|
|
|
|
if (eToken == TOK_INCLUDE)
|
|
|
|
{
|
2024-03-19 22:37:03 +01:00
|
|
|
LPTSTR szFilename;
|
2024-03-19 22:24:30 +01:00
|
|
|
eToken = Lex(LEX_PARAM); // get include parameter in 'szLexString'
|
|
|
|
if (eToken != TOK_STRING) // not a string (token don't begin with ")
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
2024-03-19 22:37:03 +01:00
|
|
|
AddToLog(_T("Include: string expected as parameter."));
|
2024-03-19 22:25:45 +01:00
|
|
|
FatalError();
|
2024-03-19 22:22:29 +01:00
|
|
|
goto abort;
|
|
|
|
}
|
2024-03-19 22:25:45 +01:00
|
|
|
szFilename = szLexString; // save pointer to allocated memory
|
2024-03-19 22:22:29 +01:00
|
|
|
if (pFirst)
|
|
|
|
pBlock = pBlock->pNext = IncludeBlocks(szLexString);
|
|
|
|
else
|
|
|
|
pBlock = pFirst = IncludeBlocks(szLexString);
|
2024-03-19 22:38:33 +01:00
|
|
|
HeapFree(hHeap,0,szFilename); // free memory
|
2024-03-19 22:25:45 +01:00
|
|
|
if (pBlock == NULL) // parsing error
|
2024-03-19 22:24:30 +01:00
|
|
|
goto abort;
|
2024-03-19 22:22:29 +01:00
|
|
|
while (pBlock->pNext) pBlock=pBlock->pNext;
|
|
|
|
continue;
|
|
|
|
}
|
2024-03-19 23:35:29 +01:00
|
|
|
if (!IsGlobalBlock(eToken)) // check for valid block commands
|
|
|
|
{
|
|
|
|
PrintfToLog(_T("%i: Invalid Block %s."), nLexLine, GetStringOf(eToken));
|
|
|
|
FatalError();
|
|
|
|
goto abort;
|
|
|
|
}
|
2024-03-19 22:22:29 +01:00
|
|
|
if (pFirst)
|
|
|
|
pBlock = pBlock->pNext = ParseBlock(eToken);
|
|
|
|
else
|
|
|
|
pBlock = pFirst = ParseBlock(eToken);
|
|
|
|
if (pBlock == NULL)
|
|
|
|
{
|
2024-03-19 22:37:03 +01:00
|
|
|
AddToLog(_T("Invalid block."));
|
2024-03-19 22:25:45 +01:00
|
|
|
FatalError();
|
2024-03-19 22:22:29 +01:00
|
|
|
goto abort;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (pFirst) pBlock->pNext = NULL;
|
2024-03-19 23:35:29 +01:00
|
|
|
if (*szText != 0) // still KML text left
|
|
|
|
{
|
|
|
|
FatalError(); // error unknown block token
|
|
|
|
goto abort;
|
|
|
|
}
|
2024-03-19 22:22:29 +01:00
|
|
|
return pFirst;
|
|
|
|
abort:
|
|
|
|
if (pFirst) FreeBlocks(pFirst);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//################
|
|
|
|
//#
|
|
|
|
//# Initialization Phase
|
|
|
|
//#
|
|
|
|
//################
|
|
|
|
|
2024-03-19 22:37:54 +01:00
|
|
|
static VOID InitGlobal(KmlBlock* pBlock)
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
2024-03-19 22:37:54 +01:00
|
|
|
KmlLine* pLine = pBlock->pFirstLine;
|
2024-03-19 22:22:29 +01:00
|
|
|
while (pLine)
|
|
|
|
{
|
|
|
|
switch (pLine->eCommand)
|
|
|
|
{
|
|
|
|
case TOK_TITLE:
|
2024-03-19 22:37:03 +01:00
|
|
|
PrintfToLog(_T("Title: %s"), (LPTSTR)pLine->nParam[0]);
|
2024-03-19 22:22:29 +01:00
|
|
|
break;
|
|
|
|
case TOK_AUTHOR:
|
2024-03-19 22:37:03 +01:00
|
|
|
PrintfToLog(_T("Author: %s"), (LPTSTR)pLine->nParam[0]);
|
2024-03-19 22:22:29 +01:00
|
|
|
break;
|
|
|
|
case TOK_PRINT:
|
2024-03-19 22:37:03 +01:00
|
|
|
AddToLog((LPTSTR)pLine->nParam[0]);
|
2024-03-19 22:22:29 +01:00
|
|
|
break;
|
2024-03-19 22:38:33 +01:00
|
|
|
case TOK_HARDWARE:
|
|
|
|
PrintfToLog(_T("Hardware Platform: %s"), (LPTSTR)pLine->nParam[0]);
|
|
|
|
break;
|
2024-03-19 22:22:29 +01:00
|
|
|
case TOK_MODEL:
|
2024-03-19 22:37:03 +01:00
|
|
|
cCurrentRomType = ((BYTE *)pLine->nParam[0])[0];
|
|
|
|
PrintfToLog(_T("Calculator Model : %c"), cCurrentRomType);
|
|
|
|
break;
|
|
|
|
case TOK_CLASS:
|
|
|
|
nCurrentClass = pLine->nParam[0];
|
|
|
|
PrintfToLog(_T("Calculator Class : %u"), nCurrentClass);
|
2024-03-19 22:22:29 +01:00
|
|
|
break;
|
|
|
|
case TOK_DEBUG:
|
|
|
|
bDebug = pLine->nParam[0]&1;
|
2024-03-19 22:37:03 +01:00
|
|
|
PrintfToLog(_T("Debug %s"), bDebug?_T("On"):_T("Off"));
|
2024-03-19 22:22:29 +01:00
|
|
|
break;
|
|
|
|
case TOK_ROM:
|
|
|
|
if (pbyRom != NULL)
|
|
|
|
{
|
2024-03-19 22:37:03 +01:00
|
|
|
PrintfToLog(_T("Rom %s Ignored."), (LPTSTR)pLine->nParam[0]);
|
|
|
|
AddToLog(_T("Please put only one Rom command in the Global block."));
|
2024-03-19 22:22:29 +01:00
|
|
|
break;
|
|
|
|
}
|
2024-03-19 22:37:03 +01:00
|
|
|
if (!MapRom((LPTSTR)pLine->nParam[0]))
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
2024-03-19 22:37:03 +01:00
|
|
|
PrintfToLog(_T("Cannot open Rom %s"), (LPTSTR)pLine->nParam[0]);
|
2024-03-19 22:22:29 +01:00
|
|
|
break;
|
|
|
|
}
|
2024-03-19 22:37:03 +01:00
|
|
|
PrintfToLog(_T("Rom %s Loaded."), (LPTSTR)pLine->nParam[0]);
|
2024-03-19 22:22:29 +01:00
|
|
|
break;
|
|
|
|
case TOK_PATCH:
|
|
|
|
if (pbyRom == NULL)
|
|
|
|
{
|
2024-03-19 22:37:03 +01:00
|
|
|
PrintfToLog(_T("Patch %s ignored."), (LPTSTR)pLine->nParam[0]);
|
|
|
|
AddToLog(_T("Please put the Rom command before any Patch."));
|
2024-03-19 22:22:29 +01:00
|
|
|
break;
|
|
|
|
}
|
2024-03-19 22:37:03 +01:00
|
|
|
if (PatchRom((LPTSTR)pLine->nParam[0]) == TRUE)
|
|
|
|
PrintfToLog(_T("Patch %s Loaded"), (LPTSTR)pLine->nParam[0]);
|
2024-03-19 22:22:29 +01:00
|
|
|
else
|
2024-03-19 22:37:03 +01:00
|
|
|
PrintfToLog(_T("Patch %s is Wrong or Missing"), (LPTSTR)pLine->nParam[0]);
|
2024-03-19 22:22:29 +01:00
|
|
|
break;
|
|
|
|
case TOK_BITMAP:
|
|
|
|
if (hMainDC != NULL)
|
|
|
|
{
|
2024-03-19 22:37:03 +01:00
|
|
|
PrintfToLog(_T("Bitmap %s Ignored."), (LPTSTR)pLine->nParam[0]);
|
|
|
|
AddToLog(_T("Please put only one Bitmap command in the Global block."));
|
2024-03-19 22:22:29 +01:00
|
|
|
break;
|
|
|
|
}
|
2024-03-19 22:37:03 +01:00
|
|
|
if (!CreateMainBitmap((LPTSTR)pLine->nParam[0]))
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
2024-03-19 22:37:03 +01:00
|
|
|
PrintfToLog(_T("Cannot Load Bitmap %s."), (LPTSTR)pLine->nParam[0]);
|
2024-03-19 22:22:29 +01:00
|
|
|
break;
|
|
|
|
}
|
2024-03-19 22:37:03 +01:00
|
|
|
PrintfToLog(_T("Bitmap %s Loaded."), (LPTSTR)pLine->nParam[0]);
|
2024-03-19 22:22:29 +01:00
|
|
|
break;
|
|
|
|
default:
|
2024-03-19 22:37:03 +01:00
|
|
|
PrintfToLog(_T("Command %s Ignored in Block %s"), GetStringOf(pLine->eCommand), GetStringOf(pBlock->eType));
|
2024-03-19 22:22:29 +01:00
|
|
|
}
|
|
|
|
pLine = pLine->pNext;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-03-19 22:37:54 +01:00
|
|
|
static KmlLine* InitBackground(KmlBlock* pBlock)
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
2024-03-19 22:37:54 +01:00
|
|
|
KmlLine* pLine = pBlock->pFirstLine;
|
2024-03-19 22:22:29 +01:00
|
|
|
while (pLine)
|
|
|
|
{
|
|
|
|
switch (pLine->eCommand)
|
|
|
|
{
|
|
|
|
case TOK_OFFSET:
|
|
|
|
nBackgroundX = pLine->nParam[0];
|
|
|
|
nBackgroundY = pLine->nParam[1];
|
|
|
|
break;
|
|
|
|
case TOK_SIZE:
|
|
|
|
nBackgroundW = pLine->nParam[0];
|
|
|
|
nBackgroundH = pLine->nParam[1];
|
|
|
|
break;
|
|
|
|
case TOK_END:
|
|
|
|
return pLine;
|
|
|
|
default:
|
2024-03-19 22:37:03 +01:00
|
|
|
PrintfToLog(_T("Command %s Ignored in Block %s"), GetStringOf(pLine->eCommand), GetStringOf(pBlock->eType));
|
2024-03-19 22:22:29 +01:00
|
|
|
}
|
|
|
|
pLine = pLine->pNext;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2024-03-19 22:37:54 +01:00
|
|
|
static KmlLine* InitLcd(KmlBlock* pBlock)
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
2024-03-19 22:37:54 +01:00
|
|
|
KmlLine* pLine = pBlock->pFirstLine;
|
2024-03-19 22:22:29 +01:00
|
|
|
while (pLine)
|
|
|
|
{
|
|
|
|
switch (pLine->eCommand)
|
|
|
|
{
|
|
|
|
case TOK_OFFSET:
|
|
|
|
nLcdX = pLine->nParam[0];
|
|
|
|
nLcdY = pLine->nParam[1];
|
|
|
|
break;
|
|
|
|
case TOK_ZOOM:
|
2024-03-19 22:38:33 +01:00
|
|
|
nLcdZoom = pLine->nParam[0];
|
2024-03-19 23:35:29 +01:00
|
|
|
if (!(nLcdZoom >= 1 && nLcdZoom <= 4))
|
2024-03-19 22:38:33 +01:00
|
|
|
nLcdZoom = 1;
|
2024-03-19 22:22:29 +01:00
|
|
|
break;
|
|
|
|
case TOK_COLOR:
|
|
|
|
SetLcdColor(pLine->nParam[0],pLine->nParam[1],pLine->nParam[2],pLine->nParam[3]);
|
|
|
|
break;
|
|
|
|
case TOK_END:
|
|
|
|
return pLine;
|
|
|
|
default:
|
2024-03-19 22:37:03 +01:00
|
|
|
PrintfToLog(_T("Command %s Ignored in Block %s"), GetStringOf(pLine->eCommand), GetStringOf(pBlock->eType));
|
2024-03-19 22:22:29 +01:00
|
|
|
}
|
|
|
|
pLine = pLine->pNext;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2024-03-19 22:37:54 +01:00
|
|
|
static KmlLine* InitAnnunciator(KmlBlock* pBlock)
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
2024-03-19 22:37:54 +01:00
|
|
|
KmlLine* pLine = pBlock->pFirstLine;
|
2024-03-19 22:22:29 +01:00
|
|
|
UINT nId = pBlock->nId-1;
|
2024-03-19 22:37:54 +01:00
|
|
|
if (nId >= ARRAYSIZEOF(pAnnunciator))
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
2024-03-19 22:37:03 +01:00
|
|
|
PrintfToLog(_T("Wrong Annunciator Id %i"), nId);
|
2024-03-19 22:22:29 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
nAnnunciators++;
|
|
|
|
while (pLine)
|
|
|
|
{
|
|
|
|
switch (pLine->eCommand)
|
|
|
|
{
|
|
|
|
case TOK_OFFSET:
|
|
|
|
pAnnunciator[nId].nOx = pLine->nParam[0];
|
|
|
|
pAnnunciator[nId].nOy = pLine->nParam[1];
|
|
|
|
break;
|
|
|
|
case TOK_DOWN:
|
|
|
|
pAnnunciator[nId].nDx = pLine->nParam[0];
|
|
|
|
pAnnunciator[nId].nDy = pLine->nParam[1];
|
|
|
|
break;
|
|
|
|
case TOK_SIZE:
|
|
|
|
pAnnunciator[nId].nCx = pLine->nParam[0];
|
|
|
|
pAnnunciator[nId].nCy = pLine->nParam[1];
|
|
|
|
break;
|
|
|
|
case TOK_END:
|
|
|
|
return pLine;
|
|
|
|
default:
|
2024-03-19 22:37:03 +01:00
|
|
|
PrintfToLog(_T("Command %s Ignored in Block %s"), GetStringOf(pLine->eCommand), GetStringOf(pBlock->eType));
|
2024-03-19 22:22:29 +01:00
|
|
|
}
|
|
|
|
pLine = pLine->pNext;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2024-03-19 22:37:54 +01:00
|
|
|
static VOID InitButton(KmlBlock* pBlock)
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
2024-03-19 22:37:54 +01:00
|
|
|
KmlLine* pLine = pBlock->pFirstLine;
|
2024-03-19 22:22:29 +01:00
|
|
|
UINT nLevel = 0;
|
|
|
|
if (nButtons>=256)
|
|
|
|
{
|
2024-03-19 22:37:03 +01:00
|
|
|
AddToLog(_T("Only the first 256 buttons will be defined."));
|
2024-03-19 22:22:29 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
pButton[nButtons].nId = pBlock->nId;
|
|
|
|
pButton[nButtons].bDown = FALSE;
|
|
|
|
pButton[nButtons].nType = 0; // default : user defined button
|
|
|
|
while (pLine)
|
|
|
|
{
|
|
|
|
if (nLevel)
|
|
|
|
{
|
2024-03-19 23:35:29 +01:00
|
|
|
if (IsBlock(pLine->eCommand)) nLevel++;
|
2024-03-19 22:22:29 +01:00
|
|
|
if (pLine->eCommand == TOK_END) nLevel--;
|
|
|
|
pLine = pLine->pNext;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (IsBlock(pLine->eCommand)) nLevel++;
|
|
|
|
switch (pLine->eCommand)
|
|
|
|
{
|
|
|
|
case TOK_TYPE:
|
|
|
|
pButton[nButtons].nType = pLine->nParam[0];
|
|
|
|
break;
|
|
|
|
case TOK_OFFSET:
|
|
|
|
pButton[nButtons].nOx = pLine->nParam[0];
|
|
|
|
pButton[nButtons].nOy = pLine->nParam[1];
|
|
|
|
break;
|
|
|
|
case TOK_DOWN:
|
|
|
|
pButton[nButtons].nDx = pLine->nParam[0];
|
|
|
|
pButton[nButtons].nDy = pLine->nParam[1];
|
|
|
|
break;
|
|
|
|
case TOK_SIZE:
|
|
|
|
pButton[nButtons].nCx = pLine->nParam[0];
|
|
|
|
pButton[nButtons].nCy = pLine->nParam[1];
|
|
|
|
break;
|
|
|
|
case TOK_OUTIN:
|
|
|
|
pButton[nButtons].nOut = pLine->nParam[0];
|
|
|
|
pButton[nButtons].nIn = pLine->nParam[1];
|
|
|
|
break;
|
|
|
|
case TOK_ONDOWN:
|
|
|
|
pButton[nButtons].pOnDown = pLine;
|
|
|
|
break;
|
|
|
|
case TOK_ONUP:
|
|
|
|
pButton[nButtons].pOnUp = pLine;
|
|
|
|
break;
|
|
|
|
case TOK_NOHOLD:
|
|
|
|
pButton[nButtons].dwFlags &= ~(BUTTON_VIRTUAL);
|
|
|
|
pButton[nButtons].dwFlags |= BUTTON_NOHOLD;
|
|
|
|
break;
|
|
|
|
case TOK_VIRTUAL:
|
|
|
|
pButton[nButtons].dwFlags &= ~(BUTTON_NOHOLD);
|
|
|
|
pButton[nButtons].dwFlags |= BUTTON_VIRTUAL;
|
|
|
|
break;
|
|
|
|
default:
|
2024-03-19 22:37:03 +01:00
|
|
|
PrintfToLog(_T("Command %s Ignored in Block %s %i"), GetStringOf(pLine->eCommand), GetStringOf(pBlock->eType), pBlock->nId);
|
2024-03-19 22:22:29 +01:00
|
|
|
}
|
|
|
|
pLine = pLine->pNext;
|
|
|
|
}
|
|
|
|
if (nLevel)
|
2024-03-19 22:37:03 +01:00
|
|
|
PrintfToLog(_T("%i Open Block(s) in Block %s %i"), nLevel, GetStringOf(pBlock->eType), pBlock->nId);
|
2024-03-19 22:22:29 +01:00
|
|
|
nButtons++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//################
|
|
|
|
//#
|
|
|
|
//# Execution
|
|
|
|
//#
|
|
|
|
//################
|
|
|
|
|
2024-03-19 22:37:54 +01:00
|
|
|
static KmlLine* SkipLines(KmlLine* pLine, TokenId eCommand)
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
|
|
|
UINT nLevel = 0;
|
|
|
|
while (pLine)
|
|
|
|
{
|
|
|
|
if (IsBlock(pLine->eCommand)) nLevel++;
|
2024-03-19 23:35:29 +01:00
|
|
|
if (pLine->eCommand == eCommand)
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
2024-03-19 23:35:29 +01:00
|
|
|
// found token, return command behind token
|
2024-03-19 22:22:29 +01:00
|
|
|
if (nLevel == 0) return pLine->pNext;
|
|
|
|
}
|
|
|
|
if (pLine->eCommand == TOK_END)
|
|
|
|
{
|
|
|
|
if (nLevel)
|
|
|
|
nLevel--;
|
|
|
|
else
|
2024-03-19 23:35:29 +01:00
|
|
|
break;
|
2024-03-19 22:22:29 +01:00
|
|
|
}
|
|
|
|
pLine = pLine->pNext;
|
|
|
|
}
|
|
|
|
return pLine;
|
|
|
|
}
|
|
|
|
|
2024-03-19 22:37:54 +01:00
|
|
|
static KmlLine* If(KmlLine* pLine, BOOL bCondition)
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
|
|
|
pLine = pLine->pNext;
|
|
|
|
if (bCondition)
|
|
|
|
{
|
|
|
|
while (pLine)
|
|
|
|
{
|
|
|
|
if (pLine->eCommand == TOK_END)
|
|
|
|
{
|
|
|
|
pLine = pLine->pNext;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (pLine->eCommand == TOK_ELSE)
|
|
|
|
{
|
|
|
|
pLine = SkipLines(pLine, TOK_END);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pLine = RunLine(pLine);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pLine = SkipLines(pLine, TOK_ELSE);
|
|
|
|
while (pLine)
|
|
|
|
{
|
|
|
|
if (pLine->eCommand == TOK_END)
|
|
|
|
{
|
|
|
|
pLine = pLine->pNext;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pLine = RunLine(pLine);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return pLine;
|
|
|
|
}
|
|
|
|
|
2024-03-19 22:37:54 +01:00
|
|
|
static KmlLine* RunLine(KmlLine* pLine)
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
|
|
|
switch (pLine->eCommand)
|
|
|
|
{
|
|
|
|
case TOK_MAP:
|
|
|
|
if (byVKeyMap[pLine->nParam[0]&0xFF]&1)
|
|
|
|
PressButtonById(pLine->nParam[1]);
|
|
|
|
else
|
|
|
|
ReleaseButtonById(pLine->nParam[1]);
|
|
|
|
break;
|
|
|
|
case TOK_PRESS:
|
|
|
|
PressButtonById(pLine->nParam[0]);
|
|
|
|
break;
|
|
|
|
case TOK_RELEASE:
|
|
|
|
ReleaseButtonById(pLine->nParam[0]);
|
|
|
|
break;
|
|
|
|
case TOK_MENUITEM:
|
|
|
|
PostMessage(hWnd, WM_COMMAND, 0x19C40+(pLine->nParam[0]&0xFF), 0);
|
|
|
|
break;
|
|
|
|
case TOK_SETFLAG:
|
|
|
|
nKMLFlags |= 1<<(pLine->nParam[0]&0x1F);
|
|
|
|
break;
|
|
|
|
case TOK_RESETFLAG:
|
|
|
|
nKMLFlags &= ~(1<<(pLine->nParam[0]&0x1F));
|
|
|
|
break;
|
|
|
|
case TOK_NOTFLAG:
|
|
|
|
nKMLFlags ^= 1<<(pLine->nParam[0]&0x1F);
|
|
|
|
break;
|
|
|
|
case TOK_IFPRESSED:
|
|
|
|
return If(pLine,byVKeyMap[pLine->nParam[0]&0xFF]);
|
|
|
|
break;
|
|
|
|
case TOK_IFFLAG:
|
|
|
|
return If(pLine,(nKMLFlags>>(pLine->nParam[0]&0x1F))&1);
|
2024-03-19 22:37:03 +01:00
|
|
|
default:
|
|
|
|
break;
|
2024-03-19 22:22:29 +01:00
|
|
|
}
|
|
|
|
return pLine->pNext;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//################
|
|
|
|
//#
|
|
|
|
//# Clean Up
|
|
|
|
//#
|
|
|
|
//################
|
|
|
|
|
2024-03-19 22:37:54 +01:00
|
|
|
static VOID FreeLines(KmlLine* pLine)
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
|
|
|
while (pLine)
|
|
|
|
{
|
2024-03-19 22:37:54 +01:00
|
|
|
KmlLine* pThisLine = pLine;
|
2024-03-19 22:22:29 +01:00
|
|
|
UINT i = 0;
|
|
|
|
DWORD nParams;
|
2024-03-19 22:24:30 +01:00
|
|
|
while (pLexToken[i].nLen) // search in all token definitions
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
2024-03-19 22:24:30 +01:00
|
|
|
// break when token definition found
|
2024-03-19 22:22:29 +01:00
|
|
|
if (pLexToken[i].eId == pLine->eCommand) break;
|
2024-03-19 22:24:30 +01:00
|
|
|
i++; // next token definition
|
2024-03-19 22:22:29 +01:00
|
|
|
}
|
2024-03-19 22:24:30 +01:00
|
|
|
nParams = pLexToken[i].nParams; // get argument types of command
|
|
|
|
i = 0; // first parameter
|
|
|
|
while ((nParams&7)) // argument left
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
2024-03-19 22:24:30 +01:00
|
|
|
if ((nParams&7) == TYPE_STRING) // string type
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
2024-03-19 22:38:33 +01:00
|
|
|
HeapFree(hHeap,0,(LPVOID)pLine->nParam[i]);
|
2024-03-19 22:22:29 +01:00
|
|
|
}
|
2024-03-19 22:25:45 +01:00
|
|
|
i++; // incr. parameter buffer index
|
2024-03-19 22:24:30 +01:00
|
|
|
nParams >>= 3; // next argument type
|
2024-03-19 22:22:29 +01:00
|
|
|
}
|
2024-03-19 22:24:30 +01:00
|
|
|
pLine = pLine->pNext; // get next line
|
2024-03-19 22:38:33 +01:00
|
|
|
HeapFree(hHeap,0,pThisLine);
|
2024-03-19 22:22:29 +01:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-03-19 22:37:54 +01:00
|
|
|
VOID FreeBlocks(KmlBlock* pBlock)
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
|
|
|
while (pBlock)
|
|
|
|
{
|
2024-03-19 22:37:54 +01:00
|
|
|
KmlBlock* pThisBlock = pBlock;
|
2024-03-19 22:22:29 +01:00
|
|
|
pBlock = pBlock->pNext;
|
|
|
|
FreeLines(pThisBlock->pFirstLine);
|
2024-03-19 22:38:33 +01:00
|
|
|
HeapFree(hHeap,0,pThisBlock);
|
2024-03-19 22:22:29 +01:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-03-19 22:37:03 +01:00
|
|
|
VOID KillKML(VOID)
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
2024-03-19 22:37:03 +01:00
|
|
|
if ((nState==SM_RUN)||(nState==SM_SLEEP))
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
2024-03-19 22:37:03 +01:00
|
|
|
AbortMessage(_T("FATAL: KillKML while emulator is running !!!"));
|
|
|
|
SwitchToState(SM_RETURN);
|
2024-03-19 22:22:29 +01:00
|
|
|
DestroyWindow(hWnd);
|
|
|
|
}
|
|
|
|
UnmapRom();
|
|
|
|
DestroyLcdBitmap();
|
|
|
|
DestroyMainBitmap();
|
|
|
|
if (hPalette)
|
|
|
|
{
|
2024-03-19 22:24:30 +01:00
|
|
|
BOOL err;
|
2024-03-19 22:37:03 +01:00
|
|
|
|
2024-03-19 22:24:30 +01:00
|
|
|
if (hWindowDC) SelectPalette(hWindowDC, hOldPalette, FALSE);
|
|
|
|
err = DeleteObject(hPalette);
|
2024-03-19 22:25:45 +01:00
|
|
|
_ASSERT(err != FALSE); // freed resource memory
|
2024-03-19 22:22:29 +01:00
|
|
|
hPalette = NULL;
|
|
|
|
}
|
|
|
|
bClicking = FALSE;
|
|
|
|
uButtonClicked = 0;
|
|
|
|
FreeBlocks(pKml);
|
|
|
|
pKml = NULL;
|
|
|
|
nButtons = 0;
|
|
|
|
nScancodes = 0;
|
|
|
|
nAnnunciators = 0;
|
2024-03-19 22:38:33 +01:00
|
|
|
bDebug = TRUE;
|
|
|
|
nKMLFlags = 0;
|
2024-03-19 22:37:03 +01:00
|
|
|
ZeroMemory(pButton, sizeof(pButton));
|
|
|
|
ZeroMemory(pAnnunciator, sizeof(pAnnunciator));
|
|
|
|
ZeroMemory(pVKey, sizeof(pVKey));
|
2024-03-19 22:22:29 +01:00
|
|
|
ClearLog();
|
2024-03-19 22:37:03 +01:00
|
|
|
nBackgroundX = 0;
|
|
|
|
nBackgroundY = 0;
|
2024-03-19 22:22:29 +01:00
|
|
|
nBackgroundW = 256;
|
|
|
|
nBackgroundH = 0;
|
2024-03-19 22:38:33 +01:00
|
|
|
nLcdZoom = 1;
|
2024-03-19 23:35:29 +01:00
|
|
|
cCurrentRomType = 0;
|
2024-03-19 22:22:29 +01:00
|
|
|
UpdateWindowStatus();
|
|
|
|
ResizeWindow();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//################
|
|
|
|
//#
|
|
|
|
//# Extract Keyword's Parameters
|
|
|
|
//#
|
|
|
|
//################
|
|
|
|
|
2024-03-19 22:37:54 +01:00
|
|
|
static LPTSTR GetStringParam(KmlBlock* pBlock, TokenId eBlock, TokenId eCommand, UINT nParam)
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
|
|
|
while (pBlock)
|
|
|
|
{
|
|
|
|
if (pBlock->eType == eBlock)
|
|
|
|
{
|
2024-03-19 22:37:54 +01:00
|
|
|
KmlLine* pLine = pBlock->pFirstLine;
|
2024-03-19 22:22:29 +01:00
|
|
|
while (pLine)
|
|
|
|
{
|
|
|
|
if (pLine->eCommand == eCommand)
|
|
|
|
{
|
2024-03-19 22:37:03 +01:00
|
|
|
return (LPTSTR)pLine->nParam[nParam];
|
2024-03-19 22:22:29 +01:00
|
|
|
}
|
|
|
|
pLine = pLine->pNext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pBlock = pBlock->pNext;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2024-03-19 22:37:54 +01:00
|
|
|
static DWORD GetIntegerParam(KmlBlock* pBlock, TokenId eBlock, TokenId eCommand, UINT nParam)
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
|
|
|
while (pBlock)
|
|
|
|
{
|
|
|
|
if (pBlock->eType == eBlock)
|
|
|
|
{
|
2024-03-19 22:37:54 +01:00
|
|
|
KmlLine* pLine = pBlock->pFirstLine;
|
2024-03-19 22:22:29 +01:00
|
|
|
while (pLine)
|
|
|
|
{
|
|
|
|
if (pLine->eCommand == eCommand)
|
|
|
|
{
|
|
|
|
return pLine->nParam[nParam];
|
|
|
|
}
|
|
|
|
pLine = pLine->pNext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pBlock = pBlock->pNext;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//################
|
|
|
|
//#
|
|
|
|
//# Buttons
|
|
|
|
//#
|
|
|
|
//################
|
|
|
|
|
2024-03-19 22:37:03 +01:00
|
|
|
static INT iSqrt(INT nNumber) // integer y=sqrt(x) function
|
|
|
|
{
|
|
|
|
INT m, b = 0, t = nNumber;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
m = (b + t + 1) / 2; // median number
|
|
|
|
if (m * m - nNumber > 0) // calculate x^2-y
|
|
|
|
t = m; // adjust upper border
|
2024-03-19 23:35:29 +01:00
|
|
|
else
|
2024-03-19 22:37:03 +01:00
|
|
|
b = m; // adjust lower border
|
|
|
|
}
|
|
|
|
while(t - b > 1);
|
|
|
|
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VOID AdjustPixel(UINT x, UINT y, BYTE byOffset)
|
|
|
|
{
|
|
|
|
COLORREF rgb;
|
|
|
|
WORD wB, wG, wR;
|
2024-03-19 23:35:29 +01:00
|
|
|
|
2024-03-19 22:37:03 +01:00
|
|
|
rgb = GetPixel(hWindowDC, x, y);
|
|
|
|
|
|
|
|
// adjust color red
|
|
|
|
wR = (((WORD) rgb) & 0x00FF) + byOffset;
|
|
|
|
if (wR > 0xFF) wR = 0xFF;
|
|
|
|
rgb >>= 8;
|
|
|
|
// adjust color green
|
|
|
|
wG = (((WORD) rgb) & 0x00FF) + byOffset;
|
|
|
|
if (wG > 0xFF) wG = 0xFF;
|
|
|
|
rgb >>= 8;
|
|
|
|
// adjust color blue
|
|
|
|
wB = (((WORD) rgb) & 0x00FF) + byOffset;
|
|
|
|
if (wB > 0xFF) wB = 0xFF;
|
|
|
|
|
|
|
|
SetPixel(hWindowDC, x, y, RGB(wR,wG,wB));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// draw transparent circle with center coordinates and radius in pixel
|
|
|
|
static __inline VOID TransparentCircle(UINT cx, UINT cy, UINT r)
|
|
|
|
{
|
|
|
|
#define HIGHADJ 0x80 // color incr. at center
|
|
|
|
#define LOWADJ 0x08 // color incr. at border
|
|
|
|
|
|
|
|
INT x, y;
|
|
|
|
INT rr = r * r; // calculate r^2
|
|
|
|
|
|
|
|
// y-rows of circle
|
|
|
|
for (y = 0; y < (INT) r; ++y)
|
|
|
|
{
|
|
|
|
INT yy = y * y; // calculate y^2
|
|
|
|
|
2024-03-19 23:35:29 +01:00
|
|
|
// x-columns of circle
|
2024-03-19 22:37:03 +01:00
|
|
|
INT nXWidth = iSqrt(rr-yy);
|
|
|
|
|
|
|
|
for (x = 0; x < nXWidth; ++x)
|
|
|
|
{
|
|
|
|
// color offset, sqrt(x*x+y*y) <= r !!!
|
|
|
|
BYTE byOff = HIGHADJ - (BYTE) (iSqrt((x*x+yy) * (HIGHADJ-LOWADJ)*(HIGHADJ-LOWADJ) / rr));
|
2024-03-19 23:35:29 +01:00
|
|
|
|
2024-03-19 22:37:03 +01:00
|
|
|
AdjustPixel(cx+x, cy+y, byOff);
|
|
|
|
if (x != 0) AdjustPixel(cx-x, cy+y, byOff);
|
|
|
|
if (y != 0) AdjustPixel(cx+x, cy-y, byOff);
|
|
|
|
if (x != 0 && y != 0) AdjustPixel(cx-x, cy-y, byOff);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
|
|
|
#undef HIGHADJ
|
|
|
|
#undef LOWADJ
|
|
|
|
}
|
|
|
|
|
2024-03-19 22:22:29 +01:00
|
|
|
static VOID DrawButton(UINT nId)
|
|
|
|
{
|
|
|
|
UINT x0 = pButton[nId].nOx;
|
|
|
|
UINT y0 = pButton[nId].nOy;
|
|
|
|
|
2024-03-19 22:25:45 +01:00
|
|
|
EnterCriticalSection(&csGDILock); // solving NT GDI problems
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
2024-03-19 22:24:30 +01:00
|
|
|
switch (pButton[nId].nType)
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
2024-03-19 22:37:03 +01:00
|
|
|
case 0: // bitmap key
|
2024-03-19 22:24:30 +01:00
|
|
|
if (pButton[nId].bDown)
|
|
|
|
{
|
|
|
|
BitBlt(hWindowDC, x0, y0, pButton[nId].nCx, pButton[nId].nCy, hMainDC, pButton[nId].nDx, pButton[nId].nDy, SRCCOPY);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-03-19 22:37:03 +01:00
|
|
|
// update background only
|
2024-03-19 22:24:30 +01:00
|
|
|
BitBlt(hWindowDC, x0, y0, pButton[nId].nCx, pButton[nId].nCy, hMainDC, x0, y0, SRCCOPY);
|
|
|
|
}
|
|
|
|
break;
|
2024-03-19 22:37:03 +01:00
|
|
|
case 1: // shift key to right down
|
2024-03-19 22:24:30 +01:00
|
|
|
if (pButton[nId].bDown)
|
|
|
|
{
|
|
|
|
UINT x1 = x0+pButton[nId].nCx-1;
|
|
|
|
UINT y1 = y0+pButton[nId].nCy-1;
|
|
|
|
BitBlt(hWindowDC, x0+3,y0+3,pButton[nId].nCx-5,pButton[nId].nCy-5,hMainDC,x0+2,y0+2,SRCCOPY);
|
|
|
|
SelectObject(hWindowDC, GetStockObject(BLACK_PEN));
|
2024-03-19 22:37:03 +01:00
|
|
|
MoveToEx(hWindowDC, x0, y0, NULL); LineTo(hWindowDC, x1, y0);
|
|
|
|
MoveToEx(hWindowDC, x0, y0, NULL); LineTo(hWindowDC, x0, y1);
|
2024-03-19 22:24:30 +01:00
|
|
|
SelectObject(hWindowDC, GetStockObject(WHITE_PEN));
|
2024-03-19 22:37:03 +01:00
|
|
|
MoveToEx(hWindowDC, x1, y0, NULL); LineTo(hWindowDC, x1, y1);
|
|
|
|
MoveToEx(hWindowDC, x0, y1, NULL); LineTo(hWindowDC, x1+1, y1);
|
2024-03-19 22:24:30 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
BitBlt(hWindowDC, x0, y0, pButton[nId].nCx, pButton[nId].nCy, hMainDC, x0, y0, SRCCOPY);
|
|
|
|
}
|
|
|
|
break;
|
2024-03-19 22:37:03 +01:00
|
|
|
case 2: // do nothing
|
2024-03-19 22:24:30 +01:00
|
|
|
break;
|
2024-03-19 22:37:03 +01:00
|
|
|
case 3: // invert key color, even in display
|
2024-03-19 22:24:30 +01:00
|
|
|
if (pButton[nId].bDown)
|
|
|
|
{
|
|
|
|
PatBlt(hWindowDC, x0, y0, pButton[nId].nCx, pButton[nId].nCy, DSTINVERT);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RECT Rect;
|
2024-03-19 22:37:54 +01:00
|
|
|
Rect.left = x0 - nBackgroundX;
|
|
|
|
Rect.top = y0 - nBackgroundY;
|
|
|
|
Rect.right = Rect.left + pButton[nId].nCx;
|
|
|
|
Rect.bottom = Rect.top + pButton[nId].nCy;
|
2024-03-19 22:37:03 +01:00
|
|
|
InvalidateRect(hWnd, &Rect, FALSE); // call WM_PAINT for background and display redraw
|
2024-03-19 22:24:30 +01:00
|
|
|
}
|
|
|
|
break;
|
2024-03-19 22:37:03 +01:00
|
|
|
case 4: // bitmap key, even in display
|
2024-03-19 22:24:30 +01:00
|
|
|
if (pButton[nId].bDown)
|
|
|
|
{
|
2024-03-19 22:37:03 +01:00
|
|
|
// update background only
|
2024-03-19 22:24:30 +01:00
|
|
|
BitBlt(hWindowDC, x0, y0, pButton[nId].nCx, pButton[nId].nCy, hMainDC, x0, y0, SRCCOPY);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RECT Rect;
|
2024-03-19 22:37:54 +01:00
|
|
|
Rect.left = x0 - nBackgroundX;
|
|
|
|
Rect.top = y0 - nBackgroundY;
|
|
|
|
Rect.right = Rect.left + pButton[nId].nCx;
|
|
|
|
Rect.bottom = Rect.top + pButton[nId].nCy;
|
2024-03-19 22:37:03 +01:00
|
|
|
InvalidateRect(hWnd, &Rect, FALSE); // call WM_PAINT for background and display redraw
|
2024-03-19 22:24:30 +01:00
|
|
|
}
|
|
|
|
break;
|
2024-03-19 22:37:03 +01:00
|
|
|
case 5: // transparent circle
|
2024-03-19 22:24:30 +01:00
|
|
|
if (pButton[nId].bDown)
|
|
|
|
{
|
2024-03-19 22:37:03 +01:00
|
|
|
TransparentCircle(x0 + pButton[nId].nCx / 2, // x-center coordinate
|
|
|
|
y0 + pButton[nId].nCy / 2, // y-center coordinate
|
|
|
|
min(pButton[nId].nCx,pButton[nId].nCy) / 2); // radius
|
2024-03-19 22:24:30 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-03-19 22:37:03 +01:00
|
|
|
// update background only
|
2024-03-19 22:24:30 +01:00
|
|
|
BitBlt(hWindowDC, x0, y0, pButton[nId].nCx, pButton[nId].nCy, hMainDC, x0, y0, SRCCOPY);
|
|
|
|
}
|
|
|
|
break;
|
2024-03-19 22:37:03 +01:00
|
|
|
default: // black key, default drawing on illegal types
|
2024-03-19 22:24:30 +01:00
|
|
|
if (pButton[nId].bDown)
|
2024-03-19 22:37:03 +01:00
|
|
|
{
|
|
|
|
PatBlt(hWindowDC, x0, y0, pButton[nId].nCx, pButton[nId].nCy, BLACKNESS);
|
|
|
|
}
|
2024-03-19 22:24:30 +01:00
|
|
|
else
|
2024-03-19 22:37:03 +01:00
|
|
|
{
|
|
|
|
// update background only
|
2024-03-19 22:24:30 +01:00
|
|
|
BitBlt(hWindowDC, x0, y0, pButton[nId].nCx, pButton[nId].nCy, hMainDC, x0, y0, SRCCOPY);
|
2024-03-19 22:37:03 +01:00
|
|
|
}
|
2024-03-19 22:22:29 +01:00
|
|
|
}
|
2024-03-19 22:25:45 +01:00
|
|
|
GdiFlush();
|
2024-03-19 22:22:29 +01:00
|
|
|
}
|
2024-03-19 22:25:45 +01:00
|
|
|
LeaveCriticalSection(&csGDILock);
|
2024-03-19 22:22:29 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VOID PressButton(UINT nId)
|
|
|
|
{
|
2024-03-19 22:25:45 +01:00
|
|
|
if (pButton[nId].bDown) return; // key already pressed -> exit
|
|
|
|
|
2024-03-19 22:22:29 +01:00
|
|
|
pButton[nId].bDown = TRUE;
|
|
|
|
DrawButton(nId);
|
|
|
|
if (pButton[nId].nIn)
|
|
|
|
{
|
|
|
|
KeyboardEvent(TRUE,pButton[nId].nOut,pButton[nId].nIn);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-03-19 22:37:54 +01:00
|
|
|
KmlLine* pLine = pButton[nId].pOnDown;
|
2024-03-19 22:22:29 +01:00
|
|
|
while ((pLine)&&(pLine->eCommand!=TOK_END))
|
|
|
|
{
|
|
|
|
pLine = RunLine(pLine);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VOID ReleaseButton(UINT nId)
|
|
|
|
{
|
|
|
|
pButton[nId].bDown = FALSE;
|
|
|
|
DrawButton(nId);
|
|
|
|
if (pButton[nId].nIn)
|
|
|
|
{
|
|
|
|
KeyboardEvent(FALSE,pButton[nId].nOut,pButton[nId].nIn);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-03-19 22:37:54 +01:00
|
|
|
KmlLine* pLine = pButton[nId].pOnUp;
|
2024-03-19 22:22:29 +01:00
|
|
|
while ((pLine)&&(pLine->eCommand!=TOK_END))
|
|
|
|
{
|
|
|
|
pLine = RunLine(pLine);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VOID PressButtonById(UINT nId)
|
|
|
|
{
|
|
|
|
UINT i;
|
|
|
|
for (i=0; i<nButtons; i++)
|
|
|
|
{
|
|
|
|
if (nId == pButton[i].nId)
|
|
|
|
{
|
|
|
|
PressButton(i);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VOID ReleaseButtonById(UINT nId)
|
|
|
|
{
|
|
|
|
UINT i;
|
|
|
|
for (i=0; i<nButtons; i++)
|
|
|
|
{
|
|
|
|
if (nId == pButton[i].nId)
|
|
|
|
{
|
|
|
|
ReleaseButton(i);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-03-19 22:25:45 +01:00
|
|
|
static VOID ReleaseAllButtons(VOID) // release all buttons
|
2024-03-19 22:24:30 +01:00
|
|
|
{
|
|
|
|
UINT i;
|
|
|
|
for (i=0; i<nButtons; i++) // scan all buttons
|
|
|
|
{
|
|
|
|
if (pButton[i].bDown) // button pressed
|
|
|
|
ReleaseButton(i); // release button
|
|
|
|
}
|
|
|
|
|
|
|
|
bPressed = FALSE; // key not pressed
|
|
|
|
bClicking = FALSE; // var uButtonClicked not valid (no virtual or nohold key)
|
|
|
|
uButtonClicked = 0; // set var to default
|
|
|
|
}
|
|
|
|
|
2024-03-19 23:33:35 +01:00
|
|
|
VOID ReloadButtons(BYTE *Keyboard_Row, UINT nSize)
|
|
|
|
{
|
|
|
|
UINT i;
|
|
|
|
for (i=0; i<nButtons; i++) // scan all buttons
|
|
|
|
{
|
|
|
|
if (pButton[i].nOut < nSize) // valid out code
|
|
|
|
{
|
|
|
|
// get state of button from keyboard matrix
|
|
|
|
pButton[i].bDown = ((Keyboard_Row[pButton[i].nOut] & pButton[i].nIn) != 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-19 22:37:03 +01:00
|
|
|
VOID RefreshButtons(RECT *rc)
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
|
|
|
UINT i;
|
2024-03-19 23:35:29 +01:00
|
|
|
for (i=0; i<nButtons; i++)
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
2024-03-19 22:37:03 +01:00
|
|
|
if ( pButton[i].bDown
|
|
|
|
&& rc->right > (LONG) (pButton[i].nOx)
|
|
|
|
&& rc->bottom > (LONG) (pButton[i].nOy)
|
2024-03-19 23:35:29 +01:00
|
|
|
&& rc->left <= (LONG) (pButton[i].nOx + pButton[i].nCx)
|
2024-03-19 22:37:03 +01:00
|
|
|
&& rc->top <= (LONG) (pButton[i].nOy + pButton[i].nCy))
|
2024-03-19 22:25:45 +01:00
|
|
|
{
|
2024-03-19 22:37:03 +01:00
|
|
|
// on button type 3 and 5 clear complete key area before drawing
|
|
|
|
if (pButton[i].nType == 3 || pButton[i].nType == 5)
|
2024-03-19 22:25:45 +01:00
|
|
|
{
|
|
|
|
UINT x0 = pButton[i].nOx;
|
|
|
|
UINT y0 = pButton[i].nOy;
|
2024-03-19 22:36:03 +01:00
|
|
|
EnterCriticalSection(&csGDILock); // solving NT GDI problems
|
|
|
|
{
|
|
|
|
BitBlt(hWindowDC, x0, y0, pButton[i].nCx, pButton[i].nCy, hMainDC, x0, y0, SRCCOPY);
|
|
|
|
GdiFlush();
|
|
|
|
}
|
|
|
|
LeaveCriticalSection(&csGDILock);
|
2024-03-19 22:25:45 +01:00
|
|
|
}
|
|
|
|
DrawButton(i); // redraw pressed button
|
|
|
|
}
|
2024-03-19 22:22:29 +01:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//################
|
|
|
|
//#
|
|
|
|
//# Annunciators
|
|
|
|
//#
|
|
|
|
//################
|
|
|
|
|
|
|
|
VOID DrawAnnunciator(UINT nId, BOOL bOn)
|
|
|
|
{
|
2024-03-19 22:37:03 +01:00
|
|
|
UINT nSx,nSy;
|
|
|
|
|
|
|
|
--nId; // zero based ID
|
2024-03-19 22:37:54 +01:00
|
|
|
if (nId >= ARRAYSIZEOF(pAnnunciator)) return;
|
2024-03-19 22:37:03 +01:00
|
|
|
if (bOn)
|
|
|
|
{
|
|
|
|
nSx = pAnnunciator[nId].nDx; // position of annunciator
|
|
|
|
nSy = pAnnunciator[nId].nDy;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nSx = pAnnunciator[nId].nOx; // position of background
|
|
|
|
nSy = pAnnunciator[nId].nOy;
|
|
|
|
}
|
2024-03-19 22:25:45 +01:00
|
|
|
EnterCriticalSection(&csGDILock); // solving NT GDI problems
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
2024-03-19 22:37:03 +01:00
|
|
|
BitBlt(hWindowDC,
|
|
|
|
pAnnunciator[nId].nOx, pAnnunciator[nId].nOy,
|
|
|
|
pAnnunciator[nId].nCx, pAnnunciator[nId].nCy,
|
|
|
|
hMainDC,
|
|
|
|
nSx, nSy,
|
|
|
|
SRCCOPY);
|
2024-03-19 22:25:45 +01:00
|
|
|
GdiFlush();
|
2024-03-19 22:22:29 +01:00
|
|
|
}
|
2024-03-19 22:25:45 +01:00
|
|
|
LeaveCriticalSection(&csGDILock);
|
2024-03-19 22:22:29 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//################
|
|
|
|
//#
|
|
|
|
//# Mouse
|
|
|
|
//#
|
|
|
|
//################
|
|
|
|
|
|
|
|
static BOOL ClipButton(UINT x, UINT y, UINT nId)
|
|
|
|
{
|
2024-03-19 22:37:54 +01:00
|
|
|
x += nBackgroundX; // source display offset
|
|
|
|
y += nBackgroundY;
|
|
|
|
|
2024-03-19 22:22:29 +01:00
|
|
|
return (pButton[nId].nOx<=x)
|
|
|
|
&& (pButton[nId].nOy<=y)
|
|
|
|
&&(x<(pButton[nId].nOx+pButton[nId].nCx))
|
|
|
|
&&(y<(pButton[nId].nOy+pButton[nId].nCy));
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID MouseButtonDownAt(UINT nFlags, DWORD x, DWORD y)
|
|
|
|
{
|
|
|
|
UINT i;
|
|
|
|
for (i=0; i<nButtons; i++)
|
|
|
|
{
|
|
|
|
if (ClipButton(x,y,i))
|
|
|
|
{
|
|
|
|
if (pButton[i].dwFlags&BUTTON_NOHOLD)
|
|
|
|
{
|
2024-03-19 22:25:45 +01:00
|
|
|
if (nFlags&MK_LBUTTON) // use only with left mouse button
|
2024-03-19 22:24:30 +01:00
|
|
|
{
|
|
|
|
bClicking = TRUE;
|
|
|
|
uButtonClicked = i;
|
|
|
|
pButton[i].bDown = TRUE;
|
|
|
|
DrawButton(i);
|
|
|
|
}
|
2024-03-19 22:22:29 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (pButton[i].dwFlags&BUTTON_VIRTUAL)
|
|
|
|
{
|
2024-03-19 22:25:45 +01:00
|
|
|
if (!(nFlags&MK_LBUTTON)) // use only with left mouse button
|
2024-03-19 22:24:30 +01:00
|
|
|
return;
|
2024-03-19 22:22:29 +01:00
|
|
|
bClicking = TRUE;
|
|
|
|
uButtonClicked = i;
|
|
|
|
}
|
2024-03-19 22:25:45 +01:00
|
|
|
bPressed = TRUE; // key pressed
|
|
|
|
uLastPressedKey = i; // save pressed key
|
2024-03-19 22:22:29 +01:00
|
|
|
PressButton(i);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID MouseButtonUpAt(UINT nFlags, DWORD x, DWORD y)
|
|
|
|
{
|
|
|
|
UINT i;
|
2024-03-19 22:25:45 +01:00
|
|
|
if (bPressed) // emulator key pressed
|
2024-03-19 22:24:30 +01:00
|
|
|
{
|
2024-03-19 22:25:45 +01:00
|
|
|
ReleaseAllButtons(); // release all buttons
|
2024-03-19 22:24:30 +01:00
|
|
|
return;
|
|
|
|
}
|
2024-03-19 22:22:29 +01:00
|
|
|
for (i=0; i<nButtons; i++)
|
|
|
|
{
|
|
|
|
if (ClipButton(x,y,i))
|
|
|
|
{
|
|
|
|
if ((bClicking)&&(uButtonClicked != i)) break;
|
|
|
|
ReleaseButton(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bClicking = FALSE;
|
|
|
|
uButtonClicked = 0;
|
|
|
|
return;
|
|
|
|
UNREFERENCED_PARAMETER(nFlags);
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID MouseMovesTo(UINT nFlags, DWORD x, DWORD y)
|
|
|
|
{
|
2024-03-19 22:38:33 +01:00
|
|
|
UINT i;
|
|
|
|
HCURSOR hCursor;
|
|
|
|
|
|
|
|
// set cursor
|
|
|
|
_ASSERT(hCursorArrow);
|
|
|
|
_ASSERT(hCursorHand);
|
|
|
|
hCursor = hCursorArrow; // normal arrow cursor
|
|
|
|
if (!bClassicCursor)
|
|
|
|
{
|
|
|
|
for (i = 0; i < nButtons; i++) // scan all buttons
|
|
|
|
{
|
|
|
|
if (ClipButton(x,y,i)) // cursor over button?
|
|
|
|
{
|
|
|
|
hCursor = hCursorHand; // hand cursor
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// make sure that class cursor is NULL
|
|
|
|
_ASSERT(GetClassLong(hWnd,GCL_HCURSOR) == 0);
|
|
|
|
SetCursor(hCursor);
|
|
|
|
|
2024-03-19 22:24:30 +01:00
|
|
|
if (!(nFlags&MK_LBUTTON)) return; // left mouse key not pressed -> quit
|
2024-03-19 22:25:45 +01:00
|
|
|
if ((bPressed) && !(ClipButton(x,y,uLastPressedKey))) // not on last pressed key
|
|
|
|
ReleaseAllButtons(); // release all buttons
|
2024-03-19 22:24:30 +01:00
|
|
|
if (!bClicking) return; // normal emulation key -> quit
|
|
|
|
|
2024-03-19 22:22:29 +01:00
|
|
|
if (pButton[uButtonClicked].dwFlags&BUTTON_NOHOLD)
|
|
|
|
{
|
|
|
|
if (ClipButton(x,y, uButtonClicked) != pButton[uButtonClicked].bDown)
|
|
|
|
{
|
|
|
|
pButton[uButtonClicked].bDown = !pButton[uButtonClicked].bDown;
|
|
|
|
DrawButton(uButtonClicked);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (pButton[uButtonClicked].dwFlags&BUTTON_VIRTUAL)
|
|
|
|
{
|
|
|
|
if (!ClipButton(x,y, uButtonClicked))
|
|
|
|
{
|
|
|
|
ReleaseButton(uButtonClicked);
|
|
|
|
bClicking = FALSE;
|
|
|
|
uButtonClicked = 0;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//################
|
|
|
|
//#
|
|
|
|
//# Keyboard
|
|
|
|
//#
|
|
|
|
//################
|
|
|
|
|
|
|
|
VOID RunKey(BYTE nId, BOOL bPressed)
|
|
|
|
{
|
|
|
|
if (pVKey[nId])
|
|
|
|
{
|
2024-03-19 22:37:54 +01:00
|
|
|
KmlLine* pLine = pVKey[nId]->pFirstLine;
|
2024-03-19 22:22:29 +01:00
|
|
|
byVKeyMap[nId] = bPressed;
|
|
|
|
while (pLine) pLine = RunLine(pLine);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (bDebug&&bPressed)
|
|
|
|
{
|
2024-03-19 22:37:03 +01:00
|
|
|
TCHAR szTemp[128];
|
|
|
|
wsprintf(szTemp,_T("Scancode %i"),nId);
|
2024-03-19 22:22:29 +01:00
|
|
|
InfoMessage(szTemp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-03-19 23:33:35 +01:00
|
|
|
//################
|
|
|
|
//#
|
|
|
|
//# Macro player
|
|
|
|
//#
|
|
|
|
//################
|
|
|
|
|
|
|
|
VOID PlayKey(UINT nOut, UINT nIn, BOOL bPressed)
|
|
|
|
{
|
|
|
|
// scan from last buttons because LCD buttons mostly defined first
|
2024-03-19 23:35:29 +01:00
|
|
|
INT i = nButtons;
|
2024-03-19 23:33:35 +01:00
|
|
|
while (--i >= 0)
|
|
|
|
{
|
|
|
|
if (pButton[i].nOut == nOut && pButton[i].nIn == nIn)
|
|
|
|
{
|
|
|
|
if (bPressed)
|
|
|
|
PressButton(i);
|
|
|
|
else
|
|
|
|
ReleaseButton(i);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-03-19 22:22:29 +01:00
|
|
|
//################
|
|
|
|
//#
|
|
|
|
//# Load and Initialize Script
|
|
|
|
//#
|
|
|
|
//################
|
|
|
|
|
2024-03-19 22:37:54 +01:00
|
|
|
static KmlBlock* LoadKMLGlobal(LPCTSTR szFilename)
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
2024-03-19 22:37:54 +01:00
|
|
|
HANDLE hFile;
|
|
|
|
LPTSTR lpBuf;
|
|
|
|
KmlBlock* pBlock;
|
|
|
|
DWORD eToken;
|
2024-03-19 22:22:29 +01:00
|
|
|
|
2024-03-19 22:38:33 +01:00
|
|
|
SetCurrentDirectory(szEmuDirectory);
|
2024-03-19 23:33:35 +01:00
|
|
|
hFile = CreateFile(szFilename,
|
|
|
|
GENERIC_READ,
|
|
|
|
FILE_SHARE_READ,
|
|
|
|
NULL,
|
|
|
|
OPEN_EXISTING,
|
|
|
|
FILE_FLAG_SEQUENTIAL_SCAN,
|
|
|
|
NULL);
|
2024-03-19 22:22:29 +01:00
|
|
|
SetCurrentDirectory(szCurrentDirectory);
|
|
|
|
if (hFile == INVALID_HANDLE_VALUE) return NULL;
|
2024-03-19 22:37:03 +01:00
|
|
|
if ((lpBuf = MapKMLFile(hFile)) == NULL)
|
2024-03-19 22:22:29 +01:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
InitLex(lpBuf);
|
|
|
|
pBlock = NULL;
|
2024-03-19 23:35:29 +01:00
|
|
|
while ((eToken = Lex(LEX_BLOCK)) != TOK_NONE)
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
2024-03-19 23:35:29 +01:00
|
|
|
if (eToken == TOK_GLOBAL)
|
|
|
|
{
|
|
|
|
pBlock = ParseBlock(eToken);
|
|
|
|
if (pBlock) pBlock->pNext = NULL;
|
|
|
|
break;
|
|
|
|
}
|
2024-03-19 22:22:29 +01:00
|
|
|
}
|
|
|
|
CleanLex();
|
|
|
|
ClearLog();
|
2024-03-19 22:38:33 +01:00
|
|
|
HeapFree(hHeap,0,lpBuf);
|
2024-03-19 22:22:29 +01:00
|
|
|
return pBlock;
|
|
|
|
}
|
|
|
|
|
2024-03-19 22:37:03 +01:00
|
|
|
BOOL InitKML(LPCTSTR szFilename, BOOL bNoLog)
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
2024-03-19 22:37:54 +01:00
|
|
|
HANDLE hFile;
|
|
|
|
LPTSTR lpBuf;
|
|
|
|
KmlBlock* pBlock;
|
|
|
|
BOOL bOk = FALSE;
|
2024-03-19 22:22:29 +01:00
|
|
|
|
|
|
|
KillKML();
|
|
|
|
|
|
|
|
nBlocksIncludeLevel = 0;
|
2024-03-19 22:37:03 +01:00
|
|
|
PrintfToLog(_T("Reading %s"), szFilename);
|
2024-03-19 22:38:33 +01:00
|
|
|
SetCurrentDirectory(szEmuDirectory);
|
2024-03-19 23:33:35 +01:00
|
|
|
hFile = CreateFile(szFilename,
|
|
|
|
GENERIC_READ,
|
|
|
|
FILE_SHARE_READ,
|
|
|
|
NULL,
|
|
|
|
OPEN_EXISTING,
|
|
|
|
FILE_FLAG_SEQUENTIAL_SCAN,
|
|
|
|
NULL);
|
2024-03-19 22:22:29 +01:00
|
|
|
SetCurrentDirectory(szCurrentDirectory);
|
|
|
|
if (hFile == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
2024-03-19 22:37:03 +01:00
|
|
|
AddToLog(_T("Error while opening the file."));
|
2024-03-19 22:22:29 +01:00
|
|
|
goto quit;
|
|
|
|
}
|
2024-03-19 22:37:03 +01:00
|
|
|
if ((lpBuf = MapKMLFile(hFile)) == NULL)
|
2024-03-19 22:22:29 +01:00
|
|
|
goto quit;
|
|
|
|
|
|
|
|
InitLex(lpBuf);
|
|
|
|
pKml = ParseBlocks();
|
|
|
|
CleanLex();
|
|
|
|
|
2024-03-19 22:38:33 +01:00
|
|
|
HeapFree(hHeap,0,lpBuf);
|
2024-03-19 22:22:29 +01:00
|
|
|
if (pKml == NULL) goto quit;
|
|
|
|
|
|
|
|
pBlock = pKml;
|
|
|
|
while (pBlock)
|
|
|
|
{
|
|
|
|
switch (pBlock->eType)
|
|
|
|
{
|
|
|
|
case TOK_BUTTON:
|
|
|
|
InitButton(pBlock);
|
|
|
|
break;
|
|
|
|
case TOK_SCANCODE:
|
|
|
|
nScancodes++;
|
|
|
|
pVKey[pBlock->nId] = pBlock;
|
|
|
|
break;
|
|
|
|
case TOK_ANNUNCIATOR:
|
|
|
|
InitAnnunciator(pBlock);
|
|
|
|
break;
|
|
|
|
case TOK_GLOBAL:
|
|
|
|
InitGlobal(pBlock);
|
|
|
|
break;
|
|
|
|
case TOK_LCD:
|
|
|
|
InitLcd(pBlock);
|
|
|
|
break;
|
|
|
|
case TOK_BACKGROUND:
|
|
|
|
InitBackground(pBlock);
|
|
|
|
break;
|
|
|
|
default:
|
2024-03-19 22:37:03 +01:00
|
|
|
PrintfToLog(_T("Block %s Ignored."), GetStringOf(pBlock->eType));
|
2024-03-19 22:22:29 +01:00
|
|
|
pBlock = pBlock->pNext;
|
|
|
|
}
|
|
|
|
pBlock = pBlock->pNext;
|
|
|
|
}
|
2024-03-19 23:35:29 +01:00
|
|
|
|
|
|
|
if (!isModelValid(cCurrentRomType))
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
2024-03-19 23:35:29 +01:00
|
|
|
AddToLog(_T("This KML Script doesn't specify a valid model."));
|
2024-03-19 22:22:29 +01:00
|
|
|
goto quit;
|
|
|
|
}
|
|
|
|
if (pbyRom == NULL)
|
|
|
|
{
|
2024-03-19 22:37:03 +01:00
|
|
|
AddToLog(_T("This KML Script doesn't specify the ROM to use, or the ROM could not be loaded."));
|
2024-03-19 22:22:29 +01:00
|
|
|
goto quit;
|
|
|
|
}
|
2024-03-19 23:35:29 +01:00
|
|
|
if (hMainDC == NULL)
|
|
|
|
{
|
|
|
|
AddToLog(_T("This KML Script doesn't specify the background bitmap, or bitmap could not be loaded."));
|
|
|
|
goto quit;
|
|
|
|
}
|
|
|
|
|
2024-03-19 22:22:29 +01:00
|
|
|
CreateLcdBitmap();
|
|
|
|
|
2024-03-19 22:37:03 +01:00
|
|
|
PrintfToLog(_T("%i Buttons Defined"), nButtons);
|
|
|
|
PrintfToLog(_T("%i Scancodes Defined"), nScancodes);
|
|
|
|
PrintfToLog(_T("%i Annunciators Defined"), nAnnunciators);
|
2024-03-19 22:22:29 +01:00
|
|
|
|
|
|
|
bOk = TRUE;
|
|
|
|
|
|
|
|
quit:
|
|
|
|
if (bOk)
|
|
|
|
{
|
2024-03-19 22:38:33 +01:00
|
|
|
// HP38G/HP39G/HP40G have no object loading, ignore
|
|
|
|
DragAcceptFiles(hWnd,cCurrentRomType != '6' && cCurrentRomType != 'A' && cCurrentRomType != 'E');
|
|
|
|
|
2024-03-19 22:22:29 +01:00
|
|
|
if (!bNoLog)
|
|
|
|
{
|
2024-03-19 22:37:03 +01:00
|
|
|
AddToLog(_T("Press Ok to Continue."));
|
2024-03-19 22:22:29 +01:00
|
|
|
if (bAlwaysDisplayLog&&(!DisplayKMLLog(bOk)))
|
|
|
|
{
|
|
|
|
KillKML();
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-03-19 22:37:03 +01:00
|
|
|
AddToLog(_T("Press Cancel to Abort."));
|
2024-03-19 22:22:29 +01:00
|
|
|
if (!DisplayKMLLog(bOk))
|
|
|
|
{
|
|
|
|
KillKML();
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ResizeWindow();
|
|
|
|
ClearLog();
|
|
|
|
return bOk;
|
|
|
|
}
|