Switch to SDL3
This commit is contained in:
parent
a8b58c8a1b
commit
934ca543d2
@ -33,8 +33,10 @@ add_executable(nes
|
||||
src/Mapper/Mapper1.h
|
||||
src/Bus.cpp
|
||||
src/Bus.h
|
||||
src/Utils.h)
|
||||
src/Utils.h
|
||||
examples/sdl/SdlGamepadController.cpp
|
||||
examples/sdl/SdlGamepadController.h)
|
||||
|
||||
find_package(SDL2 CONFIG REQUIRED)
|
||||
find_package(SDL3 CONFIG REQUIRED)
|
||||
find_package(fmt REQUIRED)
|
||||
target_link_libraries(nes PRIVATE SDL2::SDL2 fmt::fmt)
|
||||
target_link_libraries(nes PRIVATE SDL3::SDL3 fmt::fmt)
|
||||
11
examples/sdl/SdlGamepadController.cpp
Normal file
11
examples/sdl/SdlGamepadController.cpp
Normal file
@ -0,0 +1,11 @@
|
||||
//
|
||||
// Created by selim on 09.09.2025.
|
||||
//
|
||||
|
||||
#include "SdlGamepadController.h"
|
||||
|
||||
void SdlGamepadController::poll()
|
||||
{
|
||||
//SDL_GetJoysticks()
|
||||
//SDL_GetJoystickButton()
|
||||
}
|
||||
17
examples/sdl/SdlGamepadController.h
Normal file
17
examples/sdl/SdlGamepadController.h
Normal file
@ -0,0 +1,17 @@
|
||||
//
|
||||
// Created by selim on 09.09.2025.
|
||||
//
|
||||
|
||||
#ifndef NES_SDLGAMEPADCONTROLLER_H
|
||||
#define NES_SDLGAMEPADCONTROLLER_H
|
||||
|
||||
#include "../../src/Controller.h"
|
||||
|
||||
class SdlGamepadController: public nes::Controller
|
||||
{
|
||||
public:
|
||||
void poll() override;
|
||||
};
|
||||
|
||||
|
||||
#endif //NES_SDLGAMEPADCONTROLLER_H
|
||||
@ -3,7 +3,7 @@
|
||||
//
|
||||
|
||||
#include "SdlKeyboardController.h"
|
||||
#include <SDL.h>
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
void SdlKeyboardController::poll() {
|
||||
auto state = SDL_GetKeyboardState(nullptr);
|
||||
|
||||
@ -7,16 +7,16 @@
|
||||
namespace nes {
|
||||
|
||||
SdlWindow::SdlWindow(uint16_t width, uint16_t height): _width(width), _height(height) {
|
||||
int res = SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER);
|
||||
int res = SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_GAMEPAD);
|
||||
if(res < 0) throw std::runtime_error("Error initializing SDL");
|
||||
|
||||
Uint32 flags = SDL_WINDOW_ALLOW_HIGHDPI; //| SDL_WINDOW_VULKAN | SDL_WINDOW_METAL;
|
||||
_wnd.reset(SDL_CreateWindow("NES", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, flags));
|
||||
Uint32 flags = SDL_WINDOW_HIGH_PIXEL_DENSITY; //| SDL_WINDOW_VULKAN | SDL_WINDOW_METAL;
|
||||
_wnd.reset(SDL_CreateWindow("NES", width, height, flags));
|
||||
if(!_wnd) throw std::runtime_error("Error creating SDL window");
|
||||
|
||||
SDL_SetWindowResizable(_wnd.get(), SDL_TRUE);
|
||||
SDL_SetWindowResizable(_wnd.get(), true);
|
||||
|
||||
_renderer.reset(SDL_CreateRenderer(_wnd.get(), -1, 0));
|
||||
_renderer.reset(SDL_CreateRenderer(_wnd.get(), nullptr));
|
||||
if(!_renderer) throw std::runtime_error("Error creating SDL renderer");
|
||||
|
||||
_texture.reset(SDL_CreateTexture(_renderer.get(), SDL_PIXELFORMAT_ABGR8888, SDL_TEXTUREACCESS_STREAMING, width, height));
|
||||
@ -27,7 +27,7 @@ namespace nes {
|
||||
int pitch = static_cast<int>(_width*sizeof(Pixel));
|
||||
SDL_UpdateTexture(_texture.get(), nullptr, buffer, pitch);
|
||||
SDL_RenderClear(_renderer.get());
|
||||
SDL_RenderCopy(_renderer.get(), _texture.get(), nullptr, nullptr);
|
||||
SDL_RenderTexture(_renderer.get(), _texture.get(), nullptr, nullptr);
|
||||
SDL_RenderPresent(_renderer.get());
|
||||
}
|
||||
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
|
||||
#include "../../src/Ppu.h"
|
||||
|
||||
#include <SDL.h>
|
||||
#include <SDL3/SDL.h>
|
||||
#include <memory>
|
||||
|
||||
namespace nes {
|
||||
|
||||
@ -21,9 +21,9 @@ int main() {
|
||||
frameRendered = true;
|
||||
});
|
||||
device.connect(std::make_shared<SdlKeyboardController>());
|
||||
//device.insertCartridge("/home/selim/Downloads/dk.nes");
|
||||
device.insertCartridge("/Users/selim/Documents/nes/ppu_tests/power_up_palette.nes");
|
||||
device.insertCartridge("/Users/selim/Documents/nes/ff.nes");
|
||||
device.insertCartridge("/home/selim/Documents/nes/smb.nes");
|
||||
//device.insertCartridge("/Users/selim/Documents/nes/ppu_tests/power_up_palette.nes");
|
||||
//device.insertCartridge("/Users/selim/Documents/nes/ff.nes");
|
||||
//device.insertCartridge("C:\\Users\\selim\\Documents\\nestest.nes");
|
||||
|
||||
auto frameStart = std::chrono::steady_clock::now();
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <cstddef>
|
||||
#include <cstring>
|
||||
|
||||
namespace nes {
|
||||
|
||||
|
||||
@ -11,6 +11,8 @@ namespace nes {
|
||||
|
||||
class Controller {
|
||||
public:
|
||||
virtual ~Controller() = default;
|
||||
|
||||
enum Key: uint8_t {
|
||||
A = 7,
|
||||
B = 6,
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
#define UTILS_H
|
||||
|
||||
#include <concepts>
|
||||
#include <cstddef>
|
||||
|
||||
namespace nes {
|
||||
|
||||
|
||||
15
vcpkg.json
15
vcpkg.json
@ -1,15 +0,0 @@
|
||||
{
|
||||
"name" : "nes",
|
||||
"version-string" : "1.0.0",
|
||||
"builtin-baseline" : "c95000e1b5bb62884de08d5e952993c8bced9db6",
|
||||
"dependencies": [
|
||||
{
|
||||
"name": "sdl2",
|
||||
"version>=": "2.26.5"
|
||||
},
|
||||
{
|
||||
"name": "fmt",
|
||||
"version>=": "10.0.0"
|
||||
}
|
||||
]
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user