- [CHG] Mòdul zxscreen renombrat a zx_screen
- [NEW] Les coses de la ULA ara estàn en el modul zx_ula - [NEW] zx_screen ja agafa el color del borde de la ULA
This commit is contained in:
69
zx_screen.cpp
Normal file
69
zx_screen.cpp
Normal file
@@ -0,0 +1,69 @@
|
||||
#include "zx_screen.h"
|
||||
#include "z80.h"
|
||||
#include "zx_ula.h"
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
namespace zxscreen
|
||||
{
|
||||
uint32_t palette[16] = {
|
||||
0x000000, 0x000080, 0x800000, 0x800080, 0x008000, 0x008080, 0x808000, 0x808080,
|
||||
0x000000, 0x0000FF, 0xFF0000, 0xFF00FF, 0x00FF00, 0x00FFFF, 0xFFFF00, 0xFFFFFF
|
||||
};
|
||||
SDL_Window *win = nullptr;
|
||||
SDL_Renderer *ren = nullptr;
|
||||
SDL_Texture *tex = nullptr;
|
||||
|
||||
void show()
|
||||
{
|
||||
if (win) return;
|
||||
win = SDL_CreateWindow("ZX Spectrum Screen", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 352, 288, SDL_WINDOW_RESIZABLE);
|
||||
ren = SDL_CreateRenderer(win, -1, 0);
|
||||
tex = SDL_CreateTexture(ren, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, 352, 288);
|
||||
refresh();
|
||||
}
|
||||
|
||||
void refresh()
|
||||
{
|
||||
const uint8_t* memory = z80::getMem();
|
||||
const uint8_t border_color = zx_ula::get_border_color();
|
||||
//memory+=0x4000;
|
||||
|
||||
Uint32* pixels;
|
||||
int pitch;
|
||||
SDL_LockTexture(tex, NULL, (void**)&pixels, &pitch);
|
||||
|
||||
// Upper border
|
||||
for (int i=0; i<352*48;++i) *(pixels++) = palette[border_color];
|
||||
|
||||
// scanlines
|
||||
for (uint8_t y=0; y<192; ++y)
|
||||
{
|
||||
// Left border
|
||||
for (int j=0;j<48;++j) *(pixels++) = palette[border_color];
|
||||
|
||||
// Actual screen
|
||||
for (uint8_t x=0;x<32;++x)
|
||||
{
|
||||
uint8_t color = memory[0x5800 + x + (y>>3)*32];
|
||||
|
||||
uint16_t address = 0x4000 | (x&0x1f) | ((y&0x7)<<8) | ((y&0x38)<<2) | ((y&0xc0)<<5);
|
||||
uint8_t block = memory[address];
|
||||
for (int i=0;i<8;++i)
|
||||
{
|
||||
*(pixels++)=(block&0x80) ? palette[color&0x7] : palette[(color>>3)&0x7];
|
||||
block = block<<1;
|
||||
}
|
||||
}
|
||||
|
||||
// Right border
|
||||
for (int j=0;j<48;++j) *(pixels++) = palette[border_color];
|
||||
}
|
||||
|
||||
// Lower border
|
||||
for (int i=0; i<352*48;++i) *(pixels++)=palette[border_color];
|
||||
|
||||
SDL_UnlockTexture(tex);
|
||||
SDL_RenderCopy(ren, tex, NULL, NULL);
|
||||
SDL_RenderPresent(ren);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user