2005-03-14 04:08:15 +00:00
|
|
|
//============================================================================
|
|
|
|
//
|
|
|
|
// SSSS tt lll lll
|
|
|
|
// SS SS tt ll ll
|
|
|
|
// SS tttttt eeee ll ll aaaa
|
|
|
|
// SSSS tt ee ee ll ll aa
|
|
|
|
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
|
|
|
|
// SS SS tt ee ll ll aa aa
|
|
|
|
// SSSS ttt eeeee llll llll aaaaa
|
|
|
|
//
|
2011-01-01 16:04:32 +00:00
|
|
|
// Copyright (c) 1995-2011 by Bradford W. Mott, Stephen Anthony
|
2010-04-10 21:37:23 +00:00
|
|
|
// and the Stella Team
|
2005-03-14 04:08:15 +00:00
|
|
|
//
|
2010-01-10 03:23:32 +00:00
|
|
|
// See the file "License.txt" for information on usage and redistribution of
|
2005-03-14 04:08:15 +00:00
|
|
|
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
|
|
|
//
|
2009-05-13 13:55:40 +00:00
|
|
|
// $Id$
|
2005-03-14 04:08:15 +00:00
|
|
|
//
|
|
|
|
// Based on code from ScummVM - Scumm Interpreter
|
|
|
|
// Copyright (C) 2002-2004 The ScummVM project
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
#ifndef ARRAY_HXX
|
|
|
|
#define ARRAY_HXX
|
|
|
|
|
Added RiotDebug class, which for now only duplicates the previous
functionality of the Debugger::riotState() method. It will become
more useful when I add a RIOT tab to the debugger. Also, added
change tracking infrastructure.
Fixed long-standing bug with viewing the contents of TIM{1, 8, 64, 1024}T
registers. Apparently, the output generated by the 'riot' debugger
command showed either INTIM or TIMINT for those registers, and not the
actual value written to those registers.
Added INTIM, TIMINT, and TIMCLKS to the riot output, which show the
current values of the timer, the timer interrupt, and the number of
'timer clocks' resulting from writing to a timer register.
Cleaned up some of the debugger API, removing pointers and using
references instead.
git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@1479 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
2008-04-19 21:11:52 +00:00
|
|
|
#include <cassert>
|
2005-03-14 04:08:15 +00:00
|
|
|
|
|
|
|
#include "bspf.hxx"
|
|
|
|
|
Moved the Array class from namespace GUI to Common, since it's used in
many places other than the GUI code.
As a diversion from the joystick stuff, I'm experimenting with event
recording. Eventually, this will allow one to record a state + events,
and then load that INP file again. When loaded, Stella will replay the
events, and you'll be able to see exactly what happened before. Since
this is based on frames, the replaying can speed up and slow
down by changing the emulation framerate. And it can be exited at any
point, and normal emulation can continue. Or at least that's how I
want it to work.
A preliminary spec for the event stream is -X A B A B ... -X ...,
where X represents how many frames to wait, and 'A B' are event/value
pairs representing an event in Stella. I think this is very similar
to the scheme that Thomas J. recently added to z26, so converting to
a Stella eventstream should be easy.
git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@905 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
2005-12-09 01:16:14 +00:00
|
|
|
namespace Common {
|
2005-06-02 21:37:33 +00:00
|
|
|
|
2005-03-14 04:08:15 +00:00
|
|
|
template <class T>
|
|
|
|
class Array
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
int _capacity;
|
|
|
|
int _size;
|
|
|
|
T *_data;
|
|
|
|
|
|
|
|
public:
|
|
|
|
typedef T *iterator;
|
|
|
|
typedef const T *const_iterator;
|
|
|
|
|
|
|
|
public:
|
|
|
|
Array<T>() : _capacity(0), _size(0), _data(0) {}
|
|
|
|
Array<T>(const Array<T>& array) : _capacity(0), _size(0), _data(0)
|
|
|
|
{
|
|
|
|
_size = array._size;
|
2005-12-09 19:09:49 +00:00
|
|
|
_capacity = _size + 128;
|
2005-03-14 04:08:15 +00:00
|
|
|
_data = new T[_capacity];
|
|
|
|
for(int i = 0; i < _size; i++)
|
|
|
|
_data[i] = array._data[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
~Array<T>()
|
|
|
|
{
|
|
|
|
if (_data)
|
|
|
|
delete [] _data;
|
|
|
|
}
|
|
|
|
|
|
|
|
void push_back(const T& element)
|
|
|
|
{
|
|
|
|
ensureCapacity(_size + 1);
|
|
|
|
_data[_size++] = element;
|
|
|
|
}
|
|
|
|
|
|
|
|
void push_back(const Array<T>& array)
|
|
|
|
{
|
|
|
|
ensureCapacity(_size + array._size);
|
|
|
|
for(int i = 0; i < array._size; i++)
|
|
|
|
_data[_size++] = array._data[i];
|
|
|
|
}
|
|
|
|
|
2010-08-16 16:41:24 +00:00
|
|
|
void push_back_unique(const T& element)
|
|
|
|
{
|
|
|
|
if(!contains(element))
|
|
|
|
{
|
|
|
|
ensureCapacity(_size + 1);
|
|
|
|
_data[_size++] = element;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-03-14 04:08:15 +00:00
|
|
|
void insert_at(int idx, const T& element)
|
|
|
|
{
|
|
|
|
assert(idx >= 0 && idx <= _size);
|
|
|
|
ensureCapacity(_size + 1);
|
|
|
|
// The following loop is not efficient if you can just memcpy things around.
|
|
|
|
// e.g. if you have a list of ints. But for real objects (String...), memcpy
|
|
|
|
// usually isn't correct (specifically, for any class which has a non-default
|
|
|
|
// copy behaviour. E.g. the String class uses a refCounter which has to be
|
|
|
|
// updated whenever a String is copied.
|
|
|
|
for(int i = _size; i > idx; i--)
|
|
|
|
_data[i] = _data[i-1];
|
|
|
|
|
|
|
|
_data[idx] = element;
|
|
|
|
_size++;
|
|
|
|
}
|
|
|
|
|
|
|
|
T remove_at(int idx)
|
|
|
|
{
|
|
|
|
assert(idx >= 0 && idx < _size);
|
|
|
|
T tmp = _data[idx];
|
|
|
|
for(int i = idx; i < _size - 1; i++)
|
|
|
|
_data[i] = _data[i+1];
|
|
|
|
_size--;
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: insert, remove, ...
|
|
|
|
|
|
|
|
T& operator [](int idx)
|
|
|
|
{
|
|
|
|
assert(idx >= 0 && idx < _size);
|
|
|
|
return _data[idx];
|
|
|
|
}
|
|
|
|
|
|
|
|
const T& operator [](int idx) const
|
|
|
|
{
|
|
|
|
assert(idx >= 0 && idx < _size);
|
|
|
|
return _data[idx];
|
|
|
|
}
|
|
|
|
|
2011-05-24 16:04:48 +00:00
|
|
|
Array<T>& operator =(const Array<T>& array)
|
2005-03-14 04:08:15 +00:00
|
|
|
{
|
|
|
|
if (_data)
|
|
|
|
delete [] _data;
|
|
|
|
_size = array._size;
|
2005-12-09 19:09:49 +00:00
|
|
|
_capacity = _size + 128;
|
2005-03-14 04:08:15 +00:00
|
|
|
_data = new T[_capacity];
|
|
|
|
for(int i = 0; i < _size; i++)
|
|
|
|
_data[i] = array._data[i];
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2005-05-13 01:03:27 +00:00
|
|
|
unsigned int size() const { return _size; }
|
2005-03-14 04:08:15 +00:00
|
|
|
|
|
|
|
void clear()
|
|
|
|
{
|
2005-04-04 02:19:22 +00:00
|
|
|
if(_data)
|
|
|
|
{
|
|
|
|
delete [] _data;
|
|
|
|
_data = 0;
|
|
|
|
}
|
|
|
|
_size = 0;
|
|
|
|
_capacity = 0;
|
|
|
|
}
|
2005-03-14 04:08:15 +00:00
|
|
|
|
2005-04-04 02:19:22 +00:00
|
|
|
bool isEmpty() const
|
|
|
|
{
|
|
|
|
return (_size == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
iterator begin()
|
|
|
|
{
|
|
|
|
return _data;
|
|
|
|
}
|
|
|
|
|
|
|
|
iterator end()
|
|
|
|
{
|
|
|
|
return _data + _size;
|
|
|
|
}
|
|
|
|
|
|
|
|
const_iterator begin() const
|
|
|
|
{
|
|
|
|
return _data;
|
|
|
|
}
|
|
|
|
|
|
|
|
const_iterator end() const
|
|
|
|
{
|
|
|
|
return _data + _size;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool contains(const T &key) const
|
|
|
|
{
|
|
|
|
for (const_iterator i = begin(); i != end(); ++i) {
|
|
|
|
if (*i == key)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void ensureCapacity(int new_len)
|
|
|
|
{
|
|
|
|
if (new_len <= _capacity)
|
|
|
|
return;
|
|
|
|
|
|
|
|
T *old_data = _data;
|
2005-12-09 19:09:49 +00:00
|
|
|
_capacity = new_len + 128;
|
2005-04-04 02:19:22 +00:00
|
|
|
_data = new T[_capacity];
|
|
|
|
|
|
|
|
if (old_data)
|
|
|
|
{
|
|
|
|
// Copy old data
|
|
|
|
for (int i = 0; i < _size; i++)
|
|
|
|
_data[i] = old_data[i];
|
|
|
|
delete [] old_data;
|
|
|
|
}
|
|
|
|
}
|
2005-03-14 04:08:15 +00:00
|
|
|
};
|
|
|
|
|
2010-08-19 21:48:28 +00:00
|
|
|
} // Namespace Common
|
2005-06-02 21:37:33 +00:00
|
|
|
|
Moved the Array class from namespace GUI to Common, since it's used in
many places other than the GUI code.
As a diversion from the joystick stuff, I'm experimenting with event
recording. Eventually, this will allow one to record a state + events,
and then load that INP file again. When loaded, Stella will replay the
events, and you'll be able to see exactly what happened before. Since
this is based on frames, the replaying can speed up and slow
down by changing the emulation framerate. And it can be exited at any
point, and normal emulation can continue. Or at least that's how I
want it to work.
A preliminary spec for the event stream is -X A B A B ... -X ...,
where X represents how many frames to wait, and 'A B' are event/value
pairs representing an event in Stella. I think this is very similar
to the scheme that Thomas J. recently added to z26, so converting to
a Stella eventstream should be easy.
git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@905 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
2005-12-09 01:16:14 +00:00
|
|
|
typedef Common::Array<int> IntArray;
|
|
|
|
typedef Common::Array<bool> BoolArray;
|
|
|
|
typedef Common::Array<uInt8> ByteArray;
|
2005-07-02 18:34:54 +00:00
|
|
|
|
2005-03-14 04:08:15 +00:00
|
|
|
#endif
|