1
0
mirror of https://github.com/TomHarte/CLK.git synced 2025-01-11 08:30:55 +00:00

Made an attempt properly to emulate the RDY line and the Atari's use of it.

This commit is contained in:
Thomas Harte 2015-07-31 16:54:20 -04:00
parent 53dd5c8f16
commit c1d1fb65cb
2 changed files with 132 additions and 115 deletions

View File

@ -194,13 +194,14 @@ void Machine::output_pixels(int count)
int Machine::perform_bus_operation(CPU6502::BusOperation operation, uint16_t address, uint8_t *value)
{
uint8_t returnValue = 0xff;
int cycle_count = 1;
output_pixels(3);
if(_horizontalTimer == 227)
set_ready_line(false);
if(operation != CPU6502::BusOperation::Ready) {
// check for a ROM access
if ((address&0x1000) && isReadOperation(operation)) {
// if(operation == CPU6502::BusOperation::ReadOpcode) printf("[%04x]\n", address);
returnValue &= _rom[address&_romMask];
}
@ -233,8 +234,7 @@ int Machine::perform_bus_operation(CPU6502::BusOperation operation, uint16_t add
case 0x01: _vBlankEnabled = !!(*value & 0x02); break;
case 0x02: {
cycle_count += ((_horizontalTimer+1) / 3);
output_pixels(_horizontalTimer+1);
set_ready_line(true);
} break;
case 0x03: _horizontalTimer = 227; break;
@ -322,16 +322,17 @@ int Machine::perform_bus_operation(CPU6502::BusOperation operation, uint16_t add
if(isReadOperation(operation)) {
*value = returnValue;
}
}
if(_piaTimerValue < cycle_count) {
_piaTimerValue = 0x100 - cycle_count + _piaTimerValue;
if(_piaTimerValue) {
_piaTimerValue --;
} else {
_piaTimerValue = 0xff;
_piaTimerShift = 0;
_piaTimerStatus |= 0xc0;
}
else
_piaTimerValue -= cycle_count;
return cycle_count;
return 1;
}
void Machine::set_rom(size_t length, const uint8_t *data)

View File

@ -39,7 +39,7 @@ enum BusOperation {
Read, ReadOpcode, Write, Ready, None
};
#define isReadOperation(v) (v != CPU6502::BusOperation::Write)
#define isReadOperation(v) (v == CPU6502::BusOperation::Read || v == CPU6502::BusOperation::ReadOpcode)
extern const uint8_t JamOpcode;
@ -370,7 +370,8 @@ template <class T> class Processor {
int _cycles_left_to_run;
bool _read_line_is_enabled;
bool _ready_line_is_enabled;
bool _ready_is_active;
public:
Processor()
@ -380,7 +381,8 @@ template <class T> class Processor {
_is_jammed = false;
_jam_handler = nullptr;
_cycles_left_to_run = 0;
_read_line_is_enabled = false;
_ready_line_is_enabled = false;
_ready_is_active = false;
}
const MicroOp *get_reset_program() {
@ -425,9 +427,13 @@ template <class T> class Processor {
while(_cycles_left_to_run > 0) {
while (_nextBusOperation != BusOperation::Ready && _cycles_left_to_run > 0) {
while (_ready_is_active && _cycles_left_to_run > 0) {
_cycles_left_to_run -= static_cast<T *>(this)->perform_bus_operation(BusOperation::Ready, _busAddress, _busValue);
}
if (_nextBusOperation != BusOperation::None && _nextBusOperation != BusOperation::Ready) {
while (!_ready_is_active && _cycles_left_to_run > 0) {
if (_nextBusOperation != BusOperation::None) {
_cycles_left_to_run -= static_cast<T *>(this)->perform_bus_operation(_nextBusOperation, _busAddress, _busValue);
_nextBusOperation = BusOperation::None;
}
@ -863,6 +869,9 @@ template <class T> class Processor {
break;
}
if (isReadOperation(_nextBusOperation) && _ready_line_is_enabled) {
_ready_is_active = true;
}
}
}
}
@ -919,6 +928,13 @@ template <class T> class Processor {
void set_ready_line(bool active)
{
if(active)
_ready_line_is_enabled = true;
else
{
_ready_line_is_enabled = false;
_ready_is_active = false;
}
}
bool is_jammed()