Main Page   Data Structures   File List   Data Fields   Globals   Related Pages  

cpuuidll.c

Go to the documentation of this file.
00001 
00006 #include "../dllkit/dllkit.h"
00007 #include "../usrmsgs.h"
00008 #include "resource.h"
00009 #include <commctrl.h>
00010 #include <stdio.h>
00011 #include <tchar.h>
00012 
00014 HANDLE hThisModule;
00016 MSGLIST Msgs;
00019 INITDLLSTRUCT info;
00020 
00022 HMENU hMenu;
00024 HMENU hCpuMenu;
00025 
00026 BOOL Running;
00027 
00028 /* ----- begin forward declarations */
00030 void SetStatusRunning();
00032 void SetStatusStopped();
00033 /* ----- end forward declarations */
00034 
00036 BOOL APIENTRY DllMain(HANDLE hModule, DWORD  ul_reason_for_call, 
00037                                           LPVOID lpReserved)
00038 {
00039         hThisModule = hModule;
00040         switch (ul_reason_for_call) {
00041         case DLL_PROCESS_ATTACH:
00042                 CreateMsgList(&Msgs, 3);
00043                 break;
00044         case DLL_PROCESS_DETACH:
00045                 FreeMsgList(Msgs);
00046                 break;
00047         }       
00048     return TRUE;
00049 }
00050 
00051 DLLEXPORT void __cdecl InitDll(INITDLLSTRUCT* ids, INITDLLINFO* idi)
00052 {
00053         TBADDBITMAP tbab;
00054         TBBUTTON tbt[7];
00055         int index;
00056 
00057         // Fill the msglist with messages we want handle
00058         AddMessage(Msgs, WM_COMMAND);
00059         AddMessage(Msgs, CPURUNNING);
00060         AddMessage(Msgs, CPUSTOPPED);
00061 
00062         // Copy informations passed to this dll
00063         info.CSMemory = ids->CSMemory;
00064         info.hInst = ids->hInst;
00065         info.hWnd = ids->hWnd;
00066         info.memory = ids->memory;
00067         info.memgetb = ids->memgetb;
00068         info.memsetb = ids->memsetb;
00069         info.optional = ids->optional;
00070         info.hTb = ids->hTb;
00071 
00072         // Append local menu to the main menu bar
00073         hMenu = GetMenu(info.hWnd);
00074         hCpuMenu = LoadMenu(hThisModule, MAKEINTRESOURCE(IDR_MENU));
00075         AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT) hCpuMenu, "&CPU");
00076         DrawMenuBar(info.hWnd);
00077 
00078         // Add buttons to the main toolbar
00079         tbab.hInst = hThisModule;
00080         tbab.nID = IDR_TOOLBAR;
00081         index = SendMessage(info.hTb, TB_ADDBITMAP, (WPARAM) 5, 
00082         (WPARAM) &tbab); 
00083         ZeroMemory(&tbt, sizeof(TBBUTTON) * 5);
00084         tbt[0].iBitmap = index;
00085         tbt[0].idCommand = ID_RESUME;
00086         tbt[0].fsState = TBSTATE_ENABLED;
00087         tbt[0].fsStyle = TBSTYLE_BUTTON | TBSTYLE_AUTOSIZE;
00088         tbt[1].iBitmap = index + 1;
00089         tbt[1].idCommand = ID_PAUSE;
00090         tbt[1].fsState = TBSTATE_ENABLED;
00091         tbt[1].fsStyle = TBSTYLE_BUTTON | TBSTYLE_AUTOSIZE;
00092         tbt[2].iBitmap = index + 2;
00093         tbt[2].idCommand = ID_NMI;
00094         tbt[2].fsState = TBSTATE_ENABLED;
00095         tbt[2].fsStyle = TBSTYLE_BUTTON | TBSTYLE_AUTOSIZE;
00096         tbt[3].iBitmap = index + 3;
00097         tbt[3].idCommand = ID_IRQ;
00098         tbt[3].fsState = TBSTATE_ENABLED;
00099         tbt[3].fsStyle = TBSTYLE_BUTTON | TBSTYLE_AUTOSIZE;
00100         tbt[4].iBitmap = index + 4;
00101         tbt[4].idCommand = ID_RESET;
00102         tbt[4].fsState = TBSTATE_ENABLED;
00103         tbt[4].fsStyle = TBSTYLE_BUTTON | TBSTYLE_AUTOSIZE;
00104 
00105     SendMessage(info.hTb, TB_ADDBUTTONS, (WPARAM) 5, 
00106         (LPARAM) &tbt); 
00107 
00108         SendMessage(info.hTb, TB_ENABLEBUTTON, 
00109                 (WPARAM) ID_PAUSE, (LPARAM) MAKELONG(FALSE, 0)); 
00110         SendMessage(info.hTb, TB_ENABLEBUTTON, 
00111                 (WPARAM) ID_RESET, (LPARAM) MAKELONG(FALSE, 0)); 
00112         SendMessage(info.hTb, TB_ENABLEBUTTON, 
00113                 (WPARAM) ID_IRQ, (LPARAM) MAKELONG(FALSE, 0)); 
00114         SendMessage(info.hTb, TB_ENABLEBUTTON, 
00115                 (WPARAM) ID_NMI, (LPARAM) MAKELONG(FALSE, 0)); 
00116 
00117     SendMessage(info.hTb, TB_AUTOSIZE, 0, 0); 
00118 
00119         Running = FALSE;
00120 
00121         idi->iolo = 0;
00122         idi->iohi = 0;
00123         idi->msglist = Msgs;
00124 }
00125 
00126 DLLEXPORT void __cdecl OnMessage(MESSAGEDLLSTRUCT* mds)
00127 {
00128         int wmId, wmEvent;
00129 
00130         switch (mds->message) {
00131         case WM_COMMAND:
00132                 wmId = LOWORD(mds->wParam); 
00133                 wmEvent = HIWORD(mds->wParam); 
00134                 switch (wmId) {
00135                 case ID_RESUME:
00136                         SetStatusRunning();
00137                         SendMessage(info.hWnd, STARTCPU, 0, 0);
00138                         break;          
00139                 case ID_PAUSE:
00140                         SetStatusStopped();
00141                         SendMessage(info.hWnd, PAUSECPU, 0, 0);
00142                         break;
00143                 case ID_RESET:
00144                         (*info.memsetb)(RESETID, 255);
00145                         SendMessage(info.hWnd, RESETMSG, 0, 0);
00146                         break;
00147                 case ID_IRQ:
00148                         (*info.memsetb)(IRQID, 255);
00149                         SendMessage(info.hWnd, IRQMSG, 0, 0);
00150                         break;
00151                 case ID_NMI:
00152                         (*info.memsetb)(NMIID, 255);
00153                         SendMessage(info.hWnd, NMIMSG, 0, 0);
00154                         break;
00155                 case ID_ABOUT:
00156                         MessageBox(info.hWnd, "Cpu UI\nAdds the CPU menu and buttons which enable sending commands to cpu from GUI\n(c)2002 Petr Cermak", "About", MB_OK);
00157                         break;
00158                 }
00159                 break;
00160         case CPURUNNING:
00161                 if (!Running) {
00162                         SetStatusRunning();
00163                 }
00164                 break;
00165         case CPUSTOPPED:
00166                 if (Running) {
00167                         SetStatusStopped();
00168                 }
00169                 break;
00170         }
00171 
00172 }
00173 
00174 void SetStatusRunning()
00175 {
00176         Running = TRUE;
00177         EnableMenuItem(hCpuMenu, ID_RESUME, MF_GRAYED | MF_BYCOMMAND);
00178         EnableMenuItem(hCpuMenu, ID_PAUSE, MF_ENABLED | MF_BYCOMMAND);
00179         EnableMenuItem(hCpuMenu, ID_RESET, MF_ENABLED | MF_BYCOMMAND);
00180         EnableMenuItem(hCpuMenu, ID_IRQ, MF_ENABLED | MF_BYCOMMAND);
00181         EnableMenuItem(hCpuMenu, ID_NMI, MF_ENABLED | MF_BYCOMMAND);
00182         SendMessage(info.hTb, TB_ENABLEBUTTON, 
00183                 (WPARAM) ID_RESUME, (LPARAM) MAKELONG(FALSE, 0)); 
00184         SendMessage(info.hTb, TB_ENABLEBUTTON, 
00185                 (WPARAM) ID_PAUSE, (LPARAM) MAKELONG(TRUE, 0)); 
00186         SendMessage(info.hTb, TB_ENABLEBUTTON, 
00187                 (WPARAM) ID_RESET, (LPARAM) MAKELONG(TRUE, 0)); 
00188         SendMessage(info.hTb, TB_ENABLEBUTTON, 
00189                 (WPARAM) ID_IRQ, (LPARAM) MAKELONG(TRUE, 0)); 
00190         SendMessage(info.hTb, TB_ENABLEBUTTON, 
00191                 (WPARAM) ID_NMI, (LPARAM) MAKELONG(TRUE, 0)); 
00192 }
00193 
00194 void SetStatusStopped()
00195 {
00196         Running = FALSE;
00197         EnableMenuItem(hCpuMenu, ID_RESUME, MF_ENABLED | MF_BYCOMMAND);
00198         EnableMenuItem(hCpuMenu, ID_PAUSE, MF_GRAYED | MF_BYCOMMAND);
00199         EnableMenuItem(hCpuMenu, ID_RESET, MF_GRAYED | MF_BYCOMMAND);
00200         EnableMenuItem(hCpuMenu, ID_IRQ, MF_GRAYED | MF_BYCOMMAND);
00201         EnableMenuItem(hCpuMenu, ID_NMI, MF_GRAYED | MF_BYCOMMAND);
00202         SendMessage(info.hTb, TB_ENABLEBUTTON, 
00203                 (WPARAM) ID_RESUME, (LPARAM) MAKELONG(TRUE, 0)); 
00204         SendMessage(info.hTb, TB_ENABLEBUTTON, 
00205                 (WPARAM) ID_PAUSE, (LPARAM) MAKELONG(FALSE, 0)); 
00206         SendMessage(info.hTb, TB_ENABLEBUTTON, 
00207                 (WPARAM) ID_RESET, (LPARAM) MAKELONG(FALSE, 0)); 
00208         SendMessage(info.hTb, TB_ENABLEBUTTON, 
00209                 (WPARAM) ID_IRQ, (LPARAM) MAKELONG(FALSE, 0)); 
00210         SendMessage(info.hTb, TB_ENABLEBUTTON, 
00211                 (WPARAM) ID_NMI, (LPARAM) MAKELONG(FALSE, 0)); 
00212 }
00213 
00214 DLLEXPORT void __cdecl IOFunc(UINT adr, unsigned char* data, 
00215                                                                                   iomode mode)
00216 {
00217 }
00218 

Generated on Fri Sep 6 18:32:14 2002 for Emu6502 by doxygen1.2.17