2015-07-16 23:56:02 +00:00
|
|
|
//
|
|
|
|
// Atari2600.hpp
|
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.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef Atari2600_cpp
|
|
|
|
#define Atari2600_cpp
|
|
|
|
|
2016-06-19 22:57:40 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
|
2016-01-05 04:12:47 +00:00
|
|
|
#include "../../Processors/6502/CPU6502.hpp"
|
2016-06-01 01:23:44 +00:00
|
|
|
#include "../CRTMachine.hpp"
|
2016-12-03 18:41:55 +00:00
|
|
|
#include "PIA.hpp"
|
2016-12-03 18:39:46 +00:00
|
|
|
#include "Speaker.hpp"
|
2016-06-19 22:57:40 +00:00
|
|
|
|
2016-09-15 23:34:45 +00:00
|
|
|
#include "../ConfigurationTarget.hpp"
|
2015-08-19 00:33:24 +00:00
|
|
|
#include "Atari2600Inputs.h"
|
2015-07-16 23:56:02 +00:00
|
|
|
|
|
|
|
namespace Atari2600 {
|
|
|
|
|
2016-06-03 01:22:55 +00:00
|
|
|
const unsigned int number_of_upcoming_events = 6;
|
2016-05-27 18:33:08 +00:00
|
|
|
const unsigned int number_of_recorded_counters = 7;
|
2016-05-17 11:09:18 +00:00
|
|
|
|
2016-09-15 23:34:45 +00:00
|
|
|
class Machine:
|
|
|
|
public CPU6502::Processor<Machine>,
|
|
|
|
public CRTMachine::Machine,
|
|
|
|
public ConfigurationTarget::Machine {
|
2015-07-16 23:56:02 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
Machine();
|
2015-07-28 01:15:10 +00:00
|
|
|
~Machine();
|
2015-07-16 23:56:02 +00:00
|
|
|
|
2016-09-15 23:34:45 +00:00
|
|
|
void configure_as_target(const StaticAnalyser::Target &target);
|
2015-07-31 22:04:33 +00:00
|
|
|
void switch_region();
|
2015-07-16 23:56:02 +00:00
|
|
|
|
2015-08-19 00:33:24 +00:00
|
|
|
void set_digital_input(Atari2600DigitalInput input, bool state);
|
2016-06-19 23:36:34 +00:00
|
|
|
void set_switch_is_enabled(Atari2600Switch input, bool state);
|
2015-08-19 00:33:24 +00:00
|
|
|
|
2016-06-01 01:23:44 +00:00
|
|
|
// to satisfy CPU6502::Processor
|
|
|
|
unsigned int perform_bus_operation(CPU6502::BusOperation operation, uint16_t address, uint8_t *value);
|
2016-06-01 23:27:04 +00:00
|
|
|
void synchronise();
|
2016-06-01 01:23:44 +00:00
|
|
|
|
|
|
|
// to satisfy CRTMachine::Machine
|
|
|
|
virtual void setup_output(float aspect_ratio);
|
|
|
|
virtual void close_output();
|
2016-12-03 19:07:38 +00:00
|
|
|
virtual std::shared_ptr<Outputs::CRT::CRT> get_crt() { return crt_; }
|
|
|
|
virtual std::shared_ptr<Outputs::Speaker> get_speaker() { return speaker_; }
|
2016-06-01 01:23:44 +00:00
|
|
|
virtual void run_for_cycles(int number_of_cycles) { CPU6502::Processor<Machine>::run_for_cycles(number_of_cycles); }
|
2016-06-17 00:39:46 +00:00
|
|
|
// TODO: different rate for PAL
|
2015-07-22 22:15:18 +00:00
|
|
|
|
2015-07-16 23:56:02 +00:00
|
|
|
private:
|
2016-12-03 19:07:38 +00:00
|
|
|
uint8_t *rom_, *rom_pages_[4];
|
|
|
|
size_t rom_size_;
|
2015-07-16 23:56:02 +00:00
|
|
|
|
2016-06-19 22:57:40 +00:00
|
|
|
// the RIOT
|
2016-12-03 19:07:38 +00:00
|
|
|
PIA mos6532_;
|
2015-07-16 23:56:02 +00:00
|
|
|
|
2015-07-31 00:52:26 +00:00
|
|
|
// playfield registers
|
2016-12-03 19:07:38 +00:00
|
|
|
uint8_t playfield_control_;
|
|
|
|
uint8_t playfield_colour_;
|
|
|
|
uint8_t background_colour_;
|
|
|
|
uint8_t playfield_[41];
|
2015-07-31 00:52:26 +00:00
|
|
|
|
2016-05-26 01:43:19 +00:00
|
|
|
// ... and derivatives
|
2016-12-03 19:07:38 +00:00
|
|
|
int ball_size_, missile_size_[2];
|
2016-05-26 01:43:19 +00:00
|
|
|
|
2016-05-17 01:54:27 +00:00
|
|
|
// delayed clock events
|
|
|
|
enum OutputState {
|
|
|
|
Sync,
|
|
|
|
Blank,
|
|
|
|
ColourBurst,
|
|
|
|
Pixel
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Event {
|
|
|
|
enum Action {
|
2016-05-18 01:41:32 +00:00
|
|
|
Playfield = 1 << 0,
|
2016-05-30 23:56:36 +00:00
|
|
|
ResetCounter = 1 << 1,
|
2016-05-26 01:12:25 +00:00
|
|
|
|
2016-05-30 23:56:36 +00:00
|
|
|
HMoveSetup = 1 << 2,
|
|
|
|
HMoveCompare = 1 << 3,
|
|
|
|
HMoveDecrement = 1 << 4,
|
2016-05-17 01:54:27 +00:00
|
|
|
};
|
2016-05-17 22:21:49 +00:00
|
|
|
int updates;
|
2016-05-18 01:41:32 +00:00
|
|
|
|
2016-05-17 01:54:27 +00:00
|
|
|
OutputState state;
|
2016-12-03 19:07:38 +00:00
|
|
|
uint8_t playfield_pixel;
|
2016-05-30 23:56:36 +00:00
|
|
|
int counter;
|
2016-05-18 01:41:32 +00:00
|
|
|
|
2016-12-03 19:07:38 +00:00
|
|
|
Event() : updates(0), playfield_pixel(0) {}
|
|
|
|
} upcoming_events_[number_of_upcoming_events];
|
|
|
|
unsigned int upcoming_events_pointer_;
|
2016-05-17 01:54:27 +00:00
|
|
|
|
2016-05-27 18:33:08 +00:00
|
|
|
// object counters
|
|
|
|
struct ObjectCounter {
|
|
|
|
int count; // the counter value, multiplied by four, counting phase
|
|
|
|
int pixel; // for non-sprite objects, a count of cycles since the last counter reset; for sprite objects a count of pixels so far elapsed
|
|
|
|
int broad_pixel; // for sprite objects, a count of cycles since the last counter reset; otherwise unused
|
|
|
|
|
|
|
|
ObjectCounter() : count(0), pixel(0), broad_pixel(0) {}
|
2016-12-03 19:07:38 +00:00
|
|
|
} object_counter_[number_of_recorded_counters][5];
|
|
|
|
unsigned int object_counter_pointer_;
|
2016-05-27 18:33:08 +00:00
|
|
|
|
|
|
|
// the latched playfield output
|
2016-12-03 19:07:38 +00:00
|
|
|
uint8_t playfield_output_, next_playfield_output_;
|
2016-05-16 23:55:56 +00:00
|
|
|
|
2015-07-31 00:52:26 +00:00
|
|
|
// player registers
|
2016-12-03 19:07:38 +00:00
|
|
|
uint8_t player_colour_[2];
|
|
|
|
uint8_t player_reflection_mask_[2];
|
|
|
|
uint8_t player_graphics_[2][2];
|
|
|
|
uint8_t player_graphics_selector_[2];
|
2015-07-31 00:52:26 +00:00
|
|
|
|
2016-05-27 18:33:08 +00:00
|
|
|
// object flags
|
2016-12-03 19:07:38 +00:00
|
|
|
bool has_second_copy_[2];
|
|
|
|
bool has_third_copy_[2];
|
|
|
|
bool has_fourth_copy_[2];
|
|
|
|
uint8_t object_motions_[5]; // the value stored to this counter's motion register
|
2016-05-27 18:33:08 +00:00
|
|
|
|
2015-07-31 00:52:26 +00:00
|
|
|
// player + missile registers
|
2016-12-03 19:07:38 +00:00
|
|
|
uint8_t player_and_missile_size_[2];
|
2015-07-31 00:52:26 +00:00
|
|
|
|
|
|
|
// missile registers
|
2016-12-03 19:07:38 +00:00
|
|
|
uint8_t missile_graphics_enable_[2];
|
|
|
|
bool missile_graphics_reset_[2];
|
2015-07-31 00:52:26 +00:00
|
|
|
|
|
|
|
// ball registers
|
2016-12-03 19:07:38 +00:00
|
|
|
uint8_t ball_graphics_enable_[2];
|
|
|
|
uint8_t ball_graphics_selector_;
|
2015-07-19 20:48:14 +00:00
|
|
|
|
|
|
|
// graphics output
|
2016-12-03 19:07:38 +00:00
|
|
|
unsigned int horizontal_timer_;
|
|
|
|
bool vsync_enabled_, vblank_enabled_;
|
2016-05-17 22:21:49 +00:00
|
|
|
|
|
|
|
// horizontal motion control
|
2016-12-03 19:07:38 +00:00
|
|
|
uint8_t hmove_counter_;
|
|
|
|
uint8_t hmove_flags_;
|
2016-05-17 22:21:49 +00:00
|
|
|
|
2015-08-19 00:33:24 +00:00
|
|
|
// joystick state
|
2016-12-03 19:07:38 +00:00
|
|
|
uint8_t tia_input_value_[2];
|
2015-08-19 00:33:24 +00:00
|
|
|
|
2015-08-12 23:31:57 +00:00
|
|
|
// collisions
|
2016-12-03 19:07:38 +00:00
|
|
|
uint8_t collisions_[8];
|
2015-08-12 23:31:57 +00:00
|
|
|
|
2015-08-16 20:08:29 +00:00
|
|
|
void output_pixels(unsigned int count);
|
2016-05-16 23:04:13 +00:00
|
|
|
uint8_t get_output_pixel();
|
2016-05-21 14:18:15 +00:00
|
|
|
void update_timers(int mask);
|
2016-06-01 01:23:44 +00:00
|
|
|
|
2016-06-01 23:27:04 +00:00
|
|
|
// outputs
|
2016-12-03 19:07:38 +00:00
|
|
|
std::shared_ptr<Outputs::CRT::CRT> crt_;
|
|
|
|
std::shared_ptr<Speaker> speaker_;
|
2015-07-19 20:48:14 +00:00
|
|
|
|
2016-06-21 01:47:27 +00:00
|
|
|
// current mode
|
2016-12-03 19:07:38 +00:00
|
|
|
bool is_pal_region_;
|
2016-06-21 01:47:27 +00:00
|
|
|
|
2016-06-01 23:27:04 +00:00
|
|
|
// speaker backlog accumlation counter
|
2016-12-03 19:07:38 +00:00
|
|
|
unsigned int cycles_since_speaker_update_;
|
2016-06-01 23:27:04 +00:00
|
|
|
void update_audio();
|
|
|
|
|
2015-07-19 20:48:14 +00:00
|
|
|
// latched output state
|
2016-12-03 19:07:38 +00:00
|
|
|
unsigned int last_output_state_duration_;
|
|
|
|
OutputState state_by_extend_time_[2][57];
|
|
|
|
OutputState *state_by_time_;
|
|
|
|
OutputState last_output_state_;
|
|
|
|
uint8_t *output_buffer_;
|
2016-05-26 01:43:19 +00:00
|
|
|
|
|
|
|
// lookup table for collision reporting
|
2016-12-03 19:07:38 +00:00
|
|
|
uint8_t reported_collisions_[64][8];
|
2016-05-26 01:43:19 +00:00
|
|
|
void setup_reported_collisions();
|
2015-07-16 23:56:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* Atari2600_cpp */
|