45 lines
851 B
C++
45 lines
851 B
C++
//
|
|
// Created by selim on 9/23/23.
|
|
//
|
|
|
|
#include "Dma.h"
|
|
#include "Ppu.h"
|
|
#include "System.h"
|
|
|
|
namespace nes {
|
|
|
|
Dma::Dma(System *system, Ppu *ppu): _system{system}, _ppu{ppu} {
|
|
|
|
}
|
|
|
|
bool Dma::active() const {
|
|
return _active;
|
|
}
|
|
|
|
void Dma::tick(uint64_t cycles) {
|
|
if(_dummy) {
|
|
if(cycles % 2 == 1) {
|
|
_dummy = false;
|
|
}
|
|
} else {
|
|
if(cycles % 2 == 0) {
|
|
_data = _system->read((_page << 8) | _address);
|
|
} else {
|
|
_ppu->writeOam(_address, _data);
|
|
_address++;
|
|
|
|
if(_address == 0) {
|
|
_active = false;
|
|
_dummy = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void Dma::start(uint8_t page) {
|
|
_page = page;
|
|
_active = true;
|
|
}
|
|
|
|
}
|