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;
|
2015-07-21 03:18:56 +00:00
|
|
|
static const char atari2600DataType[] = "Atari2600";
|
2015-07-31 21:47:10 +00:00
|
|
|
static const int horizontalTimerReload = 227;
|
2015-07-16 23:56:02 +00:00
|
|
|
|
|
|
|
Machine::Machine()
|
|
|
|
{
|
|
|
|
_timestamp = 0;
|
2015-08-10 14:09:40 +00:00
|
|
|
_horizontalTimer = 0;
|
2015-07-19 20:48:14 +00:00
|
|
|
_lastOutputStateDuration = 0;
|
|
|
|
_lastOutputState = OutputState::Sync;
|
2015-08-06 03:36:04 +00:00
|
|
|
_crt = new Outputs::CRT(228, 262, 1, 4);
|
2015-07-30 21:16:49 +00:00
|
|
|
_piaTimerStatus = 0xff;
|
2015-08-12 23:31:57 +00:00
|
|
|
memset(_collisions, 0xff, sizeof(_collisions));
|
2015-07-20 01:21:34 +00:00
|
|
|
|
2015-07-31 20:44:53 +00:00
|
|
|
setup6502();
|
2015-08-12 23:51:06 +00:00
|
|
|
set_reset_line(true);
|
2015-07-16 23:56:02 +00:00
|
|
|
}
|
|
|
|
|
2015-07-28 01:15:10 +00:00
|
|
|
Machine::~Machine()
|
|
|
|
{
|
|
|
|
delete _crt;
|
|
|
|
}
|
|
|
|
|
2015-07-31 22:04:33 +00:00
|
|
|
void Machine::switch_region()
|
|
|
|
{
|
2015-08-06 03:36:04 +00:00
|
|
|
_crt->set_new_timing(228, 312);
|
2015-07-31 22:04:33 +00:00
|
|
|
}
|
|
|
|
|
2015-07-19 20:48:14 +00:00
|
|
|
void Machine::get_output_pixel(uint8_t *pixel, int offset)
|
2015-07-16 23:56:02 +00:00
|
|
|
{
|
2015-07-27 23:04:03 +00:00
|
|
|
const uint8_t palette[16][3] =
|
|
|
|
{
|
|
|
|
{255, 255, 255}, {253, 250, 115}, {236, 199, 125}, {252, 187, 151},
|
|
|
|
{252, 180, 181}, {235, 177, 223}, {211, 178, 250}, {187, 182, 250},
|
|
|
|
{164, 186, 250}, {166, 201, 250}, {164, 224, 251}, {165, 251, 213},
|
|
|
|
{185, 251, 187}, {201, 250, 168}, {225, 235, 160}, {252, 223, 145}
|
|
|
|
};
|
2015-07-28 00:18:25 +00:00
|
|
|
const uint8_t alphaValues[8] =
|
|
|
|
{
|
2015-07-30 15:52:28 +00:00
|
|
|
// 0, 64, 108, 144, 176, 200, 220, 255
|
|
|
|
// };
|
|
|
|
//
|
|
|
|
// {
|
2015-07-28 00:18:25 +00:00
|
|
|
69, 134, 108, 161, 186, 210, 235, 255
|
|
|
|
};
|
2015-07-19 20:48:14 +00:00
|
|
|
|
2015-07-31 01:30:00 +00:00
|
|
|
// get the playfield pixel and hence a proposed colour
|
2015-07-30 15:52:28 +00:00
|
|
|
const int x = offset >> 2;
|
|
|
|
const int mirrored = (x / 20) & (_playfieldControl&1);
|
|
|
|
const int index = mirrored ? x - 20 : 19 - (x%20);
|
|
|
|
const int byte = 2 - (index >> 3);
|
|
|
|
const int lowestBit = (byte&1)^1;
|
|
|
|
const int bit = (index & 7)^(lowestBit | (lowestBit << 1) | (lowestBit << 2));
|
|
|
|
uint8_t playfieldPixel = (_playfield[byte] >> bit)&1;
|
|
|
|
uint8_t playfieldColour = ((_playfieldControl&6) == 2) ? _playerColour[x / 20] : _playfieldColour;
|
|
|
|
|
2015-07-31 01:30:00 +00:00
|
|
|
// get player and missile proposed pixels
|
|
|
|
uint8_t playerPixels[2], missilePixels[2];
|
2015-07-30 15:52:28 +00:00
|
|
|
for(int c = 0; c < 2; c++)
|
2015-07-30 03:48:52 +00:00
|
|
|
{
|
2015-07-31 01:30:00 +00:00
|
|
|
// figure out player colour
|
2015-07-30 16:07:28 +00:00
|
|
|
int flipMask = (_playerReflection[c]&0x8) ? 0 : 7;
|
2015-07-30 03:48:52 +00:00
|
|
|
|
2015-08-10 14:09:40 +00:00
|
|
|
int relativeTimer = _objectCounter[c] - 5;
|
2015-07-30 15:52:28 +00:00
|
|
|
switch (_playerAndMissileSize[c]&7)
|
|
|
|
{
|
|
|
|
case 0: break;
|
|
|
|
case 1:
|
|
|
|
if (relativeTimer >= 16) relativeTimer -= 16;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
if (relativeTimer >= 32) relativeTimer -= 32;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
if (relativeTimer >= 32) relativeTimer -= 32;
|
|
|
|
else if (relativeTimer >= 16) relativeTimer -= 16;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
if (relativeTimer >= 64) relativeTimer -= 64;
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
relativeTimer >>= 1;
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
if (relativeTimer >= 64) relativeTimer -= 64;
|
|
|
|
else if (relativeTimer >= 32) relativeTimer -= 32;
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
relativeTimer >>= 2;
|
|
|
|
break;
|
2015-07-30 03:48:52 +00:00
|
|
|
}
|
2015-07-30 15:52:28 +00:00
|
|
|
|
2015-07-30 16:07:28 +00:00
|
|
|
if(relativeTimer >= 0 && relativeTimer < 8)
|
2015-07-30 15:52:28 +00:00
|
|
|
playerPixels[c] = (_playerGraphics[c] >> (relativeTimer ^ flipMask)) &1;
|
|
|
|
else
|
|
|
|
playerPixels[c] = 0;
|
2015-07-31 01:09:18 +00:00
|
|
|
|
|
|
|
// figure out missile colour
|
2015-08-10 14:09:40 +00:00
|
|
|
int missileIndex = _objectCounter[2+c] - 4;
|
2015-07-31 01:09:18 +00:00
|
|
|
int missileSize = 1 << ((_playerAndMissileSize[c] >> 4)&3);
|
2015-08-10 15:43:45 +00:00
|
|
|
missilePixels[c] = (missileIndex >= 0 && missileIndex < missileSize && (_missileGraphicsEnable[c]&2) && !(_missileGraphicsReset[c]&2)) ? 1 : 0;
|
2015-07-30 15:52:28 +00:00
|
|
|
}
|
|
|
|
|
2015-07-31 01:30:00 +00:00
|
|
|
// get the ball proposed colour
|
|
|
|
uint8_t ballPixel;
|
2015-08-10 14:09:40 +00:00
|
|
|
int ballIndex = _objectCounter[4] - 4;
|
2015-07-31 01:30:00 +00:00
|
|
|
int ballSize = 1 << ((_playfieldControl >> 4)&3);
|
|
|
|
ballPixel = (ballIndex >= 0 && ballIndex < ballSize && (_ballGraphicsEnable&2)) ? 1 : 0;
|
|
|
|
|
2015-08-12 23:31:57 +00:00
|
|
|
// accumulate collisions
|
|
|
|
_collisions[0] |= ((missilePixels[0] | playerPixels[0]) << 6);
|
|
|
|
_collisions[0] |= ((missilePixels[0] | playerPixels[1]) << 7);
|
|
|
|
_collisions[1] |= ((missilePixels[1] | playerPixels[0]) << 6);
|
|
|
|
_collisions[1] |= ((missilePixels[1] | playerPixels[1]) << 7);
|
|
|
|
|
|
|
|
_collisions[2] |= ((ballPixel | playerPixels[0]) << 6);
|
|
|
|
_collisions[2] |= ((playfieldPixel | playerPixels[0]) << 7);
|
|
|
|
_collisions[3] |= ((ballPixel | playerPixels[1]) << 6);
|
|
|
|
_collisions[3] |= ((playfieldPixel | playerPixels[1]) << 7);
|
|
|
|
|
|
|
|
_collisions[4] |= ((ballPixel | missilePixels[0]) << 6);
|
|
|
|
_collisions[4] |= ((playfieldPixel | missilePixels[0]) << 7);
|
|
|
|
_collisions[5] |= ((ballPixel | missilePixels[1]) << 6);
|
|
|
|
_collisions[5] |= ((playfieldPixel | missilePixels[1]) << 7);
|
|
|
|
|
|
|
|
_collisions[6] |= ((playfieldPixel | ballPixel) << 7);
|
|
|
|
|
|
|
|
_collisions[7] |= ((playerPixels[0] | playerPixels[1]) << 7);
|
|
|
|
_collisions[7] |= ((missilePixels[0] | missilePixels[1]) << 6);
|
|
|
|
|
2015-07-31 01:30:00 +00:00
|
|
|
// apply appropriate priority to pick a colour
|
|
|
|
playfieldPixel |= ballPixel;
|
2015-07-30 15:52:28 +00:00
|
|
|
uint8_t outputColour = playfieldPixel ? playfieldColour : _backgroundColour;
|
|
|
|
|
2015-07-31 00:07:20 +00:00
|
|
|
if(!(_playfieldControl&0x04) || !playfieldPixel) {
|
2015-07-31 01:09:18 +00:00
|
|
|
if (playerPixels[1] || missilePixels[1]) outputColour = _playerColour[1];
|
|
|
|
if (playerPixels[0] || missilePixels[0]) outputColour = _playerColour[0];
|
2015-07-30 03:48:52 +00:00
|
|
|
}
|
2015-07-30 02:37:37 +00:00
|
|
|
|
2015-07-31 01:30:00 +00:00
|
|
|
// map that colour to an RGBA
|
2015-08-06 03:36:04 +00:00
|
|
|
pixel[0] = palette[outputColour >> 4][0];
|
|
|
|
pixel[1] = palette[outputColour >> 4][1];
|
|
|
|
pixel[2] = palette[outputColour >> 4][2];
|
|
|
|
pixel[3] = alphaValues[(outputColour >> 1)&7];
|
2015-07-19 20:48:14 +00:00
|
|
|
}
|
2015-07-16 23:56:02 +00:00
|
|
|
|
2015-07-19 20:48:14 +00:00
|
|
|
void Machine::output_pixels(int count)
|
|
|
|
{
|
2015-08-03 00:32:18 +00:00
|
|
|
const int32_t start_of_sync = 214;
|
2015-08-06 00:55:27 +00:00
|
|
|
const int32_t end_of_sync = 198;
|
2015-08-03 00:32:18 +00:00
|
|
|
|
2015-07-31 01:09:18 +00:00
|
|
|
_timestamp += count;
|
2015-07-19 20:48:14 +00:00
|
|
|
while(count--)
|
|
|
|
{
|
2015-07-28 02:12:13 +00:00
|
|
|
OutputState state;
|
|
|
|
|
2015-08-09 23:20:18 +00:00
|
|
|
// update hmove
|
2015-08-10 07:16:17 +00:00
|
|
|
if (!(_horizontalTimer&3) && _hMoveFlags) {
|
2015-08-10 15:55:16 +00:00
|
|
|
for(int c = 0; c < 5; c++) {
|
|
|
|
if ((_hMoveCounter^8^(_objectMotion[c] >> 4)) == 0xf) _hMoveFlags &= ~(1 << c);
|
|
|
|
if (_hMoveFlags&(1 << c)) _objectCounter[c] = (_objectCounter[c]+1)%160;
|
|
|
|
}
|
2015-08-09 23:20:18 +00:00
|
|
|
|
2015-08-10 15:43:45 +00:00
|
|
|
_hMoveCounter = (_hMoveCounter-1)&0xf;
|
2015-08-09 23:33:37 +00:00
|
|
|
}
|
2015-08-09 23:20:18 +00:00
|
|
|
|
2015-07-19 20:48:14 +00:00
|
|
|
// logic: if in vsync, output that; otherwise if in vblank then output that;
|
|
|
|
// otherwise output a pixel
|
|
|
|
if(_vSyncEnabled) {
|
2015-08-03 00:32:18 +00:00
|
|
|
state = (_horizontalTimer < start_of_sync) ? OutputState::Sync : OutputState::Blank;
|
2015-07-19 20:48:14 +00:00
|
|
|
} else {
|
2015-07-16 23:56:02 +00:00
|
|
|
|
2015-07-19 20:48:14 +00:00
|
|
|
// blank is decoded as 68 counts; sync and colour burst as 16 counts
|
|
|
|
|
2015-07-31 20:44:53 +00:00
|
|
|
// 4 blank
|
|
|
|
// 4 sync
|
|
|
|
// 9 'blank'; colour burst after 4
|
|
|
|
// 40 pixels
|
|
|
|
|
2015-07-23 23:24:25 +00:00
|
|
|
// it'll be about 43 cycles from start of hsync to start of visible frame, so...
|
|
|
|
// guesses, until I can find information: 26 cycles blank, 16 sync, 40 blank, 160 pixels
|
2015-08-03 00:32:18 +00:00
|
|
|
if(_horizontalTimer >= start_of_sync) state = OutputState::Blank;
|
|
|
|
else if (_horizontalTimer >= end_of_sync) state = OutputState::Sync;
|
2015-08-09 23:20:18 +00:00
|
|
|
else if (_horizontalTimer >= (_vBlankExtend ? 152 : 160)) state = OutputState::Blank;
|
2015-07-19 20:48:14 +00:00
|
|
|
else {
|
|
|
|
if(_vBlankEnabled) {
|
2015-07-28 02:12:13 +00:00
|
|
|
state = OutputState::Blank;
|
2015-07-19 20:48:14 +00:00
|
|
|
} else {
|
2015-07-28 02:12:13 +00:00
|
|
|
state = OutputState::Pixel;
|
2015-07-19 20:48:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-07-16 23:56:02 +00:00
|
|
|
|
2015-07-28 02:12:13 +00:00
|
|
|
_lastOutputStateDuration++;
|
|
|
|
if(state != _lastOutputState)
|
|
|
|
{
|
|
|
|
switch(_lastOutputState)
|
|
|
|
{
|
2015-08-06 03:36:04 +00:00
|
|
|
case OutputState::Blank: _crt->output_blank(_lastOutputStateDuration); break;
|
|
|
|
case OutputState::Sync: _crt->output_sync(_lastOutputStateDuration); break;
|
|
|
|
case OutputState::Pixel: _crt->output_data(_lastOutputStateDuration, atari2600DataType); break;
|
2015-07-28 02:12:13 +00:00
|
|
|
}
|
|
|
|
_lastOutputStateDuration = 0;
|
|
|
|
_lastOutputState = state;
|
|
|
|
|
|
|
|
if(state == OutputState::Pixel)
|
|
|
|
{
|
2015-08-12 23:31:57 +00:00
|
|
|
// printf("%d %d\n", _objectCounter[0], _objectCounter[1]);
|
2015-08-09 23:20:18 +00:00
|
|
|
_vBlankExtend = false;
|
2015-08-06 03:36:04 +00:00
|
|
|
_crt->allocate_write_area(160);
|
2015-07-28 02:12:13 +00:00
|
|
|
_outputBuffer = _crt->get_write_target_for_buffer(0);
|
2015-08-12 23:31:57 +00:00
|
|
|
} else {
|
|
|
|
_outputBuffer = nullptr;
|
2015-07-28 02:12:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-12 23:31:57 +00:00
|
|
|
if(_horizontalTimer < (_vBlankExtend ? 152 : 160))
|
2015-08-09 21:47:11 +00:00
|
|
|
{
|
2015-08-09 23:20:18 +00:00
|
|
|
if(_outputBuffer)
|
|
|
|
get_output_pixel(&_outputBuffer[_lastOutputStateDuration * 4], 159 - _horizontalTimer);
|
2015-07-28 02:12:13 +00:00
|
|
|
|
2015-08-09 23:20:18 +00:00
|
|
|
// increment all graphics counters
|
2015-08-10 15:55:16 +00:00
|
|
|
for(int c = 0; c < 5; c++)
|
|
|
|
_objectCounter[c] = (_objectCounter[c]+1)%160;
|
2015-08-09 21:47:11 +00:00
|
|
|
}
|
|
|
|
|
2015-07-26 19:45:19 +00:00
|
|
|
// assumption here: signed shifts right; otherwise it's just
|
|
|
|
// an attempt to avoid both the % operator and a conditional
|
|
|
|
_horizontalTimer--;
|
|
|
|
const int32_t sign_extension = _horizontalTimer >> 31;
|
2015-07-31 21:47:10 +00:00
|
|
|
_horizontalTimer = (_horizontalTimer&~sign_extension) | (sign_extension&horizontalTimerReload);
|
2015-07-16 23:56:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-26 19:55:19 +00:00
|
|
|
int Machine::perform_bus_operation(CPU6502::BusOperation operation, uint16_t address, uint8_t *value)
|
2015-07-19 20:48:14 +00:00
|
|
|
{
|
2015-08-12 23:51:06 +00:00
|
|
|
set_reset_line(false);
|
|
|
|
|
2015-07-19 20:48:14 +00:00
|
|
|
uint8_t returnValue = 0xff;
|
2015-08-09 06:42:01 +00:00
|
|
|
int cycles_run_for = 1;
|
2015-08-12 23:31:57 +00:00
|
|
|
const int32_t ready_line_disable_time = 225;//horizontalTimerReload;
|
2015-08-10 14:09:40 +00:00
|
|
|
|
2015-08-09 06:42:01 +00:00
|
|
|
if(operation == CPU6502::BusOperation::Ready) {
|
2015-08-12 23:31:57 +00:00
|
|
|
int32_t distance_to_end_of_ready = (_horizontalTimer - ready_line_disable_time + horizontalTimerReload + 1)%(horizontalTimerReload + 1);
|
2015-08-09 23:33:37 +00:00
|
|
|
cycles_run_for = distance_to_end_of_ready / 3;
|
2015-08-09 06:42:01 +00:00
|
|
|
output_pixels(distance_to_end_of_ready);
|
|
|
|
} else {
|
|
|
|
output_pixels(3);
|
|
|
|
}
|
2015-07-16 23:56:02 +00:00
|
|
|
|
2015-08-12 23:31:57 +00:00
|
|
|
if(_horizontalTimer == ready_line_disable_time)
|
|
|
|
set_ready_line(false);
|
|
|
|
|
2015-07-31 20:54:20 +00:00
|
|
|
if(operation != CPU6502::BusOperation::Ready) {
|
2015-08-09 06:42:01 +00:00
|
|
|
|
2015-07-31 20:54:20 +00:00
|
|
|
// check for a ROM access
|
|
|
|
if ((address&0x1000) && isReadOperation(operation)) {
|
|
|
|
returnValue &= _rom[address&_romMask];
|
|
|
|
}
|
2015-07-16 23:56:02 +00:00
|
|
|
|
2015-07-31 20:54:20 +00:00
|
|
|
// check for a RAM access
|
|
|
|
if ((address&0x1280) == 0x80) {
|
2015-07-16 23:56:02 +00:00
|
|
|
|
2015-07-31 20:54:20 +00:00
|
|
|
if(isReadOperation(operation)) {
|
|
|
|
returnValue &= _ram[address&0x7f];
|
|
|
|
} else {
|
|
|
|
_ram[address&0x7f] = *value;
|
|
|
|
}
|
2015-07-16 23:56:02 +00:00
|
|
|
}
|
|
|
|
|
2015-07-31 20:54:20 +00:00
|
|
|
// check for a TIA access
|
|
|
|
if (!(address&0x1080)) {
|
|
|
|
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
|
|
|
|
returnValue &= _collisions[decodedAddress];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x08:
|
|
|
|
case 0x09:
|
|
|
|
case 0x0a:
|
|
|
|
case 0x0b:
|
|
|
|
// TODO: pot ports
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x0c:
|
|
|
|
case 0x0d:
|
|
|
|
// TODO: inputs
|
|
|
|
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) {
|
2015-08-12 23:31:57 +00:00
|
|
|
case 0x00:
|
|
|
|
_vSyncEnabled = !!(*value & 0x02);
|
|
|
|
break;
|
2015-07-31 20:54:20 +00:00
|
|
|
case 0x01: _vBlankEnabled = !!(*value & 0x02); break;
|
|
|
|
|
2015-08-10 15:43:45 +00:00
|
|
|
case 0x02:
|
2015-07-31 20:54:20 +00:00
|
|
|
set_ready_line(true);
|
2015-08-10 15:43:45 +00:00
|
|
|
break;
|
2015-08-10 14:09:40 +00:00
|
|
|
case 0x03:
|
|
|
|
_horizontalTimer = 0;
|
|
|
|
break;
|
2015-07-31 20:54:20 +00:00
|
|
|
|
2015-08-12 23:31:57 +00:00
|
|
|
case 0x04:
|
|
|
|
case 0x05: _playerAndMissileSize[decodedAddress - 0x04] = *value; break;
|
2015-07-31 20:54:20 +00:00
|
|
|
|
2015-08-12 23:31:57 +00:00
|
|
|
case 0x06:
|
|
|
|
case 0x07: _playerColour[decodedAddress - 0x06] = *value; break;
|
2015-07-31 20:54:20 +00:00
|
|
|
case 0x08: _playfieldColour = *value; break;
|
|
|
|
case 0x09: _backgroundColour = *value; break;
|
|
|
|
|
|
|
|
case 0x0a: _playfieldControl = *value; break;
|
2015-08-12 23:31:57 +00:00
|
|
|
case 0x0b:
|
|
|
|
case 0x0c: _playerReflection[decodedAddress - 0x0b] = *value; break;
|
|
|
|
case 0x0d:
|
|
|
|
case 0x0e:
|
|
|
|
case 0x0f: _playfield[decodedAddress - 0x0d] = *value; break;
|
|
|
|
|
|
|
|
case 0x10: case 0x11: case 0x12: case 0x13:
|
|
|
|
case 0x14: _objectCounter[decodedAddress - 0x10] = 0; break;
|
2015-07-31 20:54:20 +00:00
|
|
|
|
|
|
|
case 0x1c:
|
2015-07-31 03:01:28 +00:00
|
|
|
_ballGraphicsEnable = _ballGraphicsEnableLatch;
|
2015-07-31 20:54:20 +00:00
|
|
|
case 0x1b: {
|
2015-08-12 23:31:57 +00:00
|
|
|
int index = decodedAddress - 0x1b;
|
2015-07-31 20:54:20 +00:00
|
|
|
_playerGraphicsLatch[index] = *value;
|
|
|
|
if(!(_playerGraphicsLatchEnable[index]&1))
|
|
|
|
_playerGraphics[index] = _playerGraphicsLatch[index];
|
|
|
|
_playerGraphics[index^1] = _playerGraphicsLatch[index^1];
|
|
|
|
} break;
|
|
|
|
case 0x1d: _missileGraphicsEnable[0] = *value; break;
|
|
|
|
case 0x1e: _missileGraphicsEnable[1] = *value; break;
|
|
|
|
case 0x1f:
|
|
|
|
_ballGraphicsEnableLatch = *value;
|
|
|
|
if(!(_ballGraphicsEnableDelay&1))
|
|
|
|
_ballGraphicsEnable = _ballGraphicsEnableLatch;
|
|
|
|
break;
|
|
|
|
|
2015-08-12 23:31:57 +00:00
|
|
|
case 0x20:
|
|
|
|
case 0x21:
|
|
|
|
case 0x22:
|
|
|
|
case 0x23:
|
|
|
|
case 0x24: _objectMotion[decodedAddress - 0x20] = *value; break;
|
2015-07-31 20:54:20 +00:00
|
|
|
|
|
|
|
case 0x25: _playerGraphicsLatchEnable[0] = *value; break;
|
|
|
|
case 0x26: _playerGraphicsLatchEnable[1] = *value; break;
|
|
|
|
case 0x27: _ballGraphicsEnableDelay = *value; break;
|
|
|
|
|
2015-08-10 15:43:45 +00:00
|
|
|
case 0x28:
|
|
|
|
case 0x29:
|
2015-08-10 15:55:16 +00:00
|
|
|
if (!(*value&0x02) && _missileGraphicsReset[decodedAddress - 0x28]&0x02)
|
|
|
|
_objectCounter[decodedAddress - 0x26] = _objectCounter[decodedAddress - 0x28]; // TODO: +3 for normal, +6 for double, +10 for quad
|
|
|
|
_missileGraphicsReset[decodedAddress - 0x28] = *value;
|
|
|
|
break;
|
2015-07-31 20:54:20 +00:00
|
|
|
|
|
|
|
case 0x2a:
|
2015-08-09 23:20:18 +00:00
|
|
|
_vBlankExtend = true;
|
2015-08-09 23:33:37 +00:00
|
|
|
_hMoveCounter = 15;
|
2015-08-09 23:20:18 +00:00
|
|
|
_hMoveFlags = 0x1f;
|
2015-07-31 20:54:20 +00:00
|
|
|
break;
|
2015-08-10 14:09:40 +00:00
|
|
|
case 0x2b:
|
2015-08-10 15:55:16 +00:00
|
|
|
_objectMotion[0] =
|
|
|
|
_objectMotion[1] =
|
|
|
|
_objectMotion[2] =
|
|
|
|
_objectMotion[3] =
|
|
|
|
_objectMotion[4] = 0;
|
|
|
|
break;
|
2015-08-12 23:31:57 +00:00
|
|
|
case 0x2c:
|
|
|
|
_collisions[0] = _collisions[1] = _collisions[2] =
|
|
|
|
_collisions[3] = _collisions[4] = _collisions[5] = 0x3f;
|
|
|
|
_collisions[6] = 0x7f;
|
|
|
|
_collisions[7] = 0x3f;
|
|
|
|
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
|
|
|
// printf("Uncaught TIA %04x\n", address);
|
2015-07-16 23:56:02 +00:00
|
|
|
}
|
|
|
|
|
2015-07-31 20:54:20 +00:00
|
|
|
// check for a PIA access
|
|
|
|
if ((address&0x1280) == 0x280) {
|
|
|
|
if(isReadOperation(operation)) {
|
|
|
|
switch(address & 0xf) {
|
2015-08-12 23:31:57 +00:00
|
|
|
case 0x00:
|
|
|
|
// TODO: port A read
|
|
|
|
break;
|
|
|
|
case 0x01:
|
|
|
|
// TODO: port A DDR
|
|
|
|
break;
|
|
|
|
case 0x02:
|
|
|
|
// TODO: port B read
|
|
|
|
break;
|
|
|
|
case 0x03:
|
|
|
|
// TODO: port B DDR
|
|
|
|
break;
|
2015-08-10 15:55:16 +00:00
|
|
|
case 0x04:
|
|
|
|
returnValue &= _piaTimerValue >> _piaTimerShift;
|
|
|
|
|
|
|
|
if(_writtenPiaTimerShift != _piaTimerShift) {
|
|
|
|
_piaTimerShift = _writtenPiaTimerShift;
|
|
|
|
_piaTimerValue <<= _writtenPiaTimerShift;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x05:
|
|
|
|
returnValue &= _piaTimerStatus;
|
|
|
|
_piaTimerStatus &= ~0x40;
|
|
|
|
break;
|
2015-07-31 20:54:20 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch(address & 0x0f) {
|
2015-08-10 15:55:16 +00:00
|
|
|
case 0x04: _writtenPiaTimerShift = _piaTimerShift = 0; _piaTimerValue = *value << 0; _piaTimerStatus &= ~0xc0; break;
|
|
|
|
case 0x05: _writtenPiaTimerShift = _piaTimerShift = 3; _piaTimerValue = *value << 3; _piaTimerStatus &= ~0xc0; break;
|
|
|
|
case 0x06: _writtenPiaTimerShift = _piaTimerShift = 6; _piaTimerValue = *value << 6; _piaTimerStatus &= ~0xc0; break;
|
|
|
|
case 0x07: _writtenPiaTimerShift = _piaTimerShift = 10; _piaTimerValue = *value << 10; _piaTimerStatus &= ~0xc0; 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
|
|
|
// printf("Uncaught PIA %04x\n", address);
|
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
|
|
|
}
|
|
|
|
|
2015-08-09 06:42:01 +00:00
|
|
|
if(_piaTimerValue >= cycles_run_for) {
|
|
|
|
_piaTimerValue -= cycles_run_for;
|
2015-07-31 20:54:20 +00:00
|
|
|
} else {
|
2015-08-09 06:42:01 +00:00
|
|
|
_piaTimerValue += 0xff - cycles_run_for;
|
2015-07-30 21:16:49 +00:00
|
|
|
_piaTimerShift = 0;
|
|
|
|
_piaTimerStatus |= 0xc0;
|
|
|
|
}
|
2015-07-26 19:55:19 +00:00
|
|
|
|
2015-08-12 23:31:57 +00:00
|
|
|
return cycles_run_for;
|
2015-07-16 23:56:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Machine::set_rom(size_t length, const uint8_t *data)
|
|
|
|
{
|
|
|
|
length = std::min((size_t)4096, length);
|
|
|
|
memcpy(_rom, data, length);
|
|
|
|
_romMask = length - 1;
|
|
|
|
}
|