#include "zxscreen.h" #include "z80.h" #include 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(); //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[7]; // scanlines for (uint8_t y=0; y<192; ++y) { // Left border for (int j=0;j<48;++j) *(pixels++) = palette[7]; // Actual screen for (uint8_t x=0;x<32;++x) { 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[7] : palette[0]; block = block<<1; } } // Right border for (int j=0;j<48;++j) *(pixels++) = palette[7]; } // Lower border for (int i=0; i<352*48;++i) *(pixels++)=palette[7]; SDL_UnlockTexture(tex); SDL_RenderCopy(ren, tex, NULL, NULL); SDL_RenderPresent(ren); } }