Nestreme.h
上传用户:luhy168
上传日期:2022-01-10
资源大小:240k
文件大小:7k
源码类别:

模拟服务器

开发平台:

Visual C++

  1. //------------------------------------------------------------------------------
  2. // Name: Nestreme.h
  3. // Desc: Holds all the function prototypes and other stuff for Nestreme.cpp
  4. //------------------------------------------------------------------------------
  5. #ifndef __NESTREME_H__
  6. #define __NESTREME_H__
  7. //-----------------------------------------------------------------------------
  8. // Defines
  9. //-----------------------------------------------------------------------------
  10. #define OPTIONS_NUM_DEBUGLINES     500
  11. #define OPTIONS_NUM_BREAKPOINTS    10
  12. #define OPTIONS_NUM_GFXFRAMESKIP   0
  13. #define OPTIONS_NUM_AUDIOFRAMESKIP 0
  14. #define NUM_SCANLINES_SCREEN    240
  15. #define NUM_SCANLINES_VBLANK    22
  16. #define REGISTER_LISTBOX_WIDTH 300
  17. #define NES_PRGROM_PAGESIZE    0x4000
  18. #define NES_CHRROM_PAGESIZE    0x1000
  19. #define FATAL(hwnd, strError) 
  20. { MessageBox(hwnd, strError, "Nestreme", MB_OK | MB_ICONSTOP); return FALSE; }
  21. #define SAFE_DELETE_ARRAY(pArray) 
  22. if (pArray != NULL) delete [] pArray;
  23. #define ListView_Check(hwndCodeLV, uListViewItem) 
  24. ListView_SetItemState(hwndCodeLV, uListViewItem, INDEXTOSTATEIMAGEMASK(2), LVIS_STATEIMAGEMASK);
  25. #define ListView_UnCheck(hwndCodeLV, uListViewItem) 
  26. ListView_SetItemState(hwndCodeLV, uListViewItem, INDEXTOSTATEIMAGEMASK(1), LVIS_STATEIMAGEMASK);
  27. #define ADD_VAR_TO_REG_LISTVIEW(Pos, strVar, byVar) 
  28. sprintf(strText, strVar); 
  29. InsertListViewText(hwndRegsLV, Pos, 0, strText); 
  30. sprintf(strText, "%02X", byVar); 
  31. InsertListViewText(hwndRegsLV, Pos, 1, strText); 
  32. #define ADD_BLANK_TO_REG_LISTVIEW(Pos) 
  33. sprintf(strText, " "); 
  34. InsertListViewText(hwndRegsLV, Pos, 0, strText); 
  35. #define UPDATE_VAR_IN_REG_LISTVIEW(Pos, strVar, byVar) 
  36. sprintf(strText, strVar); 
  37. SetListViewText(hwndRegsLV, Pos, 0, strText); 
  38. sprintf(strText, "%02X", byVar); 
  39. SetListViewText(hwndRegsLV, Pos, 1, strText);
  40. #define PUSH_BYTE(byData) 
  41. CPU.Memory[0x100+CPU.S] = byData; 
  42. CPU.S--; 
  43. #define POP_BYTE(byData) 
  44. CPU.S++; 
  45. byData = CPU.Memory[0x100+CPU.S]; 
  46. //-----------------------------------------------------------------------------
  47. // Includes
  48. //-----------------------------------------------------------------------------
  49. #include "Cpu.h"
  50. #include "Ppu.h"
  51. #include "NESData.h"
  52. #include "Joystick.h"
  53. //-----------------------------------------------------------------------------
  54. // Function prototypes
  55. //-----------------------------------------------------------------------------
  56. LRESULT CALLBACK WndProcMain(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  57. LRESULT CALLBACK WndProcDebug(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  58. LRESULT CALLBACK WndProcMemory(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  59. HRESULT      AddBreakpoint(WORD wAddress, UINT uListViewItem);
  60. HRESULT      AddRegistersToListView();
  61. HRESULT      CleanUp();
  62. HRESULT      CPU_DoCyclicTasks();
  63. DWORD WINAPI CPU_Run(LPVOID lpParam);
  64. DWORD WINAPI CPU_RunUntilBreak(LPVOID lpParam);
  65. HRESULT      CPU_Step();
  66. HRESULT      CreateMemoryDump(HWND hwndParent, HWND* phwndEdit, HWND* phwndButton);
  67. HRESULT      CreateDebugWindow(HWND hwndParent);
  68. HWND         CreateListView(HWND hWndParent, UINT uFirstColRsc, UINT uNumColumns);
  69. HRESULT      CreateMDIClientWindow(HWND hwndFrame);
  70. HRESULT      CreateMemoryWindow(HWND hwndParent);
  71. HWND WINAPI  CreateTabControl(HWND hwndParent, UINT uTextResource, UINT uNumTabs);
  72. HRESULT      CreateTooltip(HWND hwnd, LPSTR strToolTip);
  73. HRESULT      DisableBreakpoint(UINT uBreakpointIndex, UINT uListViewItem);
  74. HRESULT      DisplayMainMemDump(HWND hwndEditCtrl);
  75. HRESULT      DisplayPPUMemDump(HWND hwndEditCtrl);
  76. HRESULT      DisplayPRGROMMemDump(HWND hwndEditCtrl);
  77. HRESULT      DisplaySpriteMemDump(HWND hwndEditCtrl);
  78. HRESULT      DisplayStackMemDump(HWND hwndEditCtrl);
  79. HRESULT      DissassembleROM();
  80. HRESULT      FreeNESFile();
  81. HRESULT      InitializeApp();
  82. HRESULT      InsertListViewText(HWND hwndLV, UINT uRow, UINT uCol, LPSTR strText);
  83. HRESULT      LoadNESFile(HWND hwnd);
  84. HRESULT      LoadROMToMem(LPSTR strRomFileName);
  85. HRESULT      MemoryDumpToString(char** pstrMemory, BYTE* pMemory, UINT uStartByte, UINT uEndByte);
  86. HRESULT      PromptForFileOpen(HWND hwndOwner);
  87. HRESULT      ResetNES();
  88. HRESULT      ResizeDebugControls(HWND hwndChild, HWND hwndCodeLB, HWND hwndRegLB);
  89. HRESULT      ToggleBreakpoint(UINT uItem);
  90. HRESULT      UpdateInstrCursorPos();
  91. HRESULT      UpdateDebugInfo();
  92. HRESULT      UpdateRegisters();
  93. VOID         Wait(DWORD dwTime);
  94. // Mapper .dll functions.
  95. typedef BOOL (*MAPPERLOAD)(NESDATA*);
  96. typedef BYTE (*MAPPERREAD)(WORD);
  97. typedef BOOL (*MAPPERWRITE)(WORD, BYTE);
  98. MAPPERLOAD  MapperOnLoad;
  99. MAPPERREAD  MapperOnRead;
  100. MAPPERWRITE MapperOnWrite;
  101. //-----------------------------------------------------------------------------
  102. // External functions needed in this file.
  103. //-----------------------------------------------------------------------------
  104. extern BYTE    PrintInstrToString(LPSTR strInstr, WORD wPC);
  105. //-----------------------------------------------------------------------------
  106. // Globals
  107. //-----------------------------------------------------------------------------
  108. HINSTANCE g_hInstance;
  109. HINSTANCE hinstMapperLib;
  110. LPSTR strClassName       = "Nestreme!";
  111. LPSTR strAppName         = "Nestreme";
  112. LPSTR strDebugClassName  = "Nestreme_Debug!";
  113. LPSTR strDebugTitleName  = "Nestreme code and registers";
  114. LPSTR strMemoryClassName = "Nestreme_Memory!";
  115. LPSTR strMemoryTitleName = "Memory Contents";
  116. LPSTR strRunClassName    = "Nestreme_Run!";
  117. LPSTR strRunTitleName    = "Run";
  118. HWND hwndMain;      // Handle to the main window.
  119. HWND hwndMDIClient; // Handle to the MDI Client window.
  120. HWND hwndDebugWnd;  // Handle to the child window.
  121. HWND hwndMemoryWnd; // Handle to the memory window.
  122. HWND hwndRunWnd;    // Handle to the run window.
  123. HWND hwndCodeLV;    // Code disassembly list view.
  124. HWND hwndRegsLV;    // Register list view.
  125. HWND hwndTT;        // Tooltip window.
  126. HANDLE hThreadGo;     // Handle to the thread created when go is selected.
  127. DWORD  dwThreadIDGo;  // Thread ID of the thread created when go is selected.
  128. HANDLE hThreadRun;    // Handle to the thread created when go is selected.
  129. DWORD  dwThreadIDRun; // Thread ID of the thread created when go is selected.
  130. NES6502 CPU = {0};        // Our global CPU.
  131. NESPPU  PPU = {0};        // Our global PPU.
  132. BYTE*   abyPRGROM;        // Global array of program-rom.
  133. WORD    wNumPRGROMPages;  // Number of program-rom pages.
  134. BYTE*   abyCHRROM;        // Global array of character-rom.
  135. WORD    wNumCHRROMPages;  // Number of character-rom pages.
  136. BYTE    abySPRRAM[256];   // Sprite memory.
  137. BYTE    strFileName[512]; // File name of the rom.
  138. BYTE    abyRomHeader[16]; // The header of the rom.
  139. WORD    wScanline;        // The current scanline that is being drawn.
  140. // Array of addresses to break execution on,
  141. // the number of breakpoints in the array, and a 
  142. // boolean variable to tell us to halt execution.
  143. WORD  awBreakpoints[OPTIONS_NUM_BREAKPOINTS+1] = {0}; 
  144. DWORD dwNumBreakpoints = 0;
  145. BOOL  bBreak = FALSE;
  146. // Is our app running.
  147. BOOL  bRunning = FALSE;
  148. // Our options for our program.
  149. BOOL  Options_bBackgroundEnabled = TRUE;
  150. BOOL  Options_bSpritesEnabled    = TRUE;
  151. // Used to toggle the first and second write of registers $2005/$2006
  152. BYTE byVRAMAddrRegToggle = 0; 
  153. // Address of the VRAM write register.
  154. WORD wVRAMAddress = 0;
  155. // The scrolling values for the scanline.
  156. BYTE byHScroll[300];
  157. BYTE byVScroll[300];
  158. // The joysticks.
  159. Joystick Joy1(0x4016);
  160. #endif