home *** CD-ROM | disk | FTP | other *** search
-
- /* Poke.c: Poke dialog interface implementation.
- *
- * Copyright 1996 Rui Fernando Ferreira Ribeiro.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
- #include <windows.h>
- #include "wspecem.h" // Local header
- #include "env.h"
-
- // determine wich value there's on the box, and if there is one, return
- // it
- static BOOL ReadInt(HWND hwnd,int Control,unsigned short Min,
- unsigned short Max, unsigned short *Val)
- {
- BOOL fError;
- int n;
-
- n=(int)GetDlgItemInt(hwnd,Control,&fError,FALSE);
- if (!fError || (n < Min) || (n > Max))
- return(TRUE);
- else
- *Val=n;
- return(FALSE);
- }
-
- // dispatcher : handle the dialog
- BOOL CALLBACK DoPoke(HWND hwnd,UINT Message,WPARAM wParam,LPARAM lParam)
- {
- static unsigned short address = 16384;
- unsigned short val;
-
- char szBuffer[7];
-
- switch(Message)
- {
- case WM_INITDIALOG:
- wsprintf((LPSTR)szBuffer, "%u", address);
- SendDlgItemMessage(hwnd,IDC_ADDRESS,WM_SETTEXT,
- 0,(LPARAM)(LPSTR)szBuffer);
- val = (unsigned char)readbyte(address);
- wsprintf((LPSTR)szBuffer, "%u", val);
- SendDlgItemMessage(hwnd,IDC_VALUE,WM_SETTEXT,
- 0,(LPARAM)(LPSTR)szBuffer);
- return(TRUE);
-
- case WM_COMMAND:
- switch(wParam)
- {
- case IDOK:
- if(ReadInt(hwnd,IDC_ADDRESS,16384,65535,&address))
- {
- MessageBeep(MB_ICONEXCLAMATION);
- MessageBox(hwnd, "Address must be between 16384 and 65535.",
- "Poke", MB_OK | MB_ICONEXCLAMATION);
- SetFocus(GetDlgItem(hwnd, IDC_ADDRESS) );
- return(TRUE);
- }
-
- if(ReadInt(hwnd,IDC_VALUE,0,255,&val))
- {
- MessageBeep(MB_ICONEXCLAMATION);
- MessageBox(hwnd, "Value must be between 0 and 255.",
- "Poke", MB_OK | MB_ICONEXCLAMATION);
- SetFocus(GetDlgItem(hwnd, IDC_VALUE) );
- return(TRUE);
- }
- writebyte(address, val);
- EndDialog(hwnd,1);
- return(TRUE);
-
- case IDCANCEL:
- EndDialog(hwnd,0);
- return(TRUE);
- }
- }
- return(FALSE);
- }
-
- /* EOF: Poke.c */
-