1 #pragma once 2 #include "stdafx.h" 3 4 namespace PSFlags 5 { 6 enum PSFlags : uint8_t 7 { 8 Carry = 0x01, 9 Zero = 0x02, 10 Interrupt = 0x04, 11 Decimal = 0x08, 12 Break = 0x10, 13 Reserved = 0x20, 14 Overflow = 0x40, 15 Negative = 0x80 16 }; 17 } 18 19 enum class AddrMode 20 { 21 None, Acc, Imp, Imm, Rel, 22 Zero, Abs, ZeroX, ZeroY, 23 Ind, IndX, IndY, IndYW, 24 AbsX, AbsXW, AbsY, AbsYW 25 }; 26 27 enum class IRQSource 28 { 29 External = 1, 30 FrameCounter = 2, 31 DMC = 4, 32 FdsDisk = 8, 33 }; 34 35 enum class MemoryOperation 36 { 37 Read = 1, 38 Write = 2, 39 Any = 3 40 }; 41 42 enum class MemoryOperationType 43 { 44 Read = 0, 45 Write = 1, 46 ExecOpCode = 2, 47 ExecOperand = 3, 48 PpuRenderingRead = 4, 49 DummyRead = 5, 50 DmcRead = 6, 51 DummyWrite = 7 52 }; 53 54 struct State 55 { 56 uint16_t PC = 0; 57 uint8_t SP = 0; 58 uint8_t A = 0; 59 uint8_t X = 0; 60 uint8_t Y = 0; 61 uint8_t PS = 0; 62 uint32_t IRQFlag = 0; 63 uint64_t CycleCount = 0; 64 bool NMIFlag = false; 65 66 //Used by debugger 67 uint16_t DebugPC = 0; 68 uint16_t PreviousDebugPC = 0; 69 }; 70 71 enum class PrgMemoryType 72 { 73 PrgRom, 74 SaveRam, 75 WorkRam, 76 }; 77 78 enum class ChrMemoryType 79 { 80 Default, 81 ChrRom, 82 ChrRam, 83 NametableRam 84 }; 85 86 enum MemoryAccessType 87 { 88 Unspecified = -1, 89 NoAccess = 0x00, 90 Read = 0x01, 91 Write = 0x02, 92 ReadWrite = 0x03 93 }; 94 95 enum class MirroringType 96 { 97 Horizontal, 98 Vertical, 99 ScreenAOnly, 100 ScreenBOnly, 101 FourScreens 102 }; 103 104 struct CartridgeState 105 { 106 uint32_t PrgRomSize; 107 uint32_t ChrRomSize; 108 uint32_t ChrRamSize; 109 110 uint32_t PrgPageCount; 111 uint32_t PrgPageSize; 112 int32_t PrgMemoryOffset[0x100]; 113 PrgMemoryType PrgType[0x100]; 114 MemoryAccessType PrgMemoryAccess[0x100]; 115 116 uint32_t ChrPageCount; 117 uint32_t ChrPageSize; 118 int32_t ChrMemoryOffset[0x40]; 119 ChrMemoryType ChrType[0x40]; 120 MemoryAccessType ChrMemoryAccess[0x40]; 121 122 uint32_t WorkRamPageSize; 123 uint32_t SaveRamPageSize; 124 125 MirroringType Mirroring; 126 bool HasBattery; 127 }; 128 129 struct PPUControlFlags 130 { 131 bool VerticalWrite; 132 uint16_t SpritePatternAddr; 133 uint16_t BackgroundPatternAddr; 134 bool LargeSprites; 135 bool VBlank; 136 137 bool Grayscale; 138 bool BackgroundMask; 139 bool SpriteMask; 140 bool BackgroundEnabled; 141 bool SpritesEnabled; 142 bool IntensifyRed; 143 bool IntensifyGreen; 144 bool IntensifyBlue; 145 }; 146 147 struct PPUStatusFlags 148 { 149 bool SpriteOverflow; 150 bool Sprite0Hit; 151 bool VerticalBlank; 152 }; 153 154 struct PPUState 155 { 156 uint8_t Control; 157 uint8_t Mask; 158 uint8_t Status; 159 uint32_t SpriteRamAddr; 160 uint16_t VideoRamAddr; 161 uint8_t XScroll; 162 uint16_t TmpVideoRamAddr; 163 bool WriteToggle; 164 165 uint16_t HighBitShift; 166 uint16_t LowBitShift; 167 }; 168 169 struct TileInfo 170 { 171 uint8_t LowByte; 172 uint8_t HighByte; 173 uint32_t PaletteOffset; 174 uint16_t TileAddr; 175 176 int32_t AbsoluteTileAddr; //used by HD ppu 177 uint8_t OffsetY; //used by HD ppu 178 }; 179 180 struct SpriteInfo : TileInfo 181 { 182 bool HorizontalMirror; 183 bool BackgroundPriority; 184 uint8_t SpriteX; 185 186 bool VerticalMirror; //used by HD ppu 187 }; 188 189 struct ApuLengthCounterState 190 { 191 bool Halt; 192 uint8_t Counter; 193 uint8_t ReloadValue; 194 }; 195 196 struct ApuEnvelopeState 197 { 198 bool StartFlag; 199 bool Loop; 200 bool ConstantVolume; 201 uint8_t Divider; 202 uint8_t Counter; 203 uint8_t Volume; 204 }; 205 206 struct ApuSquareState 207 { 208 uint8_t Duty; 209 uint8_t DutyPosition; 210 uint16_t Period; 211 uint16_t Timer; 212 213 bool SweepEnabled; 214 bool SweepNegate; 215 uint8_t SweepPeriod; 216 uint8_t SweepShift; 217 218 bool Enabled; 219 uint8_t OutputVolume; 220 double Frequency; 221 222 ApuLengthCounterState LengthCounter; 223 ApuEnvelopeState Envelope; 224 }; 225 226 struct ApuTriangleState 227 { 228 uint16_t Period; 229 uint16_t Timer; 230 uint8_t SequencePosition; 231 232 bool Enabled; 233 double Frequency; 234 uint8_t OutputVolume; 235 236 ApuLengthCounterState LengthCounter; 237 }; 238 239 struct ApuNoiseState 240 { 241 uint16_t Period; 242 uint16_t Timer; 243 uint16_t ShiftRegister; 244 bool ModeFlag; 245 246 bool Enabled; 247 double Frequency; 248 uint8_t OutputVolume; 249 250 ApuLengthCounterState LengthCounter; 251 ApuEnvelopeState Envelope; 252 }; 253 254 struct ApuDmcState 255 { 256 double SampleRate; 257 uint16_t SampleAddr; 258 uint16_t SampleLength; 259 260 bool Loop; 261 bool IrqEnabled; 262 uint16_t Period; 263 uint16_t Timer; 264 uint16_t BytesRemaining; 265 266 uint8_t OutputVolume; 267 }; 268 269 struct ApuFrameCounterState 270 { 271 bool FiveStepMode; 272 uint8_t SequencePosition; 273 bool IrqEnabled; 274 }; 275 276 struct ApuState 277 { 278 ApuSquareState Square1; 279 ApuSquareState Square2; 280 ApuTriangleState Triangle; 281 ApuNoiseState Noise; 282 ApuDmcState Dmc; 283 ApuFrameCounterState FrameCounter; 284 }; 285 286 struct MousePosition 287 { 288 int16_t X; 289 int16_t Y; 290 }; 291 292 struct MouseMovement 293 { 294 int16_t dx; 295 int16_t dy; 296 }; 297 298 enum class ConsoleFeatures 299 { 300 None = 0, 301 Fds = 1, 302 Nsf = 2, 303 VsSystem = 4, 304 BarcodeReader = 8, 305 TapeRecorder = 16, 306 BandaiMicrophone = 32, 307 DatachBarcodeReader = 64 308 }; 309 310 enum class RecordMovieFrom 311 { 312 StartWithoutSaveData = 0, 313 StartWithSaveData, 314 CurrentState 315 }; 316 317 struct RecordMovieOptions 318 { 319 public: 320 char Filename[2000] = {}; 321 char Author[250] = {}; 322 char Description[10000] = {}; 323 324 RecordMovieFrom RecordFrom = RecordMovieFrom::StartWithoutSaveData; 325 }; 326 327 enum class GameSystem 328 { 329 NesNtsc, 330 NesPal, 331 Famicom, 332 Dendy, 333 VsSystem, 334 Playchoice, 335 FDS, 336 Unknown, 337 }; 338 339 enum class BusConflictType 340 { 341 Default = 0, 342 Yes, 343 No 344 }; 345 346 struct HashInfo 347 { 348 uint32_t Crc32 = 0; 349 uint32_t PrgCrc32 = 0; 350 uint32_t PrgChrCrc32 = 0; 351 string Sha1; 352 string PrgChrMd5; 353 }; 354 355 enum class RomFormat 356 { 357 Unknown = 0, 358 iNes = 1, 359 Unif = 2, 360 Fds = 3, 361 Nsf = 4, 362 }; 363 364 enum class VsSystemType 365 { 366 Default = 0, 367 RbiBaseballProtection = 1, 368 TkoBoxingProtection = 2, 369 SuperXeviousProtection = 3, 370 IceClimberProtection = 4, 371 VsDualSystem = 5, 372 RaidOnBungelingBayProtection = 6, 373 }; 374 375 enum class GameInputType 376 { 377 Unspecified = 0, 378 StandardControllers = 1, 379 FourScore = 2, 380 FourPlayerAdapter = 3, 381 VsSystem = 4, 382 VsSystemSwapped = 5, 383 VsSystemSwapAB = 6, 384 VsZapper = 7, 385 Zapper = 8, 386 TwoZappers = 9, 387 BandaiHypershot = 0x0A, 388 PowerPadSideA = 0x0B, 389 PowerPadSideB = 0x0C, 390 FamilyTrainerSideA = 0x0D, 391 FamilyTrainerSideB = 0x0E, 392 ArkanoidControllerNes = 0x0F, 393 ArkanoidControllerFamicom = 0x10, 394 DoubleArkanoidController = 0x11, 395 KonamiHyperShot = 0x12, 396 PachinkoController = 0x13, 397 ExcitingBoxing = 0x14, 398 JissenMahjong = 0x15, 399 PartyTap = 0x16, 400 OekaKidsTablet = 0x17, 401 BarcodeBattler = 0x18, 402 MiraclePiano = 0x19, //not supported yet 403 PokkunMoguraa = 0x1A, //not supported yet 404 TopRider = 0x1B, //not supported yet 405 DoubleFisted = 0x1C, //not supported yet 406 Famicom3dSystem = 0x1D, //not supported yet 407 DoremikkoKeyboard = 0x1E, //not supported yet 408 ROB = 0x1F, //not supported yet 409 FamicomDataRecorder = 0x20, 410 TurboFile = 0x21, 411 BattleBox = 0x22, 412 FamilyBasicKeyboard = 0x23, 413 Pec586Keyboard = 0x24, //not supported yet 414 Bit79Keyboard = 0x25, //not supported yet 415 SuborKeyboard = 0x26, 416 SuborKeyboardMouse1 = 0x27, 417 SuborKeyboardMouse2 = 0x28, 418 SnesMouse = 0x29, 419 GenericMulticart = 0x2A, //not supported yet 420 SnesControllers = 0x2B, 421 RacermateBicycle = 0x2C, //not supported yet 422 UForce = 0x2D, //not supported yet 423 LastEntry 424 }; 425 426 enum class PpuModel 427 { 428 Ppu2C02 = 0, 429 Ppu2C03 = 1, 430 Ppu2C04A = 2, 431 Ppu2C04B = 3, 432 Ppu2C04C = 4, 433 Ppu2C04D = 5, 434 Ppu2C05A = 6, 435 Ppu2C05B = 7, 436 Ppu2C05C = 8, 437 Ppu2C05D = 9, 438 Ppu2C05E = 10 439 }; 440 441 enum class ConsoleId 442 { 443 Master = 0, 444 Slave = 1, 445 HistoryViewer = 2 446 };