nes/src/Ppu.cpp

46 lines
1.0 KiB
C++

//
// Created by selim on 8/22/23.
//
#include "Ppu.h"
namespace nes {
Ppu::Ppu(): _column{}, _scanline{} {
_frameBuffer = std::make_unique<Pixel[]>(SCREEN_WIDTH*SCREEN_HEIGHT);
}
void Ppu::tick() {
if(_column < SCREEN_WIDTH && _scanline < SCREEN_HEIGHT && _scanline >= 0) {
Pixel black = {0, 0, 0, 100};
Pixel white = {255, 255, 255, 100};
Pixel pixel = std::rand() % 2 == 0 ? black : white;
setPixel(_scanline, _column, pixel);
}
_column++;
if(_column >= 341) {
_column = 0;
_scanline++;
if(_scanline >= 261) {
_scanline = -1;
onNewFrame(_frameBuffer.get());
}
}
}
void Ppu::write(uint16_t address, uint8_t value) {
}
uint8_t Ppu::read(uint16_t address) {
return 0;
}
void Ppu::setPixel(uint16_t row, uint16_t column, Pixel pixel) {
size_t index = row*SCREEN_WIDTH + column;
_frameBuffer[index] = pixel;
}
}