Fix NesKit bindings
This commit is contained in:
parent
3d8b37aff4
commit
ab0e00e390
2
.gitignore
vendored
2
.gitignore
vendored
@ -4,3 +4,5 @@ cmake-build-debug/
|
|||||||
out/
|
out/
|
||||||
build/
|
build/
|
||||||
CMakeLists.txt.user
|
CMakeLists.txt.user
|
||||||
|
**/.DS_Store
|
||||||
|
.swiftpm/
|
||||||
|
|||||||
@ -1,7 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<Workspace
|
|
||||||
version = "1.0">
|
|
||||||
<FileRef
|
|
||||||
location = "self:">
|
|
||||||
</FileRef>
|
|
||||||
</Workspace>
|
|
||||||
Binary file not shown.
@ -1,32 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
||||||
<plist version="1.0">
|
|
||||||
<dict>
|
|
||||||
<key>SchemeUserState</key>
|
|
||||||
<dict>
|
|
||||||
<key>NesKit.xcscheme_^#shared#^_</key>
|
|
||||||
<dict>
|
|
||||||
<key>orderHint</key>
|
|
||||||
<integer>0</integer>
|
|
||||||
</dict>
|
|
||||||
<key>nes-Package.xcscheme_^#shared#^_</key>
|
|
||||||
<dict>
|
|
||||||
<key>orderHint</key>
|
|
||||||
<integer>1</integer>
|
|
||||||
</dict>
|
|
||||||
</dict>
|
|
||||||
<key>SuppressBuildableAutocreation</key>
|
|
||||||
<dict>
|
|
||||||
<key>NesKit</key>
|
|
||||||
<dict>
|
|
||||||
<key>primary</key>
|
|
||||||
<true/>
|
|
||||||
</dict>
|
|
||||||
<key>nes</key>
|
|
||||||
<dict>
|
|
||||||
<key>primary</key>
|
|
||||||
<true/>
|
|
||||||
</dict>
|
|
||||||
</dict>
|
|
||||||
</dict>
|
|
||||||
</plist>
|
|
||||||
@ -25,15 +25,35 @@
|
|||||||
_system = std::make_unique<nes::System>();
|
_system = std::make_unique<nes::System>();
|
||||||
_condition = [NSCondition new];
|
_condition = [NSCondition new];
|
||||||
_runEmulation = YES;
|
_runEmulation = YES;
|
||||||
|
}
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
size_t frameBufferSize = nes::Ppu::SCREEN_WIDTH * nes::Ppu::SCREEN_HEIGHT * sizeof(nes::Pixel);
|
- (void)runRom:(NSURL*)url {
|
||||||
|
_system->insertCartridge([url fileSystemRepresentation]);
|
||||||
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||||
|
while(TRUE) {
|
||||||
|
[_condition lock];
|
||||||
|
while (!_runEmulation) {
|
||||||
|
[_condition wait];
|
||||||
|
}
|
||||||
|
|
||||||
_system->setNewFrameCallback([frameBufferSize, self](auto frameBuffer) {
|
while(_runEmulation) {
|
||||||
|
auto frameBuffer = _system->tick();
|
||||||
|
if(frameBuffer) {
|
||||||
_runEmulation = NO;
|
_runEmulation = NO;
|
||||||
|
[self generateFrame:frameBuffer];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CGImageRelease(_frame);
|
[_condition unlock];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
CGDataProviderRef dataProvider = CGDataProviderCreateWithData(NULL, (void*)frameBuffer, frameBufferSize, NULL);
|
- (void)generateFrame:(const nes::Pixel*)buffer {
|
||||||
|
size_t frameBufferSize = nes::Ppu::SCREEN_WIDTH * nes::Ppu::SCREEN_HEIGHT * sizeof(nes::Pixel);
|
||||||
|
CGDataProviderRef dataProvider = CGDataProviderCreateWithData(NULL, (void*)buffer, frameBufferSize, NULL);
|
||||||
CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
|
CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
|
||||||
CGImageRef image = CGImageCreate(nes::Ppu::SCREEN_WIDTH,
|
CGImageRef image = CGImageCreate(nes::Ppu::SCREEN_WIDTH,
|
||||||
nes::Ppu::SCREEN_HEIGHT,
|
nes::Ppu::SCREEN_HEIGHT,
|
||||||
@ -50,29 +70,9 @@
|
|||||||
CGColorSpaceRelease(colorspace);
|
CGColorSpaceRelease(colorspace);
|
||||||
|
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
CGImageRelease(_frame);
|
||||||
_frame = image;
|
_frame = image;
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)runRom:(NSURL*)url {
|
|
||||||
_system->insertCartridge([url fileSystemRepresentation]);
|
|
||||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
|
||||||
while(TRUE) {
|
|
||||||
[_condition lock];
|
|
||||||
while (!_runEmulation) {
|
|
||||||
[_condition wait];
|
|
||||||
}
|
|
||||||
|
|
||||||
while(_runEmulation) {
|
|
||||||
_system->tick();
|
|
||||||
}
|
|
||||||
|
|
||||||
[_condition unlock];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)stepToNextFrame {
|
- (void)stepToNextFrame {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user