├── .clang-format
├── .editorconfig
├── .gitattributes
├── .github
└── workflows
│ └── nin.yml
├── .gitignore
├── CMakeLists.txt
├── LICENSE
├── LICENSE-GPLv2.txt
├── README.md
├── cmake
├── FindQtDeploy.cmake
└── FindRuby.cmake
├── data
├── nin.desktop
├── nin.icns
├── nin.ico
├── nin.plist
├── nin.png
├── nin.rc
└── test_roms
│ ├── blargg_branch_timing
│ ├── 1-basics.nes
│ ├── 2-backward.nes
│ └── 3-forward.nes
│ ├── blargg_cpu_test5
│ ├── 01-basics.nes
│ ├── 02-implied.nes
│ ├── 03-immediate.nes
│ ├── 04-zero_page.nes
│ ├── 05-zp_xy.nes
│ ├── 06-absolute.nes
│ ├── 07-abs_xy.nes
│ ├── 08-ind_x.nes
│ ├── 09-ind_y.nes
│ ├── 10-branches.nes
│ ├── 11-stack.nes
│ ├── 12-jmp_jsr.nes
│ ├── 13-rts.nes
│ ├── 14-rti.nes
│ ├── 15-brk.nes
│ └── 16-special.nes
│ ├── blargg_ppu_tests
│ ├── 1-palette_ram.nes
│ ├── 2-sprite_ram.nes
│ ├── 3-vbl_clear_time.nes
│ └── 4-vram_access.nes
│ ├── blargg_ppu_vbl_nmi
│ ├── 01-vbl_basics.nes
│ ├── 02-vbl_set_time.nes
│ ├── 03-vbl_clear_time.nes
│ ├── 04-nmi_control.nes
│ ├── 05-nmi_timing.nes
│ ├── 06-suppression.nes
│ ├── 07-nmi_on_timing.nes
│ ├── 08-nmi_off_timing.nes
│ ├── 09-even_odd_frames.nes
│ └── 10-even_odd_timing.nes
│ ├── blargg_sprite_hit_tests
│ ├── 01-basics.nes
│ ├── 02-alignment.nes
│ ├── 03-corners.nes
│ ├── 04-flip.nes
│ ├── 05-left_clip.nes
│ ├── 06-right_edge.nes
│ ├── 07-screen_bottom.nes
│ ├── 08-double_height.nes
│ ├── 09-timing_basics.nes
│ ├── 10-timing_order.nes
│ └── 11-edge_timing.nes
│ └── blargg_vbl_nmi_timing
│ ├── 1-frame_basics.nes
│ ├── 2-vbl_timing.nes
│ ├── 3-even_odd_frames.nes
│ ├── 4-vbl_clear_timing.nes
│ ├── 5-nmi_suppression.nes
│ ├── 6-nmi_disable.nes
│ └── 7-nmi_timing.nes
├── include
└── nin
│ └── nin.h
├── screenshots
├── kirby.png
├── mario.png
├── mario3.png
├── megaman2.png
├── punchout.png
└── zelda.png
├── src
├── CMakeLists.txt
├── NinEmu
│ ├── CMakeLists.txt
│ ├── Core
│ │ ├── Audio.cpp
│ │ ├── Audio.h
│ │ ├── EmulatorInfo.h
│ │ ├── EmulatorWorker.cpp
│ │ ├── EmulatorWorker.h
│ │ ├── Settings.cpp
│ │ └── Settings.h
│ ├── Menu
│ │ ├── DiskMenu.cpp
│ │ ├── DiskMenu.h
│ │ ├── GraphicsMenu.cpp
│ │ └── GraphicsMenu.h
│ ├── UI
│ │ ├── DisassemblerWidget.cpp
│ │ ├── DisassemblerWidget.h
│ │ ├── HexView.cpp
│ │ ├── HexView.h
│ │ ├── RenderWidget.cpp
│ │ ├── RenderWidget.h
│ │ ├── SignalVisualizer.cpp
│ │ └── SignalVisualizer.h
│ ├── UX
│ │ ├── AspectRatio.h
│ │ └── Overscan.h
│ ├── Window
│ │ ├── AudioVisualizerWindow.cpp
│ │ ├── AudioVisualizerWindow.h
│ │ ├── DebuggerWindow.cpp
│ │ ├── DebuggerWindow.h
│ │ ├── MainWindow.cpp
│ │ ├── MainWindow.h
│ │ ├── MemorySearchWindow.cpp
│ │ ├── MemorySearchWindow.h
│ │ ├── MemoryWindow.cpp
│ │ └── MemoryWindow.h
│ └── main.cpp
├── libnin
│ ├── API.cpp
│ ├── APU.cpp
│ ├── APU.h
│ ├── Audio.cpp
│ ├── Audio.h
│ ├── BusMain.cpp
│ ├── BusMain.h
│ ├── BusVideo.cpp
│ ├── BusVideo.h
│ ├── CMakeLists.txt
│ ├── CPU.cpp
│ ├── CPU.h
│ ├── CPU_impl.h
│ ├── Cart.cpp
│ ├── Cart.h
│ ├── Disk.cpp
│ ├── Disk.h
│ ├── HardwareInfo.cpp
│ ├── HardwareInfo.h
│ ├── HardwareSpecs.cpp
│ ├── HardwareSpecs.h
│ ├── IRQ.h
│ ├── Input.cpp
│ ├── Input.h
│ ├── Mapper.cpp
│ ├── Mapper.h
│ ├── Mapper
│ │ ├── AXROM.cpp
│ │ ├── AXROM.h
│ │ ├── Action52.cpp
│ │ ├── Action52.h
│ │ ├── CNROM.cpp
│ │ ├── CNROM.h
│ │ ├── CPROM.cpp
│ │ ├── CPROM.h
│ │ ├── ColorDreams.cpp
│ │ ├── ColorDreams.h
│ │ ├── DXROM.cpp
│ │ ├── DXROM.h
│ │ ├── DiskSystem.cpp
│ │ ├── DiskSystem.h
│ │ ├── GXROM.cpp
│ │ ├── GXROM.h
│ │ ├── MMC1.cpp
│ │ ├── MMC1.h
│ │ ├── MMC2.cpp
│ │ ├── MMC2.h
│ │ ├── MMC3.cpp
│ │ ├── MMC3.h
│ │ ├── MMC4.cpp
│ │ ├── MMC4.h
│ │ ├── MMC5.cpp
│ │ ├── MMC5.h
│ │ ├── Mapper15.cpp
│ │ ├── Mapper15.h
│ │ ├── UXROM.cpp
│ │ └── UXROM.h
│ ├── MapperID.cpp
│ ├── MapperID.h
│ ├── MapperVariant.h
│ ├── MemberStateHelper.h
│ ├── Memory.cpp
│ ├── Memory.h
│ ├── NMI.h
│ ├── NonCopyable.h
│ ├── PPU.cpp
│ ├── PPU.h
│ ├── RomHeader.h
│ ├── Save.cpp
│ ├── Save.h
│ ├── State.cpp
│ ├── State.h
│ ├── Util.h
│ ├── Video.cpp
│ ├── Video.h
│ └── config.h.in
├── ninconv
│ ├── CMakeLists.txt
│ ├── crc32.c
│ ├── dirent.h
│ ├── gen_db.rb
│ ├── inc
│ │ └── db.inc
│ ├── ninconv.c
│ └── ninconv.h
├── ninhash
│ ├── CMakeLists.txt
│ └── ninhash.cpp
├── ninperf
│ ├── CMakeLists.txt
│ └── ninperf.cpp
└── nintests
│ ├── CMakeLists.txt
│ ├── TestSuite.cpp
│ ├── TestSuite.h
│ └── main.cpp
├── third_party
├── CMakeLists.txt
└── openal
│ └── CMakeLists.txt
└── tools
└── gen_6502.rb
/.clang-format:
--------------------------------------------------------------------------------
1 | ---
2 | Language: Cpp
3 |
4 | AccessModifierOffset: -4
5 | AlignConsecutiveAssignments: true
6 | AlignConsecutiveDeclarations: true
7 | AlignConsecutiveMacros: true
8 | AllowShortIfStatementsOnASingleLine: true
9 | AlwaysBreakTemplateDeclarations: No
10 | BinPackArguments: false
11 | BinPackParameters: false
12 | BreakBeforeBraces: Allman
13 | BreakConstructorInitializersBeforeComma: true
14 | ColumnLimit: 0
15 | ConstructorInitializerIndentWidth: 0
16 | Cpp11BracedListStyle: true
17 | DerivePointerAlignment: false
18 | IndentWidth: 4
19 | NamespaceIndentation: None
20 | PointerAlignment: Left
21 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | charset = utf-8
5 | end_of_line = lf
6 | indent_size = 4
7 | indent_style = space
8 | insert_final_newline = true
9 | trim_trailing_whitespace = true
10 |
11 | [*.yml]
12 | indent_size = 2
13 |
14 | [*.rb]
15 | indent_size = 2
16 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | * text=auto
2 | db.inc linguist-language=C linguist-vendored
3 | dirent.h linguist-language=C linguist-vendored
4 |
--------------------------------------------------------------------------------
/.github/workflows/nin.yml:
--------------------------------------------------------------------------------
1 | name: Nin
2 |
3 | on:
4 | push:
5 | branches:
6 | - "*"
7 | tags:
8 | - "v*"
9 | pull_request:
10 |
11 | jobs:
12 | build:
13 | strategy:
14 | fail-fast: false
15 | matrix:
16 | name:
17 | - win64
18 | - win32
19 | - macos
20 | - linux
21 | include:
22 | - name: win64
23 | os: windows-2019
24 | qt_arch: win64_msvc2017_64
25 | cmake_opts: -A x64
26 | - name: win32
27 | os: windows-2019
28 | qt_arch: win32_msvc2015
29 | cmake_opts: -A Win32
30 | - name: macos
31 | os: macos-latest
32 | cmake_opts: -DCMAKE_BUILD_TYPE=Release
33 | - name: linux
34 | os: ubuntu-16.04
35 | cmake_opts: -DCMAKE_BUILD_TYPE=Release
36 | runs-on: ${{ matrix.os }}
37 | env:
38 | QT_VERSION: 5.9.9
39 | steps:
40 | - name: Cache Qt
41 | id: cache-qt
42 | uses: actions/cache@v1
43 | with:
44 | path: ../Qt
45 | key: Qt-${{ env.QT_VERSION }}-${{ matrix.name }}
46 | - name: Install Qt
47 | uses: jurplel/install-qt-action@v2
48 | with:
49 | arch: ${{ matrix.qt_arch }}
50 | cached: ${{ steps.cache-qt.outputs.cache-hit }}
51 | version: ${{ env.QT_VERSION }}
52 | - name: Install Ruby
53 | uses: actions/setup-ruby@v1
54 | with:
55 | ruby-version: 2.6.x
56 | - name: Checkout
57 | uses: actions/checkout@v2
58 | - name: Setup
59 | run: |
60 | mkdir build
61 | - name: Build
62 | run: |
63 | cmake .. ${{ matrix.cmake_opts }}
64 | cmake --build . --config Release
65 | working-directory: ./build
66 | - name: Test
67 | run: cmake --build . --config Release --target test
68 | working-directory: ./build
69 | - name: Package
70 | run: |
71 | cmake --build . --config Release --target package
72 | cmake -E remove_directory ./pkg/_CPack_Packages
73 | working-directory: ./build
74 | - name: Upload Artifact
75 | uses: actions/upload-artifact@v1
76 | with:
77 | name: ${{ matrix.name }}
78 | path: build/pkg
79 | release:
80 | if: startsWith(github.ref, 'refs/tags/')
81 | needs: [build]
82 | runs-on: ubuntu-latest
83 | steps:
84 | - name: Download win64
85 | uses: actions/download-artifact@v1
86 | with:
87 | name: win64
88 | path: pkg
89 | - name: Download win32
90 | uses: actions/download-artifact@v1
91 | with:
92 | name: win32
93 | path: pkg
94 | - name: Download macOS
95 | uses: actions/download-artifact@v1
96 | with:
97 | name: macOS
98 | path: pkg
99 | - name: Download linux
100 | uses: actions/download-artifact@v1
101 | with:
102 | name: linux
103 | path: pkg
104 | - name: Release
105 | uses: softprops/action-gh-release@v1
106 | with:
107 | files: "pkg/*"
108 | draft: true
109 | prerelease: true
110 | env:
111 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
112 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 | /CMakeSettings.json
3 |
--------------------------------------------------------------------------------
/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # Nin, a Nintendo Entertainment System Emulator.
2 | #
3 | # Copyright (c) 2018-2020 Maxime Bacoux
4 | # All rights reserved.
5 | #
6 | # This program is free software; you can redistribute it and/or
7 | # modify it under the terms of the GNU General Public License
8 | # Version 2, as published by the Free Software Foundation.
9 | #
10 | # Alternatively, this program can be licensed under a commercial license
11 | # upon request.
12 | #
13 | # When using the program under the GNU General Public License Version 2 license,
14 | # the following apply:
15 | #
16 | # 1. This program is distributed in the hope that it will be useful,
17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 | # GNU General Public License for more details.
20 | #
21 | # 2. You should have received a copy of the GNU General Public License
22 | # along with this program; if not, write to the Free Software
23 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 |
25 | cmake_minimum_required(VERSION 3.14)
26 |
27 | set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
28 |
29 | set(CMAKE_OSX_DEPLOYMENT_TARGET 10.9 CACHE STRING "")
30 |
31 | set(VERSION_MAJOR 0)
32 | set(VERSION_MINOR 8)
33 | set(VERSION_PATCH 0)
34 | set(VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
35 |
36 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
37 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
38 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
39 |
40 | project(Nin VERSION "${VERSION}" LANGUAGES C CXX)
41 |
42 | add_subdirectory(third_party)
43 | add_subdirectory(src)
44 |
45 | # CPack
46 | set(CPACK_PACKAGE_NAME "Nin")
47 | set(CPACK_PACKAGE_VENDOR "Maxime Bacoux")
48 | set(CPACK_PACKAGE_CONTACT "Maxime Bacoux")
49 | set(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR})
50 | set(CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR})
51 | set(CPACK_PACKAGE_VERSION_PATCH ${VERSION_PATCH})
52 | set(CPACK_PACKAGE_DIRECTORY "${CMAKE_BINARY_DIR}/pkg")
53 |
54 | if (WIN32)
55 | set(CPACK_GENERATOR "ZIP")
56 | elseif(APPLE)
57 | set(CPACK_GENERATOR "DragNDrop")
58 | set(CPACK_SYSTEM_NAME "mac")
59 | elseif(UNIX)
60 | set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6, libgcc1, libstdc++6, libopenal1, libgl1, libopengl0, libqt5core5a, libqt5gui5, libqt5widgets5, libqt5gamepad5")
61 | set(CPACK_GENERATOR "DEB")
62 | endif()
63 | include(CPack)
64 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Nin, a Nintendo Entertainment System Emulator.
2 |
3 | Copyright (c) 2018-2020 Maxime Bacoux
4 | All rights reserved.
5 |
6 | This program is free software; you can redistribute it and/or
7 | modify it under the terms of the GNU General Public License
8 | Version 2, as published by the Free Software Foundation.
9 |
10 | Alternatively, this program can be licensed under a commercial license
11 | upon request.
12 |
13 | When using the program under the GNU General Public License Version 2 license,
14 | the following apply:
15 |
16 | 1. This program is distributed in the hope that it will be useful,
17 | but WITHOUT ANY WARRANTY; without even the implied warranty of
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 | GNU General Public License for more details.
20 |
21 | 2. You should have received a copy of the GNU General Public License
22 | along with this program; if not, write to the Free Software
23 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
The advanced NES emulator
4 |
5 |
6 | 
7 | 
8 | 
9 | 
10 | 
11 |
12 | ## Overview
13 |
14 | Nin is an advanced Nintendo Entertainement System and Famicom emulator that is actively being developped.
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 | ## Features
26 |
27 | Right now, the emulator is not very polished on the UX side, but can run many games without issues.
28 | A gamepad is supported. The exact mapping will depend on the vendor's layout.
29 | On a keyboard, the arrows are mapped to the NES D-Pad, Space is Select, Enter is Start, Z is A and X is B.
30 | Multiple controllers or other kinds of controller are not currently supported.
31 |
32 | ## Supported Mappers
33 |
34 | * NROM
35 | * MMC1
36 | * MMC2
37 | * MMC3
38 | * MMC4
39 | * MMC5
40 | * UxROM (Standard, 180)
41 | * CNROM
42 | * AxROM
43 | * GxROM
44 | * Color Dreams
45 | * Action 52
46 |
47 | MMC3 support is still experimental.
48 |
49 | ## Build
50 |
51 | Nin requires cmake and Qt 5.12 or newer.
52 |
53 | Basic build instructions under an Unix-like OS:
54 |
55 | git clone https://github.com/Nax/nin
56 | cd nin
57 | mkdir build
58 | cd build
59 | cmake .. -DCMAKE_BUILD_TYPE=Release
60 | make
61 |
62 | Under windows, MSVC 2017 and 2019 are the prefered toolchains.
63 |
64 | ## License
65 |
66 | Nin is [dual licensed](LICENSE) under the follwing licenses:
67 |
68 | * The [GNU General Public License Version 2](LICENSE-GPLv2.txt)
69 | * A commercial license, upon request
70 |
71 | ## Author
72 |
73 | Nin was developped by [Maxime Bacoux "Nax"](https://github.com/Nax).
74 |
--------------------------------------------------------------------------------
/cmake/FindQtDeploy.cmake:
--------------------------------------------------------------------------------
1 | # Nin, a Nintendo Entertainment System Emulator.
2 | #
3 | # Copyright (c) 2018-2020 Maxime Bacoux
4 | # All rights reserved.
5 | #
6 | # This program is free software; you can redistribute it and/or
7 | # modify it under the terms of the GNU General Public License
8 | # Version 2, as published by the Free Software Foundation.
9 | #
10 | # Alternatively, this program can be licensed under a commercial license
11 | # upon request.
12 | #
13 | # When using the program under the GNU General Public License Version 2 license,
14 | # the following apply:
15 | #
16 | # 1. This program is distributed in the hope that it will be useful,
17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 | # GNU General Public License for more details.
20 | #
21 | # 2. You should have received a copy of the GNU General Public License
22 | # along with this program; if not, write to the Free Software
23 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 |
25 | if (APPLE)
26 | set(_name macdeployqt)
27 | elseif (WIN32)
28 | set(_name windeployqt)
29 | else()
30 | set(_name linuxdeployqt)
31 | endif()
32 |
33 | find_program(
34 | QT_DEPLOY
35 | NAMES ${_name}
36 | PATH_SUFFIXES bin
37 | PATHS
38 | ENV QTDIR
39 | ENV QT_DIR
40 | ENV Qt5_DIR
41 | ENV Qt5_ROOT
42 | )
43 |
44 | include(FindPackageHandleStandardArgs)
45 | find_package_handle_standard_args(QtDeploy DEFAULT_MSG QT_DEPLOY)
46 | mark_as_advanced(QT_DEPLOY)
47 |
--------------------------------------------------------------------------------
/cmake/FindRuby.cmake:
--------------------------------------------------------------------------------
1 | # Nin, a Nintendo Entertainment System Emulator.
2 | #
3 | # Copyright (c) 2018-2020 Maxime Bacoux
4 | # All rights reserved.
5 | #
6 | # This program is free software; you can redistribute it and/or
7 | # modify it under the terms of the GNU General Public License
8 | # Version 2, as published by the Free Software Foundation.
9 | #
10 | # Alternatively, this program can be licensed under a commercial license
11 | # upon request.
12 | #
13 | # When using the program under the GNU General Public License Version 2 license,
14 | # the following apply:
15 | #
16 | # 1. This program is distributed in the hope that it will be useful,
17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 | # GNU General Public License for more details.
20 | #
21 | # 2. You should have received a copy of the GNU General Public License
22 | # along with this program; if not, write to the Free Software
23 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 |
25 | find_program(
26 | RUBY_EXECUTABLE ruby
27 | )
28 |
29 | include(FindPackageHandleStandardArgs)
30 | find_package_handle_standard_args(Ruby DEFAULT_MSG RUBY_EXECUTABLE)
31 | mark_as_advanced(RUBY_EXECUTABLE)
32 |
--------------------------------------------------------------------------------
/data/nin.desktop:
--------------------------------------------------------------------------------
1 | [Desktop Entry]
2 | Type=Application
3 | Name=Nin
4 | Comment=A NES emulator
5 | Exec=nin
6 | Icon=nin
7 | Terminal=false
8 | Categories=Emulator;Game;
9 |
--------------------------------------------------------------------------------
/data/nin.icns:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nax/nin/745c396f22134e4a9d648a652ea6a19d473436f4/data/nin.icns
--------------------------------------------------------------------------------
/data/nin.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nax/nin/745c396f22134e4a9d648a652ea6a19d473436f4/data/nin.ico
--------------------------------------------------------------------------------
/data/nin.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | English
7 | CFBundleExecutable
8 | Nin
9 | CFBundleGetInfoString
10 |
11 | CFBundleIconFile
12 | nin
13 | CFBundleIdentifier
14 |
15 | CFBundleInfoDictionaryVersion
16 | 6.0
17 | CFBundleLongVersionString
18 |
19 | CFBundleName
20 |
21 | CFBundlePackageType
22 | APPL
23 | CFBundleShortVersionString
24 |
25 | CFBundleSignature
26 | ????
27 | CFBundleVersion
28 |
29 | CSResourcesFileMapped
30 |
31 | NSHumanReadableCopyright
32 |
33 | NSPrincipalClass
34 | NSApplication
35 | NSHighResolutionCapable
36 | True
37 |
38 |
39 |
--------------------------------------------------------------------------------
/data/nin.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nax/nin/745c396f22134e4a9d648a652ea6a19d473436f4/data/nin.png
--------------------------------------------------------------------------------
/data/nin.rc:
--------------------------------------------------------------------------------
1 | IDI_ICON1 ICON DISCARDABLE "nin.ico"
2 |
--------------------------------------------------------------------------------
/data/test_roms/blargg_branch_timing/1-basics.nes:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nax/nin/745c396f22134e4a9d648a652ea6a19d473436f4/data/test_roms/blargg_branch_timing/1-basics.nes
--------------------------------------------------------------------------------
/data/test_roms/blargg_branch_timing/2-backward.nes:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nax/nin/745c396f22134e4a9d648a652ea6a19d473436f4/data/test_roms/blargg_branch_timing/2-backward.nes
--------------------------------------------------------------------------------
/data/test_roms/blargg_branch_timing/3-forward.nes:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nax/nin/745c396f22134e4a9d648a652ea6a19d473436f4/data/test_roms/blargg_branch_timing/3-forward.nes
--------------------------------------------------------------------------------
/data/test_roms/blargg_cpu_test5/01-basics.nes:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nax/nin/745c396f22134e4a9d648a652ea6a19d473436f4/data/test_roms/blargg_cpu_test5/01-basics.nes
--------------------------------------------------------------------------------
/data/test_roms/blargg_cpu_test5/02-implied.nes:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nax/nin/745c396f22134e4a9d648a652ea6a19d473436f4/data/test_roms/blargg_cpu_test5/02-implied.nes
--------------------------------------------------------------------------------
/data/test_roms/blargg_cpu_test5/03-immediate.nes:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nax/nin/745c396f22134e4a9d648a652ea6a19d473436f4/data/test_roms/blargg_cpu_test5/03-immediate.nes
--------------------------------------------------------------------------------
/data/test_roms/blargg_cpu_test5/04-zero_page.nes:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nax/nin/745c396f22134e4a9d648a652ea6a19d473436f4/data/test_roms/blargg_cpu_test5/04-zero_page.nes
--------------------------------------------------------------------------------
/data/test_roms/blargg_cpu_test5/05-zp_xy.nes:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nax/nin/745c396f22134e4a9d648a652ea6a19d473436f4/data/test_roms/blargg_cpu_test5/05-zp_xy.nes
--------------------------------------------------------------------------------
/data/test_roms/blargg_cpu_test5/06-absolute.nes:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nax/nin/745c396f22134e4a9d648a652ea6a19d473436f4/data/test_roms/blargg_cpu_test5/06-absolute.nes
--------------------------------------------------------------------------------
/data/test_roms/blargg_cpu_test5/07-abs_xy.nes:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nax/nin/745c396f22134e4a9d648a652ea6a19d473436f4/data/test_roms/blargg_cpu_test5/07-abs_xy.nes
--------------------------------------------------------------------------------
/data/test_roms/blargg_cpu_test5/08-ind_x.nes:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nax/nin/745c396f22134e4a9d648a652ea6a19d473436f4/data/test_roms/blargg_cpu_test5/08-ind_x.nes
--------------------------------------------------------------------------------
/data/test_roms/blargg_cpu_test5/09-ind_y.nes:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nax/nin/745c396f22134e4a9d648a652ea6a19d473436f4/data/test_roms/blargg_cpu_test5/09-ind_y.nes
--------------------------------------------------------------------------------
/data/test_roms/blargg_cpu_test5/10-branches.nes:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nax/nin/745c396f22134e4a9d648a652ea6a19d473436f4/data/test_roms/blargg_cpu_test5/10-branches.nes
--------------------------------------------------------------------------------
/data/test_roms/blargg_cpu_test5/11-stack.nes:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nax/nin/745c396f22134e4a9d648a652ea6a19d473436f4/data/test_roms/blargg_cpu_test5/11-stack.nes
--------------------------------------------------------------------------------
/data/test_roms/blargg_cpu_test5/12-jmp_jsr.nes:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nax/nin/745c396f22134e4a9d648a652ea6a19d473436f4/data/test_roms/blargg_cpu_test5/12-jmp_jsr.nes
--------------------------------------------------------------------------------
/data/test_roms/blargg_cpu_test5/13-rts.nes:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nax/nin/745c396f22134e4a9d648a652ea6a19d473436f4/data/test_roms/blargg_cpu_test5/13-rts.nes
--------------------------------------------------------------------------------
/data/test_roms/blargg_cpu_test5/14-rti.nes:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nax/nin/745c396f22134e4a9d648a652ea6a19d473436f4/data/test_roms/blargg_cpu_test5/14-rti.nes
--------------------------------------------------------------------------------
/data/test_roms/blargg_cpu_test5/15-brk.nes:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nax/nin/745c396f22134e4a9d648a652ea6a19d473436f4/data/test_roms/blargg_cpu_test5/15-brk.nes
--------------------------------------------------------------------------------
/data/test_roms/blargg_cpu_test5/16-special.nes:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nax/nin/745c396f22134e4a9d648a652ea6a19d473436f4/data/test_roms/blargg_cpu_test5/16-special.nes
--------------------------------------------------------------------------------
/data/test_roms/blargg_ppu_tests/1-palette_ram.nes:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nax/nin/745c396f22134e4a9d648a652ea6a19d473436f4/data/test_roms/blargg_ppu_tests/1-palette_ram.nes
--------------------------------------------------------------------------------
/data/test_roms/blargg_ppu_tests/2-sprite_ram.nes:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nax/nin/745c396f22134e4a9d648a652ea6a19d473436f4/data/test_roms/blargg_ppu_tests/2-sprite_ram.nes
--------------------------------------------------------------------------------
/data/test_roms/blargg_ppu_tests/3-vbl_clear_time.nes:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nax/nin/745c396f22134e4a9d648a652ea6a19d473436f4/data/test_roms/blargg_ppu_tests/3-vbl_clear_time.nes
--------------------------------------------------------------------------------
/data/test_roms/blargg_ppu_tests/4-vram_access.nes:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nax/nin/745c396f22134e4a9d648a652ea6a19d473436f4/data/test_roms/blargg_ppu_tests/4-vram_access.nes
--------------------------------------------------------------------------------
/data/test_roms/blargg_ppu_vbl_nmi/01-vbl_basics.nes:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nax/nin/745c396f22134e4a9d648a652ea6a19d473436f4/data/test_roms/blargg_ppu_vbl_nmi/01-vbl_basics.nes
--------------------------------------------------------------------------------
/data/test_roms/blargg_ppu_vbl_nmi/02-vbl_set_time.nes:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nax/nin/745c396f22134e4a9d648a652ea6a19d473436f4/data/test_roms/blargg_ppu_vbl_nmi/02-vbl_set_time.nes
--------------------------------------------------------------------------------
/data/test_roms/blargg_ppu_vbl_nmi/03-vbl_clear_time.nes:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nax/nin/745c396f22134e4a9d648a652ea6a19d473436f4/data/test_roms/blargg_ppu_vbl_nmi/03-vbl_clear_time.nes
--------------------------------------------------------------------------------
/data/test_roms/blargg_ppu_vbl_nmi/04-nmi_control.nes:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nax/nin/745c396f22134e4a9d648a652ea6a19d473436f4/data/test_roms/blargg_ppu_vbl_nmi/04-nmi_control.nes
--------------------------------------------------------------------------------
/data/test_roms/blargg_ppu_vbl_nmi/05-nmi_timing.nes:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nax/nin/745c396f22134e4a9d648a652ea6a19d473436f4/data/test_roms/blargg_ppu_vbl_nmi/05-nmi_timing.nes
--------------------------------------------------------------------------------
/data/test_roms/blargg_ppu_vbl_nmi/06-suppression.nes:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nax/nin/745c396f22134e4a9d648a652ea6a19d473436f4/data/test_roms/blargg_ppu_vbl_nmi/06-suppression.nes
--------------------------------------------------------------------------------
/data/test_roms/blargg_ppu_vbl_nmi/07-nmi_on_timing.nes:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nax/nin/745c396f22134e4a9d648a652ea6a19d473436f4/data/test_roms/blargg_ppu_vbl_nmi/07-nmi_on_timing.nes
--------------------------------------------------------------------------------
/data/test_roms/blargg_ppu_vbl_nmi/08-nmi_off_timing.nes:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nax/nin/745c396f22134e4a9d648a652ea6a19d473436f4/data/test_roms/blargg_ppu_vbl_nmi/08-nmi_off_timing.nes
--------------------------------------------------------------------------------
/data/test_roms/blargg_ppu_vbl_nmi/09-even_odd_frames.nes:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nax/nin/745c396f22134e4a9d648a652ea6a19d473436f4/data/test_roms/blargg_ppu_vbl_nmi/09-even_odd_frames.nes
--------------------------------------------------------------------------------
/data/test_roms/blargg_ppu_vbl_nmi/10-even_odd_timing.nes:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nax/nin/745c396f22134e4a9d648a652ea6a19d473436f4/data/test_roms/blargg_ppu_vbl_nmi/10-even_odd_timing.nes
--------------------------------------------------------------------------------
/data/test_roms/blargg_sprite_hit_tests/01-basics.nes:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nax/nin/745c396f22134e4a9d648a652ea6a19d473436f4/data/test_roms/blargg_sprite_hit_tests/01-basics.nes
--------------------------------------------------------------------------------
/data/test_roms/blargg_sprite_hit_tests/02-alignment.nes:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nax/nin/745c396f22134e4a9d648a652ea6a19d473436f4/data/test_roms/blargg_sprite_hit_tests/02-alignment.nes
--------------------------------------------------------------------------------
/data/test_roms/blargg_sprite_hit_tests/03-corners.nes:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nax/nin/745c396f22134e4a9d648a652ea6a19d473436f4/data/test_roms/blargg_sprite_hit_tests/03-corners.nes
--------------------------------------------------------------------------------
/data/test_roms/blargg_sprite_hit_tests/04-flip.nes:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nax/nin/745c396f22134e4a9d648a652ea6a19d473436f4/data/test_roms/blargg_sprite_hit_tests/04-flip.nes
--------------------------------------------------------------------------------
/data/test_roms/blargg_sprite_hit_tests/05-left_clip.nes:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nax/nin/745c396f22134e4a9d648a652ea6a19d473436f4/data/test_roms/blargg_sprite_hit_tests/05-left_clip.nes
--------------------------------------------------------------------------------
/data/test_roms/blargg_sprite_hit_tests/06-right_edge.nes:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nax/nin/745c396f22134e4a9d648a652ea6a19d473436f4/data/test_roms/blargg_sprite_hit_tests/06-right_edge.nes
--------------------------------------------------------------------------------
/data/test_roms/blargg_sprite_hit_tests/07-screen_bottom.nes:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nax/nin/745c396f22134e4a9d648a652ea6a19d473436f4/data/test_roms/blargg_sprite_hit_tests/07-screen_bottom.nes
--------------------------------------------------------------------------------
/data/test_roms/blargg_sprite_hit_tests/08-double_height.nes:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nax/nin/745c396f22134e4a9d648a652ea6a19d473436f4/data/test_roms/blargg_sprite_hit_tests/08-double_height.nes
--------------------------------------------------------------------------------
/data/test_roms/blargg_sprite_hit_tests/09-timing_basics.nes:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nax/nin/745c396f22134e4a9d648a652ea6a19d473436f4/data/test_roms/blargg_sprite_hit_tests/09-timing_basics.nes
--------------------------------------------------------------------------------
/data/test_roms/blargg_sprite_hit_tests/10-timing_order.nes:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nax/nin/745c396f22134e4a9d648a652ea6a19d473436f4/data/test_roms/blargg_sprite_hit_tests/10-timing_order.nes
--------------------------------------------------------------------------------
/data/test_roms/blargg_sprite_hit_tests/11-edge_timing.nes:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nax/nin/745c396f22134e4a9d648a652ea6a19d473436f4/data/test_roms/blargg_sprite_hit_tests/11-edge_timing.nes
--------------------------------------------------------------------------------
/data/test_roms/blargg_vbl_nmi_timing/1-frame_basics.nes:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nax/nin/745c396f22134e4a9d648a652ea6a19d473436f4/data/test_roms/blargg_vbl_nmi_timing/1-frame_basics.nes
--------------------------------------------------------------------------------
/data/test_roms/blargg_vbl_nmi_timing/2-vbl_timing.nes:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nax/nin/745c396f22134e4a9d648a652ea6a19d473436f4/data/test_roms/blargg_vbl_nmi_timing/2-vbl_timing.nes
--------------------------------------------------------------------------------
/data/test_roms/blargg_vbl_nmi_timing/3-even_odd_frames.nes:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nax/nin/745c396f22134e4a9d648a652ea6a19d473436f4/data/test_roms/blargg_vbl_nmi_timing/3-even_odd_frames.nes
--------------------------------------------------------------------------------
/data/test_roms/blargg_vbl_nmi_timing/4-vbl_clear_timing.nes:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nax/nin/745c396f22134e4a9d648a652ea6a19d473436f4/data/test_roms/blargg_vbl_nmi_timing/4-vbl_clear_timing.nes
--------------------------------------------------------------------------------
/data/test_roms/blargg_vbl_nmi_timing/5-nmi_suppression.nes:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nax/nin/745c396f22134e4a9d648a652ea6a19d473436f4/data/test_roms/blargg_vbl_nmi_timing/5-nmi_suppression.nes
--------------------------------------------------------------------------------
/data/test_roms/blargg_vbl_nmi_timing/6-nmi_disable.nes:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nax/nin/745c396f22134e4a9d648a652ea6a19d473436f4/data/test_roms/blargg_vbl_nmi_timing/6-nmi_disable.nes
--------------------------------------------------------------------------------
/data/test_roms/blargg_vbl_nmi_timing/7-nmi_timing.nes:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nax/nin/745c396f22134e4a9d648a652ea6a19d473436f4/data/test_roms/blargg_vbl_nmi_timing/7-nmi_timing.nes
--------------------------------------------------------------------------------
/screenshots/kirby.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nax/nin/745c396f22134e4a9d648a652ea6a19d473436f4/screenshots/kirby.png
--------------------------------------------------------------------------------
/screenshots/mario.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nax/nin/745c396f22134e4a9d648a652ea6a19d473436f4/screenshots/mario.png
--------------------------------------------------------------------------------
/screenshots/mario3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nax/nin/745c396f22134e4a9d648a652ea6a19d473436f4/screenshots/mario3.png
--------------------------------------------------------------------------------
/screenshots/megaman2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nax/nin/745c396f22134e4a9d648a652ea6a19d473436f4/screenshots/megaman2.png
--------------------------------------------------------------------------------
/screenshots/punchout.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nax/nin/745c396f22134e4a9d648a652ea6a19d473436f4/screenshots/punchout.png
--------------------------------------------------------------------------------
/screenshots/zelda.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nax/nin/745c396f22134e4a9d648a652ea6a19d473436f4/screenshots/zelda.png
--------------------------------------------------------------------------------
/src/NinEmu/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # Nin, a Nintendo Entertainment System Emulator.
2 | #
3 | # Copyright (c) 2018-2020 Maxime Bacoux
4 | # All rights reserved.
5 | #
6 | # This program is free software; you can redistribute it and/or
7 | # modify it under the terms of the GNU General Public License
8 | # Version 2, as published by the Free Software Foundation.
9 | #
10 | # Alternatively, this program can be licensed under a commercial license
11 | # upon request.
12 | #
13 | # When using the program under the GNU General Public License Version 2 license,
14 | # the following apply:
15 | #
16 | # 1. This program is distributed in the hope that it will be useful,
17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 | # GNU General Public License for more details.
20 | #
21 | # 2. You should have received a copy of the GNU General Public License
22 | # along with this program; if not, write to the Free Software
23 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 |
25 | set(CMAKE_AUTOMOC ON)
26 | set(CMAKE_AUTOUIC ON)
27 |
28 | find_package(Threads REQUIRED)
29 | find_package(OpenGL REQUIRED)
30 | find_package(Qt5 COMPONENTS Core Widgets Gamepad REQUIRED)
31 |
32 | if (APPLE OR WIN32)
33 | find_package(QtDeploy REQUIRED)
34 | endif()
35 |
36 | file(GLOB_RECURSE SOURCES "*.cpp")
37 | if (APPLE)
38 | list(APPEND SOURCES "${CMAKE_SOURCE_DIR}/data/nin.icns")
39 | set_source_files_properties("${CMAKE_SOURCE_DIR}/data/nin.icns" PROPERTIES MACOSX_PACKAGE_LOCATION "Resources")
40 | elseif(WIN32)
41 | list(APPEND SOURCES "${CMAKE_SOURCE_DIR}/data/nin.rc")
42 | endif()
43 |
44 | # Compilation
45 | add_executable(nin MACOSX_BUNDLE WIN32 ${SOURCES})
46 | target_include_directories(nin PRIVATE "${CMAKE_SOURCE_DIR}/src")
47 | target_link_libraries(nin OpenGL::GL OpenAL::AL libnin Qt5::Core Qt5::Widgets Qt5::Gamepad Threads::Threads)
48 |
49 | if (UNIX AND NOT APPLE)
50 | target_link_options(nin PRIVATE -pthread)
51 | elseif (APPLE)
52 | target_compile_definitions(nin PRIVATE GL_SILENCE_DEPRECATION=1)
53 | target_compile_options(nin PRIVATE "-Wno-unknown-pragmas")
54 | set_target_properties(nin
55 | PROPERTIES
56 | OUTPUT_NAME "Nin"
57 | MACOSX_BUNDLE_INFO_PLIST "${CMAKE_SOURCE_DIR}/data/nin.plist"
58 | MACOSX_BUNDLE_ICON_FILE "nin"
59 | )
60 | elseif(WIN32)
61 | get_target_property(OPENAL_DLL OpenAL::AL IMPORTED_LOCATION)
62 | add_custom_command(
63 | TARGET nin POST_BUILD
64 | COMMAND ${CMAKE_COMMAND} -E copy_if_different "${OPENAL_DLL}" "$"
65 | COMMAND "${QT_DEPLOY}" "$" "--no-compiler-runtime" "--no-opengl-sw" "--no-system-d3d-compiler"
66 | COMMENT "Copying DLLs"
67 | VERBATIM
68 | )
69 | endif ()
70 |
--------------------------------------------------------------------------------
/src/NinEmu/Core/Audio.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #ifndef AUDIO_H
28 | #define AUDIO_H
29 |
30 | #include
31 | #include
32 | #include
33 | #include
34 | #include
35 | #include
36 |
37 | class Audio : public QObject
38 | {
39 | Q_OBJECT;
40 |
41 | public:
42 | explicit Audio(QObject* parent = nullptr);
43 | virtual ~Audio();
44 |
45 | uint32_t frequency() const;
46 |
47 | public slots:
48 | void reset();
49 | void pushSamples(const float* samples);
50 |
51 | private:
52 | static const int kBufferCount = 4;
53 |
54 | void adjustDrift();
55 |
56 | ALCdevice* _device;
57 | ALCcontext* _context;
58 | ALuint _source;
59 | std::vector _buffers;
60 | uint32_t _frequency;
61 | double _playbackDrift;
62 | };
63 |
64 | #endif
65 |
--------------------------------------------------------------------------------
/src/NinEmu/Core/EmulatorInfo.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #ifndef EMULATOR_INFO_H
28 | #define EMULATOR_INFO_H
29 |
30 | struct EmulatorInfo
31 | {
32 | int diskSideCount;
33 | };
34 |
35 | #endif
36 |
--------------------------------------------------------------------------------
/src/NinEmu/Core/EmulatorWorker.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #ifndef EMULATOR_WORKER_H
28 | #define EMULATOR_WORKER_H
29 |
30 | #include
31 | #include
32 | #include
33 | #include
34 | #include
35 | #include
36 | #include
37 | #include
38 | #include
39 |
40 | class EmulatorWorker : public QObject
41 | {
42 | Q_OBJECT;
43 |
44 | public:
45 | explicit EmulatorWorker(QObject* parent = nullptr);
46 | virtual ~EmulatorWorker();
47 |
48 | bool loadRom(const QString& path);
49 | void closeRom();
50 |
51 | void pause();
52 | void resume();
53 | void stepFrame();
54 | void stepSingle();
55 |
56 | void insertDisk(int disk);
57 |
58 | void inputKeyPress(uint8_t key);
59 | void inputKeyRelease(uint8_t key);
60 |
61 | void setAudioFrequency(uint32_t freq);
62 |
63 | void syncAudio();
64 |
65 | signals:
66 | void frame(const char* texture);
67 | void audio(const float* samples);
68 | void audioEvent(void);
69 | void update(NinState* state);
70 | void reset(const EmulatorInfo& info);
71 |
72 | private:
73 | void workerMain();
74 | void workerUpdate();
75 | void workerStepFrame();
76 | void workerStepSingle();
77 | void closeRomRaw();
78 |
79 | QString getSaveLocation(const QString& prefix, const QString& name);
80 |
81 | static void audioCallback(void* emu, const float* samples);
82 |
83 | enum class WorkerState
84 | {
85 | Idle,
86 | Paused,
87 | Starting,
88 | Running,
89 | StepFrame,
90 | StepSingle,
91 | Stopping
92 | };
93 |
94 | using Clock = std::chrono::high_resolution_clock;
95 | using Duration = std::chrono::nanoseconds;
96 | using TimePoint = std::chrono::time_point;
97 |
98 | EmulatorInfo _info;
99 |
100 | std::thread _thread;
101 | std::mutex _mutex;
102 | std::condition_variable _cv;
103 | std::atomic _workerState;
104 |
105 | std::atomic_size_t _frameCycles;
106 | std::atomic_size_t _frameDelay;
107 | std::atomic_size_t _cyc;
108 | std::atomic_uint_fast8_t _input;
109 | std::atomic_uint_fast64_t _accumulator;
110 |
111 | std::atomic_uint_fast32_t _audioFrequency;
112 |
113 | std::mutex _audioMutex;
114 | float _audioBuffer[NIN_AUDIO_SAMPLE_SIZE];
115 |
116 | char _frameBuffer[NIN_FRAME_SIZE];
117 |
118 | NinState* _state;
119 | };
120 |
121 | #endif
122 |
--------------------------------------------------------------------------------
/src/NinEmu/Core/Settings.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #include
28 |
29 | Settings::Settings(QObject* parent)
30 | : QObject(parent)
31 | , _aspectRatio(SettingAspectRatio::Square)
32 | , _overscan(SettingOverscan::None)
33 | {
34 | }
35 |
36 | SettingAspectRatio Settings::aspectRatio() const
37 | {
38 | return _aspectRatio;
39 | }
40 |
41 | SettingOverscan Settings::overscan() const
42 | {
43 | return _overscan;
44 | }
45 |
46 | void Settings::setAspectRatio(SettingAspectRatio aspectRatio)
47 | {
48 | _aspectRatio = aspectRatio;
49 | }
50 |
51 | void Settings::setOverscan(SettingOverscan overscan)
52 | {
53 | _overscan = overscan;
54 | }
55 |
--------------------------------------------------------------------------------
/src/NinEmu/Core/Settings.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #ifndef NIN_EMU_CORE_SETTINGS_H
28 | #define NIN_EMU_CORE_SETTINGS_H
29 |
30 | #include
31 |
32 | enum class SettingAspectRatio
33 | {
34 | Square = 0,
35 | Fit = 1
36 | };
37 |
38 | enum class SettingOverscan
39 | {
40 | None = 0,
41 | Small = 1,
42 | Medium = 2,
43 | Large = 3
44 | };
45 |
46 | class Settings : public QObject
47 | {
48 | Q_OBJECT;
49 |
50 | public:
51 | explicit Settings(QObject* parent = nullptr);
52 |
53 | SettingAspectRatio aspectRatio() const;
54 | SettingOverscan overscan() const;
55 |
56 | void setAspectRatio(SettingAspectRatio aspectRatio);
57 | void setOverscan(SettingOverscan overscan);
58 |
59 | private:
60 | SettingAspectRatio _aspectRatio;
61 | SettingOverscan _overscan;
62 | };
63 |
64 | #endif
65 |
--------------------------------------------------------------------------------
/src/NinEmu/Menu/DiskMenu.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #include
28 | #include
29 |
30 | DiskMenu::DiskMenu(QWidget* parent)
31 | : QMenu(parent)
32 | {
33 | setTitle("");
34 | }
35 |
36 | void DiskMenu::setDiskSideCount(int diskSideCount)
37 | {
38 | QAction* action;
39 |
40 | if (diskSideCount == 0)
41 | {
42 | setTitle("");
43 | return;
44 | }
45 |
46 | setTitle(tr("Disk"));
47 | for (auto a : _diskActions)
48 | removeAction(a);
49 | for (auto a : _diskActions)
50 | a->deleteLater();
51 | _diskActions.clear();
52 |
53 | switch (diskSideCount)
54 | {
55 | case 1:
56 | action = new QAction("Insert Disk", this);
57 | _diskActions.push_back(action);
58 | break;
59 | case 2:
60 | action = new QAction("Insert Side A", this);
61 | _diskActions.push_back(action);
62 | action = new QAction("Insert Side B", this);
63 | _diskActions.push_back(action);
64 | break;
65 | default:
66 | for (int i = 0; i < diskSideCount; ++i)
67 | {
68 | action = new QAction(QString("Insert Disk " + QString::number(i / 2 + 1) + " Side " + (i & 1 ? "B" : "A")), this);
69 | _diskActions.push_back(action);
70 | }
71 | }
72 |
73 | for (int i = 0; i < diskSideCount; ++i)
74 | {
75 | _diskActions[i]->setData(i);
76 | connect(_diskActions[i], &QAction::triggered, this, &DiskMenu::selectDisk);
77 | addAction(_diskActions[i]);
78 | }
79 | }
80 |
81 | void DiskMenu::selectDisk()
82 | {
83 | int diskSide = qobject_cast(sender())->data().toInt();
84 | insertDisk(diskSide);
85 | }
86 |
--------------------------------------------------------------------------------
/src/NinEmu/Menu/DiskMenu.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #ifndef NIN_EMU_MENU_DISK
28 | #define NIN_EMU_MENU_DISK
29 |
30 | #include
31 | #include
32 | #include
33 |
34 | class DiskMenu : public QMenu
35 | {
36 | Q_OBJECT;
37 |
38 | public:
39 | explicit DiskMenu(QWidget* parent = nullptr);
40 |
41 | void setDiskSideCount(int diskCount);
42 |
43 | signals:
44 | void insertDisk(int);
45 |
46 | private slots:
47 | void selectDisk();
48 |
49 | private:
50 | std::vector _diskActions;
51 | };
52 |
53 | #endif
54 |
--------------------------------------------------------------------------------
/src/NinEmu/Menu/GraphicsMenu.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #ifndef NIN_EMU_MENU_GRAPHICS
28 | #define NIN_EMU_MENU_GRAPHICS
29 |
30 | #include
31 | #include
32 |
33 | #include
34 | #include
35 |
36 | class GraphicsMenu : public QMenu
37 | {
38 | Q_OBJECT;
39 |
40 | public:
41 | explicit GraphicsMenu(QWidget* parent = nullptr);
42 |
43 | signals:
44 | void fullscreen(bool);
45 | void fit(bool);
46 | void integerScale(bool);
47 | void aspectRatio(AspectRatio);
48 | void overscan(Overscan);
49 |
50 | private:
51 | void createSubMenuAspectRatio();
52 | void createSubMenuOverscan();
53 |
54 | void selectAspectRatio();
55 | void selectOverscan();
56 | };
57 |
58 | #endif
59 |
--------------------------------------------------------------------------------
/src/NinEmu/UI/DisassemblerWidget.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #ifndef DISASSEMBLER_WIDGET_H
28 | #define DISASSEMBLER_WIDGET_H
29 |
30 | #include
31 | #include
32 | #include
33 | #include
34 | #include
35 |
36 | class DisassemblerWidget : public QAbstractScrollArea
37 | {
38 | Q_OBJECT;
39 |
40 | public:
41 | DisassemblerWidget(QWidget* parent = nullptr);
42 |
43 | virtual void paintEvent(QPaintEvent* event) override;
44 | void disassemble(uint16_t pc, const uint8_t* data, std::size_t dataSize);
45 |
46 | private:
47 | struct DisasmInstr
48 | {
49 | uint16_t addr;
50 | uint8_t raw[3];
51 | uint8_t rawCount;
52 | char str[32];
53 | };
54 |
55 | std::uint8_t disassembleInstr(DisasmInstr& instr, uint16_t pc, const uint8_t* data);
56 |
57 | QWidget* _viewport;
58 | DisasmInstr _buffer[64];
59 | };
60 |
61 | #endif
62 |
--------------------------------------------------------------------------------
/src/NinEmu/UI/HexView.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #include
28 | #include
29 | #include
30 |
31 | #define LINE_HEIGHT (16)
32 |
33 | HexView::HexView(const uint8_t* buffer, size_t bufferSize, QWidget* parent)
34 | : QAbstractScrollArea(parent)
35 | , _bufferSize(bufferSize)
36 | , _buffer(buffer)
37 | {
38 | QFont f = QFontDatabase::systemFont(QFontDatabase::FixedFont);
39 | setFont(f);
40 | setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding);
41 | setFixedWidth(80 + 17 * 20);
42 |
43 | _viewport = new QWidget();
44 | setViewport(_viewport);
45 |
46 | verticalScrollBar()->setSingleStep(1);
47 | verticalScrollBar()->setPageStep(16);
48 | updateScroll();
49 |
50 | setAutoFillBackground(true);
51 | setPalette(QPalette(Qt::white));
52 | }
53 |
54 | void HexView::paintEvent(QPaintEvent* event)
55 | {
56 | QPainter painter(_viewport);
57 | uint16_t addr;
58 | char tmp[7];
59 | int offset;
60 | int lineCount;
61 |
62 | offset = verticalScrollBar()->value();
63 | lineCount = size().height() / LINE_HEIGHT;
64 |
65 | for (int j = 0; j < lineCount; ++j)
66 | {
67 | painter.setPen(Qt::blue);
68 | addr = (j + offset) << 4;
69 | snprintf(tmp, sizeof(tmp), "0x%04X", addr);
70 | painter.drawText(QPoint(5, j * LINE_HEIGHT + 14), tmp);
71 | painter.setPen(Qt::black);
72 |
73 | for (unsigned i = 0; i < 16; ++i)
74 | {
75 | snprintf(tmp, sizeof(tmp), "%02X", _buffer[addr]);
76 | painter.drawText(QPoint(80 + i * 20, j * LINE_HEIGHT + 14), tmp);
77 | addr++;
78 | }
79 | }
80 |
81 | QAbstractScrollArea::paintEvent(event);
82 | }
83 |
84 | void HexView::resizeEvent(QResizeEvent* event)
85 | {
86 | QAbstractScrollArea::resizeEvent(event);
87 | updateScroll();
88 | }
89 |
90 | void HexView::updateScroll()
91 | {
92 | int maxScroll;
93 |
94 | maxScroll = (int)(_bufferSize / 16);
95 | maxScroll -= (_viewport->size().height() / LINE_HEIGHT);
96 |
97 | if (maxScroll < 0)
98 | maxScroll = 0;
99 |
100 | verticalScrollBar()->setMaximum(maxScroll);
101 | update();
102 | }
103 |
--------------------------------------------------------------------------------
/src/NinEmu/UI/HexView.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #ifndef HEX_VIEW_H
28 | #define HEX_VIEW_H
29 |
30 | #include
31 | #include
32 | #include
33 | #include
34 |
35 | class HexView : public QAbstractScrollArea
36 | {
37 | Q_OBJECT;
38 |
39 | public:
40 | HexView(const uint8_t* buffer, size_t bufferSize, QWidget* parent = nullptr);
41 |
42 | virtual void paintEvent(QPaintEvent* event) override;
43 | virtual void resizeEvent(QResizeEvent* event) override;
44 |
45 | private:
46 | void updateScroll();
47 |
48 | QWidget* _viewport;
49 | size_t _bufferSize;
50 | const uint8_t* _buffer;
51 | };
52 |
53 | #endif
54 |
--------------------------------------------------------------------------------
/src/NinEmu/UI/RenderWidget.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #ifndef RENDER_WIDGET_H
28 | #define RENDER_WIDGET_H
29 |
30 | #include
31 | #include
32 | #include
33 | #include
34 |
35 | class RenderWidget : public QOpenGLWidget
36 | {
37 | Q_OBJECT;
38 |
39 | public:
40 | explicit RenderWidget(QWidget* parent = nullptr);
41 | virtual ~RenderWidget();
42 |
43 | virtual void initializeGL() override;
44 | virtual void paintGL() override;
45 | virtual void resizeGL(int w, int j) override;
46 |
47 | void setFit(bool fit);
48 | void setIntegerScale(bool integerScale);
49 | void setPixelAspectRatio(float pixelAspectRatio);
50 | void setOverscan(int x, int y);
51 |
52 | void updateTexture(const char* texture);
53 |
54 | private:
55 | void computeViewBox();
56 |
57 | std::mutex _mutex;
58 | GLuint _texture;
59 | char _rawTexture[256 * 240 * 4];
60 | bool _fit;
61 | bool _integerScale;
62 | float _pixelAspectRatio;
63 | int _xOverscan;
64 | int _yOverscan;
65 | float _xMin;
66 | float _xMax;
67 | float _yMin;
68 | float _yMax;
69 | float _texXMin;
70 | float _texXMax;
71 | float _texYMin;
72 | float _texYMax;
73 | };
74 |
75 | #endif
76 |
--------------------------------------------------------------------------------
/src/NinEmu/UI/SignalVisualizer.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #ifndef SIGNAL_VISUALIZER_H
28 | #define SIGNAL_VISUALIZER_H
29 |
30 | #include
31 | #include
32 | #include
33 | #include
34 |
35 | class SignalVisualizer : public QOpenGLWidget
36 | {
37 | Q_OBJECT;
38 |
39 | public:
40 | explicit SignalVisualizer(size_t sampleCount, QWidget* parent = nullptr);
41 | virtual ~SignalVisualizer();
42 |
43 | virtual void initializeGL() override;
44 | virtual void paintGL() override;
45 | virtual void resizeGL(int w, int j) override;
46 |
47 | bool dirty() const;
48 |
49 | void setSamples(const float* samples);
50 | void setResolution(float min, float max);
51 | void setColor(float r, float g, float b);
52 | void setBackgroundColor(float r, float g, float b);
53 |
54 | private:
55 | std::mutex _mutex;
56 | size_t _sampleCount;
57 | float* _samples;
58 | float _min;
59 | float _max;
60 | float _color[3];
61 | float _colorBg[3];
62 | bool _dirty;
63 | };
64 |
65 | #endif
66 |
--------------------------------------------------------------------------------
/src/NinEmu/UX/AspectRatio.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #ifndef NIN_EMU_UX_ASPECT_RATIO_H
28 | #define NIN_EMU_UX_ASPECT_RATIO_H
29 |
30 | enum class AspectRatio
31 | {
32 | Square = 1,
33 | NTSC = 2
34 | };
35 |
36 | #endif
37 |
--------------------------------------------------------------------------------
/src/NinEmu/UX/Overscan.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #ifndef NIN_EMU_UX_OVERSCAN_H
28 | #define NIN_EMU_UX_OVERSCAN_H
29 |
30 | enum class Overscan
31 | {
32 | None = 0,
33 | Small = 1,
34 | Medium = 2,
35 | Large = 3
36 | };
37 |
38 | #endif
39 |
--------------------------------------------------------------------------------
/src/NinEmu/Window/AudioVisualizerWindow.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #ifndef AUDIO_VISUALIZER_WINDOW_H
28 | #define AUDIO_VISUALIZER_WINDOW_H
29 |
30 | #include
31 | #include
32 |
33 | #include
34 |
35 | class SignalVisualizer;
36 | class AudioVisualizerWindow : public QWidget
37 | {
38 | Q_OBJECT;
39 |
40 | public:
41 | explicit AudioVisualizerWindow(QWidget* parent = nullptr);
42 |
43 | public slots:
44 | void refresh(const float* samples);
45 |
46 | private:
47 | SignalVisualizer* _timeDomainVisualizer;
48 | SignalVisualizer* _freqDomainVisualizer;
49 | };
50 |
51 | #endif
52 |
--------------------------------------------------------------------------------
/src/NinEmu/Window/DebuggerWindow.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #ifndef DEBUGGER_WINDOW_H
28 | #define DEBUGGER_WINDOW_H
29 |
30 | #include
31 | #include
32 | #include
33 |
34 | #include
35 |
36 | class DisassemblerWidget;
37 | class DebuggerWindow : public QWidget
38 | {
39 | Q_OBJECT;
40 |
41 | public:
42 | explicit DebuggerWindow(QWidget* parent = nullptr);
43 |
44 | public slots:
45 | void refresh(NinState* state);
46 |
47 | private:
48 | QSpinBox* _spinPC;
49 | QSpinBox* _spinA;
50 | QSpinBox* _spinX;
51 | QSpinBox* _spinY;
52 | QSpinBox* _spinS;
53 |
54 | DisassemblerWidget* _disasm;
55 | };
56 |
57 | #endif
58 |
--------------------------------------------------------------------------------
/src/NinEmu/Window/MemorySearchWindow.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #ifndef MEMORY_SEARCH_WINDOW_H
28 | #define MEMORY_SEARCH_WINDOW_H 1
29 |
30 | #include
31 | #include
32 | #include
33 | #include
34 | #include
35 | #include
36 |
37 | class MemorySearchWindow : public QWidget
38 | {
39 | Q_OBJECT;
40 |
41 | public:
42 | explicit MemorySearchWindow(QWidget* parent = nullptr);
43 |
44 | public slots:
45 | void refresh(NinState* state);
46 |
47 | private:
48 | enum class SearchFunc
49 | {
50 | Equal = 0,
51 | NotEqual,
52 | Lesser,
53 | Greater,
54 | LesserEqual,
55 | GreaterEqual
56 | };
57 |
58 | enum class SearchValue
59 | {
60 | Previous = 0,
61 | First,
62 | Custom
63 | };
64 |
65 | struct MemorySpan
66 | {
67 | std::uint16_t base;
68 | std::uint16_t size;
69 | };
70 |
71 | void setSearchFunc(int searchFunc);
72 | void setSearchValue(int searchValue);
73 |
74 | void updateTable();
75 | void updateResults();
76 | void reset();
77 | void search();
78 | bool searchPredicate(std::uint16_t addr) const;
79 |
80 | QLabel* _labelResults;
81 | QTableWidget* _table;
82 |
83 | SearchFunc _searchFunc;
84 | SearchValue _searchValue;
85 | std::vector _spans;
86 | uint8_t _buffer[0x10000];
87 | uint8_t _bufferPrev[0x10000];
88 | uint8_t _bufferFirst[0x10000];
89 | };
90 |
91 | #endif
92 |
--------------------------------------------------------------------------------
/src/NinEmu/Window/MemoryWindow.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #include
28 | #include
29 |
30 | MemoryWindow::MemoryWindow(QWidget* parent)
31 | : QWidget(parent, Qt::Window)
32 | {
33 | QVBoxLayout* layout;
34 | QLabel* label;
35 |
36 | memset(_buffer, 0xff, 0x10000);
37 |
38 | setWindowTitle("Memory Viewer");
39 |
40 | layout = new QVBoxLayout;
41 |
42 | label = new QLabel("Memory");
43 |
44 | _hexView = new HexView(_buffer, 0x10000);
45 | _hexView->show();
46 | _hexView->repaint();
47 |
48 | layout->addWidget(label);
49 | layout->addWidget(_hexView, 1);
50 | setLayout(layout);
51 | show();
52 |
53 | setFixedWidth(width());
54 | }
55 |
56 | void MemoryWindow::refresh(NinState* state)
57 | {
58 | ninDumpMemory(state, _buffer, 0, 0x10000);
59 | _hexView->update();
60 | }
61 |
--------------------------------------------------------------------------------
/src/NinEmu/Window/MemoryWindow.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #ifndef MEMORY_WINDOW_H
28 | #define MEMORY_WINDOW_H
29 |
30 | #include
31 | #include
32 | #include
33 |
34 | #include
35 | #include
36 |
37 | class MemoryWindow : public QWidget
38 | {
39 | Q_OBJECT;
40 |
41 | public:
42 | explicit MemoryWindow(QWidget* parent = nullptr);
43 |
44 | public slots:
45 | void refresh(NinState* state);
46 |
47 | private:
48 | HexView* _hexView;
49 | uint8_t _buffer[0x10000];
50 | };
51 |
52 | #endif
53 |
--------------------------------------------------------------------------------
/src/NinEmu/main.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #if defined(_MSC_VER)
28 | #include
29 | #else
30 | #include
31 | #endif
32 |
33 | #include
34 | #include
35 |
36 | int main(int argc, char** argv)
37 | {
38 | _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON);
39 |
40 | QApplication app(argc, argv);
41 | QApplication::setApplicationName("Nin");
42 | QApplication::setOrganizationName("NotAndXor");
43 |
44 | MainWindow mainWindow;
45 |
46 | mainWindow.show();
47 | return app.exec();
48 | }
49 |
--------------------------------------------------------------------------------
/src/libnin/Audio.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #ifndef LIBNIN_AUDIO_H
28 | #define LIBNIN_AUDIO_H 1
29 |
30 | #include
31 | #include
32 | #include
33 |
34 | namespace libnin
35 | {
36 |
37 | class HardwareInfo;
38 | class Audio : private NonCopyable
39 | {
40 | public:
41 | Audio(const HardwareInfo& info);
42 | ~Audio();
43 |
44 | void setCallback(NINAUDIOCALLBACK callback, void* arg);
45 | void setTargetFrequency(std::uint32_t freq);
46 |
47 | void push(float sample);
48 |
49 | private:
50 | static constexpr const int kOversampling = 8;
51 | static constexpr const int kTargetFrequency = 48000;
52 | static constexpr const int kTargetFrequencyRaw = kTargetFrequency * kOversampling;
53 | static constexpr const int kLowPassFilterWidth = 64;
54 | static constexpr const int kMaxRawSamples = NIN_AUDIO_SAMPLE_SIZE * kOversampling + kLowPassFilterWidth;
55 |
56 | void resample();
57 |
58 | const HardwareInfo& _info;
59 |
60 | NINAUDIOCALLBACK _callback;
61 | void* _callbackArg;
62 | std::uint32_t _targetFrequency;
63 | std::uint32_t _accumulator;
64 | float _samplesRaw[kMaxRawSamples];
65 | float _samples[NIN_AUDIO_SAMPLE_SIZE];
66 | std::uint16_t _samplesCursor;
67 | };
68 |
69 | }; // namespace libnin
70 |
71 | #endif
72 |
--------------------------------------------------------------------------------
/src/libnin/BusMain.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #ifndef LIBNIN_BUS_MAIN_H
28 | #define LIBNIN_BUS_MAIN_H 1
29 |
30 | #include
31 | #include
32 |
33 | namespace libnin
34 | {
35 |
36 | enum class WriteAction
37 | {
38 | None,
39 | DMA
40 | };
41 |
42 | class Memory;
43 | class Cart;
44 | class Mapper;
45 | class PPU;
46 | class APU;
47 | class Input;
48 | class BusMain : private NonCopyable
49 | {
50 | public:
51 | BusMain(Memory& memory, Cart& cart, Mapper& mapper, PPU& ppu, APU& apu, Input& input);
52 |
53 | std::uint8_t read(std::uint16_t addr);
54 | WriteAction write(std::uint16_t addr, std::uint8_t value);
55 |
56 | void dump(std::uint8_t* dst, std::uint16_t start, std::size_t len);
57 |
58 | private:
59 | Memory& _memory;
60 | Cart& _cart;
61 | Mapper& _mapper;
62 | PPU& _ppu;
63 | APU& _apu;
64 | Input& _input;
65 | };
66 |
67 | }; // namespace libnin
68 |
69 | #endif
70 |
--------------------------------------------------------------------------------
/src/libnin/BusVideo.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #include
28 | #include
29 | #include
30 | #include
31 |
32 | using namespace libnin;
33 |
34 | static std::uint8_t badIO(std::uint16_t addr, int write)
35 | {
36 | printf("PPU bad IO at 0x%04x (%c)\n", addr, write ? 'w' : 'r');
37 | fflush(stdout);
38 | return 0;
39 | }
40 |
41 | BusVideo::BusVideo(Memory& memory, Cart& cart, Mapper& mapper)
42 | : _memory(memory)
43 | , _cart(cart)
44 | , _mapper(mapper)
45 | {
46 | }
47 |
48 | std::uint8_t BusVideo::read(std::uint16_t addr)
49 | {
50 | addr &= 0x3fff;
51 | _mapper.videoRead(addr);
52 | if (addr < 0x2000)
53 | return _mapper.chrRead(addr / 0x400, addr & 0x3ff);
54 | else if (addr < 0x2400)
55 | return _mapper.ntRead(0, addr & 0x3ff);
56 | else if (addr < 0x2800)
57 | return _mapper.ntRead(1, addr & 0x3ff);
58 | else if (addr < 0x2c00)
59 | return _mapper.ntRead(2, addr & 0x3ff);
60 | else if (addr < 0x3000)
61 | return _mapper.ntRead(3, addr & 0x3ff);
62 | else if (addr < 0x3400)
63 | return _mapper.ntRead(0, addr & 0x3ff);
64 | else if (addr < 0x3800)
65 | return _mapper.ntRead(1, addr & 0x3ff);
66 | else if (addr < 0x3c00)
67 | return _mapper.ntRead(2, addr & 0x3ff);
68 | else if (addr < 0x3f00)
69 | return _mapper.ntRead(3, addr & 0x3ff);
70 | else
71 | return _memory.palettes[addr & 0x1f];
72 | }
73 |
74 | void BusVideo::write(std::uint16_t addr, std::uint8_t value)
75 | {
76 | addr &= 0x3fff;
77 | if (addr < 0x2000)
78 | _mapper.chrWrite(addr / 0x400, addr & 0x3ff, value);
79 | else if (addr < 0x2400)
80 | _mapper.ntWrite(0, addr & 0x3ff, value);
81 | else if (addr < 0x2800)
82 | _mapper.ntWrite(1, addr & 0x3ff, value);
83 | else if (addr < 0x2c00)
84 | _mapper.ntWrite(2, addr & 0x3ff, value);
85 | else if (addr < 0x3000)
86 | _mapper.ntWrite(3, addr & 0x3ff, value);
87 | else if (addr < 0x3400)
88 | _mapper.ntWrite(0, addr & 0x3ff, value);
89 | else if (addr < 0x3800)
90 | _mapper.ntWrite(1, addr & 0x3ff, value);
91 | else if (addr < 0x3c00)
92 | _mapper.ntWrite(2, addr & 0x3ff, value);
93 | else if (addr < 0x3f00)
94 | _mapper.ntWrite(3, addr & 0x3ff, value);
95 | else
96 | {
97 | if ((addr & 0x03) == 0)
98 | {
99 | _memory.palettes[addr & 0x0f] = value;
100 | _memory.palettes[0x10 | (addr & 0x0f)] = value;
101 | }
102 | else
103 | _memory.palettes[addr & 0x1f] = value;
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/src/libnin/BusVideo.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #ifndef LIBNIN_BUS_VIDEO_H
28 | #define LIBNIN_BUS_VIDEO_H 1
29 |
30 | #include
31 | #include
32 |
33 | namespace libnin
34 | {
35 |
36 | class Memory;
37 | class Cart;
38 | class Mapper;
39 | class BusVideo : private NonCopyable
40 | {
41 | public:
42 | BusVideo(Memory& memory, Cart& cart, Mapper& mapper);
43 |
44 | std::uint8_t read(std::uint16_t addr);
45 | void write(std::uint16_t addr, std::uint8_t value);
46 |
47 | private:
48 | Memory& _memory;
49 | Cart& _cart;
50 | Mapper& _mapper;
51 | };
52 |
53 | } // namespace libnin
54 |
55 | #endif
56 |
--------------------------------------------------------------------------------
/src/libnin/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # Nin, a Nintendo Entertainment System Emulator.
2 | #
3 | # Copyright (c) 2018-2020 Maxime Bacoux
4 | # All rights reserved.
5 | #
6 | # This program is free software; you can redistribute it and/or
7 | # modify it under the terms of the GNU General Public License
8 | # Version 2, as published by the Free Software Foundation.
9 | #
10 | # Alternatively, this program can be licensed under a commercial license
11 | # upon request.
12 | #
13 | # When using the program under the GNU General Public License Version 2 license,
14 | # the following apply:
15 | #
16 | # 1. This program is distributed in the hope that it will be useful,
17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 | # GNU General Public License for more details.
20 | #
21 | # 2. You should have received a copy of the GNU General Public License
22 | # along with this program; if not, write to the Free Software
23 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 |
25 | find_package(Ruby REQUIRED)
26 |
27 | set(CONFIG_IN "${CMAKE_CURRENT_SOURCE_DIR}/config.h.in")
28 | set(CONFIG_OUT "${CMAKE_BINARY_DIR}/include/nin/config.h")
29 | configure_file("${CONFIG_IN}" "${CONFIG_OUT}")
30 |
31 | set(SOURCES_CODEGEN_CPU "${CMAKE_BINARY_DIR}/CPU_instr.cpp")
32 | add_custom_command(
33 | OUTPUT "${SOURCES_CODEGEN_CPU}"
34 | COMMAND "${RUBY_EXECUTABLE}" "${CMAKE_SOURCE_DIR}/tools/gen_6502.rb" "${SOURCES_CODEGEN_CPU}"
35 | DEPENDS "${CMAKE_SOURCE_DIR}/tools/gen_6502.rb"
36 | COMMENT "Generating CPU_instr.cpp"
37 | VERBATIM
38 | )
39 |
40 | file(GLOB_RECURSE SOURCES "*.c" "*.cpp")
41 | list(APPEND SOURCES "${CONFIG_OUT}" "${SOURCES_CODEGEN_CPU}")
42 |
43 | add_library(libnin SHARED ${SOURCES})
44 | target_include_directories(libnin PRIVATE "${CMAKE_SOURCE_DIR}/src" PUBLIC "${CMAKE_SOURCE_DIR}/include" "${CMAKE_BINARY_DIR}/include")
45 |
46 | if (WIN32)
47 | set_target_properties(libnin PROPERTIES OUTPUT_NAME libnin)
48 | target_compile_definitions(libnin PRIVATE NIN_DLL=1)
49 | else()
50 | set_target_properties(libnin PROPERTIES OUTPUT_NAME nin)
51 | endif()
52 |
--------------------------------------------------------------------------------
/src/libnin/Cart.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #include
28 | #include
29 |
30 | using namespace libnin;
31 |
32 | void Cart::load(int id, std::uint16_t bankCount, std::FILE* file)
33 | {
34 | CartSegment& seg = _segments[id];
35 |
36 | std::uint32_t size;
37 | std::uint32_t bankSize;
38 |
39 | delete[] seg.base;
40 |
41 | switch (id)
42 | {
43 | case CART_PRG_ROM:
44 | case CART_PRG_RAM:
45 | bankSize = 0x2000;
46 | break;
47 | case CART_CHR_ROM:
48 | case CART_CHR_RAM:
49 | bankSize = 0x400;
50 | break;
51 | default:
52 | UNREACHABLE();
53 | }
54 |
55 | size = bankCount * bankSize;
56 | seg.bankCount = bankCount;
57 |
58 | if (size == 0)
59 | {
60 | seg.base = nullptr;
61 | }
62 | else if (file)
63 | {
64 | seg.base = new std::uint8_t[size];
65 | std::fread(seg.base, size, 1, file);
66 | }
67 | else
68 | {
69 | seg.base = new std::uint8_t[size]();
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/src/libnin/Cart.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #ifndef LIBNIN_CART_H
28 | #define LIBNIN_CART_H 1
29 |
30 | #include
31 | #include
32 | #include
33 |
34 | #define CART_PRG_ROM 0
35 | #define CART_PRG_RAM 1
36 | #define CART_CHR_ROM 2
37 | #define CART_CHR_RAM 3
38 |
39 | namespace libnin
40 | {
41 |
42 | struct CartSegment : private NonCopyable
43 | {
44 | CartSegment()
45 | : base{}
46 | , bankCount{}
47 | {
48 | }
49 | ~CartSegment() { delete[] base; }
50 |
51 | std::uint8_t* base;
52 | std::uint16_t bankCount;
53 | };
54 |
55 | class Cart : private NonCopyable
56 | {
57 | public:
58 | const CartSegment& segment(int id) const { return _segments[id]; };
59 |
60 | void load(int id, std::uint16_t bankCount, std::FILE* file);
61 |
62 | private:
63 | CartSegment _segments[4];
64 | };
65 |
66 | }; // namespace libnin
67 |
68 | #endif
69 |
--------------------------------------------------------------------------------
/src/libnin/Disk.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #include
28 |
29 | using namespace libnin;
30 |
31 | Disk::Disk()
32 | : _data{}
33 | , _dataSide{}
34 | , _sideCount{}
35 | , _side{}
36 | , _insertClock{}
37 | , _inserted{}
38 | {
39 | }
40 |
41 | Disk::~Disk()
42 | {
43 | delete[] _data;
44 | }
45 |
46 | void Disk::tick()
47 | {
48 | if (_insertClock)
49 | _insertClock--;
50 | }
51 |
52 | void Disk::setSide(int diskSide)
53 | {
54 | if (diskSide < 0 || diskSide >= _sideCount)
55 | {
56 | _inserted = false;
57 | return;
58 | }
59 | _side = std::uint8_t(diskSide);
60 | _dataSide = _data + std::uintptr_t(DiskSize) * _side;
61 | _insertClock = 1000000;
62 | }
63 |
64 | void Disk::load(std::FILE* f, int offset, std::uint8_t sideCount)
65 | {
66 | _sideCount = sideCount;
67 | delete[] _data;
68 | _data = new std::uint8_t[(std::size_t)DiskSize * _sideCount]();
69 |
70 | for (std::uint8_t i = 0; i < _sideCount; ++i)
71 | {
72 | loadSide(f, offset, i);
73 | }
74 |
75 | _dataSide = _data;
76 | _inserted = true;
77 | }
78 |
79 | void Disk::loadSide(std::FILE* f, int fileOffset, int side)
80 | {
81 | std::uint8_t* dst;
82 | std::uint32_t offset;
83 | std::uint16_t fileSize;
84 | std::uint8_t fileCount;
85 |
86 | dst = _data + (std::size_t)DiskSize * side;
87 | std::fseek(f, fileOffset + side * DiskSizeArchive, SEEK_SET);
88 |
89 | /* First, large gap */
90 | offset = Gap0;
91 | dst[offset - 1] = 0x80;
92 |
93 | /* Load block 1 */
94 | std::fread(dst + offset, 0x38, 1, f);
95 | offset += 0x3a;
96 | offset += Gap1;
97 | dst[offset - 1] = 0x80;
98 |
99 | /* Load block 2 */
100 | std::fread(dst + offset, 0x02, 1, f);
101 | fileCount = dst[offset + 1];
102 | offset += 0x04;
103 |
104 | for (int i = 0; i < fileCount; ++i)
105 | {
106 | offset += Gap1;
107 | dst[offset - 1] = 0x80;
108 |
109 | /* Block 3 */
110 | std::fread(dst + offset, 0x10, 1, f);
111 | fileSize = *(std::uint16_t*)(dst + offset + 13);
112 | offset += 0x12;
113 | offset += Gap1;
114 | dst[offset - 1] = 0x80;
115 |
116 | /* Block 4 */
117 | std::fread(dst + offset, (std::size_t)fileSize + 1, 1, f);
118 | offset += (fileSize + 3);
119 | }
120 | }
121 |
--------------------------------------------------------------------------------
/src/libnin/Disk.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #ifndef LIBNIN_DISK_H
28 | #define LIBNIN_DISK_H 1
29 |
30 | #include
31 | #include
32 | #include
33 |
34 | namespace libnin
35 | {
36 |
37 | class Disk : private NonCopyable
38 | {
39 | public:
40 | static constexpr const int Gap0 = 3538;
41 | static constexpr const int Gap1 = 122;
42 | static constexpr const int DiskSizeArchive = 65500;
43 | static constexpr const int DiskSize = 0x14000;
44 |
45 | Disk();
46 | ~Disk();
47 |
48 | std::uint8_t sideCount() const { return _sideCount; }
49 | bool inserted() const { return _inserted && !(_insertClock); }
50 |
51 | std::uint8_t read(std::uint32_t addr) const { return inserted() ? _dataSide[addr] : 0x00; }
52 | void write(std::uint32_t addr, std::uint8_t value)
53 | {
54 | if (inserted())
55 | {
56 | _dataSide[addr] = value;
57 | }
58 | }
59 |
60 | void tick();
61 | void setSide(int diskSide);
62 |
63 | void load(std::FILE* file, int offset, std::uint8_t sideCount);
64 |
65 | private:
66 | void loadSide(std::FILE* f, int offset, int side);
67 |
68 | std::uint8_t* _data;
69 | std::uint8_t* _dataSide;
70 | std::uint8_t _sideCount;
71 | std::uint8_t _side;
72 | std::uint32_t _insertClock;
73 | bool _inserted;
74 | };
75 |
76 | } // namespace libnin
77 |
78 | #endif
79 |
--------------------------------------------------------------------------------
/src/libnin/HardwareInfo.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #include
28 |
29 | using namespace libnin;
30 |
31 | HardwareInfo::HardwareInfo()
32 | {
33 | setRegion(NIN_REGION_NTSC);
34 | setSystem(NIN_SYSTEM_NES);
35 | }
36 |
37 | void HardwareInfo::setRegion(NinRegion region)
38 | {
39 | _region = region;
40 | switch (region)
41 | {
42 | case NIN_REGION_NTSC:
43 | default:
44 | _specs = HardwareSpecs::NTSC;
45 | break;
46 | case NIN_REGION_PAL:
47 | _specs = HardwareSpecs::PAL;
48 | break;
49 | }
50 | }
51 |
52 | void HardwareInfo::setSystem(NinSystem system)
53 | {
54 | _system = system;
55 | }
56 |
--------------------------------------------------------------------------------
/src/libnin/HardwareInfo.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #ifndef LIBNIN_HARDWARE_INFO_H
28 | #define LIBNIN_HARDWARE_INFO_H 1
29 |
30 | #include
31 | #include
32 | #include
33 |
34 | namespace libnin
35 | {
36 |
37 | class HardwareInfo : NonCopyable
38 | {
39 | public:
40 | HardwareInfo();
41 |
42 | NinRegion region() const { return _region; }
43 | NinSystem system() const { return _system; }
44 | const HardwareSpecs& specs() const { return _specs; }
45 |
46 | void setRegion(NinRegion region);
47 | void setSystem(NinSystem system);
48 |
49 | private:
50 | NinRegion _region;
51 | NinSystem _system;
52 | HardwareSpecs _specs;
53 | };
54 |
55 | }; // namespace libnin
56 |
57 | #endif
58 |
--------------------------------------------------------------------------------
/src/libnin/HardwareSpecs.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #include
28 |
29 | using namespace libnin;
30 |
31 | const HardwareSpecs HardwareSpecs::NTSC = {
32 | 1789773,
33 | 29781,
34 | 16639267,
35 | 0,
36 | 0,
37 | 20,
38 | 29828,
39 | {7457, 14913, 22371, 29829, 37281},
40 | {4, 8, 16, 32, 64, 96, 128, 160, 202, 254, 380, 508, 762, 1016, 2034, 4068},
41 | {214, 190, 170, 160, 143, 127, 113, 107, 95, 80, 71, 64, 53, 42, 36, 27},
42 | };
43 |
44 | const HardwareSpecs HardwareSpecs::PAL = {
45 | 1662607,
46 | 33248,
47 | 19997200,
48 | 1,
49 | 1,
50 | 70,
51 | 33251,
52 | {8312, 16626, 24938, 33252, 41560},
53 | {4, 8, 14, 30, 60, 88, 118, 148, 188, 236, 354, 472, 708, 944, 1890, 3778},
54 | {199, 177, 158, 149, 138, 118, 105, 99, 88, 74, 66, 59, 49, 39, 33, 25},
55 | };
56 |
--------------------------------------------------------------------------------
/src/libnin/HardwareSpecs.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #ifndef LIBNIN_HARDWARE_SPECS_H
28 | #define LIBNIN_HARDWARE_SPECS_H 1
29 |
30 | #include
31 |
32 | namespace libnin
33 | {
34 |
35 | class HardwareSpecs
36 | {
37 | public:
38 | std::uint32_t clockRate;
39 | std::uint32_t frameCycles;
40 | std::uint32_t frameDelay;
41 | std::uint32_t cycleExtraIncrement;
42 | std::uint32_t firstVisibleScanline;
43 | std::uint16_t vblank;
44 | std::uint16_t apuFrameIrq;
45 | std::uint16_t apuFrameCycles[5];
46 | std::uint16_t apuNoisePeriod[16];
47 | std::uint16_t apuDmcPeriod[16];
48 |
49 | static const HardwareSpecs NTSC;
50 | static const HardwareSpecs PAL;
51 | };
52 |
53 | } // namespace libnin
54 |
55 | #endif
56 |
--------------------------------------------------------------------------------
/src/libnin/IRQ.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #ifndef LIBNIN_IRQ_H
28 | #define LIBNIN_IRQ_H 1
29 |
30 | #include
31 | #include
32 |
33 | #define IRQ_APU_FRAME 0x01
34 | #define IRQ_APU_DMC 0x02
35 | #define IRQ_MAPPER1 0x04
36 | #define IRQ_MAPPER2 0x08
37 |
38 | namespace libnin
39 | {
40 |
41 | class IRQ : private NonCopyable
42 | {
43 | public:
44 | IRQ()
45 | : _irq(0)
46 | {
47 | }
48 |
49 | bool high() const { return !!_irq; }
50 | bool check(std::uint8_t flag) const { return !!(_irq & flag); }
51 |
52 | void set(std::uint8_t flag) { _irq |= flag; }
53 | void unset(std::uint8_t flag) { _irq &= ~flag; }
54 |
55 | private:
56 | std::uint8_t _irq;
57 | };
58 |
59 | }; // namespace libnin
60 |
61 | #endif
62 |
--------------------------------------------------------------------------------
/src/libnin/Input.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #include
28 |
29 | using namespace libnin;
30 |
31 | Input::Input()
32 | : _polling{}
33 | , _state{}
34 | , _controller{}
35 | , _controllerLatch{}
36 | {
37 | }
38 |
39 | void Input::set(std::uint8_t value)
40 | {
41 | _state = value;
42 | }
43 |
44 | void Input::poll(bool polling)
45 | {
46 | _polling = polling;
47 | if (_polling)
48 | reset();
49 | }
50 |
51 | std::uint8_t Input::read()
52 | {
53 | if (_polling)
54 | reset();
55 | if (_controllerLatch < 8)
56 | return ((_controller >> _controllerLatch++) & 0x01);
57 | return 0x01;
58 | }
59 |
60 | void Input::reset()
61 | {
62 | _controller = _state;
63 | _controllerLatch = 0;
64 | }
65 |
--------------------------------------------------------------------------------
/src/libnin/Input.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #ifndef LIBNIN_INPUT_H
28 | #define LIBNIN_INPUT_H 1
29 |
30 | #include
31 | #include
32 |
33 | namespace libnin
34 | {
35 |
36 | class Input : private NonCopyable
37 | {
38 | public:
39 | Input();
40 |
41 | void set(std::uint8_t input);
42 | void poll(bool polling);
43 |
44 | std::uint8_t read();
45 |
46 | private:
47 | void reset();
48 |
49 | bool _polling;
50 | std::uint8_t _state;
51 | std::uint8_t _controller;
52 | std::uint8_t _controllerLatch;
53 | };
54 |
55 | } // namespace libnin
56 |
57 | #endif
58 |
--------------------------------------------------------------------------------
/src/libnin/Mapper/AXROM.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #include
28 | #include
29 | #include
30 |
31 | namespace libnin
32 | {
33 |
34 | void MapperAXROM::handleWrite(std::uint16_t addr, std::uint8_t value)
35 | {
36 | if (addr >= 0x8000)
37 | {
38 | mirror(((value >> 4) & 1) ? NIN_MIRROR_B : NIN_MIRROR_A);
39 | bankPrg32k(2, CART_PRG_ROM, value & 0xf);
40 | }
41 | }
42 |
43 | void MapperAXROM::handleWrite_Conflicts(std::uint16_t addr, std::uint8_t value)
44 | {
45 | if (addr >= 0x8000)
46 | {
47 | value &= _prg[(addr - 0x8000) / 0x2000 + 2][addr & 0x1fff];
48 | mirror(((value >> 4) & 1) ? NIN_MIRROR_B : NIN_MIRROR_A);
49 | bankPrg32k(2, CART_PRG_ROM, value & 0xf);
50 | }
51 | }
52 |
53 | } // namespace libnin
54 |
--------------------------------------------------------------------------------
/src/libnin/Mapper/AXROM.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #ifndef LIBNIN_MAPPER_AXROM_H
28 | #define LIBNIN_MAPPER_AXROM_H 1
29 |
30 | #include
31 | #include
32 |
33 | namespace libnin
34 | {
35 |
36 | class MapperAXROM : public Mapper
37 | {
38 | public:
39 | void handleWrite(std::uint16_t addr, std::uint8_t value);
40 | void handleWrite_Conflicts(std::uint16_t addr, std::uint8_t value);
41 | };
42 |
43 | } // namespace libnin
44 |
45 | #endif
46 |
--------------------------------------------------------------------------------
/src/libnin/Mapper/Action52.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #include
28 | #include
29 | #include
30 |
31 | namespace libnin
32 | {
33 |
34 | void MapperAction52::handleInit()
35 | {
36 | bankPrg32k(2, CART_PRG_ROM, 0);
37 | bankChr8k(0);
38 | }
39 |
40 | void MapperAction52::handleWrite(std::uint16_t addr, std::uint8_t value)
41 | {
42 | std::uint16_t prgBank;
43 | std::uint16_t chrBank;
44 |
45 | if (addr >= 0x8000)
46 | {
47 | chrBank = ((addr & 0x000f) << 2) | (value & 0x03);
48 | prgBank = (addr >> 6) & 0x1f;
49 | switch ((addr >> 0xb) & 0x3)
50 | {
51 | case 0:
52 | prgBank += 0;
53 | break;
54 | case 1:
55 | prgBank += 32;
56 | break;
57 | case 2:
58 | break;
59 | case 3:
60 | prgBank += 64;
61 | }
62 |
63 | bankChr8k(chrBank);
64 | if (addr & 0x20)
65 | {
66 | bankPrg16k(2, CART_PRG_ROM, prgBank);
67 | bankPrg16k(4, CART_PRG_ROM, prgBank);
68 | }
69 | else
70 | {
71 | bankPrg16k(2, CART_PRG_ROM, (prgBank & 0xfffe) | 0);
72 | bankPrg16k(4, CART_PRG_ROM, (prgBank & 0xfffe) | 1);
73 | }
74 | mirror(addr & 0x2000 ? NIN_MIRROR_V : NIN_MIRROR_H);
75 | }
76 | }
77 |
78 | } // namespace libnin
79 |
--------------------------------------------------------------------------------
/src/libnin/Mapper/Action52.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #ifndef LIBNIN_MAPPER_ACTION52_H
28 | #define LIBNIN_MAPPER_ACTION52_H 1
29 |
30 | #include
31 | #include
32 |
33 | namespace libnin
34 | {
35 |
36 | class MapperAction52 : public Mapper
37 | {
38 | public:
39 | void handleInit();
40 | void handleWrite(std::uint16_t addr, std::uint8_t value);
41 | };
42 |
43 | } // namespace libnin
44 |
45 | #endif
46 |
--------------------------------------------------------------------------------
/src/libnin/Mapper/CNROM.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #include
28 | #include
29 | #include
30 |
31 | namespace libnin
32 | {
33 |
34 | void MapperCNROM::handleWrite(std::uint16_t addr, std::uint8_t value)
35 | {
36 | if (addr >= 0x8000)
37 | {
38 | bankChr8k(value & 0x03);
39 | }
40 | }
41 |
42 | } // namespace libnin
43 |
--------------------------------------------------------------------------------
/src/libnin/Mapper/CNROM.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #ifndef LIBNIN_MAPPER_CNROM_H
28 | #define LIBNIN_MAPPER_CNROM_H 1
29 |
30 | #include
31 | #include
32 |
33 | namespace libnin
34 | {
35 |
36 | class MapperCNROM : public Mapper
37 | {
38 | public:
39 | void handleWrite(std::uint16_t addr, std::uint8_t value);
40 | };
41 |
42 | } // namespace libnin
43 |
44 | #endif
45 |
--------------------------------------------------------------------------------
/src/libnin/Mapper/CPROM.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #include
28 | #include
29 | #include
30 |
31 | namespace libnin
32 | {
33 |
34 | void MapperCPROM::handleWrite(std::uint16_t addr, std::uint8_t value)
35 | {
36 | if (addr >= 0x8000)
37 | {
38 | bankChr4k(1, value & 0x03);
39 | }
40 | }
41 |
42 | } // namespace libnin
43 |
--------------------------------------------------------------------------------
/src/libnin/Mapper/CPROM.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #ifndef LIBNIN_MAPPER_CPROM_H
28 | #define LIBNIN_MAPPER_CPROM_H 1
29 |
30 | #include
31 | #include
32 |
33 | namespace libnin
34 | {
35 |
36 | class MapperCPROM : public Mapper
37 | {
38 | public:
39 | void handleWrite(std::uint16_t addr, std::uint8_t value);
40 | };
41 |
42 | } // namespace libnin
43 |
44 | #endif
45 |
--------------------------------------------------------------------------------
/src/libnin/Mapper/ColorDreams.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #include
28 | #include
29 | #include
30 |
31 | namespace libnin
32 | {
33 |
34 | void MapperColorDreams::handleWrite(std::uint16_t addr, std::uint8_t value)
35 | {
36 | if (addr >= 0x8000)
37 | {
38 | bankPrg32k(2, CART_PRG_ROM, value & 0x3);
39 | bankChr8k(value >> 4);
40 | }
41 | }
42 |
43 | } // namespace libnin
44 |
--------------------------------------------------------------------------------
/src/libnin/Mapper/ColorDreams.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #ifndef LIBNIN_MAPPER_COLORDREAMS_H
28 | #define LIBNIN_MAPPER_COLORDREAMS_H 1
29 |
30 | #include
31 | #include
32 |
33 | namespace libnin
34 | {
35 |
36 | class MapperColorDreams : public Mapper
37 | {
38 | public:
39 | void handleWrite(std::uint16_t addr, std::uint8_t value);
40 | };
41 |
42 | } // namespace libnin
43 |
44 | #endif
45 |
--------------------------------------------------------------------------------
/src/libnin/Mapper/DXROM.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #include
28 | #include
29 | #include
30 |
31 | namespace libnin
32 | {
33 |
34 | void MapperDXROM::handleInit()
35 | {
36 | _bankSelect = 0;
37 |
38 | bankPrg8k(2, CART_PRG_ROM, 0);
39 | bankPrg8k(3, CART_PRG_ROM, 0);
40 | bankPrg8k(4, CART_PRG_ROM, -2);
41 | bankPrg8k(5, CART_PRG_ROM, -1);
42 | }
43 |
44 | void MapperDXROM::handleWrite(std::uint16_t addr, std::uint8_t value)
45 | {
46 | if (addr >= 0x8000 && addr <= 0x9fff)
47 | {
48 | if ((addr & 1) == 0)
49 | _bankSelect = value & 7;
50 | else
51 | {
52 | switch (_bankSelect)
53 | {
54 | case 0:
55 | bankChr2k(0, (value & 0x3e) >> 1);
56 | break;
57 | case 1:
58 | bankChr2k(1, (value & 0x3e) >> 1);
59 | break;
60 | case 2:
61 | bankChr1k(4, value & 0x3f);
62 | break;
63 | case 3:
64 | bankChr1k(5, value & 0x3f);
65 | break;
66 | case 4:
67 | bankChr1k(6, value & 0x3f);
68 | break;
69 | case 5:
70 | bankChr1k(7, value & 0x3f);
71 | break;
72 | case 6:
73 | bankPrg8k(2, CART_PRG_ROM, value & 0x0f);
74 | break;
75 | case 7:
76 | bankPrg8k(3, CART_PRG_ROM, value & 0x0f);
77 | break;
78 | }
79 | }
80 | }
81 | }
82 |
83 | } // namespace libnin
84 |
--------------------------------------------------------------------------------
/src/libnin/Mapper/DXROM.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #ifndef LIBNIN_MAPPER_DXROM_H
28 | #define LIBNIN_MAPPER_DXROM_H 1
29 |
30 | #include
31 | #include
32 |
33 | namespace libnin
34 | {
35 |
36 | class MapperDXROM : public Mapper
37 | {
38 | public:
39 | void handleInit();
40 | void handleWrite(std::uint16_t addr, std::uint8_t value);
41 |
42 | private:
43 | std::uint8_t _bankSelect : 3;
44 | };
45 |
46 | } // namespace libnin
47 |
48 | #endif
49 |
--------------------------------------------------------------------------------
/src/libnin/Mapper/DiskSystem.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #ifndef LIBNIN_MAPPER_DISK_SYSTEM_H
28 | #define LIBNIN_MAPPER_DISK_SYSTEM_H 1
29 |
30 | #include
31 | #include
32 |
33 | namespace libnin
34 | {
35 |
36 | class MapperDiskSystem : public Mapper
37 | {
38 | public:
39 | void handleInit();
40 | void handleTick();
41 | std::uint8_t handleRead(std::uint16_t addr);
42 | void handleWrite(std::uint16_t addr, std::uint8_t value);
43 |
44 | private:
45 | std::uint32_t _headPos;
46 | std::uint16_t _delay;
47 | std::uint16_t _irqReloadValue;
48 | std::uint16_t _irqTimer;
49 | std::uint8_t _extPort;
50 | std::uint8_t _latchRead;
51 | std::uint8_t _latchWrite;
52 | std::uint8_t _sideCount;
53 |
54 | bool _motor : 1;
55 | bool _noScan : 1;
56 | bool _inData : 1;
57 | bool _write : 1;
58 | bool _irqEnabledTransfer : 1;
59 | bool _irqEnabledTimer : 1;
60 | bool _irqReloadFlag : 1;
61 | bool _transfered : 1;
62 | bool _scanning : 1;
63 | bool _skippedGap : 1;
64 | bool _endOfDisk : 1;
65 | bool _transmitCRC : 1;
66 | };
67 |
68 | } // namespace libnin
69 |
70 | #endif
71 |
--------------------------------------------------------------------------------
/src/libnin/Mapper/GXROM.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #include
28 | #include
29 | #include
30 |
31 | namespace libnin
32 | {
33 |
34 | void MapperGXROM::handleWrite(std::uint16_t addr, std::uint8_t value)
35 | {
36 | if (addr >= 0x8000)
37 | {
38 | bankPrg32k(2, CART_PRG_ROM, (value >> 4) & 0x3);
39 | bankChr8k(value & 0x3);
40 | }
41 | }
42 |
43 | } // namespace libnin
44 |
--------------------------------------------------------------------------------
/src/libnin/Mapper/GXROM.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #ifndef LIBNIN_MAPPER_GXROM_H
28 | #define LIBNIN_MAPPER_GXROM_H 1
29 |
30 | #include
31 | #include
32 |
33 | namespace libnin
34 | {
35 |
36 | class MapperGXROM : public Mapper
37 | {
38 | public:
39 | void handleWrite(std::uint16_t addr, std::uint8_t value);
40 | };
41 |
42 | } // namespace libnin
43 |
44 | #endif
45 |
--------------------------------------------------------------------------------
/src/libnin/Mapper/MMC1.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #ifndef LIBNIN_MAPPER_MMC1_H
28 | #define LIBNIN_MAPPER_MMC1_H 1
29 |
30 | #include
31 | #include
32 |
33 | namespace libnin
34 | {
35 |
36 | class MapperMMC1 : public Mapper
37 | {
38 | public:
39 | void handleInit();
40 | void handleWrite(std::uint16_t addr, std::uint8_t value);
41 |
42 | private:
43 | void regWrite(std::uint16_t addr, std::uint8_t value);
44 | void applyPrg();
45 | void applyChr();
46 | void applyMirror();
47 |
48 | std::uint8_t _shift;
49 | std::uint8_t _count;
50 | std::uint8_t _mirroring : 2;
51 | std::uint8_t _prgBankMode : 2;
52 | std::uint8_t _chrBankMode : 1;
53 | std::uint8_t _chrBank0 : 5;
54 | std::uint8_t _chrBank1 : 5;
55 | std::uint8_t _prgBank : 4;
56 | };
57 |
58 | } // namespace libnin
59 |
60 | #endif
61 |
--------------------------------------------------------------------------------
/src/libnin/Mapper/MMC2.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #include
28 | #include
29 | #include
30 |
31 | namespace libnin
32 | {
33 |
34 | void MapperMMC2::handleInit()
35 | {
36 | _bankLatch0Lo = 0;
37 | _bankLatch0Hi = 0;
38 | _bankLatch1Lo = 0;
39 | _bankLatch1Hi = 0;
40 | _latch0 = 0;
41 | _latch1 = 0;
42 |
43 | bankPrg8k(3, CART_PRG_ROM, -3);
44 | bankPrg8k(4, CART_PRG_ROM, -2);
45 | bankPrg8k(5, CART_PRG_ROM, -1);
46 |
47 | applyChr();
48 | }
49 |
50 | void MapperMMC2::handleWrite(std::uint16_t addr, std::uint8_t value)
51 | {
52 | switch (addr & 0xf000)
53 | {
54 | case 0xa000: // PRG ROM bank
55 | bankPrg8k(2, CART_PRG_ROM, value & 0xf);
56 | break;
57 | case 0xb000:
58 | _bankLatch0Lo = value & 0x1f;
59 | applyChr();
60 | break;
61 | case 0xc000:
62 | _bankLatch0Hi = value & 0x1f;
63 | applyChr();
64 | break;
65 | case 0xd000:
66 | _bankLatch1Lo = value & 0x1f;
67 | applyChr();
68 | break;
69 | case 0xe000:
70 | _bankLatch1Hi = value & 0x1f;
71 | applyChr();
72 | break;
73 | case 0xf000:
74 | if (value & 0x1)
75 | mirror(NIN_MIRROR_V);
76 | else
77 | mirror(NIN_MIRROR_H);
78 | }
79 | }
80 |
81 | void MapperMMC2::handleVideoRead(std::uint16_t addr)
82 | {
83 | if (addr == 0x0fd8)
84 | {
85 | _latch0 = 0;
86 | applyChr();
87 | }
88 | else if (addr == 0x0fe8)
89 | {
90 | _latch0 = 1;
91 | applyChr();
92 | }
93 | else if (addr >= 0x1fd8 && addr <= 0x1fdf)
94 | {
95 | _latch1 = 0;
96 | applyChr();
97 | }
98 | else if (addr >= 0x1fe8 && addr <= 0x1fef)
99 | {
100 | _latch1 = 1;
101 | applyChr();
102 | }
103 | }
104 |
105 | void MapperMMC2::applyChr()
106 | {
107 | bankChr4k(0, _latch0 ? _bankLatch0Hi : _bankLatch0Lo);
108 | bankChr4k(1, _latch1 ? _bankLatch1Hi : _bankLatch1Lo);
109 | }
110 |
111 | } // namespace libnin
112 |
--------------------------------------------------------------------------------
/src/libnin/Mapper/MMC2.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #ifndef LIBNIN_MAPPER_MMC2_H
28 | #define LIBNIN_MAPPER_MMC2_H 1
29 |
30 | #include
31 | #include
32 |
33 | namespace libnin
34 | {
35 |
36 | class MapperMMC2 : public Mapper
37 | {
38 | public:
39 | void handleInit();
40 | void handleWrite(std::uint16_t addr, std::uint8_t value);
41 | void handleVideoRead(std::uint16_t addr);
42 |
43 | private:
44 | void applyChr();
45 |
46 | std::uint8_t _bankLatch0Lo;
47 | std::uint8_t _bankLatch0Hi;
48 | std::uint8_t _bankLatch1Lo;
49 | std::uint8_t _bankLatch1Hi;
50 | std::uint8_t _latch0 : 1;
51 | std::uint8_t _latch1 : 1;
52 | };
53 |
54 | } // namespace libnin
55 |
56 | #endif
57 |
--------------------------------------------------------------------------------
/src/libnin/Mapper/MMC3.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #ifndef LIBNIN_MAPPER_MMC3_H
28 | #define LIBNIN_MAPPER_MMC3_H 1
29 |
30 | #include
31 | #include
32 |
33 | namespace libnin
34 | {
35 |
36 | class MapperMMC3 : public Mapper
37 | {
38 | public:
39 | void handleInit();
40 | void handleInit_Multi37();
41 | void handleInit_Multi47();
42 | void handleWrite(std::uint16_t addr, std::uint8_t value);
43 | void handleWrite_Multi37(std::uint16_t addr, std::uint8_t value);
44 | void handleWrite_Multi47(std::uint16_t addr, std::uint8_t value);
45 | void handleVideoRead(std::uint16_t addr);
46 |
47 | private:
48 | void apply();
49 | void bankPrg(int slot, int index);
50 | void bankChr(int slot, int index);
51 |
52 | std::uint8_t _bankSelect : 3;
53 | std::uint8_t _bank[8];
54 | std::uint8_t _bankModePrgRom : 1;
55 | std::uint8_t _bankModeChrRom : 1;
56 |
57 | std::uint8_t _irqScanlineEnabled : 1;
58 | std::uint8_t _irqScanlineReload : 1;
59 | std::uint8_t _irqScanlineCounter;
60 | std::uint8_t _irqScanlineReloadValue;
61 | std::uint16_t _irqScanlineFilterShifter;
62 | std::uint16_t _oldVmemAddr;
63 |
64 | std::uint32_t _prgBankAnd;
65 | std::uint32_t _prgBankOr;
66 | std::uint32_t _chrBankAnd;
67 | std::uint32_t _chrBankOr;
68 | };
69 |
70 | } // namespace libnin
71 |
72 | #endif
73 |
--------------------------------------------------------------------------------
/src/libnin/Mapper/MMC4.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #include
28 | #include
29 | #include
30 |
31 | namespace libnin
32 | {
33 |
34 | void MapperMMC4::handleWrite(std::uint16_t addr, std::uint8_t value)
35 | {
36 | switch (addr & 0xf000)
37 | {
38 | case 0xa000: // PRG ROM bank
39 | bankPrg16k(2, CART_PRG_ROM, value & 0xf);
40 | break;
41 | default:
42 | MapperMMC2::handleWrite(addr, value);
43 | break;
44 | }
45 | }
46 |
47 | } // namespace libnin
48 |
--------------------------------------------------------------------------------
/src/libnin/Mapper/MMC4.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #ifndef LIBNIN_MAPPER_MMC4_H
28 | #define LIBNIN_MAPPER_MMC4_H 1
29 |
30 | #include
31 | #include
32 |
33 | namespace libnin
34 | {
35 |
36 | class MapperMMC4 : public MapperMMC2
37 | {
38 | public:
39 | void handleWrite(std::uint16_t addr, std::uint8_t value);
40 | };
41 |
42 | } // namespace libnin
43 |
44 | #endif
45 |
--------------------------------------------------------------------------------
/src/libnin/Mapper/MMC5.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #ifndef LIBNIN_MAPPER_MMC5_H
28 | #define LIBNIN_MAPPER_MMC5_H 1
29 |
30 | #include
31 | #include
32 |
33 | namespace libnin
34 | {
35 |
36 | class MapperMMC5 : public Mapper
37 | {
38 | public:
39 | void handleInit();
40 | void handleTick();
41 | std::uint8_t handleRead(std::uint16_t addr);
42 | void handleWrite(std::uint16_t addr, std::uint8_t value);
43 | void handleVideoRead(std::uint16_t addr);
44 | std::uint8_t handleNtRead(int nametable, std::uint16_t off);
45 | void handleNtWrite(int nametable, std::uint16_t off, std::uint8_t value);
46 | std::uint8_t handleChrRead(int bank, std::uint16_t offset);
47 |
48 | private:
49 | void applyPrg();
50 | void applyChr();
51 |
52 | std::uint8_t _bankModePrg : 2;
53 | std::uint8_t _bankModeChr : 2;
54 | std::uint8_t _bankSelectPrg[5];
55 | std::uint8_t _bankSelectChr[12];
56 | std::uint8_t _nametable;
57 | std::uint8_t _fillNT;
58 | std::uint8_t _fillAT;
59 | std::uint8_t _mul[2];
60 | std::uint8_t* _chr2[8];
61 |
62 | std::uint16_t _ppuAddr;
63 | std::uint8_t _ppuAddrCount;
64 | std::uint8_t _ppuIdleCount;
65 | std::uint8_t _fetchCount;
66 | std::uint8_t _scanline;
67 | std::uint8_t _scanlineTarget;
68 |
69 | bool _ppuReading : 1;
70 | bool _ppuSpriteFlag : 1;
71 | bool _ppuRenderFlag : 1;
72 | bool _mode8x16 : 1;
73 | bool _inFrame : 1;
74 | bool _scanlineEnabled : 1;
75 | bool _scanlinePending : 1;
76 | };
77 |
78 | } // namespace libnin
79 |
80 | #endif
81 |
--------------------------------------------------------------------------------
/src/libnin/Mapper/Mapper15.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #include
28 | #include
29 | #include
30 | #include
31 |
32 | namespace libnin
33 | {
34 |
35 | void Mapper15::handleInit()
36 | {
37 | bankPrg32k(2, CART_PRG_ROM, 0);
38 | mirror(NIN_MIRROR_H);
39 | }
40 |
41 | void Mapper15::handleWrite(std::uint16_t addr, std::uint8_t value)
42 | {
43 | if (addr >= 0x8000)
44 | {
45 | if (value & 0x40)
46 | mirror(NIN_MIRROR_V);
47 | else
48 | mirror(NIN_MIRROR_H);
49 |
50 | switch (addr & 3)
51 | {
52 | case 0:
53 | /* NROM-256 */
54 | bankPrg32k(2, CART_PRG_ROM, (value & 0x3f) >> 1);
55 | break;
56 | case 1:
57 | /* UNROM */
58 | bankPrg16k(2, CART_PRG_ROM, value & 0x3f);
59 | bankPrg16k(4, CART_PRG_ROM, (value & 0x3f) | 7);
60 | break;
61 | case 2:
62 | /* NROM-64 */
63 | bankPrg8k(2, CART_PRG_ROM, ((value & 0x3f) << 1) | (value >> 7));
64 | bankPrg8k(3, CART_PRG_ROM, ((value & 0x3f) << 1) | (value >> 7));
65 | bankPrg8k(4, CART_PRG_ROM, ((value & 0x3f) << 1) | (value >> 7));
66 | bankPrg8k(5, CART_PRG_ROM, ((value & 0x3f) << 1) | (value >> 7));
67 | break;
68 | case 3:
69 | /* NROM-128 */
70 | bankPrg16k(2, CART_PRG_ROM, (value & 0x3f));
71 | bankPrg16k(4, CART_PRG_ROM, (value & 0x3f));
72 | break;
73 | }
74 | }
75 | }
76 |
77 | } // namespace libnin
78 |
--------------------------------------------------------------------------------
/src/libnin/Mapper/Mapper15.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #ifndef LIBNIN_MAPPER_MAPPER15_H
28 | #define LIBNIN_MAPPER_MAPPER15_H 1
29 |
30 | #include
31 | #include
32 |
33 | namespace libnin
34 | {
35 |
36 | class Mapper15 : public Mapper
37 | {
38 | public:
39 | void handleInit();
40 | void handleWrite(std::uint16_t addr, std::uint8_t value);
41 | };
42 |
43 | } // namespace libnin
44 |
45 | #endif
46 |
--------------------------------------------------------------------------------
/src/libnin/Mapper/UXROM.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #include
28 | #include
29 | #include
30 |
31 | namespace libnin
32 | {
33 |
34 | template
35 | static void applyUxROM(MapperUXROM& mapper, std::uint16_t addr, std::uint8_t value)
36 | {
37 | if (addr >= 0x8000)
38 | {
39 | if (conflicts)
40 | {
41 | value &= mapper.bank(((addr - 0x8000) / 0x2000) + 2)[addr & 0x1fff];
42 | }
43 | mapper.bankPrg16k(bank, CART_PRG_ROM, value >> shift);
44 | }
45 | }
46 |
47 | void MapperUXROM::handleWrite(std::uint16_t addr, std::uint8_t value)
48 | {
49 | applyUxROM(*this, addr, value);
50 | }
51 |
52 | void MapperUXROM::handleWrite_NoConflicts(std::uint16_t addr, std::uint8_t value)
53 | {
54 | applyUxROM(*this, addr, value);
55 | }
56 |
57 | void MapperUXROM::handleWrite_UN1ROM(std::uint16_t addr, std::uint8_t value)
58 | {
59 | applyUxROM(*this, addr, value);
60 | }
61 |
62 | void MapperUXROM::handleWrite_UNROM180(std::uint16_t addr, std::uint8_t value)
63 | {
64 | applyUxROM(*this, addr, value);
65 | }
66 |
67 | } // namespace libnin
68 |
--------------------------------------------------------------------------------
/src/libnin/Mapper/UXROM.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #ifndef LIBNIN_MAPPER_UXROM_H
28 | #define LIBNIN_MAPPER_UXROM_H 1
29 |
30 | #include
31 | #include
32 |
33 | namespace libnin
34 | {
35 |
36 | class MapperUXROM : public Mapper
37 | {
38 | public:
39 | void handleWrite(std::uint16_t addr, std::uint8_t value);
40 | void handleWrite_NoConflicts(std::uint16_t addr, std::uint8_t value);
41 | void handleWrite_UN1ROM(std::uint16_t addr, std::uint8_t value);
42 | void handleWrite_UNROM180(std::uint16_t addr, std::uint8_t value);
43 | };
44 |
45 | } // namespace libnin
46 |
47 | #endif
48 |
--------------------------------------------------------------------------------
/src/libnin/MapperID.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #include
28 |
29 | using namespace libnin;
30 |
31 | MapperID libnin::getMapperID(int mapper, int submapper)
32 | {
33 | switch (mapper)
34 | {
35 | case 0:
36 | return MapperID::NROM;
37 | case 1:
38 | return MapperID::MMC1;
39 | case 2:
40 | if (submapper == 1)
41 | return MapperID::UxROM_NoConflicts;
42 | return MapperID::UxROM;
43 | case 3:
44 | return MapperID::CNROM;
45 | case 4:
46 | return MapperID::MMC3;
47 | case 5:
48 | return MapperID::MMC5;
49 | case 7:
50 | if (submapper == 2)
51 | return MapperID::AxROM_Conflicts;
52 | return MapperID::AxROM;
53 | case 9:
54 | return MapperID::MMC2;
55 | case 10:
56 | return MapperID::MMC4;
57 | case 11:
58 | return MapperID::ColorDreams;
59 | case 13:
60 | return MapperID::CPROM;
61 | case 15:
62 | return MapperID::Mapper15;
63 | case 20:
64 | return MapperID::FDS;
65 | case 37:
66 | return MapperID::MMC3_Multi37;
67 | case 47:
68 | return MapperID::MMC3_Multi47;
69 | case 66:
70 | return MapperID::GxROM;
71 | case 94:
72 | return MapperID::UxROM_UN1ROM;
73 | case 180:
74 | return MapperID::UxROM_UNROM180;
75 | case 206:
76 | return MapperID::DxROM;
77 | case 228:
78 | return MapperID::Action52;
79 | default:
80 | return MapperID::Unknown;
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/src/libnin/MapperID.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #ifndef LIBNIN_MAPPER_ID_H
28 | #define LIBNIN_MAPPER_ID_H
29 |
30 | namespace libnin
31 | {
32 |
33 | enum class MapperID
34 | {
35 | Bad = -2,
36 | Unknown = -1,
37 | NROM = 0,
38 | MMC1,
39 | MMC2,
40 | MMC3,
41 | MMC3_Multi37,
42 | MMC3_Multi47,
43 | MMC4,
44 | MMC5,
45 | AxROM,
46 | AxROM_Conflicts,
47 | CNROM,
48 | CPROM,
49 | DxROM,
50 | GxROM,
51 | UxROM,
52 | UxROM_NoConflicts,
53 | UxROM_UN1ROM,
54 | UxROM_UNROM180,
55 | ColorDreams,
56 | Action52,
57 | Mapper15,
58 | FDS
59 | };
60 |
61 | MapperID getMapperID(int mapper, int submapper);
62 |
63 | } // namespace libnin
64 |
65 | #endif
66 |
--------------------------------------------------------------------------------
/src/libnin/MapperVariant.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #ifndef LIBNIN_MAPPER_VARIANT_H
28 | #define LIBNIN_MAPPER_VARIANT_H 1
29 |
30 | #include
31 | #include
32 | #include
33 | #include
34 | #include
35 | #include
36 | #include
37 | #include
38 | #include
39 | #include
40 | #include
41 | #include
42 | #include
43 | #include
44 | #include
45 | #include
46 |
47 | namespace libnin
48 | {
49 |
50 | union MapperVariant
51 | {
52 | public:
53 | MapperVariant(Memory& memory, Cart& cart, Disk& disk, IRQ& irq)
54 | : mapper{memory, cart, disk, irq}
55 | {
56 | }
57 |
58 | ~MapperVariant() {}
59 |
60 | Mapper mapper;
61 | MapperAXROM axrom;
62 | MapperCNROM cnrom;
63 | MapperDXROM dxrom;
64 | MapperGXROM gxrom;
65 | MapperUXROM uxrom;
66 | MapperMMC1 mmc1;
67 | MapperMMC2 mmc2;
68 | MapperMMC3 mmc3;
69 | MapperMMC4 mmc4;
70 | MapperMMC5 mmc5;
71 | MapperAction52 action52;
72 | MapperColorDreams colorDreams;
73 | MapperDiskSystem diskSystem;
74 | };
75 |
76 | } // namespace libnin
77 |
78 | #endif
79 |
--------------------------------------------------------------------------------
/src/libnin/MemberStateHelper.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #ifndef LIBNIN_MEMBER_STATE_HELPER_H
28 | #define LIBNIN_MEMBER_STATE_HELPER_H 1
29 |
30 | namespace libnin
31 | {
32 |
33 | template
34 | struct MemberStateHelper
35 | {
36 | using Pointer = MemberStateHelper (T::*)();
37 |
38 | MemberStateHelper()
39 | : p{}
40 | {
41 | }
42 | MemberStateHelper(const MemberStateHelper& h)
43 | : p{h.p}
44 | {
45 | }
46 | MemberStateHelper(Pointer pp)
47 | : p(pp)
48 | {
49 | }
50 |
51 | MemberStateHelper& operator=(const MemberStateHelper& h)
52 | {
53 | p = h.p;
54 | return *this;
55 | }
56 | operator Pointer() { return p; }
57 | bool operator==(const MemberStateHelper& other) const { return p == other.p; }
58 |
59 | Pointer p;
60 | };
61 |
62 | } // namespace libnin
63 |
64 | #endif
65 |
--------------------------------------------------------------------------------
/src/libnin/Memory.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #include
28 |
29 | using namespace libnin;
30 |
31 | Memory::Memory()
32 | : ram{}
33 | , vram{}
34 | , exvram{}
35 | , palettes{}
36 | , oam{}
37 | {
38 | }
39 |
--------------------------------------------------------------------------------
/src/libnin/Memory.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #ifndef LIBNIN_MEMORY_H
28 | #define LIBNIN_MEMORY_H 1
29 |
30 | #include
31 | #include
32 |
33 | namespace libnin
34 | {
35 |
36 | class Memory : private NonCopyable
37 | {
38 | public:
39 | Memory();
40 |
41 | std::uint8_t ram[0x800];
42 | std::uint8_t vram[0x1000];
43 | std::uint8_t exvram[0x800];
44 | std::uint8_t palettes[0x20];
45 | std::uint8_t oam[0x100];
46 | };
47 |
48 | } // namespace libnin
49 |
50 | #endif
51 |
--------------------------------------------------------------------------------
/src/libnin/NMI.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #ifndef LIBNIN_NMI_H
28 | #define LIBNIN_NMI_H 1
29 |
30 | #include
31 | #include
32 |
33 | #define NMI_OCCURED 0x01
34 | #define NMI_OUTPUT 0x02
35 |
36 | namespace libnin
37 | {
38 |
39 | class NMI : private NonCopyable
40 | {
41 | public:
42 | NMI()
43 | : _status{}
44 | , _latch{}
45 | {
46 | }
47 |
48 | bool high() const { return _latch; }
49 | bool check(std::uint8_t flag) const { return !!(_status & flag); }
50 |
51 | void set(std::uint8_t flag)
52 | {
53 | std::uint8_t prev;
54 |
55 | prev = _status;
56 | _status |= flag;
57 |
58 | if ((prev != _status) && (_status == (NMI_OCCURED | NMI_OUTPUT)))
59 | _latch = true;
60 | }
61 |
62 | void unset(std::uint8_t flag)
63 | {
64 | _status &= ~flag;
65 | }
66 |
67 | void ack()
68 | {
69 | _latch = false;
70 | }
71 |
72 | private:
73 | std::uint8_t _status : 2;
74 | bool _latch : 1;
75 | };
76 |
77 | }; // namespace libnin
78 |
79 | #endif
80 |
--------------------------------------------------------------------------------
/src/libnin/NonCopyable.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #ifndef LIBNIN_NON_COPYABLE_H
28 | #define LIBNIN_NON_COPYABLE_H 1
29 |
30 | namespace libnin
31 | {
32 |
33 | class NonCopyable
34 | {
35 | public:
36 | NonCopyable() {}
37 | ~NonCopyable() {}
38 |
39 | NonCopyable(const NonCopyable&) = delete;
40 | NonCopyable& operator=(const NonCopyable&) = delete;
41 | };
42 |
43 | } // namespace libnin
44 |
45 | #endif
46 |
--------------------------------------------------------------------------------
/src/libnin/RomHeader.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #ifndef LIBNIN_ROM_HEADER_H
28 | #define LIBNIN_ROM_HEADER_H 1
29 |
30 | #include
31 |
32 | namespace libnin
33 | {
34 |
35 | struct RomHeaderLegacy
36 | {
37 | std::uint8_t reserved[8];
38 | };
39 |
40 | struct RomHeaderNes2
41 | {
42 | std::uint8_t mapperEx : 4;
43 | std::uint8_t submapper : 4;
44 | std::uint8_t prgRomSizeHi : 4;
45 | std::uint8_t chrRomSizeHi : 4;
46 | std::uint8_t prgRamSizeShift : 4;
47 | std::uint8_t prgNvramSizeShift : 4;
48 | std::uint8_t chrRamSizeShift : 4;
49 | std::uint8_t chrNvramSizeShift : 4;
50 | std::uint8_t region : 2;
51 | std::uint8_t reserved0 : 6;
52 | std::uint8_t reserved[3];
53 | };
54 |
55 | struct RomHeader
56 | {
57 | char magic[4];
58 | std::uint8_t prgRomSize;
59 | std::uint8_t chrRomSize;
60 | std::uint8_t mirroring : 1;
61 | std::uint8_t battery : 1;
62 | std::uint8_t trainer : 1;
63 | std::uint8_t quadScreen : 1;
64 | std::uint8_t mapperLo : 4;
65 | std::uint8_t vs : 1;
66 | std::uint8_t playChoice : 1;
67 | std::uint8_t magicNes2 : 2;
68 | std::uint8_t mapperHi : 4;
69 |
70 | union
71 | {
72 | RomHeaderLegacy ines;
73 | RomHeaderNes2 nes2;
74 | };
75 | };
76 |
77 | } // namespace libnin
78 |
79 | #endif
80 |
--------------------------------------------------------------------------------
/src/libnin/Save.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #include
28 | #include
29 |
30 | using namespace libnin;
31 |
32 | Save::Save(Cart& cart)
33 | : _cart{cart}
34 | , _file{}
35 | , _battery{}
36 | {
37 | }
38 |
39 | Save::~Save()
40 | {
41 | sync();
42 | if (_file)
43 | std::fclose(_file);
44 | }
45 |
46 | void Save::setBattery(bool battery)
47 | {
48 | _battery = battery;
49 | }
50 |
51 | void Save::setSaveFile(const char* path)
52 | {
53 | if (!_battery)
54 | return;
55 |
56 | _file = std::fopen(path, "ab");
57 | if (_file)
58 | std::fclose(_file);
59 |
60 | _file = std::fopen(path, "r+b");
61 | if (_file)
62 | {
63 | _cart.load(CART_PRG_RAM, _cart.segment(CART_PRG_RAM).bankCount, _file);
64 | }
65 | }
66 |
67 | void Save::sync()
68 | {
69 | const CartSegment& prgRam = _cart.segment(CART_PRG_RAM);
70 |
71 | if (!_file)
72 | return;
73 |
74 | std::fseek(_file, 0, SEEK_SET);
75 | std::fwrite(prgRam.base, std::size_t(prgRam.bankCount) * 0x2000, 1, _file);
76 | std::fflush(_file);
77 | }
78 |
--------------------------------------------------------------------------------
/src/libnin/Save.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #ifndef LIBNIN_SAVE_H
28 | #define LIBNIN_SAVE_H 1
29 |
30 | #include
31 | #include
32 |
33 | namespace libnin
34 | {
35 |
36 | class Cart;
37 | class Save : private NonCopyable
38 | {
39 | public:
40 | Save(Cart& cart);
41 | ~Save();
42 |
43 | void setBattery(bool battery);
44 | void setSaveFile(const char* path);
45 | void sync();
46 |
47 | private:
48 | Cart& _cart;
49 |
50 | std::FILE* _file;
51 | bool _battery;
52 | };
53 |
54 | } // namespace libnin
55 |
56 | #endif
57 |
--------------------------------------------------------------------------------
/src/libnin/State.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #ifndef LIBNIN_STATE_H
28 | #define LIBNIN_STATE_H 1
29 |
30 | #include
31 | #include
32 | #include
33 | #include
34 | #include
35 | #include
36 | #include
37 | #include
38 | #include
39 | #include
40 | #include
41 | #include
42 | #include
43 | #include
44 | #include
45 | #include
46 | #include
47 | #include
48 | #include
49 | #include
50 | #include
51 |
52 | #define BITMAP_X 256
53 | #define BITMAP_Y 240
54 |
55 | #define DEBUG_LEVEL 0
56 |
57 | #define CLOCK_RATE_NTSC 1789773
58 |
59 | namespace libnin
60 | {
61 |
62 | class State : private NonCopyable
63 | {
64 | public:
65 | State();
66 | ~State();
67 |
68 | static State* create(NinError& err, const char* path);
69 |
70 | Memory memory;
71 | HardwareInfo info;
72 | Cart cart;
73 | Disk disk;
74 | Save save;
75 | Input input;
76 | IRQ irq;
77 | NMI nmi;
78 | Video video;
79 | union
80 | {
81 | Mapper mapper;
82 | MapperVariant mapperVariant;
83 | };
84 |
85 | BusVideo busVideo;
86 | Audio audio;
87 | APU apu;
88 | PPU ppu;
89 | BusMain busMain;
90 | CPU cpu;
91 | };
92 |
93 | } // namespace libnin
94 |
95 | /* Expose the state to the world */
96 | struct NinState : public libnin::State
97 | {
98 | };
99 |
100 | #endif
101 |
--------------------------------------------------------------------------------
/src/libnin/Util.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #ifndef LIBNIN_UTIL_H
28 | #define LIBNIN_UTIL_H 1
29 |
30 | #include
31 |
32 | #define UNUSED(x) ((void)x)
33 |
34 | #if defined(WIN32) || defined(_WIN32)
35 | #define UNREACHABLE() __assume(0)
36 | #else
37 | #define UNREACHABLE() __builtin_unreachable()
38 | #endif
39 |
40 | #endif
41 |
--------------------------------------------------------------------------------
/src/libnin/Video.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #include
28 | #include
29 |
30 | using namespace libnin;
31 |
32 | /* A R G B */
33 | const uint32_t Video::kPalette[] = {
34 | 0xff7c7c7c,
35 | 0xfffc0000,
36 | 0xffbc0000,
37 | 0xffbc2844,
38 | 0xff840094,
39 | 0xff2000a8,
40 | 0xff0010a8,
41 | 0xff001488,
42 | 0xff003050,
43 | 0xff007800,
44 | 0xff006800,
45 | 0xff005800,
46 | 0xff584000,
47 | 0xff000000,
48 | 0xff000000,
49 | 0xff000000,
50 | 0xffbcbcbc,
51 | 0xfff87800,
52 | 0xfff85800,
53 | 0xfffc4468,
54 | 0xffcc00d8,
55 | 0xff5800e4,
56 | 0xff0038f8,
57 | 0xff105ce4,
58 | 0xff007cac,
59 | 0xff00b800,
60 | 0xff00a800,
61 | 0xff44a800,
62 | 0xff888800,
63 | 0xff000000,
64 | 0xff000000,
65 | 0xff000000,
66 | 0xfff8f8f8,
67 | 0xfffcbc3c,
68 | 0xfffc8868,
69 | 0xfff87898,
70 | 0xfff878f8,
71 | 0xff9858f8,
72 | 0xff5878f8,
73 | 0xff44a0fc,
74 | 0xff00b8f8,
75 | 0xff18f8b8,
76 | 0xff54d858,
77 | 0xff98f858,
78 | 0xffd8e800,
79 | 0xff787878,
80 | 0xff000000,
81 | 0xff000000,
82 | 0xfffcfcfc,
83 | 0xfffce4a4,
84 | 0xfff8b8b8,
85 | 0xfff8b8d8,
86 | 0xfff8b8f8,
87 | 0xffc0a4f8,
88 | 0xffb0d0f0,
89 | 0xffa8e0fc,
90 | 0xff78d8f8,
91 | 0xff78f8d8,
92 | 0xffb8f8b8,
93 | 0xffd8f8b8,
94 | 0xfffcfc00,
95 | 0xfff8d8f8,
96 | 0xff000000,
97 | 0xff000000,
98 | };
99 |
100 | Video::Video()
101 | : _buffer0{}
102 | , _buffer1{}
103 | , _frontBuffer{_buffer0}
104 | , _backBuffer{_buffer1}
105 | , _frameChanged{}
106 | {
107 | }
108 |
109 | void Video::swap()
110 | {
111 | std::uint32_t* tmp;
112 |
113 | tmp = _backBuffer;
114 | _backBuffer = _frontBuffer;
115 | _frontBuffer = tmp;
116 | std::memset(_backBuffer, 0, sizeof(_buffer0));
117 | _frameChanged = true;
118 | }
119 |
--------------------------------------------------------------------------------
/src/libnin/Video.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #ifndef LIBNIN_VIDEO_H
28 | #define LIBNIN_VIDEO_H 1
29 |
30 | #include
31 | #include
32 |
33 | namespace libnin
34 | {
35 |
36 | class Video : private NonCopyable
37 | {
38 | public:
39 | Video();
40 |
41 | const std::uint32_t* front() const { return _frontBuffer; }
42 |
43 | void write(std::uint32_t pos, std::uint8_t color) { _backBuffer[pos] = kPalette[color]; }
44 | void swap();
45 | bool changed()
46 | {
47 | bool tmp = _frameChanged;
48 | _frameChanged = false;
49 | return tmp;
50 | }
51 |
52 | private:
53 | static const std::uint32_t kPalette[];
54 |
55 | std::uint32_t _buffer0[256 * 240];
56 | std::uint32_t _buffer1[256 * 240];
57 | std::uint32_t* _frontBuffer;
58 | std::uint32_t* _backBuffer;
59 | bool _frameChanged;
60 | };
61 |
62 | }; // namespace libnin
63 |
64 | #endif
65 |
--------------------------------------------------------------------------------
/src/libnin/config.h.in:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #ifndef NIN_CONFIG_H
28 | #define NIN_CONFIG_H
29 |
30 | #define NIN_VERSION_MAJOR @VERSION_MAJOR @
31 | #define NIN_VERSION_MINOR @VERSION_MINOR @
32 | #define NIN_VERSION_PATCH @VERSION_PATCH @
33 | #define NIN_VERSION "@VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_PATCH@"
34 |
35 | #endif
36 |
--------------------------------------------------------------------------------
/src/ninconv/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # Nin, a Nintendo Entertainment System Emulator.
2 | #
3 | # Copyright (c) 2018-2020 Maxime Bacoux
4 | # All rights reserved.
5 | #
6 | # This program is free software; you can redistribute it and/or
7 | # modify it under the terms of the GNU General Public License
8 | # Version 2, as published by the Free Software Foundation.
9 | #
10 | # Alternatively, this program can be licensed under a commercial license
11 | # upon request.
12 | #
13 | # When using the program under the GNU General Public License Version 2 license,
14 | # the following apply:
15 | #
16 | # 1. This program is distributed in the hope that it will be useful,
17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 | # GNU General Public License for more details.
20 | #
21 | # 2. You should have received a copy of the GNU General Public License
22 | # along with this program; if not, write to the Free Software
23 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 |
25 | file(GLOB_RECURSE SOURCES "*.c")
26 | add_executable(ninconv ${SOURCES})
27 |
--------------------------------------------------------------------------------
/src/ninconv/gen_db.rb:
--------------------------------------------------------------------------------
1 | # Nin, a Nintendo Entertainment System Emulator.
2 | #
3 | # Copyright (c) 2018-2020 Maxime Bacoux
4 | # All rights reserved.
5 | #
6 | # This program is free software; you can redistribute it and/or
7 | # modify it under the terms of the GNU General Public License
8 | # Version 2, as published by the Free Software Foundation.
9 | #
10 | # Alternatively, this program can be licensed under a commercial license
11 | # upon request.
12 | #
13 | # When using the program under the GNU General Public License Version 2 license,
14 | # the following apply:
15 | #
16 | # 1. This program is distributed in the hope that it will be useful,
17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 | # GNU General Public License for more details.
20 | #
21 | # 2. You should have received a copy of the GNU General Public License
22 | # along with this program; if not, write to the Free Software
23 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 |
25 | require 'nokogiri'
26 |
27 | Game = Struct.new(
28 | :name,
29 | :crc32,
30 | :region,
31 | :mapper,
32 | :mirror,
33 | :battery,
34 | :prg_rom_size,
35 | :prg_ram_size,
36 | :chr_rom_size,
37 | :chr_ram_size
38 | ) do
39 | def serialize
40 | n = name.tr('"', '')
41 | %Q[{ "#{n}", #{"0x%08x" % crc32}, #{region}, #{mapper}, #{mirror}, #{battery}, #{"0x%0x" % prg_rom_size}, #{"0x%0x" % prg_ram_size}, #{"0x%0x" % chr_rom_size}, #{"0x%0x" % chr_ram_size} },]
42 | end
43 | end
44 |
45 | def convert_size(x)
46 | x.to_i * 1024
47 | end
48 |
49 | db_file = ARGV[0]
50 | db = File.open(db_file) { |f| Nokogiri::XML(f) }
51 |
52 | games = []
53 |
54 | db.root.css('game').each do |g|
55 | g.css('cartridge').each do |c|
56 | game = Game.new
57 | name = g.attr('name')
58 | region = g.attr('region')
59 | rev = c.attr('revision')
60 | game.name = name + " (" + region + ")"
61 | game.name.tr!('.<>:|?*', '')
62 | if (rev)
63 | game.name += " (Rev " + rev + ")"
64 | end
65 | game.name.tr!('\\/', '-')
66 | game.crc32 = c.attr('crc').to_s.to_i(16)
67 | game.region = 0
68 | if c.attr('system').include?('PAL')
69 | game.region = 1
70 | end
71 |
72 | board = c.css('board').first
73 | pad = c.css('pad').first
74 |
75 | game.mirror = 0
76 | game.mapper = board.attr('mapper').to_i
77 | if pad && pad.attr("h") == "1"
78 | game.mirror = 1
79 | end
80 |
81 | game.prg_rom_size = 0
82 | game.prg_ram_size = 0
83 | game.chr_rom_size = 0
84 | game.chr_ram_size = 0
85 | game.battery = 0
86 |
87 | prg = c.css('prg').first
88 | if prg
89 | game.prg_rom_size = convert_size(prg.attr('size'))
90 | end
91 |
92 | chr = c.css('chr').first
93 | if chr
94 | game.chr_rom_size = convert_size(chr.attr('size'))
95 | end
96 |
97 | wram = c.css('wram').first
98 | if wram
99 | game.prg_ram_size = convert_size(wram.attr('size'))
100 | game.battery = wram.attr('battery') ? 1 : 0
101 | end
102 |
103 | vram = c.css('vram').first
104 | if vram
105 | game.chr_ram_size = convert_size(vram.attr('size'))
106 | end
107 |
108 | games << game
109 | end
110 | end
111 |
112 | games.uniq! { |x| x.crc32 }
113 | games.sort_by! { |x| x.crc32 }
114 |
115 | File.open("inc/db.inc", "wb") do |f|
116 | games.each do |g|
117 | f << g.serialize
118 | f << "\n"
119 | end
120 | end
121 |
--------------------------------------------------------------------------------
/src/ninconv/ninconv.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #ifndef NINCONV_H
28 | #define NINCONV_H 1
29 |
30 | #include
31 | #include
32 |
33 | typedef struct
34 | {
35 | const char* name;
36 | uint32_t crc32;
37 | uint8_t region : 1;
38 | uint16_t mapper;
39 | uint8_t mirror : 1;
40 | uint8_t battery : 1;
41 | uint32_t prgRomSize;
42 | uint32_t prgRamSize;
43 | uint32_t chrRomSize;
44 | uint32_t chrRamSize;
45 | } NinDbGame;
46 |
47 | uint32_t crc32(FILE* f);
48 |
49 | #endif
50 |
--------------------------------------------------------------------------------
/src/ninhash/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # Nin, a Nintendo Entertainment System Emulator.
2 | #
3 | # Copyright (c) 2018-2020 Maxime Bacoux
4 | # All rights reserved.
5 | #
6 | # This program is free software; you can redistribute it and/or
7 | # modify it under the terms of the GNU General Public License
8 | # Version 2, as published by the Free Software Foundation.
9 | #
10 | # Alternatively, this program can be licensed under a commercial license
11 | # upon request.
12 | #
13 | # When using the program under the GNU General Public License Version 2 license,
14 | # the following apply:
15 | #
16 | # 1. This program is distributed in the hope that it will be useful,
17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 | # GNU General Public License for more details.
20 | #
21 | # 2. You should have received a copy of the GNU General Public License
22 | # along with this program; if not, write to the Free Software
23 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 |
25 | set(SOURCES ninhash.cpp)
26 | add_executable(ninhash ${SOURCES})
27 | target_link_libraries(ninhash libnin)
28 |
--------------------------------------------------------------------------------
/src/ninhash/ninhash.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #include
28 | #include
29 | #include
30 | #include
31 | #include
32 |
33 | #define SEC_NTSC(x) ((std::size_t)((x)*1789773))
34 |
35 | static void dummyAudio(void*, const float*)
36 | {
37 | }
38 |
39 | static std::uint32_t qhash(const std::uint8_t* data, std::size_t len)
40 | {
41 | uint32_t hash = 0;
42 |
43 | for (std::size_t i = 0; i < len; ++i)
44 | {
45 | hash += data[i];
46 | hash += (hash << 10);
47 | hash ^= (hash >> 6);
48 | }
49 |
50 | hash += (hash << 3);
51 | hash ^= (hash >> 11);
52 | hash += (hash << 15);
53 |
54 | return hash;
55 | }
56 |
57 | int main(int argc, char** argv)
58 | {
59 | std::uint32_t hash;
60 | NinState* state;
61 | std::size_t dummy;
62 | std::uint8_t tmp[0x800];
63 |
64 | if (argc != 3)
65 | return 1;
66 |
67 | ninCreateState(&state, argv[1]);
68 | if (!state)
69 | return 1;
70 |
71 | ninAudioSetCallback(state, &dummyAudio, nullptr);
72 | ninRunCycles(state, SEC_NTSC(std::atoi(argv[2])), &dummy);
73 | ninDumpNametable(state, tmp, 0);
74 | ninDumpNametable(state, tmp + 0x400, 1);
75 |
76 | hash = qhash(tmp, 0x800);
77 |
78 | std::printf("0x%08x\n", hash);
79 |
80 | return 0;
81 | }
82 |
--------------------------------------------------------------------------------
/src/ninperf/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # Nin, a Nintendo Entertainment System Emulator.
2 | #
3 | # Copyright (c) 2018-2020 Maxime Bacoux
4 | # All rights reserved.
5 | #
6 | # This program is free software; you can redistribute it and/or
7 | # modify it under the terms of the GNU General Public License
8 | # Version 2, as published by the Free Software Foundation.
9 | #
10 | # Alternatively, this program can be licensed under a commercial license
11 | # upon request.
12 | #
13 | # When using the program under the GNU General Public License Version 2 license,
14 | # the following apply:
15 | #
16 | # 1. This program is distributed in the hope that it will be useful,
17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 | # GNU General Public License for more details.
20 | #
21 | # 2. You should have received a copy of the GNU General Public License
22 | # along with this program; if not, write to the Free Software
23 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 |
25 | set(SOURCES ninperf.cpp)
26 | add_executable(ninperf ${SOURCES})
27 | target_link_libraries(ninperf libnin)
28 |
--------------------------------------------------------------------------------
/src/ninperf/ninperf.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #include
28 | #include
29 | #include
30 | #include
31 | #include
32 | #include
33 |
34 | #define COUNT 10000000
35 | #define SLICE 4096
36 |
37 | using Clock = std::chrono::high_resolution_clock;
38 | using TimePoint = Clock::time_point;
39 | using Duration = std::chrono::duration;
40 |
41 | static void dummyAudio(void*, const float*)
42 | {
43 | }
44 |
45 | int main(int argc, char** argv)
46 | {
47 | NinState* state;
48 | TimePoint before;
49 | TimePoint after;
50 | double duration;
51 | std::uint64_t cps;
52 | size_t cyc;
53 | size_t tmp;
54 |
55 | if (argc != 2)
56 | return 1;
57 |
58 | ninCreateState(&state, argv[1]);
59 | if (!state)
60 | return 1;
61 |
62 | srand((unsigned)time(NULL));
63 | ninAudioSetCallback(state, &dummyAudio, nullptr);
64 |
65 | cyc = 0;
66 | before = Clock::now();
67 | for (;;)
68 | {
69 | ninSetInput(state, (rand() & 0xff));
70 | ninRunCycles(state, SLICE, &tmp);
71 | cyc += SLICE;
72 | cyc += tmp;
73 | if (cyc >= COUNT)
74 | break;
75 | }
76 | after = Clock::now();
77 | duration = std::chrono::duration_cast(after - before).count();
78 | cps = (std::uint64_t)((double)cyc / duration);
79 | printf("%llu cycles/s\n", (long long unsigned int)cps);
80 | return 0;
81 | }
82 |
--------------------------------------------------------------------------------
/src/nintests/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # Nin, a Nintendo Entertainment System Emulator.
2 | #
3 | # Copyright (c) 2018-2020 Maxime Bacoux
4 | # All rights reserved.
5 | #
6 | # This program is free software; you can redistribute it and/or
7 | # modify it under the terms of the GNU General Public License
8 | # Version 2, as published by the Free Software Foundation.
9 | #
10 | # Alternatively, this program can be licensed under a commercial license
11 | # upon request.
12 | #
13 | # When using the program under the GNU General Public License Version 2 license,
14 | # the following apply:
15 | #
16 | # 1. This program is distributed in the hope that it will be useful,
17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 | # GNU General Public License for more details.
20 | #
21 | # 2. You should have received a copy of the GNU General Public License
22 | # along with this program; if not, write to the Free Software
23 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 |
25 | find_package(Threads REQUIRED)
26 |
27 | file(GLOB_RECURSE SOURCES "*.cpp" "*.h")
28 | add_executable(nintests ${SOURCES})
29 | target_link_libraries(nintests libnin Threads::Threads)
30 |
31 | if (UNIX AND NOT APPLE)
32 | target_link_options(nintests PRIVATE -pthread)
33 | endif()
34 |
35 | add_custom_target(
36 | test
37 | COMMAND nintests
38 | WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/data/test_roms"
39 | VERBATIM
40 | USES_TERMINAL
41 | )
42 |
--------------------------------------------------------------------------------
/src/nintests/TestSuite.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Nin, a Nintendo Entertainment System Emulator.
3 | *
4 | * Copyright (c) 2018-2020 Maxime Bacoux
5 | * All rights reserved.
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * Version 2, as published by the Free Software Foundation.
10 | *
11 | * Alternatively, this program can be licensed under a commercial license
12 | * upon request.
13 | *
14 | * When using the program under the GNU General Public License Version 2 license,
15 | * the following apply:
16 | *
17 | * 1. This program is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * 2. You should have received a copy of the GNU General Public License
23 | * along with this program; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 | */
26 |
27 | #ifndef TEST_SUITE_H
28 | #define TEST_SUITE_H
29 |
30 | #include
31 | #include
32 | #include