Fixed CHR RAM write
This commit is contained in:
parent
f114104e8e
commit
a8b58c8a1b
23
NesKitSwift/NesSystemSwift.swift
Normal file
23
NesKitSwift/NesSystemSwift.swift
Normal file
@ -0,0 +1,23 @@
|
||||
//
|
||||
// NesSystemSwift.swift
|
||||
// NesKit
|
||||
//
|
||||
// Created by Selim Mustafaev on 08.08.2025.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import NesKitCpp
|
||||
|
||||
class NesSystemSwift {
|
||||
|
||||
var nesSystem: nes.System?
|
||||
|
||||
init() {
|
||||
|
||||
let frameBufferSize = nes.Ppu.SCREEN_WIDTH * nes.Ppu.SCREEN_HEIGHT * MemoryLayout<nes.Pixel>.stride
|
||||
|
||||
nesSystem?.setNewFrameCallback({ frameBuffer in
|
||||
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
// swift-tools-version: 5.8
|
||||
// swift-tools-version: 6.1
|
||||
// The swift-tools-version declares the minimum version of Swift required to build this package.
|
||||
|
||||
import PackageDescription
|
||||
@ -6,21 +6,32 @@ import PackageDescription
|
||||
let package = Package(
|
||||
name: "NesKit",
|
||||
platforms: [
|
||||
.macOS(.v13),
|
||||
.iOS(.v16)
|
||||
.macOS(.v15),
|
||||
.iOS(.v18)
|
||||
],
|
||||
products: [
|
||||
.library(name: "NesKit", targets: ["NesKit"]),
|
||||
.library(name: "NesKitSwift", targets: ["NesKitSwift"])
|
||||
],
|
||||
targets: [
|
||||
// Targets are the basic building blocks of a package, defining a module or a test suite.
|
||||
// Targets can depend on other targets in this package and products from dependencies.
|
||||
.target(name: "NesKitCpp",
|
||||
.target(
|
||||
name: "NesKitCpp",
|
||||
path: "src",
|
||||
exclude: ["Logger.cpp", "Logger.h"]),
|
||||
.target(name: "NesKit",
|
||||
exclude: ["Logger.cpp", "Logger.h"]
|
||||
),
|
||||
.target(
|
||||
name: "NesKit",
|
||||
dependencies: [.target(name: "NesKitCpp")],
|
||||
path: "NesKit")
|
||||
path: "NesKit"
|
||||
),
|
||||
.target(
|
||||
name: "NesKitSwift",
|
||||
dependencies: [.target(name: "NesKitCpp")],
|
||||
path: "NesKitSwift",
|
||||
swiftSettings: [.interoperabilityMode(.Cxx)]
|
||||
)
|
||||
],
|
||||
cxxLanguageStandard: .cxx20
|
||||
)
|
||||
|
||||
@ -22,7 +22,8 @@ int main() {
|
||||
});
|
||||
device.connect(std::make_shared<SdlKeyboardController>());
|
||||
//device.insertCartridge("/home/selim/Downloads/dk.nes");
|
||||
device.insertCartridge("/Users/selim/Documents/drm.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();
|
||||
|
||||
@ -5,8 +5,6 @@
|
||||
#include "Bus.h"
|
||||
#include <iostream>
|
||||
|
||||
#include "../../../../../../opt/homebrew/Cellar/fmt/11.2.0/include/fmt/format.h"
|
||||
|
||||
namespace nes {
|
||||
|
||||
Bus::Bus(uint8_t *ram,
|
||||
@ -48,6 +46,10 @@ namespace nes {
|
||||
return _cartridge->readChr(address);
|
||||
}
|
||||
|
||||
void Bus::writeChr(uint16_t address, uint8_t value) const {
|
||||
_cartridge->writeChr(address, value);
|
||||
}
|
||||
|
||||
uint8_t Bus::read(uint16_t address) const {
|
||||
if(address < 0x2000) {
|
||||
return _ram[address & 0x07FF];
|
||||
|
||||
@ -30,6 +30,7 @@ namespace nes {
|
||||
|
||||
[[nodiscard]] Cartridge::Mirroring cartridgeMirroring() const;
|
||||
uint8_t readChr(uint16_t address) const;
|
||||
void writeChr(uint16_t address, uint8_t value) const;
|
||||
|
||||
uint8_t read(uint16_t address) const;
|
||||
void write(uint16_t address, uint8_t value);
|
||||
|
||||
@ -4,12 +4,12 @@
|
||||
|
||||
#include "Ppu.h"
|
||||
|
||||
#include "../../../../../../opt/homebrew/Cellar/fmt/11.2.0/include/fmt/base.h"
|
||||
|
||||
#ifdef NES_LOGGING
|
||||
#include <fmt/format.h>
|
||||
#endif
|
||||
|
||||
#include <print>
|
||||
|
||||
namespace nes {
|
||||
|
||||
Ppu::Ppu(): _column{}, _scanline{}, _status{}, _control{}, _mask{} {
|
||||
@ -230,7 +230,7 @@ namespace nes {
|
||||
_oam->write(value);
|
||||
break;
|
||||
default:
|
||||
fmt::println("unknown ppu write");
|
||||
//fmt::println("unknown ppu write");
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -304,7 +304,7 @@ namespace nes {
|
||||
address &= 0x3FFF;
|
||||
|
||||
if(address < 0x2000) {
|
||||
// Can't write to CHR ROM
|
||||
_bus->writeChr(address, value);
|
||||
}
|
||||
else if(address >= 0x2000 && address < 0x3F00) {
|
||||
address &= 0x0FFF;
|
||||
|
||||
@ -28,8 +28,8 @@ namespace nes {
|
||||
|
||||
class Ppu {
|
||||
public:
|
||||
static constexpr uint16_t SCREEN_WIDTH = 256;
|
||||
static constexpr uint16_t SCREEN_HEIGHT = 240;
|
||||
static const size_t SCREEN_WIDTH = 256;
|
||||
static const size_t SCREEN_HEIGHT = 240;
|
||||
|
||||
enum ControlAddress: uint16_t {
|
||||
Control = 0x0000,
|
||||
|
||||
4
src/include/module.modulemap
Normal file
4
src/include/module.modulemap
Normal file
@ -0,0 +1,4 @@
|
||||
module NesKitCpp {
|
||||
header "NesKitCpp.h"
|
||||
export *
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user