54 lines
1.3 KiB
C++
54 lines
1.3 KiB
C++
//
|
|
// Created by selim on 8/22/23.
|
|
//
|
|
|
|
#include "Ppu.h"
|
|
|
|
namespace nes {
|
|
|
|
Ppu::Ppu(): _column{}, _scanline{}, _status{} {
|
|
_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) {
|
|
switch (address) {
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
uint8_t Ppu::read(uint16_t address) {
|
|
switch (address) {
|
|
case Status:
|
|
uint8_t value = _status.value & 0xE0;
|
|
_status.verticalBlank = 0;
|
|
return value;
|
|
}
|
|
}
|
|
|
|
void Ppu::setPixel(uint16_t row, uint16_t column, Pixel pixel) {
|
|
size_t index = row*SCREEN_WIDTH + column;
|
|
_frameBuffer[index] = pixel;
|
|
}
|
|
} |