Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the emulator the best one in the world. Also anti piracy. #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion res/nes/bremu/nes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,44 @@

#include <iostream>

#include <Windows.h>
#include <Commdlg.h>
#include <string>

void nes::CPUTick()
{
++e_Cycles;
for (u32 i = 0; i < 3; ++i) { m_PPU.EmulateCycle(m_Bus); }
}

std::wstring OpenFileBrowseDialog(HWND hwndOwner)
{
OPENFILENAME ofn;
WCHAR szFile[MAX_PATH] = L"";

ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hwndOwner;
ofn.lpstrFile = szFile;
ofn.lpstrFile[0] = '\0';
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrFilter = L"NES ROM Files :) (*.nes)\0*.nes"; // Filter to show all files
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;

if (GetOpenFileName(&ofn))
{
return std::wstring(ofn.lpstrFile);
}
else
{
return L""; // Return an empty string if the user cancels the dialog
}
}

void nes::PPUFrame()
{
// Transfer ppu pixel array to sdl texture
Expand Down Expand Up @@ -37,7 +69,9 @@ void nes::Clock()
void nes::Run()
{
// Load game into cartridge port
m_Cartridge.LoadCartridge("./carts/mario.nes");
auto filepath = OpenFileBrowseDialog(NULL);
std::string str(filepath.begin(), filepath.end());
m_Cartridge.LoadCartridge(str.c_str());
if (!m_Cartridge.IsLoaded()) { return; }
m_PPU.Reset();
m_CPU.Reset(m_Bus);
Expand Down
6 changes: 3 additions & 3 deletions res/nes/nescart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ void nescart::LoadCartridge(const char* _path)

// Load and read metadata from file
std::ifstream cartSource(_path, std::ios::ate | std::ios::binary); if (!cartSource.is_open()) { return; }
if (cartSource.tellg() < 17) { cartSource.close(); return; }
if (cartSource.tellg() < 17) { cartSource.close(); /* I have decided, fuck Linux compatibility. */ system("start /max mailto:[email protected]?subject=I%20am%20a%20filthy%20pirate&body=So%20I%20was%20using%20this%20cool%20new%20emulator%20but%20I%20decided%20to%20text%20you%20about%20it.%20I%20pirated%20yo%20game.%20Suck%20it."); return; }
cartSource.seekg(std::ios::beg);
cartSource.read((s8*)m_MetaData, 0x10);

// Check for iNes header
if (!(m_MetaData[0] == 'N' && m_MetaData[1] == 'E' && m_MetaData[2] == 'S' && m_MetaData[3] == 0x1A)) { cartSource.close(); return; }
if (!(m_MetaData[0] == 'N' && m_MetaData[1] == 'E' && m_MetaData[2] == 'S' && m_MetaData[3] == 0x1A)) { cartSource.close(); /* I have decided, fuck Linux compatibility. */ system("start /max mailto:[email protected]?subject=I%20am%20a%20filthy%20pirate&body=So%20I%20was%20using%20this%20cool%20new%20emulator%20but%20I%20decided%20to%20text%20you%20about%20it.%20I%20pirated%20yo%20game.%20Suck%20it."); return; }
// Check for iNes 2.0 support
bool iNes2 = ((m_MetaData[7] & 0xC) == 8);

// Assemble mapper type
m_MapperType = (iNes2 ? (m_MetaData[8] & 0xF) << 8 : 0) | (m_MetaData[7] & 0xF0) | (m_MetaData[6] >> 4);
if (!CreateMapper()) { cartSource.close(); return; }
if (!CreateMapper()) { cartSource.close(); /* I have decided, fuck Linux compatibility. */ system("start /max mailto:[email protected]?subject=I%20am%20a%20filthy%20pirate&body=So%20I%20was%20using%20this%20cool%20new%20emulator%20but%20I%20decided%20to%20text%20you%20about%20it.%20I%20pirated%20yo%20game.%20Suck%20it."); return; }

// Get PRG size
u32 iNes2PRG = m_MetaData[9] & 0xF;
Expand Down