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"
|
|
|
|
|
|
|
|
static VOID FatalError();
|
2024-03-19 22:37:03 +01:00
|
|
|
static VOID InitLex(LPTSTR szScript);
|
2024-03-19 22:22:29 +01:00
|
|
|
static VOID CleanLex();
|
|
|
|
static VOID SkipWhite(UINT nMode);
|
|
|
|
static TokenId ParseToken(UINT nMode);
|
|
|
|
static DWORD ParseInteger();
|
2024-03-19 22:37:03 +01:00
|
|
|
static LPTSTR ParseString();
|
2024-03-19 22:22:29 +01:00
|
|
|
static TokenId Lex(UINT nMode);
|
|
|
|
static Line* ParseLine(TokenId eCommand);
|
2024-03-19 22:37:03 +01:00
|
|
|
static Line* IncludeLines(LPCTSTR szFilename);
|
2024-03-19 22:22:29 +01:00
|
|
|
static Line* ParseLines();
|
|
|
|
static Block* ParseBlock(TokenId eBlock);
|
2024-03-19 22:37:03 +01:00
|
|
|
static Block* IncludeBlocks(LPCTSTR szFilename);
|
2024-03-19 22:22:29 +01:00
|
|
|
static Block* ParseBlocks();
|
|
|
|
static VOID FreeLines(Line* pLine);
|
|
|
|
static VOID PressButton(UINT nId);
|
|
|
|
static VOID ReleaseButton(UINT nId);
|
|
|
|
static VOID PressButtonById(UINT nId);
|
|
|
|
static VOID ReleaseButtonById(UINT nId);
|
2024-03-19 22:37:03 +01:00
|
|
|
static LPTSTR GetStringParam(Block* pBlock, TokenId eBlock, TokenId eCommand, UINT nParam);
|
|
|
|
static DWORD GetIntegerParam(Block* pBlock, TokenId eBlock, TokenId eCommand, UINT nParam);
|
|
|
|
static Line* SkipLines(Line* pLine, TokenId eCommand);
|
2024-03-19 22:22:29 +01:00
|
|
|
static Line* If(Line* pLine, BOOL bCondition);
|
|
|
|
static Line* RunLine(Line* pLine);
|
2024-03-19 22:37:03 +01:00
|
|
|
static Block* LoadKMLGlobal(LPCTSTR szFilename);
|
2024-03-19 22:22:29 +01:00
|
|
|
|
|
|
|
Block* pKml;
|
2024-03-19 22:37:03 +01:00
|
|
|
static Block* pVKey[256];
|
|
|
|
static BYTE byVKeyMap[256];
|
|
|
|
static Button pButton[256];
|
2024-03-19 22:22:29 +01:00
|
|
|
static Annunciator pAnnunciator[6];
|
2024-03-19 22:37:03 +01:00
|
|
|
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;
|
|
|
|
static LPTSTR szLexDelim[] =
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
2024-03-19 22:37:03 +01:00
|
|
|
_T(""),
|
|
|
|
_T(" \t\n\r"),
|
|
|
|
_T(" \t\n\r"),
|
|
|
|
_T(" \t\r")
|
2024-03-19 22:22:29 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static Token pLexToken[] =
|
|
|
|
{
|
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")},
|
|
|
|
{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")},
|
|
|
|
{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")},
|
|
|
|
{TOK_LCD, 000000, 3,_T("Lcd")},
|
|
|
|
{TOK_END, 000000, 3,_T("End")},
|
|
|
|
{0, 000000, 0,_T("")},
|
2024-03-19 22:22:29 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static TokenId eIsBlock[] =
|
|
|
|
{
|
|
|
|
TOK_IFFLAG,
|
|
|
|
TOK_IFPRESSED,
|
|
|
|
TOK_ONDOWN,
|
|
|
|
TOK_ONUP,
|
|
|
|
TOK_NONE
|
|
|
|
};
|
|
|
|
|
|
|
|
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 BOOL bKmlLogOkEnabled = FALSE;
|
|
|
|
|
|
|
|
static VOID ClearLog()
|
|
|
|
{
|
|
|
|
nLogLength = 0;
|
|
|
|
if (szLog != NULL)
|
|
|
|
{
|
|
|
|
LocalFree(szLog);
|
|
|
|
szLog = NULL;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-03-19 22:37:03 +01:00
|
|
|
static VOID AddToLog(LPTSTR szString)
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
2024-03-19 22:37:03 +01:00
|
|
|
UINT nLength = lstrlen(szString);
|
2024-03-19 22:22:29 +01:00
|
|
|
if (szLog == NULL)
|
|
|
|
{
|
2024-03-19 22:37:03 +01:00
|
|
|
nLogLength = nLength + 3; // CR+LF+\0
|
|
|
|
szLog = LocalAlloc(LMEM_FIXED,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 22:37:03 +01:00
|
|
|
LPTSTR szLogTmp = LocalReAlloc(szLog,(nLogLength+nLength+2)*sizeof(szLog[0]),LMEM_MOVEABLE);
|
|
|
|
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);
|
|
|
|
nLogLength += nLength + 2; // CR+LF
|
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 22:37:03 +01:00
|
|
|
LPTSTR lpOutput;
|
2024-03-19 22:22:29 +01:00
|
|
|
va_list arglist;
|
|
|
|
|
|
|
|
va_start(arglist,lpFormat);
|
|
|
|
lpOutput = LocalAlloc(0,1024);
|
|
|
|
wvsprintf(lpOutput,lpFormat,arglist);
|
|
|
|
AddToLog(lpOutput);
|
|
|
|
LocalFree(lpOutput);
|
|
|
|
va_end(arglist);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL CALLBACK KMLLogProc(HWND hDlg, UINT message, DWORD wParam, LONG lParam)
|
|
|
|
{
|
2024-03-19 22:37:03 +01:00
|
|
|
LPTSTR szString;
|
2024-03-19 22:22:29 +01:00
|
|
|
|
|
|
|
switch (message)
|
|
|
|
{
|
|
|
|
case WM_INITDIALOG:
|
|
|
|
// set OK
|
|
|
|
EnableWindow(GetDlgItem(hDlg,IDOK),bKmlLogOkEnabled);
|
|
|
|
// 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
|
|
|
|
if (szLog == NULL)
|
2024-03-19 22:37:03 +01:00
|
|
|
SetDlgItemText(hDlg,IDC_KMLLOG,_T("Memory Allocation Failure."));
|
2024-03-19 22:22:29 +01:00
|
|
|
else
|
|
|
|
SetDlgItemText(hDlg,IDC_KMLLOG,szLog);
|
|
|
|
// set IDC_ALWAYSDISPLOG
|
|
|
|
CheckDlgButton(hDlg,IDC_ALWAYSDISPLOG,bAlwaysDisplayLog);
|
|
|
|
// redraw window
|
|
|
|
InvalidateRect(hDlg, NULL, TRUE);
|
|
|
|
return TRUE;
|
|
|
|
case WM_COMMAND:
|
|
|
|
bAlwaysDisplayLog = IsDlgButtonChecked(hDlg, IDC_ALWAYSDISPLOG);
|
|
|
|
if ((wParam == IDCANCEL)||(wParam == IDOK)) EndDialog(hDlg, wParam);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
UNREFERENCED_PARAMETER(lParam);
|
|
|
|
UNREFERENCED_PARAMETER(hDlg);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL DisplayKMLLog(BOOL bOkEnabled)
|
|
|
|
{
|
|
|
|
BOOL bResult;
|
|
|
|
bKmlLogOkEnabled = bOkEnabled;
|
|
|
|
bResult = DialogBox(hApp, MAKEINTRESOURCE(IDD_KMLLOG), hWnd, (DLGPROC)KMLLogProc);
|
|
|
|
return (bResult == IDOK);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//################
|
|
|
|
//#
|
|
|
|
//# Choose Script
|
|
|
|
//#
|
|
|
|
//################
|
|
|
|
|
|
|
|
typedef struct _KmlScript
|
|
|
|
{
|
2024-03-19 22:37:03 +01:00
|
|
|
LPTSTR szFilename;
|
|
|
|
LPTSTR szTitle;
|
2024-03-19 22:22:29 +01:00
|
|
|
DWORD nId;
|
|
|
|
struct _KmlScript* pNext;
|
|
|
|
} KmlScript;
|
|
|
|
|
|
|
|
static UINT nKmlFiles;
|
|
|
|
static KmlScript* pKmlList;
|
|
|
|
static CHAR cKmlType;
|
|
|
|
|
|
|
|
static VOID DestroyKmlList()
|
|
|
|
{
|
|
|
|
KmlScript* pList;
|
|
|
|
|
|
|
|
while (pKmlList)
|
|
|
|
{
|
|
|
|
pList = pKmlList->pNext;
|
|
|
|
LocalFree(pKmlList->szFilename);
|
|
|
|
LocalFree(pKmlList->szTitle);
|
|
|
|
LocalFree(pKmlList);
|
|
|
|
pKmlList = pList;
|
|
|
|
}
|
|
|
|
nKmlFiles = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VOID CreateKmlList()
|
|
|
|
{
|
|
|
|
HANDLE hFindFile;
|
|
|
|
WIN32_FIND_DATA pFindFileData;
|
|
|
|
|
|
|
|
SetCurrentDirectory(szEmu48Directory);
|
2024-03-19 22:37:03 +01:00
|
|
|
hFindFile = FindFirstFile(_T("*.KML"),&pFindFileData);
|
2024-03-19 22:22:29 +01:00
|
|
|
SetCurrentDirectory(szCurrentDirectory);
|
|
|
|
nKmlFiles = 0;
|
|
|
|
if (hFindFile == INVALID_HANDLE_VALUE) return;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
KmlScript* pScript;
|
|
|
|
Block* 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;
|
|
|
|
if (cKmlType)
|
|
|
|
{
|
|
|
|
szTitle = GetStringParam(pBlock,TOK_GLOBAL,TOK_MODEL,0);
|
|
|
|
if ((!szTitle)||(szTitle[0]!=cKmlType))
|
|
|
|
{
|
|
|
|
FreeBlocks(pBlock);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pScript = LocalAlloc(0, sizeof(KmlScript));
|
|
|
|
pScript->szFilename = DuplicateString(pFindFileData.cFileName);
|
|
|
|
szTitle = GetStringParam(pBlock,TOK_GLOBAL,TOK_TITLE,0);
|
|
|
|
if (szTitle == NULL) szTitle = DuplicateString(pScript->szFilename);
|
|
|
|
pScript->szTitle = DuplicateString(szTitle);
|
|
|
|
FreeBlocks(pBlock);
|
|
|
|
pScript->nId = nKmlFiles;
|
|
|
|
pScript->pNext = pKmlList;
|
|
|
|
pKmlList = pScript;
|
|
|
|
nKmlFiles++;
|
|
|
|
} while (FindNextFile(hFindFile,&pFindFileData));
|
|
|
|
FindClose(hFindFile);
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
|
|
|
|
static BOOL CALLBACK ChooseKMLProc(HWND hDlg, UINT message, DWORD wParam, LONG lParam)
|
|
|
|
{
|
|
|
|
HWND hList;
|
|
|
|
KmlScript* pList;
|
|
|
|
UINT nIndex;
|
|
|
|
|
|
|
|
switch (message)
|
|
|
|
{
|
|
|
|
case WM_INITDIALOG:
|
|
|
|
SetDlgItemText(hDlg,IDC_EMU48DIR,szEmu48Directory);
|
|
|
|
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_SETTEXT:
|
|
|
|
{
|
2024-03-19 22:37:03 +01:00
|
|
|
TCHAR szBuffer[80];
|
|
|
|
wsprintf(szBuffer,_T("%i %i %i"), hDlg, wParam, lParam);
|
2024-03-19 22:22:29 +01:00
|
|
|
InfoMessage(szBuffer);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WM_COMMAND:
|
|
|
|
if (wParam == IDC_UPDATE)
|
|
|
|
{
|
|
|
|
DestroyKmlList();
|
2024-03-19 22:24:30 +01:00
|
|
|
GetDlgItemText(hDlg,IDC_EMU48DIR,szEmu48Directory,sizeof(szEmu48Directory));
|
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);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (wParam == IDOK)
|
|
|
|
{
|
2024-03-19 22:24:30 +01:00
|
|
|
GetDlgItemText(hDlg,IDC_EMU48DIR,szEmu48Directory,sizeof(szEmu48Directory));
|
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)
|
|
|
|
{
|
|
|
|
if (pList->nId == nIndex) break;
|
|
|
|
pList = pList->pNext;
|
|
|
|
}
|
|
|
|
if (pList)
|
|
|
|
{
|
|
|
|
lstrcpy(szCurrentKml, pList->szFilename);
|
|
|
|
EndDialog(hDlg, IDOK);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (wParam == IDCANCEL)
|
|
|
|
{
|
|
|
|
EndDialog(hDlg, IDCANCEL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
UNREFERENCED_PARAMETER(lParam);
|
|
|
|
UNREFERENCED_PARAMETER(hDlg);
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
lpBuf = LocalAlloc(LMEM_FIXED,(dwFileSizeLow+1)*sizeof(lpBuf[0]));
|
|
|
|
if (lpBuf == NULL)
|
|
|
|
{
|
|
|
|
PrintfToLog(_T("Cannot allocate %i bytes."), (dwFileSizeLow+1)*sizeof(lpBuf[0]));
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
#if defined _UNICODE
|
|
|
|
{
|
|
|
|
LPSTR szTmp = LocalAlloc(LMEM_FIXED,dwFileSizeLow+1);
|
|
|
|
if (szTmp == NULL)
|
|
|
|
{
|
|
|
|
LocalFree(lpBuf);
|
|
|
|
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);
|
|
|
|
LocalFree(szTmp);
|
|
|
|
}
|
|
|
|
#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
|
|
|
|
//#
|
|
|
|
//################
|
|
|
|
|
|
|
|
static VOID FatalError()
|
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VOID CleanLex()
|
|
|
|
{
|
|
|
|
nLexLine = 0;
|
|
|
|
nLexInteger = 0;
|
|
|
|
szLexString = NULL;
|
|
|
|
szText = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Change this poor (and slow!) code
|
|
|
|
static BOOL IsBlock(TokenId eId)
|
|
|
|
{
|
|
|
|
UINT uBlock = 0;
|
|
|
|
while (eIsBlock[uBlock] != TOK_NONE)
|
|
|
|
{
|
|
|
|
if (eId == eIsBlock[uBlock]) return TRUE;
|
|
|
|
uBlock++;
|
|
|
|
}
|
|
|
|
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 22:37:03 +01:00
|
|
|
do szText++; while (*szText != _T('\n'));
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static DWORD ParseInteger()
|
|
|
|
{
|
|
|
|
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++;
|
|
|
|
}
|
|
|
|
return nNum;
|
|
|
|
}
|
|
|
|
|
2024-03-19 22:37:03 +01:00
|
|
|
static LPTSTR ParseString()
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
2024-03-19 22:37:03 +01:00
|
|
|
LPTSTR szString;
|
|
|
|
LPTSTR szBuffer;
|
|
|
|
UINT nLength;
|
|
|
|
UINT nBlock;
|
2024-03-19 22:22:29 +01:00
|
|
|
|
|
|
|
szText++;
|
|
|
|
nLength = 0;
|
|
|
|
nBlock = 255;
|
|
|
|
szBuffer = LocalAlloc(0,nBlock+1);
|
2024-03-19 22:37:03 +01:00
|
|
|
while (*szText != _T('"'))
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
2024-03-19 22:37:03 +01:00
|
|
|
if (*szText == _T('\\')) szText++;
|
2024-03-19 22:22:29 +01:00
|
|
|
if (*szText == 0)
|
|
|
|
{
|
|
|
|
FatalError();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
szBuffer[nLength] = *szText;
|
|
|
|
nLength++;
|
|
|
|
if (nLength == nBlock)
|
|
|
|
{
|
|
|
|
nBlock += 256;
|
|
|
|
szBuffer = LocalReAlloc(szBuffer, nBlock+1, LMEM_MOVEABLE);
|
|
|
|
}
|
|
|
|
szText++;
|
|
|
|
}
|
|
|
|
szText++;
|
|
|
|
szBuffer[nLength] = 0;
|
|
|
|
szString = DuplicateString(szBuffer);
|
|
|
|
LocalFree(szBuffer);
|
|
|
|
return szString;
|
|
|
|
}
|
|
|
|
|
|
|
|
static TokenId Lex(UINT nMode)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Line* ParseLine(TokenId eCommand)
|
|
|
|
{
|
|
|
|
UINT i, j;
|
|
|
|
DWORD nParams;
|
|
|
|
TokenId eToken;
|
|
|
|
Line* pLine;
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (pLexToken[i].nLen)
|
|
|
|
{
|
|
|
|
if (pLexToken[i].eId == eCommand) break;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
if (pLexToken[i].nLen == 0) return NULL;
|
|
|
|
|
|
|
|
j = 0;
|
|
|
|
pLine = LocalAlloc(LPTR,sizeof(Line));
|
|
|
|
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
|
|
|
|
if (eToken == TOK_STRING) LocalFree(szLexString);
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
LocalFree((LPVOID)pLine->nParam[i]);
|
|
|
|
}
|
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:22:29 +01:00
|
|
|
LocalFree(pLine);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2024-03-19 22:37:03 +01:00
|
|
|
static Line* IncludeLines(LPCTSTR szFilename)
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
|
|
|
HANDLE hFile;
|
2024-03-19 22:37:03 +01:00
|
|
|
LPTSTR lpbyBuf;
|
2024-03-19 22:22:29 +01:00
|
|
|
UINT uOldLine;
|
2024-03-19 22:37:03 +01:00
|
|
|
LPTSTR szOldText;
|
2024-03-19 22:22:29 +01:00
|
|
|
Line* pLine;
|
|
|
|
|
|
|
|
SetCurrentDirectory(szEmu48Directory);
|
|
|
|
hFile = CreateFile(szFilename, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
|
|
|
|
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;
|
|
|
|
LocalFree(lpbyBuf);
|
|
|
|
|
|
|
|
return pLine;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Line* ParseLines()
|
|
|
|
{
|
|
|
|
Line* pLine;
|
|
|
|
Line* pFirst = NULL;
|
|
|
|
TokenId eToken;
|
|
|
|
UINT nLevel = 0;
|
|
|
|
|
2024-03-19 22:37:03 +01:00
|
|
|
while ((eToken = Lex(LEX_COMMAND)))
|
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:25:45 +01:00
|
|
|
LocalFree(szFilename); // free memory
|
|
|
|
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 22:37:03 +01:00
|
|
|
AddToLog(_T("Open block."));
|
2024-03-19 22:22:29 +01:00
|
|
|
abort:
|
|
|
|
if (pFirst)
|
|
|
|
{
|
|
|
|
FreeLines(pFirst);
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Block* ParseBlock(TokenId eType)
|
|
|
|
{
|
|
|
|
UINT u1;
|
|
|
|
Block* pBlock;
|
|
|
|
TokenId eToken;
|
|
|
|
|
|
|
|
nLinesIncludeLevel = 0;
|
|
|
|
|
|
|
|
pBlock = LocalAlloc(LPTR,sizeof(Block));
|
|
|
|
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:22:29 +01:00
|
|
|
LocalFree(pBlock);
|
|
|
|
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:22:29 +01:00
|
|
|
LocalFree(pBlock);
|
|
|
|
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:22:29 +01:00
|
|
|
LocalFree(pBlock);
|
|
|
|
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
|
|
|
{
|
|
|
|
LocalFree(pBlock);
|
|
|
|
pBlock = NULL;
|
|
|
|
}
|
|
|
|
|
2024-03-19 22:22:29 +01:00
|
|
|
return pBlock;
|
|
|
|
}
|
|
|
|
|
2024-03-19 22:37:03 +01:00
|
|
|
static Block* IncludeBlocks(LPCTSTR szFilename)
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
|
|
|
HANDLE hFile;
|
2024-03-19 22:37:03 +01:00
|
|
|
LPTSTR lpbyBuf;
|
2024-03-19 22:22:29 +01:00
|
|
|
UINT uOldLine;
|
2024-03-19 22:37:03 +01:00
|
|
|
LPTSTR szOldText;
|
2024-03-19 22:22:29 +01:00
|
|
|
Block* pFirst;
|
|
|
|
|
|
|
|
SetCurrentDirectory(szEmu48Directory);
|
|
|
|
hFile = CreateFile(szFilename, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
|
|
|
|
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;
|
|
|
|
LocalFree(lpbyBuf);
|
|
|
|
|
|
|
|
return pFirst;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Block* ParseBlocks()
|
|
|
|
{
|
|
|
|
TokenId eToken;
|
|
|
|
Block* pFirst = NULL;
|
|
|
|
Block* pBlock;
|
|
|
|
|
|
|
|
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:25:45 +01:00
|
|
|
LocalFree(szFilename); // free memory
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
return pFirst;
|
|
|
|
abort:
|
|
|
|
if (pFirst) FreeBlocks(pFirst);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//################
|
|
|
|
//#
|
|
|
|
//# Initialization Phase
|
|
|
|
//#
|
|
|
|
//################
|
|
|
|
|
|
|
|
static VOID InitGlobal(Block* pBlock)
|
|
|
|
{
|
|
|
|
Line* pLine = pBlock->pFirstLine;
|
|
|
|
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;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Line* InitBackground(Block* pBlock)
|
|
|
|
{
|
|
|
|
Line* pLine = pBlock->pFirstLine;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Line* InitLcd(Block* pBlock)
|
|
|
|
{
|
|
|
|
Line* pLine = pBlock->pFirstLine;
|
|
|
|
while (pLine)
|
|
|
|
{
|
|
|
|
switch (pLine->eCommand)
|
|
|
|
{
|
|
|
|
case TOK_OFFSET:
|
|
|
|
nLcdX = pLine->nParam[0];
|
|
|
|
nLcdY = pLine->nParam[1];
|
|
|
|
break;
|
|
|
|
case TOK_ZOOM:
|
2024-03-19 22:25:45 +01:00
|
|
|
nLcdDoubled = pLine->nParam[0];
|
2024-03-19 22:24:30 +01:00
|
|
|
if (nLcdDoubled != 1 && nLcdDoubled != 2 && nLcdDoubled != 4)
|
|
|
|
nLcdDoubled = 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Line* InitAnnunciator(Block* pBlock)
|
|
|
|
{
|
|
|
|
Line* pLine = pBlock->pFirstLine;
|
|
|
|
UINT nId = pBlock->nId-1;
|
|
|
|
if (nId >= 6)
|
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VOID InitButton(Block* pBlock)
|
|
|
|
{
|
|
|
|
Line* pLine = pBlock->pFirstLine;
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
//#
|
|
|
|
//################
|
|
|
|
|
|
|
|
static Line* SkipLines(Line* pLine, TokenId eCommand)
|
|
|
|
{
|
|
|
|
UINT nLevel = 0;
|
|
|
|
while (pLine)
|
|
|
|
{
|
|
|
|
if (IsBlock(pLine->eCommand)) nLevel++;
|
|
|
|
if (pLine->eCommand==eCommand)
|
|
|
|
{
|
|
|
|
if (nLevel == 0) return pLine->pNext;
|
|
|
|
}
|
|
|
|
if (pLine->eCommand == TOK_END)
|
|
|
|
{
|
|
|
|
if (nLevel)
|
|
|
|
nLevel--;
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
pLine = pLine->pNext;
|
|
|
|
}
|
|
|
|
return pLine;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Line* If(Line* pLine, BOOL bCondition)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Line* RunLine(Line* pLine)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
//#
|
|
|
|
//################
|
|
|
|
|
|
|
|
static VOID FreeLines(Line* pLine)
|
|
|
|
{
|
|
|
|
while (pLine)
|
|
|
|
{
|
|
|
|
Line* pThisLine = pLine;
|
|
|
|
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:24:30 +01:00
|
|
|
LocalFree((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:22:29 +01:00
|
|
|
LocalFree(pThisLine);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID FreeBlocks(Block* pBlock)
|
|
|
|
{
|
|
|
|
while (pBlock)
|
|
|
|
{
|
|
|
|
Block* pThisBlock = pBlock;
|
|
|
|
pBlock = pBlock->pNext;
|
|
|
|
FreeLines(pThisBlock->pFirstLine);
|
|
|
|
LocalFree(pThisBlock);
|
|
|
|
}
|
|
|
|
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: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;
|
|
|
|
UpdateWindowStatus();
|
|
|
|
ResizeWindow();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//################
|
|
|
|
//#
|
|
|
|
//# Extract Keyword's Parameters
|
|
|
|
//#
|
|
|
|
//################
|
|
|
|
|
2024-03-19 22:37:03 +01:00
|
|
|
static LPTSTR GetStringParam(Block* pBlock, TokenId eBlock, TokenId eCommand, UINT nParam)
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
|
|
|
while (pBlock)
|
|
|
|
{
|
|
|
|
if (pBlock->eType == eBlock)
|
|
|
|
{
|
|
|
|
Line* pLine = pBlock->pFirstLine;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static DWORD GetIntegerParam(Block* pBlock, TokenId eBlock, TokenId eCommand, UINT nParam)
|
|
|
|
{
|
|
|
|
while (pBlock)
|
|
|
|
{
|
|
|
|
if (pBlock->eType == eBlock)
|
|
|
|
{
|
|
|
|
Line* pLine = pBlock->pFirstLine;
|
|
|
|
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
|
|
|
|
else
|
|
|
|
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;
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
// x-columns of circle
|
|
|
|
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));
|
|
|
|
|
|
|
|
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;
|
|
|
|
Rect.left = x0;
|
|
|
|
Rect.right = x0 + pButton[nId].nCx;
|
|
|
|
Rect.top = y0;
|
|
|
|
Rect.bottom = y0 + 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;
|
|
|
|
Rect.left = x0;
|
|
|
|
Rect.right = x0 + pButton[nId].nCx;
|
|
|
|
Rect.top = y0;
|
|
|
|
Rect.bottom = y0 + 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
|
|
|
|
{
|
|
|
|
Line* pLine = pButton[nId].pOnDown;
|
|
|
|
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
|
|
|
|
{
|
|
|
|
Line* pLine = pButton[nId].pOnUp;
|
|
|
|
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 22:37:03 +01:00
|
|
|
VOID RefreshButtons(RECT *rc)
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
|
|
|
UINT i;
|
|
|
|
for (i=0; i<nButtons; i++)
|
|
|
|
{
|
2024-03-19 22:37:03 +01:00
|
|
|
if ( pButton[i].bDown
|
|
|
|
&& rc->right > (LONG) (pButton[i].nOx)
|
|
|
|
&& rc->bottom > (LONG) (pButton[i].nOy)
|
|
|
|
&& rc->left <= (LONG) (pButton[i].nOx + pButton[i].nCx)
|
|
|
|
&& 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:22:29 +01:00
|
|
|
if (nId>=6) 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)
|
|
|
|
{
|
|
|
|
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: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])
|
|
|
|
{
|
|
|
|
Line* pLine = pVKey[nId]->pFirstLine;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//################
|
|
|
|
//#
|
|
|
|
//# Load and Initialize Script
|
|
|
|
//#
|
|
|
|
//################
|
|
|
|
|
2024-03-19 22:37:03 +01:00
|
|
|
static Block* LoadKMLGlobal(LPCTSTR szFilename)
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
|
|
|
HANDLE hFile;
|
2024-03-19 22:37:03 +01:00
|
|
|
LPTSTR lpBuf;
|
2024-03-19 22:22:29 +01:00
|
|
|
Block* pBlock;
|
|
|
|
DWORD eToken;
|
|
|
|
|
|
|
|
SetCurrentDirectory(szEmu48Directory);
|
|
|
|
hFile = CreateFile(szFilename, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
|
|
|
|
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;
|
|
|
|
eToken = Lex(LEX_BLOCK);
|
|
|
|
if (eToken == TOK_GLOBAL)
|
|
|
|
{
|
|
|
|
pBlock = ParseBlock(eToken);
|
|
|
|
if (pBlock) pBlock->pNext = NULL;
|
|
|
|
}
|
|
|
|
CleanLex();
|
|
|
|
ClearLog();
|
|
|
|
LocalFree(lpBuf);
|
|
|
|
return pBlock;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-03-19 22:37:03 +01:00
|
|
|
BOOL InitKML(LPCTSTR szFilename, BOOL bNoLog)
|
2024-03-19 22:22:29 +01:00
|
|
|
{
|
|
|
|
HANDLE hFile;
|
2024-03-19 22:37:03 +01:00
|
|
|
LPTSTR lpBuf;
|
2024-03-19 22:22:29 +01:00
|
|
|
Block* pBlock;
|
2024-03-19 22:37:03 +01:00
|
|
|
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:22:29 +01:00
|
|
|
SetCurrentDirectory(szEmu48Directory);
|
|
|
|
hFile = CreateFile(szFilename, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
|
|
|
|
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();
|
|
|
|
|
|
|
|
LocalFree(lpBuf);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cCurrentRomType == 0)
|
|
|
|
{
|
2024-03-19 22:37:03 +01:00
|
|
|
AddToLog(_T("This KML Script doesn't specify the ROM Type."));
|
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;
|
|
|
|
}
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|