diff options
-rw-r--r-- | ldmicro/CMakeLists.txt | 31 | ||||
-rw-r--r-- | ldmicro/coildialog.cpp | 330 | ||||
-rw-r--r-- | ldmicro/commentdialog.cpp | 108 | ||||
-rw-r--r-- | ldmicro/confdialog.cpp | 12 | ||||
-rw-r--r-- | ldmicro/contactsdialog.cpp | 268 | ||||
-rw-r--r-- | ldmicro/draw.cpp | 1868 | ||||
-rw-r--r-- | ldmicro/helpdialog.cpp | 384 | ||||
-rw-r--r-- | ldmicro/includes/naminglist.h | 16 | ||||
-rw-r--r-- | ldmicro/lang.cpp | 2 | ||||
-rw-r--r-- | ldmicro/resetdialog.cpp | 214 | ||||
-rw-r--r-- | ldmicro/simpledialog.cpp | 740 | ||||
-rw-r--r-- | ldmicro/simulate.cpp | 1455 |
12 files changed, 2694 insertions, 2734 deletions
diff --git a/ldmicro/CMakeLists.txt b/ldmicro/CMakeLists.txt index 8c568fa..7abcaad 100644 --- a/ldmicro/CMakeLists.txt +++ b/ldmicro/CMakeLists.txt @@ -30,12 +30,12 @@ IF(UNIX) find_package (PkgConfig REQUIRED) pkg_check_modules (GTK3 REQUIRED gtk+-3.0) - # Version control + ## Version control set (LDMicro_VERSION_MAJOR 1) set (LDMicro_VERSION_MINOR 0) - # configure a header file to pass some of the CMake settings - # to the source code + ## configure a header file to pass some of the CMake settings + ## to the source code include_directories("${CMAKE_CURRENT_SOURCE_DIR}/lib/linuxUI") include_directories("${CMAKE_CURRENT_SOURCE_DIR}/lib/freezeLD") include_directories("${CMAKE_CURRENT_SOURCE_DIR}/includes") @@ -46,7 +46,7 @@ IF(UNIX) ) MESSAGE ( STATUS " PROJECT_INCLUDE_DIR: " ${PROJECT_INCLUDE_DIR} ) - # Add GTK3 include files if GTK3 is found + ## Add GTK3 include files if GTK3 is found IF ( GTK3_FOUND ) include_directories (${GTK3_INCLUDE_DIRS}) link_directories (${GTK3_LIBRARY_DIRS}) @@ -60,8 +60,7 @@ IF(UNIX) ## Dummy compile and install to test linuxUI ## to compile LDmicro uncomment the below 2 line2 - set (COMPILE_CPP_SOURCES #naminglist.cpp - arduino.cpp + set (COMPILE_CPP_SOURCES arduino.cpp avr.cpp pic16.cpp interpreted.cpp @@ -71,21 +70,21 @@ IF(UNIX) lang.cpp miscutil.cpp iolist.cpp - #confdialog.cpp - #lutdialog.cpp - #resetdialog.cpp - #simpledialog.cpp - #coildialog.cpp - #contactsdialog.cpp - #commentdialog.cpp - #simulate.cpp + confdialog.cpp + lutdialog.cpp + resetdialog.cpp + simpledialog.cpp + coildialog.cpp + contactsdialog.cpp + commentdialog.cpp + simulate.cpp loadsave.cpp undoredo.cpp circuit.cpp draw_outputdev.cpp - #draw.cpp + draw.cpp schematic.cpp - #helpdialog.cpp + helpdialog.cpp maincontrols.cpp ldmicro.cpp) diff --git a/ldmicro/coildialog.cpp b/ldmicro/coildialog.cpp index 070dd42..22fd10c 100644 --- a/ldmicro/coildialog.cpp +++ b/ldmicro/coildialog.cpp @@ -42,169 +42,169 @@ static LONG_PTR PrevNameProc; //----------------------------------------------------------------------------- // Don't allow any characters other than A-Za-z0-9_ in the name. //----------------------------------------------------------------------------- -static LRESULT CALLBACK MyNameProc(HWND hwnd, UINT msg, WPARAM wParam, - LPARAM lParam) -{ - if(msg == WM_CHAR) { - if(!(isalpha(wParam) || isdigit(wParam) || wParam == '_' || - wParam == '\b')) - { - return 0; - } - } - - return CallWindowProc((WNDPROC)PrevNameProc, hwnd, msg, wParam, lParam); -} - -static void MakeControls(void) -{ - HWND grouper = CreateWindowEx(0, WC_BUTTON, _("Type"), - WS_CHILD | BS_GROUPBOX | WS_VISIBLE | WS_TABSTOP, - 7, 3, 120, 105, CoilDialog, NULL, Instance, NULL); - NiceFont(grouper); - - NormalRadio = CreateWindowEx(0, WC_BUTTON, _("( ) Normal"), - WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE | WS_GROUP, - 16, 21, 100, 20, CoilDialog, NULL, Instance, NULL); - NiceFont(NormalRadio); - - NegatedRadio = CreateWindowEx(0, WC_BUTTON, _("(/) Negated"), - WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE, - 16, 41, 100, 20, CoilDialog, NULL, Instance, NULL); - NiceFont(NegatedRadio); - - SetOnlyRadio = CreateWindowEx(0, WC_BUTTON, _("(S) Set-Only"), - WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE, - 16, 61, 100, 20, CoilDialog, NULL, Instance, NULL); - NiceFont(SetOnlyRadio); - - ResetOnlyRadio = CreateWindowEx(0, WC_BUTTON, _("(R) Reset-Only"), - WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE, - 16, 81, 105, 20, CoilDialog, NULL, Instance, NULL); - NiceFont(ResetOnlyRadio); - - HWND grouper2 = CreateWindowEx(0, WC_BUTTON, _("Source"), - WS_CHILD | BS_GROUPBOX | WS_VISIBLE, - 140, 3, 120, 65, CoilDialog, NULL, Instance, NULL); - NiceFont(grouper2); - - SourceInternalRelayRadio = CreateWindowEx(0, WC_BUTTON, _("Internal Relay"), - WS_CHILD | BS_AUTORADIOBUTTON | WS_VISIBLE | WS_GROUP | WS_TABSTOP, - 149, 21, 100, 20, CoilDialog, NULL, Instance, NULL); - NiceFont(SourceInternalRelayRadio); - - SourceMcuPinRadio = CreateWindowEx(0, WC_BUTTON, _("Pin on MCU"), - WS_CHILD | BS_AUTORADIOBUTTON | WS_VISIBLE | WS_TABSTOP, - 149, 41, 100, 20, CoilDialog, NULL, Instance, NULL); - NiceFont(SourceMcuPinRadio); - - HWND textLabel = CreateWindowEx(0, WC_STATIC, _("Name:"), - WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | SS_RIGHT, - 135, 80, 50, 21, CoilDialog, NULL, Instance, NULL); - NiceFont(textLabel); - - NameTextbox = CreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT, "", - WS_CHILD | ES_AUTOHSCROLL | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE, - 190, 80, 155, 21, CoilDialog, NULL, Instance, NULL); - FixedFont(NameTextbox); - - OkButton = CreateWindowEx(0, WC_BUTTON, _("OK"), - WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE | BS_DEFPUSHBUTTON, - 276, 10, 70, 23, CoilDialog, NULL, Instance, NULL); - NiceFont(OkButton); - - CancelButton = CreateWindowEx(0, WC_BUTTON, _("Cancel"), - WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE, - 276, 40, 70, 23, CoilDialog, NULL, Instance, NULL); - NiceFont(CancelButton); - - PrevNameProc = SetWindowLongPtr(NameTextbox, GWLP_WNDPROC, - (LONG_PTR)MyNameProc); -} - -void ShowCoilDialog(BOOL *negated, BOOL *setOnly, BOOL *resetOnly, char *name) -{ - CoilDialog = CreateWindowClient(0, "LDmicroDialog", - _("Coil"), WS_OVERLAPPED | WS_SYSMENU, - 100, 100, 359, 115, NULL, NULL, Instance, NULL); - RECT r; - GetClientRect(CoilDialog, &r); - - MakeControls(); +// static LRESULT CALLBACK MyNameProc(HWND hwnd, UINT msg, WPARAM wParam, +// LPARAM lParam) +// { +// if(msg == WM_CHAR) { +// if(!(isalpha(wParam) || isdigit(wParam) || wParam == '_' || +// wParam == '\b')) +// { +// return 0; +// } +// } + +// return CallWindowProc((WNDPROC)PrevNameProc, hwnd, msg, wParam, lParam); +// } + +// static void MakeControls(void) +// { +// HWND grouper = CreateWindowEx(0, WC_BUTTON, _("Type"), +// WS_CHILD | BS_GROUPBOX | WS_VISIBLE | WS_TABSTOP, +// 7, 3, 120, 105, CoilDialog, NULL, Instance, NULL); +// NiceFont(grouper); + +// NormalRadio = CreateWindowEx(0, WC_BUTTON, _("( ) Normal"), +// WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE | WS_GROUP, +// 16, 21, 100, 20, CoilDialog, NULL, Instance, NULL); +// NiceFont(NormalRadio); + +// NegatedRadio = CreateWindowEx(0, WC_BUTTON, _("(/) Negated"), +// WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE, +// 16, 41, 100, 20, CoilDialog, NULL, Instance, NULL); +// NiceFont(NegatedRadio); + +// SetOnlyRadio = CreateWindowEx(0, WC_BUTTON, _("(S) Set-Only"), +// WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE, +// 16, 61, 100, 20, CoilDialog, NULL, Instance, NULL); +// NiceFont(SetOnlyRadio); + +// ResetOnlyRadio = CreateWindowEx(0, WC_BUTTON, _("(R) Reset-Only"), +// WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE, +// 16, 81, 105, 20, CoilDialog, NULL, Instance, NULL); +// NiceFont(ResetOnlyRadio); + +// HWND grouper2 = CreateWindowEx(0, WC_BUTTON, _("Source"), +// WS_CHILD | BS_GROUPBOX | WS_VISIBLE, +// 140, 3, 120, 65, CoilDialog, NULL, Instance, NULL); +// NiceFont(grouper2); + +// SourceInternalRelayRadio = CreateWindowEx(0, WC_BUTTON, _("Internal Relay"), +// WS_CHILD | BS_AUTORADIOBUTTON | WS_VISIBLE | WS_GROUP | WS_TABSTOP, +// 149, 21, 100, 20, CoilDialog, NULL, Instance, NULL); +// NiceFont(SourceInternalRelayRadio); + +// SourceMcuPinRadio = CreateWindowEx(0, WC_BUTTON, _("Pin on MCU"), +// WS_CHILD | BS_AUTORADIOBUTTON | WS_VISIBLE | WS_TABSTOP, +// 149, 41, 100, 20, CoilDialog, NULL, Instance, NULL); +// NiceFont(SourceMcuPinRadio); + +// HWND textLabel = CreateWindowEx(0, WC_STATIC, _("Name:"), +// WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | SS_RIGHT, +// 135, 80, 50, 21, CoilDialog, NULL, Instance, NULL); +// NiceFont(textLabel); + +// NameTextbox = CreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT, "", +// WS_CHILD | ES_AUTOHSCROLL | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE, +// 190, 80, 155, 21, CoilDialog, NULL, Instance, NULL); +// FixedFont(NameTextbox); + +// OkButton = CreateWindowEx(0, WC_BUTTON, _("OK"), +// WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE | BS_DEFPUSHBUTTON, +// 276, 10, 70, 23, CoilDialog, NULL, Instance, NULL); +// NiceFont(OkButton); + +// CancelButton = CreateWindowEx(0, WC_BUTTON, _("Cancel"), +// WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE, +// 276, 40, 70, 23, CoilDialog, NULL, Instance, NULL); +// NiceFont(CancelButton); + +// PrevNameProc = SetWindowLongPtr(NameTextbox, GWLP_WNDPROC, +// (LONG_PTR)MyNameProc); +// } + +// void ShowCoilDialog(BOOL *negated, BOOL *setOnly, BOOL *resetOnly, char *name) +// { +// CoilDialog = CreateWindowClient(0, "LDmicroDialog", +// _("Coil"), WS_OVERLAPPED | WS_SYSMENU, +// 100, 100, 359, 115, NULL, NULL, Instance, NULL); +// RECT r; +// GetClientRect(CoilDialog, &r); + +// MakeControls(); - if(name[0] == 'R') { - SendMessage(SourceInternalRelayRadio, BM_SETCHECK, BST_CHECKED, 0); - } else { - SendMessage(SourceMcuPinRadio, BM_SETCHECK, BST_CHECKED, 0); - } - SendMessage(NameTextbox, WM_SETTEXT, 0, (LPARAM)(name + 1)); - if(*negated) { - SendMessage(NegatedRadio, BM_SETCHECK, BST_CHECKED, 0); - } else if(*setOnly) { - SendMessage(SetOnlyRadio, BM_SETCHECK, BST_CHECKED, 0); - } else if(*resetOnly) { - SendMessage(ResetOnlyRadio, BM_SETCHECK, BST_CHECKED, 0); - } else { - SendMessage(NormalRadio, BM_SETCHECK, BST_CHECKED, 0); - } - - EnableWindow(MainWindow, FALSE); - ShowWindow(CoilDialog, TRUE); - SetFocus(NameTextbox); - SendMessage(NameTextbox, EM_SETSEL, 0, -1); - - MSG msg; - DWORD ret; - DialogDone = FALSE; - DialogCancel = FALSE; - while((ret = GetMessage(&msg, NULL, 0, 0)) && !DialogDone) { - if(msg.message == WM_KEYDOWN) { - if(msg.wParam == VK_RETURN) { - DialogDone = TRUE; - break; - } else if(msg.wParam == VK_ESCAPE) { - DialogDone = TRUE; - DialogCancel = TRUE; - break; - } - } - - if(IsDialogMessage(CoilDialog, &msg)) continue; - TranslateMessage(&msg); - DispatchMessage(&msg); - } - - if(!DialogCancel) { - if(SendMessage(SourceInternalRelayRadio, BM_GETSTATE, 0, 0) - & BST_CHECKED) - { - name[0] = 'R'; - } else { - name[0] = 'Y'; - } - SendMessage(NameTextbox, WM_GETTEXT, (WPARAM)16, (LPARAM)(name+1)); - - if(SendMessage(NormalRadio, BM_GETSTATE, 0, 0) & BST_CHECKED) { - *negated = FALSE; - *setOnly = FALSE; - *resetOnly = FALSE; - } else if(SendMessage(NegatedRadio, BM_GETSTATE, 0, 0) & BST_CHECKED) { - *negated = TRUE; - *setOnly = FALSE; - *resetOnly = FALSE; - } else if(SendMessage(SetOnlyRadio, BM_GETSTATE, 0, 0) & BST_CHECKED) { - *negated = FALSE; - *setOnly = TRUE; - *resetOnly = FALSE; - } else if(SendMessage(ResetOnlyRadio, BM_GETSTATE, 0, 0) & BST_CHECKED) - { - *negated = FALSE; - *setOnly = FALSE; - *resetOnly = TRUE; - } - } - - EnableWindow(MainWindow, TRUE); - DestroyWindow(CoilDialog); - return; -} +// if(name[0] == 'R') { +// SendMessage(SourceInternalRelayRadio, BM_SETCHECK, BST_CHECKED, 0); +// } else { +// SendMessage(SourceMcuPinRadio, BM_SETCHECK, BST_CHECKED, 0); +// } +// SendMessage(NameTextbox, WM_SETTEXT, 0, (LPARAM)(name + 1)); +// if(*negated) { +// SendMessage(NegatedRadio, BM_SETCHECK, BST_CHECKED, 0); +// } else if(*setOnly) { +// SendMessage(SetOnlyRadio, BM_SETCHECK, BST_CHECKED, 0); +// } else if(*resetOnly) { +// SendMessage(ResetOnlyRadio, BM_SETCHECK, BST_CHECKED, 0); +// } else { +// SendMessage(NormalRadio, BM_SETCHECK, BST_CHECKED, 0); +// } + +// EnableWindow(MainWindow, FALSE); +// ShowWindow(CoilDialog, TRUE); +// SetFocus(NameTextbox); +// SendMessage(NameTextbox, EM_SETSEL, 0, -1); + +// MSG msg; +// DWORD ret; +// DialogDone = FALSE; +// DialogCancel = FALSE; +// while((ret = GetMessage(&msg, NULL, 0, 0)) && !DialogDone) { +// if(msg.message == WM_KEYDOWN) { +// if(msg.wParam == VK_RETURN) { +// DialogDone = TRUE; +// break; +// } else if(msg.wParam == VK_ESCAPE) { +// DialogDone = TRUE; +// DialogCancel = TRUE; +// break; +// } +// } + +// if(IsDialogMessage(CoilDialog, &msg)) continue; +// TranslateMessage(&msg); +// DispatchMessage(&msg); +// } + +// if(!DialogCancel) { +// if(SendMessage(SourceInternalRelayRadio, BM_GETSTATE, 0, 0) +// & BST_CHECKED) +// { +// name[0] = 'R'; +// } else { +// name[0] = 'Y'; +// } +// SendMessage(NameTextbox, WM_GETTEXT, (WPARAM)16, (LPARAM)(name+1)); + +// if(SendMessage(NormalRadio, BM_GETSTATE, 0, 0) & BST_CHECKED) { +// *negated = FALSE; +// *setOnly = FALSE; +// *resetOnly = FALSE; +// } else if(SendMessage(NegatedRadio, BM_GETSTATE, 0, 0) & BST_CHECKED) { +// *negated = TRUE; +// *setOnly = FALSE; +// *resetOnly = FALSE; +// } else if(SendMessage(SetOnlyRadio, BM_GETSTATE, 0, 0) & BST_CHECKED) { +// *negated = FALSE; +// *setOnly = TRUE; +// *resetOnly = FALSE; +// } else if(SendMessage(ResetOnlyRadio, BM_GETSTATE, 0, 0) & BST_CHECKED) +// { +// *negated = FALSE; +// *setOnly = FALSE; +// *resetOnly = TRUE; +// } +// } + +// EnableWindow(MainWindow, TRUE); +// DestroyWindow(CoilDialog); +// return; +// } diff --git a/ldmicro/commentdialog.cpp b/ldmicro/commentdialog.cpp index 4cfe13b..9bea08d 100644 --- a/ldmicro/commentdialog.cpp +++ b/ldmicro/commentdialog.cpp @@ -31,67 +31,67 @@ static HWND CommentDialog; static HWND CommentTextbox; -static void MakeControls(void) -{ - CommentTextbox = CreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT, "", - WS_CHILD | ES_AUTOHSCROLL | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE | - ES_MULTILINE | ES_WANTRETURN, - 7, 10, 600, 38, CommentDialog, NULL, Instance, NULL); - FixedFont(CommentTextbox); +// static void MakeControls(void) +// { +// CommentTextbox = CreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT, "", +// WS_CHILD | ES_AUTOHSCROLL | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE | +// ES_MULTILINE | ES_WANTRETURN, +// 7, 10, 600, 38, CommentDialog, NULL, Instance, NULL); +// FixedFont(CommentTextbox); - OkButton = CreateWindowEx(0, WC_BUTTON, _("OK"), - WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE | BS_DEFPUSHBUTTON, - 620, 6, 70, 23, CommentDialog, NULL, Instance, NULL); - NiceFont(OkButton); +// OkButton = CreateWindowEx(0, WC_BUTTON, _("OK"), +// WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE | BS_DEFPUSHBUTTON, +// 620, 6, 70, 23, CommentDialog, NULL, Instance, NULL); +// NiceFont(OkButton); - CancelButton = CreateWindowEx(0, WC_BUTTON, _("Cancel"), - WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE, - 620, 36, 70, 23, CommentDialog, NULL, Instance, NULL); - NiceFont(CancelButton); -} +// CancelButton = CreateWindowEx(0, WC_BUTTON, _("Cancel"), +// WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE, +// 620, 36, 70, 23, CommentDialog, NULL, Instance, NULL); +// NiceFont(CancelButton); +// } -void ShowCommentDialog(char *comment) -{ - CommentDialog = CreateWindowClient(0, "LDmicroDialog", - _("Comment"), WS_OVERLAPPED | WS_SYSMENU, - 100, 100, 700, 65, NULL, NULL, Instance, NULL); +// void ShowCommentDialog(char *comment) +// { +// CommentDialog = CreateWindowClient(0, "LDmicroDialog", +// _("Comment"), WS_OVERLAPPED | WS_SYSMENU, +// 100, 100, 700, 65, NULL, NULL, Instance, NULL); - MakeControls(); +// MakeControls(); - SendMessage(CommentTextbox, WM_SETTEXT, 0, (LPARAM)comment); +// SendMessage(CommentTextbox, WM_SETTEXT, 0, (LPARAM)comment); - EnableWindow(MainWindow, FALSE); - ShowWindow(CommentDialog, TRUE); - SetFocus(CommentTextbox); - SendMessage(CommentTextbox, EM_SETSEL, 0, -1); +// EnableWindow(MainWindow, FALSE); +// ShowWindow(CommentDialog, TRUE); +// SetFocus(CommentTextbox); +// SendMessage(CommentTextbox, EM_SETSEL, 0, -1); - MSG msg; - DWORD ret; - DialogDone = FALSE; - DialogCancel = FALSE; - while((ret = GetMessage(&msg, NULL, 0, 0)) && !DialogDone) { - if(msg.message == WM_KEYDOWN) { - if(msg.wParam == VK_TAB && GetFocus() == CommentTextbox) { - SetFocus(OkButton); - continue; - } else if(msg.wParam == VK_ESCAPE) { - DialogDone = TRUE; - DialogCancel = TRUE; - break; - } - } +// MSG msg; +// DWORD ret; +// DialogDone = FALSE; +// DialogCancel = FALSE; +// while((ret = GetMessage(&msg, NULL, 0, 0)) && !DialogDone) { +// if(msg.message == WM_KEYDOWN) { +// if(msg.wParam == VK_TAB && GetFocus() == CommentTextbox) { +// SetFocus(OkButton); +// continue; +// } else if(msg.wParam == VK_ESCAPE) { +// DialogDone = TRUE; +// DialogCancel = TRUE; +// break; +// } +// } - if(IsDialogMessage(CommentDialog, &msg)) continue; - TranslateMessage(&msg); - DispatchMessage(&msg); - } +// if(IsDialogMessage(CommentDialog, &msg)) continue; +// TranslateMessage(&msg); +// DispatchMessage(&msg); +// } - if(!DialogCancel) { - SendMessage(CommentTextbox, WM_GETTEXT, (WPARAM)(MAX_COMMENT_LEN-1), - (LPARAM)comment); - } +// if(!DialogCancel) { +// SendMessage(CommentTextbox, WM_GETTEXT, (WPARAM)(MAX_COMMENT_LEN-1), +// (LPARAM)comment); +// } - EnableWindow(MainWindow, TRUE); - DestroyWindow(CommentDialog); - return; -} +// EnableWindow(MainWindow, TRUE); +// DestroyWindow(CommentDialog); +// return; +// } diff --git a/ldmicro/confdialog.cpp b/ldmicro/confdialog.cpp index 1b77fd0..f908893 100644 --- a/ldmicro/confdialog.cpp +++ b/ldmicro/confdialog.cpp @@ -64,8 +64,8 @@ static LONG_PTR PrevBaudProc; // return CallWindowProc((WNDPROC)t, hwnd, msg, wParam, lParam); // } -// static void MakeControls(void) -// { +static void MakeControls(void) +{ // HWND textLabel = CreateWindowEx(0, WC_STATIC, _("Cycle Time (ms):"), // WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | SS_RIGHT, // 5, 13, 145, 21, ConfDialog, NULL, Instance, NULL); @@ -178,10 +178,10 @@ static LONG_PTR PrevBaudProc; // PrevBaudProc = SetWindowLongPtr(BaudTextbox, GWLP_WNDPROC, // (LONG_PTR)MyNumberProc); -// } +} -// void ShowConfDialog(void) -// { +void ShowConfDialog(void) +{ // // The window's height will be resized later, to fit the explanation text. // ConfDialog = CreateWindowClient(0, "LDmicroDialog", _("PLC Configuration"), // WS_OVERLAPPED | WS_SYSMENU, @@ -246,4 +246,4 @@ static LONG_PTR PrevBaudProc; // EnableWindow(MainWindow, TRUE); // DestroyWindow(ConfDialog); // return; -// } +} diff --git a/ldmicro/contactsdialog.cpp b/ldmicro/contactsdialog.cpp index fe2922c..a845220 100644 --- a/ldmicro/contactsdialog.cpp +++ b/ldmicro/contactsdialog.cpp @@ -40,138 +40,138 @@ static LONG_PTR PrevNameProc; //----------------------------------------------------------------------------- // Don't allow any characters other than A-Za-z0-9_ in the name. //----------------------------------------------------------------------------- -static LRESULT CALLBACK MyNameProc(HWND hwnd, UINT msg, WPARAM wParam, - LPARAM lParam) -{ - if(msg == WM_CHAR) { - if(!(isalpha(wParam) || isdigit(wParam) || wParam == '_' || - wParam == '\b')) - { - return 0; - } - } - - return CallWindowProc((WNDPROC)PrevNameProc, hwnd, msg, wParam, lParam); -} - -static void MakeControls(void) -{ - HWND grouper = CreateWindowEx(0, WC_BUTTON, _("Source"), - WS_CHILD | BS_GROUPBOX | WS_VISIBLE, - 7, 3, 120, 85, ContactsDialog, NULL, Instance, NULL); - NiceFont(grouper); - - SourceInternalRelayRadio = CreateWindowEx(0, WC_BUTTON, _("Internal Relay"), - WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE, - 16, 21, 100, 20, ContactsDialog, NULL, Instance, NULL); - NiceFont(SourceInternalRelayRadio); - - SourceInputPinRadio = CreateWindowEx(0, WC_BUTTON, _("Input pin"), - WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE, - 16, 41, 100, 20, ContactsDialog, NULL, Instance, NULL); - NiceFont(SourceInputPinRadio); - - SourceOutputPinRadio = CreateWindowEx(0, WC_BUTTON, _("Output pin"), - WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE, - 16, 61, 100, 20, ContactsDialog, NULL, Instance, NULL); - NiceFont(SourceOutputPinRadio); - - HWND textLabel = CreateWindowEx(0, WC_STATIC, _("Name:"), - WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | SS_RIGHT, - 135, 16, 50, 21, ContactsDialog, NULL, Instance, NULL); - NiceFont(textLabel); - - NameTextbox = CreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT, "", - WS_CHILD | ES_AUTOHSCROLL | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE, - 190, 16, 115, 21, ContactsDialog, NULL, Instance, NULL); - FixedFont(NameTextbox); - - NegatedCheckbox = CreateWindowEx(0, WC_BUTTON, _("|/| Negated"), - WS_CHILD | BS_AUTOCHECKBOX | WS_TABSTOP | WS_VISIBLE, - 146, 44, 160, 20, ContactsDialog, NULL, Instance, NULL); - NiceFont(NegatedCheckbox); - - OkButton = CreateWindowEx(0, WC_BUTTON, _("OK"), - WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE | BS_DEFPUSHBUTTON, - 321, 10, 70, 23, ContactsDialog, NULL, Instance, NULL); - NiceFont(OkButton); - - CancelButton = CreateWindowEx(0, WC_BUTTON, _("Cancel"), - WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE, - 321, 40, 70, 23, ContactsDialog, NULL, Instance, NULL); - NiceFont(CancelButton); - - PrevNameProc = SetWindowLongPtr(NameTextbox, GWLP_WNDPROC, - (LONG_PTR)MyNameProc); -} - -void ShowContactsDialog(BOOL *negated, char *name) -{ - ContactsDialog = CreateWindowClient(0, "LDmicroDialog", - _("Contacts"), WS_OVERLAPPED | WS_SYSMENU, - 100, 100, 404, 95, NULL, NULL, Instance, NULL); - - MakeControls(); +// static LRESULT CALLBACK MyNameProc(HWND hwnd, UINT msg, WPARAM wParam, +// LPARAM lParam) +// { +// if(msg == WM_CHAR) { +// if(!(isalpha(wParam) || isdigit(wParam) || wParam == '_' || +// wParam == '\b')) +// { +// return 0; +// } +// } + +// return CallWindowProc((WNDPROC)PrevNameProc, hwnd, msg, wParam, lParam); +// } + +// static void MakeControls(void) +// { +// HWND grouper = CreateWindowEx(0, WC_BUTTON, _("Source"), +// WS_CHILD | BS_GROUPBOX | WS_VISIBLE, +// 7, 3, 120, 85, ContactsDialog, NULL, Instance, NULL); +// NiceFont(grouper); + +// SourceInternalRelayRadio = CreateWindowEx(0, WC_BUTTON, _("Internal Relay"), +// WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE, +// 16, 21, 100, 20, ContactsDialog, NULL, Instance, NULL); +// NiceFont(SourceInternalRelayRadio); + +// SourceInputPinRadio = CreateWindowEx(0, WC_BUTTON, _("Input pin"), +// WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE, +// 16, 41, 100, 20, ContactsDialog, NULL, Instance, NULL); +// NiceFont(SourceInputPinRadio); + +// SourceOutputPinRadio = CreateWindowEx(0, WC_BUTTON, _("Output pin"), +// WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE, +// 16, 61, 100, 20, ContactsDialog, NULL, Instance, NULL); +// NiceFont(SourceOutputPinRadio); + +// HWND textLabel = CreateWindowEx(0, WC_STATIC, _("Name:"), +// WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | SS_RIGHT, +// 135, 16, 50, 21, ContactsDialog, NULL, Instance, NULL); +// NiceFont(textLabel); + +// NameTextbox = CreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT, "", +// WS_CHILD | ES_AUTOHSCROLL | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE, +// 190, 16, 115, 21, ContactsDialog, NULL, Instance, NULL); +// FixedFont(NameTextbox); + +// NegatedCheckbox = CreateWindowEx(0, WC_BUTTON, _("|/| Negated"), +// WS_CHILD | BS_AUTOCHECKBOX | WS_TABSTOP | WS_VISIBLE, +// 146, 44, 160, 20, ContactsDialog, NULL, Instance, NULL); +// NiceFont(NegatedCheckbox); + +// OkButton = CreateWindowEx(0, WC_BUTTON, _("OK"), +// WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE | BS_DEFPUSHBUTTON, +// 321, 10, 70, 23, ContactsDialog, NULL, Instance, NULL); +// NiceFont(OkButton); + +// CancelButton = CreateWindowEx(0, WC_BUTTON, _("Cancel"), +// WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE, +// 321, 40, 70, 23, ContactsDialog, NULL, Instance, NULL); +// NiceFont(CancelButton); + +// PrevNameProc = SetWindowLongPtr(NameTextbox, GWLP_WNDPROC, +// (LONG_PTR)MyNameProc); +// } + +// void ShowContactsDialog(BOOL *negated, char *name) +// { +// ContactsDialog = CreateWindowClient(0, "LDmicroDialog", +// _("Contacts"), WS_OVERLAPPED | WS_SYSMENU, +// 100, 100, 404, 95, NULL, NULL, Instance, NULL); + +// MakeControls(); - if(name[0] == 'R') { - SendMessage(SourceInternalRelayRadio, BM_SETCHECK, BST_CHECKED, 0); - } else if(name[0] == 'Y') { - SendMessage(SourceOutputPinRadio, BM_SETCHECK, BST_CHECKED, 0); - } else { - SendMessage(SourceInputPinRadio, BM_SETCHECK, BST_CHECKED, 0); - } - if(*negated) { - SendMessage(NegatedCheckbox, BM_SETCHECK, BST_CHECKED, 0); - } - SendMessage(NameTextbox, WM_SETTEXT, 0, (LPARAM)(name + 1)); - - EnableWindow(MainWindow, FALSE); - ShowWindow(ContactsDialog, TRUE); - SetFocus(NameTextbox); - SendMessage(NameTextbox, EM_SETSEL, 0, -1); - - MSG msg; - DWORD ret; - DialogDone = FALSE; - DialogCancel = FALSE; - while((ret = GetMessage(&msg, NULL, 0, 0)) && !DialogDone) { - if(msg.message == WM_KEYDOWN) { - if(msg.wParam == VK_RETURN) { - DialogDone = TRUE; - break; - } else if(msg.wParam == VK_ESCAPE) { - DialogDone = TRUE; - DialogCancel = TRUE; - break; - } - } - - if(IsDialogMessage(ContactsDialog, &msg)) continue; - TranslateMessage(&msg); - DispatchMessage(&msg); - } - - if(!DialogCancel) { - if(SendMessage(NegatedCheckbox, BM_GETSTATE, 0, 0) & BST_CHECKED) { - *negated = TRUE; - } else { - *negated = FALSE; - } - if(SendMessage(SourceInternalRelayRadio, BM_GETSTATE, 0, 0) - & BST_CHECKED) - { - name[0] = 'R'; - } else if(SendMessage(SourceInputPinRadio, BM_GETSTATE, 0, 0) - & BST_CHECKED) - { - name[0] = 'X'; - } else { - name[0] = 'Y'; - } - SendMessage(NameTextbox, WM_GETTEXT, (WPARAM)16, (LPARAM)(name+1)); - } - - EnableWindow(MainWindow, TRUE); - DestroyWindow(ContactsDialog); - return; -} +// if(name[0] == 'R') { +// SendMessage(SourceInternalRelayRadio, BM_SETCHECK, BST_CHECKED, 0); +// } else if(name[0] == 'Y') { +// SendMessage(SourceOutputPinRadio, BM_SETCHECK, BST_CHECKED, 0); +// } else { +// SendMessage(SourceInputPinRadio, BM_SETCHECK, BST_CHECKED, 0); +// } +// if(*negated) { +// SendMessage(NegatedCheckbox, BM_SETCHECK, BST_CHECKED, 0); +// } +// SendMessage(NameTextbox, WM_SETTEXT, 0, (LPARAM)(name + 1)); + +// EnableWindow(MainWindow, FALSE); +// ShowWindow(ContactsDialog, TRUE); +// SetFocus(NameTextbox); +// SendMessage(NameTextbox, EM_SETSEL, 0, -1); + +// MSG msg; +// DWORD ret; +// DialogDone = FALSE; +// DialogCancel = FALSE; +// while((ret = GetMessage(&msg, NULL, 0, 0)) && !DialogDone) { +// if(msg.message == WM_KEYDOWN) { +// if(msg.wParam == VK_RETURN) { +// DialogDone = TRUE; +// break; +// } else if(msg.wParam == VK_ESCAPE) { +// DialogDone = TRUE; +// DialogCancel = TRUE; +// break; +// } +// } + +// if(IsDialogMessage(ContactsDialog, &msg)) continue; +// TranslateMessage(&msg); +// DispatchMessage(&msg); +// } + +// if(!DialogCancel) { +// if(SendMessage(NegatedCheckbox, BM_GETSTATE, 0, 0) & BST_CHECKED) { +// *negated = TRUE; +// } else { +// *negated = FALSE; +// } +// if(SendMessage(SourceInternalRelayRadio, BM_GETSTATE, 0, 0) +// & BST_CHECKED) +// { +// name[0] = 'R'; +// } else if(SendMessage(SourceInputPinRadio, BM_GETSTATE, 0, 0) +// & BST_CHECKED) +// { +// name[0] = 'X'; +// } else { +// name[0] = 'Y'; +// } +// SendMessage(NameTextbox, WM_GETTEXT, (WPARAM)16, (LPARAM)(name+1)); +// } + +// EnableWindow(MainWindow, TRUE); +// DestroyWindow(ContactsDialog); +// return; +// } diff --git a/ldmicro/draw.cpp b/ldmicro/draw.cpp index 75fcf54..f08e34c 100644 --- a/ldmicro/draw.cpp +++ b/ldmicro/draw.cpp @@ -55,19 +55,19 @@ BOOL ThisHighlighted; // warn the user and undo their changes if they created something too wide. // This is not very clean. //----------------------------------------------------------------------------- -static BOOL CheckBoundsUndoIfFails(int gx, int gy) -{ - if(gx >= DISPLAY_MATRIX_X_SIZE || gx < 0 || - gy >= DISPLAY_MATRIX_Y_SIZE || gy < 0) - { - if(CanUndo()) { - UndoUndo(); - Error(_("Too many elements in subcircuit!")); - return TRUE; - } - } - return FALSE; -} +// static BOOL CheckBoundsUndoIfFails(int gx, int gy) +// { +// if(gx >= DISPLAY_MATRIX_X_SIZE || gx < 0 || +// gy >= DISPLAY_MATRIX_Y_SIZE || gy < 0) +// { +// if(CanUndo()) { +// UndoUndo(); +// Error(_("Too many elements in subcircuit!")); +// return TRUE; +// } +// } +// return FALSE; +// } //----------------------------------------------------------------------------- // Determine the width, in leaf element units, of a particular subcircuit. @@ -75,111 +75,111 @@ static BOOL CheckBoundsUndoIfFails(int gx, int gy) // of the widths of its members, and the width of a parallel circuit is // the maximum of the widths of its members. //----------------------------------------------------------------------------- -static int CountWidthOfElement(int which, void *elem, int soFar) -{ - switch(which) { - case ELEM_PLACEHOLDER: - case ELEM_OPEN: - case ELEM_SHORT: - case ELEM_CONTACTS: - case ELEM_TON: - case ELEM_TOF: - case ELEM_RTO: - case ELEM_CTU: - case ELEM_CTD: - case ELEM_ONE_SHOT_RISING: - case ELEM_ONE_SHOT_FALLING: - case ELEM_EQU: - case ELEM_NEQ: - case ELEM_GRT: - case ELEM_GEQ: - case ELEM_LES: - case ELEM_LEQ: - case ELEM_UART_RECV: - case ELEM_UART_SEND: - return 1; - - case ELEM_FORMATTED_STRING: - return 2; - - case ELEM_COMMENT: { - if(soFar != 0) oops(); - - ElemLeaf *l = (ElemLeaf *)elem; - char tbuf[MAX_COMMENT_LEN]; - - strcpy(tbuf, l->d.comment.str); - char *b = strchr(tbuf, '\n'); - - int len; - if(b) { - *b = '\0'; - len = max(strlen(tbuf)-1, strlen(b+1)); - } else { - len = strlen(tbuf); - } - // round up, and allow space for lead-in - len = (len + 7 + (POS_WIDTH-1)) / POS_WIDTH; - return max(ColsAvailable, len); - } - case ELEM_CTC: - case ELEM_RES: - case ELEM_COIL: - case ELEM_MOVE: - case ELEM_SHIFT_REGISTER: - case ELEM_LOOK_UP_TABLE: - case ELEM_PIECEWISE_LINEAR: - case ELEM_MASTER_RELAY: - case ELEM_READ_ADC: - case ELEM_SET_PWM: - case ELEM_PERSIST: - if(ColsAvailable - soFar > 1) { - return ColsAvailable - soFar; - } else { - return 1; - } - - case ELEM_ADD: - case ELEM_SUB: - case ELEM_MUL: - case ELEM_DIV: - if(ColsAvailable - soFar > 2) { - return ColsAvailable - soFar; - } else { - return 2; - } - - case ELEM_SERIES_SUBCKT: { - // total of the width of the members - int total = 0; - int i; - ElemSubcktSeries *s = (ElemSubcktSeries *)elem; - for(i = 0; i < s->count; i++) { - total += CountWidthOfElement(s->contents[i].which, - s->contents[i].d.any, total+soFar); - } - return total; - } - - case ELEM_PARALLEL_SUBCKT: { - // greatest of the width of the members - int max = 0; - int i; - ElemSubcktParallel *p = (ElemSubcktParallel *)elem; - for(i = 0; i < p->count; i++) { - int w = CountWidthOfElement(p->contents[i].which, - p->contents[i].d.any, soFar); - if(w > max) { - max = w; - } - } - return max; - } - - default: - oops(); - } -} +// static int CountWidthOfElement(int which, void *elem, int soFar) +// { +// switch(which) { +// case ELEM_PLACEHOLDER: +// case ELEM_OPEN: +// case ELEM_SHORT: +// case ELEM_CONTACTS: +// case ELEM_TON: +// case ELEM_TOF: +// case ELEM_RTO: +// case ELEM_CTU: +// case ELEM_CTD: +// case ELEM_ONE_SHOT_RISING: +// case ELEM_ONE_SHOT_FALLING: +// case ELEM_EQU: +// case ELEM_NEQ: +// case ELEM_GRT: +// case ELEM_GEQ: +// case ELEM_LES: +// case ELEM_LEQ: +// case ELEM_UART_RECV: +// case ELEM_UART_SEND: +// return 1; + +// case ELEM_FORMATTED_STRING: +// return 2; + +// case ELEM_COMMENT: { +// if(soFar != 0) oops(); + +// ElemLeaf *l = (ElemLeaf *)elem; +// char tbuf[MAX_COMMENT_LEN]; + +// strcpy(tbuf, l->d.comment.str); +// char *b = strchr(tbuf, '\n'); + +// int len; +// if(b) { +// *b = '\0'; +// len = max(strlen(tbuf)-1, strlen(b+1)); +// } else { +// len = strlen(tbuf); +// } +// // round up, and allow space for lead-in +// len = (len + 7 + (POS_WIDTH-1)) / POS_WIDTH; +// return max(ColsAvailable, len); +// } +// case ELEM_CTC: +// case ELEM_RES: +// case ELEM_COIL: +// case ELEM_MOVE: +// case ELEM_SHIFT_REGISTER: +// case ELEM_LOOK_UP_TABLE: +// case ELEM_PIECEWISE_LINEAR: +// case ELEM_MASTER_RELAY: +// case ELEM_READ_ADC: +// case ELEM_SET_PWM: +// case ELEM_PERSIST: +// if(ColsAvailable - soFar > 1) { +// return ColsAvailable - soFar; +// } else { +// return 1; +// } + +// case ELEM_ADD: +// case ELEM_SUB: +// case ELEM_MUL: +// case ELEM_DIV: +// if(ColsAvailable - soFar > 2) { +// return ColsAvailable - soFar; +// } else { +// return 2; +// } + +// case ELEM_SERIES_SUBCKT: { +// // total of the width of the members +// int total = 0; +// int i; +// ElemSubcktSeries *s = (ElemSubcktSeries *)elem; +// for(i = 0; i < s->count; i++) { +// total += CountWidthOfElement(s->contents[i].which, +// s->contents[i].d.any, total+soFar); +// } +// return total; +// } + +// case ELEM_PARALLEL_SUBCKT: { +// // greatest of the width of the members +// int max = 0; +// int i; +// ElemSubcktParallel *p = (ElemSubcktParallel *)elem; +// for(i = 0; i < p->count; i++) { +// int w = CountWidthOfElement(p->contents[i].which, +// p->contents[i].d.any, soFar); +// if(w > max) { +// max = w; +// } +// } +// return max; +// } + +// default: +// oops(); +// } +// } //----------------------------------------------------------------------------- // Determine the height, in leaf element units, of a particular subcircuit. @@ -188,729 +188,733 @@ static int CountWidthOfElement(int which, void *elem, int soFar) // maximum of the heights of its members. (This is the dual of the width // case.) //----------------------------------------------------------------------------- -int CountHeightOfElement(int which, void *elem) -{ - switch(which) { - CASE_LEAF - return 1; - - case ELEM_PARALLEL_SUBCKT: { - // total of the height of the members - int total = 0; - int i; - ElemSubcktParallel *s = (ElemSubcktParallel *)elem; - for(i = 0; i < s->count; i++) { - total += CountHeightOfElement(s->contents[i].which, - s->contents[i].d.any); - } - return total; - } - - case ELEM_SERIES_SUBCKT: { - // greatest of the height of the members - int max = 0; - int i; - ElemSubcktSeries *s = (ElemSubcktSeries *)elem; - for(i = 0; i < s->count; i++) { - int w = CountHeightOfElement(s->contents[i].which, - s->contents[i].d.any); - if(w > max) { - max = w; - } - } - return max; - } - - default: - oops(); - } -} +// int CountHeightOfElement(int which, void *elem) +// { +// switch(which) { +// CASE_LEAF +// return 1; + +// case ELEM_PARALLEL_SUBCKT: { +// // total of the height of the members +// int total = 0; +// int i; +// ElemSubcktParallel *s = (ElemSubcktParallel *)elem; +// for(i = 0; i < s->count; i++) { +// total += CountHeightOfElement(s->contents[i].which, +// s->contents[i].d.any); +// } +// return total; +// } + +// case ELEM_SERIES_SUBCKT: { +// // greatest of the height of the members +// int max = 0; +// int i; +// ElemSubcktSeries *s = (ElemSubcktSeries *)elem; +// for(i = 0; i < s->count; i++) { +// int w = CountHeightOfElement(s->contents[i].which, +// s->contents[i].d.any); +// if(w > max) { +// max = w; +// } +// } +// return max; +// } + +// default: +// oops(); +// } +// } //----------------------------------------------------------------------------- // Determine the width, in leaf element units, of the widest row of the PLC // program (i.e. loop over all the rungs and find the widest). //----------------------------------------------------------------------------- -int ProgCountWidestRow(void) -{ - int i; - int max = 0; - int colsTemp = ColsAvailable; - ColsAvailable = 0; - for(i = 0; i < Prog.numRungs; i++) { - int w = CountWidthOfElement(ELEM_SERIES_SUBCKT, Prog.rungs[i], 0); - if(w > max) { - max = w; - } - } - ColsAvailable = colsTemp; - return max; -} +// int ProgCountWidestRow(void) +// { +// int i; +// int max = 0; +// int colsTemp = ColsAvailable; +// ColsAvailable = 0; +// for(i = 0; i < Prog.numRungs; i++) { +// int w = CountWidthOfElement(ELEM_SERIES_SUBCKT, Prog.rungs[i], 0); +// if(w > max) { +// max = w; +// } +// } +// ColsAvailable = colsTemp; +// return max; +// } //----------------------------------------------------------------------------- // Draw a vertical wire one leaf element unit high up from (cx, cy), where cx // and cy are in charcter units. //----------------------------------------------------------------------------- -static void VerticalWire(int cx, int cy) -{ - int j; - for(j = 1; j < POS_HEIGHT; j++) { - DrawChars(cx, cy + (POS_HEIGHT/2 - j), "|"); - } - DrawChars(cx, cy + (POS_HEIGHT/2), "+"); - DrawChars(cx, cy + (POS_HEIGHT/2 - POS_HEIGHT), "+"); -} +// static void VerticalWire(int cx, int cy) +// { +// int j; +// for(j = 1; j < POS_HEIGHT; j++) { +// DrawChars(cx, cy + (POS_HEIGHT/2 - j), "|"); +// } +// DrawChars(cx, cy + (POS_HEIGHT/2), "+"); +// DrawChars(cx, cy + (POS_HEIGHT/2 - POS_HEIGHT), "+"); +// } //----------------------------------------------------------------------------- // Convenience functions for making the text colors pretty, for DrawElement. //----------------------------------------------------------------------------- -static void NormText(void) -{ - SetTextColor(Hdc, InSimulationMode ? HighlightColours.simOff : - HighlightColours.def); - SelectObject(Hdc, FixedWidthFont); -} -static void EmphText(void) -{ - SetTextColor(Hdc, InSimulationMode ? HighlightColours.simOn : - HighlightColours.selected); - SelectObject(Hdc, FixedWidthFontBold); -} -static void NameText(void) -{ - if(!InSimulationMode && !ThisHighlighted) { - SetTextColor(Hdc, HighlightColours.name); - } -} -static void BodyText(void) -{ - if(!InSimulationMode && !ThisHighlighted) { - SetTextColor(Hdc, HighlightColours.def); - } -} -static void PoweredText(BOOL powered) -{ - if(InSimulationMode) { - if(powered) - EmphText(); - else - NormText(); - } -} +// static void NormText(void) +// { +// SetTextColor(Hdc, InSimulationMode ? HighlightColours.simOff : +// HighlightColours.def); +// SelectObject(Hdc, FixedWidthFont); +// } + +// static void EmphText(void) +// { +// SetTextColor(Hdc, InSimulationMode ? HighlightColours.simOn : +// HighlightColours.selected); +// SelectObject(Hdc, FixedWidthFontBold); +// } + +// static void NameText(void) +// { +// if(!InSimulationMode && !ThisHighlighted) { +// SetTextColor(Hdc, HighlightColours.name); +// } +// } + +// static void BodyText(void) +// { +// if(!InSimulationMode && !ThisHighlighted) { +// SetTextColor(Hdc, HighlightColours.def); +// } +// } + +// static void PoweredText(BOOL powered) +// { +// if(InSimulationMode) { +// if(powered) +// EmphText(); +// else +// NormText(); +// } +// } //----------------------------------------------------------------------------- // Count the length of a string, in characters. Nonstandard because the // string may contain special characters to indicate formatting (syntax // highlighting). //----------------------------------------------------------------------------- -static int FormattedStrlen(char *str) -{ - int l = 0; - while(*str) { - if(*str > 10) { - l++; - } - str++; - } - return l; -} +// static int FormattedStrlen(char *str) +// { +// int l = 0; +// while(*str) { +// if(*str > 10) { +// l++; +// } +// str++; +// } +// return l; +// } //----------------------------------------------------------------------------- // Draw a string, centred in the space of a single position, with spaces on // the left and right. Draws on the upper line of the position. //----------------------------------------------------------------------------- -static void CenterWithSpaces(int cx, int cy, char *str, BOOL powered, - BOOL isName) -{ - int extra = POS_WIDTH - FormattedStrlen(str); - PoweredText(powered); - if(isName) NameText(); - DrawChars(cx + (extra/2), cy + (POS_HEIGHT/2) - 1, str); - if(isName) BodyText(); -} +// static void CenterWithSpaces(int cx, int cy, char *str, BOOL powered, +// BOOL isName) +// { +// int extra = POS_WIDTH - FormattedStrlen(str); +// PoweredText(powered); +// if(isName) NameText(); +// DrawChars(cx + (extra/2), cy + (POS_HEIGHT/2) - 1, str); +// if(isName) BodyText(); +// } //----------------------------------------------------------------------------- // Like CenterWithWires, but for an arbitrary width position (e.g. for ADD // and SUB, which are double-width). //----------------------------------------------------------------------------- -static void CenterWithWiresWidth(int cx, int cy, char *str, BOOL before, - BOOL after, int totalWidth) -{ - int extra = totalWidth - FormattedStrlen(str); - - PoweredText(after); - DrawChars(cx + (extra/2), cy + (POS_HEIGHT/2), str); - - PoweredText(before); - int i; - for(i = 0; i < (extra/2); i++) { - DrawChars(cx + i, cy + (POS_HEIGHT/2), "-"); - } - PoweredText(after); - for(i = FormattedStrlen(str)+(extra/2); i < totalWidth; i++) { - DrawChars(cx + i, cy + (POS_HEIGHT/2), "-"); - } -} +// static void CenterWithWiresWidth(int cx, int cy, char *str, BOOL before, +// BOOL after, int totalWidth) +// { +// int extra = totalWidth - FormattedStrlen(str); + +// PoweredText(after); +// DrawChars(cx + (extra/2), cy + (POS_HEIGHT/2), str); + +// PoweredText(before); +// int i; +// for(i = 0; i < (extra/2); i++) { +// DrawChars(cx + i, cy + (POS_HEIGHT/2), "-"); +// } +// PoweredText(after); +// for(i = FormattedStrlen(str)+(extra/2); i < totalWidth; i++) { +// DrawChars(cx + i, cy + (POS_HEIGHT/2), "-"); +// } +// } //----------------------------------------------------------------------------- // Draw a string, centred in the space of a single position, with en dashes on // the left and right coloured according to the powered state. Draws on the // middle line. //----------------------------------------------------------------------------- -static void CenterWithWires(int cx, int cy, char *str, BOOL before, BOOL after) -{ - CenterWithWiresWidth(cx, cy, str, before, after, POS_WIDTH); -} +// static void CenterWithWires(int cx, int cy, char *str, BOOL before, BOOL after) +// { +// CenterWithWiresWidth(cx, cy, str, before, after, POS_WIDTH); +// } //----------------------------------------------------------------------------- // Draw an end of line element (coil, RES, MOV, etc.). Special things about // an end of line element: we must right-justify it. //----------------------------------------------------------------------------- -static BOOL DrawEndOfLine(int which, ElemLeaf *leaf, int *cx, int *cy, - BOOL poweredBefore) -{ - int cx0 = *cx, cy0 = *cy; - - BOOL poweredAfter = leaf->poweredAfter; - - int thisWidth; - switch(which) { - case ELEM_ADD: - case ELEM_SUB: - case ELEM_MUL: - case ELEM_DIV: - thisWidth = 2; - break; - - default: - thisWidth = 1; - break; - } - - NormText(); - PoweredText(poweredBefore); - while(*cx < (ColsAvailable-thisWidth)*POS_WIDTH) { - int gx = *cx/POS_WIDTH; - int gy = *cy/POS_HEIGHT; - - if(CheckBoundsUndoIfFails(gx, gy)) return FALSE; - - if(gx >= DISPLAY_MATRIX_X_SIZE) oops(); - DM_BOUNDS(gx, gy); - DisplayMatrix[gx][gy] = PADDING_IN_DISPLAY_MATRIX; - DisplayMatrixWhich[gx][gy] = ELEM_PADDING; - - int i; - for(i = 0; i < POS_WIDTH; i++) { - DrawChars(*cx + i, *cy + (POS_HEIGHT/2), "-"); - } - *cx += POS_WIDTH; - cx0 += POS_WIDTH; - } - - if(leaf == Selected && !InSimulationMode) { - EmphText(); - ThisHighlighted = TRUE; - } else { - ThisHighlighted = FALSE; - } - - switch(which) { - case ELEM_CTC: { - char buf[256]; - ElemCounter *c = &leaf->d.counter; - sprintf(buf, "{\x01""CTC\x02 0:%d}", c->max); - - CenterWithSpaces(*cx, *cy, c->name, poweredAfter, TRUE); - CenterWithWires(*cx, *cy, buf, poweredBefore, poweredAfter); - break; - } - case ELEM_RES: { - ElemReset *r = &leaf->d.reset; - CenterWithSpaces(*cx, *cy, r->name, poweredAfter, TRUE); - CenterWithWires(*cx, *cy, "{RES}", poweredBefore, poweredAfter); - break; - } - case ELEM_READ_ADC: { - ElemReadAdc *r = &leaf->d.readAdc; - CenterWithSpaces(*cx, *cy, r->name, poweredAfter, TRUE); - CenterWithWires(*cx, *cy, "{READ ADC}", poweredBefore, - poweredAfter); - break; - } - case ELEM_SET_PWM: { - ElemSetPwm *s = &leaf->d.setPwm; - CenterWithSpaces(*cx, *cy, s->name, poweredAfter, TRUE); - char l[50]; - if(s->targetFreq >= 100000) { - sprintf(l, "{PWM %d kHz}", (s->targetFreq+500)/1000); - } else if(s->targetFreq >= 10000) { - sprintf(l, "{PWM %.1f kHz}", s->targetFreq/1000.0); - } else if(s->targetFreq >= 1000) { - sprintf(l, "{PWM %.2f kHz}", s->targetFreq/1000.0); - } else { - sprintf(l, "{PWM %d Hz}", s->targetFreq); - } - CenterWithWires(*cx, *cy, l, poweredBefore, - poweredAfter); - break; - } - case ELEM_PERSIST: - CenterWithSpaces(*cx, *cy, leaf->d.persist.var, poweredAfter, TRUE); - CenterWithWires(*cx, *cy, "{PERSIST}", poweredBefore, poweredAfter); - break; - - case ELEM_MOVE: { - char top[256]; - char bot[256]; - ElemMove *m = &leaf->d.move; - - if((strlen(m->dest) > (POS_WIDTH - 9)) || - (strlen(m->src) > (POS_WIDTH - 9))) - { - CenterWithWires(*cx, *cy, TOO_LONG, poweredBefore, - poweredAfter); - break; - } - - strcpy(top, "{ }"); - memcpy(top+1, m->dest, strlen(m->dest)); - top[strlen(m->dest) + 3] = ':'; - top[strlen(m->dest) + 4] = '='; - - strcpy(bot, "{ \x01MOV\x02}"); - memcpy(bot+2, m->src, strlen(m->src)); - - CenterWithSpaces(*cx, *cy, top, poweredAfter, FALSE); - CenterWithWires(*cx, *cy, bot, poweredBefore, poweredAfter); - break; - } - case ELEM_MASTER_RELAY: - CenterWithWires(*cx, *cy, "{MASTER RLY}", poweredBefore, - poweredAfter); - break; - - case ELEM_SHIFT_REGISTER: { - char bot[MAX_NAME_LEN+20]; - memset(bot, ' ', sizeof(bot)); - bot[0] = '{'; - sprintf(bot+2, "%s0..%d", leaf->d.shiftRegister.name, - leaf->d.shiftRegister.stages-1); - bot[strlen(bot)] = ' '; - bot[13] = '}'; - bot[14] = '\0'; - CenterWithSpaces(*cx, *cy, "{\x01SHIFT REG\x02 }", - poweredAfter, FALSE); - CenterWithWires(*cx, *cy, bot, poweredBefore, poweredAfter); - break; - } - case ELEM_PIECEWISE_LINEAR: - case ELEM_LOOK_UP_TABLE: { - char top[MAX_NAME_LEN+20], bot[MAX_NAME_LEN+20]; - char *dest, *index, *str; - if(which == ELEM_PIECEWISE_LINEAR) { - dest = leaf->d.piecewiseLinear.dest; - index = leaf->d.piecewiseLinear.index; - str = "PWL"; - } else { - dest = leaf->d.lookUpTable.dest; - index = leaf->d.lookUpTable.index; - str = "LUT"; - } - memset(top, ' ', sizeof(top)); - top[0] = '{'; - sprintf(top+2, "%s :=", dest); - top[strlen(top)] = ' '; - top[13] = '}'; - top[14] = '\0'; - CenterWithSpaces(*cx, *cy, top, poweredAfter, FALSE); - memset(bot, ' ', sizeof(bot)); - bot[0] = '{'; - sprintf(bot+2, " %s[%s]", str, index); - bot[strlen(bot)] = ' '; - bot[13] = '}'; - bot[14] = '\0'; - CenterWithWires(*cx, *cy, bot, poweredBefore, poweredAfter); - break; - } - case ELEM_COIL: { - char buf[4]; - ElemCoil *c = &leaf->d.coil; - - buf[0] = '('; - if(c->negated) { - buf[1] = '/'; - } else if(c->setOnly) { - buf[1] = 'S'; - } else if(c->resetOnly) { - buf[1] = 'R'; - } else { - buf[1] = ' '; - } - buf[2] = ')'; - buf[3] = '\0'; - - CenterWithSpaces(*cx, *cy, c->name, poweredAfter, TRUE); - CenterWithWires(*cx, *cy, buf, poweredBefore, poweredAfter); - break; - } - case ELEM_DIV: - case ELEM_MUL: - case ELEM_SUB: - case ELEM_ADD: { - char top[POS_WIDTH*2-3+2]; - char bot[POS_WIDTH*2-3]; - - memset(top, ' ', sizeof(top)-1); - top[0] = '{'; - - memset(bot, ' ', sizeof(bot)-1); - bot[0] = '{'; - - int lt = 1; - if(which == ELEM_ADD) { - memcpy(top+lt, "\x01""ADD\x02", 5); - } else if(which == ELEM_SUB) { - memcpy(top+lt, "\x01SUB\x02", 5); - } else if(which == ELEM_MUL) { - memcpy(top+lt, "\x01MUL\x02", 5); - } else if(which == ELEM_DIV) { - memcpy(top+lt, "\x01""DIV\x02", 5); - } else oops(); - - lt += 7; - memcpy(top+lt, leaf->d.math.dest, strlen(leaf->d.math.dest)); - lt += strlen(leaf->d.math.dest) + 2; - top[lt++] = ':'; - top[lt++] = '='; - - int lb = 2; - memcpy(bot+lb, leaf->d.math.op1, strlen(leaf->d.math.op1)); - lb += strlen(leaf->d.math.op1) + 1; - if(which == ELEM_ADD) { - bot[lb++] = '+'; - } else if(which == ELEM_SUB) { - bot[lb++] = '-'; - } else if(which == ELEM_MUL) { - bot[lb++] = '*'; - } else if(which == ELEM_DIV) { - bot[lb++] = '/'; - } else oops(); - lb++; - memcpy(bot+lb, leaf->d.math.op2, strlen(leaf->d.math.op2)); - lb += strlen(leaf->d.math.op2); - - int l = max(lb, lt - 2); - top[l+2] = '}'; top[l+3] = '\0'; - bot[l] = '}'; bot[l+1] = '\0'; - - int extra = 2*POS_WIDTH - FormattedStrlen(top); - PoweredText(poweredAfter); - DrawChars(*cx + (extra/2), *cy + (POS_HEIGHT/2) - 1, top); - CenterWithWiresWidth(*cx, *cy, bot, poweredBefore, poweredAfter, - 2*POS_WIDTH); - - *cx += POS_WIDTH; - - break; - } - default: - oops(); - break; - } - - *cx += POS_WIDTH; - - return poweredAfter; -} +// static BOOL DrawEndOfLine(int which, ElemLeaf *leaf, int *cx, int *cy, +// BOOL poweredBefore) +// { +// int cx0 = *cx, cy0 = *cy; + +// BOOL poweredAfter = leaf->poweredAfter; + +// int thisWidth; +// switch(which) { +// case ELEM_ADD: +// case ELEM_SUB: +// case ELEM_MUL: +// case ELEM_DIV: +// thisWidth = 2; +// break; + +// default: +// thisWidth = 1; +// break; +// } + +// NormText(); +// PoweredText(poweredBefore); +// while(*cx < (ColsAvailable-thisWidth)*POS_WIDTH) { +// int gx = *cx/POS_WIDTH; +// int gy = *cy/POS_HEIGHT; + +// if(CheckBoundsUndoIfFails(gx, gy)) return FALSE; + +// if(gx >= DISPLAY_MATRIX_X_SIZE) oops(); +// DM_BOUNDS(gx, gy); +// DisplayMatrix[gx][gy] = PADDING_IN_DISPLAY_MATRIX; +// DisplayMatrixWhich[gx][gy] = ELEM_PADDING; + +// int i; +// for(i = 0; i < POS_WIDTH; i++) { +// DrawChars(*cx + i, *cy + (POS_HEIGHT/2), "-"); +// } +// *cx += POS_WIDTH; +// cx0 += POS_WIDTH; +// } + +// if(leaf == Selected && !InSimulationMode) { +// EmphText(); +// ThisHighlighted = TRUE; +// } else { +// ThisHighlighted = FALSE; +// } + +// switch(which) { +// case ELEM_CTC: { +// char buf[256]; +// ElemCounter *c = &leaf->d.counter; +// sprintf(buf, "{\x01""CTC\x02 0:%d}", c->max); + +// CenterWithSpaces(*cx, *cy, c->name, poweredAfter, TRUE); +// CenterWithWires(*cx, *cy, buf, poweredBefore, poweredAfter); +// break; +// } +// case ELEM_RES: { +// ElemReset *r = &leaf->d.reset; +// CenterWithSpaces(*cx, *cy, r->name, poweredAfter, TRUE); +// CenterWithWires(*cx, *cy, "{RES}", poweredBefore, poweredAfter); +// break; +// } +// case ELEM_READ_ADC: { +// ElemReadAdc *r = &leaf->d.readAdc; +// CenterWithSpaces(*cx, *cy, r->name, poweredAfter, TRUE); +// CenterWithWires(*cx, *cy, "{READ ADC}", poweredBefore, +// poweredAfter); +// break; +// } +// case ELEM_SET_PWM: { +// ElemSetPwm *s = &leaf->d.setPwm; +// CenterWithSpaces(*cx, *cy, s->name, poweredAfter, TRUE); +// char l[50]; +// if(s->targetFreq >= 100000) { +// sprintf(l, "{PWM %d kHz}", (s->targetFreq+500)/1000); +// } else if(s->targetFreq >= 10000) { +// sprintf(l, "{PWM %.1f kHz}", s->targetFreq/1000.0); +// } else if(s->targetFreq >= 1000) { +// sprintf(l, "{PWM %.2f kHz}", s->targetFreq/1000.0); +// } else { +// sprintf(l, "{PWM %d Hz}", s->targetFreq); +// } +// CenterWithWires(*cx, *cy, l, poweredBefore, +// poweredAfter); +// break; +// } +// case ELEM_PERSIST: +// CenterWithSpaces(*cx, *cy, leaf->d.persist.var, poweredAfter, TRUE); +// CenterWithWires(*cx, *cy, "{PERSIST}", poweredBefore, poweredAfter); +// break; + +// case ELEM_MOVE: { +// char top[256]; +// char bot[256]; +// ElemMove *m = &leaf->d.move; + +// if((strlen(m->dest) > (POS_WIDTH - 9)) || +// (strlen(m->src) > (POS_WIDTH - 9))) +// { +// CenterWithWires(*cx, *cy, TOO_LONG, poweredBefore, +// poweredAfter); +// break; +// } + +// strcpy(top, "{ }"); +// memcpy(top+1, m->dest, strlen(m->dest)); +// top[strlen(m->dest) + 3] = ':'; +// top[strlen(m->dest) + 4] = '='; + +// strcpy(bot, "{ \x01MOV\x02}"); +// memcpy(bot+2, m->src, strlen(m->src)); + +// CenterWithSpaces(*cx, *cy, top, poweredAfter, FALSE); +// CenterWithWires(*cx, *cy, bot, poweredBefore, poweredAfter); +// break; +// } +// case ELEM_MASTER_RELAY: +// CenterWithWires(*cx, *cy, "{MASTER RLY}", poweredBefore, +// poweredAfter); +// break; + +// case ELEM_SHIFT_REGISTER: { +// char bot[MAX_NAME_LEN+20]; +// memset(bot, ' ', sizeof(bot)); +// bot[0] = '{'; +// sprintf(bot+2, "%s0..%d", leaf->d.shiftRegister.name, +// leaf->d.shiftRegister.stages-1); +// bot[strlen(bot)] = ' '; +// bot[13] = '}'; +// bot[14] = '\0'; +// CenterWithSpaces(*cx, *cy, "{\x01SHIFT REG\x02 }", +// poweredAfter, FALSE); +// CenterWithWires(*cx, *cy, bot, poweredBefore, poweredAfter); +// break; +// } +// case ELEM_PIECEWISE_LINEAR: +// case ELEM_LOOK_UP_TABLE: { +// char top[MAX_NAME_LEN+20], bot[MAX_NAME_LEN+20]; +// char *dest, *index, *str; +// if(which == ELEM_PIECEWISE_LINEAR) { +// dest = leaf->d.piecewiseLinear.dest; +// index = leaf->d.piecewiseLinear.index; +// str = "PWL"; +// } else { +// dest = leaf->d.lookUpTable.dest; +// index = leaf->d.lookUpTable.index; +// str = "LUT"; +// } +// memset(top, ' ', sizeof(top)); +// top[0] = '{'; +// sprintf(top+2, "%s :=", dest); +// top[strlen(top)] = ' '; +// top[13] = '}'; +// top[14] = '\0'; +// CenterWithSpaces(*cx, *cy, top, poweredAfter, FALSE); +// memset(bot, ' ', sizeof(bot)); +// bot[0] = '{'; +// sprintf(bot+2, " %s[%s]", str, index); +// bot[strlen(bot)] = ' '; +// bot[13] = '}'; +// bot[14] = '\0'; +// CenterWithWires(*cx, *cy, bot, poweredBefore, poweredAfter); +// break; +// } +// case ELEM_COIL: { +// char buf[4]; +// ElemCoil *c = &leaf->d.coil; + +// buf[0] = '('; +// if(c->negated) { +// buf[1] = '/'; +// } else if(c->setOnly) { +// buf[1] = 'S'; +// } else if(c->resetOnly) { +// buf[1] = 'R'; +// } else { +// buf[1] = ' '; +// } +// buf[2] = ')'; +// buf[3] = '\0'; + +// CenterWithSpaces(*cx, *cy, c->name, poweredAfter, TRUE); +// CenterWithWires(*cx, *cy, buf, poweredBefore, poweredAfter); +// break; +// } +// case ELEM_DIV: +// case ELEM_MUL: +// case ELEM_SUB: +// case ELEM_ADD: { +// char top[POS_WIDTH*2-3+2]; +// char bot[POS_WIDTH*2-3]; + +// memset(top, ' ', sizeof(top)-1); +// top[0] = '{'; + +// memset(bot, ' ', sizeof(bot)-1); +// bot[0] = '{'; + +// int lt = 1; +// if(which == ELEM_ADD) { +// memcpy(top+lt, "\x01""ADD\x02", 5); +// } else if(which == ELEM_SUB) { +// memcpy(top+lt, "\x01SUB\x02", 5); +// } else if(which == ELEM_MUL) { +// memcpy(top+lt, "\x01MUL\x02", 5); +// } else if(which == ELEM_DIV) { +// memcpy(top+lt, "\x01""DIV\x02", 5); +// } else oops(); + +// lt += 7; +// memcpy(top+lt, leaf->d.math.dest, strlen(leaf->d.math.dest)); +// lt += strlen(leaf->d.math.dest) + 2; +// top[lt++] = ':'; +// top[lt++] = '='; + +// int lb = 2; +// memcpy(bot+lb, leaf->d.math.op1, strlen(leaf->d.math.op1)); +// lb += strlen(leaf->d.math.op1) + 1; +// if(which == ELEM_ADD) { +// bot[lb++] = '+'; +// } else if(which == ELEM_SUB) { +// bot[lb++] = '-'; +// } else if(which == ELEM_MUL) { +// bot[lb++] = '*'; +// } else if(which == ELEM_DIV) { +// bot[lb++] = '/'; +// } else oops(); +// lb++; +// memcpy(bot+lb, leaf->d.math.op2, strlen(leaf->d.math.op2)); +// lb += strlen(leaf->d.math.op2); + +// int l = max(lb, lt - 2); +// top[l+2] = '}'; top[l+3] = '\0'; +// bot[l] = '}'; bot[l+1] = '\0'; + +// int extra = 2*POS_WIDTH - FormattedStrlen(top); +// PoweredText(poweredAfter); +// DrawChars(*cx + (extra/2), *cy + (POS_HEIGHT/2) - 1, top); +// CenterWithWiresWidth(*cx, *cy, bot, poweredBefore, poweredAfter, +// 2*POS_WIDTH); + +// *cx += POS_WIDTH; + +// break; +// } +// default: +// oops(); +// break; +// } + +// *cx += POS_WIDTH; + +// return poweredAfter; +// } //----------------------------------------------------------------------------- // Draw a leaf element. Special things about a leaf: no need to recurse // further, and we must put it into the display matrix. //----------------------------------------------------------------------------- -static BOOL DrawLeaf(int which, ElemLeaf *leaf, int *cx, int *cy, - BOOL poweredBefore) -{ - int cx0 = *cx, cy0 = *cy; - BOOL poweredAfter = leaf->poweredAfter; - - switch(which) { - case ELEM_COMMENT: { - char tbuf[MAX_COMMENT_LEN]; - char tlbuf[MAX_COMMENT_LEN+8]; - - strcpy(tbuf, leaf->d.comment.str); - char *b = strchr(tbuf, '\n'); - - if(b) { - if(b[-1] == '\r') b[-1] = '\0'; - *b = '\0'; - sprintf(tlbuf, "\x03 ; %s\x02", tbuf); - DrawChars(*cx, *cy + (POS_HEIGHT/2) - 1, tlbuf); - sprintf(tlbuf, "\x03 ; %s\x02", b+1); - DrawChars(*cx, *cy + (POS_HEIGHT/2), tlbuf); - } else { - sprintf(tlbuf, "\x03 ; %s\x02", tbuf); - DrawChars(*cx, *cy + (POS_HEIGHT/2) - 1, tlbuf); - } - - *cx += ColsAvailable*POS_WIDTH; - break; - } - case ELEM_PLACEHOLDER: { - NormText(); - CenterWithWiresWidth(*cx, *cy, "--", FALSE, FALSE, 2); - *cx += POS_WIDTH; - break; - } - case ELEM_CONTACTS: { - char buf[4]; - ElemContacts *c = &leaf->d.contacts; - - buf[0] = ']'; - buf[1] = c->negated ? '/' : ' '; - buf[2] = '['; - buf[3] = '\0'; - - CenterWithSpaces(*cx, *cy, c->name, poweredAfter, TRUE); - CenterWithWires(*cx, *cy, buf, poweredBefore, poweredAfter); - - *cx += POS_WIDTH; - break; - } - { - char *s; - case ELEM_EQU: - s = "=="; goto cmp; - case ELEM_NEQ: - s = "/="; goto cmp; - case ELEM_GRT: - s = ">"; goto cmp; - case ELEM_GEQ: - s = ">="; goto cmp; - case ELEM_LES: - s = "<"; goto cmp; - case ELEM_LEQ: - s = "<="; goto cmp; -cmp: - char s1[POS_WIDTH+10], s2[POS_WIDTH+10]; - int l1, l2, lmax; - - l1 = 2 + 1 + strlen(s) + strlen(leaf->d.cmp.op1); - l2 = 2 + 1 + strlen(leaf->d.cmp.op2); - lmax = max(l1, l2); - - if(lmax < POS_WIDTH) { - memset(s1, ' ', sizeof(s1)); - s1[0] = '['; - s1[lmax-1] = ']'; - s1[lmax] = '\0'; - strcpy(s2, s1); - memcpy(s1+1, leaf->d.cmp.op1, strlen(leaf->d.cmp.op1)); - memcpy(s1+strlen(leaf->d.cmp.op1)+2, s, strlen(s)); - memcpy(s2+2, leaf->d.cmp.op2, strlen(leaf->d.cmp.op2)); - } else { - strcpy(s1, ""); - strcpy(s2, TOO_LONG); - } - - CenterWithSpaces(*cx, *cy, s1, poweredAfter, FALSE); - CenterWithWires(*cx, *cy, s2, poweredBefore, poweredAfter); - - *cx += POS_WIDTH; - break; - } - case ELEM_OPEN: - CenterWithWires(*cx, *cy, "+ +", poweredBefore, poweredAfter); - *cx += POS_WIDTH; - break; - - case ELEM_SHORT: - CenterWithWires(*cx, *cy, "+------+", poweredBefore, poweredAfter); - *cx += POS_WIDTH; - break; - - case ELEM_ONE_SHOT_RISING: - case ELEM_ONE_SHOT_FALLING: { - char *s1, *s2; - if(which == ELEM_ONE_SHOT_RISING) { - s1 = " _ "; - s2 = "[\x01OSR\x02_/ ]"; - } else if(which == ELEM_ONE_SHOT_FALLING) { - s1 = " _ "; - s2 = "[\x01OSF\x02 \\_]"; - } else oops(); - - CenterWithSpaces(*cx, *cy, s1, poweredAfter, FALSE); - CenterWithWires(*cx, *cy, s2, poweredBefore, poweredAfter); - - *cx += POS_WIDTH; - break; - } - case ELEM_CTU: - case ELEM_CTD: { - char *s; - if(which == ELEM_CTU) - s = "\x01""CTU\x02"; - else if(which == ELEM_CTD) - s = "\x01""CTD\x02"; - else oops(); - - char buf[256]; - ElemCounter *c = &leaf->d.counter; - sprintf(buf, "[%s >=%d]", s, c->max); - - CenterWithSpaces(*cx, *cy, c->name, poweredAfter, TRUE); - CenterWithWires(*cx, *cy, buf, poweredBefore, poweredAfter); - - *cx += POS_WIDTH; - break; - } - case ELEM_RTO: - case ELEM_TON: - case ELEM_TOF: { - char *s; - if(which == ELEM_TON) - s = "\x01TON\x02"; - else if(which == ELEM_TOF) - s = "\x01TOF\x02"; - else if(which == ELEM_RTO) - s = "\x01RTO\x02"; - else oops(); - - char buf[256]; - ElemTimer *t = &leaf->d.timer; - if(t->delay >= 1000*1000) { - sprintf(buf, "[%s %.3f s]", s, t->delay/1000000.0); - } else if(t->delay >= 100*1000) { - sprintf(buf, "[%s %.1f ms]", s, t->delay/1000.0); - } else { - sprintf(buf, "[%s %.2f ms]", s, t->delay/1000.0); - } - - CenterWithSpaces(*cx, *cy, t->name, poweredAfter, TRUE); - CenterWithWires(*cx, *cy, buf, poweredBefore, poweredAfter); - - *cx += POS_WIDTH; - break; - } - case ELEM_FORMATTED_STRING: { - // Careful, string could be longer than fits in our space. - char str[POS_WIDTH*2]; - memset(str, 0, sizeof(str)); - char *srcStr = leaf->d.fmtdStr.string; - memcpy(str, srcStr, min(strlen(srcStr), POS_WIDTH*2 - 7)); - - char bot[100]; - sprintf(bot, "{\"%s\"}", str); - - int extra = 2*POS_WIDTH - strlen(leaf->d.fmtdStr.var); - PoweredText(poweredAfter); - NameText(); - DrawChars(*cx + (extra/2), *cy + (POS_HEIGHT/2) - 1, - leaf->d.fmtdStr.var); - BodyText(); - - CenterWithWiresWidth(*cx, *cy, bot, poweredBefore, poweredAfter, - 2*POS_WIDTH); - *cx += 2*POS_WIDTH; - break; - } - case ELEM_UART_RECV: - case ELEM_UART_SEND: - CenterWithWires(*cx, *cy, - (which == ELEM_UART_RECV) ? "{UART RECV}" : "{UART SEND}", - poweredBefore, poweredAfter); - CenterWithSpaces(*cx, *cy, leaf->d.uart.name, poweredAfter, TRUE); - *cx += POS_WIDTH; - break; - - default: - poweredAfter = DrawEndOfLine(which, leaf, cx, cy, poweredBefore); - break; - } - - // And now we can enter the element into the display matrix so that the - // UI routines know what element is at position (gx, gy) when the user - // clicks there, and so that we know where to put the cursor if this - // element is selected. - - // Don't use original cx0, as an end of line element might be further - // along than that. - cx0 = *cx - POS_WIDTH; - - int gx = cx0/POS_WIDTH; - int gy = cy0/POS_HEIGHT; - if(CheckBoundsUndoIfFails(gx, gy)) return FALSE; - DM_BOUNDS(gx, gy); - - DisplayMatrix[gx][gy] = leaf; - DisplayMatrixWhich[gx][gy] = which; - - int xadj = 0; - switch(which) { - case ELEM_ADD: - case ELEM_SUB: - case ELEM_MUL: - case ELEM_DIV: - case ELEM_FORMATTED_STRING: - DM_BOUNDS(gx-1, gy); - DisplayMatrix[gx-1][gy] = leaf; - DisplayMatrixWhich[gx-1][gy] = which; - xadj = POS_WIDTH*FONT_WIDTH; - break; - } - - if(which == ELEM_COMMENT) { - int i; - for(i = 0; i < ColsAvailable; i++) { - DisplayMatrix[i][gy] = leaf; - DisplayMatrixWhich[i][gy] = ELEM_COMMENT; - } - xadj = (ColsAvailable-1)*POS_WIDTH*FONT_WIDTH; - } - - int x0 = X_PADDING + cx0*FONT_WIDTH; - int y0 = Y_PADDING + cy0*FONT_HEIGHT; - - if(leaf->selectedState != SELECTED_NONE && leaf == Selected) { - SelectionActive = TRUE; - } - switch(leaf->selectedState) { - case SELECTED_LEFT: - Cursor.left = x0 + FONT_WIDTH - 4 - xadj; - Cursor.top = y0 - FONT_HEIGHT/2; - Cursor.width = 2; - Cursor.height = POS_HEIGHT*FONT_HEIGHT; - break; - - case SELECTED_RIGHT: - Cursor.left = x0 + (POS_WIDTH-1)*FONT_WIDTH - 5; - Cursor.top = y0 - FONT_HEIGHT/2; - Cursor.width = 2; - Cursor.height = POS_HEIGHT*FONT_HEIGHT; - break; - - case SELECTED_ABOVE: - Cursor.left = x0 + FONT_WIDTH/2 - xadj; - Cursor.top = y0 - 2; - Cursor.width = (POS_WIDTH-2)*FONT_WIDTH + xadj; - Cursor.height = 2; - break; - - case SELECTED_BELOW: - Cursor.left = x0 + FONT_WIDTH/2 - xadj; - Cursor.top = y0 + (POS_HEIGHT-1)*FONT_HEIGHT + - FONT_HEIGHT/2 - 2; - Cursor.width = (POS_WIDTH-2)*(FONT_WIDTH) + xadj; - Cursor.height = 2; - break; - - default: - break; - } - - return poweredAfter; -} +// static BOOL DrawLeaf(int which, ElemLeaf *leaf, int *cx, int *cy, +// BOOL poweredBefore) +// { +// int cx0 = *cx, cy0 = *cy; +// BOOL poweredAfter = leaf->poweredAfter; + +// switch(which) { +// case ELEM_COMMENT: { +// char tbuf[MAX_COMMENT_LEN]; +// char tlbuf[MAX_COMMENT_LEN+8]; + +// strcpy(tbuf, leaf->d.comment.str); +// char *b = strchr(tbuf, '\n'); + +// if(b) { +// if(b[-1] == '\r') b[-1] = '\0'; +// *b = '\0'; +// sprintf(tlbuf, "\x03 ; %s\x02", tbuf); +// DrawChars(*cx, *cy + (POS_HEIGHT/2) - 1, tlbuf); +// sprintf(tlbuf, "\x03 ; %s\x02", b+1); +// DrawChars(*cx, *cy + (POS_HEIGHT/2), tlbuf); +// } else { +// sprintf(tlbuf, "\x03 ; %s\x02", tbuf); +// DrawChars(*cx, *cy + (POS_HEIGHT/2) - 1, tlbuf); +// } + +// *cx += ColsAvailable*POS_WIDTH; +// break; +// } +// case ELEM_PLACEHOLDER: { +// NormText(); +// CenterWithWiresWidth(*cx, *cy, "--", FALSE, FALSE, 2); +// *cx += POS_WIDTH; +// break; +// } +// case ELEM_CONTACTS: { +// char buf[4]; +// ElemContacts *c = &leaf->d.contacts; + +// buf[0] = ']'; +// buf[1] = c->negated ? '/' : ' '; +// buf[2] = '['; +// buf[3] = '\0'; + +// CenterWithSpaces(*cx, *cy, c->name, poweredAfter, TRUE); +// CenterWithWires(*cx, *cy, buf, poweredBefore, poweredAfter); + +// *cx += POS_WIDTH; +// break; +// } +// { +// char *s; +// case ELEM_EQU: +// s = "=="; goto cmp; +// case ELEM_NEQ: +// s = "/="; goto cmp; +// case ELEM_GRT: +// s = ">"; goto cmp; +// case ELEM_GEQ: +// s = ">="; goto cmp; +// case ELEM_LES: +// s = "<"; goto cmp; +// case ELEM_LEQ: +// s = "<="; goto cmp; +// cmp: +// char s1[POS_WIDTH+10], s2[POS_WIDTH+10]; +// int l1, l2, lmax; + +// l1 = 2 + 1 + strlen(s) + strlen(leaf->d.cmp.op1); +// l2 = 2 + 1 + strlen(leaf->d.cmp.op2); +// lmax = max(l1, l2); + +// if(lmax < POS_WIDTH) { +// memset(s1, ' ', sizeof(s1)); +// s1[0] = '['; +// s1[lmax-1] = ']'; +// s1[lmax] = '\0'; +// strcpy(s2, s1); +// memcpy(s1+1, leaf->d.cmp.op1, strlen(leaf->d.cmp.op1)); +// memcpy(s1+strlen(leaf->d.cmp.op1)+2, s, strlen(s)); +// memcpy(s2+2, leaf->d.cmp.op2, strlen(leaf->d.cmp.op2)); +// } else { +// strcpy(s1, ""); +// strcpy(s2, TOO_LONG); +// } + +// CenterWithSpaces(*cx, *cy, s1, poweredAfter, FALSE); +// CenterWithWires(*cx, *cy, s2, poweredBefore, poweredAfter); + +// *cx += POS_WIDTH; +// break; +// } +// case ELEM_OPEN: +// CenterWithWires(*cx, *cy, "+ +", poweredBefore, poweredAfter); +// *cx += POS_WIDTH; +// break; + +// case ELEM_SHORT: +// CenterWithWires(*cx, *cy, "+------+", poweredBefore, poweredAfter); +// *cx += POS_WIDTH; +// break; + +// case ELEM_ONE_SHOT_RISING: +// case ELEM_ONE_SHOT_FALLING: { +// char *s1, *s2; +// if(which == ELEM_ONE_SHOT_RISING) { +// s1 = " _ "; +// s2 = "[\x01OSR\x02_/ ]"; +// } else if(which == ELEM_ONE_SHOT_FALLING) { +// s1 = " _ "; +// s2 = "[\x01OSF\x02 \\_]"; +// } else oops(); + +// CenterWithSpaces(*cx, *cy, s1, poweredAfter, FALSE); +// CenterWithWires(*cx, *cy, s2, poweredBefore, poweredAfter); + +// *cx += POS_WIDTH; +// break; +// } +// case ELEM_CTU: +// case ELEM_CTD: { +// char *s; +// if(which == ELEM_CTU) +// s = "\x01""CTU\x02"; +// else if(which == ELEM_CTD) +// s = "\x01""CTD\x02"; +// else oops(); + +// char buf[256]; +// ElemCounter *c = &leaf->d.counter; +// sprintf(buf, "[%s >=%d]", s, c->max); + +// CenterWithSpaces(*cx, *cy, c->name, poweredAfter, TRUE); +// CenterWithWires(*cx, *cy, buf, poweredBefore, poweredAfter); + +// *cx += POS_WIDTH; +// break; +// } +// case ELEM_RTO: +// case ELEM_TON: +// case ELEM_TOF: { +// char *s; +// if(which == ELEM_TON) +// s = "\x01TON\x02"; +// else if(which == ELEM_TOF) +// s = "\x01TOF\x02"; +// else if(which == ELEM_RTO) +// s = "\x01RTO\x02"; +// else oops(); + +// char buf[256]; +// ElemTimer *t = &leaf->d.timer; +// if(t->delay >= 1000*1000) { +// sprintf(buf, "[%s %.3f s]", s, t->delay/1000000.0); +// } else if(t->delay >= 100*1000) { +// sprintf(buf, "[%s %.1f ms]", s, t->delay/1000.0); +// } else { +// sprintf(buf, "[%s %.2f ms]", s, t->delay/1000.0); +// } + +// CenterWithSpaces(*cx, *cy, t->name, poweredAfter, TRUE); +// CenterWithWires(*cx, *cy, buf, poweredBefore, poweredAfter); + +// *cx += POS_WIDTH; +// break; +// } +// case ELEM_FORMATTED_STRING: { +// // Careful, string could be longer than fits in our space. +// char str[POS_WIDTH*2]; +// memset(str, 0, sizeof(str)); +// char *srcStr = leaf->d.fmtdStr.string; +// memcpy(str, srcStr, min(strlen(srcStr), POS_WIDTH*2 - 7)); + +// char bot[100]; +// sprintf(bot, "{\"%s\"}", str); + +// int extra = 2*POS_WIDTH - strlen(leaf->d.fmtdStr.var); +// PoweredText(poweredAfter); +// NameText(); +// DrawChars(*cx + (extra/2), *cy + (POS_HEIGHT/2) - 1, +// leaf->d.fmtdStr.var); +// BodyText(); + +// CenterWithWiresWidth(*cx, *cy, bot, poweredBefore, poweredAfter, +// 2*POS_WIDTH); +// *cx += 2*POS_WIDTH; +// break; +// } +// case ELEM_UART_RECV: +// case ELEM_UART_SEND: +// CenterWithWires(*cx, *cy, +// (which == ELEM_UART_RECV) ? "{UART RECV}" : "{UART SEND}", +// poweredBefore, poweredAfter); +// CenterWithSpaces(*cx, *cy, leaf->d.uart.name, poweredAfter, TRUE); +// *cx += POS_WIDTH; +// break; + +// default: +// poweredAfter = DrawEndOfLine(which, leaf, cx, cy, poweredBefore); +// break; +// } + +// // And now we can enter the element into the display matrix so that the +// // UI routines know what element is at position (gx, gy) when the user +// // clicks there, and so that we know where to put the cursor if this +// // element is selected. + +// // Don't use original cx0, as an end of line element might be further +// // along than that. +// cx0 = *cx - POS_WIDTH; + +// int gx = cx0/POS_WIDTH; +// int gy = cy0/POS_HEIGHT; +// if(CheckBoundsUndoIfFails(gx, gy)) return FALSE; +// DM_BOUNDS(gx, gy); + +// DisplayMatrix[gx][gy] = leaf; +// DisplayMatrixWhich[gx][gy] = which; + +// int xadj = 0; +// switch(which) { +// case ELEM_ADD: +// case ELEM_SUB: +// case ELEM_MUL: +// case ELEM_DIV: +// case ELEM_FORMATTED_STRING: +// DM_BOUNDS(gx-1, gy); +// DisplayMatrix[gx-1][gy] = leaf; +// DisplayMatrixWhich[gx-1][gy] = which; +// xadj = POS_WIDTH*FONT_WIDTH; +// break; +// } + +// if(which == ELEM_COMMENT) { +// int i; +// for(i = 0; i < ColsAvailable; i++) { +// DisplayMatrix[i][gy] = leaf; +// DisplayMatrixWhich[i][gy] = ELEM_COMMENT; +// } +// xadj = (ColsAvailable-1)*POS_WIDTH*FONT_WIDTH; +// } + +// int x0 = X_PADDING + cx0*FONT_WIDTH; +// int y0 = Y_PADDING + cy0*FONT_HEIGHT; + +// if(leaf->selectedState != SELECTED_NONE && leaf == Selected) { +// SelectionActive = TRUE; +// } +// switch(leaf->selectedState) { +// case SELECTED_LEFT: +// Cursor.left = x0 + FONT_WIDTH - 4 - xadj; +// Cursor.top = y0 - FONT_HEIGHT/2; +// Cursor.width = 2; +// Cursor.height = POS_HEIGHT*FONT_HEIGHT; +// break; + +// case SELECTED_RIGHT: +// Cursor.left = x0 + (POS_WIDTH-1)*FONT_WIDTH - 5; +// Cursor.top = y0 - FONT_HEIGHT/2; +// Cursor.width = 2; +// Cursor.height = POS_HEIGHT*FONT_HEIGHT; +// break; + +// case SELECTED_ABOVE: +// Cursor.left = x0 + FONT_WIDTH/2 - xadj; +// Cursor.top = y0 - 2; +// Cursor.width = (POS_WIDTH-2)*FONT_WIDTH + xadj; +// Cursor.height = 2; +// break; + +// case SELECTED_BELOW: +// Cursor.left = x0 + FONT_WIDTH/2 - xadj; +// Cursor.top = y0 + (POS_HEIGHT-1)*FONT_HEIGHT + +// FONT_HEIGHT/2 - 2; +// Cursor.width = (POS_WIDTH-2)*(FONT_WIDTH) + xadj; +// Cursor.height = 2; +// break; + +// default: +// break; +// } + +// return poweredAfter; +// } //----------------------------------------------------------------------------- // Draw a particular subcircuit with its top left corner at *cx and *cy (in @@ -922,145 +926,145 @@ cmp: // element, else FALSE. This is needed to colour all the wires correctly, // since the colouring indicates whether a wire is energized. //----------------------------------------------------------------------------- -BOOL DrawElement(int which, void *elem, int *cx, int *cy, BOOL poweredBefore) -{ - BOOL poweredAfter; - - int cx0 = *cx, cy0 = *cy; - ElemLeaf *leaf = (ElemLeaf *)elem; - - SetBkColor(Hdc, InSimulationMode ? HighlightColours.simBg : - HighlightColours.bg); - NormText(); - - if(elem == Selected && !InSimulationMode) { - EmphText(); - ThisHighlighted = TRUE; - } else { - ThisHighlighted = FALSE; - } - - switch(which) { - case ELEM_SERIES_SUBCKT: { - int i; - ElemSubcktSeries *s = (ElemSubcktSeries *)elem; - poweredAfter = poweredBefore; - for(i = 0; i < s->count; i++) { - poweredAfter = DrawElement(s->contents[i].which, - s->contents[i].d.any, cx, cy, poweredAfter); - } - break; - } - case ELEM_PARALLEL_SUBCKT: { - int i; - ElemSubcktParallel *p = (ElemSubcktParallel *)elem; - int widthMax = CountWidthOfElement(which, elem, (*cx)/POS_WIDTH); - int heightMax = CountHeightOfElement(which, elem); - - poweredAfter = FALSE; - - int lowestPowered = -1; - int downBy = 0; - for(i = 0; i < p->count; i++) { - BOOL poweredThis; - - poweredThis = DrawElement(p->contents[i].which, - p->contents[i].d.any, cx, cy, poweredBefore); - - if(InSimulationMode) { - if(poweredThis) poweredAfter = TRUE; - PoweredText(poweredThis); - } - - while((*cx - cx0) < widthMax*POS_WIDTH) { - int gx = *cx/POS_WIDTH; - int gy = *cy/POS_HEIGHT; - - if(CheckBoundsUndoIfFails(gx, gy)) return FALSE; - - DM_BOUNDS(gx, gy); - DisplayMatrix[gx][gy] = PADDING_IN_DISPLAY_MATRIX; - DisplayMatrixWhich[gx][gy] = ELEM_PADDING; - - char buf[256]; - int j; - for(j = 0; j < POS_WIDTH; j++) { - buf[j] = '-'; - } - buf[j] = '\0'; - DrawChars(*cx, *cy + (POS_HEIGHT/2), buf); - *cx += POS_WIDTH; - } - - *cx = cx0; - int justDrewHeight = CountHeightOfElement(p->contents[i].which, - p->contents[i].d.any); - *cy += POS_HEIGHT*justDrewHeight; - - downBy += justDrewHeight; - if(poweredThis) { - lowestPowered = downBy - 1; - } - } - *cx = cx0 + POS_WIDTH*widthMax; - *cy = cy0; - - int j; - BOOL needWire; - - if(*cx/POS_WIDTH != ColsAvailable) { - needWire = FALSE; - for(j = heightMax - 1; j >= 1; j--) { - if(j <= lowestPowered) PoweredText(poweredAfter); - if(DisplayMatrix[*cx/POS_WIDTH - 1][*cy/POS_HEIGHT + j]) { - needWire = TRUE; - } - if(needWire) VerticalWire(*cx - 1, *cy + j*POS_HEIGHT); - } - // stupid special case - if(lowestPowered == 0 && InSimulationMode) { - EmphText(); - DrawChars(*cx - 1, *cy + (POS_HEIGHT/2), "+"); - } - } - - PoweredText(poweredBefore); - needWire = FALSE; - for(j = heightMax - 1; j >= 1; j--) { - if(DisplayMatrix[cx0/POS_WIDTH][*cy/POS_HEIGHT + j]) { - needWire = TRUE; - } - if(needWire) VerticalWire(cx0 - 1, *cy + j*POS_HEIGHT); - } - - break; - } - default: - poweredAfter = DrawLeaf(which, leaf, cx, cy, poweredBefore); - break; - } - - - NormText(); - return poweredAfter; -} +// BOOL DrawElement(int which, void *elem, int *cx, int *cy, BOOL poweredBefore) +// { +// BOOL poweredAfter; + +// int cx0 = *cx, cy0 = *cy; +// ElemLeaf *leaf = (ElemLeaf *)elem; + +// SetBkColor(Hdc, InSimulationMode ? HighlightColours.simBg : +// HighlightColours.bg); +// NormText(); + +// if(elem == Selected && !InSimulationMode) { +// EmphText(); +// ThisHighlighted = TRUE; +// } else { +// ThisHighlighted = FALSE; +// } + +// switch(which) { +// case ELEM_SERIES_SUBCKT: { +// int i; +// ElemSubcktSeries *s = (ElemSubcktSeries *)elem; +// poweredAfter = poweredBefore; +// for(i = 0; i < s->count; i++) { +// poweredAfter = DrawElement(s->contents[i].which, +// s->contents[i].d.any, cx, cy, poweredAfter); +// } +// break; +// } +// case ELEM_PARALLEL_SUBCKT: { +// int i; +// ElemSubcktParallel *p = (ElemSubcktParallel *)elem; +// int widthMax = CountWidthOfElement(which, elem, (*cx)/POS_WIDTH); +// int heightMax = CountHeightOfElement(which, elem); + +// poweredAfter = FALSE; + +// int lowestPowered = -1; +// int downBy = 0; +// for(i = 0; i < p->count; i++) { +// BOOL poweredThis; + +// poweredThis = DrawElement(p->contents[i].which, +// p->contents[i].d.any, cx, cy, poweredBefore); + +// if(InSimulationMode) { +// if(poweredThis) poweredAfter = TRUE; +// PoweredText(poweredThis); +// } + +// while((*cx - cx0) < widthMax*POS_WIDTH) { +// int gx = *cx/POS_WIDTH; +// int gy = *cy/POS_HEIGHT; + +// if(CheckBoundsUndoIfFails(gx, gy)) return FALSE; + +// DM_BOUNDS(gx, gy); +// DisplayMatrix[gx][gy] = PADDING_IN_DISPLAY_MATRIX; +// DisplayMatrixWhich[gx][gy] = ELEM_PADDING; + +// char buf[256]; +// int j; +// for(j = 0; j < POS_WIDTH; j++) { +// buf[j] = '-'; +// } +// buf[j] = '\0'; +// DrawChars(*cx, *cy + (POS_HEIGHT/2), buf); +// *cx += POS_WIDTH; +// } + +// *cx = cx0; +// int justDrewHeight = CountHeightOfElement(p->contents[i].which, +// p->contents[i].d.any); +// *cy += POS_HEIGHT*justDrewHeight; + +// downBy += justDrewHeight; +// if(poweredThis) { +// lowestPowered = downBy - 1; +// } +// } +// *cx = cx0 + POS_WIDTH*widthMax; +// *cy = cy0; + +// int j; +// BOOL needWire; + +// if(*cx/POS_WIDTH != ColsAvailable) { +// needWire = FALSE; +// for(j = heightMax - 1; j >= 1; j--) { +// if(j <= lowestPowered) PoweredText(poweredAfter); +// if(DisplayMatrix[*cx/POS_WIDTH - 1][*cy/POS_HEIGHT + j]) { +// needWire = TRUE; +// } +// if(needWire) VerticalWire(*cx - 1, *cy + j*POS_HEIGHT); +// } +// // stupid special case +// if(lowestPowered == 0 && InSimulationMode) { +// EmphText(); +// DrawChars(*cx - 1, *cy + (POS_HEIGHT/2), "+"); +// } +// } + +// PoweredText(poweredBefore); +// needWire = FALSE; +// for(j = heightMax - 1; j >= 1; j--) { +// if(DisplayMatrix[cx0/POS_WIDTH][*cy/POS_HEIGHT + j]) { +// needWire = TRUE; +// } +// if(needWire) VerticalWire(cx0 - 1, *cy + j*POS_HEIGHT); +// } + +// break; +// } +// default: +// poweredAfter = DrawLeaf(which, leaf, cx, cy, poweredBefore); +// break; +// } + + +// NormText(); +// return poweredAfter; +// } //----------------------------------------------------------------------------- // Draw the rung that signals the end of the program. Kind of useless but // do it anyways, for convention. //----------------------------------------------------------------------------- -void DrawEndRung(int cx, int cy) -{ - int i; - char *str = "[END]"; - int lead = (POS_WIDTH - strlen(str))/2; - ThisHighlighted = TRUE; - for(i = 0; i < lead; i++) { - DrawChars(cx + i, cy + (POS_HEIGHT/2), "-"); - } - DrawChars(cx + i, cy + (POS_HEIGHT/2), str); - i += strlen(str); - for(; i < ColsAvailable*POS_WIDTH; i++) { - DrawChars(cx + i, cy + (POS_HEIGHT/2), "-"); - } -} +// void DrawEndRung(int cx, int cy) +// { +// int i; +// char *str = "[END]"; +// int lead = (POS_WIDTH - strlen(str))/2; +// ThisHighlighted = TRUE; +// for(i = 0; i < lead; i++) { +// DrawChars(cx + i, cy + (POS_HEIGHT/2), "-"); +// } +// DrawChars(cx + i, cy + (POS_HEIGHT/2), str); +// i += strlen(str); +// for(; i < ColsAvailable*POS_WIDTH; i++) { +// DrawChars(cx + i, cy + (POS_HEIGHT/2), "-"); +// } +// } diff --git a/ldmicro/helpdialog.cpp b/ldmicro/helpdialog.cpp index cf23caa..a800f61 100644 --- a/ldmicro/helpdialog.cpp +++ b/ldmicro/helpdialog.cpp @@ -27,7 +27,7 @@ #include <stdio.h> #include <stdlib.h> //#include <commctrl.h> -#include <richedit.h> +//#include <richedit.h> #include "ldmicro.h" @@ -100,209 +100,209 @@ static int TitleHeight; #define RICH_EDIT_HEIGHT(h) \ ((((h) - 3 + (FONT_HEIGHT/2)) / FONT_HEIGHT) * FONT_HEIGHT) -static void SizeRichEdit(int a) -{ - RECT r; - GetClientRect(HelpDialog[a], &r); - - SetWindowPos(RichEdit[a], HWND_TOP, 6, 3, r.right - 6, - RICH_EDIT_HEIGHT(r.bottom), 0); -} - -static BOOL Resizing(RECT *r, int wParam) -{ - BOOL touched = FALSE; - if(r->right - r->left < 650) { - int diff = 650 - (r->right - r->left); - if(wParam == WMSZ_RIGHT || wParam == WMSZ_TOPRIGHT || - wParam == WMSZ_BOTTOMRIGHT) - { - r->right += diff; - } else { - r->left -= diff; - } - touched = TRUE; - } - - if(!(wParam == WMSZ_LEFT || wParam == WMSZ_RIGHT)) { - int h = r->bottom - r->top - TitleHeight - 5; - if(RICH_EDIT_HEIGHT(h) != h) { - int diff = h - RICH_EDIT_HEIGHT(h); - if(wParam == WMSZ_TOP || wParam == WMSZ_TOPRIGHT || - wParam == WMSZ_TOPLEFT) - { - r->top += diff; - } else { - r->bottom -= diff; - } - touched = TRUE; - } - } - - return !touched; -} - -static void MakeControls(int a) -{ - HMODULE re = LoadLibrary("RichEd20.dll"); - if(!re) oops(); - - RichEdit[a] = CreateWindowEx(0, RICHEDIT_CLASS, - "", WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | ES_READONLY | - ES_MULTILINE | WS_VSCROLL, - 0, 0, 100, 100, HelpDialog[a], NULL, Instance, NULL); - - SendMessage(RichEdit[a], WM_SETFONT, (WPARAM)FixedWidthFont, TRUE); - SendMessage(RichEdit[a], EM_SETBKGNDCOLOR, (WPARAM)0, RGB(0, 0, 0)); - - SizeRichEdit(a); - - int i; - BOOL nextSubHead = FALSE; - for(i = 0; Text[a][i]; i++) { - char *s = Text[a][i]; - - CHARFORMAT cf; - cf.cbSize = sizeof(cf); - cf.dwMask = CFM_BOLD | CFM_COLOR; - cf.dwEffects = 0; - if((s[0] == '=') || - (Text[a][i+1] && Text[a][i+1][0] == '=')) - { - cf.crTextColor = RGB(255, 255, 110); - } else if(s[3] == '|' && s[4] == '|') { - cf.crTextColor = RGB(255, 110, 255); - } else if(s[0] == '>' || nextSubHead) { - // Need to make a copy because the strings we are passed aren't - // mutable. - char copy[1024]; - if(strlen(s) >= sizeof(copy)) oops(); - strcpy(copy, s); - - int j; - for(j = 1; copy[j]; j++) { - if(copy[j] == ' ' && copy[j-1] == ' ') - break; - } - BOOL justHeading = (copy[j] == '\0'); - copy[j] = '\0'; - cf.crTextColor = RGB(110, 255, 110); - SendMessage(RichEdit[a], EM_SETCHARFORMAT, SCF_SELECTION, - (LPARAM)&cf); - SendMessage(RichEdit[a], EM_REPLACESEL, (WPARAM)FALSE, - (LPARAM)copy); - SendMessage(RichEdit[a], EM_SETSEL, (WPARAM)-1, (LPARAM)-1); +// static void SizeRichEdit(int a) +// { +// RECT r; +// GetClientRect(HelpDialog[a], &r); + +// SetWindowPos(RichEdit[a], HWND_TOP, 6, 3, r.right - 6, +// RICH_EDIT_HEIGHT(r.bottom), 0); +// } + +// static BOOL Resizing(RECT *r, int wParam) +// { +// BOOL touched = FALSE; +// if(r->right - r->left < 650) { +// int diff = 650 - (r->right - r->left); +// if(wParam == WMSZ_RIGHT || wParam == WMSZ_TOPRIGHT || +// wParam == WMSZ_BOTTOMRIGHT) +// { +// r->right += diff; +// } else { +// r->left -= diff; +// } +// touched = TRUE; +// } + +// if(!(wParam == WMSZ_LEFT || wParam == WMSZ_RIGHT)) { +// int h = r->bottom - r->top - TitleHeight - 5; +// if(RICH_EDIT_HEIGHT(h) != h) { +// int diff = h - RICH_EDIT_HEIGHT(h); +// if(wParam == WMSZ_TOP || wParam == WMSZ_TOPRIGHT || +// wParam == WMSZ_TOPLEFT) +// { +// r->top += diff; +// } else { +// r->bottom -= diff; +// } +// touched = TRUE; +// } +// } + +// return !touched; +// } + +// static void MakeControls(int a) +// { +// HMODULE re = LoadLibrary("RichEd20.dll"); +// if(!re) oops(); + +// RichEdit[a] = CreateWindowEx(0, RICHEDIT_CLASS, +// "", WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | ES_READONLY | +// ES_MULTILINE | WS_VSCROLL, +// 0, 0, 100, 100, HelpDialog[a], NULL, Instance, NULL); + +// SendMessage(RichEdit[a], WM_SETFONT, (WPARAM)FixedWidthFont, TRUE); +// SendMessage(RichEdit[a], EM_SETBKGNDCOLOR, (WPARAM)0, RGB(0, 0, 0)); + +// SizeRichEdit(a); + +// int i; +// BOOL nextSubHead = FALSE; +// for(i = 0; Text[a][i]; i++) { +// char *s = Text[a][i]; + +// CHARFORMAT cf; +// cf.cbSize = sizeof(cf); +// cf.dwMask = CFM_BOLD | CFM_COLOR; +// cf.dwEffects = 0; +// if((s[0] == '=') || +// (Text[a][i+1] && Text[a][i+1][0] == '=')) +// { +// cf.crTextColor = RGB(255, 255, 110); +// } else if(s[3] == '|' && s[4] == '|') { +// cf.crTextColor = RGB(255, 110, 255); +// } else if(s[0] == '>' || nextSubHead) { +// // Need to make a copy because the strings we are passed aren't +// // mutable. +// char copy[1024]; +// if(strlen(s) >= sizeof(copy)) oops(); +// strcpy(copy, s); + +// int j; +// for(j = 1; copy[j]; j++) { +// if(copy[j] == ' ' && copy[j-1] == ' ') +// break; +// } +// BOOL justHeading = (copy[j] == '\0'); +// copy[j] = '\0'; +// cf.crTextColor = RGB(110, 255, 110); +// SendMessage(RichEdit[a], EM_SETCHARFORMAT, SCF_SELECTION, +// (LPARAM)&cf); +// SendMessage(RichEdit[a], EM_REPLACESEL, (WPARAM)FALSE, +// (LPARAM)copy); +// SendMessage(RichEdit[a], EM_SETSEL, (WPARAM)-1, (LPARAM)-1); - // Special case if there's nothing except title on the line - if(!justHeading) { - copy[j] = ' '; - } - s += j; - cf.crTextColor = RGB(255, 110, 255); - nextSubHead = !nextSubHead; - } else { - cf.crTextColor = RGB(255, 255, 255); - } - - SendMessage(RichEdit[a], EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf); - SendMessage(RichEdit[a], EM_REPLACESEL, (WPARAM)FALSE, (LPARAM)s); - SendMessage(RichEdit[a], EM_SETSEL, (WPARAM)-1, (LPARAM)-1); - - if(Text[a][i+1]) { - SendMessage(RichEdit[a], EM_REPLACESEL, FALSE, (LPARAM)"\r\n"); - SendMessage(RichEdit[a], EM_SETSEL, (WPARAM)-1, (LPARAM)-1); - } - } - - SendMessage(RichEdit[a], EM_SETSEL, (WPARAM)0, (LPARAM)0); -} +// // Special case if there's nothing except title on the line +// if(!justHeading) { +// copy[j] = ' '; +// } +// s += j; +// cf.crTextColor = RGB(255, 110, 255); +// nextSubHead = !nextSubHead; +// } else { +// cf.crTextColor = RGB(255, 255, 255); +// } + +// SendMessage(RichEdit[a], EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf); +// SendMessage(RichEdit[a], EM_REPLACESEL, (WPARAM)FALSE, (LPARAM)s); +// SendMessage(RichEdit[a], EM_SETSEL, (WPARAM)-1, (LPARAM)-1); + +// if(Text[a][i+1]) { +// SendMessage(RichEdit[a], EM_REPLACESEL, FALSE, (LPARAM)"\r\n"); +// SendMessage(RichEdit[a], EM_SETSEL, (WPARAM)-1, (LPARAM)-1); +// } +// } + +// SendMessage(RichEdit[a], EM_SETSEL, (WPARAM)0, (LPARAM)0); +// } //----------------------------------------------------------------------------- // Window proc for the help dialog. //----------------------------------------------------------------------------- -static LRESULT CALLBACK HelpProc(HWND hwnd, UINT msg, WPARAM wParam, - LPARAM lParam) -{ - int a = (hwnd == HelpDialog[0] ? 0 : 1); - switch (msg) { - case WM_SIZING: { - RECT *r = (RECT *)lParam; - return Resizing(r, wParam); - break; - } - case WM_SIZE: - SizeRichEdit(a); - break; - - case WM_ACTIVATE: - case WM_KEYDOWN: - SetFocus(RichEdit[a]); - break; +// static LRESULT CALLBACK HelpProc(HWND hwnd, UINT msg, WPARAM wParam, +// LPARAM lParam) +// { +// int a = (hwnd == HelpDialog[0] ? 0 : 1); +// switch (msg) { +// case WM_SIZING: { +// RECT *r = (RECT *)lParam; +// return Resizing(r, wParam); +// break; +// } +// case WM_SIZE: +// SizeRichEdit(a); +// break; + +// case WM_ACTIVATE: +// case WM_KEYDOWN: +// SetFocus(RichEdit[a]); +// break; - case WM_DESTROY: - case WM_CLOSE: - HelpWindowOpen[a] = FALSE; - // fall through - default: - return DefWindowProc(hwnd, msg, wParam, lParam); - } +// case WM_DESTROY: +// case WM_CLOSE: +// HelpWindowOpen[a] = FALSE; +// // fall through +// default: +// return DefWindowProc(hwnd, msg, wParam, lParam); +// } - return 1; -} +// return 1; +// } //----------------------------------------------------------------------------- // Create the class for the help window. //----------------------------------------------------------------------------- -static void MakeClass(void) -{ - WNDCLASSEX wc; - memset(&wc, 0, sizeof(wc)); - wc.cbSize = sizeof(wc); - - wc.style = CS_BYTEALIGNCLIENT | CS_BYTEALIGNWINDOW | CS_OWNDC | - CS_DBLCLKS; - wc.lpfnWndProc = (WNDPROC)HelpProc; - wc.hInstance = Instance; - wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); - wc.lpszClassName = "LDmicroHelp"; - wc.lpszMenuName = NULL; - wc.hCursor = LoadCursor(NULL, IDC_ARROW); - wc.hIcon = (HICON)LoadImage(Instance, MAKEINTRESOURCE(4000), - IMAGE_ICON, 32, 32, 0); - wc.hIconSm = (HICON)LoadImage(Instance, MAKEINTRESOURCE(4000), - IMAGE_ICON, 16, 16, 0); - - RegisterClassEx(&wc); -} - -void ShowHelpDialog(BOOL about) -{ - int a = about ? 1 : 0; - if(HelpWindowOpen[a]) { - SetForegroundWindow(HelpDialog[a]); - return; - } - - MakeClass(); - - char *s = about ? "About LDmicro" : "LDmicro Help"; - HelpDialog[a] = CreateWindowEx(0, "LDmicroHelp", s, - WS_OVERLAPPED | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | - WS_SIZEBOX, - 100, 100, 650, 300+10*FONT_HEIGHT, NULL, NULL, Instance, NULL); - MakeControls(a); +// static void MakeClass(void) +// { +// WNDCLASSEX wc; +// memset(&wc, 0, sizeof(wc)); +// wc.cbSize = sizeof(wc); + +// wc.style = CS_BYTEALIGNCLIENT | CS_BYTEALIGNWINDOW | CS_OWNDC | +// CS_DBLCLKS; +// wc.lpfnWndProc = (WNDPROC)HelpProc; +// wc.hInstance = Instance; +// wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); +// wc.lpszClassName = "LDmicroHelp"; +// wc.lpszMenuName = NULL; +// wc.hCursor = LoadCursor(NULL, IDC_ARROW); +// wc.hIcon = (HICON)LoadImage(Instance, MAKEINTRESOURCE(4000), +// IMAGE_ICON, 32, 32, 0); +// wc.hIconSm = (HICON)LoadImage(Instance, MAKEINTRESOURCE(4000), +// IMAGE_ICON, 16, 16, 0); + +// RegisterClassEx(&wc); +// } + +// void ShowHelpDialog(BOOL about) +// { +// int a = about ? 1 : 0; +// if(HelpWindowOpen[a]) { +// SetForegroundWindow(HelpDialog[a]); +// return; +// } + +// MakeClass(); + +// char *s = about ? "About LDmicro" : "LDmicro Help"; +// HelpDialog[a] = CreateWindowEx(0, "LDmicroHelp", s, +// WS_OVERLAPPED | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | +// WS_SIZEBOX, +// 100, 100, 650, 300+10*FONT_HEIGHT, NULL, NULL, Instance, NULL); +// MakeControls(a); - ShowWindow(HelpDialog[a], TRUE); - SetFocus(RichEdit[a]); +// ShowWindow(HelpDialog[a], TRUE); +// SetFocus(RichEdit[a]); - HelpWindowOpen[a] = TRUE; +// HelpWindowOpen[a] = TRUE; - RECT r; - GetClientRect(HelpDialog[a], &r); - TitleHeight = 300 - r.bottom; +// RECT r; +// GetClientRect(HelpDialog[a], &r); +// TitleHeight = 300 - r.bottom; - GetWindowRect(HelpDialog[a], &r); - Resizing(&r, WMSZ_TOP); - SetWindowPos(HelpDialog[a], HWND_TOP, r.left, r.top, r.right - r.left, - r.bottom - r.top, 0); -} +// GetWindowRect(HelpDialog[a], &r); +// Resizing(&r, WMSZ_TOP); +// SetWindowPos(HelpDialog[a], HWND_TOP, r.left, r.top, r.right - r.left, +// r.bottom - r.top, 0); +// } diff --git a/ldmicro/includes/naminglist.h b/ldmicro/includes/naminglist.h deleted file mode 100644 index 43a7a76..0000000 --- a/ldmicro/includes/naminglist.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef _NAMING_LIST -#define _NAMING_LIST - -extern HWND NamingList; - -// void NamingListProc(NMHDR *h); - -int NameList_AddName(LPCTSTR Name, int Index); -double NameList_RegisterVolt(LPCTSTR Name, double volt); //Forcefully set voltage will not be accessible outside the cpp file -double NameList_SetVolt(int Index, double volt); //Set voltage if current voltage>specified voltage -double NameList_DeRegisterVolt(LPCTSTR Name); //Send a message to rest of the components to set new voltage -void NamingListProc(NMHDR *h); - - -// void ConfigureNamingList(int type,int PinOnProcessor, MCUPort); -#endif diff --git a/ldmicro/lang.cpp b/ldmicro/lang.cpp index 67952bc..83f9036 100644 --- a/ldmicro/lang.cpp +++ b/ldmicro/lang.cpp @@ -42,7 +42,7 @@ typedef struct LangTag { // These are the actual translation tables, so should be included in just // one place. -//#include "obj/lang-tables.h" +#include "obj/lang-tables.h" #define LDLANG_EN char *_(char *in) diff --git a/ldmicro/resetdialog.cpp b/ldmicro/resetdialog.cpp index b83cd42..70a5218 100644 --- a/ldmicro/resetdialog.cpp +++ b/ldmicro/resetdialog.cpp @@ -38,111 +38,111 @@ static LONG_PTR PrevNameProc; //----------------------------------------------------------------------------- // Don't allow any characters other than A-Za-z0-9_ in the name. //----------------------------------------------------------------------------- -static LRESULT CALLBACK MyNameProc(HWND hwnd, UINT msg, WPARAM wParam, - LPARAM lParam) -{ - if(msg == WM_CHAR) { - if(!(isalpha(wParam) || isdigit(wParam) || wParam == '_' || - wParam == '\b')) - { - return 0; - } - } - - return CallWindowProc((WNDPROC)PrevNameProc, hwnd, msg, wParam, lParam); -} - -static void MakeControls(void) -{ - HWND grouper = CreateWindowEx(0, WC_BUTTON, _("Type"), - WS_CHILD | BS_GROUPBOX | WS_VISIBLE, - 7, 3, 120, 65, ResetDialog, NULL, Instance, NULL); - NiceFont(grouper); - - TypeTimerRadio = CreateWindowEx(0, WC_BUTTON, _("Timer"), - WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE, - 16, 21, 100, 20, ResetDialog, NULL, Instance, NULL); - NiceFont(TypeTimerRadio); - - TypeCounterRadio = CreateWindowEx(0, WC_BUTTON, _("Counter"), - WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE, - 16, 41, 100, 20, ResetDialog, NULL, Instance, NULL); - NiceFont(TypeCounterRadio); - - HWND textLabel = CreateWindowEx(0, WC_STATIC, _("Name:"), - WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | SS_RIGHT, - 135, 16, 50, 21, ResetDialog, NULL, Instance, NULL); - NiceFont(textLabel); - - NameTextbox = CreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT, "", - WS_CHILD | ES_AUTOHSCROLL | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE, - 190, 16, 115, 21, ResetDialog, NULL, Instance, NULL); - FixedFont(NameTextbox); - - OkButton = CreateWindowEx(0, WC_BUTTON, _("OK"), - WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE | BS_DEFPUSHBUTTON, - 321, 10, 70, 23, ResetDialog, NULL, Instance, NULL); - NiceFont(OkButton); - - CancelButton = CreateWindowEx(0, WC_BUTTON, _("Cancel"), - WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE, - 321, 40, 70, 23, ResetDialog, NULL, Instance, NULL); - NiceFont(CancelButton); - - PrevNameProc = SetWindowLongPtr(NameTextbox, GWLP_WNDPROC, - (LONG_PTR)MyNameProc); -} - -void ShowResetDialog(char *name) -{ - ResetDialog = CreateWindowClient(0, "LDmicroDialog", - _("Reset"), WS_OVERLAPPED | WS_SYSMENU, - 100, 100, 404, 75, NULL, NULL, Instance, NULL); - - MakeControls(); +// static LRESULT CALLBACK MyNameProc(HWND hwnd, UINT msg, WPARAM wParam, +// LPARAM lParam) +// { +// if(msg == WM_CHAR) { +// if(!(isalpha(wParam) || isdigit(wParam) || wParam == '_' || +// wParam == '\b')) +// { +// return 0; +// } +// } + +// return CallWindowProc((WNDPROC)PrevNameProc, hwnd, msg, wParam, lParam); +// } + +// static void MakeControls(void) +// { +// HWND grouper = CreateWindowEx(0, WC_BUTTON, _("Type"), +// WS_CHILD | BS_GROUPBOX | WS_VISIBLE, +// 7, 3, 120, 65, ResetDialog, NULL, Instance, NULL); +// NiceFont(grouper); + +// TypeTimerRadio = CreateWindowEx(0, WC_BUTTON, _("Timer"), +// WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE, +// 16, 21, 100, 20, ResetDialog, NULL, Instance, NULL); +// NiceFont(TypeTimerRadio); + +// TypeCounterRadio = CreateWindowEx(0, WC_BUTTON, _("Counter"), +// WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE, +// 16, 41, 100, 20, ResetDialog, NULL, Instance, NULL); +// NiceFont(TypeCounterRadio); + +// HWND textLabel = CreateWindowEx(0, WC_STATIC, _("Name:"), +// WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | SS_RIGHT, +// 135, 16, 50, 21, ResetDialog, NULL, Instance, NULL); +// NiceFont(textLabel); + +// NameTextbox = CreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT, "", +// WS_CHILD | ES_AUTOHSCROLL | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE, +// 190, 16, 115, 21, ResetDialog, NULL, Instance, NULL); +// FixedFont(NameTextbox); + +// OkButton = CreateWindowEx(0, WC_BUTTON, _("OK"), +// WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE | BS_DEFPUSHBUTTON, +// 321, 10, 70, 23, ResetDialog, NULL, Instance, NULL); +// NiceFont(OkButton); + +// CancelButton = CreateWindowEx(0, WC_BUTTON, _("Cancel"), +// WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE, +// 321, 40, 70, 23, ResetDialog, NULL, Instance, NULL); +// NiceFont(CancelButton); + +// PrevNameProc = SetWindowLongPtr(NameTextbox, GWLP_WNDPROC, +// (LONG_PTR)MyNameProc); +// } + +// void ShowResetDialog(char *name) +// { +// ResetDialog = CreateWindowClient(0, "LDmicroDialog", +// _("Reset"), WS_OVERLAPPED | WS_SYSMENU, +// 100, 100, 404, 75, NULL, NULL, Instance, NULL); + +// MakeControls(); - if(name[0] == 'T') { - SendMessage(TypeTimerRadio, BM_SETCHECK, BST_CHECKED, 0); - } else { - SendMessage(TypeCounterRadio, BM_SETCHECK, BST_CHECKED, 0); - } - SendMessage(NameTextbox, WM_SETTEXT, 0, (LPARAM)(name + 1)); - - EnableWindow(MainWindow, FALSE); - ShowWindow(ResetDialog, TRUE); - SetFocus(NameTextbox); - SendMessage(NameTextbox, EM_SETSEL, 0, -1); - - MSG msg; - DWORD ret; - DialogDone = FALSE; - DialogCancel = FALSE; - while((ret = GetMessage(&msg, NULL, 0, 0)) && !DialogDone) { - if(msg.message == WM_KEYDOWN) { - if(msg.wParam == VK_RETURN) { - DialogDone = TRUE; - break; - } else if(msg.wParam == VK_ESCAPE) { - DialogDone = TRUE; - DialogCancel = TRUE; - break; - } - } - - if(IsDialogMessage(ResetDialog, &msg)) continue; - TranslateMessage(&msg); - DispatchMessage(&msg); - } - - if(!DialogCancel) { - if(SendMessage(TypeTimerRadio, BM_GETSTATE, 0, 0) & BST_CHECKED) { - name[0] = 'T'; - } else { - name[0] = 'C'; - } - SendMessage(NameTextbox, WM_GETTEXT, (WPARAM)16, (LPARAM)(name+1)); - } - - EnableWindow(MainWindow, TRUE); - DestroyWindow(ResetDialog); -} +// if(name[0] == 'T') { +// SendMessage(TypeTimerRadio, BM_SETCHECK, BST_CHECKED, 0); +// } else { +// SendMessage(TypeCounterRadio, BM_SETCHECK, BST_CHECKED, 0); +// } +// SendMessage(NameTextbox, WM_SETTEXT, 0, (LPARAM)(name + 1)); + +// EnableWindow(MainWindow, FALSE); +// ShowWindow(ResetDialog, TRUE); +// SetFocus(NameTextbox); +// SendMessage(NameTextbox, EM_SETSEL, 0, -1); + +// MSG msg; +// DWORD ret; +// DialogDone = FALSE; +// DialogCancel = FALSE; +// while((ret = GetMessage(&msg, NULL, 0, 0)) && !DialogDone) { +// if(msg.message == WM_KEYDOWN) { +// if(msg.wParam == VK_RETURN) { +// DialogDone = TRUE; +// break; +// } else if(msg.wParam == VK_ESCAPE) { +// DialogDone = TRUE; +// DialogCancel = TRUE; +// break; +// } +// } + +// if(IsDialogMessage(ResetDialog, &msg)) continue; +// TranslateMessage(&msg); +// DispatchMessage(&msg); +// } + +// if(!DialogCancel) { +// if(SendMessage(TypeTimerRadio, BM_GETSTATE, 0, 0) & BST_CHECKED) { +// name[0] = 'T'; +// } else { +// name[0] = 'C'; +// } +// SendMessage(NameTextbox, WM_GETTEXT, (WPARAM)16, (LPARAM)(name+1)); +// } + +// EnableWindow(MainWindow, TRUE); +// DestroyWindow(ResetDialog); +// } diff --git a/ldmicro/simpledialog.cpp b/ldmicro/simpledialog.cpp index 7edfc5c..14aab25 100644 --- a/ldmicro/simpledialog.cpp +++ b/ldmicro/simpledialog.cpp @@ -44,379 +44,379 @@ static BOOL NoCheckingOnBox[MAX_BOXES]; //----------------------------------------------------------------------------- // Don't allow any characters other than -A-Za-z0-9_ in the box. //----------------------------------------------------------------------------- -static LRESULT CALLBACK MyAlnumOnlyProc(HWND hwnd, UINT msg, WPARAM wParam, - LPARAM lParam) -{ - if(msg == WM_CHAR) { - if(!(isalpha(wParam) || isdigit(wParam) || wParam == '_' || - wParam == '\b' || wParam == '-' || wParam == '\'')) - { - return 0; - } - } - - int i; - for(i = 0; i < MAX_BOXES; i++) { - if(hwnd == Textboxes[i]) { - return CallWindowProc((WNDPROC)PrevAlnumOnlyProc[i], hwnd, msg, - wParam, lParam); - } - } - oops(); -} +// static LRESULT CALLBACK MyAlnumOnlyProc(HWND hwnd, UINT msg, WPARAM wParam, +// LPARAM lParam) +// { +// if(msg == WM_CHAR) { +// if(!(isalpha(wParam) || isdigit(wParam) || wParam == '_' || +// wParam == '\b' || wParam == '-' || wParam == '\'')) +// { +// return 0; +// } +// } + +// int i; +// for(i = 0; i < MAX_BOXES; i++) { +// if(hwnd == Textboxes[i]) { +// return CallWindowProc((WNDPROC)PrevAlnumOnlyProc[i], hwnd, msg, +// wParam, lParam); +// } +// } +// oops(); +// } //----------------------------------------------------------------------------- // Don't allow any characters other than -0-9. in the box. //----------------------------------------------------------------------------- -static LRESULT CALLBACK MyNumOnlyProc(HWND hwnd, UINT msg, WPARAM wParam, - LPARAM lParam) -{ - if(msg == WM_CHAR) { - if(!(isdigit(wParam) || wParam == '.' || wParam == '\b' - || wParam == '-')) - { - return 0; - } - } - - int i; - for(i = 0; i < MAX_BOXES; i++) { - if(hwnd == Textboxes[i]) { - return CallWindowProc((WNDPROC)PrevNumOnlyProc[i], hwnd, msg, - wParam, lParam); - } - } - oops(); -} - -static void MakeControls(int boxes, char **labels, DWORD fixedFontMask) -{ - int i; - HDC hdc = GetDC(SimpleDialog); - SelectObject(hdc, MyNiceFont); - - SIZE si; - - int maxLen = 0; - for(i = 0; i < boxes; i++) { - GetTextExtentPoint32(hdc, labels[i], strlen(labels[i]), &si); - if(si.cx > maxLen) maxLen = si.cx; - } - - int adj; - if(maxLen > 70) { - adj = maxLen - 70; - } else { - adj = 0; - } - - for(i = 0; i < boxes; i++) { - GetTextExtentPoint32(hdc, labels[i], strlen(labels[i]), &si); - - Labels[i] = CreateWindowEx(0, WC_STATIC, labels[i], - WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE, - (80 + adj) - si.cx - 4, 13 + i*30, si.cx, 21, - SimpleDialog, NULL, Instance, NULL); - NiceFont(Labels[i]); - - Textboxes[i] = CreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT, "", - WS_CHILD | ES_AUTOHSCROLL | WS_TABSTOP | WS_CLIPSIBLINGS | - WS_VISIBLE, - 80 + adj, 12 + 30*i, 120 - adj, 21, - SimpleDialog, NULL, Instance, NULL); - - if(fixedFontMask & (1 << i)) { - FixedFont(Textboxes[i]); - } else { - NiceFont(Textboxes[i]); - } - } - ReleaseDC(SimpleDialog, hdc); - - OkButton = CreateWindowEx(0, WC_BUTTON, _("OK"), - WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE | BS_DEFPUSHBUTTON, - 218, 11, 70, 23, SimpleDialog, NULL, Instance, NULL); - NiceFont(OkButton); - - CancelButton = CreateWindowEx(0, WC_BUTTON, _("Cancel"), - WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE, - 218, 41, 70, 23, SimpleDialog, NULL, Instance, NULL); - NiceFont(CancelButton); -} - -BOOL ShowSimpleDialog(char *title, int boxes, char **labels, DWORD numOnlyMask, - DWORD alnumOnlyMask, DWORD fixedFontMask, char **dests) -{ - BOOL didCancel; - - if(boxes > MAX_BOXES) oops(); - - SimpleDialog = CreateWindowClient(0, "LDmicroDialog", title, - WS_OVERLAPPED | WS_SYSMENU, - 100, 100, 304, 15 + 30*(boxes < 2 ? 2 : boxes), NULL, NULL, - Instance, NULL); - - MakeControls(boxes, labels, fixedFontMask); +// static LRESULT CALLBACK MyNumOnlyProc(HWND hwnd, UINT msg, WPARAM wParam, +// LPARAM lParam) +// { +// if(msg == WM_CHAR) { +// if(!(isdigit(wParam) || wParam == '.' || wParam == '\b' +// || wParam == '-')) +// { +// return 0; +// } +// } + +// int i; +// for(i = 0; i < MAX_BOXES; i++) { +// if(hwnd == Textboxes[i]) { +// return CallWindowProc((WNDPROC)PrevNumOnlyProc[i], hwnd, msg, +// wParam, lParam); +// } +// } +// oops(); +// } + +// static void MakeControls(int boxes, char **labels, DWORD fixedFontMask) +// { +// int i; +// HDC hdc = GetDC(SimpleDialog); +// SelectObject(hdc, MyNiceFont); + +// SIZE si; + +// int maxLen = 0; +// for(i = 0; i < boxes; i++) { +// GetTextExtentPoint32(hdc, labels[i], strlen(labels[i]), &si); +// if(si.cx > maxLen) maxLen = si.cx; +// } + +// int adj; +// if(maxLen > 70) { +// adj = maxLen - 70; +// } else { +// adj = 0; +// } + +// for(i = 0; i < boxes; i++) { +// GetTextExtentPoint32(hdc, labels[i], strlen(labels[i]), &si); + +// Labels[i] = CreateWindowEx(0, WC_STATIC, labels[i], +// WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE, +// (80 + adj) - si.cx - 4, 13 + i*30, si.cx, 21, +// SimpleDialog, NULL, Instance, NULL); +// NiceFont(Labels[i]); + +// Textboxes[i] = CreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT, "", +// WS_CHILD | ES_AUTOHSCROLL | WS_TABSTOP | WS_CLIPSIBLINGS | +// WS_VISIBLE, +// 80 + adj, 12 + 30*i, 120 - adj, 21, +// SimpleDialog, NULL, Instance, NULL); + +// if(fixedFontMask & (1 << i)) { +// FixedFont(Textboxes[i]); +// } else { +// NiceFont(Textboxes[i]); +// } +// } +// ReleaseDC(SimpleDialog, hdc); + +// OkButton = CreateWindowEx(0, WC_BUTTON, _("OK"), +// WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE | BS_DEFPUSHBUTTON, +// 218, 11, 70, 23, SimpleDialog, NULL, Instance, NULL); +// NiceFont(OkButton); + +// CancelButton = CreateWindowEx(0, WC_BUTTON, _("Cancel"), +// WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE, +// 218, 41, 70, 23, SimpleDialog, NULL, Instance, NULL); +// NiceFont(CancelButton); +// } + +// BOOL ShowSimpleDialog(char *title, int boxes, char **labels, DWORD numOnlyMask, +// DWORD alnumOnlyMask, DWORD fixedFontMask, char **dests) +// { +// BOOL didCancel; + +// if(boxes > MAX_BOXES) oops(); + +// SimpleDialog = CreateWindowClient(0, "LDmicroDialog", title, +// WS_OVERLAPPED | WS_SYSMENU, +// 100, 100, 304, 15 + 30*(boxes < 2 ? 2 : boxes), NULL, NULL, +// Instance, NULL); + +// MakeControls(boxes, labels, fixedFontMask); - int i; - for(i = 0; i < boxes; i++) { - SendMessage(Textboxes[i], WM_SETTEXT, 0, (LPARAM)dests[i]); - - if(numOnlyMask & (1 << i)) { - PrevNumOnlyProc[i] = SetWindowLongPtr(Textboxes[i], GWLP_WNDPROC, - (LONG_PTR)MyNumOnlyProc); - } - if(alnumOnlyMask & (1 << i)) { - PrevAlnumOnlyProc[i] = SetWindowLongPtr(Textboxes[i], GWLP_WNDPROC, - (LONG_PTR)MyAlnumOnlyProc); - } - } - - EnableWindow(MainWindow, FALSE); - ShowWindow(SimpleDialog, TRUE); - SetFocus(Textboxes[0]); - SendMessage(Textboxes[0], EM_SETSEL, 0, -1); - - MSG msg; - DWORD ret; - DialogDone = FALSE; - DialogCancel = FALSE; - while((ret = GetMessage(&msg, NULL, 0, 0)) && !DialogDone) { - if(msg.message == WM_KEYDOWN) { - if(msg.wParam == VK_RETURN) { - DialogDone = TRUE; - break; - } else if(msg.wParam == VK_ESCAPE) { - DialogDone = TRUE; - DialogCancel = TRUE; - break; - } - } - - if(IsDialogMessage(SimpleDialog, &msg)) continue; - TranslateMessage(&msg); - DispatchMessage(&msg); - } - - didCancel = DialogCancel; - - if(!didCancel) { - for(i = 0; i < boxes; i++) { - if(NoCheckingOnBox[i]) { - char get[64]; - SendMessage(Textboxes[i], WM_GETTEXT, 60, (LPARAM)get); - strcpy(dests[i], get); - } else { - char get[20]; - SendMessage(Textboxes[i], WM_GETTEXT, 15, (LPARAM)get); - - if( (!strchr(get, '\'')) || - (get[0] == '\'' && get[2] == '\'' && strlen(get)==3) ) - { - if(strlen(get) == 0) { - Error(_("Empty textbox; not permitted.")); - } else { - strcpy(dests[i], get); - } - } else { - Error(_("Bad use of quotes: <%s>"), get); - } - } - } - } - - EnableWindow(MainWindow, TRUE); - DestroyWindow(SimpleDialog); - - return !didCancel; -} - -void ShowTimerDialog(int which, int *delay, char *name) -{ - char *s; - switch(which) { - case ELEM_TON: s = _("Turn-On Delay"); break; - case ELEM_TOF: s = _("Turn-Off Delay"); break; - case ELEM_RTO: s = _("Retentive Turn-On Delay"); break; - default: oops(); break; - } +// int i; +// for(i = 0; i < boxes; i++) { +// SendMessage(Textboxes[i], WM_SETTEXT, 0, (LPARAM)dests[i]); + +// if(numOnlyMask & (1 << i)) { +// PrevNumOnlyProc[i] = SetWindowLongPtr(Textboxes[i], GWLP_WNDPROC, +// (LONG_PTR)MyNumOnlyProc); +// } +// if(alnumOnlyMask & (1 << i)) { +// PrevAlnumOnlyProc[i] = SetWindowLongPtr(Textboxes[i], GWLP_WNDPROC, +// (LONG_PTR)MyAlnumOnlyProc); +// } +// } + +// EnableWindow(MainWindow, FALSE); +// ShowWindow(SimpleDialog, TRUE); +// SetFocus(Textboxes[0]); +// SendMessage(Textboxes[0], EM_SETSEL, 0, -1); + +// MSG msg; +// DWORD ret; +// DialogDone = FALSE; +// DialogCancel = FALSE; +// while((ret = GetMessage(&msg, NULL, 0, 0)) && !DialogDone) { +// if(msg.message == WM_KEYDOWN) { +// if(msg.wParam == VK_RETURN) { +// DialogDone = TRUE; +// break; +// } else if(msg.wParam == VK_ESCAPE) { +// DialogDone = TRUE; +// DialogCancel = TRUE; +// break; +// } +// } + +// if(IsDialogMessage(SimpleDialog, &msg)) continue; +// TranslateMessage(&msg); +// DispatchMessage(&msg); +// } + +// didCancel = DialogCancel; + +// if(!didCancel) { +// for(i = 0; i < boxes; i++) { +// if(NoCheckingOnBox[i]) { +// char get[64]; +// SendMessage(Textboxes[i], WM_GETTEXT, 60, (LPARAM)get); +// strcpy(dests[i], get); +// } else { +// char get[20]; +// SendMessage(Textboxes[i], WM_GETTEXT, 15, (LPARAM)get); + +// if( (!strchr(get, '\'')) || +// (get[0] == '\'' && get[2] == '\'' && strlen(get)==3) ) +// { +// if(strlen(get) == 0) { +// Error(_("Empty textbox; not permitted.")); +// } else { +// strcpy(dests[i], get); +// } +// } else { +// Error(_("Bad use of quotes: <%s>"), get); +// } +// } +// } +// } + +// EnableWindow(MainWindow, TRUE); +// DestroyWindow(SimpleDialog); + +// return !didCancel; +// } + +// void ShowTimerDialog(int which, int *delay, char *name) +// { +// char *s; +// switch(which) { +// case ELEM_TON: s = _("Turn-On Delay"); break; +// case ELEM_TOF: s = _("Turn-Off Delay"); break; +// case ELEM_RTO: s = _("Retentive Turn-On Delay"); break; +// default: oops(); break; +// } - char *labels[] = { _("Name:"), _("Delay (ms):") }; - - char delBuf[16]; - char nameBuf[16]; - sprintf(delBuf, "%.3f", (*delay / 1000.0)); - strcpy(nameBuf, name+1); - char *dests[] = { nameBuf, delBuf }; - - if(ShowSimpleDialog(s, 2, labels, (1 << 1), (1 << 0), (1 << 0), dests)) { - name[0] = 'T'; - strcpy(name+1, nameBuf); - double del = atof(delBuf); - if(del > 2140000) { // 2**31/1000, don't overflow signed int - Error(_("Delay too long; maximum is 2**31 us.")); - } else if(del <= 0) { - Error(_("Delay cannot be zero or negative.")); - } else { - *delay = (int)(1000*del + 0.5); - } - } -} - -void ShowCounterDialog(int which, int *maxV, char *name) -{ - char *title; - - switch(which) { - case ELEM_CTU: title = _("Count Up"); break; - case ELEM_CTD: title = _("Count Down"); break; - case ELEM_CTC: title = _("Circular Counter"); break; - - default: oops(); - } - - char *labels[] = { _("Name:"), (which == ELEM_CTC ? _("Max value:") : - _("True if >= :")) }; - char maxS[128]; - sprintf(maxS, "%d", *maxV); - char *dests[] = { name+1, maxS }; - ShowSimpleDialog(title, 2, labels, 0x2, 0x1, 0x1, dests); - *maxV = atoi(maxS); -} - -void ShowCmpDialog(int which, char *op1, char *op2) -{ - char *title; - char *l2; - switch(which) { - case ELEM_EQU: - title = _("If Equals"); - l2 = "= :"; - break; - - case ELEM_NEQ: - title = _("If Not Equals"); - l2 = "/= :"; - break; - - case ELEM_GRT: - title = _("If Greater Than"); - l2 = "> :"; - break; - - case ELEM_GEQ: - title = _("If Greater Than or Equal To"); - l2 = ">= :"; - break; - - case ELEM_LES: - title = _("If Less Than"); - l2 = "< :"; - break; - - case ELEM_LEQ: - title = _("If Less Than or Equal To"); - l2 = "<= :"; - break; - - default: - oops(); - } - char *labels[] = { _("'Closed' if:"), l2 }; - char *dests[] = { op1, op2 }; - ShowSimpleDialog(title, 2, labels, 0, 0x3, 0x3, dests); -} - -void ShowMoveDialog(char *dest, char *src) -{ - char *labels[] = { _("Destination:"), _("Source:") }; - char *dests[] = { dest, src }; - ShowSimpleDialog(_("Move"), 2, labels, 0, 0x3, 0x3, dests); -} - -void ShowReadAdcDialog(char *name) -{ - char *labels[] = { _("Destination:") }; - char *dests[] = { name }; - ShowSimpleDialog(_("Read A/D Converter"), 1, labels, 0, 0x1, 0x1, dests); -} - -void ShowSetPwmDialog(char *name, int *targetFreq) -{ - char freq[100]; - sprintf(freq, "%d", *targetFreq); - - char *labels[] = { _("Duty cycle var:"), _("Frequency (Hz):") }; - char *dests[] = { name, freq }; - ShowSimpleDialog(_("Set PWM Duty Cycle"), 2, labels, 0x2, 0x1, 0x1, dests); - - *targetFreq = atoi(freq); -} - -void ShowUartDialog(int which, char *name) -{ - char *labels[] = { (which == ELEM_UART_RECV) ? _("Destination:") : - _("Source:") }; - char *dests[] = { name }; - - ShowSimpleDialog((which == ELEM_UART_RECV) ? _("Receive from UART") : - _("Send to UART"), 1, labels, 0, 0x1, 0x1, dests); -} - -void ShowMathDialog(int which, char *dest, char *op1, char *op2) -{ - char *l2, *title; - if(which == ELEM_ADD) { - l2 = "+ :"; - title = _("Add"); - } else if(which == ELEM_SUB) { - l2 = "- :"; - title = _("Subtract"); - } else if(which == ELEM_MUL) { - l2 = "* :"; - title = _("Multiply"); - } else if(which == ELEM_DIV) { - l2 = "/ :"; - title = _("Divide"); - } else oops(); - - char *labels[] = { _("Destination:"), _("is set := :"), l2 }; - char *dests[] = { dest, op1, op2 }; - ShowSimpleDialog(title, 3, labels, 0, 0x7, 0x7, dests); -} - -void ShowShiftRegisterDialog(char *name, int *stages) -{ - char stagesStr[20]; - sprintf(stagesStr, "%d", *stages); - - char *labels[] = { _("Name:"), _("Stages:") }; - char *dests[] = { name, stagesStr }; - ShowSimpleDialog(_("Shift Register"), 2, labels, 0x2, 0x1, 0x1, dests); - - *stages = atoi(stagesStr); - - if(*stages <= 0 || *stages >= 200) { - Error(_("Not a reasonable size for a shift register.")); - *stages = 1; - } -} - -void ShowFormattedStringDialog(char *var, char *string) -{ - char *labels[] = { _("Variable:"), _("String:") }; - char *dests[] = { var, string }; - NoCheckingOnBox[0] = TRUE; - NoCheckingOnBox[1] = TRUE; - ShowSimpleDialog(_("Formatted String Over UART"), 2, labels, 0x0, - 0x1, 0x3, dests); - NoCheckingOnBox[0] = FALSE; - NoCheckingOnBox[1] = FALSE; -} - -void ShowPersistDialog(char *var) -{ - char *labels[] = { _("Variable:") }; - char *dests[] = { var }; - ShowSimpleDialog(_("Make Persistent"), 1, labels, 0, 1, 1, dests); -} +// char *labels[] = { _("Name:"), _("Delay (ms):") }; + +// char delBuf[16]; +// char nameBuf[16]; +// sprintf(delBuf, "%.3f", (*delay / 1000.0)); +// strcpy(nameBuf, name+1); +// char *dests[] = { nameBuf, delBuf }; + +// if(ShowSimpleDialog(s, 2, labels, (1 << 1), (1 << 0), (1 << 0), dests)) { +// name[0] = 'T'; +// strcpy(name+1, nameBuf); +// double del = atof(delBuf); +// if(del > 2140000) { // 2**31/1000, don't overflow signed int +// Error(_("Delay too long; maximum is 2**31 us.")); +// } else if(del <= 0) { +// Error(_("Delay cannot be zero or negative.")); +// } else { +// *delay = (int)(1000*del + 0.5); +// } +// } +// } + +// void ShowCounterDialog(int which, int *maxV, char *name) +// { +// char *title; + +// switch(which) { +// case ELEM_CTU: title = _("Count Up"); break; +// case ELEM_CTD: title = _("Count Down"); break; +// case ELEM_CTC: title = _("Circular Counter"); break; + +// default: oops(); +// } + +// char *labels[] = { _("Name:"), (which == ELEM_CTC ? _("Max value:") : +// _("True if >= :")) }; +// char maxS[128]; +// sprintf(maxS, "%d", *maxV); +// char *dests[] = { name+1, maxS }; +// ShowSimpleDialog(title, 2, labels, 0x2, 0x1, 0x1, dests); +// *maxV = atoi(maxS); +// } + +// void ShowCmpDialog(int which, char *op1, char *op2) +// { +// char *title; +// char *l2; +// switch(which) { +// case ELEM_EQU: +// title = _("If Equals"); +// l2 = "= :"; +// break; + +// case ELEM_NEQ: +// title = _("If Not Equals"); +// l2 = "/= :"; +// break; + +// case ELEM_GRT: +// title = _("If Greater Than"); +// l2 = "> :"; +// break; + +// case ELEM_GEQ: +// title = _("If Greater Than or Equal To"); +// l2 = ">= :"; +// break; + +// case ELEM_LES: +// title = _("If Less Than"); +// l2 = "< :"; +// break; + +// case ELEM_LEQ: +// title = _("If Less Than or Equal To"); +// l2 = "<= :"; +// break; + +// default: +// oops(); +// } +// char *labels[] = { _("'Closed' if:"), l2 }; +// char *dests[] = { op1, op2 }; +// ShowSimpleDialog(title, 2, labels, 0, 0x3, 0x3, dests); +// } + +// void ShowMoveDialog(char *dest, char *src) +// { +// char *labels[] = { _("Destination:"), _("Source:") }; +// char *dests[] = { dest, src }; +// ShowSimpleDialog(_("Move"), 2, labels, 0, 0x3, 0x3, dests); +// } + +// void ShowReadAdcDialog(char *name) +// { +// char *labels[] = { _("Destination:") }; +// char *dests[] = { name }; +// ShowSimpleDialog(_("Read A/D Converter"), 1, labels, 0, 0x1, 0x1, dests); +// } + +// void ShowSetPwmDialog(char *name, int *targetFreq) +// { +// char freq[100]; +// sprintf(freq, "%d", *targetFreq); + +// char *labels[] = { _("Duty cycle var:"), _("Frequency (Hz):") }; +// char *dests[] = { name, freq }; +// ShowSimpleDialog(_("Set PWM Duty Cycle"), 2, labels, 0x2, 0x1, 0x1, dests); + +// *targetFreq = atoi(freq); +// } + +// void ShowUartDialog(int which, char *name) +// { +// char *labels[] = { (which == ELEM_UART_RECV) ? _("Destination:") : +// _("Source:") }; +// char *dests[] = { name }; + +// ShowSimpleDialog((which == ELEM_UART_RECV) ? _("Receive from UART") : +// _("Send to UART"), 1, labels, 0, 0x1, 0x1, dests); +// } + +// void ShowMathDialog(int which, char *dest, char *op1, char *op2) +// { +// char *l2, *title; +// if(which == ELEM_ADD) { +// l2 = "+ :"; +// title = _("Add"); +// } else if(which == ELEM_SUB) { +// l2 = "- :"; +// title = _("Subtract"); +// } else if(which == ELEM_MUL) { +// l2 = "* :"; +// title = _("Multiply"); +// } else if(which == ELEM_DIV) { +// l2 = "/ :"; +// title = _("Divide"); +// } else oops(); + +// char *labels[] = { _("Destination:"), _("is set := :"), l2 }; +// char *dests[] = { dest, op1, op2 }; +// ShowSimpleDialog(title, 3, labels, 0, 0x7, 0x7, dests); +// } + +// void ShowShiftRegisterDialog(char *name, int *stages) +// { +// char stagesStr[20]; +// sprintf(stagesStr, "%d", *stages); + +// char *labels[] = { _("Name:"), _("Stages:") }; +// char *dests[] = { name, stagesStr }; +// ShowSimpleDialog(_("Shift Register"), 2, labels, 0x2, 0x1, 0x1, dests); + +// *stages = atoi(stagesStr); + +// if(*stages <= 0 || *stages >= 200) { +// Error(_("Not a reasonable size for a shift register.")); +// *stages = 1; +// } +// } + +// void ShowFormattedStringDialog(char *var, char *string) +// { +// char *labels[] = { _("Variable:"), _("String:") }; +// char *dests[] = { var, string }; +// NoCheckingOnBox[0] = TRUE; +// NoCheckingOnBox[1] = TRUE; +// ShowSimpleDialog(_("Formatted String Over UART"), 2, labels, 0x0, +// 0x1, 0x3, dests); +// NoCheckingOnBox[0] = FALSE; +// NoCheckingOnBox[1] = FALSE; +// } + +// void ShowPersistDialog(char *var) +// { +// char *labels[] = { _("Variable:") }; +// char *dests[] = { var }; +// ShowSimpleDialog(_("Make Persistent"), 1, labels, 0, 1, 1, dests); +// } diff --git a/ldmicro/simulate.cpp b/ldmicro/simulate.cpp index 57da046..ecb9b0e 100644 --- a/ldmicro/simulate.cpp +++ b/ldmicro/simulate.cpp @@ -31,9 +31,8 @@ #include <limits.h> #include "ldmicro.h" -#include "simulate.h" #include "intcode.h" -#include "freeze.h" +#include "freezeLD.h" static struct { char name[MAX_NAME_LEN]; @@ -107,125 +106,117 @@ static char *MarkUsedVariable(char *name, DWORD flag); // Looks in the SingleBitItems list; if an item is not present then it is // FALSE by default. //----------------------------------------------------------------------------- -static BOOL SingleBitOn(char *name) -{ - int i; - for(i = 0; i < SingleBitItemsCount; i++) { - if(strcmp(SingleBitItems[i].name, name)==0) { - return SingleBitItems[i].powered; - } - } - return FALSE; -} +// static BOOL SingleBitOn(char *name) +// { +// int i; +// for(i = 0; i < SingleBitItemsCount; i++) { +// if(strcmp(SingleBitItems[i].name, name)==0) { +// return SingleBitItems[i].powered; +// } +// } +// return FALSE; +// } //----------------------------------------------------------------------------- // Set the state of a single-bit item. Adds it to the list if it is not there // already. //----------------------------------------------------------------------------- -static void SetSingleBit(char *name, BOOL state) -{ - int i; - for(i = 0; i < SingleBitItemsCount; i++) { - if(strcmp(SingleBitItems[i].name, name)==0) { - if((name[0] == 'Y') && (SingleBitItems[i].powered != state)) - { - TranslateState(name, state); - /*char Debug[256]; - sprintf_s(Debug, "SetSingleBit: \tname: %s \t state: %d\n", - name, state); - OutputDebugString(Debug);*/ - } - SingleBitItems[i].powered = state; - return; - } - } - if(i < MAX_IO) { - strcpy(SingleBitItems[i].name, name); - SingleBitItems[i].powered = state; - SingleBitItemsCount++; - } -} +// static void SetSingleBit(char *name, BOOL state) +// { +// int i; +// for(i = 0; i < SingleBitItemsCount; i++) { +// if(strcmp(SingleBitItems[i].name, name)==0) { +// SingleBitItems[i].powered = state; +// return; +// } +// } +// if(i < MAX_IO) { +// strcpy(SingleBitItems[i].name, name); +// SingleBitItems[i].powered = state; +// SingleBitItemsCount++; +// } +// } //----------------------------------------------------------------------------- // Count a timer up (i.e. increment its associated count by 1). Must already // exist in the table. //----------------------------------------------------------------------------- -static void IncrementVariable(char *name) -{ - int i; - for(i = 0; i < VariablesCount; i++) { - if(strcmp(Variables[i].name, name)==0) { - (Variables[i].val)++; - return; - } - } - oops(); -} +// static void IncrementVariable(char *name) +// { +// int i; +// for(i = 0; i < VariablesCount; i++) { +// if(strcmp(Variables[i].name, name)==0) { +// (Variables[i].val)++; +// return; +// } +// } +// oops(); +// } //----------------------------------------------------------------------------- // Set a variable to a value. //----------------------------------------------------------------------------- -static void SetSimulationVariable(char *name, SWORD val) -{ - int i; - for(i = 0; i < VariablesCount; i++) { - if(strcmp(Variables[i].name, name)==0) { - Variables[i].val = val; - return; - } - } - MarkUsedVariable(name, VAR_FLAG_OTHERWISE_FORGOTTEN); - SetSimulationVariable(name, val); -} +// static void SetSimulationVariable(char *name, SWORD val) +// { +// int i; +// for(i = 0; i < VariablesCount; i++) { +// if(strcmp(Variables[i].name, name)==0) { +// Variables[i].val = val; +// return; +// } +// } +// MarkUsedVariable(name, VAR_FLAG_OTHERWISE_FORGOTTEN); +// SetSimulationVariable(name, val); +// } //----------------------------------------------------------------------------- // Read a variable's value. //----------------------------------------------------------------------------- -SWORD GetSimulationVariable(char *name) -{ - int i; - for(i = 0; i < VariablesCount; i++) { - if(strcmp(Variables[i].name, name)==0) { - return Variables[i].val; - } - } - MarkUsedVariable(name, VAR_FLAG_OTHERWISE_FORGOTTEN); - return GetSimulationVariable(name); -} +// SWORD GetSimulationVariable(char *name) +// { +// int i; +// for(i = 0; i < VariablesCount; i++) { +// if(strcmp(Variables[i].name, name)==0) { +// return Variables[i].val; +// } +// } +// MarkUsedVariable(name, VAR_FLAG_OTHERWISE_FORGOTTEN); +// return GetSimulationVariable(name); +// } //----------------------------------------------------------------------------- // Set the shadow copy of a variable associated with a READ ADC operation. This // will get committed to the real copy when the rung-in condition to the // READ ADC is true. //----------------------------------------------------------------------------- -void SetAdcShadow(char *name, SWORD val) -{ - int i; - for(i = 0; i < AdcShadowsCount; i++) { - if(strcmp(AdcShadows[i].name, name)==0) { - AdcShadows[i].val = val; - return; - } - } - strcpy(AdcShadows[i].name, name); - AdcShadows[i].val = val; - AdcShadowsCount++; -} +// void SetAdcShadow(char *name, SWORD val) +// { +// int i; +// for(i = 0; i < AdcShadowsCount; i++) { +// if(strcmp(AdcShadows[i].name, name)==0) { +// AdcShadows[i].val = val; +// return; +// } +// } +// strcpy(AdcShadows[i].name, name); +// AdcShadows[i].val = val; +// AdcShadowsCount++; +// } //----------------------------------------------------------------------------- // Return the shadow value of a variable associated with a READ ADC. This is // what gets copied into the real variable when an ADC read is simulated. //----------------------------------------------------------------------------- -SWORD GetAdcShadow(char *name) -{ - int i; - for(i = 0; i < AdcShadowsCount; i++) { - if(strcmp(AdcShadows[i].name, name)==0) { - return AdcShadows[i].val; - } - } - return 0; -} +// SWORD GetAdcShadow(char *name) +// { +// int i; +// for(i = 0; i < AdcShadowsCount; i++) { +// if(strcmp(AdcShadows[i].name, name)==0) { +// return AdcShadows[i].val; +// } +// } +// return 0; +// } //----------------------------------------------------------------------------- // Mark how a variable is used; a series of flags that we can OR together, @@ -233,62 +224,62 @@ SWORD GetAdcShadow(char *name) // (e.g. just a TON, an RTO with its reset, etc.). Returns NULL for success, // else an error string. //----------------------------------------------------------------------------- -static char *MarkUsedVariable(char *name, DWORD flag) -{ - int i; - for(i = 0; i < VariablesCount; i++) { - if(strcmp(Variables[i].name, name)==0) { - break; - } - } - if(i >= MAX_IO) return ""; - - if(i == VariablesCount) { - strcpy(Variables[i].name, name); - Variables[i].usedFlags = 0; - Variables[i].val = 0; - VariablesCount++; - } - - switch(flag) { - case VAR_FLAG_TOF: - if(Variables[i].usedFlags != 0) - return _("TOF: variable cannot be used elsewhere"); - break; - - case VAR_FLAG_TON: - if(Variables[i].usedFlags != 0) - return _("TON: variable cannot be used elsewhere"); - break; +// static char *MarkUsedVariable(char *name, DWORD flag) +// { +// int i; +// for(i = 0; i < VariablesCount; i++) { +// if(strcmp(Variables[i].name, name)==0) { +// break; +// } +// } +// if(i >= MAX_IO) return ""; + +// if(i == VariablesCount) { +// strcpy(Variables[i].name, name); +// Variables[i].usedFlags = 0; +// Variables[i].val = 0; +// VariablesCount++; +// } + +// switch(flag) { +// case VAR_FLAG_TOF: +// if(Variables[i].usedFlags != 0) +// return _("TOF: variable cannot be used elsewhere"); +// break; + +// case VAR_FLAG_TON: +// if(Variables[i].usedFlags != 0) +// return _("TON: variable cannot be used elsewhere"); +// break; - case VAR_FLAG_RTO: - if(Variables[i].usedFlags & ~VAR_FLAG_RES) - return _("RTO: variable can only be used for RES elsewhere"); - break; - - case VAR_FLAG_CTU: - case VAR_FLAG_CTD: - case VAR_FLAG_CTC: - case VAR_FLAG_RES: - case VAR_FLAG_ANY: - break; - - case VAR_FLAG_OTHERWISE_FORGOTTEN: - if(name[0] != '$') { - Error(_("Variable '%s' not assigned to, e.g. with a " - "MOV statement, an ADD statement, etc.\r\n\r\n" - "This is probably a programming error; now it " - "will always be zero."), name); - } - break; - - default: - oops(); - } - - Variables[i].usedFlags |= flag; - return NULL; -} +// case VAR_FLAG_RTO: +// if(Variables[i].usedFlags & ~VAR_FLAG_RES) +// return _("RTO: variable can only be used for RES elsewhere"); +// break; + +// case VAR_FLAG_CTU: +// case VAR_FLAG_CTD: +// case VAR_FLAG_CTC: +// case VAR_FLAG_RES: +// case VAR_FLAG_ANY: +// break; + +// case VAR_FLAG_OTHERWISE_FORGOTTEN: +// if(name[0] != '$') { +// Error(_("Variable '%s' not assigned to, e.g. with a " +// "MOV statement, an ADD statement, etc.\r\n\r\n" +// "This is probably a programming error; now it " +// "will always be zero."), name); +// } +// break; + +// default: +// oops(); +// } + +// Variables[i].usedFlags |= flag; +// return NULL; +// } //----------------------------------------------------------------------------- // Check for duplicate uses of a single variable. For example, there should @@ -296,205 +287,207 @@ static char *MarkUsedVariable(char *name, DWORD flag) // to have an RTO with the same name as its reset; in fact, verify that // there must be a reset for each RTO. //----------------------------------------------------------------------------- -static void MarkWithCheck(char *name, int flag) -{ - char *s = MarkUsedVariable(name, flag); - if(s) { - Error(_("Variable for '%s' incorrectly assigned: %s."), name, s); - } -} -static void CheckVariableNamesCircuit(int which, void *elem) -{ - ElemLeaf *l = (ElemLeaf *)elem; - char *name = NULL; - DWORD flag; - - switch(which) { - case ELEM_SERIES_SUBCKT: { - int i; - ElemSubcktSeries *s = (ElemSubcktSeries *)elem; - for(i = 0; i < s->count; i++) { - CheckVariableNamesCircuit(s->contents[i].which, - s->contents[i].d.any); - } - break; - } - - case ELEM_PARALLEL_SUBCKT: { - int i; - ElemSubcktParallel *p = (ElemSubcktParallel *)elem; - for(i = 0; i < p->count; i++) { - CheckVariableNamesCircuit(p->contents[i].which, - p->contents[i].d.any); - } - break; - } +// static void MarkWithCheck(char *name, int flag) +// { +// char *s = MarkUsedVariable(name, flag); +// if(s) { +// Error(_("Variable for '%s' incorrectly assigned: %s."), name, s); +// } +// } + +// static void CheckVariableNamesCircuit(int which, void *elem) +// { +// ElemLeaf *l = (ElemLeaf *)elem; +// char *name = NULL; +// DWORD flag; + +// switch(which) { +// case ELEM_SERIES_SUBCKT: { +// int i; +// ElemSubcktSeries *s = (ElemSubcktSeries *)elem; +// for(i = 0; i < s->count; i++) { +// CheckVariableNamesCircuit(s->contents[i].which, +// s->contents[i].d.any); +// } +// break; +// } + +// case ELEM_PARALLEL_SUBCKT: { +// int i; +// ElemSubcktParallel *p = (ElemSubcktParallel *)elem; +// for(i = 0; i < p->count; i++) { +// CheckVariableNamesCircuit(p->contents[i].which, +// p->contents[i].d.any); +// } +// break; +// } - case ELEM_RTO: - case ELEM_TOF: - case ELEM_TON: - if(which == ELEM_RTO) - flag = VAR_FLAG_RTO; - else if(which == ELEM_TOF) - flag = VAR_FLAG_TOF; - else if(which == ELEM_TON) - flag = VAR_FLAG_TON; - else oops(); - - MarkWithCheck(l->d.timer.name, flag); - - break; - - case ELEM_CTU: - case ELEM_CTD: - case ELEM_CTC: - if(which == ELEM_CTU) - flag = VAR_FLAG_CTU; - else if(which == ELEM_CTD) - flag = VAR_FLAG_CTD; - else if(which == ELEM_CTC) - flag = VAR_FLAG_CTC; - else oops(); - - MarkWithCheck(l->d.counter.name, flag); - - break; - - case ELEM_RES: - MarkWithCheck(l->d.reset.name, VAR_FLAG_RES); - break; - - case ELEM_MOVE: - MarkWithCheck(l->d.move.dest, VAR_FLAG_ANY); - break; - - case ELEM_LOOK_UP_TABLE: - MarkWithCheck(l->d.lookUpTable.dest, VAR_FLAG_ANY); - break; - - case ELEM_PIECEWISE_LINEAR: - MarkWithCheck(l->d.piecewiseLinear.dest, VAR_FLAG_ANY); - break; - - case ELEM_READ_ADC: - MarkWithCheck(l->d.readAdc.name, VAR_FLAG_ANY); - break; - - case ELEM_ADD: - case ELEM_SUB: - case ELEM_MUL: - case ELEM_DIV: - MarkWithCheck(l->d.math.dest, VAR_FLAG_ANY); - break; - - case ELEM_UART_RECV: - MarkWithCheck(l->d.uart.name, VAR_FLAG_ANY); - break; - - case ELEM_SHIFT_REGISTER: { - int i; - for(i = 1; i < l->d.shiftRegister.stages; i++) { - char str[MAX_NAME_LEN+10]; - sprintf(str, "%s%d", l->d.shiftRegister.name, i); - MarkWithCheck(str, VAR_FLAG_ANY); - } - break; - } - - case ELEM_PERSIST: - case ELEM_FORMATTED_STRING: - case ELEM_SET_PWM: - case ELEM_MASTER_RELAY: - case ELEM_UART_SEND: - case ELEM_PLACEHOLDER: - case ELEM_COMMENT: - case ELEM_OPEN: - case ELEM_SHORT: - case ELEM_COIL: - case ELEM_CONTACTS: - case ELEM_ONE_SHOT_RISING: - case ELEM_ONE_SHOT_FALLING: - case ELEM_EQU: - case ELEM_NEQ: - case ELEM_GRT: - case ELEM_GEQ: - case ELEM_LES: - case ELEM_LEQ: - break; - - default: - oops(); - } -} -static void CheckVariableNames(void) -{ - int i; - for(i = 0; i < Prog.numRungs; i++) { - CheckVariableNamesCircuit(ELEM_SERIES_SUBCKT, Prog.rungs[i]); - } -} +// case ELEM_RTO: +// case ELEM_TOF: +// case ELEM_TON: +// if(which == ELEM_RTO) +// flag = VAR_FLAG_RTO; +// else if(which == ELEM_TOF) +// flag = VAR_FLAG_TOF; +// else if(which == ELEM_TON) +// flag = VAR_FLAG_TON; +// else oops(); + +// MarkWithCheck(l->d.timer.name, flag); + +// break; + +// case ELEM_CTU: +// case ELEM_CTD: +// case ELEM_CTC: +// if(which == ELEM_CTU) +// flag = VAR_FLAG_CTU; +// else if(which == ELEM_CTD) +// flag = VAR_FLAG_CTD; +// else if(which == ELEM_CTC) +// flag = VAR_FLAG_CTC; +// else oops(); + +// MarkWithCheck(l->d.counter.name, flag); + +// break; + +// case ELEM_RES: +// MarkWithCheck(l->d.reset.name, VAR_FLAG_RES); +// break; + +// case ELEM_MOVE: +// MarkWithCheck(l->d.move.dest, VAR_FLAG_ANY); +// break; + +// case ELEM_LOOK_UP_TABLE: +// MarkWithCheck(l->d.lookUpTable.dest, VAR_FLAG_ANY); +// break; + +// case ELEM_PIECEWISE_LINEAR: +// MarkWithCheck(l->d.piecewiseLinear.dest, VAR_FLAG_ANY); +// break; + +// case ELEM_READ_ADC: +// MarkWithCheck(l->d.readAdc.name, VAR_FLAG_ANY); +// break; + +// case ELEM_ADD: +// case ELEM_SUB: +// case ELEM_MUL: +// case ELEM_DIV: +// MarkWithCheck(l->d.math.dest, VAR_FLAG_ANY); +// break; + +// case ELEM_UART_RECV: +// MarkWithCheck(l->d.uart.name, VAR_FLAG_ANY); +// break; + +// case ELEM_SHIFT_REGISTER: { +// int i; +// for(i = 1; i < l->d.shiftRegister.stages; i++) { +// char str[MAX_NAME_LEN+10]; +// sprintf(str, "%s%d", l->d.shiftRegister.name, i); +// MarkWithCheck(str, VAR_FLAG_ANY); +// } +// break; +// } + +// case ELEM_PERSIST: +// case ELEM_FORMATTED_STRING: +// case ELEM_SET_PWM: +// case ELEM_MASTER_RELAY: +// case ELEM_UART_SEND: +// case ELEM_PLACEHOLDER: +// case ELEM_COMMENT: +// case ELEM_OPEN: +// case ELEM_SHORT: +// case ELEM_COIL: +// case ELEM_CONTACTS: +// case ELEM_ONE_SHOT_RISING: +// case ELEM_ONE_SHOT_FALLING: +// case ELEM_EQU: +// case ELEM_NEQ: +// case ELEM_GRT: +// case ELEM_GEQ: +// case ELEM_LES: +// case ELEM_LEQ: +// break; + +// default: +// oops(); +// } +// } + +// static void CheckVariableNames(void) +// { +// int i; +// for(i = 0; i < Prog.numRungs; i++) { +// CheckVariableNamesCircuit(ELEM_SERIES_SUBCKT, Prog.rungs[i]); +// } +// } //----------------------------------------------------------------------------- // The IF condition is true. Execute the body, up until the ELSE or the // END IF, and then skip the ELSE if it is present. Called with PC on the // IF, returns with PC on the END IF. //----------------------------------------------------------------------------- -static void IfConditionTrue(void) -{ - IntPc++; - // now PC is on the first statement of the IF body - SimulateIntCode(); - // now PC is on the ELSE or the END IF - if(IntCode[IntPc].op == INT_ELSE) { - int nesting = 1; - for(; ; IntPc++) { - if(IntPc >= IntCodeLen) oops(); - - if(IntCode[IntPc].op == INT_END_IF) { - nesting--; - } else if(INT_IF_GROUP(IntCode[IntPc].op)) { - nesting++; - } - if(nesting == 0) break; - } - } else if(IntCode[IntPc].op == INT_END_IF) { - return; - } else { - oops(); - } -} +// static void IfConditionTrue(void) +// { +// IntPc++; +// // now PC is on the first statement of the IF body +// SimulateIntCode(); +// // now PC is on the ELSE or the END IF +// if(IntCode[IntPc].op == INT_ELSE) { +// int nesting = 1; +// for(; ; IntPc++) { +// if(IntPc >= IntCodeLen) oops(); + +// if(IntCode[IntPc].op == INT_END_IF) { +// nesting--; +// } else if(INT_IF_GROUP(IntCode[IntPc].op)) { +// nesting++; +// } +// if(nesting == 0) break; +// } +// } else if(IntCode[IntPc].op == INT_END_IF) { +// return; +// } else { +// oops(); +// } +// } //----------------------------------------------------------------------------- // The IF condition is false. Skip the body, up until the ELSE or the END // IF, and then execute the ELSE if it is present. Called with PC on the IF, // returns with PC on the END IF. //----------------------------------------------------------------------------- -static void IfConditionFalse(void) -{ - int nesting = 0; - for(; ; IntPc++) { - if(IntPc >= IntCodeLen) oops(); - - if(IntCode[IntPc].op == INT_END_IF) { - nesting--; - } else if(INT_IF_GROUP(IntCode[IntPc].op)) { - nesting++; - } else if(IntCode[IntPc].op == INT_ELSE && nesting == 1) { - break; - } - if(nesting == 0) break; - } - - // now PC is on the ELSE or the END IF - if(IntCode[IntPc].op == INT_ELSE) { - IntPc++; - SimulateIntCode(); - } else if(IntCode[IntPc].op == INT_END_IF) { - return; - } else { - oops(); - } -} +// static void IfConditionFalse(void) +// { +// int nesting = 0; +// for(; ; IntPc++) { +// if(IntPc >= IntCodeLen) oops(); + +// if(IntCode[IntPc].op == INT_END_IF) { +// nesting--; +// } else if(INT_IF_GROUP(IntCode[IntPc].op)) { +// nesting++; +// } else if(IntCode[IntPc].op == INT_ELSE && nesting == 1) { +// break; +// } +// if(nesting == 0) break; +// } + +// // now PC is on the ELSE or the END IF +// if(IntCode[IntPc].op == INT_ELSE) { +// IntPc++; +// SimulateIntCode(); +// } else if(IntCode[IntPc].op == INT_END_IF) { +// return; +// } else { +// oops(); +// } +// } //----------------------------------------------------------------------------- // Evaluate a circuit, calling ourselves recursively to evaluate if/else @@ -502,229 +495,229 @@ static void IfConditionFalse(void) // internal tables. Returns when it reaches an end if or an else construct, // or at the end of the program. //----------------------------------------------------------------------------- -static void SimulateIntCode(void) -{ - for(; IntPc < IntCodeLen; IntPc++) { - IntOp *a = &IntCode[IntPc]; - switch(a->op) { - case INT_SIMULATE_NODE_STATE: - if(*(a->poweredAfter) != SingleBitOn(a->name1)) - NeedRedraw = TRUE; - *(a->poweredAfter) = SingleBitOn(a->name1); - break; - - case INT_SET_BIT: - SetSingleBit(a->name1, TRUE); - break; - - case INT_CLEAR_BIT: - SetSingleBit(a->name1, FALSE); - break; - - case INT_COPY_BIT_TO_BIT: - SetSingleBit(a->name1, SingleBitOn(a->name2)); - break; - - case INT_SET_VARIABLE_TO_LITERAL: - if(GetSimulationVariable(a->name1) != - a->literal && a->name1[0] != '$') - { - NeedRedraw = TRUE; - } - SetSimulationVariable(a->name1, a->literal); - break; - - case INT_SET_VARIABLE_TO_VARIABLE: - if(GetSimulationVariable(a->name1) != - GetSimulationVariable(a->name2)) - { - NeedRedraw = TRUE; - } - SetSimulationVariable(a->name1, - GetSimulationVariable(a->name2)); - break; - - case INT_INCREMENT_VARIABLE: - IncrementVariable(a->name1); - break; - - { - SWORD v; - case INT_SET_VARIABLE_ADD: - v = GetSimulationVariable(a->name2) + - GetSimulationVariable(a->name3); - goto math; - case INT_SET_VARIABLE_SUBTRACT: - v = GetSimulationVariable(a->name2) - - GetSimulationVariable(a->name3); - goto math; - case INT_SET_VARIABLE_MULTIPLY: - v = GetSimulationVariable(a->name2) * - GetSimulationVariable(a->name3); - goto math; - case INT_SET_VARIABLE_DIVIDE: - if(GetSimulationVariable(a->name3) != 0) { - v = GetSimulationVariable(a->name2) / - GetSimulationVariable(a->name3); - } else { - v = 0; - Error(_("Division by zero; halting simulation")); - StopSimulation(); - } - goto math; -math: - if(GetSimulationVariable(a->name1) != v) { - NeedRedraw = TRUE; - SetSimulationVariable(a->name1, v); - } - break; - } - -#define IF_BODY \ - { \ - IfConditionTrue(); \ - } else { \ - IfConditionFalse(); \ - } - case INT_IF_BIT_SET: - if(SingleBitOn(a->name1)) - IF_BODY - break; - - case INT_IF_BIT_CLEAR: - if(!SingleBitOn(a->name1)) - IF_BODY - break; - - case INT_IF_VARIABLE_LES_LITERAL: - if(GetSimulationVariable(a->name1) < a->literal) - IF_BODY - break; - - case INT_IF_VARIABLE_EQUALS_VARIABLE: - if(GetSimulationVariable(a->name1) == - GetSimulationVariable(a->name2)) - IF_BODY - break; - - case INT_IF_VARIABLE_GRT_VARIABLE: - if(GetSimulationVariable(a->name1) > - GetSimulationVariable(a->name2)) - IF_BODY - break; - - case INT_SET_PWM: - // Dummy call will cause a warning if no one ever assigned - // to that variable. - (void)GetSimulationVariable(a->name1); - break; - - // Don't try to simulate the EEPROM stuff: just hold the EEPROM - // busy all the time, so that the program never does anything - // with it. - case INT_EEPROM_BUSY_CHECK: - SetSingleBit(a->name1, TRUE); - break; - - case INT_EEPROM_READ: - case INT_EEPROM_WRITE: - oops(); - break; - - case INT_READ_ADC: - // Keep the shadow copies of the ADC variables because in - // the real device they will not be updated until an actual - // read is performed, which occurs only for a true rung-in - // condition there. - SetSimulationVariable(a->name1, GetAdcShadow(a->name1)); - break; - - case INT_UART_SEND: - if(SingleBitOn(a->name2) && (SimulateUartTxCountdown == 0)) { - SimulateUartTxCountdown = 2; - AppendToUartSimulationTextControl( - (BYTE)GetSimulationVariable(a->name1)); - } - if(SimulateUartTxCountdown == 0) { - SetSingleBit(a->name2, FALSE); - } else { - SetSingleBit(a->name2, TRUE); - } - break; - - case INT_UART_RECV: - if(QueuedUartCharacter >= 0) { - SetSingleBit(a->name2, TRUE); - SetSimulationVariable(a->name1, (SWORD)QueuedUartCharacter); - QueuedUartCharacter = -1; - } else { - SetSingleBit(a->name2, FALSE); - } - break; - - case INT_END_IF: - case INT_ELSE: - return; - - case INT_COMMENT: - break; +// static void SimulateIntCode(void) +// { +// for(; IntPc < IntCodeLen; IntPc++) { +// IntOp *a = &IntCode[IntPc]; +// switch(a->op) { +// case INT_SIMULATE_NODE_STATE: +// if(*(a->poweredAfter) != SingleBitOn(a->name1)) +// NeedRedraw = TRUE; +// *(a->poweredAfter) = SingleBitOn(a->name1); +// break; + +// case INT_SET_BIT: +// SetSingleBit(a->name1, TRUE); +// break; + +// case INT_CLEAR_BIT: +// SetSingleBit(a->name1, FALSE); +// break; + +// case INT_COPY_BIT_TO_BIT: +// SetSingleBit(a->name1, SingleBitOn(a->name2)); +// break; + +// case INT_SET_VARIABLE_TO_LITERAL: +// if(GetSimulationVariable(a->name1) != +// a->literal && a->name1[0] != '$') +// { +// NeedRedraw = TRUE; +// } +// SetSimulationVariable(a->name1, a->literal); +// break; + +// case INT_SET_VARIABLE_TO_VARIABLE: +// if(GetSimulationVariable(a->name1) != +// GetSimulationVariable(a->name2)) +// { +// NeedRedraw = TRUE; +// } +// SetSimulationVariable(a->name1, +// GetSimulationVariable(a->name2)); +// break; + +// case INT_INCREMENT_VARIABLE: +// IncrementVariable(a->name1); +// break; + +// { +// SWORD v; +// case INT_SET_VARIABLE_ADD: +// v = GetSimulationVariable(a->name2) + +// GetSimulationVariable(a->name3); +// goto math; +// case INT_SET_VARIABLE_SUBTRACT: +// v = GetSimulationVariable(a->name2) - +// GetSimulationVariable(a->name3); +// goto math; +// case INT_SET_VARIABLE_MULTIPLY: +// v = GetSimulationVariable(a->name2) * +// GetSimulationVariable(a->name3); +// goto math; +// case INT_SET_VARIABLE_DIVIDE: +// if(GetSimulationVariable(a->name3) != 0) { +// v = GetSimulationVariable(a->name2) / +// GetSimulationVariable(a->name3); +// } else { +// v = 0; +// Error(_("Division by zero; halting simulation")); +// StopSimulation(); +// } +// goto math; +// math: +// if(GetSimulationVariable(a->name1) != v) { +// NeedRedraw = TRUE; +// SetSimulationVariable(a->name1, v); +// } +// break; +// } + +// #define IF_BODY \ +// { \ +// IfConditionTrue(); \ +// } else { \ +// IfConditionFalse(); \ +// } +// case INT_IF_BIT_SET: +// if(SingleBitOn(a->name1)) +// IF_BODY +// break; + +// case INT_IF_BIT_CLEAR: +// if(!SingleBitOn(a->name1)) +// IF_BODY +// break; + +// case INT_IF_VARIABLE_LES_LITERAL: +// if(GetSimulationVariable(a->name1) < a->literal) +// IF_BODY +// break; + +// case INT_IF_VARIABLE_EQUALS_VARIABLE: +// if(GetSimulationVariable(a->name1) == +// GetSimulationVariable(a->name2)) +// IF_BODY +// break; + +// case INT_IF_VARIABLE_GRT_VARIABLE: +// if(GetSimulationVariable(a->name1) > +// GetSimulationVariable(a->name2)) +// IF_BODY +// break; + +// case INT_SET_PWM: +// // Dummy call will cause a warning if no one ever assigned +// // to that variable. +// (void)GetSimulationVariable(a->name1); +// break; + +// // Don't try to simulate the EEPROM stuff: just hold the EEPROM +// // busy all the time, so that the program never does anything +// // with it. +// case INT_EEPROM_BUSY_CHECK: +// SetSingleBit(a->name1, TRUE); +// break; + +// case INT_EEPROM_READ: +// case INT_EEPROM_WRITE: +// oops(); +// break; + +// case INT_READ_ADC: +// // Keep the shadow copies of the ADC variables because in +// // the real device they will not be updated until an actual +// // read is performed, which occurs only for a true rung-in +// // condition there. +// SetSimulationVariable(a->name1, GetAdcShadow(a->name1)); +// break; + +// case INT_UART_SEND: +// if(SingleBitOn(a->name2) && (SimulateUartTxCountdown == 0)) { +// SimulateUartTxCountdown = 2; +// AppendToUartSimulationTextControl( +// (BYTE)GetSimulationVariable(a->name1)); +// } +// if(SimulateUartTxCountdown == 0) { +// SetSingleBit(a->name2, FALSE); +// } else { +// SetSingleBit(a->name2, TRUE); +// } +// break; + +// case INT_UART_RECV: +// if(QueuedUartCharacter >= 0) { +// SetSingleBit(a->name2, TRUE); +// SetSimulationVariable(a->name1, (SWORD)QueuedUartCharacter); +// QueuedUartCharacter = -1; +// } else { +// SetSingleBit(a->name2, FALSE); +// } +// break; + +// case INT_END_IF: +// case INT_ELSE: +// return; + +// case INT_COMMENT: +// break; - default: - oops(); - break; - } - } -} +// default: +// oops(); +// break; +// } +// } +// } //----------------------------------------------------------------------------- // Called by the Windows timer that triggers cycles when we are running // in real time. //----------------------------------------------------------------------------- -void CALLBACK PlcCycleTimer(HWND hwnd, UINT msg, UINT_PTR id, DWORD time) -{ - int i; - for(i = 0; i < CyclesPerTimerTick; i++) { - SimulateOneCycle(FALSE); - } -} +// void CALLBACK PlcCycleTimer(HWND hwnd, UINT msg, UINT_PTR id, DWORD time) +// { +// int i; +// for(i = 0; i < CyclesPerTimerTick; i++) { +// SimulateOneCycle(FALSE); +// } +// } //----------------------------------------------------------------------------- // Simulate one cycle of the PLC. Update everything, and keep track of whether // any outputs have changed. If so, force a screen refresh. If requested do // a screen refresh regardless. //----------------------------------------------------------------------------- -void SimulateOneCycle(BOOL forceRefresh) -{ - // When there is an error message up, the modal dialog makes its own - // event loop, and there is risk that we would go recursive. So let - // us fix that. (Note that there are no concurrency issues; we really - // would get called recursively, not just reentrantly.) - static BOOL Simulating = FALSE; +// void SimulateOneCycle(BOOL forceRefresh) +// { +// // When there is an error message up, the modal dialog makes its own +// // event loop, and there is risk that we would go recursive. So let +// // us fix that. (Note that there are no concurrency issues; we really +// // would get called recursively, not just reentrantly.) +// static BOOL Simulating = FALSE; - if(Simulating) return; - Simulating = TRUE; +// if(Simulating) return; +// Simulating = TRUE; - NeedRedraw = FALSE; +// NeedRedraw = FALSE; - if(SimulateUartTxCountdown > 0) { - SimulateUartTxCountdown--; - } else { - SimulateUartTxCountdown = 0; - } +// if(SimulateUartTxCountdown > 0) { +// SimulateUartTxCountdown--; +// } else { +// SimulateUartTxCountdown = 0; +// } - IntPc = 0; - SimulateIntCode(); +// IntPc = 0; +// SimulateIntCode(); - if(NeedRedraw || SimulateRedrawAfterNextCycle || forceRefresh) { - InvalidateRect(MainWindow, NULL, FALSE); - ListView_RedrawItems(IoList, 0, Prog.io.count - 1); - } +// if(NeedRedraw || SimulateRedrawAfterNextCycle || forceRefresh) { +// InvalidateRect(MainWindow, NULL, FALSE); +// ListView_RedrawItems(IoList, 0, Prog.io.count - 1); +// } - SimulateRedrawAfterNextCycle = FALSE; - if(NeedRedraw) SimulateRedrawAfterNextCycle = TRUE; +// SimulateRedrawAfterNextCycle = FALSE; +// if(NeedRedraw) SimulateRedrawAfterNextCycle = TRUE; - Simulating = FALSE; -} +// Simulating = FALSE; +// } //----------------------------------------------------------------------------- // Start the timer that we use to trigger PLC cycles in approximately real @@ -732,270 +725,250 @@ void SimulateOneCycle(BOOL forceRefresh) // is about as fast as anyone could follow by eye. Faster timers will just // go instantly. //----------------------------------------------------------------------------- -void StartSimulationTimer(void) -{ - int p = Prog.cycleTime/1000; - if(p < 5) { - SetTimer(MainWindow, TIMER_SIMULATE, 10, PlcCycleTimer); - CyclesPerTimerTick = 10000 / Prog.cycleTime; - } else { - SetTimer(MainWindow, TIMER_SIMULATE, p, PlcCycleTimer); - CyclesPerTimerTick = 1; - } -} +// void StartSimulationTimer(void) +// { +// int p = Prog.cycleTime/1000; +// if(p < 5) { +// SetTimer(MainWindow, TIMER_SIMULATE, 10, PlcCycleTimer); +// CyclesPerTimerTick = 10000 / Prog.cycleTime; +// } else { +// SetTimer(MainWindow, TIMER_SIMULATE, p, PlcCycleTimer); +// CyclesPerTimerTick = 1; +// } +// } //----------------------------------------------------------------------------- // Clear out all the parameters relating to the previous simulation. //----------------------------------------------------------------------------- -void ClearSimulationData(void) -{ - VariablesCount = 0; - SingleBitItemsCount = 0; - AdcShadowsCount = 0; - QueuedUartCharacter = -1; - SimulateUartTxCountdown = 0; +// void ClearSimulationData(void) +// { +// VariablesCount = 0; +// SingleBitItemsCount = 0; +// AdcShadowsCount = 0; +// QueuedUartCharacter = -1; +// SimulateUartTxCountdown = 0; - CheckVariableNames(); +// CheckVariableNames(); - SimulateRedrawAfterNextCycle = TRUE; +// SimulateRedrawAfterNextCycle = TRUE; - if(!GenerateIntermediateCode()) { - ToggleSimulationMode(); - return; - } +// if(!GenerateIntermediateCode()) { +// ToggleSimulationMode(); +// return; +// } - SimulateOneCycle(TRUE); -} +// SimulateOneCycle(TRUE); +// } //----------------------------------------------------------------------------- // Provide a description for an item (Xcontacts, Ycoil, Rrelay, Ttimer, // or other) in the I/O list. //----------------------------------------------------------------------------- -void DescribeForIoList(char *name, char *out) -{ - switch(name[0]) { - case 'R': - case 'X': - case 'Y': - sprintf(out, "%d", SingleBitOn(name)); - break; - - case 'T': { - double dtms = GetSimulationVariable(name) * - (Prog.cycleTime / 1000.0); - if(dtms < 1000) { - sprintf(out, "%.2f ms", dtms); - } else { - sprintf(out, "%.3f s", dtms / 1000); - } - break; - } - default: { - SWORD v = GetSimulationVariable(name); - sprintf(out, "%hd (0x%04hx)", v, v); - break; - } - } -} +// void DescribeForIoList(char *name, char *out) +// { +// switch(name[0]) { +// case 'R': +// case 'X': +// case 'Y': +// sprintf(out, "%d", SingleBitOn(name)); +// break; + +// case 'T': { +// double dtms = GetSimulationVariable(name) * +// (Prog.cycleTime / 1000.0); +// if(dtms < 1000) { +// sprintf(out, "%.2f ms", dtms); +// } else { +// sprintf(out, "%.3f s", dtms / 1000); +// } +// break; +// } +// default: { +// SWORD v = GetSimulationVariable(name); +// sprintf(out, "%hd (0x%04hx)", v, v); +// break; +// } +// } +// } //----------------------------------------------------------------------------- // Toggle the state of a contact input; for simulation purposes, so that we // can set the input state of the program. //----------------------------------------------------------------------------- -void SimulationToggleContact(char *name) -{ - BOOL value = !SingleBitOn(name); - SetSingleBit(name, value); - ListView_RedrawItems(IoList, 0, Prog.io.count - 1); - // TranslateState(name, value); -} - -void SimulationSetContact(char* name) -{ - BOOL value = TRUE; - SetSingleBit(name, value); - ListView_RedrawItems(IoList, 0, Prog.io.count - 1); - MCUPinState(name,value); - // TranslateState(name, value); -} - -void SimulationResetContact(char* name) -{ - BOOL value = FALSE; - SetSingleBit(name, value); - ListView_RedrawItems(IoList, 0, Prog.io.count - 1); - MCUPinState(name,value); - // TranslateState(name, value); -} +// void SimulationToggleContact(char *name) +// { +// SetSingleBit(name, !SingleBitOn(name)); +// ListView_RedrawItems(IoList, 0, Prog.io.count - 1); +// } //----------------------------------------------------------------------------- // Dialog proc for the popup that lets you interact with the UART stuff. //----------------------------------------------------------------------------- -static LRESULT CALLBACK UartSimulationProc(HWND hwnd, UINT msg, - WPARAM wParam, LPARAM lParam) -{ - switch (msg) { - case WM_DESTROY: - DestroyUartSimulationWindow(); - break; +// static LRESULT CALLBACK UartSimulationProc(HWND hwnd, UINT msg, +// WPARAM wParam, LPARAM lParam) +// { +// switch (msg) { +// case WM_DESTROY: +// DestroyUartSimulationWindow(); +// break; - case WM_CLOSE: - break; +// case WM_CLOSE: +// break; - case WM_SIZE: - MoveWindow(UartSimulationTextControl, 0, 0, LOWORD(lParam), - HIWORD(lParam), TRUE); - break; +// case WM_SIZE: +// MoveWindow(UartSimulationTextControl, 0, 0, LOWORD(lParam), +// HIWORD(lParam), TRUE); +// break; - case WM_ACTIVATE: - if(wParam != WA_INACTIVE) { - SetFocus(UartSimulationTextControl); - } - break; +// case WM_ACTIVATE: +// if(wParam != WA_INACTIVE) { +// SetFocus(UartSimulationTextControl); +// } +// break; - default: - return DefWindowProc(hwnd, msg, wParam, lParam); - } - return 1; -} +// default: +// return DefWindowProc(hwnd, msg, wParam, lParam); +// } +// return 1; +// } //----------------------------------------------------------------------------- // Intercept WM_CHAR messages that to the terminal simulation window so that // we can redirect them to the PLC program. //----------------------------------------------------------------------------- -static LRESULT CALLBACK UartSimulationTextProc(HWND hwnd, UINT msg, - WPARAM wParam, LPARAM lParam) -{ - if(msg == WM_CHAR) { - QueuedUartCharacter = (BYTE)wParam; - return 0; - } +// static LRESULT CALLBACK UartSimulationTextProc(HWND hwnd, UINT msg, +// WPARAM wParam, LPARAM lParam) +// { +// if(msg == WM_CHAR) { +// QueuedUartCharacter = (BYTE)wParam; +// return 0; +// } - return CallWindowProc((WNDPROC)PrevTextProc, hwnd, msg, wParam, lParam); -} +// return CallWindowProc((WNDPROC)PrevTextProc, hwnd, msg, wParam, lParam); +// } //----------------------------------------------------------------------------- // Pop up the UART simulation window; like a terminal window where the // characters that you type go into UART RECV instruction and whatever // the program puts into UART SEND shows up as text. //----------------------------------------------------------------------------- -void ShowUartSimulationWindow(void) -{ - WNDCLASSEX wc; - memset(&wc, 0, sizeof(wc)); - wc.cbSize = sizeof(wc); +// void ShowUartSimulationWindow(void) +// { +// WNDCLASSEX wc; +// memset(&wc, 0, sizeof(wc)); +// wc.cbSize = sizeof(wc); - wc.style = CS_BYTEALIGNCLIENT | CS_BYTEALIGNWINDOW | CS_OWNDC | - CS_DBLCLKS; - wc.lpfnWndProc = (WNDPROC)UartSimulationProc; - wc.hInstance = Instance; - wc.hbrBackground = (HBRUSH)COLOR_BTNSHADOW; - wc.lpszClassName = "LDmicroUartSimulationWindow"; - wc.lpszMenuName = NULL; - wc.hCursor = LoadCursor(NULL, IDC_ARROW); +// wc.style = CS_BYTEALIGNCLIENT | CS_BYTEALIGNWINDOW | CS_OWNDC | +// CS_DBLCLKS; +// wc.lpfnWndProc = (WNDPROC)UartSimulationProc; +// wc.hInstance = Instance; +// wc.hbrBackground = (HBRUSH)COLOR_BTNSHADOW; +// wc.lpszClassName = "LDmicroUartSimulationWindow"; +// wc.lpszMenuName = NULL; +// wc.hCursor = LoadCursor(NULL, IDC_ARROW); - RegisterClassEx(&wc); +// RegisterClassEx(&wc); - DWORD TerminalX = 200, TerminalY = 200, TerminalW = 300, TerminalH = 150; +// DWORD TerminalX = 200, TerminalY = 200, TerminalW = 300, TerminalH = 150; - ThawDWORD(TerminalX); - ThawDWORD(TerminalY); - ThawDWORD(TerminalW); - ThawDWORD(TerminalH); +// ThawDWORD(TerminalX); +// ThawDWORD(TerminalY); +// ThawDWORD(TerminalW); +// ThawDWORD(TerminalH); - if(TerminalW > 800) TerminalW = 100; - if(TerminalH > 800) TerminalH = 100; +// if(TerminalW > 800) TerminalW = 100; +// if(TerminalH > 800) TerminalH = 100; - RECT r; - GetClientRect(GetDesktopWindow(), &r); - if(TerminalX >= (DWORD)(r.right - 10)) TerminalX = 100; - if(TerminalY >= (DWORD)(r.bottom - 10)) TerminalY = 100; +// RECT r; +// GetClientRect(GetDesktopWindow(), &r); +// if(TerminalX >= (DWORD)(r.right - 10)) TerminalX = 100; +// if(TerminalY >= (DWORD)(r.bottom - 10)) TerminalY = 100; - UartSimulationWindow = CreateWindowClient(WS_EX_TOOLWINDOW | - WS_EX_APPWINDOW, "LDmicroUartSimulationWindow", - "UART Simulation (Terminal)", WS_VISIBLE | WS_SIZEBOX, - TerminalX, TerminalY, TerminalW, TerminalH, - NULL, NULL, Instance, NULL); +// UartSimulationWindow = CreateWindowClient(WS_EX_TOOLWINDOW | +// WS_EX_APPWINDOW, "LDmicroUartSimulationWindow", +// "UART Simulation (Terminal)", WS_VISIBLE | WS_SIZEBOX, +// TerminalX, TerminalY, TerminalW, TerminalH, +// NULL, NULL, Instance, NULL); - UartSimulationTextControl = CreateWindowEx(0, WC_EDIT, "", WS_CHILD | - WS_CLIPSIBLINGS | WS_VISIBLE | ES_AUTOVSCROLL | ES_MULTILINE | - WS_VSCROLL, 0, 0, TerminalW, TerminalH, UartSimulationWindow, NULL, - Instance, NULL); +// UartSimulationTextControl = CreateWindowEx(0, WC_EDIT, "", WS_CHILD | +// WS_CLIPSIBLINGS | WS_VISIBLE | ES_AUTOVSCROLL | ES_MULTILINE | +// WS_VSCROLL, 0, 0, TerminalW, TerminalH, UartSimulationWindow, NULL, +// Instance, NULL); - HFONT fixedFont = CreateFont(14, 0, 0, 0, FW_REGULAR, FALSE, FALSE, FALSE, - ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, - FF_DONTCARE, "Lucida Console"); - if(!fixedFont) - fixedFont = (HFONT)GetStockObject(SYSTEM_FONT); +// HFONT fixedFont = CreateFont(14, 0, 0, 0, FW_REGULAR, FALSE, FALSE, FALSE, +// ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, +// FF_DONTCARE, "Lucida Console"); +// if(!fixedFont) +// fixedFont = (HFONT)GetStockObject(SYSTEM_FONT); - SendMessage((HWND)UartSimulationTextControl, WM_SETFONT, (WPARAM)fixedFont, - TRUE); +// SendMessage((HWND)UartSimulationTextControl, WM_SETFONT, (WPARAM)fixedFont, +// TRUE); - PrevTextProc = SetWindowLongPtr(UartSimulationTextControl, - GWLP_WNDPROC, (LONG_PTR)UartSimulationTextProc); +// PrevTextProc = SetWindowLongPtr(UartSimulationTextControl, +// GWLP_WNDPROC, (LONG_PTR)UartSimulationTextProc); - ShowWindow(UartSimulationWindow, TRUE); - SetFocus(MainWindow); -} +// ShowWindow(UartSimulationWindow, TRUE); +// SetFocus(MainWindow); +// } //----------------------------------------------------------------------------- // Get rid of the UART simulation terminal-type window. //----------------------------------------------------------------------------- -void DestroyUartSimulationWindow(void) -{ - // Try not to destroy the window if it is already destroyed; that is - // not for the sake of the window, but so that we don't trash the - // stored position. - if(UartSimulationWindow == NULL) return; +// void DestroyUartSimulationWindow(void) +// { +// // Try not to destroy the window if it is already destroyed; that is +// // not for the sake of the window, but so that we don't trash the +// // stored position. +// if(UartSimulationWindow == NULL) return; - DWORD TerminalX, TerminalY, TerminalW, TerminalH; - RECT r; +// DWORD TerminalX, TerminalY, TerminalW, TerminalH; +// RECT r; - GetClientRect(UartSimulationWindow, &r); - TerminalW = r.right - r.left; - TerminalH = r.bottom - r.top; +// GetClientRect(UartSimulationWindow, &r); +// TerminalW = r.right - r.left; +// TerminalH = r.bottom - r.top; - GetWindowRect(UartSimulationWindow, &r); - TerminalX = r.left; - TerminalY = r.top; +// GetWindowRect(UartSimulationWindow, &r); +// TerminalX = r.left; +// TerminalY = r.top; - FreezeDWORD(TerminalX); - FreezeDWORD(TerminalY); - FreezeDWORD(TerminalW); - FreezeDWORD(TerminalH); +// FreezeDWORD(TerminalX); +// FreezeDWORD(TerminalY); +// FreezeDWORD(TerminalW); +// FreezeDWORD(TerminalH); - DestroyWindow(UartSimulationWindow); - UartSimulationWindow = NULL; -} +// DestroyWindow(UartSimulationWindow); +// UartSimulationWindow = NULL; +// } //----------------------------------------------------------------------------- // Append a received character to the terminal buffer. //----------------------------------------------------------------------------- -static void AppendToUartSimulationTextControl(BYTE b) -{ - char append[5]; - - if((isalnum(b) || strchr("[]{};':\",.<>/?`~ !@#$%^&*()-=_+|", b) || - b == '\r' || b == '\n') && b != '\0') - { - append[0] = b; - append[1] = '\0'; - } else { - sprintf(append, "\\x%02x", b); - } - -#define MAX_SCROLLBACK 256 - char buf[MAX_SCROLLBACK]; - - SendMessage(UartSimulationTextControl, WM_GETTEXT, (WPARAM)sizeof(buf), - (LPARAM)buf); - - int overBy = (strlen(buf) + strlen(append) + 1) - sizeof(buf); - if(overBy > 0) { - memmove(buf, buf + overBy, strlen(buf)); - } - strcat(buf, append); - - SendMessage(UartSimulationTextControl, WM_SETTEXT, 0, (LPARAM)buf); - SendMessage(UartSimulationTextControl, EM_LINESCROLL, 0, (LPARAM)INT_MAX); -} +// static void AppendToUartSimulationTextControl(BYTE b) +// { +// char append[5]; + +// if((isalnum(b) || strchr("[]{};':\",.<>/?`~ !@#$%^&*()-=_+|", b) || +// b == '\r' || b == '\n') && b != '\0') +// { +// append[0] = b; +// append[1] = '\0'; +// } else { +// sprintf(append, "\\x%02x", b); +// } + +// #define MAX_SCROLLBACK 256 +// char buf[MAX_SCROLLBACK]; + +// SendMessage(UartSimulationTextControl, WM_GETTEXT, (WPARAM)sizeof(buf), +// (LPARAM)buf); + +// int overBy = (strlen(buf) + strlen(append) + 1) - sizeof(buf); +// if(overBy > 0) { +// memmove(buf, buf + overBy, strlen(buf)); +// } +// strcat(buf, append); + +// SendMessage(UartSimulationTextControl, WM_SETTEXT, 0, (LPARAM)buf); +// SendMessage(UartSimulationTextControl, EM_LINESCROLL, 0, (LPARAM)INT_MAX); +// } |