2019-03-09 05:00:23 +00:00
|
|
|
|
//
|
|
|
|
|
// 68000.hpp
|
|
|
|
|
// Clock Signal
|
|
|
|
|
//
|
|
|
|
|
// Created by Thomas Harte on 08/03/2019.
|
|
|
|
|
// Copyright © 2019 Thomas Harte. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#ifndef MC68000_h
|
|
|
|
|
#define MC68000_h
|
|
|
|
|
|
2019-07-25 02:13:32 +00:00
|
|
|
|
#include <cassert>
|
2019-03-09 05:00:23 +00:00
|
|
|
|
#include <cstdint>
|
2019-05-03 18:48:39 +00:00
|
|
|
|
#include <cstring>
|
2019-03-12 02:47:58 +00:00
|
|
|
|
#include <iomanip>
|
2019-03-10 21:27:34 +00:00
|
|
|
|
#include <iostream>
|
2019-07-25 02:02:50 +00:00
|
|
|
|
#include <limits>
|
2019-05-03 18:48:39 +00:00
|
|
|
|
#include <ostream>
|
2019-05-03 18:50:07 +00:00
|
|
|
|
#include <vector>
|
2019-03-09 05:00:23 +00:00
|
|
|
|
|
2019-07-09 23:55:30 +00:00
|
|
|
|
#include "../../ClockReceiver/ForceInline.hpp"
|
2019-03-09 05:00:23 +00:00
|
|
|
|
#include "../../ClockReceiver/ClockReceiver.hpp"
|
2019-03-10 21:27:34 +00:00
|
|
|
|
#include "../RegisterSizes.hpp"
|
2019-03-09 05:00:23 +00:00
|
|
|
|
|
|
|
|
|
namespace CPU {
|
|
|
|
|
namespace MC68000 {
|
|
|
|
|
|
2019-03-10 21:27:34 +00:00
|
|
|
|
/*!
|
|
|
|
|
A microcycle is an atomic unit of 68000 bus activity — it is a single item large enough
|
|
|
|
|
fully to specify a sequence of bus events that occur without any possible interruption.
|
|
|
|
|
|
|
|
|
|
Concretely, a standard read cycle breaks down into at least two microcycles:
|
|
|
|
|
|
2019-05-03 18:20:59 +00:00
|
|
|
|
1) a 4 half-cycle length microcycle in which the address strobe is signalled; and
|
|
|
|
|
2) a 4 half-cycle length microcycle in which at least one of the data strobes is
|
2019-03-10 21:27:34 +00:00
|
|
|
|
signalled, and the data bus is sampled.
|
|
|
|
|
|
|
|
|
|
That is, assuming DTack were signalled when microcycle (1) ended. If not then additional
|
|
|
|
|
wait state microcycles would fall between those two parts.
|
|
|
|
|
|
|
|
|
|
The 68000 data sheet defines when the address becomes valid during microcycle (1), and
|
|
|
|
|
when the address strobe is actually asserted. But those timings are fixed. So simply
|
|
|
|
|
telling you that this was a microcycle during which the address trobe was signalled is
|
|
|
|
|
sufficient fully to describe the bus activity.
|
|
|
|
|
|
|
|
|
|
(Aside: see the 68000 template's definition for options re: implicit DTack; if your
|
|
|
|
|
68000 owner can always predict exactly how long it will hold DTack following observation
|
|
|
|
|
of an address-strobing microcycle, it can just supply those periods for accounting and
|
|
|
|
|
avoid the runtime cost of actual DTack emulation. But such as the bus allows.)
|
|
|
|
|
*/
|
2019-03-09 05:00:23 +00:00
|
|
|
|
struct Microcycle {
|
2019-12-09 01:19:44 +00:00
|
|
|
|
/// Indicates that the address strobe and exactly one of the data strobes are active; you can determine
|
|
|
|
|
/// which by inspecting the low bit of the provided address. The RW line indicates a read.
|
|
|
|
|
static const int SelectByte = 1 << 0;
|
|
|
|
|
// Maintenance note: this is bit 0 to reduce the cost of getting a host-endian
|
|
|
|
|
// bytewise address. See implementation of host_endian_byte_address().
|
|
|
|
|
|
|
|
|
|
/// Indicates that the address and both data select strobes are active.
|
|
|
|
|
static const int SelectWord = 1 << 1;
|
|
|
|
|
|
2019-03-16 21:54:58 +00:00
|
|
|
|
/// A NewAddress cycle is one in which the address strobe is initially low but becomes high;
|
|
|
|
|
/// this correlates to states 0 to 5 of a standard read/write cycle.
|
2019-12-09 01:19:44 +00:00
|
|
|
|
static const int NewAddress = 1 << 2;
|
2019-03-16 21:54:58 +00:00
|
|
|
|
|
|
|
|
|
/// A SameAddress cycle is one in which the address strobe is continuously asserted, but neither
|
|
|
|
|
/// of the data strobes are.
|
2019-12-09 01:19:44 +00:00
|
|
|
|
static const int SameAddress = 1 << 3;
|
2019-03-16 21:54:58 +00:00
|
|
|
|
|
2019-03-30 03:40:54 +00:00
|
|
|
|
/// A Reset cycle is one in which the RESET output is asserted.
|
2019-12-09 01:19:44 +00:00
|
|
|
|
static const int Reset = 1 << 4;
|
2019-03-16 21:54:58 +00:00
|
|
|
|
|
|
|
|
|
/// If set, indicates a read. Otherwise, a write.
|
2019-05-03 18:20:59 +00:00
|
|
|
|
static const int Read = 1 << 5;
|
2019-03-16 21:54:58 +00:00
|
|
|
|
|
2019-05-02 01:59:06 +00:00
|
|
|
|
/// Contains the value of line FC0 if it is not implicit via InterruptAcknowledge.
|
2019-05-03 18:20:59 +00:00
|
|
|
|
static const int IsData = 1 << 6;
|
2019-03-16 21:54:58 +00:00
|
|
|
|
|
2019-05-02 01:59:06 +00:00
|
|
|
|
/// Contains the value of line FC1 if it is not implicit via InterruptAcknowledge.
|
2019-05-03 18:20:59 +00:00
|
|
|
|
static const int IsProgram = 1 << 7;
|
2019-03-10 21:42:13 +00:00
|
|
|
|
|
2019-05-02 01:59:06 +00:00
|
|
|
|
/// The interrupt acknowledge cycle is that during which the 68000 seeks to obtain the vector for
|
|
|
|
|
/// an interrupt it plans to observe. Noted on a real 68000 by all FCs being set to 1.
|
2019-05-03 18:20:59 +00:00
|
|
|
|
static const int InterruptAcknowledge = 1 << 8;
|
2019-05-02 01:59:06 +00:00
|
|
|
|
|
2019-05-03 18:20:59 +00:00
|
|
|
|
/// Represents the state of the 68000's valid memory address line — indicating whether this microcycle
|
|
|
|
|
/// is synchronised with the E clock to satisfy a valid peripheral address request.
|
|
|
|
|
static const int IsPeripheral = 1 << 9;
|
|
|
|
|
|
2019-11-04 02:10:42 +00:00
|
|
|
|
/// Provides the 68000's bus grant line — indicating whether a bus request has been acknowledged.
|
|
|
|
|
static const int BusGrant = 1 << 10;
|
|
|
|
|
|
2019-05-03 18:20:59 +00:00
|
|
|
|
/// Contains a valid combination of the various static const int flags, describing the operation
|
|
|
|
|
/// performed by this Microcycle.
|
2019-03-10 21:27:34 +00:00
|
|
|
|
int operation = 0;
|
2019-05-03 18:20:59 +00:00
|
|
|
|
|
|
|
|
|
/// Describes the duration of this Microcycle.
|
2019-03-17 01:47:46 +00:00
|
|
|
|
HalfCycles length = HalfCycles(4);
|
2019-03-10 21:27:34 +00:00
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
For expediency, this provides a full 32-bit byte-resolution address — e.g.
|
|
|
|
|
if reading indirectly via an address register, this will indicate the full
|
|
|
|
|
value of the address register.
|
|
|
|
|
|
2019-05-03 18:20:59 +00:00
|
|
|
|
The receiver should ignore bits 0 and 24+. Use word_address() automatically
|
|
|
|
|
to obtain the only the 68000's real address lines, giving a 23-bit address
|
|
|
|
|
at word resolution.
|
2019-03-10 21:27:34 +00:00
|
|
|
|
*/
|
|
|
|
|
const uint32_t *address = nullptr;
|
2019-05-03 18:20:59 +00:00
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
If this is a write cycle, dereference value to get the value loaded onto
|
|
|
|
|
the data bus.
|
|
|
|
|
|
|
|
|
|
If this is a read cycle, write the value on the data bus to it.
|
|
|
|
|
|
|
|
|
|
Otherwise, this value is undefined.
|
|
|
|
|
|
|
|
|
|
Byte values are provided via @c value.halves.low. @c value.halves.high is undefined.
|
|
|
|
|
This is true regardless of whether the upper or lower byte of a word is being
|
|
|
|
|
accessed.
|
|
|
|
|
|
|
|
|
|
Word values occupy the entirety of @c value.full.
|
|
|
|
|
*/
|
2019-03-10 21:27:34 +00:00
|
|
|
|
RegisterPair16 *value = nullptr;
|
2019-03-16 21:54:58 +00:00
|
|
|
|
|
2019-05-03 18:20:59 +00:00
|
|
|
|
/// @returns @c true if two Microcycles are equal; @c false otherwise.
|
2019-03-17 01:47:46 +00:00
|
|
|
|
bool operator ==(const Microcycle &rhs) const {
|
2019-04-30 02:43:15 +00:00
|
|
|
|
if(value != rhs.value) return false;
|
|
|
|
|
if(address != rhs.address) return false;
|
|
|
|
|
if(length != rhs.length) return false;
|
|
|
|
|
if(operation != rhs.operation) return false;
|
|
|
|
|
return true;
|
2019-03-17 01:47:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-03-16 21:54:58 +00:00
|
|
|
|
// Various inspectors.
|
|
|
|
|
|
|
|
|
|
/*! @returns true if any data select line is active; @c false otherwise. */
|
2019-07-09 23:55:30 +00:00
|
|
|
|
forceinline bool data_select_active() const {
|
2019-05-03 18:20:59 +00:00
|
|
|
|
return bool(operation & (SelectWord | SelectByte | InterruptAcknowledge));
|
2019-03-16 21:54:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
@returns 0 if this byte access wants the low part of a 16-bit word; 8 if it wants the high part.
|
|
|
|
|
*/
|
2019-07-09 23:55:30 +00:00
|
|
|
|
forceinline unsigned int byte_shift() const {
|
2019-03-16 21:54:58 +00:00
|
|
|
|
return (((*address) & 1) << 3) ^ 8;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
2019-04-19 17:29:35 +00:00
|
|
|
|
Obtains the mask to apply to a word that will leave only the byte this microcycle is selecting.
|
|
|
|
|
|
2019-03-16 21:54:58 +00:00
|
|
|
|
@returns 0x00ff if this byte access wants the low part of a 16-bit word; 0xff00 if it wants the high part.
|
|
|
|
|
*/
|
2019-07-09 23:55:30 +00:00
|
|
|
|
forceinline uint16_t byte_mask() const {
|
2019-04-19 17:29:35 +00:00
|
|
|
|
return uint16_t(0xff00) >> (((*address) & 1) << 3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
Obtains the mask to apply to a word that will leave only the byte this microcycle **isn't** selecting.
|
|
|
|
|
i.e. this is the part of a word that should be untouched by this microcycle.
|
|
|
|
|
|
|
|
|
|
@returns 0xff00 if this byte access wants the low part of a 16-bit word; 0x00ff if it wants the high part.
|
|
|
|
|
*/
|
2019-07-09 23:55:30 +00:00
|
|
|
|
forceinline uint16_t untouched_byte_mask() const {
|
2019-04-19 17:29:35 +00:00
|
|
|
|
return uint16_t(uint16_t(0xff) << (((*address) & 1) << 3));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
Assuming this cycle is a byte write, mutates @c destination by writing the byte to the proper upper or
|
|
|
|
|
lower part, retaining the other half.
|
|
|
|
|
*/
|
2019-07-09 23:55:30 +00:00
|
|
|
|
forceinline uint16_t write_byte(uint16_t destination) const {
|
2019-04-19 17:29:35 +00:00
|
|
|
|
return uint16_t((destination & untouched_byte_mask()) | (value->halves.low << byte_shift()));
|
2019-03-16 21:54:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-04-19 17:29:35 +00:00
|
|
|
|
/*!
|
|
|
|
|
@returns non-zero if this is a byte read and 68000 LDS is asserted.
|
|
|
|
|
*/
|
2019-07-09 23:55:30 +00:00
|
|
|
|
forceinline int lower_data_select() const {
|
2019-03-16 21:54:58 +00:00
|
|
|
|
return (operation & SelectByte) & ((*address & 1) << 3);
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-19 17:29:35 +00:00
|
|
|
|
/*!
|
|
|
|
|
@returns non-zero if this is a byte read and 68000 UDS is asserted.
|
|
|
|
|
*/
|
2019-07-09 23:55:30 +00:00
|
|
|
|
forceinline int upper_data_select() const {
|
2019-03-16 21:54:58 +00:00
|
|
|
|
return (operation & SelectByte) & ~((*address & 1) << 3);
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-19 17:29:35 +00:00
|
|
|
|
/*!
|
|
|
|
|
@returns the address being accessed at the precision a 68000 supplies it —
|
|
|
|
|
only 24 address bit precision, with the low bit shifted out. So it's the
|
|
|
|
|
68000 address at word precision: address 0 is the first word in the address
|
|
|
|
|
space, address 1 is the second word (i.e. the third and fourth bytes) in
|
|
|
|
|
the address space, etc.
|
|
|
|
|
*/
|
2019-07-09 23:55:30 +00:00
|
|
|
|
forceinline uint32_t word_address() const {
|
2019-03-16 21:54:58 +00:00
|
|
|
|
return (address ? (*address) & 0x00fffffe : 0) >> 1;
|
|
|
|
|
}
|
2019-06-24 14:55:22 +00:00
|
|
|
|
|
2019-12-09 01:19:44 +00:00
|
|
|
|
/*!
|
|
|
|
|
@returns the address of the word or byte being accessed at byte precision,
|
|
|
|
|
in the endianness of the host platform.
|
|
|
|
|
|
|
|
|
|
So: if this is a word access, and the 68000 wants to select the word at address
|
|
|
|
|
@c n, this will evaluate to @c n regardless of the host machine's endianness..
|
|
|
|
|
|
|
|
|
|
If this is a byte access and the host machine is big endian it will evalue to @c n.
|
|
|
|
|
|
|
|
|
|
If the host machine is little endian then it will evaluate to @c n^1.
|
|
|
|
|
*/
|
|
|
|
|
forceinline uint32_t host_endian_byte_address() const {
|
|
|
|
|
#if TARGET_RT_BIG_ENDIAN
|
|
|
|
|
return *address & 0xffffff;
|
|
|
|
|
#else
|
|
|
|
|
return (*address ^ (1 & operation & SelectByte)) & 0xffffff;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-02 03:01:06 +00:00
|
|
|
|
/*!
|
|
|
|
|
@returns the value on the data bus — all 16 bits, with any inactive lines
|
|
|
|
|
(as er the upper and lower data selects) being represented by 1s. Assumes
|
|
|
|
|
this is a write cycle.
|
|
|
|
|
*/
|
|
|
|
|
forceinline uint16_t value16() const {
|
|
|
|
|
if(operation & SelectWord) return value->full;
|
|
|
|
|
const auto shift = byte_shift();
|
|
|
|
|
return uint16_t((value->halves.low << shift) | (0xff00 >> shift));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
@returns the value currently on the high 8 lines of the data bus if any;
|
|
|
|
|
@c 0xff otherwise. Assumes this is a write cycle.
|
|
|
|
|
*/
|
|
|
|
|
forceinline uint8_t value8_high() const {
|
|
|
|
|
if(operation & SelectWord) {
|
|
|
|
|
return uint8_t(value->full >> 8);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return uint8_t(value->halves.low | (0xff00 >> ((*address & 1) << 3)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
@returns the value currently on the low 8 lines of the data bus if any;
|
|
|
|
|
@c 0xff otherwise. Assumes this is a write cycle.
|
|
|
|
|
*/
|
|
|
|
|
forceinline uint8_t value8_low() const {
|
|
|
|
|
if(operation & SelectWord) {
|
|
|
|
|
return uint8_t(value->full);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return uint8_t(value->halves.low | (0x00ff << ((*address & 1) << 3)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
Sets to @c value the 8- or 16-bit portion of the supplied value that is
|
|
|
|
|
currently being read. Assumes this is a read cycle.
|
|
|
|
|
*/
|
|
|
|
|
forceinline void set_value16(uint16_t v) const {
|
|
|
|
|
if(operation & Microcycle::SelectWord) {
|
|
|
|
|
value->full = v;
|
|
|
|
|
} else {
|
|
|
|
|
value->halves.low = uint8_t(v >> byte_shift());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
Equivalent to set_value16((v << 8) | 0x00ff).
|
|
|
|
|
*/
|
|
|
|
|
forceinline void set_value8_high(uint8_t v) const {
|
|
|
|
|
if(operation & Microcycle::SelectWord) {
|
|
|
|
|
value->full = uint16_t(0x00ff | (v << 8));
|
|
|
|
|
} else {
|
|
|
|
|
value->halves.low = uint8_t(v | (0xff00 >> ((*address & 1) << 3)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
Equivalent to set_value16((v) | 0xff00).
|
|
|
|
|
*/
|
|
|
|
|
forceinline void set_value8_low(uint8_t v) const {
|
|
|
|
|
if(operation & Microcycle::SelectWord) {
|
|
|
|
|
value->full = 0xff00 | v;
|
|
|
|
|
} else {
|
|
|
|
|
value->halves.low = uint8_t(v | (0x00ff << ((*address & 1) << 3)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-09 23:55:30 +00:00
|
|
|
|
/*!
|
|
|
|
|
@returns the same value as word_address() for any Microcycle with the NewAddress or
|
|
|
|
|
SameAddress flags set; undefined behaviour otherwise.
|
|
|
|
|
*/
|
|
|
|
|
forceinline uint32_t active_operation_word_address() const {
|
|
|
|
|
return ((*address) & 0x00fffffe) >> 1;
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-09 01:19:44 +00:00
|
|
|
|
/*!
|
|
|
|
|
Assuming this to be a cycle with a data select active, applies it to @c target,
|
|
|
|
|
where 'applies' means:
|
|
|
|
|
|
|
|
|
|
* if this is a byte read, reads a single byte from @c target;
|
|
|
|
|
* if this is a word read, reads a word (in the host platform's endianness) from @c target; and
|
|
|
|
|
* if this is a write, does the converse of a read.
|
|
|
|
|
*/
|
|
|
|
|
forceinline void apply(uint8_t *target) const {
|
|
|
|
|
switch(operation & (SelectWord | SelectByte | Read)) {
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case SelectWord | Read:
|
|
|
|
|
value->full = *reinterpret_cast<uint16_t *>(target);
|
|
|
|
|
break;
|
|
|
|
|
case SelectByte | Read:
|
|
|
|
|
value->halves.low = *target;
|
|
|
|
|
break;
|
|
|
|
|
case Microcycle::SelectWord:
|
|
|
|
|
*reinterpret_cast<uint16_t *>(target) = value->full;
|
|
|
|
|
break;
|
|
|
|
|
case Microcycle::SelectByte:
|
|
|
|
|
*target = value->halves.low;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-24 14:55:22 +00:00
|
|
|
|
#ifndef NDEBUG
|
|
|
|
|
bool is_resizeable = false;
|
|
|
|
|
#endif
|
2019-03-09 05:00:23 +00:00
|
|
|
|
};
|
|
|
|
|
|
2019-03-10 21:27:34 +00:00
|
|
|
|
/*!
|
|
|
|
|
This is the prototype for a 68000 bus handler; real bus handlers can descend from this
|
|
|
|
|
in order to get default implementations of any changes that may occur in the expected interface.
|
|
|
|
|
*/
|
2019-03-09 05:00:23 +00:00
|
|
|
|
class BusHandler {
|
|
|
|
|
public:
|
2019-03-10 21:27:34 +00:00
|
|
|
|
/*!
|
2019-03-10 21:42:13 +00:00
|
|
|
|
Provides the bus handler with a single Microcycle to 'perform'.
|
2019-03-10 21:27:34 +00:00
|
|
|
|
|
2019-03-10 21:42:13 +00:00
|
|
|
|
FC0 and FC1 are provided inside the microcycle as the IsData and IsProgram
|
|
|
|
|
flags; FC2 is provided here as is_supervisor — it'll be either 0 or 1.
|
2019-03-10 21:27:34 +00:00
|
|
|
|
*/
|
2019-03-10 21:42:13 +00:00
|
|
|
|
HalfCycles perform_bus_operation(const Microcycle &cycle, int is_supervisor) {
|
2019-03-10 21:27:34 +00:00
|
|
|
|
return HalfCycles(0);
|
2019-03-09 05:00:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-03-10 21:27:34 +00:00
|
|
|
|
void flush() {}
|
2019-04-24 13:59:54 +00:00
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
Provides information about the path of execution if enabled via the template.
|
|
|
|
|
*/
|
|
|
|
|
void will_perform(uint32_t address, uint16_t opcode) {}
|
2019-03-09 05:00:23 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#include "Implementation/68000Storage.hpp"
|
|
|
|
|
|
|
|
|
|
class ProcessorBase: public ProcessorStorage {
|
|
|
|
|
};
|
|
|
|
|
|
2019-06-19 21:01:49 +00:00
|
|
|
|
enum Flag: uint16_t {
|
|
|
|
|
Trace = 0x8000,
|
|
|
|
|
Supervisor = 0x2000,
|
|
|
|
|
|
2019-06-19 22:56:21 +00:00
|
|
|
|
ConditionCodes = 0x1f,
|
|
|
|
|
|
2019-06-19 21:01:49 +00:00
|
|
|
|
Extend = 0x0010,
|
|
|
|
|
Negative = 0x0008,
|
|
|
|
|
Zero = 0x0004,
|
|
|
|
|
Overflow = 0x0002,
|
|
|
|
|
Carry = 0x0001
|
|
|
|
|
};
|
|
|
|
|
|
2019-06-23 22:37:32 +00:00
|
|
|
|
struct ProcessorState {
|
|
|
|
|
uint32_t data[8];
|
|
|
|
|
uint32_t address[7];
|
|
|
|
|
uint32_t user_stack_pointer, supervisor_stack_pointer;
|
|
|
|
|
uint32_t program_counter;
|
|
|
|
|
uint16_t status;
|
|
|
|
|
|
2019-06-24 19:36:33 +00:00
|
|
|
|
/*!
|
|
|
|
|
@returns the supervisor stack pointer if @c status indicates that
|
|
|
|
|
the processor is in supervisor mode; the user stack pointer otherwise.
|
|
|
|
|
*/
|
2019-06-23 22:37:32 +00:00
|
|
|
|
uint32_t stack_pointer() const {
|
|
|
|
|
return (status & Flag::Supervisor) ? supervisor_stack_pointer : user_stack_pointer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: More state needed to indicate current instruction, the processor's
|
|
|
|
|
// progress through it, and anything it has fetched so far.
|
|
|
|
|
// uint16_t current_instruction;
|
|
|
|
|
};
|
|
|
|
|
|
2019-04-24 13:59:54 +00:00
|
|
|
|
template <class T, bool dtack_is_implicit, bool signal_will_perform = false> class Processor: public ProcessorBase {
|
2019-03-09 05:00:23 +00:00
|
|
|
|
public:
|
2019-03-10 22:40:12 +00:00
|
|
|
|
Processor(T &bus_handler) : ProcessorBase(), bus_handler_(bus_handler) {}
|
|
|
|
|
|
|
|
|
|
void run_for(HalfCycles duration);
|
2019-03-09 05:00:23 +00:00
|
|
|
|
|
2019-03-18 01:57:00 +00:00
|
|
|
|
using State = ProcessorState;
|
2019-04-29 23:22:05 +00:00
|
|
|
|
/// @returns The current processor state.
|
2019-03-18 01:57:00 +00:00
|
|
|
|
State get_state();
|
2019-04-29 23:22:05 +00:00
|
|
|
|
|
|
|
|
|
/// Sets the processor to the supplied state.
|
2019-03-18 01:57:00 +00:00
|
|
|
|
void set_state(const State &);
|
|
|
|
|
|
2019-04-29 17:45:53 +00:00
|
|
|
|
/// Sets the DTack line — @c true for active, @c false for inactive.
|
2019-04-29 23:22:05 +00:00
|
|
|
|
inline void set_dtack(bool dtack) {
|
|
|
|
|
dtack_ = dtack;
|
|
|
|
|
}
|
2019-04-29 17:45:53 +00:00
|
|
|
|
|
|
|
|
|
/// Sets the VPA (valid peripheral address) line — @c true for active, @c false for inactive.
|
2019-04-29 23:22:05 +00:00
|
|
|
|
inline void set_is_peripheral_address(bool is_peripheral_address) {
|
|
|
|
|
is_peripheral_address_ = is_peripheral_address;
|
|
|
|
|
}
|
2019-04-29 17:45:53 +00:00
|
|
|
|
|
|
|
|
|
/// Sets the bus error line — @c true for active, @c false for inactive.
|
2019-07-09 23:55:30 +00:00
|
|
|
|
inline void set_bus_error(bool bus_error) {
|
2019-04-29 23:22:05 +00:00
|
|
|
|
bus_error_ = bus_error;
|
|
|
|
|
}
|
2019-04-29 17:45:53 +00:00
|
|
|
|
|
|
|
|
|
/// Sets the interrupt lines, IPL0, IPL1 and IPL2.
|
2019-07-09 23:55:30 +00:00
|
|
|
|
inline void set_interrupt_level(int interrupt_level) {
|
2019-04-29 23:22:05 +00:00
|
|
|
|
bus_interrupt_level_ = interrupt_level;
|
|
|
|
|
}
|
2019-04-29 17:45:53 +00:00
|
|
|
|
|
|
|
|
|
/// Sets the bus request line.
|
2019-11-04 02:10:42 +00:00
|
|
|
|
/// This area of functionality is TODO.
|
2019-07-09 23:55:30 +00:00
|
|
|
|
inline void set_bus_request(bool bus_request) {
|
2019-04-29 23:22:05 +00:00
|
|
|
|
bus_request_ = bus_request;
|
|
|
|
|
}
|
2019-04-29 17:45:53 +00:00
|
|
|
|
|
|
|
|
|
/// Sets the bus acknowledge line.
|
2019-11-04 02:10:42 +00:00
|
|
|
|
/// This area of functionality is TODO.
|
2019-07-09 23:55:30 +00:00
|
|
|
|
inline void set_bus_acknowledge(bool bus_acknowledge) {
|
2019-04-29 23:22:05 +00:00
|
|
|
|
bus_acknowledge_ = bus_acknowledge;
|
|
|
|
|
}
|
2019-04-29 17:45:53 +00:00
|
|
|
|
|
2019-05-01 02:07:48 +00:00
|
|
|
|
/// Sets the halt line.
|
2019-07-09 23:55:30 +00:00
|
|
|
|
inline void set_halt(bool halt) {
|
2019-05-01 02:07:48 +00:00
|
|
|
|
halt_ = halt;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-09 05:00:23 +00:00
|
|
|
|
private:
|
|
|
|
|
T &bus_handler_;
|
|
|
|
|
};
|
|
|
|
|
|
2019-03-10 21:27:34 +00:00
|
|
|
|
#include "Implementation/68000Implementation.hpp"
|
|
|
|
|
|
2019-03-09 05:00:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif /* MC68000_h */
|