2016-01-05 04:12:47 +00:00
|
|
|
//
|
|
|
|
// Atari2600.m
|
|
|
|
// CLK
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 14/07/2015.
|
|
|
|
// Copyright © 2015 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "CSAtari2600.h"
|
|
|
|
|
|
|
|
#import "Atari2600.hpp"
|
|
|
|
#import "CSMachine+Subclassing.h"
|
|
|
|
|
|
|
|
@implementation CSAtari2600 {
|
|
|
|
Atari2600::Machine _atari2600;
|
|
|
|
|
|
|
|
int _frameCount;
|
|
|
|
int _hitCount;
|
|
|
|
BOOL _didDecideRegion;
|
|
|
|
}
|
|
|
|
|
2016-02-05 03:28:50 +00:00
|
|
|
/*- (void)crt:(Outputs::CRT *)crt didEndFrame:(CRTFrame *)frame didDetectVSync:(BOOL)didDetectVSync {
|
2016-01-05 04:12:47 +00:00
|
|
|
if(!_didDecideRegion)
|
|
|
|
{
|
|
|
|
_frameCount++;
|
|
|
|
_hitCount += didDetectVSync ? 1 : 0;
|
|
|
|
|
|
|
|
if(_frameCount > 30)
|
|
|
|
{
|
|
|
|
if(_hitCount < _frameCount >> 1)
|
|
|
|
{
|
|
|
|
_atari2600.switch_region();
|
|
|
|
_didDecideRegion = YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(_hitCount > (_frameCount * 7) >> 3)
|
|
|
|
{
|
|
|
|
_didDecideRegion = YES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[super crt:crt didEndFrame:frame didDetectVSync:didDetectVSync];
|
2016-02-05 03:28:50 +00:00
|
|
|
}*/
|
2016-01-05 04:12:47 +00:00
|
|
|
|
|
|
|
- (void)doRunForNumberOfCycles:(int)numberOfCycles {
|
|
|
|
_atari2600.run_for_cycles(numberOfCycles);
|
|
|
|
}
|
|
|
|
|
2016-03-08 02:04:04 +00:00
|
|
|
- (void)drawViewForPixelSize:(CGSize)pixelSize onlyIfDirty:(BOOL)onlyIfDirty {
|
|
|
|
_atari2600.get_crt()->draw_frame((unsigned int)pixelSize.width, (unsigned int)pixelSize.height, onlyIfDirty ? true : false);
|
|
|
|
}
|
|
|
|
|
2016-01-05 04:12:47 +00:00
|
|
|
- (void)setROM:(NSData *)rom {
|
|
|
|
_atari2600.set_rom(rom.length, (const uint8_t *)rom.bytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setState:(BOOL)state forDigitalInput:(Atari2600DigitalInput)digitalInput {
|
|
|
|
_atari2600.set_digital_input(digitalInput, state ? true : false);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setResetLineEnabled:(BOOL)enabled {
|
|
|
|
_atari2600.set_reset_line(enabled ? true : false);
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|