From 14adcd209642368e049def69bdae566262746400 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Thu, 30 Jul 2015 16:09:32 -0400 Subject: [PATCH] Had a quick bash at timer overflow. --- Machines/Atari2600.cpp | 21 ++++++++++++++------- Machines/Atari2600.hpp | 1 + 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Machines/Atari2600.cpp b/Machines/Atari2600.cpp index 2c921d5f5..40cd0ae36 100644 --- a/Machines/Atari2600.cpp +++ b/Machines/Atari2600.cpp @@ -20,6 +20,7 @@ Machine::Machine() _lastOutputStateDuration = 0; _lastOutputState = OutputState::Sync; _crt = new Outputs::CRT(228, 256, 1, 4); + _piaTimerStatus = 0xff; reset(); } @@ -272,15 +273,15 @@ int Machine::perform_bus_operation(CPU6502::BusOperation operation, uint16_t add if ((address&0x1280) == 0x280) { if(isReadOperation(operation)) { switch(address & 0xf) { -// case 0x00: - case 0x04: returnValue &= _piaTimerValue >> _piaTimerShift; break; + case 0x04: returnValue &= _piaTimerValue >> _piaTimerShift; break; + case 0x05: returnValue &= _piaTimerStatus; _piaTimerStatus &= ~0x40; break; } } else { switch(address & 0x0f) { - case 0x04: _piaTimerShift = 0; _piaTimerValue = *value << 0; break; - case 0x05: _piaTimerShift = 3; _piaTimerValue = *value << 3; break; - case 0x06: _piaTimerShift = 6; _piaTimerValue = *value << 6; break; - case 0x07: _piaTimerShift = 10; _piaTimerValue = *value << 10; break; + case 0x04: _piaTimerShift = 0; _piaTimerValue = *value << 0; _piaTimerStatus &= ~0xc0; break; + case 0x05: _piaTimerShift = 3; _piaTimerValue = *value << 3; _piaTimerStatus &= ~0xc0; break; + case 0x06: _piaTimerShift = 6; _piaTimerValue = *value << 6; _piaTimerStatus &= ~0xc0; break; + case 0x07: _piaTimerShift = 10; _piaTimerValue = *value << 10; _piaTimerStatus &= ~0xc0; break; } } // printf("Uncaught PIA %04x\n", address); @@ -290,7 +291,13 @@ int Machine::perform_bus_operation(CPU6502::BusOperation operation, uint16_t add *value = returnValue; } - _piaTimerValue -= cycle_count; + if(_piaTimerValue < cycle_count) { + _piaTimerValue = 0x100 - cycle_count + _piaTimerValue; + _piaTimerShift = 0; + _piaTimerStatus |= 0xc0; + } + else + _piaTimerValue -= cycle_count; return cycle_count; } diff --git a/Machines/Atari2600.hpp b/Machines/Atari2600.hpp index 375456304..5923c5f11 100644 --- a/Machines/Atari2600.hpp +++ b/Machines/Atari2600.hpp @@ -37,6 +37,7 @@ class Machine: public CPU6502::Processor { // the timer unsigned int _piaTimerValue; unsigned int _piaTimerShift; + uint8_t _piaTimerStatus; // graphics registers uint8_t _playfield[3], _playfieldControl;