lcd - A few steps towards handling tilemaps
Bit by bit.
This commit is contained in:
parent
da91ec4d1b
commit
19c09901fb
3 changed files with 14 additions and 7 deletions
15
lcd/lcd.cpp
15
lcd/lcd.cpp
|
@ -18,11 +18,13 @@ LCD::LCD(Cpu& cpu)
|
|||
{
|
||||
tiles[i].create(8,8,sf::Color::Red);
|
||||
}
|
||||
|
||||
for(int l = 0; l < 2; l++)
|
||||
std::memset(&tilemap[l], 0, 32*32);
|
||||
}
|
||||
|
||||
void LCD::generate_tile(int idx)
|
||||
{
|
||||
std::cerr << "Updating tile " << idx << std::endl;
|
||||
for(int y = 0, addr = idx << 4; y < 8; y++, addr+=2)
|
||||
{
|
||||
u8 a = vram_raw[addr];
|
||||
|
@ -30,7 +32,6 @@ void LCD::generate_tile(int idx)
|
|||
for(int x = 7; x >= 0; x--, a>>=1, b>>=1)
|
||||
{
|
||||
tiles[idx].setPixel(x,y,bgp.getColorByIdx( ((a&0x1) << 1) | (b&0x1)));
|
||||
//tiles[idx].setPixel(x,y,sf::Color::Red);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -146,14 +147,16 @@ u8 LCD::read8(u16 addr) {
|
|||
void LCD::render(sf::RenderTarget& target)
|
||||
{
|
||||
cpu.signalInterrupt(INT_VBlank);
|
||||
for(int row = 0; row < 16; row++)
|
||||
for(int col = 0; col < 12; col++)
|
||||
for(int row = 0; row < 32; row++)
|
||||
for(int col = 0; col < 32; col++)
|
||||
{
|
||||
unsigned int idx = row*12+col;
|
||||
unsigned int map_idx = row*32+col;
|
||||
sf::Texture txt;
|
||||
sf::Sprite spr;
|
||||
|
||||
txt.loadFromImage(tiles[idx]);
|
||||
unsigned int tile_idx = tilemap[0][map_idx];
|
||||
|
||||
txt.loadFromImage(tiles[tile_idx]);
|
||||
spr.setTexture(txt,true);
|
||||
spr.setPosition(col*8,row*8);
|
||||
target.draw(spr);
|
||||
|
|
|
@ -28,6 +28,7 @@ private:
|
|||
// Graphics
|
||||
sf::RenderTexture screenbuffer;
|
||||
sf::Image tiles[384];
|
||||
unsigned int tilemap[2][32*32];
|
||||
|
||||
// Emulated device
|
||||
u8 regLY;
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <memory/bus.h>
|
||||
#include <memory/register.h>
|
||||
#include <lcd/lcd.h>
|
||||
#include <timer/timer.h>
|
||||
#include <fstream>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
|
@ -26,7 +27,7 @@ int main(int argc, char** argv)
|
|||
return 2;
|
||||
}
|
||||
|
||||
sf::RenderWindow window(sf::VideoMode(12*8,16*8), "VGBC tiles view");
|
||||
sf::RenderWindow window(sf::VideoMode(256,256), "VGBC BG view");
|
||||
|
||||
RAM wram1(0x1000);
|
||||
RAM wram2(0x1000);
|
||||
|
@ -39,6 +40,7 @@ int main(int argc, char** argv)
|
|||
Cpu cpu(&b);
|
||||
|
||||
LCD lcd(cpu);
|
||||
TimerDiv timer;
|
||||
|
||||
b.map_device(0x0000, 0x7FFF, &mbc1);
|
||||
b.map_device(0x8000, 0x9FFF, &lcd, 0x8000);
|
||||
|
@ -47,6 +49,7 @@ int main(int argc, char** argv)
|
|||
b.map_device(0xD000, 0xDFFF, &wram2);
|
||||
b.map_device(0xE000, 0xFDFF, &wram1);
|
||||
b.map_device(0xFE00, 0xFE9F, &oam);
|
||||
b.map_device(0xFF04, 0xFF07, &timer);
|
||||
b.map_device(0xFF40, 0xFF4F, &lcd, 0xFF40);
|
||||
b.map_device(0xFF80, 0xFFFE, &hram);
|
||||
|
||||
|
|
Loading…
Reference in a new issue