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 {
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2015-07-22 22:15:18 +00:00
|
|
|
Outputs::CRT *get_crt() { return _crt; }
|
|
|
|
|
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
|
|
|
|
|
|
|
uint64_t _timestamp;
|
|
|
|
|
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
|
|
|
|
|
|
|
// 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
|
2015-07-26 19:45:19 +00:00
|
|
|
int32_t _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-07-19 20:48:14 +00:00
|
|
|
enum OutputState {
|
|
|
|
Sync,
|
|
|
|
Blank,
|
|
|
|
Pixel
|
|
|
|
};
|
2015-07-19 17:36:27 +00:00
|
|
|
|
2015-08-16 20:08:29 +00:00
|
|
|
void output_pixels(unsigned int count);
|
2015-07-19 20:48:14 +00:00
|
|
|
void get_output_pixel(uint8_t *pixel, int offset);
|
2015-07-19 17:36:27 +00:00
|
|
|
Outputs::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 */
|