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-01-05 04:12:47 +00:00
|
|
|
#include "../../Processors/6502/CPU6502.hpp"
|
2016-02-05 03:28:50 +00:00
|
|
|
#include "../../Outputs/CRT/CRT.hpp"
|
2015-07-26 19:45:19 +00:00
|
|
|
#include <stdint.h>
|
2015-08-19 00:33:24 +00:00
|
|
|
#include "Atari2600Inputs.h"
|
2015-07-16 23:56:02 +00:00
|
|
|
|
|
|
|
namespace Atari2600 {
|
|
|
|
|
2016-05-17 11:09:18 +00:00
|
|
|
const unsigned int number_of_upcoming_events = 8;
|
|
|
|
|
2015-07-16 23:56:02 +00:00
|
|
|
class Machine: public CPU6502::Processor<Machine> {
|
|
|
|
|
|
|
|
public:
|
|
|
|
Machine();
|
2015-07-28 01:15:10 +00:00
|
|
|
~Machine();
|
2015-07-16 23:56:02 +00:00
|
|
|
|
2015-08-16 20:08:29 +00:00
|
|
|
unsigned int perform_bus_operation(CPU6502::BusOperation operation, uint16_t address, uint8_t *value);
|
2015-07-16 23:56:02 +00:00
|
|
|
|
|
|
|
void set_rom(size_t length, const uint8_t *data);
|
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-03-09 01:49:07 +00:00
|
|
|
Outputs::CRT::CRT *get_crt() { return _crt; }
|
2016-04-24 10:56:08 +00:00
|
|
|
void setup_output(float aspect_ratio);
|
2016-04-25 00:34:25 +00:00
|
|
|
void close_output();
|
2015-07-22 22:15:18 +00:00
|
|
|
|
2015-07-16 23:56:02 +00:00
|
|
|
private:
|
2015-08-13 12:24:02 +00:00
|
|
|
uint8_t *_rom, *_romPages[4], _ram[128];
|
|
|
|
size_t _rom_size;
|
2015-07-16 23:56:02 +00:00
|
|
|
|
2015-07-19 20:48:14 +00:00
|
|
|
// the timer
|
2015-07-16 23:56:02 +00:00
|
|
|
unsigned int _piaTimerValue;
|
2015-08-10 15:55:16 +00:00
|
|
|
unsigned int _piaTimerShift, _writtenPiaTimerShift;
|
2015-07-30 21:16:49 +00:00
|
|
|
uint8_t _piaTimerStatus;
|
2015-07-16 23:56:02 +00:00
|
|
|
|
2015-07-31 00:52:26 +00:00
|
|
|
// playfield registers
|
2015-08-13 20:32:22 +00:00
|
|
|
uint8_t _playfieldControl;
|
2015-07-27 23:04:03 +00:00
|
|
|
uint8_t _playfieldColour;
|
|
|
|
uint8_t _backgroundColour;
|
2015-08-13 20:32:22 +00:00
|
|
|
uint8_t _playfield[40];
|
2015-07-31 00:52:26 +00:00
|
|
|
|
2016-05-17 01:54:27 +00:00
|
|
|
// delayed clock events
|
|
|
|
enum OutputState {
|
|
|
|
Sync,
|
|
|
|
Blank,
|
|
|
|
ColourBurst,
|
|
|
|
Pixel
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Event {
|
|
|
|
enum Action {
|
|
|
|
OutputSate = 1 << 0,
|
|
|
|
Playfield = 1 << 1,
|
|
|
|
};
|
|
|
|
unsigned int updates;
|
|
|
|
uint8_t playfieldOutput;
|
|
|
|
OutputState state;
|
2016-05-17 11:09:18 +00:00
|
|
|
} _upcomingEvents[number_of_upcoming_events];
|
2016-05-17 01:54:27 +00:00
|
|
|
unsigned int _upcomingEventsPointer;
|
|
|
|
|
|
|
|
uint8_t _playfieldOutput;
|
2016-05-16 23:55:56 +00:00
|
|
|
|
2015-07-31 00:52:26 +00:00
|
|
|
// player registers
|
|
|
|
uint8_t _playerColour[2];
|
2015-07-30 02:37:37 +00:00
|
|
|
uint8_t _playerReflection[2];
|
2015-07-31 00:52:26 +00:00
|
|
|
uint8_t _playerGraphicsLatch[2], _playerGraphics[2];
|
|
|
|
uint8_t _playerGraphicsLatchEnable[2];
|
2015-08-09 21:47:11 +00:00
|
|
|
bool _playerStart[2];
|
2015-07-31 00:52:26 +00:00
|
|
|
|
|
|
|
// player + missile registers
|
|
|
|
uint8_t _playerAndMissileSize[2];
|
|
|
|
|
|
|
|
// missile registers
|
2015-08-10 15:43:45 +00:00
|
|
|
uint8_t _missileGraphicsEnable[2], _missileGraphicsReset[2];
|
2015-07-31 00:52:26 +00:00
|
|
|
|
|
|
|
// ball registers
|
2015-07-31 03:01:28 +00:00
|
|
|
uint8_t _ballGraphicsEnable, _ballGraphicsEnableLatch;
|
2015-07-31 00:52:26 +00:00
|
|
|
uint8_t _ballGraphicsEnableDelay;
|
2015-07-19 20:48:14 +00:00
|
|
|
|
|
|
|
// graphics output
|
2016-05-16 12:01:29 +00:00
|
|
|
unsigned int _horizontalTimer;
|
2015-07-19 20:48:14 +00:00
|
|
|
bool _vSyncEnabled, _vBlankEnabled;
|
2015-08-09 23:20:18 +00:00
|
|
|
bool _vBlankExtend;
|
2015-08-13 17:59:23 +00:00
|
|
|
uint8_t _hMoveCounter;
|
|
|
|
bool _hMoveIsCounting, _hMoveWillCount;
|
2015-08-10 15:55:16 +00:00
|
|
|
uint8_t _objectCounter[5], _objectMotion[5];
|
2015-08-13 17:59:23 +00:00
|
|
|
uint8_t _hMoveFlags;
|
2015-07-16 23:56:02 +00:00
|
|
|
|
2015-08-19 00:33:24 +00:00
|
|
|
// joystick state
|
|
|
|
uint8_t _piaDataDirection[2];
|
|
|
|
uint8_t _piaDataValue[2];
|
2015-08-19 00:58:05 +00:00
|
|
|
uint8_t _tiaInputValue[2];
|
2015-08-19 00:33:24 +00:00
|
|
|
|
2015-08-12 23:31:57 +00:00
|
|
|
// collisions
|
|
|
|
uint8_t _collisions[8];
|
|
|
|
|
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-17 01:54:27 +00:00
|
|
|
void update_upcoming_event();
|
2016-03-09 01:49:07 +00:00
|
|
|
Outputs::CRT::CRT *_crt;
|
2015-07-19 20:48:14 +00:00
|
|
|
|
|
|
|
// latched output state
|
2015-08-16 20:08:29 +00:00
|
|
|
unsigned int _lastOutputStateDuration;
|
2015-07-19 20:48:14 +00:00
|
|
|
OutputState _lastOutputState;
|
2015-07-20 01:21:34 +00:00
|
|
|
uint8_t *_outputBuffer;
|
2015-07-16 23:56:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* Atari2600_cpp */
|