2015-07-16 23:56:02 +00:00
|
|
|
//
|
|
|
|
// Atari2600.cpp
|
2015-07-26 19:25:11 +00:00
|
|
|
// CLK
|
2015-07-16 23:56:02 +00:00
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 14/07/2015.
|
|
|
|
// Copyright © 2015 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "Atari2600.hpp"
|
|
|
|
#include <algorithm>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
using namespace Atari2600;
|
2016-05-16 12:01:29 +00:00
|
|
|
namespace {
|
2016-08-14 17:33:20 +00:00
|
|
|
static const double NTSC_clock_rate = 1194720;
|
|
|
|
static const double PAL_clock_rate = 1182298;
|
2016-05-16 12:01:29 +00:00
|
|
|
}
|
2015-07-16 23:56:02 +00:00
|
|
|
|
2015-12-06 21:53:37 +00:00
|
|
|
Machine::Machine() :
|
2016-12-03 19:07:38 +00:00
|
|
|
rom_(nullptr),
|
2017-01-29 02:46:40 +00:00
|
|
|
rom_pages_{nullptr, nullptr, nullptr, nullptr},
|
2016-12-03 19:07:38 +00:00
|
|
|
tia_input_value_{0xff, 0xff},
|
|
|
|
cycles_since_speaker_update_(0),
|
2017-02-20 02:20:37 +00:00
|
|
|
cycles_since_video_update_(0),
|
2017-03-04 19:58:28 +00:00
|
|
|
cycles_since_6532_update_(0),
|
2017-02-20 02:20:37 +00:00
|
|
|
frame_record_pointer_(0),
|
|
|
|
is_ntsc_(true)
|
2016-04-24 10:56:08 +00:00
|
|
|
{
|
2016-08-14 17:33:20 +00:00
|
|
|
set_clock_rate(NTSC_clock_rate);
|
2016-04-24 10:56:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Machine::setup_output(float aspect_ratio)
|
2015-07-16 23:56:02 +00:00
|
|
|
{
|
2017-01-29 02:46:40 +00:00
|
|
|
tia_.reset(new TIA);
|
2016-12-03 19:07:38 +00:00
|
|
|
speaker_.reset(new Speaker);
|
2017-01-29 19:19:26 +00:00
|
|
|
speaker_->set_input_rate((float)(get_clock_rate() / 38.0));
|
2017-02-20 02:20:37 +00:00
|
|
|
tia_->get_crt()->set_delegate(this);
|
2016-05-12 01:07:18 +00:00
|
|
|
}
|
|
|
|
|
2016-04-25 00:34:25 +00:00
|
|
|
void Machine::close_output()
|
|
|
|
{
|
2017-01-29 02:46:40 +00:00
|
|
|
tia_ = nullptr;
|
|
|
|
speaker_ = nullptr;
|
2016-04-25 00:34:25 +00:00
|
|
|
}
|
|
|
|
|
2015-07-28 01:15:10 +00:00
|
|
|
Machine::~Machine()
|
|
|
|
{
|
2016-12-03 19:07:38 +00:00
|
|
|
delete[] rom_;
|
2016-04-25 00:34:25 +00:00
|
|
|
close_output();
|
2015-07-28 01:15:10 +00:00
|
|
|
}
|
|
|
|
|
2015-08-16 20:08:29 +00:00
|
|
|
unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uint16_t address, uint8_t *value)
|
2015-07-19 20:48:14 +00:00
|
|
|
{
|
|
|
|
uint8_t returnValue = 0xff;
|
2016-05-28 01:51:27 +00:00
|
|
|
unsigned int cycles_run_for = 3;
|
2015-08-10 14:09:40 +00:00
|
|
|
|
2016-05-16 23:55:56 +00:00
|
|
|
// this occurs as a feedback loop — the 2600 requests ready, then performs the cycles_run_for
|
|
|
|
// leap to the end of ready only once ready is signalled — because on a 6502 ready doesn't take
|
|
|
|
// effect until the next read; therefore it isn't safe to assume that signalling ready immediately
|
|
|
|
// skips to the end of the line.
|
2017-02-08 03:14:45 +00:00
|
|
|
if(operation == CPU6502::BusOperation::Ready)
|
2017-01-29 02:46:40 +00:00
|
|
|
cycles_run_for = (unsigned int)tia_->get_cycles_until_horizontal_blank(cycles_since_video_update_);
|
2015-07-16 23:56:02 +00:00
|
|
|
|
2016-12-03 19:07:38 +00:00
|
|
|
cycles_since_speaker_update_ += cycles_run_for;
|
2017-01-29 02:46:40 +00:00
|
|
|
cycles_since_video_update_ += cycles_run_for;
|
2017-03-04 22:00:28 +00:00
|
|
|
cycles_since_6532_update_ += (cycles_run_for / 3);
|
2016-05-16 23:55:56 +00:00
|
|
|
|
2015-07-31 20:54:20 +00:00
|
|
|
if(operation != CPU6502::BusOperation::Ready) {
|
2017-03-11 17:43:12 +00:00
|
|
|
uint16_t masked_address = address & 0x1fff;
|
2015-08-09 06:42:01 +00:00
|
|
|
|
2017-03-11 17:43:12 +00:00
|
|
|
// check for potential paging
|
|
|
|
switch(paging_model_) {
|
|
|
|
default:
|
|
|
|
// check for an Atari paging access
|
|
|
|
if(rom_size_ > 4096 && ((address & 0x1f00) == 0x1f00)) {
|
|
|
|
uint8_t *base_ptr = rom_pages_[0];
|
|
|
|
uint8_t first_paging_register = (uint8_t)(0xf8 - (rom_size_ >> 14)*2);
|
|
|
|
|
|
|
|
const uint8_t paging_register = address&0xff;
|
|
|
|
if(paging_register >= first_paging_register) {
|
|
|
|
const uint16_t selected_page = paging_register - first_paging_register;
|
|
|
|
if(selected_page * 4096 < rom_size_) {
|
|
|
|
base_ptr = &rom_[selected_page * 4096];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(base_ptr != rom_pages_[0]) {
|
|
|
|
rom_pages_[0] = base_ptr;
|
|
|
|
rom_pages_[1] = base_ptr + 1024;
|
|
|
|
rom_pages_[2] = base_ptr + 2048;
|
|
|
|
rom_pages_[3] = base_ptr + 3072;
|
|
|
|
}
|
2015-08-13 12:24:02 +00:00
|
|
|
}
|
2017-03-11 17:43:12 +00:00
|
|
|
break;
|
|
|
|
case StaticAnalyser::Atari2600PagingModel::ParkerBros:
|
2017-03-11 18:04:23 +00:00
|
|
|
if(masked_address >= 0x1fe0 && masked_address < 0x1ff8) {
|
|
|
|
int slot = (masked_address >> 3) & 3;
|
2017-03-11 17:43:12 +00:00
|
|
|
int target = masked_address & 7;
|
|
|
|
rom_pages_[slot] = &rom_[target * 1024];
|
|
|
|
}
|
|
|
|
break;
|
2015-08-13 14:04:30 +00:00
|
|
|
}
|
2015-08-13 12:24:02 +00:00
|
|
|
|
2015-08-13 14:04:30 +00:00
|
|
|
// check for a ROM read
|
2017-02-26 22:47:29 +00:00
|
|
|
if(address&0x1000)
|
|
|
|
{
|
2017-02-28 01:50:59 +00:00
|
|
|
// check for a RAM access
|
|
|
|
bool was_ram_access = false;
|
|
|
|
if(has_ram_) {
|
|
|
|
if(masked_address >= ram_write_start_ && masked_address < ram_.size() + ram_write_start_) {
|
|
|
|
ram_[masked_address & ram_.size() - 1] = *value;
|
|
|
|
was_ram_access = true;
|
|
|
|
} else if(masked_address >= ram_read_start_ && masked_address < ram_.size() + ram_read_start_) {
|
|
|
|
returnValue &= ram_[masked_address & ram_.size() - 1];
|
|
|
|
was_ram_access = true;
|
|
|
|
}
|
2017-02-26 22:47:29 +00:00
|
|
|
}
|
|
|
|
|
2017-02-28 01:50:59 +00:00
|
|
|
if(isReadOperation(operation) && !was_ram_access) {
|
|
|
|
returnValue &= rom_pages_[(address >> 10)&3][address&1023];
|
2017-02-26 22:47:29 +00:00
|
|
|
}
|
2015-07-31 20:54:20 +00:00
|
|
|
}
|
2015-07-16 23:56:02 +00:00
|
|
|
|
2015-07-31 20:54:20 +00:00
|
|
|
// check for a RAM access
|
2016-04-25 02:32:24 +00:00
|
|
|
if((address&0x1280) == 0x80) {
|
2015-07-31 20:54:20 +00:00
|
|
|
if(isReadOperation(operation)) {
|
2016-12-03 19:07:38 +00:00
|
|
|
returnValue &= mos6532_.get_ram(address);
|
2015-07-31 20:54:20 +00:00
|
|
|
} else {
|
2016-12-03 19:07:38 +00:00
|
|
|
mos6532_.set_ram(address, *value);
|
2015-07-31 20:54:20 +00:00
|
|
|
}
|
2015-07-16 23:56:02 +00:00
|
|
|
}
|
|
|
|
|
2015-07-31 20:54:20 +00:00
|
|
|
// check for a TIA access
|
2016-04-25 02:32:24 +00:00
|
|
|
if(!(address&0x1080)) {
|
2015-07-31 20:54:20 +00:00
|
|
|
if(isReadOperation(operation)) {
|
2015-08-12 23:31:57 +00:00
|
|
|
const uint16_t decodedAddress = address & 0xf;
|
|
|
|
switch(decodedAddress) {
|
|
|
|
case 0x00: // missile 0 / player collisions
|
|
|
|
case 0x01: // missile 1 / player collisions
|
|
|
|
case 0x02: // player 0 / playfield / ball collisions
|
|
|
|
case 0x03: // player 1 / playfield / ball collisions
|
|
|
|
case 0x04: // missile 0 / playfield / ball collisions
|
|
|
|
case 0x05: // missile 1 / playfield / ball collisions
|
|
|
|
case 0x06: // ball / playfield collisions
|
|
|
|
case 0x07: // player / player, missile / missile collisions
|
2017-01-29 02:46:40 +00:00
|
|
|
returnValue &= tia_->get_collision_flags(decodedAddress);
|
2015-08-12 23:31:57 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x08:
|
|
|
|
case 0x09:
|
|
|
|
case 0x0a:
|
|
|
|
case 0x0b:
|
|
|
|
// TODO: pot ports
|
2017-02-26 03:58:58 +00:00
|
|
|
returnValue &= 0;
|
2015-08-12 23:31:57 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x0c:
|
|
|
|
case 0x0d:
|
2016-12-03 19:07:38 +00:00
|
|
|
returnValue &= tia_input_value_[decodedAddress - 0x0c];
|
2015-08-12 23:31:57 +00:00
|
|
|
break;
|
2015-07-31 20:54:20 +00:00
|
|
|
}
|
|
|
|
} else {
|
2015-08-10 15:55:16 +00:00
|
|
|
const uint16_t decodedAddress = address & 0x3f;
|
2015-08-10 15:43:45 +00:00
|
|
|
switch(decodedAddress) {
|
2017-02-24 02:08:32 +00:00
|
|
|
case 0x00: update_video(); tia_->set_sync(*value & 0x02); break;
|
|
|
|
case 0x01: update_video(); tia_->set_blank(*value & 0x02); break;
|
2015-07-31 20:54:20 +00:00
|
|
|
|
2017-02-24 02:08:32 +00:00
|
|
|
case 0x02: set_ready_line(true); break;
|
|
|
|
case 0x03: update_video(); tia_->reset_horizontal_counter(); break;
|
2016-06-01 23:27:04 +00:00
|
|
|
// TODO: audio will now be out of synchronisation — fix
|
2015-07-31 20:54:20 +00:00
|
|
|
|
2015-08-12 23:31:57 +00:00
|
|
|
case 0x04:
|
2017-01-29 02:46:40 +00:00
|
|
|
case 0x05: update_video(); tia_->set_player_number_and_size(decodedAddress - 0x04, *value); break;
|
2015-08-12 23:31:57 +00:00
|
|
|
case 0x06:
|
2017-01-29 02:46:40 +00:00
|
|
|
case 0x07: update_video(); tia_->set_player_missile_colour(decodedAddress - 0x06, *value); break;
|
|
|
|
case 0x08: update_video(); tia_->set_playfield_ball_colour(*value); break;
|
|
|
|
case 0x09: update_video(); tia_->set_background_colour(*value); break;
|
|
|
|
case 0x0a: update_video(); tia_->set_playfield_control_and_ball_size(*value); break;
|
2015-08-12 23:31:57 +00:00
|
|
|
case 0x0b:
|
2017-01-29 02:46:40 +00:00
|
|
|
case 0x0c: update_video(); tia_->set_player_reflected(decodedAddress - 0x0b, !((*value)&8)); break;
|
2015-08-12 23:31:57 +00:00
|
|
|
case 0x0d:
|
|
|
|
case 0x0e:
|
2017-01-29 02:46:40 +00:00
|
|
|
case 0x0f: update_video(); tia_->set_playfield(decodedAddress - 0x0d, *value); break;
|
|
|
|
case 0x10:
|
|
|
|
case 0x11: update_video(); tia_->set_player_position(decodedAddress - 0x10); break;
|
|
|
|
case 0x12:
|
2017-02-22 03:04:27 +00:00
|
|
|
case 0x13: update_video(); tia_->set_missile_position(decodedAddress - 0x12); break;
|
2017-01-29 02:46:40 +00:00
|
|
|
case 0x14: update_video(); tia_->set_ball_position(); break;
|
|
|
|
case 0x1b:
|
|
|
|
case 0x1c: update_video(); tia_->set_player_graphic(decodedAddress - 0x1b, *value); break;
|
2016-05-26 01:43:19 +00:00
|
|
|
case 0x1d:
|
2017-02-12 23:18:35 +00:00
|
|
|
case 0x1e: update_video(); tia_->set_missile_enable(decodedAddress - 0x1d, (*value)&2); break;
|
|
|
|
case 0x1f: update_video(); tia_->set_ball_enable((*value)&2); break;
|
2015-08-12 23:31:57 +00:00
|
|
|
case 0x20:
|
2017-01-29 02:46:40 +00:00
|
|
|
case 0x21: update_video(); tia_->set_player_motion(decodedAddress - 0x20, *value); break;
|
2015-08-12 23:31:57 +00:00
|
|
|
case 0x22:
|
2017-01-29 02:46:40 +00:00
|
|
|
case 0x23: update_video(); tia_->set_missile_motion(decodedAddress - 0x22, *value); break;
|
|
|
|
case 0x24: update_video(); tia_->set_ball_motion(*value); break;
|
|
|
|
case 0x25:
|
2017-02-12 23:18:35 +00:00
|
|
|
case 0x26: tia_->set_player_delay(decodedAddress - 0x25, (*value)&1); break;
|
|
|
|
case 0x27: tia_->set_ball_delay((*value)&1); break;
|
2015-08-10 15:43:45 +00:00
|
|
|
case 0x28:
|
2017-02-21 12:58:37 +00:00
|
|
|
case 0x29: update_video(); tia_->set_missile_position_to_player(decodedAddress - 0x28, (*value)&2); break;
|
2017-01-29 02:46:40 +00:00
|
|
|
case 0x2a: update_video(); tia_->move(); break;
|
|
|
|
case 0x2b: update_video(); tia_->clear_motion(); break;
|
|
|
|
case 0x2c: update_video(); tia_->clear_collision_flags(); break;
|
|
|
|
|
|
|
|
case 0x15:
|
|
|
|
case 0x16: update_audio(); speaker_->set_control(decodedAddress - 0x15, *value); break;
|
|
|
|
case 0x17:
|
|
|
|
case 0x18: update_audio(); speaker_->set_divider(decodedAddress - 0x17, *value); break;
|
|
|
|
case 0x19:
|
|
|
|
case 0x1a: update_audio(); speaker_->set_volume(decodedAddress - 0x19, *value); break;
|
2017-03-11 22:44:35 +00:00
|
|
|
|
|
|
|
case 0x3f:
|
|
|
|
if(paging_model_ == StaticAnalyser::Atari2600PagingModel::Tigervision && (masked_address == 0x3f))
|
|
|
|
{
|
|
|
|
int selected_page = (*value) % (rom_size_ / 2048);
|
|
|
|
rom_pages_[0] = &rom_[selected_page * 2048];
|
2017-03-11 23:16:29 +00:00
|
|
|
rom_pages_[1] = rom_pages_[0] + 1024;
|
2017-03-11 22:44:35 +00:00
|
|
|
}
|
|
|
|
break;
|
2015-07-31 20:54:20 +00:00
|
|
|
}
|
2015-07-16 23:56:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-31 20:54:20 +00:00
|
|
|
// check for a PIA access
|
2016-04-25 02:32:24 +00:00
|
|
|
if((address&0x1280) == 0x280) {
|
2017-03-04 19:58:28 +00:00
|
|
|
update_6532();
|
2015-07-31 20:54:20 +00:00
|
|
|
if(isReadOperation(operation)) {
|
2016-12-03 19:07:38 +00:00
|
|
|
returnValue &= mos6532_.get_register(address);
|
2015-07-31 20:54:20 +00:00
|
|
|
} else {
|
2016-12-03 19:07:38 +00:00
|
|
|
mos6532_.set_register(address, *value);
|
2015-07-16 23:56:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-31 20:54:20 +00:00
|
|
|
if(isReadOperation(operation)) {
|
|
|
|
*value = returnValue;
|
|
|
|
}
|
2015-07-16 23:56:02 +00:00
|
|
|
}
|
|
|
|
|
2017-02-24 02:08:32 +00:00
|
|
|
if(!tia_->get_cycles_until_horizontal_blank(cycles_since_video_update_)) set_ready_line(false);
|
2016-06-03 00:15:48 +00:00
|
|
|
|
2016-05-28 01:51:27 +00:00
|
|
|
return cycles_run_for / 3;
|
2015-07-16 23:56:02 +00:00
|
|
|
}
|
|
|
|
|
2015-08-19 00:33:24 +00:00
|
|
|
void Machine::set_digital_input(Atari2600DigitalInput input, bool state)
|
|
|
|
{
|
|
|
|
switch (input) {
|
2016-12-03 19:07:38 +00:00
|
|
|
case Atari2600DigitalInputJoy1Up: mos6532_.update_port_input(0, 0x10, state); break;
|
|
|
|
case Atari2600DigitalInputJoy1Down: mos6532_.update_port_input(0, 0x20, state); break;
|
|
|
|
case Atari2600DigitalInputJoy1Left: mos6532_.update_port_input(0, 0x40, state); break;
|
|
|
|
case Atari2600DigitalInputJoy1Right: mos6532_.update_port_input(0, 0x80, state); break;
|
2016-06-19 22:57:40 +00:00
|
|
|
|
2016-12-03 19:07:38 +00:00
|
|
|
case Atari2600DigitalInputJoy2Up: mos6532_.update_port_input(0, 0x01, state); break;
|
|
|
|
case Atari2600DigitalInputJoy2Down: mos6532_.update_port_input(0, 0x02, state); break;
|
|
|
|
case Atari2600DigitalInputJoy2Left: mos6532_.update_port_input(0, 0x04, state); break;
|
|
|
|
case Atari2600DigitalInputJoy2Right: mos6532_.update_port_input(0, 0x08, state); break;
|
2015-08-19 00:58:05 +00:00
|
|
|
|
|
|
|
// TODO: latching
|
2016-12-03 19:07:38 +00:00
|
|
|
case Atari2600DigitalInputJoy1Fire: if(state) tia_input_value_[0] &= ~0x80; else tia_input_value_[0] |= 0x80; break;
|
|
|
|
case Atari2600DigitalInputJoy2Fire: if(state) tia_input_value_[1] &= ~0x80; else tia_input_value_[1] |= 0x80; break;
|
2015-08-19 00:33:24 +00:00
|
|
|
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-19 23:36:34 +00:00
|
|
|
void Machine::set_switch_is_enabled(Atari2600Switch input, bool state)
|
|
|
|
{
|
|
|
|
switch(input) {
|
2016-12-03 19:07:38 +00:00
|
|
|
case Atari2600SwitchReset: mos6532_.update_port_input(1, 0x01, state); break;
|
|
|
|
case Atari2600SwitchSelect: mos6532_.update_port_input(1, 0x02, state); break;
|
|
|
|
case Atari2600SwitchColour: mos6532_.update_port_input(1, 0x08, state); break;
|
|
|
|
case Atari2600SwitchLeftPlayerDifficulty: mos6532_.update_port_input(1, 0x40, state); break;
|
|
|
|
case Atari2600SwitchRightPlayerDifficulty: mos6532_.update_port_input(1, 0x80, state); break;
|
2016-06-19 23:36:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-15 23:34:45 +00:00
|
|
|
void Machine::configure_as_target(const StaticAnalyser::Target &target)
|
2015-07-16 23:56:02 +00:00
|
|
|
{
|
2016-09-15 23:34:45 +00:00
|
|
|
if(!target.cartridges.front()->get_segments().size()) return;
|
|
|
|
Storage::Cartridge::Cartridge::Segment segment = target.cartridges.front()->get_segments().front();
|
|
|
|
size_t length = segment.data.size();
|
|
|
|
|
2016-12-03 19:07:38 +00:00
|
|
|
rom_size_ = 1024;
|
|
|
|
while(rom_size_ < length && rom_size_ < 32768) rom_size_ <<= 1;
|
2015-08-13 12:24:02 +00:00
|
|
|
|
2016-12-03 19:07:38 +00:00
|
|
|
delete[] rom_;
|
|
|
|
rom_ = new uint8_t[rom_size_];
|
2015-08-17 04:34:01 +00:00
|
|
|
|
|
|
|
size_t offset = 0;
|
2016-12-03 19:07:38 +00:00
|
|
|
const size_t copy_step = std::min(rom_size_, length);
|
|
|
|
while(offset < rom_size_)
|
2015-08-17 04:34:01 +00:00
|
|
|
{
|
2016-12-03 19:07:38 +00:00
|
|
|
size_t copy_length = std::min(copy_step, rom_size_ - offset);
|
|
|
|
memcpy(&rom_[offset], &segment.data[0], copy_length);
|
2015-08-17 04:34:01 +00:00
|
|
|
offset += copy_length;
|
|
|
|
}
|
2015-08-13 12:24:02 +00:00
|
|
|
|
2017-03-01 12:59:25 +00:00
|
|
|
// On a real paged cartridge, any page may initially be visible. Various homebrew authors appear to have
|
|
|
|
// decided the last page will always be initially visible. So do that.
|
2017-03-11 18:04:23 +00:00
|
|
|
size_t rom_mask = rom_size_ - 1;
|
2017-03-01 12:59:25 +00:00
|
|
|
uint8_t *rom_base = rom_;
|
|
|
|
if(rom_size_ > 4096) rom_base = &rom_[rom_size_ - 4096];
|
|
|
|
rom_pages_[0] = rom_base;
|
2017-03-11 18:04:23 +00:00
|
|
|
rom_pages_[1] = &rom_base[1024 & rom_mask];
|
|
|
|
rom_pages_[2] = &rom_base[2048 & rom_mask];
|
|
|
|
rom_pages_[3] = &rom_base[3072 & rom_mask];
|
2017-02-26 22:47:29 +00:00
|
|
|
|
2017-02-28 01:50:59 +00:00
|
|
|
switch(target.atari.paging_model)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
if(target.atari.uses_superchip)
|
|
|
|
{
|
|
|
|
ram_.resize(128);
|
|
|
|
has_ram_ = true;
|
|
|
|
ram_write_start_ = 0x1000;
|
|
|
|
ram_read_start_ = 0x1080;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case StaticAnalyser::Atari2600PagingModel::CommaVid:
|
|
|
|
ram_.resize(1024);
|
|
|
|
has_ram_ = true;
|
|
|
|
ram_write_start_ = 0x1400;
|
|
|
|
ram_read_start_ = 0x1000;
|
|
|
|
break;
|
|
|
|
}
|
2017-03-11 17:43:12 +00:00
|
|
|
|
|
|
|
paging_model_ = target.atari.paging_model;
|
2015-07-16 23:56:02 +00:00
|
|
|
}
|
2016-06-01 23:27:04 +00:00
|
|
|
|
2017-01-29 02:46:40 +00:00
|
|
|
#pragma mark - Audio and Video
|
2016-06-01 23:27:04 +00:00
|
|
|
|
|
|
|
void Machine::update_audio()
|
|
|
|
{
|
2016-12-03 19:07:38 +00:00
|
|
|
unsigned int audio_cycles = cycles_since_speaker_update_ / 114;
|
|
|
|
|
|
|
|
speaker_->run_for_cycles(audio_cycles);
|
|
|
|
cycles_since_speaker_update_ %= 114;
|
2016-06-01 23:27:04 +00:00
|
|
|
}
|
|
|
|
|
2017-01-29 02:46:40 +00:00
|
|
|
void Machine::update_video()
|
|
|
|
{
|
|
|
|
tia_->run_for_cycles((int)cycles_since_video_update_);
|
|
|
|
cycles_since_video_update_ = 0;
|
|
|
|
}
|
|
|
|
|
2017-03-04 19:58:28 +00:00
|
|
|
void Machine::update_6532()
|
|
|
|
{
|
|
|
|
mos6532_.run_for_cycles(cycles_since_6532_update_);
|
|
|
|
cycles_since_6532_update_ = 0;
|
|
|
|
}
|
|
|
|
|
2016-06-01 23:27:04 +00:00
|
|
|
void Machine::synchronise()
|
|
|
|
{
|
|
|
|
update_audio();
|
2017-01-29 02:46:40 +00:00
|
|
|
update_video();
|
2017-01-26 02:29:19 +00:00
|
|
|
speaker_->flush();
|
2016-06-01 23:27:04 +00:00
|
|
|
}
|
2017-02-20 02:20:37 +00:00
|
|
|
|
|
|
|
#pragma mark - CRT delegate
|
|
|
|
|
|
|
|
void Machine::crt_did_end_batch_of_frames(Outputs::CRT::CRT *crt, unsigned int number_of_frames, unsigned int number_of_unexpected_vertical_syncs)
|
|
|
|
{
|
|
|
|
const size_t number_of_frame_records = sizeof(frame_records_) / sizeof(frame_records_[0]);
|
2017-03-07 00:37:35 +00:00
|
|
|
frame_records_[frame_record_pointer_ % number_of_frame_records].number_of_frames = number_of_frames;
|
|
|
|
frame_records_[frame_record_pointer_ % number_of_frame_records].number_of_unexpected_vertical_syncs = number_of_unexpected_vertical_syncs;
|
|
|
|
frame_record_pointer_ ++;
|
2017-02-20 02:20:37 +00:00
|
|
|
|
2017-03-07 00:37:35 +00:00
|
|
|
if(frame_record_pointer_ >= 6)
|
2017-02-20 02:20:37 +00:00
|
|
|
{
|
2017-03-07 00:37:35 +00:00
|
|
|
unsigned int total_number_of_frames = 0;
|
|
|
|
unsigned int total_number_of_unexpected_vertical_syncs = 0;
|
2017-02-20 02:20:37 +00:00
|
|
|
for(size_t c = 0; c < number_of_frame_records; c++)
|
|
|
|
{
|
2017-03-07 00:37:35 +00:00
|
|
|
total_number_of_frames += frame_records_[c].number_of_frames;
|
|
|
|
total_number_of_unexpected_vertical_syncs += frame_records_[c].number_of_unexpected_vertical_syncs;
|
2017-02-20 02:20:37 +00:00
|
|
|
}
|
|
|
|
|
2017-03-07 00:37:35 +00:00
|
|
|
if(total_number_of_unexpected_vertical_syncs >= total_number_of_frames >> 1)
|
2017-02-20 02:20:37 +00:00
|
|
|
{
|
2017-03-07 00:37:35 +00:00
|
|
|
for(size_t c = 0; c < number_of_frame_records; c++)
|
|
|
|
{
|
|
|
|
frame_records_[c].number_of_frames = 0;
|
|
|
|
frame_records_[c].number_of_unexpected_vertical_syncs = 0;
|
|
|
|
}
|
|
|
|
is_ntsc_ ^= true;
|
2017-02-20 02:20:37 +00:00
|
|
|
|
2017-03-07 00:37:35 +00:00
|
|
|
double clock_rate;
|
|
|
|
if(is_ntsc_)
|
|
|
|
{
|
|
|
|
clock_rate = NTSC_clock_rate;
|
|
|
|
tia_->set_output_mode(TIA::OutputMode::NTSC);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
clock_rate = PAL_clock_rate;
|
|
|
|
tia_->set_output_mode(TIA::OutputMode::PAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
speaker_->set_input_rate((float)(clock_rate / 38.0));
|
|
|
|
speaker_->set_high_frequency_cut_off((float)(clock_rate / (38.0 * 2.0)));
|
|
|
|
set_clock_rate(clock_rate);
|
|
|
|
}
|
2017-02-20 02:20:37 +00:00
|
|
|
}
|
|
|
|
}
|