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 {
|
|
|
|
static const unsigned int horizontalTimerPeriod = 228;
|
|
|
|
}
|
2015-07-16 23:56:02 +00:00
|
|
|
|
2015-12-06 21:53:37 +00:00
|
|
|
Machine::Machine() :
|
|
|
|
_horizontalTimer(0),
|
|
|
|
_lastOutputStateDuration(0),
|
|
|
|
_lastOutputState(OutputState::Sync),
|
|
|
|
_piaTimerStatus(0xff),
|
|
|
|
_rom(nullptr),
|
|
|
|
_piaDataValue{0xff, 0xff},
|
2016-05-17 01:54:27 +00:00
|
|
|
_tiaInputValue{0xff, 0xff},
|
|
|
|
_upcomingEventsPointer(0)
|
2016-04-24 10:56:08 +00:00
|
|
|
{
|
|
|
|
memset(_collisions, 0xff, sizeof(_collisions));
|
|
|
|
set_reset_line(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Machine::setup_output(float aspect_ratio)
|
2015-07-16 23:56:02 +00:00
|
|
|
{
|
2016-04-26 00:56:15 +00:00
|
|
|
_crt = new Outputs::CRT::CRT(228, 1, 263, Outputs::CRT::ColourSpace::YIQ, 228, 1, 1);
|
2016-05-12 01:07:18 +00:00
|
|
|
|
|
|
|
// this is the NTSC phase offset function; see below for PAL
|
2016-02-05 03:28:50 +00:00
|
|
|
_crt->set_composite_sampling_function(
|
2016-05-12 02:11:01 +00:00
|
|
|
"float composite_sample(usampler2D texID, vec2 coordinate, vec2 iCoordinate, float phase, float amplitude)"
|
2016-04-26 00:56:15 +00:00
|
|
|
"{"
|
|
|
|
"uint c = texture(texID, coordinate).r;"
|
2016-05-13 02:22:24 +00:00
|
|
|
"uint y = c & 14u;"
|
2016-04-26 00:56:15 +00:00
|
|
|
"uint iPhase = (c >> 4);"
|
2016-05-12 01:07:18 +00:00
|
|
|
|
2016-05-14 20:52:24 +00:00
|
|
|
"float phaseOffset = 6.283185308 * float(iPhase - 1u) / 13.0;"
|
2016-05-13 02:22:24 +00:00
|
|
|
"return (float(y) / 14.0) * (1.0 - amplitude) + step(1, iPhase) * amplitude * cos(phase + phaseOffset);"
|
2016-02-05 03:28:50 +00:00
|
|
|
"}");
|
2016-04-24 21:56:36 +00:00
|
|
|
_crt->set_output_device(Outputs::CRT::Television);
|
2015-07-16 23:56:02 +00:00
|
|
|
}
|
|
|
|
|
2016-05-12 01:07:18 +00:00
|
|
|
void Machine::switch_region()
|
|
|
|
{
|
|
|
|
// the PAL function
|
|
|
|
_crt->set_composite_sampling_function(
|
2016-05-12 02:11:01 +00:00
|
|
|
"float composite_sample(usampler2D texID, vec2 coordinate, vec2 iCoordinate, float phase, float amplitude)"
|
2016-05-12 01:07:18 +00:00
|
|
|
"{"
|
|
|
|
"uint c = texture(texID, coordinate).r;"
|
2016-05-13 02:22:24 +00:00
|
|
|
"uint y = c & 14u;"
|
2016-05-12 01:07:18 +00:00
|
|
|
"uint iPhase = (c >> 4);"
|
|
|
|
|
2016-05-14 20:52:24 +00:00
|
|
|
"uint direction = iPhase & 1u;"
|
|
|
|
"float phaseOffset = float(7u - direction) + (float(direction) - 0.5) * 2.0 * float(iPhase >> 1);"
|
|
|
|
"phaseOffset *= 6.283185308 / 12.0;"
|
|
|
|
"return (float(y) / 14.0) * (1.0 - amplitude) + step(4, (iPhase + 2u) & 15u) * amplitude * cos(phase + phaseOffset);"
|
2016-05-12 01:07:18 +00:00
|
|
|
"}");
|
|
|
|
_crt->set_new_timing(228, 312, Outputs::CRT::ColourSpace::YUV, 228, 1);
|
|
|
|
}
|
|
|
|
|
2016-04-25 00:34:25 +00:00
|
|
|
void Machine::close_output()
|
|
|
|
{
|
|
|
|
delete _crt;
|
|
|
|
_crt = nullptr;
|
|
|
|
}
|
|
|
|
|
2015-07-28 01:15:10 +00:00
|
|
|
Machine::~Machine()
|
|
|
|
{
|
2015-08-13 12:24:02 +00:00
|
|
|
delete[] _rom;
|
2016-04-25 00:34:25 +00:00
|
|
|
close_output();
|
2015-07-28 01:15:10 +00:00
|
|
|
}
|
|
|
|
|
2016-05-17 01:54:27 +00:00
|
|
|
void Machine::update_upcoming_event()
|
2015-07-16 23:56:02 +00:00
|
|
|
{
|
2016-05-17 11:18:14 +00:00
|
|
|
unsigned int upcomingEventsPointerPlus4 = (_upcomingEventsPointer + 4)%number_of_upcoming_events;
|
|
|
|
|
2016-05-17 11:09:18 +00:00
|
|
|
// grab the background now, for display in four clocks
|
|
|
|
if(!(_horizontalTimer&3))
|
|
|
|
{
|
|
|
|
unsigned int offset = 4 + _horizontalTimer - (horizontalTimerPeriod - 160);
|
2016-05-17 11:18:14 +00:00
|
|
|
_upcomingEvents[upcomingEventsPointerPlus4].updates |= Event::Action::Playfield;
|
|
|
|
_upcomingEvents[upcomingEventsPointerPlus4].playfieldOutput = _playfield[(offset >> 2)%40];
|
2016-05-17 11:09:18 +00:00
|
|
|
}
|
2016-05-17 01:54:27 +00:00
|
|
|
|
2016-05-17 11:09:18 +00:00
|
|
|
// the ball becomes visible whenever it hits zero, regardless of whether its status
|
|
|
|
// is the result of a counter rollover or a programmatic reset
|
2016-05-17 11:18:14 +00:00
|
|
|
if(!_objectCounter[4])
|
2016-05-16 23:55:56 +00:00
|
|
|
{
|
2016-05-18 01:41:32 +00:00
|
|
|
_upcomingEvents[upcomingEventsPointerPlus4].updates |= Event::Action::ResetPixelCounter;
|
|
|
|
_upcomingEvents[upcomingEventsPointerPlus4].pixelCounterMask |= (1 << 4);
|
|
|
|
// _upcomingEvents[_upcomingEventsPointer].updates |= Event::Action::ResetPixelCounter;
|
|
|
|
// _upcomingEvents[_upcomingEventsPointer].pixelCounterMask |= (1 << 4);
|
2016-05-16 23:55:56 +00:00
|
|
|
}
|
2016-05-17 11:18:14 +00:00
|
|
|
_objectCounter[4] = (_objectCounter[4] + 1)%160;
|
2016-05-17 23:02:32 +00:00
|
|
|
// printf("-%d- ", _objectCounter[4]);
|
2016-05-17 11:09:18 +00:00
|
|
|
|
2016-05-17 11:18:14 +00:00
|
|
|
// the players and missles become visible only upon overflow to zero, so schedule for
|
|
|
|
// 5/6 clocks ahead from 159
|
2016-05-17 01:54:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t Machine::get_output_pixel()
|
|
|
|
{
|
|
|
|
unsigned int offset = _horizontalTimer - (horizontalTimerPeriod - 160);
|
|
|
|
|
|
|
|
// get the playfield pixel and hence a proposed colour
|
2015-08-13 22:23:04 +00:00
|
|
|
uint8_t playfieldColour = ((_playfieldControl&6) == 2) ? _playerColour[offset / 80] : _playfieldColour;
|
2015-07-30 15:52:28 +00:00
|
|
|
|
2016-05-17 01:54:27 +00:00
|
|
|
// get the ball proposed colour
|
2016-05-17 11:18:14 +00:00
|
|
|
uint8_t ballPixel = 0;
|
|
|
|
if(_ballGraphicsEnable&2) {
|
|
|
|
int ballSize = 1 << ((_playfieldControl >> 4)&3);
|
2016-05-18 01:41:32 +00:00
|
|
|
ballPixel = (_pixelCounter[4] < ballSize) ? 1 : 0;
|
2016-05-17 11:18:14 +00:00
|
|
|
}
|
2016-05-18 01:41:32 +00:00
|
|
|
_pixelCounter[4] ++;
|
2016-05-17 01:54:27 +00:00
|
|
|
|
2015-07-31 01:30:00 +00:00
|
|
|
// get player and missile proposed pixels
|
2016-05-16 23:04:13 +00:00
|
|
|
/* uint8_t playerPixels[2] = {0, 0}, missilePixels[2] = {0, 0};
|
2015-07-30 15:52:28 +00:00
|
|
|
for(int c = 0; c < 2; c++)
|
2015-07-30 03:48:52 +00:00
|
|
|
{
|
2015-08-19 13:46:57 +00:00
|
|
|
const uint8_t repeatMask = _playerAndMissileSize[c]&7;
|
2016-04-25 02:32:24 +00:00
|
|
|
if(_playerGraphics[c]) {
|
2015-08-16 15:23:46 +00:00
|
|
|
// figure out player colour
|
|
|
|
int flipMask = (_playerReflection[c]&0x8) ? 0 : 7;
|
|
|
|
|
|
|
|
int relativeTimer = _objectCounter[c] - 5;
|
2015-08-19 13:46:57 +00:00
|
|
|
switch (repeatMask)
|
2015-08-16 15:23:46 +00:00
|
|
|
{
|
|
|
|
case 0: break;
|
2015-08-19 13:46:57 +00:00
|
|
|
default:
|
2016-04-25 02:32:24 +00:00
|
|
|
if(repeatMask&4 && relativeTimer >= 64) relativeTimer -= 64;
|
|
|
|
else if(repeatMask&2 && relativeTimer >= 32) relativeTimer -= 32;
|
|
|
|
else if(repeatMask&1 && relativeTimer >= 16) relativeTimer -= 16;
|
2015-08-16 15:23:46 +00:00
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
relativeTimer >>= 1;
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
relativeTimer >>= 2;
|
|
|
|
break;
|
|
|
|
}
|
2015-07-30 15:52:28 +00:00
|
|
|
|
2015-08-16 15:23:46 +00:00
|
|
|
if(relativeTimer >= 0 && relativeTimer < 8)
|
|
|
|
playerPixels[c] = (_playerGraphics[c] >> (relativeTimer ^ flipMask)) &1;
|
|
|
|
}
|
2015-07-31 01:09:18 +00:00
|
|
|
|
|
|
|
// figure out missile colour
|
2016-04-25 02:32:24 +00:00
|
|
|
if((_missileGraphicsEnable[c]&2) && !(_missileGraphicsReset[c]&2)) {
|
2015-08-16 15:23:46 +00:00
|
|
|
int missileIndex = _objectCounter[2+c] - 4;
|
2015-08-19 13:46:57 +00:00
|
|
|
switch (repeatMask)
|
|
|
|
{
|
|
|
|
case 0: break;
|
|
|
|
default:
|
2016-04-25 02:32:24 +00:00
|
|
|
if(repeatMask&4 && missileIndex >= 64) missileIndex -= 64;
|
|
|
|
else if(repeatMask&2 && missileIndex >= 32) missileIndex -= 32;
|
|
|
|
else if(repeatMask&1 && missileIndex >= 16) missileIndex -= 16;
|
2015-08-19 13:46:57 +00:00
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
missileIndex >>= 1;
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
missileIndex >>= 2;
|
|
|
|
break;
|
|
|
|
}
|
2015-08-16 15:23:46 +00:00
|
|
|
int missileSize = 1 << ((_playerAndMissileSize[c] >> 4)&3);
|
|
|
|
missilePixels[c] = (missileIndex >= 0 && missileIndex < missileSize) ? 1 : 0;
|
|
|
|
}
|
2015-07-30 15:52:28 +00:00
|
|
|
}
|
|
|
|
|
2015-08-12 23:31:57 +00:00
|
|
|
// accumulate collisions
|
2016-04-25 02:32:24 +00:00
|
|
|
if(playerPixels[0] | playerPixels[1]) {
|
2015-08-16 19:39:40 +00:00
|
|
|
_collisions[0] |= ((missilePixels[0] & playerPixels[1]) << 7) | ((missilePixels[0] & playerPixels[0]) << 6);
|
|
|
|
_collisions[1] |= ((missilePixels[1] & playerPixels[0]) << 7) | ((missilePixels[1] & playerPixels[1]) << 6);
|
2015-08-12 23:31:57 +00:00
|
|
|
|
2015-08-16 19:39:40 +00:00
|
|
|
_collisions[2] |= ((playfieldPixel & playerPixels[0]) << 7) | ((ballPixel & playerPixels[0]) << 6);
|
|
|
|
_collisions[3] |= ((playfieldPixel & playerPixels[1]) << 7) | ((ballPixel & playerPixels[1]) << 6);
|
2015-08-12 23:31:57 +00:00
|
|
|
|
2015-08-16 19:39:40 +00:00
|
|
|
_collisions[7] |= ((playerPixels[0] & playerPixels[1]) << 7);
|
|
|
|
}
|
2015-08-12 23:31:57 +00:00
|
|
|
|
2016-04-25 02:32:24 +00:00
|
|
|
if(playfieldPixel | ballPixel) {
|
2015-08-16 19:39:40 +00:00
|
|
|
_collisions[4] |= ((playfieldPixel & missilePixels[0]) << 7) | ((ballPixel & missilePixels[0]) << 6);
|
|
|
|
_collisions[5] |= ((playfieldPixel & missilePixels[1]) << 7) | ((ballPixel & missilePixels[1]) << 6);
|
|
|
|
|
|
|
|
_collisions[6] |= ((playfieldPixel & ballPixel) << 7);
|
|
|
|
}
|
2015-08-12 23:31:57 +00:00
|
|
|
|
2015-08-16 19:39:40 +00:00
|
|
|
if(missilePixels[0] & missilePixels[1])
|
|
|
|
_collisions[7] |= (1 << 6);
|
2015-08-12 23:31:57 +00:00
|
|
|
|
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) {
|
2016-04-25 02:32:24 +00:00
|
|
|
if(playerPixels[1] || missilePixels[1]) outputColour = _playerColour[1];
|
|
|
|
if(playerPixels[0] || missilePixels[0]) outputColour = _playerColour[0];
|
2016-05-16 23:04:13 +00:00
|
|
|
}*/
|
2015-07-30 02:37:37 +00:00
|
|
|
|
2016-05-16 23:04:13 +00:00
|
|
|
// return colour
|
2016-05-17 11:18:14 +00:00
|
|
|
return (_playfieldOutput | ballPixel) ? playfieldColour : _backgroundColour;
|
2015-07-19 20:48:14 +00:00
|
|
|
}
|
2015-07-16 23:56:02 +00:00
|
|
|
|
2015-08-13 20:50:24 +00:00
|
|
|
// in imputing the knowledge that all we're dealing with is the rollover from 159 to 0,
|
|
|
|
// this is faster than the straightforward +1)%160 per profiling
|
2016-05-17 01:54:27 +00:00
|
|
|
//#define increment_object_counter(c) _objectCounter[c] = (_objectCounter[c]+1)&~((158-_objectCounter[c]) >> 8)
|
2015-08-13 20:50:24 +00:00
|
|
|
|
2015-08-16 20:08:29 +00:00
|
|
|
void Machine::output_pixels(unsigned int count)
|
2015-07-19 20:48:14 +00:00
|
|
|
{
|
|
|
|
while(count--)
|
|
|
|
{
|
2015-07-28 02:12:13 +00:00
|
|
|
OutputState state;
|
|
|
|
|
2016-05-18 01:41:32 +00:00
|
|
|
// determine which output will start in four cycles
|
2016-05-16 12:01:29 +00:00
|
|
|
switch(_horizontalTimer >> 2)
|
|
|
|
{
|
2016-05-18 01:41:32 +00:00
|
|
|
case 56: case 0: case 1: case 2: state = OutputState::Blank; break;
|
2016-05-17 01:54:27 +00:00
|
|
|
case 3: case 4: case 5: case 6: state = OutputState::Sync; break;
|
|
|
|
case 7: case 8: case 9: case 10: state = OutputState::ColourBurst; break;
|
2016-05-17 23:02:32 +00:00
|
|
|
case 11: case 12: case 13:
|
2016-05-18 01:41:32 +00:00
|
|
|
case 14: case 15: state = OutputState::Blank; break;
|
|
|
|
|
|
|
|
case 16: case 17: state = _vBlankExtend ? OutputState::Blank : OutputState::Pixel; break;
|
2016-05-16 23:04:13 +00:00
|
|
|
default: state = OutputState::Pixel; break;
|
2015-08-20 01:36:33 +00:00
|
|
|
}
|
|
|
|
|
2016-05-16 23:04:13 +00:00
|
|
|
// if vsync is enabled, output the opposite of the automatic hsync output
|
2015-08-20 01:36:33 +00:00
|
|
|
if(_vSyncEnabled) {
|
|
|
|
state = (state = OutputState::Sync) ? OutputState::Blank : OutputState::Sync;
|
2015-07-19 20:48:14 +00:00
|
|
|
}
|
2015-07-16 23:56:02 +00:00
|
|
|
|
2016-05-17 01:54:27 +00:00
|
|
|
// write that state as the one that will become effective in four clocks
|
2016-05-18 01:41:32 +00:00
|
|
|
_upcomingEvents[(_upcomingEventsPointer+4)%number_of_upcoming_events].state = state;
|
2016-05-17 01:54:27 +00:00
|
|
|
|
|
|
|
// grab pixel state if desired
|
|
|
|
if(state == OutputState::Pixel)
|
|
|
|
{
|
|
|
|
update_upcoming_event();
|
|
|
|
}
|
2016-05-16 12:01:29 +00:00
|
|
|
|
2016-05-17 11:09:18 +00:00
|
|
|
// apply any queued changes and flush the record
|
2016-05-17 01:54:27 +00:00
|
|
|
if(_upcomingEvents[_upcomingEventsPointer].updates & Event::Action::Playfield)
|
|
|
|
_playfieldOutput = _upcomingEvents[_upcomingEventsPointer].playfieldOutput;
|
2016-05-17 22:35:40 +00:00
|
|
|
|
2016-05-18 01:41:32 +00:00
|
|
|
if(_upcomingEvents[_upcomingEventsPointer].updates & Event::Action::ResetPixelCounter)
|
|
|
|
{
|
|
|
|
for(int c = 0; c < 5; c++)
|
|
|
|
{
|
|
|
|
if(_upcomingEvents[_upcomingEventsPointer].pixelCounterMask & (1 << c))
|
|
|
|
_pixelCounter[c] = 0;
|
|
|
|
}
|
|
|
|
_upcomingEvents[_upcomingEventsPointer].pixelCounterMask = 0;
|
|
|
|
}
|
2016-05-17 22:35:40 +00:00
|
|
|
|
|
|
|
if(_upcomingEvents[_upcomingEventsPointer].updates & Event::Action::HMoveCompare)
|
|
|
|
{
|
|
|
|
for(int c = 0; c < 5; c++)
|
|
|
|
{
|
|
|
|
if((_objectMotion[c]^8^_hMoveCounter) == 0xf)
|
|
|
|
{
|
|
|
|
_hMoveFlags &= ~(1 << c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(_hMoveFlags)
|
|
|
|
{
|
|
|
|
if(_hMoveCounter) _hMoveCounter--;
|
|
|
|
_upcomingEvents[(_upcomingEventsPointer+4)%number_of_upcoming_events].updates |= Event::Action::HMoveCompare;
|
|
|
|
_upcomingEvents[(_upcomingEventsPointer+2)%number_of_upcoming_events].updates |= Event::Action::HMoveDecrement;
|
2016-05-18 01:41:32 +00:00
|
|
|
}
|
2016-05-17 22:35:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(_upcomingEvents[_upcomingEventsPointer].updates & Event::Action::HMoveDecrement)
|
|
|
|
{
|
|
|
|
for(int c = 0; c < 5; c++)
|
|
|
|
{
|
|
|
|
if(_hMoveFlags & (1 << c))
|
|
|
|
{
|
|
|
|
_objectCounter[c] = (_objectCounter[c] + 1)%160;
|
2016-05-18 01:41:32 +00:00
|
|
|
_pixelCounter[c] ++;
|
2016-05-17 22:35:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-05-17 11:09:18 +00:00
|
|
|
_upcomingEvents[_upcomingEventsPointer].updates = 0;
|
2016-05-17 01:54:27 +00:00
|
|
|
|
|
|
|
// read that state
|
|
|
|
state = _upcomingEvents[_upcomingEventsPointer].state;
|
|
|
|
|
|
|
|
// decide what that means needs to be communicated to the CRT
|
2015-07-28 02:12:13 +00:00
|
|
|
_lastOutputStateDuration++;
|
2016-04-25 02:32:24 +00:00
|
|
|
if(state != _lastOutputState) {
|
|
|
|
switch(_lastOutputState) {
|
2016-04-26 00:56:15 +00:00
|
|
|
case OutputState::Blank: _crt->output_blank(_lastOutputStateDuration); break;
|
|
|
|
case OutputState::Sync: _crt->output_sync(_lastOutputStateDuration); break;
|
|
|
|
case OutputState::ColourBurst: _crt->output_colour_burst(_lastOutputStateDuration, 96, 0); break;
|
|
|
|
case OutputState::Pixel: _crt->output_data(_lastOutputStateDuration, 1); break;
|
2015-07-28 02:12:13 +00:00
|
|
|
}
|
|
|
|
_lastOutputStateDuration = 0;
|
|
|
|
_lastOutputState = state;
|
|
|
|
|
2016-04-25 02:32:24 +00:00
|
|
|
if(state == OutputState::Pixel) {
|
2016-03-19 21:37:55 +00:00
|
|
|
_outputBuffer = _crt->allocate_write_area(160);
|
2015-08-12 23:31:57 +00:00
|
|
|
} else {
|
|
|
|
_outputBuffer = nullptr;
|
2015-07-28 02:12:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-17 01:54:27 +00:00
|
|
|
// decide on a pixel colour if that's what's happening
|
2016-05-16 23:04:13 +00:00
|
|
|
if(state == OutputState::Pixel)
|
|
|
|
{
|
|
|
|
uint8_t colour = get_output_pixel();
|
|
|
|
if(_outputBuffer)
|
|
|
|
{
|
|
|
|
*_outputBuffer = colour;
|
|
|
|
_outputBuffer++;
|
|
|
|
}
|
|
|
|
}
|
2016-05-17 01:54:27 +00:00
|
|
|
|
2016-05-17 11:09:18 +00:00
|
|
|
// advance
|
|
|
|
_upcomingEventsPointer = (_upcomingEventsPointer + 1)%number_of_upcoming_events;
|
|
|
|
|
2016-05-17 01:54:27 +00:00
|
|
|
// advance horizontal timer, perform reset actions if requested
|
2016-05-16 12:01:29 +00:00
|
|
|
_horizontalTimer = (_horizontalTimer + 1) % horizontalTimerPeriod;
|
2016-05-16 23:04:13 +00:00
|
|
|
if(!_horizontalTimer)
|
|
|
|
{
|
|
|
|
_vBlankExtend = false;
|
2016-05-16 23:55:56 +00:00
|
|
|
set_ready_line(false);
|
2016-05-16 23:04:13 +00:00
|
|
|
}
|
2015-07-16 23:56:02 +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
|
|
|
{
|
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-16 20:08:29 +00:00
|
|
|
unsigned int cycles_run_for = 1;
|
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.
|
2015-08-09 06:42:01 +00:00
|
|
|
if(operation == CPU6502::BusOperation::Ready) {
|
2016-05-16 12:01:29 +00:00
|
|
|
unsigned int distance_to_end_of_ready = horizontalTimerPeriod - _horizontalTimer;
|
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
|
|
|
}
|
2015-07-16 23:56:02 +00:00
|
|
|
|
2016-05-16 23:55:56 +00:00
|
|
|
output_pixels(cycles_run_for * 3);
|
|
|
|
|
2016-05-16 12:01:29 +00:00
|
|
|
// if(_hMoveWillCount) {
|
|
|
|
// _hMoveCounter = 0x0f;
|
|
|
|
// _hMoveFlags = 0x1f;
|
|
|
|
// _hMoveIsCounting = true;
|
|
|
|
// _hMoveWillCount = false;
|
|
|
|
// }
|
2015-08-13 17:59:23 +00:00
|
|
|
|
2015-07-31 20:54:20 +00:00
|
|
|
if(operation != CPU6502::BusOperation::Ready) {
|
2015-08-09 06:42:01 +00:00
|
|
|
|
2015-08-13 14:04:30 +00:00
|
|
|
// check for a paging access
|
|
|
|
if(_rom_size > 4096 && ((address & 0x1f00) == 0x1f00)) {
|
|
|
|
uint8_t *base_ptr = _romPages[0];
|
2015-08-16 20:08:29 +00:00
|
|
|
uint8_t first_paging_register = (uint8_t)(0xf8 - (_rom_size >> 14)*2);
|
2015-08-13 14:04:30 +00:00
|
|
|
|
|
|
|
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];
|
2015-08-13 12:24:02 +00:00
|
|
|
}
|
2015-08-13 14:04:30 +00:00
|
|
|
}
|
2015-08-13 12:24:02 +00:00
|
|
|
|
2015-08-13 14:04:30 +00:00
|
|
|
if(base_ptr != _romPages[0]) {
|
|
|
|
_romPages[0] = base_ptr;
|
|
|
|
_romPages[1] = base_ptr + 1024;
|
|
|
|
_romPages[2] = base_ptr + 2048;
|
|
|
|
_romPages[3] = base_ptr + 3072;
|
2015-08-13 12:24:02 +00:00
|
|
|
}
|
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
|
2016-04-25 02:32:24 +00:00
|
|
|
if((address&0x1000) && isReadOperation(operation)) {
|
2015-08-13 12:24:02 +00:00
|
|
|
returnValue &= _romPages[(address >> 10)&3][address&1023];
|
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)) {
|
|
|
|
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
|
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
|
|
|
|
returnValue &= _collisions[decodedAddress];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x08:
|
|
|
|
case 0x09:
|
|
|
|
case 0x0a:
|
|
|
|
case 0x0b:
|
|
|
|
// TODO: pot ports
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x0c:
|
|
|
|
case 0x0d:
|
2015-08-19 00:58:05 +00:00
|
|
|
returnValue &= _tiaInputValue[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) {
|
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;
|
|
|
|
|
2015-08-13 22:23:04 +00:00
|
|
|
case 0x0a: {
|
|
|
|
uint8_t old_playfield_control = _playfieldControl;
|
|
|
|
_playfieldControl = *value;
|
|
|
|
|
|
|
|
// did the mirroring bit change?
|
|
|
|
if((_playfieldControl^old_playfield_control)&1) {
|
|
|
|
if(_playfieldControl&1) {
|
|
|
|
for(int c = 0; c < 20; c++) _playfield[c+20] = _playfield[19-c];
|
|
|
|
} else {
|
|
|
|
memcpy(&_playfield[20], _playfield, 20);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} break;
|
2015-08-12 23:31:57 +00:00
|
|
|
case 0x0b:
|
|
|
|
case 0x0c: _playerReflection[decodedAddress - 0x0b] = *value; break;
|
2015-08-13 20:32:22 +00:00
|
|
|
|
2015-08-12 23:31:57 +00:00
|
|
|
case 0x0d:
|
2015-08-13 20:32:22 +00:00
|
|
|
_playfield[0] = ((*value) >> 4)&1;
|
|
|
|
_playfield[1] = ((*value) >> 5)&1;
|
|
|
|
_playfield[2] = ((*value) >> 6)&1;
|
|
|
|
_playfield[3] = (*value) >> 7;
|
2015-08-13 22:23:04 +00:00
|
|
|
|
|
|
|
if(_playfieldControl&1) {
|
|
|
|
for(int c = 0; c < 4; c++) _playfield[39-c] = _playfield[c];
|
|
|
|
} else {
|
|
|
|
memcpy(&_playfield[20], _playfield, 4);
|
|
|
|
}
|
2015-08-13 20:32:22 +00:00
|
|
|
break;
|
2015-08-12 23:31:57 +00:00
|
|
|
case 0x0e:
|
2015-08-13 20:32:22 +00:00
|
|
|
_playfield[4] = (*value) >> 7;
|
|
|
|
_playfield[5] = ((*value) >> 6)&1;
|
|
|
|
_playfield[6] = ((*value) >> 5)&1;
|
|
|
|
_playfield[7] = ((*value) >> 4)&1;
|
|
|
|
_playfield[8] = ((*value) >> 3)&1;
|
|
|
|
_playfield[9] = ((*value) >> 2)&1;
|
|
|
|
_playfield[10] = ((*value) >> 1)&1;
|
|
|
|
_playfield[11] = (*value)&1;
|
2015-08-13 22:23:04 +00:00
|
|
|
|
|
|
|
if(_playfieldControl&1) {
|
|
|
|
for(int c = 0; c < 8; c++) _playfield[35-c] = _playfield[c+4];
|
|
|
|
} else {
|
|
|
|
memcpy(&_playfield[24], &_playfield[4], 8);
|
|
|
|
}
|
2015-08-13 20:32:22 +00:00
|
|
|
break;
|
|
|
|
case 0x0f:
|
|
|
|
_playfield[19] = (*value) >> 7;
|
|
|
|
_playfield[18] = ((*value) >> 6)&1;
|
|
|
|
_playfield[17] = ((*value) >> 5)&1;
|
|
|
|
_playfield[16] = ((*value) >> 4)&1;
|
|
|
|
_playfield[15] = ((*value) >> 3)&1;
|
|
|
|
_playfield[14] = ((*value) >> 2)&1;
|
|
|
|
_playfield[13] = ((*value) >> 1)&1;
|
|
|
|
_playfield[12] = (*value)&1;
|
2015-08-13 22:23:04 +00:00
|
|
|
|
|
|
|
if(_playfieldControl&1) {
|
|
|
|
for(int c = 0; c < 8; c++) _playfield[27-c] = _playfield[c+12];
|
|
|
|
} else {
|
|
|
|
memcpy(&_playfield[32], &_playfield[12], 8);
|
|
|
|
}
|
2015-08-13 20:32:22 +00:00
|
|
|
break;
|
2015-08-12 23:31:57 +00:00
|
|
|
|
|
|
|
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:
|
2015-08-13 17:59:23 +00:00
|
|
|
case 0x24:
|
2016-05-17 22:35:40 +00:00
|
|
|
_objectMotion[decodedAddress - 0x20] = (*value) & 0xf;
|
2015-08-13 17:59:23 +00:00
|
|
|
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:
|
2016-04-25 02:32:24 +00:00
|
|
|
if(!(*value&0x02) && _missileGraphicsReset[decodedAddress - 0x28]&0x02)
|
2015-08-10 15:55:16 +00:00
|
|
|
_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;
|
2016-05-17 22:21:49 +00:00
|
|
|
|
|
|
|
// clear any ongoing moves
|
|
|
|
if(_hMoveFlags)
|
|
|
|
{
|
|
|
|
for(int c = 0; c < number_of_upcoming_events; c++)
|
|
|
|
{
|
|
|
|
_upcomingEvents[c].updates &= ~(Event::Action::HMoveCompare | Event::Action::HMoveDecrement);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// schedule new moves
|
|
|
|
_hMoveFlags = 0x1f;
|
|
|
|
_hMoveCounter = 15;
|
|
|
|
_upcomingEvents[(_upcomingEventsPointer + 15)%number_of_upcoming_events].updates |= Event::Action::HMoveCompare;
|
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
|
|
|
// check for a PIA access
|
2016-04-25 02:32:24 +00:00
|
|
|
if((address&0x1280) == 0x280) {
|
2015-07-31 20:54:20 +00:00
|
|
|
if(isReadOperation(operation)) {
|
2015-08-19 00:33:24 +00:00
|
|
|
const uint8_t decodedAddress = address & 0xf;
|
2015-07-31 20:54:20 +00:00
|
|
|
switch(address & 0xf) {
|
2015-08-12 23:31:57 +00:00
|
|
|
case 0x00:
|
|
|
|
case 0x02:
|
2015-08-19 00:33:24 +00:00
|
|
|
returnValue &= _piaDataValue[decodedAddress / 2];
|
2015-08-12 23:31:57 +00:00
|
|
|
break;
|
2015-08-19 00:33:24 +00:00
|
|
|
case 0x01:
|
2015-08-12 23:31:57 +00:00
|
|
|
case 0x03:
|
2015-08-19 00:33:24 +00:00
|
|
|
// TODO: port DDR
|
2015-08-12 23:31:57 +00:00
|
|
|
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 {
|
2015-08-16 20:08:29 +00:00
|
|
|
const uint8_t decodedAddress = address & 0x0f;
|
|
|
|
switch(decodedAddress) {
|
|
|
|
case 0x04:
|
|
|
|
case 0x05:
|
|
|
|
case 0x06:
|
|
|
|
case 0x07:
|
|
|
|
_writtenPiaTimerShift = _piaTimerShift = (decodedAddress - 0x04) * 3 + (decodedAddress / 0x07);
|
|
|
|
_piaTimerValue = (unsigned int)(*value << _piaTimerShift);
|
|
|
|
_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
|
|
|
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
|
|
|
|
2016-05-16 23:55:56 +00:00
|
|
|
// output_pixels(cycles_run_for * 3);
|
|
|
|
|
2015-08-12 23:31:57 +00:00
|
|
|
return cycles_run_for;
|
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) {
|
2015-08-19 00:58:05 +00:00
|
|
|
case Atari2600DigitalInputJoy1Up: if(state) _piaDataValue[0] &= ~0x10; else _piaDataValue[0] |= 0x10; break;
|
|
|
|
case Atari2600DigitalInputJoy1Down: if(state) _piaDataValue[0] &= ~0x20; else _piaDataValue[0] |= 0x20; break;
|
|
|
|
case Atari2600DigitalInputJoy1Left: if(state) _piaDataValue[0] &= ~0x40; else _piaDataValue[0] |= 0x40; break;
|
|
|
|
case Atari2600DigitalInputJoy1Right: if(state) _piaDataValue[0] &= ~0x80; else _piaDataValue[0] |= 0x80; break;
|
|
|
|
|
|
|
|
case Atari2600DigitalInputJoy2Up: if(state) _piaDataValue[0] &= ~0x01; else _piaDataValue[0] |= 0x01; break;
|
|
|
|
case Atari2600DigitalInputJoy2Down: if(state) _piaDataValue[0] &= ~0x02; else _piaDataValue[0] |= 0x02; break;
|
|
|
|
case Atari2600DigitalInputJoy2Left: if(state) _piaDataValue[0] &= ~0x04; else _piaDataValue[0] |= 0x04; break;
|
|
|
|
case Atari2600DigitalInputJoy2Right: if(state) _piaDataValue[0] &= ~0x08; else _piaDataValue[0] |= 0x08; break;
|
|
|
|
|
|
|
|
// TODO: latching
|
|
|
|
case Atari2600DigitalInputJoy1Fire: if(state) _tiaInputValue[0] &= ~0x80; else _tiaInputValue[0] |= 0x80; break;
|
|
|
|
case Atari2600DigitalInputJoy2Fire: if(state) _tiaInputValue[1] &= ~0x80; else _tiaInputValue[1] |= 0x80; break;
|
2015-08-19 00:33:24 +00:00
|
|
|
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-16 23:56:02 +00:00
|
|
|
void Machine::set_rom(size_t length, const uint8_t *data)
|
|
|
|
{
|
2015-08-13 12:24:02 +00:00
|
|
|
_rom_size = 1024;
|
|
|
|
while(_rom_size < length && _rom_size < 32768) _rom_size <<= 1;
|
|
|
|
|
|
|
|
delete[] _rom;
|
2015-08-17 04:34:01 +00:00
|
|
|
|
2015-08-13 12:24:02 +00:00
|
|
|
_rom = new uint8_t[_rom_size];
|
2015-08-17 04:34:01 +00:00
|
|
|
|
|
|
|
size_t offset = 0;
|
|
|
|
const size_t copy_step = std::min(_rom_size, length);
|
|
|
|
while(offset < _rom_size)
|
|
|
|
{
|
|
|
|
size_t copy_length = std::min(copy_step, _rom_size - offset);
|
|
|
|
memcpy(&_rom[offset], data, copy_length);
|
|
|
|
offset += copy_length;
|
|
|
|
}
|
2015-08-13 12:24:02 +00:00
|
|
|
|
|
|
|
size_t romMask = _rom_size - 1;
|
|
|
|
_romPages[0] = _rom;
|
|
|
|
_romPages[1] = &_rom[1024 & romMask];
|
|
|
|
_romPages[2] = &_rom[2048 & romMask];
|
|
|
|
_romPages[3] = &_rom[3072 & romMask];
|
2015-07-16 23:56:02 +00:00
|
|
|
}
|